B. Parallelogram is Back

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output


Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.


Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.


Input

The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.


Output

First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.


Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.


Example

input

0 0

1 0

0 1

output

3

1 -1

-1 1

1 1


Note

If you need clarification of what parallelogram is, please check Wikipedia page:


https://en.wikipedia.org/wiki/Parallelogram







<Solution>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
 
using namespace std;
 
struct Cpoint {
    double X;
    double Y;
};
 
 
int main() {
    struct Cpoint p1, p2, p3, p4;
 
    cin >> p1.X;
    cin >> p1.Y;
    cin >> p2.X;
    cin >> p2.Y;
    cin >> p3.X;
    cin >> p3.Y;
 
    cout << "3" << endl;
    p4.X = (p1.X + p2.X) - p3.X;
    p4.Y = (p1.Y + p2.Y) - p3.Y;
    cout << p4.X << " " << p4.Y << endl;
 
    p4.X = (p2.X + p3.X) - p1.X;
    p4.Y = (p2.Y + p3.Y) - p1.Y;
    cout << p4.X << " " << p4.Y << endl;
 
    p4.X = (p1.X + p3.X) - p2.X;
    p4.Y = (p1.Y + p3.Y) - p2.Y;
    cout << p4.X << " " << p4.Y;
 
    return 0;
}
cs

<Online Solution>

http://codeforces.com/blog/entry/49186#comments


Denote the input points as ABC, and the point we need to find as D.

Consider the case when the segments AD and BC are the diagonals of parallelogram. Vector AD is equal to the sum of two vectors AB + BD = AC + CD. As in the parallelogram the opposite sides are equal and parallel, BD = ACAB = CD, and we can conclude that AD = AB + AC. So, the coordinates of the point D can be calculated as A + AB + AC = (Ax + Bx - Ax + Cx - Ax, Ay + By - Ay + Cy - Ay) = (Bx + Cx - Ax, By + Cy - Ay).

The cases where the diagonals are BD and ACCD and AB are processed in the same way.

Prove that all three given points are different. Let's suppose it's wrong. Without losing of generality suppose that the points got in cases AD and BD are equal.

Consider the system of two equations for the equality of these points:

  • Bx + Cx - Ax = Ax + Cx - Bx
  • By + Cy - Ay = Ay + Cy - By

We can see that in can be simplified as

  • Ax = Bx
  • Ay = By

And we got a contradiction, as all the points A, B, C are distinct.


A. Bachgold Problem

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output


Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.


Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.


Input

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).


Output

The first line of the output contains a single integer k — maximum possible number of primes in representation.


The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.


Examples

input

5

output

2

2 3

input

6

output

3

2 2 2





<Solution>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using namespace std;
 
int main() {
    int input;
    int count = 0;
    int ary[100000];
    cin >> input;
    count = input / 2;
    if (input % == 0)
        for (int i = 0; i < count; i++
            ary[i] = 2;
        
    else if (input % == 1) {
        for (int i = 0; i < count-1; i++
            ary[i] = 2;
        ary[count - 1= 3;
    }
    
    cout << count << endl;
    for (int i = 0; i < count; i++)
        cout << ary[i] << " ";
 
    return 0;
}
cs

<Online Solution>

http://codeforces.com/blog/entry/49186#comments

We need represent integer number N (1 < N) as a sum of maximum possible number of prime numbers, they don’t have to be different.

If N is even number, we can represent it as sum of only 2 - minimal prime number. It is minimal prime number, so number of primes in sum is maximal in this case.

If N is odd number, we can use representing of N - 1 as sum with only 2 and replace last summand from 2 to 3.

Using of any prime P > 3 as summand is not optimal, because it can be replaced by more than one 2 and 3.

https://www.acmicpc.net/problem/9012


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int N;
    unsigned long long count = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        stack<char> stack1;
        string input;
        cin >> input;
        while (!stack1.empty())
            stack1.pop();
        for (int i = 0; i < input.size(); i++) {
            if (stack1.empty())
                stack1.push(input[i]);
            else {
                if (input[i] == '(')
                    stack1.push(input[i]);
                else if (input[i] == ')')
                    if (stack1.top() == '(')
                        stack1.pop();
                    else
                        stack1.push(input[i]);
            }
        }
        if (stack1.empty())
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}
cs


https://www.acmicpc.net/problem/3986


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int N;
    unsigned long long count = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        stack<char> stack1;
        string input;
        cin >> input;
        for (int i = 0; i < input.size(); i++) {
            // method 1
            if (!stack1.empty() && input[i] == stack1.top())
                stack1.pop();
            else
                stack1.push(input[i]);
            /* method 2
            if (stack1.empty())
                stack1.push(input[i]);
            else {
                if (input[i] == stack1.top())
                    stack1.pop();
                else
                    stack1.push(input[i]);
            }
            */
        }
        if (stack1.empty())
            count++;
    }
    cout << count;
    return 0;
}
cs


https://www.acmicpc.net/problem/6198


O(2n)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stack>
#include <stdio.h>
#include <iostream>
 
using namespace std;
 
int main() {
    stack<int> stack1;
    int N;
    unsigned long long count = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int input;
        cin >> input;
        if (stack1.empty())
            stack1.push(input);
        else {
            while (stack1.top() <= input) {
                stack1.pop();
                if (stack1.empty()) {
                    stack1.push(input);
                    break;
                }
            }
            if (stack1.top() > input)
                stack1.push(input);
        }
        count += stack1.size() - 1;
    }
    cout << count;
    return 0;
}
cs


//Chromium main site

http://www.chromium.org


//Site with bug issues

https://bugs.chromium.org/p/chromium/issues/list


//Site with bug report

https://codereview.chromium.org


//Site with Chromium code

https://cs.chromium.org

http://www.chromium.org/developers/how-tos/get-the-code


##Error

[1] ' ' is not recognized as an internal or external command.

e.q. 'powershell' is not recognized as an internal or external command.


>>missing an environment variable.

Add this to your Path environment variable:

%SYSTEMROOT%\System32\


'Open Source > Chromium' 카테고리의 다른 글

[1] Fixed a Bug = 649938(tab to search hint still displayed when unfocused omnibox)  (0) 2017.09.21
Errors  (0) 2017.02.11
Sites related to Chromium  (0) 2016.12.16

https://algospot.com/judge/problem/read/DICTIONARY#


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
vector<string> words;
vector<vector<int> > adj;
vector<int> seen, order;
int C;
int N;
 
void makeGraph(const vector<string>& words){
 adj = vector<vector<int> >(26, vector<int>(260));
 for(int j = 1; j < words.size(); ++j){
  int i = j-1;
  int len = min(words[i].size(), words[j].size());
 
  for(int k = 0; k < len; ++k){
   if(words[i][k] != words[j][k]){
    int a = words[i][k] - 'a';
    int b = words[j][k] - 'a';
    adj[a][b] = 1;
    break;
   }
  }
 }
}
 
void dfs(int here){
 seen[here] = 1;
 for(int there = 0; there < adj.size(); ++there)
  if(adj[here][there] && !seen[there])
   dfs(there);
 order.push_back(here);
}
 
vector<int> topologicalSort(){
 int n = adj.size();
 seen = vector<int>(n, 0);
 order.clear();
 for(int i = 0; i < n; ++i)
  if(!seen[i])
   dfs(i);
 reverse(order.begin(), order.end());
 
 for(int i = 0; i < n; ++i)
  for(int j = i + 1; j < n; ++j)
   if(adj[order[j]][order[i]])
    return vector<int>();
 
 return order;
}
 
int main(){
 cin >> C;
 
 for(int j = 0; j < C; j++){
  cin >> N;
  words.clear();
  for(int i = 0; i < N; i++){
   string temp;
   cin >> temp;
   words.push_back(temp);
  }
 
  makeGraph(words);
  
  vector<int> arr = topologicalSort();
  
  /*for(int j = 0; j < adj.size(); j++){
   for(int i = 0; i < adj.size(); i++){
    cout << adj[j][i] << " ";  
   }
   cout << endl;
  }*/
  
  if(arr.empty()) cout << "INVALID HYPOTHESIS" << endl;
 
  else{
   for(int i = 0; i < arr.size(); i++){
    //cout << arr[i] << " ";
    char temp;
    temp = (char)(arr[i] + 'a');
    cout << temp;
   }
   cout << endl;
  }
 }
 return 0;
}
cs


+ Recent posts