var
  n, i: integer;
begin
  read(n);
  for i:=1 to n do write('ACL');
end.

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

You are given an integer K.
Print the string obtained by repeating the string ACL K times and concatenating them.

For example, if K = 3, print ACLACLACL.

Constraints

1 \leq K \leq 5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the string obtained by repeating the string ACL K times and concatenating them.

Sample Input 1

3

Sample Output 1

ACLACLACL

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


var s:String;
begin
readln(s);
write(s);
if s[length(s)]='s' then writeln('es')else writeln('s');
end.

Score : 100 points

Problem Statement

In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters.

In Taknese, the plural form of a noun is spelled based on the following rules:

If a noun's singular form does not end with s, append s to the end of the singular form.

If a noun's singular form ends with s, append es to the end of the singular form.

You are given the singular form S of a Taknese noun. Output its plural form.

Constraints

S is a string of length 1 between 1000, inclusive.

S contains only lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the plural form of the given Taknese word.

Sample Input 1

apple

Sample Output 1

apples

apple ends with e, so its plural form is apples.

Sample Input 2

bus

Sample Output 2

buses

bus ends with s, so its plural form is buses.

Sample Input 3

box

Sample Output 3

boxs


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils,math;
var
	N	        :integer;
	a,b,ans     :integer;
begin
    readln(N);
    ans:=0;
    for a:=1 to N do
    begin
        for b:=1 to (N div a) do
        begin
            if ((a*b)<N) then inc(ans);
        end;
    end;

    writeln(stdout,ans);
end.

Score : 300 points

Problem Statement

Given is a positive integer N.
How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?

Constraints

2 \leq N \leq 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

3

Sample Output 1

3

There are 3 tuples of integers that satisfy A \times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1).

Sample Input 2

100

Sample Output 2

473

Sample Input 3

1000000

Sample Output 3

13969985


program sequence_sum;
var
  n, x, m, num: int64;
  i, offset, period, rem: integer;
  a: array[0..100000] of int64;
  b: array[0..100000] of integer;
begin
  read(n, x, m);
  if n = 1 then
  begin
    writeln(x);
    halt(0);
  end;
  a[1] := x;
  b[x] := 1;
  for i := 2 to m + 1 do
  begin
    x := (x * x) mod m;
    a[i] := a[i - 1] + x;
    if i = n then
    begin
      writeln(a[i]);
      halt(0);
    end;
    if b[x] > 0 then
    begin
      offset := b[x] - 1;
      period := i - offset - 1;
      break;
    end;
    b[x] := i;
  end;
  num := (n - offset) div period;
  rem := n - offset - num * period;
  writeln((a[offset + period] - a[offset]) * num + a[offset + rem]);
end.

Score : 500 points

Problem Statement

Let us denote by f(x, m) the remainder of the Euclidean division of x by m.

Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M).
Find \displaystyle{\sum_{i=1}^N A_i}.

Constraints

1 \leq N \leq 10^{10}

0 \leq X < M \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X M

Output

Print \displaystyle{\sum_{i=1}^N A_i}.

Sample Input 1

6 2 1001

Sample Output 1

1369

The sequence A begins 2,4,16,256,471,620,\ldots Therefore, the answer is 2+4+16+256+471+620=1369.

Sample Input 2

1000 2 16

Sample Output 2

6

The sequence A begins 2,4,0,0,\ldots Therefore, the answer is 6.

Sample Input 3

10000000000 10 99959

Sample Output 3

492443256176507


program sequence_sum;
var
  n, x, m, num: int64;
  i, k, offset, period, rem: integer;
  a: array[0..100000] of int64;
  b: array[0..100000] of integer;
begin
  read(n, x, m);
  if n = 1 then
  begin
    writeln(x);
    halt(0);
  end;
  a[1] := x;
  b[integer(x)] := 1;
  for i := 2 to integer(m) + 1 do
  begin
    x := (x * x) mod m;
    a[i] := a[i - 1] + x;
    if i = n then
    begin
      writeln(a[i]);
      halt(0);
    end;
    k := integer(x);
    if b[k] > 0 then
    begin
      offset := b[k] - 1;
      period := i - offset - 1;
      break;
    end;
    b[k] := i;
  end;
  num := (n - offset) div int64(period);
  rem := integer(n - offset - num * period);
  writeln((a[offset + period] - a[offset]) * num + a[offset + rem]);
end.


program sequence_sum;
var
  n, x, m, num: int64;
  i, offset, period, rem: integer;
  a: array[0..100000] of int64;
  b: array[0..100000] of integer;
begin
  for i := 0 to 100000 do
  begin
    a[i] := 0;
    b[i] := 0;
  end;
  read(n, x, m);
  if n = 1 then
  begin
    writeln(x);
    halt(0);
  end;
  a[1] := x;
  b[x] := 1;
  for i := 2 to m do
  begin
    x := (x * x) mod m;
    a[i] := a[i - 1] + x;
    if i = n then
    begin
      writeln(a[i]);
      halt(0);
    end;
    if b[x] > 0 then
    begin
      offset := b[x] - 1;
      period := i - offset - 1;
      break;
    end;
    b[x] := i;
  end;
  num := (n - offset) div period;
  rem := n - offset - num * period;
  writeln((a[offset + period] - a[offset]) * num + a[offset + rem]);
end.


var
  i: integer;
begin
  read(i);
  write(1-i);
end.

Score : 100 points

Problem Statement

Given is an integer x that is greater than or equal to 0, and less than or equal to 1.
Output 1 if x is equal to 0, or 0 if x is equal to 1.

Constraints

0 \leq x \leq 1

x is an integer

Input

Input is given from Standard Input in the following format:

x

Output

Print 1 if x is equal to 0, or 0 if x is equal to 1.

Sample Input 1

1

Sample Output 1

0

Sample Input 2

0

Sample Output 2

1


var

k,x,i:integer;
s:string;
r:real;

begin

//program 1

readln(x);

IF (x = 0) THEN

begin
	writeln('1');
end;

IF (x = 1) THEN

begin
	writeln('0');
end;

end.


Program AtCoderBeginnerContest178;

uses
sysutils,strutils, math;

var

a,b,c,d,x,temp,t2 :int64;
s:string;
r:real;

begin

read(a);
read(b);
read(c);
read(d);

IF (b = 0) AND (d = 0) THEN
begin
	x:= a * c;
	writeln(x);
	exit;
end;

IF (a > 0) AND (c > 0) THEN//if all positive
begin
	x:= b * d;
	writeln(x);
	exit;
end;

IF (b < 0) AND (d < 0) THEN//if all negative
begin
	x:= a * c;
	writeln(x);
	exit;
end;

IF (a < 0) AND (b < 0) AND (c > 0) AND (d > 0) THEN//if both x range negative
begin
	temp:= max(a,b);
	x:= temp * min(c,d);
	writeln(x);
	exit;
end;

IF (a > 0) AND (b > 0) AND (c < 0) AND (d < 0) THEN//if both y range negative
begin
	temp:= max(c,d);
	x:= temp * min(a,b);
	writeln(x);
	exit;
end;

IF (a < 0) OR (b < 0) THEN
begin
	temp:= max(a,b);
end;

IF (c < 0) OR (d < 0) THEN
begin
	t2:= max(c,d);
end;

writeln(x);

//program 1

{readln(x);

IF (x = 0) THEN

begin
	writeln('1');
end;

IF (x = 1) THEN

begin
	writeln('0');
end;}

end.

Score : 200 points

Problem Statement

Given are integers a,b,c and d.
If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y?

Constraints

-10^9 \leq a \leq b \leq 10^9

-10^9 \leq c \leq d \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a b c d

Output

Print the answer.

Sample Input 1

1 2 1 1

Sample Output 1

2

If x = 1 and y = 1 then x \times y = 1.
If x = 2 and y = 1 then x \times y = 2.
Therefore, the answer is 2.

Sample Input 2

3 5 -4 -2

Sample Output 2

-6

The answer can be negative.

Sample Input 3

-1000000000 0 -1000000000 0

Sample Output 3

1000000000000000000


uses
sysutils, math;

var
a,b,c,d,x,t1,t2: integer;

begin

read (a);
read (b);
read(c);
read(d);

IF (b = 0) AND (c = 0) THEN
begin
	x:= a * c;
    writeln(x);
    exit;
end;

IF (a > 0) AND (c > 0) THEN
begin
	x:= b * d;
    writeln(x);
end;

IF (b < 0) AND (d < 0) THEN
begin
	x:= a * c;
    writeln(x);
    exit;
end;

IF (a < 0) AND (c < 0) THEN
begin
	x:= b * d;
    writeln(x);
    exit;
end;

IF (b < 0) OR (d < 0) THEN
begin
	x:= min(a,b) * min(c,d);
    writeln(x);
    exit;
end;

end.


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils,math;
var
	a,b,c,d		:int64;
    ans         :int64;
begin
    readln(a,b,c,d);
    ans:=max(max(a*c,a*d),max(b*c,b*d));
    writeln(stdout,ans);
end.


program test;
{$mode objfpc}{$H+}{$R-}{$S+}
Uses sysutils;
var
	N,i,j	    :integer;
    X,Y         :array [1..200000] of integer;
	tmp,ans		:integer;
begin
    readln(N);
    for i:=1 to N do if (i<N) then read(X[i],Y[i]) else readln(X[i],Y[i]);

    ans:=0;
    for i:=1 to N do
    begin
        for j:=i+1 to N do
        begin
            tmp:=ABS(X[i]-X[j])+ABS(Y[i]-Y[j]);
            if (ans<tmp) then ans:=tmp;
            tmp:=ABS(X[j]-X[i])+ABS(Y[j]-Y[i]);
            if (ans<tmp) then ans:=tmp;
        end;
    end;
    writeln(stdout,ans);
end.

Score : 500 points

Problem Statement

There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate.
What is the maximum possible Manhattan distance between two distinct points?

Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq x_i,y_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the answer.

Sample Input 1

3
1 1
2 4
3 2

Sample Output 1

4

The Manhattan distance between the first point and the second point is |1-2|+|1-4|=4, which is maximum possible.

Sample Input 2

2
1 1
1 1

Sample Output 2

0


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils;
var
	N,i,j	    :integer;
    X,Y         :array [1..200000] of integer;
	tmp,ans		:integer;
begin
    readln(N);
    for i:=1 to N do if (i<N) then read(X[i],Y[i]) else readln(X[i],Y[i]);

    ans:=0;
    for i:=1 to N-1 do
    begin
        for j:=i+1 to N do
        begin
            tmp:=ABS(X[i]-X[j])+ABS(Y[i]-Y[j]);
            if (ans<tmp) then ans:=tmp;
            tmp:=ABS(X[j]-X[i])+ABS(Y[j]-Y[i]);
            if (ans<tmp) then ans:=tmp;
        end;
    end;
    writeln(stdout,ans);
end.


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils;
var
	N,i,j	    :integer;
    X,Y         :array [1..200000] of integer;
	tmp,ans		:integer;
begin
    readln(N);
    for i:=1 to N do if (i<N) then read(X[i],Y[i]) else readln(X[i],Y[i]);

    ans:=0;
    for i:=1 to N do
    begin
        for j:=1 to N do
        begin
            if (i<>j) then
            begin
                tmp:=ABS(X[i]-X[j])+ABS(Y[i]-Y[j]);
                if (ans<tmp) then ans:=tmp;
            end;
        end;
    end;
    writeln(stdout,ans);
end.


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils;
var
	N,i		    :integer;
    X,Y         :array [1..200000] of integer;
	tmp,ans		:integer;
begin
    readln(N);
    for i:=1 to N do if (i<N) then read(X[i],Y[i]) else readln(X[i],Y[i]);

    ans:=0;
    for i:=1 to N-1 do
    begin
        tmp:=ABS(X[i]-X[i+1])+ABS(Y[i]-Y[i+1]);
        if (ans<tmp) then ans:=tmp;
    end;
    writeln(stdout,ans);
end.


var
x,y,a,b,n:integer;
c,d:integer;

begin

//mod 1000000007;

readln(n);

read(x);
readln(y);

read(a);
readln(b);

read(c);
readln(d);

x:= (x-a) + (y-b);
writeln(x);

end.


var a,b,c:Longint;
begin
    read(a,b,c);
    if a<=b*c
    then
    writeln('Yes')
    else
    writeln('No')
end.

Score : 100 points

Problem Statement

Takahashi is meeting up with Aoki.

They have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.

Takahashi will leave his house now and go straight to the place at a speed of S meters per minute.

Will he arrive in time?

Constraints

1 \leq D \leq 10000

1 \leq T \leq 10000

1 \leq S \leq 10000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

D T S

Output

If Takahashi will reach the place in time, print Yes; otherwise, print No.

Sample Input 1

1000 15 80

Sample Output 1

Yes

It takes 12.5 minutes to go 1000 meters to the place at a speed of 80 meters per minute. They have planned to meet in 15 minutes so he will arrive in time.

Sample Input 2

2000 20 100

Sample Output 2

Yes

It takes 20 minutes to go 2000 meters to the place at a speed of 100 meters per minute. They have planned to meet in 20 minutes so he will arrive just on time.

Sample Input 3

10000 1 1

Sample Output 3

No

He will be late.


uses math;
var
  n:string;
  ma,i,s:longint;
begin
  readln(n);
  for i:=1 to length(n)+1 do if n[i]='R' then inc(s) else begin ma:=max(ma,s);s:=0;end;
  writeln(ma);
end.

Score : 100 points

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.

Find the maximum number of consecutive rainy days in this period.

Constraints

|S| = 3

Each character of S is S or R.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of consecutive rainy days in the period.

Sample Input 1

RRS

Sample Output 1

2

We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.

Sample Input 2

SSS

Sample Output 2

0

It was sunny throughout the period. We had no rainy days, so we should print 0.

Sample Input 3

RSR

Sample Output 3

1

We had rain on the 1-st and 3-rd days - two "streaks" of one rainy day, so we should print 1.


program bt;

var X,K,D,a,t:int64;

begin
   readln(X,K,D);
   a:=X div D;
   t:=X mod D;
   if (k<a) then t:=t+D*(a-k);
   if (k>a) then
    begin
       if (abs(t-D) <= t) then
        begin
           t:=t-D;
           inc(a);
        end;
       if ((k-a) mod 2 <> 0) then t:=t+D;
     end;
   write(abs(t));
   readln;
end.

Score : 300 points

Problem Statement

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

More specifically, in one move, he can go from coordinate x to x + D or x - D.

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

Find the minimum possible absolute value of the coordinate of the destination.

Constraints

-10^{15} \leq X \leq 10^{15}

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

Print the minimum possible absolute value of the coordinate of the destination.

Sample Input 1

6 2 4

Sample Output 1

2

Takahashi is now at coordinate 6. It is optimal to make the following moves:

Move from coordinate 6 to (6 - 4 =) 2.

Move from coordinate 2 to (2 - 4 =) -2.

Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

Sample Input 2

7 4 3

Sample Output 2

1

Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

Here, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.


program bt;

var n,i,j,t :longint;
    a :array[1..200001] of real;

begin
   readln(n);
   for i:=1 to n do
    readln(a[i]);
   for i:=1 to n-1 do
    for j:=i+1 to n do
     if ((a[i]*a[j])=trunc(a[i]*a[j])) then inc(t);
   write(t);
   readln;
end.

Score : 300 points

Problem Statement

You are given N real values A_1, A_2, \ldots, A_N.
Compute the number of pairs of indices (i, j)
such that i < j and the product A_i \cdot A_j is integer.

Constraints

2 \leq N \leq 200\,000

0 < A_i < 10^4

A_i is given with at most 9 digits after the decimal.

Input

Input is given from Standard Input in the following format.

N
A_1
A_2
\vdots
A_N

Output

Print the number of pairs with integer product A_i \cdot A_j (and i < j).

Sample Input 1

5
7.5
2.4
17.000000001
17
16.000000000

Sample Output 1

3

There are 3 pairs with integer product:

7.5 \cdot 2.4 = 18

7.5 \cdot 16 = 120

17 \cdot 16 = 272

Sample Input 2

11
0.9
1
1
1.25
2.30000
5
70
0.000000001
9999.999999999
0.999999999
1.000000001

Sample Output 2

8


program Hello;

var n,i,j:longint;
    t : int64;
    a :array[1..200001] of longint;
begin
   readln(n);
   for i:=1 to n-1 do
    begin
       read(a[i]);
    end;
   readln(a[n]);
   for i:=1 to n-1 do
    for j:=i+1 to n do
     t:=t+((a[i]*a[j]) mod 200003);
    write(t);
    readln;
end.

Score : 800 points

Problem Statement

Let’s take a prime P = 200\,003.
You are given N integers A_1, A_2, \ldots, A_N.
Find the sum of ((A_i \cdot A_j) \bmod P) over all N \cdot (N-1) / 2 unordered pairs of elements (i < j).

Please note that the sum isn't computed modulo P.

Constraints

2 \leq N \leq 200\,000

0 \leq A_i < P = 200\,003

All values in input are integers.

Input

Input is given from Standard Input in the following format.

N
A_1 A_2 \cdots A_N

Output

Print one integer — the sum over ((A_i \cdot A_j) \bmod P).

Sample Input 1

4
2019 0 2020 200002

Sample Output 1

474287

The non-zero products are:

2019 \cdot 2020 \bmod P = 78320

2019 \cdot 200002 \bmod P = 197984

2020 \cdot 200002 \bmod P = 197983

So the answer is 0 + 78320 + 197984 + 0 + 0 + 197983 = 474287.

Sample Input 2

5
1 1 2 2 100000

Sample Output 2

600013


var x:Longint;
begin
  read(x);
  if x >= 30 then writeln('Yes')
  else writeln('No')
end.

Score : 100 points

Problem Statement

You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.

The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?

Constraints

-40 \leq X \leq 40

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print Yes if you will turn on the air conditioner; print No otherwise.

Sample Input 1

25

Sample Output 1

No

Sample Input 2

30

Sample Output 2

Yes


var x:Longint;
begin
read(x);
if x>=30 then writeln('Yes')else writeln('No');
end.


program bt;
var x:integer;
begin
   readln(x);
   if (x>=30) then write('Yes') else write('No');
   readln;
end.


var
        a,b:array[0..200005] of int64;
        i:longint;
        n,h,res:int64;
        check:real;
begin
        read(n,h);
        res:=0;
        for i:=1 to n do read(a[i],b[i]);
        for i:=1 to n do
        begin
                check:=0;
                check:=sqrt(sqr(a[i])+sqr(b[i]));
                if check<=h then inc(res);
        end;
        write(res);
end.

Score : 200 points

Problem Statement

We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i).

Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there?

We remind you that the distance between the origin and the point (p, q) can be represented as \sqrt{p^2+q^2}.

Constraints

1 \leq N \leq 2\times 10^5

0 \leq D \leq 2\times 10^5

|X_i|,|Y_i| \leq 2\times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

Print an integer representing the number of points such that the distance from the origin is at most D.

Sample Input 1

4 5
0 5
-2 4
3 4
4 -4

Sample Output 1

3

The distance between the origin and each of the given points is as follows:

\sqrt{0^2+5^2}=5

\sqrt{(-2)^2+4^2}=4.472\ldots

\sqrt{3^2+4^2}=5

\sqrt{4^2+(-4)^2}=5.656\ldots

Thus, we have three points such that the distance from the origin is at most 5.

Sample Input 2

12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669

Sample Output 3

6


program bt;

var t,n,d,i:integer;
    x,y,a:array[1..10000] of integer;

begin
   readln(n,d);
   for i:=1 to n do
    readln(x[i],y[i]);
   for i:=1 to n do
    a[i]:=trunc(sqrt(sqr(x[i])+sqr(y[i])));
   t:=0;
   for i:=1 to n do
    if (a[i]=d) then t:=t+1;
   write(t);
   readln;
end.


var N:Longint;
begin
read(N);
writeln(10-N div 200);
end.

Score: 100 points

Problem Statement

M-kun is a competitor in AtCoder, whose highest rating is X.

In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given:

From 400 through 599: 8-kyu

From 600 through 799: 7-kyu

From 800 through 999: 6-kyu

From 1000 through 1199: 5-kyu

From 1200 through 1399: 4-kyu

From 1400 through 1599: 3-kyu

From 1600 through 1799: 2-kyu

From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

400 \leq X \leq 1999

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the kyu M-kun has, as an integer.
For example, if he has 8-kyu, print 8.

Sample Input 1

725

Sample Output 1

7

M-kun's highest rating is 725, which corresponds to 7-kyu.

Thus, 7 is the correct output.

Sample Input 2

1600

Sample Output 2

2

M-kun's highest rating is 1600, which corresponds to 2-kyu.

Thus, 2 is the correct output.


program bt;

var x:integer;

begin
   readln(x);
   if (x>=400) and (x<=599) then write(8) else
   if (x>=600) and (x<=799) then write(7) else
   if (x>=800) and (x<=999) then write(6) else
   if (x>=1000) and (x<=1199) then write(5) else
   if (x>=1200) and (x<=1399) then write(4) else
   if (x>=1400) and (x<=1399) then write(3) else
   if (x>=1600) and (x<=1799) then write(2) else
   if (x>=1800) and (x<=1999) then write(1);
   readln;
end.


program bt;

var x:integer;

begin
   readln(x);
   if (x>=400) and (x<=599) then write('8') else
   if (x>=600) and (x<=799) then write('7') else
   if (x>=800) and (x<=999) then write('6') else
   if (x>=1000) and (x<=1199) then write('5') else
   if (x>=1200) and (x<=1399) then write(4) else
   if (x>=1400) and (x<=1399) then write(3) else
   if (x>=1600) and (x<=1799) then write(2) else
   if (x>=1800) and (x<=1999) then write(1);
   readln;
end.


var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.

Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

He is a genius magician who can do the following operation at most K times:

Choose one of the three cards and multiply the written integer by 2.

His magic is successful if both of the following conditions are satisfied after the operations:

The integer on the green card is strictly greater than the integer on the red card.

The integer on the blue card is strictly greater than the integer on the green card.

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

If the magic can be successful, print Yes; otherwise, print No.

Sample Input 1

7 2 5
3

Sample Output 1

Yes

The magic will be successful if, for example, he does the following operations:

First, choose the blue card. The integers on the red, green, and blue cards are now 7, 2, and 10, respectively.

Second, choose the green card. The integers on the red, green, and blue cards are now 7, 4, and 10, respectively.

Third, choose the green card. The integers on the red, green, and blue cards are now 7, 8, and 10, respectively.

Sample Input 2

7 4 2
3

Sample Output 2

No

He has no way to succeed in the magic with at most three operations.


program bt;
var a,b,c,k:integer;
begin
   readln(a,b,c);
   readln(k);
   while (b<=a) and (k>0) do
    begin
       b:=b*2;
       k:=k-1;
     end;
   while (c<=b) and (k>0) do
    begin
       c:=c*2;
       k:=k-1;
     end;
  if (b>a) and (c>b) then write('Yes') else write('No');
  readln;
 end.


program bt;

var n,k,i:longint;
    a    :array[1..200001] of longint;

begin
   readln(n,k);
   for i:=1 to n-1 do
    read(a[i]);
   readln(a[n]);
   for i:=k+1 to n do
    if (a[i]>a[i-1]) then writeln('Yes') else writeln('No');
   readln;
end.

Score: 300 points

Problem Statement

M-kun is a student in Aoki High School, where a year is divided into N terms.

There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows:

For the first through (K-1)-th terms: not given.

For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term.

M-kun scored A_i in the exam at the end of the i-th term.

For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is strictly greater than the grade for the (i-1)-th term.

Constraints

2 \leq N \leq 200000

1 \leq K \leq N-1

1 \leq A_i \leq 10^{9}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 A_3 \ldots A_N

Output

Print the answer in N-K lines.

The i-th line should contain Yes if the grade for the (K+i)-th term is greater than the grade for the (K+i-1)-th term, and No otherwise.

Sample Input 1

5 3
96 98 95 100 20

Sample Output 1

Yes
No

His grade for each term is computed as follows:

3-rd term: (96 \times 98 \times 95) = 893760

4-th term: (98 \times 95 \times 100) = 931000

5-th term: (95 \times 100 \times 20) = 190000

Sample Input 2

3 2
1001 869120 1001

Sample Output 2

No

Note that the output should be No if the grade for the 3-rd term is equal to the grade for the 2-nd term.

Sample Input 3

15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9

Sample Output 3

Yes
Yes
No
Yes
Yes
No
Yes
Yes


var
	N,i:Longint;
	p,A,T:int64;
begin
	read(N,p);
	T:=1000;
	for i:=2 to N do begin
		read(A);
		if p<A then begin
			T:=T mod p+T div p*A;
		end;
		p:=A;
	end;
	writeln(T);
end.

Score: 400 points

Problem Statement

To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.

He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:

A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.

In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.

Buy stock: Pay A_i yen and receive one stock.

Sell stock: Sell one stock for A_i yen.

What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Constraints

2 \leq N \leq 80

100 \leq A_i \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the maximum possible amount of money that M-kun can have in the end, as an integer.

Sample Input 1

7
100 130 130 130 115 115 150

Sample Output 1

1685

In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:

Initially, he has 1000 yen and no stocks.

Day 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.

Day 2: Sell 7 stocks for 910 yen. Now he has 910 yen.

Day 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.

Day 4: Do nothing.

Day 5: Buy 1 stock for 115 yen. Now he has 1185 yen.

Day 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.

Day 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.

There is no way to have 1686 yen or more in the end, so the answer is 1685.

Sample Input 2

6
200 180 160 140 120 100

Sample Output 2

1000

In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.

Sample Input 3

2
157 193

Sample Output 3

1216

In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.


var l, r, d, il, ir: integer;
begin
read(l,r,d);
writeln((r div d) - ((l - 1) div d));
end.

Score : 100 points

Problem Statement

How many multiples of d are there among the integers between L and R (inclusive)?

Constraints

All values in input are integers.

1 \leq L \leq R \leq 100

1 \leq d \leq 100

Input

Input is given from Standard Input in the following format:

L R d

Output

Print the number of multiples of d among the integers between L and R (inclusive).

Sample Input 1

5 10 2

Sample Output 1

3

Among the integers between 5 and 10, there are three multiples of 2: 6, 8, and 10.

Sample Input 2

6 20 7

Sample Output 2

2

Among the integers between 6 and 20, there are two multiples of 7: 7 and 14.

Sample Input 3

1 100 1

Sample Output 3

100


var l, r, d: integer;
begin
	readln(l,r,d);
    writeln(r/d-(l-1)/d:0:0);
end.


// program hi;
// type
//     ref = (AC, WA, TLE, RE);

// var
//     n, i: longint;
//     s: ref;
//     a: array[ref] of longint = (0, 0, 0, 0);

// begin
//     readln(n);
//     for i := 1 to n do begin
//         readln(s);
//         inc(a[s]);
//     end;
//     for s := AC to RE do
//         writeln(s, ' x ', a[s])
// end.
program sad;
const
    ref: array[1..4] of string = ('AC', 'WA', 'TLE', 'RE');

var
    n, i, j: longint;
    s: string;
    a: array[1..4] of longint = (0, 0, 0, 0);

begin
    readln(n);
    for i := 1 to n do begin
        readln(s);
        for j := 1 to 4 do
            if (s = ref[j]) then
                inc(a[j])
    end;
    for i := 1 to 4 do
        writeln(ref[i], ' x ', a[i]);
end.

Score : 200 points

Problem Statement

Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A.

The problem has N test cases.

For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively.

See the Output section for the output format.

Constraints

1 \leq N \leq 10^5

S_i is AC, WA, TLE, or RE.

Input

Input is given from Standard Input in the following format:

N
S_1
\vdots
S_N

Output

Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict is AC, WA, TLE, and RE, respectively. Print the following:

AC x C_0
WA x C_1
TLE x C_2
RE x C_3

Sample Input 1

6
AC
TLE
AC
AC
WA
TLE

Sample Output 1

AC x 3
WA x 1
TLE x 2
RE x 0

We have 3, 1, 2, and 0 test case(s) for which the verdict is AC, WA, TLE, and RE, respectively.

Sample Input 2

10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC

Sample Output 2

AC x 10
WA x 0
TLE x 0
RE x 0


program main;
var ac, wa, tle, re, i, n : integer;
    s : string;

begin
  readln(n);
  ac := 0; wa := 0; tle := 0; re := 0;
  for i := 1 to n do begin
    readln(s);
    if s = 'AC' then inc(ac)
    else if s = 'WA' then inc(wa)
    else if s = 'TLE' then inc(tle)
    else if s = 'RE' then inc(re);
  end;
  writeln('AC x ', ac);
  writeln('WA x ', wa);
  writeln('TLE x ', tle);
  writeln('RE x ', re);
end.


program main;
var
    n, i : integer;
    s : string;
    a : array[1..4] of integer;
begin
    readln(n);

    for i := 1 to 4 do
        a[i] := 0;

    for i := 1 to n do begin
        readln(s);
        if (s = 'AC') then
            a[1] := a[1] + 1
        else if (s = 'WA') then
            a[2] := a[2] + 1
        else if (s = 'TLE') then
            a[3] := a[3] + 1
        else if (s = 'RE') then
            a[4] := a[4] + 1;
    end;

    writeln('AC x ', a[1]);
    writeln('WA x ', a[2]);
    writeln('TLE x ', a[3]);
    writeln('RE x ', a[4]);
end.


program main;
var
	num, c1, c2, c3, c4, i : integer;
	result : string;
begin
	readln(num);
    c1 := 0;
    c2 := 0;
    c3 := 0;
    c4 := 0;
    for i := 1 to num do begin
    	readln(result);
        if result = 'AC'
        	then c1 := c1 + 1;
        if result = 'WA'
        	then c2 := c2 + 1;
        if result = 'TLE'
        	then c3 := c3 + 1;
        if result = 'RE'
        	then c4 := c4 + 1;
         end;
	writeln('AC x ',c1);
    writeln('WA x ',c2);
    writeln('TLE x ',c3);
    writeln('RE x ',c4);
end.


program main;
var a : integer;
begin
	readln(a);
    writeln(a + a * a + a * a * a);
end.

Score : 100 points

Problem Statement

Given an integer a as input, print the value a + a^2 + a^3.

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

Print the value a + a^2 + a^3 as an integer.

Sample Input 1

2

Sample Output 1

14

When a = 2, we have a + a^2 + a^3 = 2 + 2^2 + 2^3 = 2 + 4 + 8 = 14.

Print the answer as an input. Outputs such as 14.0 will be judged as incorrect.

Sample Input 2

10

Sample Output 2

1110


program main;
var a : integer;
begin
  readln(a);
  writeln(a+a*a+a*a*a);
end.


program main;
var n : integer;

begin
  readln(n);
  writeln(n + n*n + n*n*n);
end.


program main;
var
	num, sum : longint;

begin
	read(num);
    sum := num + (num*num) + (num*num*num);
    writeln(sum);
end.


program main;
var a : integer;
begin
	readln(a);
    writeln(a + a*a + a*a*a);
end.


program main;
var
	input:integer;
begin
	readln(input);
    writeln(input + input*input + input*input*input);
end.


program main;
var a : integer;
begin
while (a<1) and (a>10) do
readln (a);
writeln (a+a*a+a*a*a);
end.


program main;
var input:integer;
begin
	readln(input);
    writeln(input + input*input + input*input*input);
end.


program bt;

var s,t:string;
    r,i:longint;

begin
   readln(s);
   readln(t);
   r:=0;
   for i:=1 to length(s) do
    if (s[i]<>t[i]) then inc(r);
   write(r);
   readln;
end.

Score : 200 points

Problem Statement

Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.

Operation: Choose one character of S and replace it with a different character.

Constraints

S and T have lengths between 1 and 2\times 10^5 (inclusive).

S and T consists of lowercase English letters.

S and T have equal lengths.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the answer.

Sample Input 1

cupofcoffee
cupofhottea

Sample Output 1

4

We can achieve the objective in four operations, such as the following:

First, replace the sixth character c with h.

Second, replace the eighth character f with t.

Third, replace the ninth character f with t.

Fourth, replace the eleventh character e with a.

Sample Input 2

abcde
bcdea

Sample Output 2

5

Sample Input 3

apple
apple

Sample Output 3

0

No operations may be needed to achieve the objective.


program hi;
var
    s, t: string;
    i, cnt: longint;

begin
    readln(s);
    readln(t);
    cnt := 0;
    for i := 1 to length(s) do
        if s[i] <> t[i] then
            inc(cnt);
    writeln(cnt);
end.


program main;
var c : char;
begin
	readln(c);
    if(ord(c) >= 65) and (ord(c) <= 90) then
    	writeln('A')
        else if(ord(c) >= 97) and (ord(c) <= 122) then
        	writeln('a');
end.

Score : 100 points

Problem Statement

An uppercase or lowercase English letter \alpha will be given as input.
If \alpha is uppercase, print A; if it is lowercase, print a.

Constraints

\alpha is an uppercase (A - Z) or lowercase (a - z) English letter.

Input

Input is given from Standard Input in the following format:

α

Output

If \alpha is uppercase, print A; if it is lowercase, print a.

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


program alphabet;
var
    a : char;
begin
    read(a);
    if (ord(a) >= 97) and (ord(a) <= 122) then
        writeln('a')
    else
        writeln('A');
end.


program main;
var a : string;
begin
    readln(a);
    if( Upcase(a) = a ) then
        writeln('A')
    else
        writeln('a');
end.


program main;
var
    n, k, sum, min, i, j, temp : integer;
    a : array[1..1000] of integer;

begin
    readln(n, k);

    for i := 1 to n do
        read(a[i]);

    sum := 0;
    for i := 1 to k do begin
        min := i;
        for j := i + 1 to n do
            if (a[min] > a[j]) then
                min := j;

        sum := sum + a[min];
        temp := a[min];
        a[min] := a[i];
        a[i] := temp;
    end;

    writeln(sum);
end.


program main;
var
	x : char;
begin
	readln(x);
    if ((ord(x)) > 97) or ((ord(x)) = 97)
    	then writeln('a')
        	else writeln('A');
end.


program main;
var
    a, b, i, k, ans, temp : integer;
    ar : array[1..1000] of integer;
begin
    ans := 0;
    readln(a, b);
    for i := 1 to a do
        read(ar[i]);
    for i := 1 to a do
        for k := 1 to a-1 do
            if ar[k] > ar[k+1] then
                begin
                    temp := ar[k];
                    ar[k] := ar[k+1];
                    ar[k+1] := temp;
                end;
    for i := 1 to b do
        ans := ans + ar[i];
    writeln(ans);
end.

Score : 200 points

Problem Statement

A shop sells N kinds of fruits, Fruit 1, \ldots, N, at prices of p_1, \ldots, p_N yen per item, respectively. (Yen is the currency of Japan.)

Here, we will choose K kinds of fruits and buy one of each chosen kind. Find the minimum possible total price of those fruits.

Constraints

1 \leq K \leq N \leq 1000

1 \leq p_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 p_2 \ldots p_N

Output

Print an integer representing the minimum possible total price of fruits.

Sample Input 1

5 3
50 100 80 120 80

Sample Output 1

210

This shop sells Fruit 1, 2, 3, 4, and 5 for 50 yen, 100 yen, 80 yen, 120 yen, and 80 yen, respectively.

The minimum total price for three kinds of fruits is 50 + 80 + 80 = 210 yen when choosing Fruit 1, 3, and 5.

Sample Input 2

1 1
1000

Sample Output 2

1000


program main;
var
    n, k, sum, i: integer;
    a : array[1..1000] of integer;

procedure qs (l, r : integer);
var
    p, i, j, temp : integer;
begin
    p := a[(l + r) div 2]; i := l; j := r;

    while (i < j) do begin
        while (a[j] > p) do
            j := j - 1;
        while (a[i] < p) do
            i := i + 1;

        if (i < j) then begin
            temp := a[i];
            a[i] := a[j];
            a[j] := temp;
            j := j - 1;
            i := i + 1;
        end;
    end;

    if (l - r > 1) then begin
        qs(l, j);
        qs(i, r);
    end;
end;

begin
    readln(n, k);

    for i := 1 to n do
        read(a[i]);

    qs(1, n);

    sum := 0;
    for i := 1 to k do
        sum := sum + a[i];

    writeln(sum);
end.


var
	n,b,i:int64;
    a:Array[1..200000] of int64;
begin
	read(n);
    for i:=1 to n do begin
    	read(a[i]);
        b:=b xor a[i];
    end;
    for i:=1 to n do begin
    	writeln(b xor a[i]);
    end;
end.

Score : 500 points

Problem Statement

There are N Snuke Cats numbered 1, 2, \ldots, N, where N is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For n non-negative integers x_1, x_2, \ldots, x_n, their xor, x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is defined as follows:

When x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3~\textrm{xor}~5 = 6.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat i, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat i is a_i.
Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

All values in input are integers.

2 \leq N \leq 200000

N is even.

0 \leq a_i \leq 10^9

There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

The i-th of the integers from the left should represent the integer written on the scarf of Snuke Cat i.

If there are multiple possible solutions, you may print any of them.

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

5~\textrm{xor}~7~\textrm{xor}~22 = 20

26~\textrm{xor}~7~\textrm{xor}~22 = 11

26~\textrm{xor}~5~\textrm{xor}~22 = 9

26~\textrm{xor}~5~\textrm{xor}~7 = 24

Thus, this output is consistent with the given information.


var
  x, i :Longint;
begin
  read(x);
  i := 360;
  while true do begin
    if i mod x = 0 then begin
      writeln(i div x);
      exit;
    end;
    i += 360;
  end;
end.

Score : 200 points

Problem Statement

Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times:

Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise.

Constraints

1 \leq X \leq 179

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of times Takahashi will do the action before he is at the starting position again.

Sample Input 1

90

Sample Output 1

4

Takahashi's path is a square.

Sample Input 2

1

Sample Output 2

360


var N:Longint;
function gcd(a,b:Longint):Longint;
begin
if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
begin
read(N);
writeln(360 div gcd(360,N));
end.


program main;
var x : array[1..5] of integer;
	i,n : integer;
begin
	for i := 1 to 5 do begin
    	readln(x[i]);
    end;
    if(x[1] = 0)
    	then n := 1
        else if(x[2] = 0)
    		then n := 2
            else if(x[3] = 0)
    			 then n := 3
                 else if(x[4] = 0)
    			 	then n := 4
                    else if(x[5] = 0)
    			 		then n := 5;
    writeln(n);
end.

Score : 100 points

Problem Statement

We have five variables x_1, x_2, x_3, x_4, and x_5.

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

You are given the values of the five variables after this assignment.

Find out which variable Snuke assigned 0.

Constraints

The values of x_1, x_2, x_3, x_4, and x_5 given as input are a possible outcome of the assignment by Snuke.

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

If the variable Snuke assigned 0 was x_i, print the integer i.

Sample Input 1

0 2 3 4 5

Sample Output 1

1

In this case, Snuke assigned 0 to x_1, so we should print 1.

Sample Input 2

1 2 0 4 5

Sample Output 2

3


program main;
var x : array[1..5] of integer;
	i,n : integer;
begin
	for i := 1 to 5 do begin
    	readln(x[i]);
        if(x[i] = 0) then
        	n := i;
    end;
    writeln(n);
end.


program main;
var a,b,c,d,e : integer;
begin
    readln(a,b,c,d,e);
    if a = 0 then
        writeln('1');
    if b = 0 then
        writeln('2');
    if c = 0 then
        writeln('3');
    if d = 0 then
        writeln('4');
    if e = 0 then
        writeln('5');
end.


var a,s,d,f,g:longint;
begin
read(a,s,d,f,g);
writeln(15-a-s-d-f-g);
end.


program main;
var x, y, a, b : longint;
    t : real;
    r : boolean;

begin
  readln(x,y);
  r := true;
  t := (y-2*x) / 2;
  if (frac(t) = 0) and (t >= 0) then
    b := trunc(t)
  else
    r := false;
  a := x - b;
  if a < 0 then
    r := false;
  if r then
    writeln('Yes')
  else
    writeln('No');
end.


program main;
var
	i, num :integer;
    a : array[1..5] of integer;
begin

	for i := 1 to 5 do begin
    	read(a[i]);
        if a[i] = 0
        	then num := i;
    end;
    writeln(num);
end.


Score : 200 points

Problem Statement

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Constraints

1 \leq X \leq 100

1 \leq Y \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

Sample Input 1

3 8

Sample Output 1

Yes

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Sample Input 2

2 100

Sample Output 2

No

There is no combination of numbers of cranes and turtles in which this statement is correct.

Sample Input 3

1 2

Sample Output 3

Yes

We also consider the case in which there are only cranes or only turtles.


program main;
var x, y, a, b : longint;
    r : boolean;

begin
  readln(x,y);
  r := true;
  if frac((y-2*x) / 2) = 0 then
    b := (y-2*x) div 2
  else
    r := false;
  if r then
    a := x-b;
  if a < 0 then
    r := false;
  if r then
    writeln('Yes')
  else
    writeln('No');
end.


program hi;
var x, y: integer;

begin
    readln(x, y);
    if (x * 4 < y) or (x * 2 > y) or (y mod 2 = 1) then
        writeln('No')
    else
        writeln('Yes');
end.


var x,n,i:longint;
a:array[1..100]of longint;
function f(t:longint):Boolean;
var j,c:longint;
begin
c:=0;
for j:=1 to n do if a[j]=t then inc(c);
f:=c=0;
end;
begin
read(x,n);
for i:=1 to n do read(a[i]);
for i:=0 to 111 do begin
if f(x-i)then begin
writeln(x-i);
exit;
end;
if f(x+i)then begin
writeln(x+i);
exit;
end;
end;
end.

Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.


var a,b,v,w,t: longint; x:real;
begin
readln(a,v);
readln(b,w);
readln(t);
if w>=v then begin writeln('NO'); exit end;
x:=(b*v-a*w)/(v-w);
x:=(x-a)/v;
if x>t then begin writeln('NO'); exit end;
writeln('YES')
end.

Score : 200 points

Problem Statement

Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second.
The other child is now at coordinate B, and she can travel the distance of W per second.

He can catch her when his coordinate is the same as hers.
Determine whether he can catch her within T seconds (including exactly T seconds later).
We assume that both children move optimally.

Constraints

-10^9 \leq A,B \leq 10^9

1 \leq V,W \leq 10^9

1 \leq T \leq 10^9

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

If "it" can catch the other child, print YES; otherwise, print NO.

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO


program main;
var a,b : integer;
begin
    readln(a,b);
    writeln(a*b);
end.

Score : 100 points

Problem Statement

Compute A \times B.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Sample Input 1

2 5

Sample Output 1

10

We have 2 \times 5 = 10.

Sample Input 2

100 100

Sample Output 2

10000


program main;
var i, n : int64;
    m : array [1..10000] of longint;
    p : qword = 1;
    c : boolean = false;
    z : boolean = false;

begin
  readln(n);
  for i := 1 to n do
    read(m[i]);
  readln;
  for i := 1 to n do
    if (m[i] = 0) then begin
      z := true;
      break;
    end;
  if not(z) then
    for i := 1 to n do
      if p*m[i] > 1e18 then begin
        c := true;
        break;
      end
      else p := p * m[i];
  if z then
    writeln(p-p)
  else if c then
    writeln('-1')
  else writeln(p);
end.


program main;
var i, n, p, t : int64;

begin
  readln(n);
  p := 1;
  for i := 1 to n do begin
    read(t);
    p := p * t;
  end;
  readln;
  if p > 1000000000000000000 then
    writeln('-1')
  else writeln(p);
end.


program main;
var a, b : integer;

begin
  readln(a,b);
  writeln(a*b);
end.


program main;
var
    x, y : integer;
begin
    readln(x, y);
    writeln(x*y);
end.


program main;
var
	s : string;
    len : integer;

begin
	read(s);
    len := length(s);

    if (s[len]='2') or (s[len]='4') or (s[len]='5') or (s[len]='7') or (s[len]='9')
        	then writeln('hon');
        if (s[len]='0') or (s[len]='1') or (s[len]='6') or (s[len]='8')
        	then writeln('pon');
        if s[len]='3'
        	then writeln('bon');
end.

Score: 100 points

Problem Statement

The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese.

When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a positive integer N not exceeding 999 is as follows:

hon when the digit in the one's place of N is 2, 4, 5, 7, or 9;

pon when the digit in the one's place of N is 0, 1, 6 or 8;

bon when the digit in the one's place of N is 3.

Given N, print the pronunciation of "本" in the phrase "N 本".

Constraints

N is a positive integer not exceeding 999.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

16

Sample Output 1

pon

The digit in the one's place of 16 is 6, so the "本" in "16 本" is pronounced pon.

Sample Input 2

2

Sample Output 2

hon

Sample Input 3

183

Sample Output 3

bon


program main;
var
	s : string;
    len : integer;

begin
	read(s);
    len := length(s);

    if (s[len]='2') or (s[len]='4') or (s[len]='5') or (s[len]='7') or (s[len]='9')
        	then writeln('hon');
        if (s[len]='0') or (s[len]='1') or (s[len]='6') or (s[len]='8')
        	then writeln('pon');
        if s[len]='3'
        	then writeln('hon');
end.


program main;
var
	s : string;
    len : integer;

begin
	read(s);
    len := length(s);

    if (s[len]='2') or (s[len]='4') or (s[len]='5') or (s[len]='7') or (s[len]='9')
        	then writeln('hon');
        if (s[len]='0') or (s[len]='1') or (s[len]='6') or (s[len]='8')
        	then writeln('pon');
        if s[len]='0'
        	then writeln('hon');
end.


program main;
var
	s : string;
    len : integer;

begin
	read(s);
    len := length(s);

    if (s[len]='2') or (s[len]='4') or (s[len]='5') or (s[len]='7') or (s[len]='9')
        	then writeln('hon');
        if (s[len]='0') or (s[len]='1') or (s[len]='6') or (s[len]='8')
        	then writeln('pon')
        		else writeln('hon');
end.


var
	s:string;
begin
	readln(s);
	if s[length(s)]='3' then
    	writeln('pon')
    else if pos(s[length(s)],'24579')<>0 then
    	writeln('hon')
    else writeln('bon');
end.


var
  n: Integer;

begin
  read(n);

  case n mod 10 of

    2, 4, 5, 7, 9:
      writeln('hon');

    0, 1, 6, 8:
      writeln('pon');
  else
    writeln('bon');
  end;

end.


var
  n: Integer;

begin
  read(n);

  case n mod 10 of
    3:
      writeln('bon');
    0, 1, 6, 8:
      writeln('pon');
  else
    writeln('hon');
  end;

end.


var
  n, digits: Integer;
  measure: String;

begin
  read(n);
  digits := n;

  digits := digits mod 10;

  if (digits = 0) or (digits = 1) or (digits = 6) or (digits = 8) then
  begin
    measure := 'pon';
  end

  else if digits = 3 then
  begin
    measure := 'bon';
  end

  else
  begin
    measure := 'hon';
  end;

  write(measure);

end.


Var     st:ansistring;
i,j,n:longint;
begin
readln(st);
If st[length(st)] in ['2','4','5','7','9'] then writeln('hon')
else if st[length(st)] in ['0','1','6','8'] then writeln('pon')
else writeln('bon');
end.


Var     st:ansistring;
i,j,n:longint;
begin
readln(st);
If st[1] in ['2','4','5','7','9'] then writeln('hon')
else if st[1] in ['0','1','6','8'] then writeln('pon')
else writeln('bon');
end.


program dots;
var
    k : longint;
    s : string;
begin
    readln(k);
    readln(s);
    if length(s) > k then begin
        s := copy(s, 1, k);
        writeln(s,'...');
    end
    else
        writeln(s);
end.

Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result.

Constraints

K is an integer between 1 and 100 (inclusive).

S is a string consisting of lowercase English letters.

The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

nikoandsolstice has a length of 15, which exceeds K=7.

We should extract the first 7 characters in this string, append ... to the end of them, and print the result nikoand....

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.


program main;
var
	num, i, len : integer;
	s : string;

begin
	readln(num);
    readln(s);
    len := length(s);
    for i := 1 to num do
    	write(s[i]);
    if len > num
    	then write('...');
end.


program main;
var
	num, i, len : integer;
	s : string;

begin
	readln(num);
    readln(s);
    len := length(s);
    for i := 1 to num do
    	write(s[i]);
    if i < len
    	then write('...');
end.


var
  k: Integer;
  s: String;
  dots: String;

begin

  readln(k);
  readln(s);

  dots := '...';

  if length(s)>k then
  begin
    s := Copy(s,0,k) + dots;
  end;

  writeln(s);

end.


Var     st:ansistring;
i,j,k,n:longint;
begin
readln(n);readln(st);
if length(st)>n then begin delete(st,n+1,length(st)-n);writeln(st,'...');end
else writeln(st);
end.


{$APPTYPE CONSOLE}

var
  a, b, h, m: Integer;
  rad_h, rad_m: Double;
  x_h, y_h, x_m, y_m: Double;
  answer: Double;

begin
  read(a);
  read(b);
  read(h);
  read(m);

  rad_h := 2 * Pi * (h / 12) + (2 * Pi * (m / 60) * 1/12);
  rad_m := 2 * Pi * (m / 60);

  x_h := Cos(rad_h) * a;
  y_h := Sin(rad_h) * a;

  x_m := Cos(rad_m) * b;
  y_m := Sin(rad_m) * b;

  answer := Sqrt(Sqr(x_h - x_m) + Sqr(y_h - y_m));

  writeln(answer);
end.

Score: 300 points

Problem Statement

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.


Uses    crt,math;
Var     a,b,h,m,i,j,k,n:longint;
angle1,angle2,res:extended;
st:string;
begin
clrscr;
readln(a,b,h,m);
angle1:=0.5*(h*60+m);
angle2:=6*m;
angle1:=abs(angle1-angle2);
angle1:=min(360-angle1,angle1);
writeln(sqrt(a*a+b*b-2*a*b*cos((angle1)/180*pi)):0:20);
end.


Uses    crt,math;
Var     a,b,h,m,i,j,k,n:longint;
angle1,angle2,res:extended;
st:string;
begin
clrscr;
readln(a,b,h,m);
angle1:=(m/60)*360;
If angle1<180 then angle1:=360-angle1;
angle2:=((m/60+h)/12)*360;
angle1:=abs(angle1-angle2);
res:=3.14159265358979323846264;
writeln(sqrt(a*a+b*b-2*a*b*cos((angle1)/180*res)):0:18);
end.


program main;
var
    s1, s2 : string;
    pass : boolean;
begin
    pass := true;
    readln(s1);
    readln(s2);
    if length(s1) > 10
        then pass := false;
    if length(s2) - length(s1) <> 1
        then pass := false;
    s2 := copy(s2, 1, length(s2)-1);
    if s1 <> s2
        then pass := false;
    if pass
        then writeln('Yes')
        else writeln('No');
end.

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

He tried to register himself with the ID S, which turned out to be already used by another user.

Thus, he decides to register using a string obtained by appending one character at the end of S as his ID.

He is now trying to register with the ID T. Determine whether this string satisfies the property above.

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

If T satisfies the property in Problem Statement, print Yes; otherwise, print No.

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

chokudaiz can be obtained by appending z at the end of chokudai.

Sample Input 2

snuke
snekee

Sample Output 2

No

snekee cannot be obtained by appending one character at the end of snuke.

Sample Input 3

a
aa

Sample Output 3

Yes


program main;
var
	s, t : string;
    count, i, len : integer;
begin
	readln(s);
	readln(t);
    len := length(t);
    count := 0;
    for i := 1 to len do begin
    	if s[i] <> t[i]
        	then count := count + 1;
    end;
    if count <> 1
    	then writeln('No')
        	else writeln('Yes');
end.


var s,t:String;i,j:Longint;
begin
readln(s);
readln(t);
for i:=1 to length(s)do if s[i]<>t[i]then inc(j);
if j=0 then writeln('Yes')else writeln('No');
end.


program main;
var
    a, b, c, d, sum : int64;
begin
    sum := 0;
    readln(a, b, c, d);
    if d < a
        then sum := sum + d
        else begin
            sum := sum + a;
            d := d - a -b;
            if d > 0
                then sum := sum - d;
        end;
    writeln(sum);
end.

Score : 200 points

Problem Statement

We have A cards, each of which has an integer 1 written on it. Similarly, we also have B cards with 0s and C cards with -1s.

We will pick up K among these cards. What is the maximum possible sum of the numbers written on the cards chosen?

Constraints

All values in input are integers.

0 \leq A, B, C

1 \leq K \leq A + B + C \leq 2 \times 10^9

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the maximum possible sum of the numbers written on the cards chosen.

Sample Input 1

2 1 1 3

Sample Output 1

2

Consider picking up two cards with 1s and one card with a 0.
In this case, the sum of the numbers written on the cards is 2, which is the maximum possible value.

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


program main;
var
    a, b, c, d, sum : int64;
begin
    sum := 0;
    readln(a, b, c, d);
    sum := sum + a;
    d := d - a -b;
    if d > 0
        then sum := sum - d;
    writeln(sum);
end.


program main;
var
    a, b, c, d, sum : int64;
begin
    sum := 0;
    readln(a, b, c, d);
    if d < a
        then sum := sum + a
        else begin
            sum := sum + a;
            d := d - a -b;
            if d > 0
                then sum := sum -d;
        end;
    writeln(sum);
end.


Score : 300 points

Problem

Takahashi, who is a novice in competitive programming, wants to learn M algorithms.
Initially, his understanding level of each of the M algorithms is 0.

Takahashi is visiting a bookstore, where he finds N books on algorithms.
The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M).
There is no other way to increase the understanding levels of the algorithms.

Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Constraints

All values in input are integers.

1\leq N, M\leq 12

1\leq X\leq 10^5

1\leq C_i \leq 10^5

0\leq A_{i, j} \leq 10^5

Input

Input is given from Standard Input in the following format:

N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{N,M}

Output

If the objective is not achievable, print -1; otherwise, print the minimum amount of money needed to achieve it.

Sample Input 1

3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

Sample Output 1

120

Buying the second and third books makes his understanding levels of all the algorithms 10 or higher, at the minimum cost possible.

Sample Input 2

3 3 10
100 3 1 4
100 1 5 9
100 2 6 5

Sample Output 2

-1

Buying all the books is still not enough to make his understanding levels of all the algorithms 10 or higher.

Sample Input 3

8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2

Sample Output 3

1067


program AC;var x : string;begin readln(x);if x = 'ABC'then writeln('ARC')else writeln('ABC')end.

Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

There are two types of contests called ABC and ARC, and just one of them is held at a time.

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

Print the string representing the type of the contest held this week.

Sample Input 1

ABC

Sample Output 1

ARC

They held an ABC last week, so they will hold an ARC this week.


program main;
var
    s : string;
begin
    readln(s);
    if s = 'ABC'
        then writeln('ARC');
    if s = 'ARC'
        then writeln('ABC');
end.


var s:String;
begin
readln(s);
if s='ABC'then writeln('ARC')else writeln('ABC');
end.


var
 s:string[3];//省空间
begin
 readln(s);//读入s
 write('A');//先输出前一个字母
 if s[2]='B' then write('R')//如果为B，输出R
             else write('B');//否则输出B
 write('C');//输出最后一个
end.


var N,K,i,c,j,a:Longint;
ex:Array[1..100]of Boolean;
begin
read(N,K);
for i:=1 to K do begin
read(c);
for j:=1 to c do begin
read(a);
if not ex[a]then begin
ex[a]:=True;
dec(N);
end;
end;
end;
writeln(N);
end.

Score : 200 points

Problem Statement

N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town.

There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}.

Takahashi will walk around this town and make mischief on the Snukes who have no snacks. How many Snukes will fall victim to Takahashi's mischief?

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 100

1 \leq d_i \leq N

1 \leq A_{i, 1} < \cdots < A_{i, d_i} \leq N

Input

Input is given from Standard Input in the following format:

N K
d_1
A_{1, 1} \cdots A_{1, d_1}
\vdots
d_K
A_{K, 1} \cdots A_{K, d_K}

Output

Print the answer.

Sample Input 1

3 2
2
1 3
1
3

Sample Output 1

1

Snuke 1 has Snack 1.

Snuke 2 has no snacks.

Snuke 3 has Snack 1 and 2.

Thus, there will be one victim: Snuke 2.

Sample Input 2

3 3
1
3
1
3
1
3

Sample Output 2

2


program main;
var
    n, up, low : integer;
begin
    readln(n);
    readln(low, up);

    if ((up div n) > ((low - 1) div n)) then
        writeln ('OK')
    else
        writeln ('NG');
end.

Score: 100 points

Problem Statement

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

If he can achieve the objective, print OK; if he cannot, print NG.

Constraints

All values in input are integers.

1 \leq A \leq B \leq 1000

1 \leq K \leq 1000

Input

Input is given from Standard Input in the following format:

K
A B

Output

If he can achieve the objective, print OK; if he cannot, print NG.

Sample Input 1

7
500 600

Sample Output 1

OK

Among the multiples of 7, for example, 567 lies between 500 and 600.

Sample Input 2

4
5 7

Sample Output 2

NG

No multiple of 4 lies between 5 and 7.

Sample Input 3

1
11 11

Sample Output 3

OK


var k,a,b:longint;
begin
  readln(k,a,b);
  for a:=a to b do
    if a mod k=0 then
    begin
      writeln('OK');
      halt;
    end;
  writeln('NG');
end.


program main;
var x, amount, year : Int64;
begin
    readln(X);

    amount := 100;
    year := 0;
    while amount < x do begin
        amount := amount + (amount div 100);
        year := year + 1;
    end;

    writeln(year);
end.

Score : 200 points

Problem Statement

Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.

The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)

Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Constraints

101 \le X \le 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.

Sample Input 1

103

Sample Output 1

3

The balance after one year is 101 yen.

The balance after two years is 102 yen.

The balance after three years is 103 yen.

Thus, it takes three years for the balance to reach 103 yen or above.

Sample Input 2

1000000000000000000

Sample Output 2

3760

Sample Input 3

1333333333

Sample Output 3

1706


program onepercent;
var
    x : int64;
    counter : longint;

function power(a, b : real) : real;
var time, z : real;
begin
    time := 0;
    z := a;
    while time <> b do begin
        a := a * z;
        time += 1;
    end;
    power := a;
end;

function compound(count : real) : real;
const yen = 100;
begin
    compound := yen * power(1 + 0.01, count);
end;

begin
    readln(x);
    counter := 0;
    while not(compound(counter) >= x) do begin
        writeln(compound(counter));
        counter += 1;
    end;
    writeln(counter + 1);
end.


program main;
var X, amount, year : Int64;
begin
  readln(X);

  amount := 100;
  year := 0;
  while amount < X do begin
    amount := trunc(amount * 1.01);
    year := year + 1;
  end;

  writeln(year);
end.


program main;
var
    n, m, i : int64;
begin
    readln(n);

    m := 100; i := 0;
    while (m < n) do begin
        i += 1;
        m := trunc(m * 1.01);
    end;

    writeln(i);
end.


program main;
var
    yr : integer;
    target, bal : int64;
begin
    yr := 0;
    bal := 100;
    readln(target);
    while bal < target do begin
        bal := trunc(bal*1.01);
        yr := yr + 1;
        if bal >= target
            then writeln(yr);;
    end;
end.


uses math;
var
	i,tar,save : int64;
begin
	readln(tar);
	save:=100;
    i:=0;
    while save<tar do begin
    	save:=floor(save*1.01);
        inc(i);
    end;
    writeln(i);
end.


uses math;
var
	x:integer;
begin
	readln(x);
	writeln(log10(x/100)/log10(1.01):0:0)
end.


var s,i,x:int64;
begin
 readln(x);
 s:=100;
 while   s<x do
 begin
  s:=s+trunc((s*1)/100);
  i:=i+1;
 end;
 write(i);
end.


program hihi;
var s, w : integer;
begin
	readln(s, w);
    if w>=s then writeln('unsafe')
    else writeln('safe');
end.

Score : 100 points

Problem Statement

There are S sheep and W wolves.

If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

Constraints

1 \leq S \leq 100

1 \leq W \leq 100

Input

Input is given from Standard Input in the following format:

S W

Output

If the wolves will attack the sheep, print unsafe; otherwise, print safe.

Sample Input 1

4 5

Sample Output 1

unsafe

There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.

Sample Input 2

100 2

Sample Output 2

safe

Many a sheep drive away two wolves.

Sample Input 3

10 10

Sample Output 3

unsafe


program main;
type
    arraytype = array[1..200000] of string[10];
var
    i, n, count : longint;
    A : arraytype;

procedure Quicksort(var A : arraytype; left, right : integer);
var
   i, j : integer;
   pivot, temp : string;
begin
    i := left;
    j := right;
    pivot := A[(left + right) div 2];
    while i <= j do begin
        while A[i] < pivot do
            i := i + 1;
        while A[j] > pivot do
            j := j - 1;
        if i <= j then begin
            temp := A[i];
            A[i] := A[j];
            A[j] := temp;
            i := i + 1;
            j := j - 1;
        end;
    end;
    if left < j
        then Quicksort(A, left, j);
    if i < right
        then Quicksort(A, i, right);
end;

begin
    //read
    readln(n);
    for i := 1 to n do
        readln(A[i]);

    //sort
    Quicksort(A, 1, n);

    //count
    count := 1;
    for i := 2 to n do
       if A[i] <> A[i-1]
           then count := count + 1;
    writeln(count);
end.


program main;
var s, w : integer;
begin
	readln(s, w);
    if w >= s
        then writeln('unsafe')
        else writeln('safe');
end.


program saw;
var
    s, w : longint;
begin
    readln(s,w);
    if (s > w) then writeln('safe')
        else writeln('unsafe');
end.


program main;

var
	n, m : integer;

begin
	readln(n, m);
    if m >= n then
    	writeln('unsafe')
    else
    	writeln('safe');
end.


uses StrUtils;
var
  a, b: integer;
begin
  read(a);
  read(b);
  writeln(ifThen(a > b, 'safe', 'unsafe'));
end.


var a,b:Longint;
begin
read(a,b);
if a>b then writeln('safe')else writeln('unsafe');
end.


program main;
var
    n, i, ans : integer;
    prev : string;
    a : array[1..200000] of string;

procedure qs(l, r : integer);
var
    i, j : integer;
    p, temp : string;
begin
    if (l <= r) then begin
        i := l; j := l; p := a[r];
        while (i < r) do begin
            if (a[i] <= p) then begin
                temp := a[i];
                a[i] := a[j];
                a[j] := temp;
                j := j + 1;
            end;
            i := i + 1;
        end;
        temp := a[j];
        a[j] := a[r];
        a[r] := temp;

        qs(l, j - 1);
        qs(j + 1, r);
    end;
end;

begin
    readln(n);
    for i := 1 to n do
        readln(a[i]);

    qs(1, n);

    prev := a[1]; ans := 1;
    for i := 2 to n do
        if (a[i] <> prev) then begin
            ans := ans + 1;
            prev := a[i];
        end;

    writeln(ans);
end.

Score : 300 points

Problem Statement

You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.

How many kinds of items did you get?

Constraints

1 \leq N \leq 2\times 10^5

S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print the number of kinds of items you got.

Sample Input 1

3
apple
orange
apple

Sample Output 1

2

You got two kinds of items: apple and orange.

Sample Input 2

5
grape
grape
grape
grape
grape

Sample Output 2

1

Sample Input 3

4
aaaa
a
aaa
aa

Sample Output 3

4


program main;
var
    n, i, ans : integer;
    prev : string;
    a : array[1..200000] of string;

procedure qs(l, r : longint);
var
    i, j : longint;
    p, temp : string;
begin
    if (l <= r) then begin
        i := l; j := l; p := a[r];
        while (i < r) do begin
            if (a[i] <= p) then begin
                temp := a[i];
                a[i] := a[j];
                a[j] := temp;
                j := j + 1;
            end;
            i := i + 1;
        end;
        temp := a[j];
        a[j] := a[r];
        a[r] := temp;

        qs(l, j - 1);
        qs(j + 1, r);
    end;
end;

begin
    readln(n);
    for i := 1 to n do
        readln(a[i]);

    qs(1, n);

    prev := a[1]; ans := 1;
    for i := 2 to n do
        if (a[i] <> prev) then begin
            ans := ans + 1;
            prev := a[i];
        end;

    writeln(ans);
end.


program train;
var
    a : array[1..200000] of string;
    i, j, count, n : integer;
    b : array[1..200000] of integer;
begin
    readln(n);
    count := 0;
    for i := 1 to n do begin
        readln(a[i]);
        b[i] := 1;
        end;
    for i := 1 to n do
        for j := i+1 to n do
            if b[i] <> 0
                then if a[i] = a[j]
                    then b[j] := 0;
    for i := 1 to n do
        count := count + b[i];
    write(count);
end.


program train;
var
    a : array[1..200000] of string;
    i, j, count, n : integer;
    b : array[1..200000] of integer;
begin
    readln(n);
    count := 0;
    for i := 1 to n do begin
        readln(a[i]);
        b[i] := 1;
        end;
    for i := 1 to n do
        for j := i+1 to n do
            if b[j] <> 0
                then if a[i] = a[j]
                    then b[j] := 0;
    for i := 1 to n do
        count := count + b[i];
    write(count);
end.


program train;
var
    a : array[1..200000] of string;
    i, j, count, n : integer;
    b : array[1..200000] of integer;
begin
    readln(n);
    count := 0;
    for i := 1 to n do begin
        readln(a[i]);
        b[i] := 1;
        end;
    for i := 1 to n do
        for j := i+1 to n do
            if a[i] = a[j]
                then b[j] := 0;
    for i := 1 to n do
        count := count + b[i];
    write(count);
end.


program main;
type
    ar = array [1..200000] of string;
var n,i,c : longint;
    a : ar;
procedure QuickSort(var A : ar; left,right : longint);
var i,j : longint;
    p,temp : string;
begin
    i := left;
    j := right;
    p := A[(left + right) div 2];
    while i <= j do begin
        while A[i] < p do
            inc(i);
        while A[j] > p do
            dec(j);
        if i <= j then begin
            temp := A[i];
            A[i] := A[j];
            A[j] := temp;
            inc(i);
            dec(j);
        end;
    end;
    if left < j
        then QuickSort(A, left, j);
    if right > i
        then QuickSort(A, i, right);
end;

begin
    c := 1;
    readln(n);
    for i := 1 to n do
        readln(a[i]);
    QuickSort(a, 1, n);
    for i := 2 to n do
        if a[i] > a[i-1]
        then inc(c);
    writeln(c);
end.


program hi;
type ars = array[1..200000] of string;
var
    n, i, cnt: longint;
    a, tmp: ars;

procedure merge(var a, tmp: ars; l, m, r: longint);
var i, i1, i2: longint;
begin
    i := l; i1 := l; i2 := m + 1;
    while (i1 <= m) and (i2 <= r) do begin
        if a[i1] <= a[i2] then begin
            tmp[i] := a[i1];
            inc(i1);
        end else begin
            tmp[i] := a[i2];
            inc(i2);
        end;
        inc(i);
    end;
    if i1 <= m then
        while i1 <= m do begin
            tmp[i] := a[i1];
            inc(i1); inc(i);
        end
    else
        while i2 <= r do begin
            tmp[i] := a[i2];
            inc(i2); inc(i);
        end;
    for i := l to r do
        a[i] := tmp[i];
end;

procedure mSort(var a, tmp: ars; l, r: longint);
var m: longint;
begin
    if l < r then begin
        m := (l + r) div 2;
        mSort(a, tmp, l, m);
        mSort(a, tmp, m + 1, r);
        merge(a, tmp, l, m, r);
    end;
end;

begin
    readln(n);
    for i := 1 to n do
        readln(a[i]);
    mSort(a, tmp, 1, n);
    cnt := 1;
    for i := 1 to n - 1 do
        if a[i] <> a[i + 1] then
            inc(cnt);
    writeln(cnt);
end.


program gacha;
type
    arr = array[1..200000] of string;

var
    n, i, count : longint;
    list : arr;

procedure swap(var x: string; var y: string);
var tmp: string;
begin
    tmp := x;
    x := y;
    y := tmp;
end;

procedure quicksort(var x: arr; left, right: longint);
var
    i, j: integer;
    k: string;

begin
    i := left;
    j := right;
    k := x[(left + right) div 2];
    while i <= j do begin
        while x[i] < k do
            inc(i);
        while x[j] > k do
            dec(j);
        if i <= j then begin
            swap(x[i], x[j]);
            inc(i);
            dec(j);
        end;
    end;
    if left < j then
        quicksort(x, left, j);
    if right > i then
        quicksort(x, i, right);
end;

begin
    readln(n);
    for i := 1 to n do
        readln(list[i]);
    quicksort(list, 1, n);
    count := 1;
    for i := 2 to n do begin
        if list[i - 1] <> list[i] then
            inc(count);
    end;
    writeln(count);
end.


program main;
type
    arraytype = array[1..200000] of string[10];
var
    i, n, count : longint;
    A : arraytype;

procedure Quicksort(var A : arraytype; left, right : integer);
var
   i, j : integer;
   pivot, temp : string;
begin
    i := left;
    j := right;
    pivot := A[(left + right) div 2];
    while i <= j do begin
        while A[i] < pivot do
            i := i + 1;
        while A[j] > pivot do
            j := j - 1;
        if i <= j then begin
            temp := A[i];
            A[i] := A[j];
            A[j] := temp;
            i := i + 1;
            j := j - 1;
        end;
    end;
    if left < j
        then Quicksort(A, left, j);
    if i < right
        then Quicksort(A, i, right);
end;

begin
    //read
    readln(n);
    for i := 1 to n do
        readln(A[i]);

    //sort
    Quicksort(A, 1, n);

    //count
    count := 1;
    writeln(n);
    for i := 2 to n do
       if A[i] <> A[i-1]
           then count := count + 1;
end.


program main;
var
  n, cnt, i, j : LongInt;
  found : boolean;
  x : string;
  s : array[1..200000] of string;
begin
  readln(n);

  cnt := 0;
  for i := 1 to n do begin
    readln(x);

    // find x in array of s
    found := false;
    for j := 1 to cnt do
      if s[j] = x then
        found := true;

    // if cannot find x, then inc cnt and add x to s
    if not found then begin
      cnt := cnt + 1;
      s[cnt] := x;
    end;
  end;

  writeln(cnt);
end.


program main;
var n,i,j,c : integer;
    a : array[1..10000] of string;
    t : boolean;
begin
    c := 0;
    t := true;
    readln(n);
    for i := 1 to n do begin
        readln(a[i]);
        if i > 1 then
        for j := 1 to i-1 do
            if a[i] = a[j]
            then t := false;
        if t = true
        then inc(c)
        else t:=true;
    end;
    writeln(c);
end.


program main;
var
    n : LongInt;
    m, i, a : integer;
begin
    readln(n, m);
    for i := 1 to m do begin
        read(a);
        n := n - a;
    end;

    if n < 0 then
        writeln(-1)
    else
        writeln(n);
end.

Score : 200 points

Problem Statement

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints

1 \leq N \leq 10^6

1 \leq M \leq 10^4

1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.

Sample Input 1

41 2
5 6

Sample Output 1

30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.

Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.

Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9


var
	n, m, k : integer;
	i : integer;
    ok : boolean;

begin
	ok := true;
	readln(n, m);
	for i := 1 to m do
    begin
 		read(k);
    	n := n - k;
        if n < 0
        	then ok := false;
    end;
    if ok then
    	writeln(n)
    else
    	writeln(-1);
end.


program main;
var
	n, m, i, free, total : int64;
	a : array[1..100000] of int64;
begin
	read(n, m);
    total := 0;
    for i := 1 to m do begin
    	read(a[i]);
        total := total + a[i];
    end;
	free := n - total;
    if free >= 0
    	then writeln(free)
        	else writeln('-1');
end.


uses math;
var n, i, m, a, sm : longint;

begin
    readln(m, n);
    sm := 0;
    for i := 1 to n do
    begin
        read(a);
        sm := sm + a;
    end;
    writeln(max(m - sm, -1));
end.


program main;
var
    n, i, temp : integer;
    a : array[1..200000] of integer;

begin
    readln(n);

    for i := 1 to n do
        a[i] := 0;

    for i := 2 to n do begin
        read(temp);
        a[temp] := a[temp] + 1;
    end;

    for i := 1 to n do
        writeln(a[i]);
end.

Score : 300 points

Problem Statement

A company has N members, who are assigned ID numbers 1, ..., N.

Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number.

When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X.

You are given the information that the immediate boss of the member numbered i is the member numbered A_i. For each member, find how many immediate subordinates it has.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i < i

Input

Input is given from Standard Input in the following format:

N
A_2 ... A_N

Output

For each of the members numbered 1, 2, ..., N, print the number of immediate subordinates it has, in its own line.

Sample Input 1

5
1 1 2 2

Sample Output 1

2
2
0
0
0

The member numbered 1 has two immediate subordinates: the members numbered 2 and 3.

The member numbered 2 has two immediate subordinates: the members numbered 4 and 5.

The members numbered 3, 4, and 5 do not have immediate subordinates.

Sample Input 2

10
1 1 1 1 1 1 1 1 1

Sample Output 2

9
0
0
0
0
0
0
0
0
0

Sample Input 3

7
1 2 3 4 5 6

Sample Output 3

1
1
1
1
1
1
0


program management;
var
    n, i, x : longint;
    list : array[1..200000] of longint;

begin
    readln(n);
    for i in list do
        list[i] := 0;
    for i := 2 to n do begin
        read(x);
        list[x] += 1;
    end;
    for i := 1 to n do begin
        writeln(list[i]);
    end;
end.


var N,I,A:Longint;S:Array[1..200000]of Longint;
begin
read(N);
for i:=2 to N do begin
read(A);
inc(S[A]);
end;
for i:=1 to N do writeln(S[i]);
end.


program Sum_of_Large_Numbers;
const
  m: int64 = 1000000007;
  h: int64 = 500000004;
  s: int64 = 166666668;
var
  n, k: int64;
function f(i: int64): int64;
begin
  f := i*(((n+1)*(h*(i+1) mod m)-(s*((i+1)*(i*2+1) mod m) mod m)+1) mod m);
end;
begin
  read(n, k);
  writeln((m+(f(n+1)-f(k-1)) mod m) mod m);
end.


program Sum_of_Large_Numbers;
uses math;
const
  m: int64 = 1000000007;
  h: int64 = 500000004;
  s: int64 = 166666668;
var
  n, k: int64;
function f(i: int64): int64;
begin
  f := i*(((n+1)*(h*(i+1) mod m)-(s*((i+1)*(i*2+1) mod m) mod m)+1) mod m);
end;
begin
  read(n, k);
  writeln((m+(f(n+1)-f(k-1)) mod m) mod m);
end.


uses crt,math;
const   fi='';
        nmax=1000;
        vc=100000000;
type    data=int64;
var
        f:text;
        A:array[0..nmax+1,0..nmax+1] of data;
        Fx,Fy,MatchX,MatchY,tr:array[0..nmax+1] of data;
        Q:array[0..nmax*nmax] of data;
        ddx,ddy:array[0..nmax+1] of boolean;
        dau,cuoi,start,finish:data;
        n:longint;
        mm :data;

procedure docfile;
var     u,v,c:data;
        i,j:longint;
begin
        clrscr;
        readln(n);
        for i:=1 to n do
        begin
                read(u);
                for j:=1 to n do begin a[i,j] := u*abs(i-j); mm := max(mm,a[i,j]); end;
        end;
        for i:=1 to n do
        begin
                for j:=1 to n do a[i,j] := mm - a[i,j];
        end;
end;

procedure init;
var     i,j:longint;
begin
        fillchar(MatchX,sizeof(matchx),0);
        MatchY:=MatchX;

        for i:=1 to n do
                begin
                        fx[i]:=vc;
                        for j:=1 to n do
                                if fx[i]>a[i,j] then
                                        fx[i]:=a[i,j];
                end;
        for i:=1 to n do
                begin
                        fy[i]:=vc;
                        for j:=1 to n do
                                if a[i,j]-fx[i]<fy[i] then
                                        fy[i]:=a[i,j]-fx[i];
                end;
end;

function get(i,j:longint):data;
begin
        get:=a[i,j]-fx[i]-fy[j];
end;

procedure themvao(x:data);
begin
        inc(cuoi);
        q[cuoi]:=x;
end;

function layra:data;
begin
        layra:=q[dau];
        inc(dau);
end;

procedure bfs;
var     u,v,j,i:longint;
begin
        fillchar(tr,sizeof(tr),0);
        dau:=1;
        cuoi:=0;
        themvao(start);
        while dau<=cuoi do
                begin
                        u:=layra;
                        for v:=1 to n do
                                if (tr[v]=0) and (get(u,v)=0) then
                                        begin
                                                tr[v]:=u;
                                                if matchy[v]=0 then
                                                        begin
                                                                finish:=v;
                                                                exit;
                                                        end;
                                                themvao(matchy[v]);
                                        end;
                end;
end;

procedure enlager(u:longint);
var     v,next:longint;
begin
        repeat
                v:=tr[u];
                next:=MatchX[v];
                MatchX[v]:=u;
                MatchY[u]:=v;
                u:=next;
        until   u=0;
end;

procedure subX_addY;
var    delta:data;
        i,j:longint;
begin
        fillchar(ddx,sizeof(ddx),false);
        ddy:=ddx;
        ddx[start]:=true;
        for i:=1 to n do
                if tr[i]<>0 then
                        begin
                                ddx[MatchY[i]]:=true;
                                ddy[i]:=true;
                        end;
        delta:=vc;
        for i:=1 to n do
                if ddx[i] then
                        for j:=1 to n do
                                if (not ddy[j]) and (delta>get(i,j)) then
                                        delta:=get(i,j);
        for i:=1 to n do
                begin
                        if ddx[i] then fx[i]:=fx[i]+delta;
                        if ddy[i] then fy[i]:=fy[i]-delta;
                end;
end;

procedure xuli;
var     res:data;
        i,j:longint;
begin
        for i:=1 to n do
                begin
                        start:=i;
                        finish:=0;
                        repeat
                                bfs;
                                if finish=0 then subx_addy;
                        until finish<>0;
                        enlager(finish);
                end;
        res:=0;
        for i:=1 to n do
                if MatchX[i]<>0 then
                        inc(res,a[i,Matchx[i]]);
        writeln(mm*n - res);
        {for i:=1 to n do
                if MatchX[i]<>0 then
                        writeln(i, ' ',MatchX[i]);   }

end;

begin
        docfile;
        init;
        xuli;
end.

Score : 500 points

Problem Statement

There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.

You can rearrange these children just one time in any order you like.

When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points.

Find the maximum total happiness points the children can earn.

Constraints

2 \leq N \leq 2000

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum total happiness points the children can earn.

Sample Input 1

4
1 3 4 2

Sample Output 1

20

If we move the 1-st child from the left to the 3-rd position from the left, the 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and the 4-th child to the 2-nd position, the children earns 1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20 happiness points in total.

Sample Input 2

6
5 5 6 1 1 1

Sample Output 2

58

Sample Input 3

6
8 6 9 1 2 1

Sample Output 3

85


uses crt,math;
const   fi='';
        nmax=2000;
        vc=100000000;
type    data=int64;
var
        f:text;
        A:array[0..nmax+1,0..nmax+1] of data;
        Fx,Fy,MatchX,MatchY,tr:array[0..nmax+1] of data;
        Q:array[0..nmax*nmax] of data;
        ddx,ddy:array[0..nmax+1] of boolean;
        dau,cuoi,start,finish:data;
        n:longint;
        mm :data;

procedure docfile;
var     u,v,c:data;
        i,j:longint;
begin
        clrscr;
        readln(n);
        for i:=1 to n do
        begin
                read(u);
                for j:=1 to n do begin a[i,j] := u*abs(i-j); mm := max(mm,a[i,j]); end;
        end;
        for i:=1 to n do
        begin
                for j:=1 to n do a[i,j] := mm - a[i,j];
        end;
end;

procedure init;
var     i,j:longint;
begin
        fillchar(MatchX,sizeof(matchx),0);
        MatchY:=MatchX;

        for i:=1 to n do
                begin
                        fx[i]:=vc;
                        for j:=1 to n do
                                if fx[i]>a[i,j] then
                                        fx[i]:=a[i,j];
                end;
        for i:=1 to n do
                begin
                        fy[i]:=vc;
                        for j:=1 to n do
                                if a[i,j]-fx[i]<fy[i] then
                                        fy[i]:=a[i,j]-fx[i];
                end;
end;

function get(i,j:longint):data;
begin
        get:=a[i,j]-fx[i]-fy[j];
end;

procedure themvao(x:data);
begin
        inc(cuoi);
        q[cuoi]:=x;
end;

function layra:data;
begin
        layra:=q[dau];
        inc(dau);
end;

procedure bfs;
var     u,v,j,i:longint;
begin
        fillchar(tr,sizeof(tr),0);
        dau:=1;
        cuoi:=0;
        themvao(start);
        while dau<=cuoi do
                begin
                        u:=layra;
                        for v:=1 to n do
                                if (tr[v]=0) and (get(u,v)=0) then
                                        begin
                                                tr[v]:=u;
                                                if matchy[v]=0 then
                                                        begin
                                                                finish:=v;
                                                                exit;
                                                        end;
                                                themvao(matchy[v]);
                                        end;
                end;
end;

procedure enlager(u:longint);
var     v,next:longint;
begin
        repeat
                v:=tr[u];
                next:=MatchX[v];
                MatchX[v]:=u;
                MatchY[u]:=v;
                u:=next;
        until   u=0;
end;

procedure subX_addY;
var    delta:data;
        i,j:longint;
begin
        fillchar(ddx,sizeof(ddx),false);
        ddy:=ddx;
        ddx[start]:=true;
        for i:=1 to n do
                if tr[i]<>0 then
                        begin
                                ddx[MatchY[i]]:=true;
                                ddy[i]:=true;
                        end;
        delta:=vc;
        for i:=1 to n do
                if ddx[i] then
                        for j:=1 to n do
                                if (not ddy[j]) and (delta>get(i,j)) then
                                        delta:=get(i,j);
        for i:=1 to n do
                begin
                        if ddx[i] then fx[i]:=fx[i]+delta;
                        if ddy[i] then fy[i]:=fy[i]-delta;
                end;
end;

procedure xuli;
var     res:data;
        i,j:longint;
begin
        for i:=1 to n do
                begin
                        start:=i;
                        finish:=0;
                        repeat
                                bfs;
                                if finish=0 then subx_addy;
                        until finish<>0;
                        enlager(finish);
                end;
        res:=0;
        for i:=1 to n do
                if MatchX[i]<>0 then
                        inc(res,a[i,Matchx[i]]);
        writeln(mm*n - res);
        {for i:=1 to n do
                if MatchX[i]<>0 then
                        writeln(i, ' ',MatchX[i]);   }

end;

begin
        docfile;
        init;
        xuli;
end.