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
  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[integer(x)] := 1;
  for i := 2 to integer(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;
    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 period;
  rem := integer(n - offset - num * period);
  writeln((a[offset + period] - a[offset]) * num + a[offset + rem]);
end.

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

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

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.


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 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.


program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils;
var
	x		:integer;
begin
    readln(x);
    if (x=0) then writeln(stdout,1)
             else writeln(stdout,0);
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 a,b,c,d,ll,lr,rl,rr,tmp:int64;
begin
readln(a,b,c,d);
ll:=a*c;
rl:=b*d;
lr:=a*d;
rr:=b*d;
tmp:=-1000000000 * 1000000000;
if(ll>=tmp)then tmp:=ll;
if(rl>=tmp)then tmp:=rl;
if(lr>=tmp)then tmp:=lr;
if(rr>=tmp)then tmp:=rr;
writeln(tmp);
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


var a,b,c,d,s:int64;
begin
read(a,b,c,d);
s:=a*c;
if s<b*c then s:=b*c;
if s<a*d then s:=a*d;
if s<b*d then s:=b*d;
writeln(s);
end.


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) AND (d > 0) THEN
begin
	x:= max(a,b) * min(c,d);
    writeln(x);
    exit;
end;

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

end.


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 (b > 0) AND (c > 0) AND (d > 0) THEN//if all positive
begin
	x:= max(a,b) * max(c,d);
	writeln(x);
	exit;
end;

IF (a < 0) AND (b < 0) AND (c < 0) AND (d < 0) THEN//if all negative
begin
	x:= min(a,b) * min(c,d);
	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);

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 (b > 0) AND (c > 0) AND (d > 0) THEN//if all positive
begin
	x:= max(a,b) * max(c,d);
	writeln(x);
	exit;
end;

IF (a < 0) AND (b < 0) AND (c < 0) AND (d < 0) THEN//if all negative
begin
	x:= min(a,b) * min(c,d);
	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.


var

a,b,c,d,x:longint;
s:string;
r:real;

begin

readln(a);
readln(b);
readln(c);
readln(d);

x:= b * d;

writeln(x);

end.


var

a,b,c,d,x:integer;
s:string;
r:real;

begin

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

x:= b * d;

writeln(x);

end.


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

begin

//mod 1000000007;

readln(n);

read(x);
readln(y);

read(a);
readln(b);

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

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 bt;

var s:string;
    t:byte;

begin
   readln(s);
   t:=0;
   if (pos('R',S)<>0) then t:=1;
   if (pos('RR',S)<>0) then t:=2;
   if (pos('RRR',S)<>0) then t:=3;
   write(t);
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 i,j,k,n,t:longint;
    a        :array[1..1000000] of longint;

begin
   readln(n);
   for i:=1 to n-1 do
    read(a[i]);
   readln(a[n]);
   t:=0;
   for i:=1 to n-2 do
    for j:=2 to n-1 do
     for k:=3 to n do
      if (a[i]+a[j]>a[k]) and (a[i]+a[k]>a[j]) and (a[j]+a[k]>a[i]) and (a[i]<>a[j]) and (a[j]<>a[k]) and (a[i]<>a[k]) then
       inc(t);
   write(t);
end.

Score : 200 points

Problem Statement

We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:

L_i, L_j, and L_k are all different.

There exists a triangle whose sides have lengths L_i, L_j, and L_k.

Constraints

1 \leq N \leq 100

1 \leq L_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 \cdots L_N

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

Sample Input 1

5
4 4 9 7 5

Sample Output 1

5

The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).

Sample Input 2

6
4 5 4 3 3 5

Sample Output 2

8

We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.

There is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.

Sample Input 3

10
9 4 6 1 9 6 10 6 6 8

Sample Output 3

39

Sample Input 4

2
1 1

Sample Output 4

0

No triple (i, j, k) satisfies 1 \leq i < j < k \leq N, so we should print 0.


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


program main(input, output);
var
  x : integer;
begin
  readln(x);
  if x >= 30 then writeln('Yes')
  else writeln('No')
end.


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


var N,i,c:Longint;
D,x,y:int64;
begin
read(N,D);
D:=D*D;
for i:=1 to N do begin
read(x,y);
if x*x+y*y<=D then inc(c);
end;
writeln(c);
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


var x:int64;begin read(x);writeln(8-((x-400)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.


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


program bt;

var x,a:integer;

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


program bt;

var x,a:integer;

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


program bt;

var x,a:integer;

begin
   readln(x);
   if (x>=400) and (x<=599) then a:=8 else
   if (x>=600) and (x<=799) then a:=7 else
   if (x>=800) and (x<=999) then a:=6 else
   if (x>=1000) and (x<=1199) then a:=5 else
   if (x>=1200) and (x<=1399) then a:=4 else
   if (x>=1400) and (x<=1399) then a:=3 else
   if (x>=1600) and (x<=1799) then a:=2 else
   if (x>=1800) and (x<=1999) then a:=1;
   write(a);
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 n,k,i,j:longint;
    a,t   :array[1..1000000] of int64;

begin
   readln(n,k);
   for i:=1 to n-1 do
    read(a[i]);
   readln(a[n]);
   for i:=1 to n-k+1 do
    begin
       t[i]:=1;
       for j:=1 to k do
        t[i]:=t[i]*a[i+j-1];
    end;
   for i:=2 to n-k+1 do
    if (t[i]>t[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
	readln(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


program bt;
var L,R,d,i,t:integer;
begin
   readln(L,R,d);
   t:=0;
   for i:=L to R do
    if (i mod d =0) then t:=t+1;
   write(t);
   readln;
end.


program main;
var n,i,ac,wa,tle,re : integer;
    s : array[1..100000] of string;
begin
  readln(n);
  for i := 1 to n do
    readln(s[i]);
  for i := 1 to n do begin
    if (s[i] = 'AC') then inc(ac);
    if (s[i] = 'WA') then inc(wa);
    if (s[i] = 'TLE') then inc(tle);
    if (s[i] = 'RE') then inc(re);
  end;
  writeln('AC x ',ac);
  writeln('WA x ',wa);
  writeln('TLE x ',tle);
  writeln('RE x ',re);
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 i, n, AC, WA, TLE, RE : 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
    i, n, ac, wa, tle, re : integer;
    s : string;
begin
    readln(n);
    for i := 1 to n do begin
        readln(s);
        if s = 'AC'
            then ac := ac + 1;
        if s = 'WA'
            then wa := wa + 1;
        if s = 'TLE'
            then tle := tle + 1;
        if s = 'RE'
            then re := re + 1;
   end;
   writeln('AC x ', ac);
   writeln('WA x ', wa);
   writeln('TLE x ', tle);
   writeln('RE x ', re);
end.


const ver : array[1..4] of ansistring = ('AC', 'WA', 'TLE', 'RE');
var n, i, j : longint;
    s : ansistring;
    c : array[1..4] of longint;

begin
    readln(n);
    fillchar(c, sizeof(c), 0);
    for i := 1 to n do
    begin
        readln(s);
        for j := 1 to 4 do
        begin
            if (s = ver[j]) then inc(c[j]);
        end;
    end;
    for i := 1 to 4 do writeln(ver[i], ' x ', c[i]);
end.


program main;
var a : integer;
begin
    readln(a);
    writeln(a + sqr(a) + sqr(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 hi;
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
    n : integer;
begin
    readln(n);
    writeln(n+n*n+n*n*n);
end.


program main;
var input : integer;
begin
readln (input);
if (input>=1) or (input<=10) then
writeln (input+input*input+input*input*input);
end.


program main ;
var a: integer;

begin
readln(a);
if (a>=1) and (a<=10) then
  begin
  writeln(a+a*a+a*a*a);
  end;
end.


program main;
var a, b : string;
    n,i : integer;
begin
    n := 0;
    readln(a);
    readln(b);
    for i := 1 to length(a) do
        if a[i] <> b[i] then
            inc(n);
    writeln(n);
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 main;
var
	s1, s2 : string;
    count, len, i : integer;

begin
    count := 0;
	readln(s1);
    readln(s2);

    len := length(s1);
    for i := 1 to len do begin
    	if s1[i] <> s2[i]
        	then count := count + 1;
    end;
	writeln(count);
end.


program main;
var
   input1, input2:string;
   i, diff, len: integer;
begin
	readln(input1);
    readln(input2);
    diff := 0;
    for i:= 1 to length(input1) do begin
        if(input1[i] <> input2[i]) then
             diff := diff + 1;
    end;
    writeln(diff);
end.


var
    n : integer;
    a, b, x, val, y, z, k, res: int64;
    label ending;

begin
    read(n);
    read(a, b);
    n := n - 2;
    while n <> 0 do begin
            n := n - 1;
            read(val);
            x := x xor val;
    end;
    y := a + b - x;
    z := y shr 1;
    if (y < 0) or ((y and 1) <> 0) or ((x and z) <> 0) or (a < z) then
        begin
          writeln('-1');
          goto ending;
        end;
    res := z;
    k := 1 shl 40;
    while k <> 0 do begin
        if (x and k) <> 0 then begin
            if (res or k) <= a then begin
              res := res or k;
            end;
        end;
        k := k shr 1;
    end;
    res := a - res;
    if res = 0 then writeln('-1') else writeln(res);
    ending:
end.

Score : 600 points

Problem Statement

There are N piles of stones. The i-th pile has A_i stones.

Aoki and Takahashi are about to use them to play the following game:

Starting with Aoki, the two players alternately do the following operation:

Operation: Choose one pile of stones, and remove one or more stones from it.

When a player is unable to do the operation, he loses, and the other player wins.

When the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile.

In such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1-st pile to the 2-nd pile before the game begins.

If this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead.

Constraints

2 \leq N \leq 300

1 \leq A_i \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead.

Sample Input 1

2
5 3

Sample Output 1

1

Without moving stones, if Aoki first removes 2 stones from the 1-st pile, Takahashi cannot win in any way.

If Takahashi moves 1 stone from the 1-st pile to the 2-nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions.

Sample Input 2

2
3 5

Sample Output 2

-1

It is not allowed to move stones from the 2-nd pile to the 1-st.

Sample Input 3

3
1 1 2

Sample Output 3

-1

It is not allowed to move all stones from the 1-st pile.

Sample Input 4

8
10 9 8 7 6 5 4 3

Sample Output 4

3

Sample Input 5

3
4294967297 8589934593 12884901890

Sample Output 5

1

Watch out for overflows.


program main;
var i : char;
begin
  readln(i);
  if (ord(i) >= 97) and (ord(i) <= 122) then writeln('a');
  if (ord(i) >= 65) and (ord(i) <= 90) 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 main;
var c : char;

begin
  readln(c);
  if c in ['a'..'z'] then
     writeln('a')
  else if c in ['A'..'Z'] then
     writeln('A');
end.


program main;
var
    c : char;
begin
    readln(c);
    if (c >= 'a') and (c <= 'z')
        then writeln('a');
    if (c >= 'A') and (c <= 'Z')
        then writeln('A');
end.


program main;
var
    n, k, sum, mini, 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
        mini := i;
        for j := i + 1 to n do
            if (a[mini] > a[j]) then
                mini := j;

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

    writeln(sum);
end.


program main;
type
  arr = array [1..1000] of longint;

var i, n, t, sum : longint;
    juice : arr;

procedure bubble_sort (var number : arr);
var
  i, t : integer;
  swap : boolean = true;

begin
  while swap do begin
    swap := false;
    for i := 1 to (n-1) do
      if (number[i] > number[i+1]) then begin  //ascending order
      {if (number[i] < number[i+1]) then begin  //descending order}
        t := number[i];
  	   number[i] := number[i+1];
		   number[i+1] := t;
 	   swap := true;
      end;
  end;
end;

begin
  read(n);
  readln(t);
  for i := 1 to n do
    read(juice[i]);
  readln;
  bubble_sort(juice);
  sum := 0;
  for i := 1 to t do
    sum := sum + juice[i];
  writeln(sum);
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;
type
  arr = array [1..1000] of longint;

var i, n, t, sum : longint;
    juice : arr;

procedure quicksort (var number : arr; left, right : longint);
var
  l, r, t, tswap : longint;

begin
  l := left;
  r := right;
  t := number[l];
  repeat
    while (number[l] < t) and (l < right) do
      inc(l);
    while (number[r] >= t) and (r > left) do
      dec(r);
    if (l < r) then begin
     tswap := number[l];
     number[l] := number[right];
     number[r] := tswap;
    end;
  until (l >= r);
  quicksort(number, left, r);
  quicksort(number, (r+1), right);
end;

begin
  read(n);
  readln(t);
  for i := 1 to n do
    read(juice[i]);
  readln;
  quicksort(juice, 1, n);
  sum := 0;
  for i := 1 to t do
    sum := sum + juice[i];
  writeln(sum);
end.


program hi;
var
    k, n, i, j, ans: integer;
    p: array[1..1000] of integer;

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

begin
    readln(n, k);
    for i := 1 to n do
        read(p[i]);
    for i := 1 to n - 1 do
        for j := 1 to n - 1 do
            if p[j] > p[j + 1] then
                swap(p[j], p[j + 1]);
    ans := 0;
    for i := 1 to k do
        ans := ans + p[i];
    writeln(ans);
end.


program main;
var
    i, x, y, smallest, count : integer;
    total : int64;
    A : array[1..1000] of integer;
    B : array[1..1000] of boolean;
begin
    readln(x, y);
    total := 0;
    for i := 1 to x do
        B[i] := false;
    for i := 1 to x do
        read(A[i]);
    while y > 0 do begin
        smallest := 1001;
        count := 0;
        for i := 1 to x do
            if (A[i] < smallest) and (B[i] = false)
                then begin
                    smallest := A[i];
                    count := i;
                end;
        B[count] := true;
        total := total + smallest;
        y := y - 1;
    end;
    writeln(total);
end.


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
    if (l < r) then begin
        p := a[l]; 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;
            end;
        end;

        qs(l, i - 1);
        qs(i + 1, 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 += a[i];

    writeln(sum);
end.


var
	N,T:int64;
begin
	read(N);
	T:=1;
	while N>=T do begin
		dec(N,T);
		T:=T*26;
	end;
	while T>1 do begin
		T:=T div 26;
		write(Chr(N div T+97));
		N:=N mod T;
	end;
end.

Score : 300 points

Problem Statement

1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows:

the dogs numbered 1,2,\cdots,26 were respectively given the names a, b, ..., z;

the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz;

the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz;

the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz;

the dogs numbered 475255,475256,\cdots were respectively given the names aaaaa, aaaab, ...;

and so on.

To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names:

a, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ...

Now, Roger asks you:

"What is the name for the dog numbered N?"

Constraints

N is an integer.

1 \leq N \leq 1000000000000001

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer to Roger's question as a string consisting of lowercase English letters.

Sample Input 1

2

Sample Output 1

b

Sample Input 2

27

Sample Output 2

aa

Sample Input 3

123456789

Sample Output 3

jjddja


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 + 1);
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 hi;
var x, i: integer;

begin
    for i := 1 to 5 do begin
        read(x);
        if (x = 0) then
            writeln(i);
    end;
end.


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


var
  a,b,c,d,e:longint;
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.


program ct;
var
    i, x, y : longint;
begin
    read(x, y);
    readln;
    if y mod 2 = 0 then
        for i := 1 to x do begin
            if y - 4 >= 0 then
                y -= 4
            else if y - 2 >= 0 then
                y -= 2
                else break;
        end
    else y := 1;
    if y = 0 then
        writeln('Yes')
    else
        writeln('No');
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 ct;
var
    i, x, y : longint;
begin
    read(x, y);
    readln;
    for i := 1 to x do begin
        if y - 4 >= 0 then
            y -= 4
        else if y - 2 >= 0 then
            y -= 2
            else break;
    end;
    if y = 0 then
        writeln('Yes')
    else
        writeln('No');
end.


var x,y,i:longint;
begin
read(x,y);
for i:=0 to x do begin
if 2*x+2*i=y then begin
writeln('Yes');
exit;
end;
end;
writeln('No');
end.


program main;
var
    a, b : integer;
begin
    readln(a, b);
    if ( b mod 2 = 1 ) or ( a*4 < b ) or ( a*2 > b ) then
        writeln('No')
    else
        writeln('Yes');
end.


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 main;
var
    a, b, x, y, legs : integer;
begin
    readln(x, y);
    a := 0;
    b := x;
    while a <= x do begin
        legs := a*2 + b*4;
        if legs = y
            then begin
                writeln('Yes');
                halt;
            end
            else begin
                a := a + 1;
                b := b - 1;
            end;
    end;
    if a > x
        then writeln('No');
end.


var s:string;
begin
readln(s);
writeln(s[1]+s[2]+s[3])
end.

Score : 100 points

Problem Statement

When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters.
You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.

Constraints

3 \leq |S| \leq 20

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print your answer.

Sample Input 1

takahashi

Sample Output 1

tak

Sample Input 2

naohiro

Sample Output 2

nao


var a,b,v,w,t: int64; 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
  read(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 multi;
var
    a, b : longint;
begin
    read(a, b);
    readln;
    writeln(a * b);
end.


program hi;
var
    a, ans: QWord;
    n, i: integer;
    ex: boolean = false;

begin
    readln(n);
    ans := 1;
    for i := 1 to n do begin
        read(a);
        if (ans > 1000000000000000000) then
            ex := true;
        if (a = 0) then begin
            writeln(0);
            exit;
        end else if (a > 1000000000000000000) then
            ex := true
        else
            ans := ans * a;
    end;
    if (ex) or (ans > 1000000000000000000) then
        writeln(-1)
    else
        writeln(ans)
end.


program hi;
var a, b: integer;

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


program main;
var
	x, y : integer;
    sum : int64;
begin
	read(x, y);
    sum := x*y;
    writeln(sum);
end.


var a,b:Longint;
begin
read(a,b);
writeln(a*b);
end.


var
	N,i,c,t,z:int64;
begin
	read(N);
	i:=2;
	while i*i<=N do begin
		if N mod i=0 then begin
			c:=0;
			while N mod i=0 do begin
				N:=N div i;
				inc(c);
			end;
			t:=1;
			while c>=t do begin
				dec(c,t);
				inc(t);
				inc(z);
			end;
		end;
		inc(i);
	end;
	if N>1 then inc(z);
	writeln(z);
end.

Score : 400 points

Problem Statement

Given is a positive integer N. Consider repeatedly applying the operation below on N:

First, choose a positive integer z satisfying all of the conditions below:

z can be represented as z=p^e, where p is a prime number and e is a positive integer;

z divides N;

z is different from all integers chosen in previous operations.

Then, replace N with N/z.

Find the maximum number of times the operation can be applied.

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum number of times the operation can be applied.

Sample Input 1

24

Sample Output 1

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=12.)

Choose z=3 (=3^1). (Now we have N=4.)

Choose z=4 (=2^2). (Now we have N=1.)

Sample Input 2

1

Sample Output 2

0

We cannot apply the operation at all.

Sample Input 3

64

Sample Output 3

3

We can apply the operation three times by, for example, making the following choices:

Choose z=2 (=2^1). (Now we have N=32.)

Choose z=4 (=2^2). (Now we have N=8.)

Choose z=8 (=2^3). (Now we have N=1.)

Sample Input 4

1000000007

Sample Output 4

1

We can apply the operation once by, for example, making the following choice:

z=1000000007 (=1000000007^1). (Now we have N=1.)

Sample Input 5

997764507000

Sample Output 5

7


program therefore;
var
    n : string;
    x : char;
begin
    readln(n);
    x := n[length(n)];
    if (x = '2') or (x = '4') or (x = '5') or (x = '7') or (x = '9') then
        writeln('hon')
        else if x = '3' then
            writeln('bon')
                else writeln('pon');
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 n : integer;

begin
    readln(n);
    n := n mod 10;
    case n of
        2,4,5,7,9 : writeln('hon');
        0,1,6,8 : writeln('pon');
        3 : writeln('bon');
    end;
end.


program main;
var a : integer;
begin
    readln(a);
    if (a > 10) then
        repeat
            dec(a,10);
        until (a <= 10);
        case a of
            2,4,5,7,9 : writeln('hon');
            0,1,6,8 : writeln('pon');
            3 : writeln('bon');
        end;
end.


program hi;
var n: integer;

begin
    readln(n);
    n := n mod 10;
    if n in [2, 4, 5, 7, 9] then
        writeln('hon')
    else if n in [0, 1, 6, 8] then
        writeln('pon')
    else
        writeln('bon')
end.


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


var
    n: Integer;
    c: Integer;
begin
    read(n);
    c := n mod 10;
    case c of
    	3: writeln('bon');
       	0, 1, 6, 8: writeln('pon');
        else writeln('hon');
    end;
    read(n);
end.


var N:Longint;
begin
read(N);
N:=N mod 10;
if N=3 then writeln('bon')else if(N=0)or(N=1)or(N=6)or(N=8)then writeln('pon')else writeln('hon');
end.


program main;
var
    a, i : integer;
    b : string;
begin
    readln(a);
    readln(b);
    if ( a >= length(b) ) then
        writeln(b)
    else
        begin
            for i := 1 to a do
                write(b[i]);
            write('...');
        end;
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
    x : integer;
    s : string;
begin
    readln(x);
    readln(s);
    if x >= length(s)
        then writeln(s)
        else begin
            s := copy(s, 1, x);
            writeln(s,'...');
        end;
end.


var K:Longint;
S:String;
begin
readln(K);
readln(S);
if length(S)<=K then writeln(S)else writeln(copy(S,1,K),'...');
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;
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);
writeln(sqrt(a*a+b*b-2*a*b*cos((angle1)/180*pi)):0:20);
end.


program linear;
var
    a, b, c, k : longint;
begin
    readln(a, b, c, k);
    writeln(a - (k - a - b) * c);
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


var A,B,C,K:Longint;
begin
read(A,B,C,K);
if A>K then writeln(K) else if A+B>K then writeln(A) else writeln(A+A+B-K);
end.


program main;
var s : string;
begin
    readln(s);
    if s = '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
    a : string;
begin
    read(a);
    if a ='ABC'
        then writeln('ARC')
            else writeln('ABC');
end.


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


var
 s:string;
begin
 readln(s);//读入s
 if s='ABC' then write('ARC')//如果为ABC，输出ARC
            else write('ABC');//否则输出ABC
end.


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


program trickortreat;
var
    snuke : array[1..100] of boolean;
    n, k, i, j, x, y, counter : longint;
begin
    readln(n, k);
    counter := 0;
    for i := 1 to 100 do begin
        snuke[i] := false;
    end;

    for i := 1 to k do begin
        readln(x);
        for j := 1 to x do begin
            read(y);
            snuke[y] := true;
        end;
    end;

    for i := 1 to n do begin
        if not(snuke[i]) then
            counter += 1;
    end;
    writeln(counter);
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


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.


var a,b:array[1..10000000] of int64;
    i,j:longint;
    res,k,n,d:int64;
begin
 for i:=1 to 200 do   b[i]:=0;
 read(n,k);
 for i:=1 to k do
 begin
  readln(d);
  for j:=1 to d do
   begin
    read(a[j]);
    b[a[j]]:=1;
   end;
 end;
 for i:=1 to n do if(b[i]=0) then res:=res+1;
 write(res);
end.


program main;
var k, a, b, i, x : integer;
    ok : boolean;
begin
    ok := false;
	readln(k);
    readln(a, b);

    for i := a to b do begin
        x := i mod k;
        if x = 0
            then ok := true;
    end;

    if ok
        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


program wlw;
var
    k, i, a, b : longint;
    found : boolean;
begin
    readln(k);
    readln(a, b);
    found := false;
    for i := a to b do begin
        if i mod k = 0 then
            found := true;
    end;
    if not(found) then
        writeln('NG')
    else
        writeln('OK')

end.


program main;
var
    a, b, target, i : integer;
    can : boolean;
begin
    can := false;
    readln(target);
    readln(a, b);
    for i := a to b do
        if (i mod target = 0)
            then can := true;
    if can
        then writeln('OK')
        else writeln('NG');;
end.


program main;
var
	k, a, b, count, i : integer;

begin
	read(k);
    readln(a, b);

    if k = 1
    	then writeln('OK')
        	else begin
            	count := 0;
            	for i := a to b do begin
                	if (frac(i / k) = 0)
                    	then count := count +1;
                 end;
     if count <> 0
     	then writeln('OK')
        		else writeln('NG');
    end;
end.


var
	i,n,a,b:integer;
    kk:boolean;
begin
	readln(n);
    readln(a,b);
    kk:=false;
    for i:=a to b do if (i mod n)=0 then kk:=true;
    if kk then writeln('OK') else writeln('NG');
end.


var k,a,b,i,t:longint;
begin
 readln(k);read(a,b);
 t:=0;
 for i:=a to b do
  if i mod k=0 then
   begin
    t:=1;
    break;
   end;
 if t=0 then write('NG')
 else   write('OK');
end.


var a, b, k, i : longint;

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


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

begin
    readln(x);
    counter := 0;
    current := 100;
    while not(current >= x) do begin
        current := current + (current div 100);
        counter += 1;
    end;
    writeln(counter);
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 main;
var x,d,n : int64;
begin
    d:=0;
    x := 100;
    readln(n);
    repeat
    x:=trunc(x*1.01);
    inc(d);
    until (x >= n) ;
    writeln(d);
end.


program main;
var
	count, target : int64;
	sum : real;
begin
	read(target);
    sum := 100;
    count := 0;
    repeat
    	sum := sum * 1.01;
        count := count + 1;
    until sum >= target;

    writeln(count);
end.


uses math;
var
	x:int64;
begin
	readln(x);
	writeln(log10(x/100)/log10(1.01):0:0)
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.


var x, m : int64;
    ans : longint;

begin
    readln(x);
    m := 100; ans := 0;
    while (true) do
    begin
        if (m >= x) then break;
        m := m + (m div 100);
        inc(ans);
    end;
    writeln(ans);
end.


program SheepandWolves;
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 HelloWorld;
var
    s, w : integer;
begin
    readln(s, w);
    if s > w
        then writeln('safe')
        else writeln('unsafe');
end.


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


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


program main;
var
	s, w : integer;

begin
	read(s, w);
    if s < w
    	then writeln('unsafe')
        	else writeln('safe');
end.


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


var a,b:longint;
begin
  readln(a,b);
  if a<=b then write('un');
  writeln('safe');
end.


var
	arr : array[0..2068,1..2000] of string;
    s:string;
    i,j,n,temp,cnt:longint;
function hash(s:string):integer;
var
	i:integer;
    sum:longint;
begin
	sum:=0;
	for i:=1 to length(s) do begin
    	sum:=(ord(s[i])*i)+sum;
	end;
    hash:=(sum mod 2069);
end;
begin
	cnt:=0;
	for i:=0 to 2068 do
    	for j:=1 to 2000 do arr[i][j]:='.';
	readln(n);
    for i:=1 to n do begin
    	readln(s);
        cnt:=cnt+1;
        j:=1;
        temp:=hash(s);
        while (arr[temp][j]<>'.') and (arr[temp][j]<>s) do begin
        	j:=j+1;
        end;
        if (arr[temp][j]=s) then begin
        	cnt:=cnt-1;
        	continue;
        end;
        if arr[temp][j]<>'.' then continue
        else arr[temp][j]:=s;
    end;
	writeln(cnt);
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 hi;
type ars = array[1..200000] of string;
var
    n, i, cnt: longint;
    s, tmp: ars;

procedure mSort(var a, tmp: ars; l, r: longint);
var m, i, i1, i2: longint;
begin
    if l < r then begin
        m := (l + r) div 2;
        mSort(a, tmp, l, m);
        mSort(a, tmp, m + 1, r);
        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;
        while i1 <= m do begin
            tmp[i] := a[i1];
            inc(i1); inc(i);
        end;
        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;
end;

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


program main;
var n,i,j,c : longint;
    a : array[1..200000] 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 hi;
type ars = array[1..200000] of string;
var
    n, i, cnt: longint;
    s, tmp: ars;

procedure mSort(var a, tmp: ars; l, r: longint);
var m, i, i1, i2: longint;
begin
    if l < r then begin
        m := (l + r) div 2;
        mSort(a, tmp, l, m);
        mSort(a, tmp, m + 1, r);
        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(i1); inc(i);
        end;
        for i := l to r do
            a[i] := tmp[i];
    end;
end;

begin
    readln(n);
    for i := 1 to n do
        readln(s[i]);
    mSort(s, tmp, 1, n);
    cnt := 1;
    for i := 1 to n - 1 do
        if s[i] <> s[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
    if (left < right) then begin
        k := x[left];
        i := left; j := right;
        repeat
            while (x[i] < k) and (i < right) do
                i := i + 1;
            while (x[j] >= k) and (j > left) do
                j := j - 1;
            if (i < j) then
                swap(x[i], x[j])
        until (i >= j);
        quicksort(x, left, j);
        quicksort(x, j + 1, right);
    end;
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 gacha;
var
    n, i, j, x : longint;
    list : array[1..200000] of string;
    new : boolean;
begin
    readln(n);
    x := 1;
    for i := 1 to n do begin
        readln(list[i]);
        new := false;
        if (i > 1) then begin
            for j := 1 to i - 1 do begin
                if (list[j] = list[i]) then break
                    else new := true;
            end;
        end;
        if new then x += 1;
    end;
    writeln(x);
end.


type SortDataType=String;
function SortCmp(const a,b:SortDataType):Boolean;forward;
procedure SortImpl(var A:Array of SortDataType;L,R:Longint);
var
	tmp:SortDataType;
	mid,il,ir:Longint;
begin
	if R-L<20 then begin
		for ir:=R-1 downto L+1 do for il:=L to ir-1 do if SortCmp(A[il+1],A[il])then begin
			tmp:=A[il];
			A[il]:=A[il+1];
			A[il+1]:=tmp;
		end;
	end else begin
		mid:=(L+R)div 2;
		if SortCmp(A[mid],A[L])then begin
			tmp:=A[mid];
			A[mid]:=A[L];
			A[L]:=tmp;
		end;
		if SortCmp(A[R-1],A[mid])then begin
			tmp:=A[R-1];
			A[R-1]:=A[mid];
			A[mid]:=tmp;
			if SortCmp(A[mid],A[L])then begin
				tmp:=A[mid];
				A[mid]:=A[L];
				A[L]:=tmp;
			end;
		end;
		il:=L;
		ir:=R-1;
		while il<=ir do begin
			while SortCmp(A[il],A[mid])do inc(il);
			while SortCmp(A[mid],A[ir])do dec(ir);
			if il<ir then begin
				tmp:=A[il];
				A[il]:=A[ir];
				A[ir]:=tmp;
				if mid=il then mid:=ir else if mid=ir then mid:=il;
				inc(il);
				dec(ir);
			end else if il=ir then begin
				inc(il);
				dec(ir);
			end;
		end;
		SortImpl(A,L,il);
		SortImpl(A,il,R);
	end;
end;
procedure Sort(var A:Array of SortDataType;size:Longint);
begin
	SortImpl(A,0,size);
end;
function SortCmp(const a,b:SortDataType):Boolean;
begin
	SortCmp:=a<b;
end;
var
	i,N,cnt:Longint;
	A:Array[1..200000]of String;
begin
	readln(N);
	for i:=1 to N do readln(A[i]);
	sort(A,N);
	cnt:=N;
	for i:=2 to N do if A[i-1]=A[i]then dec(cnt);
	writeln(cnt);
end.


program HW;
var
    n, m, x, i : Longint;
begin
    readln(n, m);
    for i := 1 to m do begin
        read(x);
        n -= x;
    end;
    if (n >= 0) then writeln(n)
        else writeln(-1);
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


program train;
var
    n, m, i, x : longint;
begin
    read(n, m);
    for i := 1 to m do begin
        read(x);
        n := n - x;
        end;
    if n < 0
        then write('-1')
        else write(n);
end.


program train;
var
    n, m, i, x : longint;
begin
    read(n, m);
    for i := 1 to m do begin
        read(x);
        n := n - x;
        end;
    write(n);
end.


program train;
var
    n, m, i, x : integer;
begin
    read(n, m);
    for i := 1 to m do begin
        read(x);
        n := n - x;
        end;
    write(n);
end.


program main;
var
	n, m, i, sum : longint;
    a : array[1..10005] of longint;
begin
	sum := 0;
	readln(n,m);
	for i := 1 to m do a[i] := 0;
    for i := 1 to m do begin
    	read(a[i]);
        sum := sum + a[i];
    end;
    if sum > n
    	then writeln(-1)
    	else writeln(n-sum);
end.


program hihi;
var
	N : longint;
    M, i : integer;
    A : array[1..10000] of integer;

begin
	readln(N, M);
    for i:=1 to M do begin
    	read(A[i]);
       	N := N - A[i];
        end;
    if N<0
    	then N:=-1;
    writeln(N);
end.


program Homework;
var
	sum, i, N, M, a : integer;
begin
	sum := 0;
	readln(N, M);
	for i := 1 to m do begin
		read(a);
		sum := sum + a;
	end;
	if N >= sum
		then writeln(N - sum)
		else writeln('-1');
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.


program main;
var
    i,j,k:integer;
    sum,n,m,haha:Int64;
begin
    readln(n,m);
    sum:=0;
    for i:=1 to m do begin
        read(haha);
        sum:=sum+haha;
    end;
    if (n-sum>=0) then writeln(n-sum) else writeln(-1);
end.


uses math;
var n,m,i,t:longint;
begin
  readln(n,m);
  for i:=1 to m do
  begin
    read(t);
    dec(n,t);
  end;
  writeln(max(n,-1));
end.


program main;
var
    n, i, temp : integer;
    a : array[1..20000] 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]);
    write(a[n])
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 main;
var
    n, i, temp : integer;
    a : array[1..20000] 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.


program main;
var
    i, n, x : longint;
    A : array[1..200000] of longint;
begin
    readln(n);
    for i := 1 to n do
        A[i] := 0;
    for i := 1 to n do begin
        read(x);
        A[x] := A[x] + 1;
    end;
    for i := 1 to n do
        writeln(A[i]);
end.


program main;
var
    i, n, x, count, int : int64;
begin
    int := 1;
    readln(n);
    count := 0;
    for i := 1 to n-1 do begin
        read(x);
        if x = int
            then begin
                count := count + 1;
                if i = n-1
                    then writeln(count);
            end
            else begin
                writeln(count);
                count := 1;
                int := x;
                if i = n-1
                    then writeln(count);
            end;
    end;
    for i := int+1 to n do
        writeln('0');
end.


program main;
var
    i, n, x, count, int : longint;
begin
    int := 1;
    readln(n);
    count := 0;
    for i := 1 to n-1 do begin
        read(x);
        if x = int
            then begin
                count := count + 1;
                if i = n-1
                    then writeln(count);
            end
            else begin
                writeln(count);
                count := 1;
                int := x;
                if i = n-1
                    then writeln(count);
            end;
    end;
    for i := int+1 to n do
        writeln('0');
end.


Var b:Array[0 .. 200000] of Longint;
    a,n,i:Longint;
Begin
    Readln(n);
    For i:=2 to n do begin
        Read(a);
        Inc(b[a]);
    End;
    For i:=1 to n do writeln(b[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 train;
var
    n, i : longint;
    sum : Int64;
begin
    read(n);
    sum := 0;
    for i := 1 to n do
        if not ((i mod 3) = 0) and not ((i mod 5) = 0)
            then sum := sum + i;
    write(sum);
end.

Score : 200 points

Problem Statement

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.

If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.

If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.

If none of the above holds, a_i=i.

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

Constraints

1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

Sample Input 1

15

Sample Output 1

60

The first 15 terms of the FizzBuzz sequence are:

1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}

Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.

Sample Input 2

1000000

Sample Output 2

266666333332

Watch out for overflow.


program train;
var
    n, i : int64;
    sum : Int64;
begin
    read(n);
    sum := 0;
    for i := 1 to n do
        if ((i mod 3) = 0) or ((i mod 5) = 0)
            then sum := sum + i;
    write(sum);
end.


program FizzBuzzSum;
var
	n, sum, i : int64;
begin
	sum := 0;
	readln(n);
	i := 1;
	while i <= n do begin
		if ( i mod 3 <> 0 )
			then if ( i mod 5 <> 0 )
					then sum := sum + i;
		i := i + 1;
	end;

	writeln(sum);
end.


program main;
var N, i, sum : Longint;
    c, b : real;
    A : array[1..1000000] of LongInt;
begin
	read(N);
    sum := 0;
    for i := 1 to N do begin
        c := frac(i / 3);
        b := frac(i / 5);
        if (c = 0) or (b = 0)
        then A[i] := 0
        else A[i] := i;
        sum := sum + A[i];
    end;
    writeln(sum);
end.


program HelloWorld;
var
    i, n, sum : int64;
begin
    readln(n);
    sum := 0;
    for i := 1 to n do
        if (i mod 3 <> 0) and (i mod 5 <> 0)
            then sum := sum + i;
    writeln(sum);
end.


program main;
var
	num, i, sum : int64;
begin
	read(num);

    sum := 0;

    for i := 1 to num do begin
    	if (frac(i/3) = 0) or (frac(i/5) = 0)
        	then sum := sum + 0
        	    else sum := sum + i;
    end;
 	writeln(sum);
end.


program main;
var
    i,j,k:integer;
    n:longint;
    sum:longint;
begin
    readln(n);
    sum:=0;
    for i:=1 to n do if ((i mod 3) <> 0) and ((i mod 5) <> 0) then sum:=sum+i;
    writeln(sum);
end.


program FizzBuzzSum;
var
    x, i : Longint;
    sum : int64;
begin
    readln(x);
    sum := 0;
    for i := 1 to x do begin
        if (((i mod 3) <> 0) and ((i mod 5) <> 0)) then begin
            sum += i;
        end;
    end;
    writeln(sum);
end.


var
  i,n:longint;
  s:int64;
begin
  readln(n);
  for i:=1 to n do
    if (i mod 3<>0) and (i mod 5<>0) then s:=s+i;
  writeln(s);
end.


var
	N,i,a,j,ni,nj:Longint;
	dp:Array[0..100000,0..3]of int64;
begin
read(N);
for i:=0 to N do for j:=0 to 2 do dp[i,j]:=-1000000000000000000;
dp[0,0]:=0;
for i:=0 to N-1 do begin
read(a);
for j:=0 to 2 do begin
if dp[i+1,j+1]<dp[i,j]then dp[i+1,j+1]:=dp[i,j];
ni:=i+2;if ni>N then ni:=N;
nj:=j;if i+2=N then inc(nj);
if dp[ni,nj]<dp[i,j]+a then dp[ni,nj]:=dp[i,j]+a;
end;
end;
writeln(dp[N,1+N mod 2]);
end.

Score : 600 points

Problem Statement

Given is an integer sequence A_1, ..., A_N of length N.

We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen.

Find the maximum possible sum of the chosen elements.

Here \lfloor x \rfloor denotes the greatest integer not greater than x.

Constraints

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

|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_N

Output

Print the maximum possible sum of the chosen elements.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

12

Choosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.

Sample Input 2

5
-1000 -100 -10 0 10

Sample Output 2

0

Choosing -10 and 10 makes the sum 0, which is the maximum possible value.

Sample Input 3

10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

5000000000

Watch out for overflow.

Sample Input 4

27
18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49

Sample Output 4

295


program main;
var n,k : int64;
begin
    readln(n,k);
    if abs((n mod k)-k) > abs(n mod k)
    then writeln(abs(n mod k))
    else writeln(abs((n mod k)-k));
end.

Score : 300 points

Problem Statement

Given any integer x, Aoki can do the operation below.

Operation: Replace x with the absolute difference of x and K.

You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Constraints

0 ≤ N ≤ 10^{18}

1 ≤ K ≤ 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible value taken by N after Aoki does the operation zero or more times.

Sample Input 1

7 4

Sample Output 1

1

Initially, N=7.

After one operation, N becomes |7-4| = 3.

After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0


program main;
var
    a,n,m : longint;
begin
    readln(n,m);
    a := n mod m;
    if abs(a-m) < abs(a)
        then writeln(abs(a-m))
        else writeln(abs(a));
end.


program main;
var
    a,n,m : longint;
begin
    readln(n,m);
    a := n mod m;
    if abs(a-m) < a
        then writeln(abs(a-m))
        else writeln(a);
end.


program hihi;
var
	N, K, result : longint;
begin
	readln(N, K);
    if N >=K
    	then result := N mod K
    	else result := N;
    writeln(result);
end.


program hihi;
var
	N, K, result : longint;
begin
	readln(N, K);
    if N >K
    	then result := N mod K
    	else result := N;
    writeln(result);
end.


var
    n,k : int64;
begin
    readln(n,k);
    if (n mod k) < (k-(n mod k)) then
        writeln(n mod k)
    else
        writeln(k-(n mod k));
end.


program main;
var n,k,d : int64;
    b : boolean;
begin
    b := false;
    readln(n,k);
    repeat
    n := abs(n-k);
    d := abs(n-k);
    if n = 0
    then b := true;
    if d >= n
    then b := true;
    until b;
    writeln(n);
end.


program ReplacingInteger;
var
    x, y, z : int64;
begin
    readln(x, y);
    if (x > y) then begin
        if (x mod y = 0) then
            writeln(0)
            else begin
                z := x div y;
                if (x mod y < (y - x mod y)) then
                    writeln(x mod y)
                    else
                        writeln((y - x mod y));
            end;
    end
    else begin
        if (x < y) then
            writeln(abs(x))
            else if (x = y) then
                writeln(0);
        end;
end.


program ReplacingInteger;
var
    x, y : int64;
    z : Longint;
begin
    readln(x, y);
    if (x > y) then begin
        if (x mod y = 0) then
            writeln(0)
            else begin
                z := x div y;
                if (z > x mod y) then
                    writeln(z)
                    else
                        writeln(x mod y);
            end;
    end
    else begin
        if (x < y) then
            writeln(abs(x))
            else if (x = y) then
                writeln(0);
        end;
end.


program main;

var
	x, y : integer;

function min(x : integer; y : integer) : integer;
begin
	if x <= y then min := x
    else min := y;
end;

begin
	readln(x, y);
    x := x mod y;
    writeln(min(x, y - x));
end.


var
	S:String;
	N,K,C,i,now:Longint;
	R:Array[1..200000]of Longint;
begin
	readln(N,K,C);
	readln(S);
	now:=K;i:=N;
	while i>=1 do begin
		if S[i]='o'then begin
			R[i]:=now;
			dec(now);
			dec(i,C);
		end;
		dec(i);
	end;
	now:=0;i:=1;
	while i<=N do begin
		if S[i]='o'then begin
			inc(now);
			if R[i]=now then writeln(i);
			inc(i,C);
		end;
		inc(i);
	end;
end.

Score : 500 points

Problem Statement

Takahashi has decided to work on K days of his choice from the N days starting with tomorrow.

You are given an integer C and a string S. Takahashi will choose his workdays as follows:

After working for a day, he will refrain from working on the subsequent C days.

If the i-th character of S is x, he will not work on Day i, where Day 1 is tomorrow, Day 2 is the day after tomorrow, and so on.

Find all days on which Takahashi is bound to work.

Constraints

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

1 \leq K \leq N

0 \leq C \leq N

The length of S is N.

Each character of S is o or x.

Takahashi can choose his workdays so that the conditions in Problem Statement are satisfied.

Input

Input is given from Standard Input in the following format:

N K C
S

Output

Print all days on which Takahashi is bound to work in ascending order, one per line.

Sample Input 1

11 3 2
ooxxxoxxxoo

Sample Output 1

6

Takahashi is going to work on 3 days out of the 11 days. After working for a day, he will refrain from working on the subsequent 2 days.

There are four possible choices for his workdays: Day 1,6,10, Day 1,6,11, Day 2,6,10, and Day 2,6,11.

Thus, he is bound to work on Day 6.

Sample Input 2

5 2 3
ooxoo

Sample Output 2

1
5

There is only one possible choice for his workdays: Day 1,5.

Sample Input 3

5 1 0
ooooo

Sample Output 3

There may be no days on which he is bound to work.

Sample Input 4

16 4 3
ooxxoxoxxxoxoxxo

Sample Output 4

11
16


var
	N,X,Y,loop,k,ans,z,t:Longint;
begin
	read(N,X,Y);
	loop:=Y-X+1;
	for k:=1 to N-1 do begin
		ans:=0;
		if X<k then z:=X-1 else z:=k-1;
		if k-z<=loop div 2 then begin
			if 2*k-loop-1>0 then t:=2*k-loop-1 else t:=0;
			inc(ans,(z-t div 2)*2);
			if(loop mod 2=0)and(loop div 2<k)and(k-loop div 2<X)then dec(ans);
		end;
		if N-Y<k-1 then z:=N-Y else z:=k-1;
		if k-z<=loop div 2 then begin
			if 2*k-loop-1>0 then t:=2*k-loop-1 else t:=0;
			inc(ans,(z-t div 2)*2);
			if(loop mod 2=0)and(loop div 2<k)and(k-loop div 2<N+1-Y)then dec(ans);
		end;
		if N+1+X-Y>k then inc(ans,N+1+X-Y-k);
		if k=1 then dec(ans)else begin
			if X-1>=k-1 then dec(ans);
			if N-Y>=k-1 then dec(ans);
		end;
		if k*2<loop then begin
			inc(ans,loop);
		end else if k*2=loop then begin
			inc(ans,loop div 2);
		end;
		writeln(ans);
	end;
end.

Score : 400 points

Problem Statement

We have an undirected graph G with N vertices numbered 1 to N and N edges as follows:

For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1.

There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N-1, solve the problem below:

Find the number of pairs of integers (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j in G is k.

Constraints

3 \leq N \leq 2 \times 10^3

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1, 2, ..., N-1 in this order, print a line containing the answer to the problem.

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

There are five pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 1: (1,2)\,,(2,3)\,,(2,4)\,,(3,4)\,,(4,5).

There are four pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 2: (1,3)\,,(1,4)\,,(2,5)\,,(3,5).

There is one pair (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 3: (1,5).

There are no pairs (i,j) (1 \leq i < j \leq N) such that the shortest distance between Vertex i and Vertex j is 4.

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0


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

Score : 400 points

Problem Statement

We have N balls. The i-th ball has an integer A_i written on it.

For each k=1, 2, ..., N, solve the following problem and print the answer.

Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Constraints

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

1 \leq A_i \leq N

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

For each k=1,2,...,N, print a line containing the answer.

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.

From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5


var
	s:Array[0..9]of String;
	H,W,K,i,j,l,z,now,id,ans:Longint;
	cnt:Array[0..14]of Longint;
	out,take:Boolean;
begin
	readln(H,W,K);
	for i:=0 to H-1 do readln(s[i]);
	ans:=1000000000;
	for z:=0 to (1<<(H-1))-1 do begin
		for j:=0 to 14 do cnt[j]:=0;
		now:=0;
		for j:=0 to H-1 do if ((z>>j)and 1)=1 then inc(now);
		out:=False;
		for j:=0 to W-1 do begin
			id:=0;
			take:=False;
			for l:=0 to H-1 do begin
				if s[l][j+1]='1'then inc(cnt[id]);
				if cnt[id]>K then take:=True;
				if ((z>>l)and 1)=1 then inc(id);
			end;
			if take then begin
				inc(now);
				for l:=0 to id do cnt[l]:=0;
				id:=0;
				for l:=0 to H-1 do begin
					if s[l][j+1]='1'then inc(cnt[id]);
					if cnt[id]>K then out:=True;
					if((z>>l)and 1)=1 then inc(id);
				end;
			end;
		end;
		if(not out)and(ans>now)then ans:=now;
	end;
	writeln(ans);
end.

Score : 500 points

Problem Statement

We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.

The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is 0, and white if S_{i,j} is 1.

We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.

How many times do we need to cut the bar so that every block after the cuts has K or less white squares?

Constraints

1 \leq H \leq 10

1 \leq W \leq 1000

1 \leq K \leq H \times W

S_{i,j} is 0 or 1.

Input

Input is given from Standard Input in the following format:

H W K
S_{1,1}S_{1,2}...S_{1,W}
:
S_{H,1}S_{H,2}...S_{H,W}

Output

Print the number of minimum times the bar needs to be cut so that every block after the cuts has K or less white squares.

Sample Input 1

3 5 4
11100
10001
00111

Sample Output 1

2

For example, cutting between the 1-st and 2-nd rows and between the 3-rd and 4-th columns - as shown in the figure to the left - works.

Note that we cannot cut the bar in the ways shown in the two figures to the right.

Sample Input 2

3 5 8
11100
10001
00111

Sample Output 2

0

No cut is needed.

Sample Input 3

4 10 4
1110010010
1000101110
0011101001
1101000111

Sample Output 3

3


var
	s:Array[0..9]of String;
	H,W,K,i,j,l,z,now,id,ans:Longint;
	cnt:Array[0..14]of Longint;
	out,take:Boolean;
begin
	readln(H,W,K);
	for i:=0 to H-1 do readln(s[i]);
	ans:=1000000000;
	for z:=0 to (1<<(H-1))-1 do begin
		for j:=0 to 14 do cnt[j]:=0;
		now:=0;
		for j:=0 to H-1 do if ((z>>j)and 1)=1 then inc(now);
		out:=False;
		for j:=0 to W-1 do begin
			id:=0;
			take:=False;
			for l:=0 to H-1 do begin
				if s[l][j+1]='1'then inc(cnt[id]);
				if cnt[id]>K then take:=True;
				if ((z>>l)and 1)=1 then inc(id);
			end;
			if take then begin
				inc(now);
				for l:=0 to id do cnt[l]:=0;
				inc(id);
				for l:=0 to H-1 do begin
					if s[l][j+1]='1'then inc(cnt[id]);
					if cnt[id]>K then out:=True;
					if((z>>k)and 1)=1 then inc(id);
				end;
			end;
		end;
		if(not out)and(ans>now)then ans:=now;
	end;
	writeln(ans);
end.


var
  n,s,sum:int64;
  a,f:array[0..3001] of int64;
  i,j:longint;
begin
  readln(n,s);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do
    begin
      for j:=s downto a[i]+1 do f[j]:=(f[j]+f[j-a[i]]) mod 998244353;
      f[a[i]]:=(f[a[i]]+i) mod 998244353;
      sum:=(sum+(n-i+1)*f[s] mod 998244353) mod 998244353;
      f[s]:=0;
    end;
  writeln(sum);
end.

Score : 600 points

Problem Statement

Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S.

For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows:

f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S.

Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N. Since this sum can be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

1 \leq N \leq 3000

1 \leq S \leq 3000

1 \leq A_i \leq 3000

Input

Input is given from Standard Input in the following format:

N S
A_1 A_2 ... A_N

Output

Print the sum of f(L, R), modulo 998244353.

Sample Input 1

3 4
2 2 4

Sample Output 1

5

The value of f(L, R) for each pair is as follows, for a total of 5.

f(1,1) = 0

f(1,2) = 1 (for the sequence (1, 2))

f(1,3) = 2 (for (1, 2) and (3))

f(2,2) = 0

f(2,3) = 1 (for (3))

f(3,3) = 1 (for (3))

Sample Input 2

5 8
9 9 9 9 9

Sample Output 2

0

Sample Input 3

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

Sample Output 3

152


var
	N,S,i,j,A,ans:Longint;
	dp:Array[0..3001]of Longint;
begin
	read(N,S);
	for i:=1 to N do begin
		dp[S]:=i;
		read(A);
		for j:=A to S do begin
			inc(dp[j-A],dp[j]);
			if dp[j-A]>=998244353 then dec(dp[j-A],998244353);
		end;
		inc(ans,dp[0]);
		if ans>=998244353 then dec(ans,998244353);
	end;
	writeln(ans);
end.


uses math;
var n,m,i,j:longint;
    a:array[0..100,0..100]of longint;
    c:char;
begin
  fillchar(a,sizeof(a),$3f);
  a[1,0]:=0;
  readln(n,m);
  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      read(c);
      a[i,j]:=ord(c='#')+min(a[i-1,j],a[i,j-1]);
    end;
    readln;
  end;
  writeln(a[n,m]);
end.

Score : 400 points

Problem Statement

Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left.
Each square is painted black or white.

The grid is said to be good if and only if the following condition is satisfied:

From (1, 1), we can reach (H, W) by moving one square right or down repeatedly, while always being on a white square.

Note that (1, 1) and (H, W) must be white if the grid is good.

Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations.

Choose four integers r_0, c_0, r_1, c_1(1 \leq r_0 \leq r_1 \leq H, 1 \leq c_0 \leq c_1 \leq W). For each pair r, c (r_0 \leq r \leq r_1, c_0 \leq c \leq c_1), invert the color of (r, c) - that is, from white to black and vice versa.

Constraints

2 \leq H, W \leq 100

Input

Input is given from Standard Input in the following format:

H W
s_{11} s_{12} \cdots s_{1W}
s_{21} s_{22} \cdots s_{2W}
\vdots
s_{H1} s_{H2} \cdots s_{HW}

Here s_{rc} represents the color of (r, c) - # stands for black, and . stands for white.

Output

Print the minimum number of operations needed.

Sample Input 1

3 3
.##
.#.
##.

Sample Output 1

1

Do the operation with (r_0, c_0, r_1, c_1) = (2, 2, 2, 2) to change just the color of (2, 2), and we are done.

Sample Input 2

2 2
#.
.#

Sample Output 2

2

Sample Input 3

4 4
..##
#...
###.
###.

Sample Output 3

0

No operation may be needed.

Sample Input 4

5 5
.#.#.
#.#.#
.#.#.
#.#.#
.#.#.

Sample Output 4

4