B. Spotlights
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

  • there is no actor in the cell the spotlight is placed to;
  • there is at least one actor in the direction the spotlight projects.

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

Output

Print one integer — the number of good positions for placing the spotlight.

Examples
input
2 4
0 1 0 0
1 0 1 0
output
9
input
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0
output
20
Note

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.



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
#include <iostream>
#include <stdio.h>
#include <vector>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int M, N;
    cin >> M >> N;
    vector<vector<int> > ary(M, vector<int>(N));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++)
            scanf("%d"&ary[i][j]);
    }
    int result = 0;
    for (int i = 0; i < M; i++) {
        bool cool = false;
        for (int j = 0; j < N; j++) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }    
        cool = false;
        for (int j = N-1; j > -1; j--) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
    }
    for (int j = 0; j < N; j++) {
        bool cool = false;
        for (int i = 0; i < M; i++) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
        cool = false;
        for (int i = M - 1; i > -1; i--) {
            if (ary[i][j] == 1)
                cool = true;
            else if (ary[i][j] == && cool == true)
                result++;
        }
    }
    cout << result;
    return 0;
}
cs


A. Interview with Oleg
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.

There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogoogogoogogogo are fillers, but the words googogogogogog and oggo are not fillers.

The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.

To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.

Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview.

The second line contains the string s of length n, consisting of lowercase English letters.

Output

Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.

Examples
input
7
aogogob
output
a***b
input
13
ogogmgogogogo
output
***gmg***
input
9
ogoogoogo
output
*********
Note

The first sample contains one filler word ogogo, so the interview for printing is "a***b".

The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".


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>
#include <string>
#include <cstring>
 
#pragma warning (disable : 4996)
using namespace std;
 
int main() {
    int N;
    string S;
    string ans;
    cin >> N >> S;
    int idx = 0;
    while (idx < S.length()) {
        if (S[idx] == 'o' && S[idx + 1== 'g' && S[idx + 2== 'o' ) {
            int tmp = idx + 3;
            while (1) {
                if (S[tmp] == 'g' && S[tmp + 1== 'o')
                    tmp += 2;
                else
                    break;
            }
            idx = tmp;
            ans += "***";
        }
        else {
            ans += S[idx];
            idx++;
        }
    }
 
    cout << ans;
 
    return 0;
}
cs


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.

+ Recent posts