program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils;
var
	s		:string;
begin
    readln(s);
    if s[length(s)]='s' then writeln(stdout,s+'es')
                        else writeln(stdout,s+'s');
end.

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

Score : 100 points

Problem Statement

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

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

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

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

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

Constraints

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

S contains only lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the plural form of the given Taknese word.

Sample Input 1

apple

Sample Output 1

apples

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

Sample Input 2

bus

Sample Output 2

buses

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

Sample Input 3

box

Sample Output 3

boxs

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 test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils,math;
var
	N,i,cnt	:integer;
    d1,d2   :integer;
	ans	    :string;
begin
    readln(N);
	ans:='No';
    cnt:=0;
    for i:=1 to N do
    begin
        readln(d1,d2);
        if (d1=d2) then
        begin
            inc(cnt);
            if (cnt>=3) then
            begin
            	ans:='Yes';
                //break;
            end;
        end
        else cnt:=0;
    end;

    writeln(stdout,ans);
end.

Score : 200 points

Problem Statement

Tak performed the following action N times: rolling two dice.
The result of the i-th roll is D_{i,1} and D_{i,2}.

Check if doublets occurred at least three times in a row.
Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold.

Constraints

3 \leq N \leq 100

1\leq D_{i,j} \leq 6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
D_{1,1} D_{1,2}
\vdots
D_{N,1} D_{N,2}

Output

Print Yes if doublets occurred at least three times in a row. Print No otherwise.

Sample Input 1

5
1 2
6 6
4 4
3 3
3 2

Sample Output 1

Yes

From the second roll to the fourth roll, three doublets occurred in a row.

Sample Input 2

5
1 1
2 2
3 4
5 5
6 6

Sample Output 2

No

Sample Input 3

6
1 1
2 2
3 3
4 4
5 5
6 6

Sample Output 3

Yes


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

Score : 500 points

Problem Statement

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

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

Constraints

1 \leq N \leq 10^{10}

0 \leq X < M \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X M

Output

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

Sample Input 1

6 2 1001

Sample Output 1

1369

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

Sample Input 2

1000 2 16

Sample Output 2

6

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

Sample Input 3

10000000000 10 99959

Sample Output 3

492443256176507


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


var i:integer;
begin
readln(i);
writeln(1-i);
end.

Score : 100 points

Problem Statement

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

Constraints

0 \leq x \leq 1

x is an integer

Input

Input is given from Standard Input in the following format:

x

Output

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

Sample Input 1

1

Sample Output 1

0

Sample Input 2

0

Sample Output 2

1


var a:Longint;
begin
read(a);
writeln(1-a);
end.


var a,b,c,d,ll,lr,rl,rr,tmp:int64;
begin
readln(a,b,c,d);
ll:=a*c;
rl:=b*c;
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


Program AtCoderBeginnerContest178;

uses
sysutils,strutils, math;

var

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

begin

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

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

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

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

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

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

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

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

writeln(x);

//program 1

{readln(x);

IF (x = 0) THEN

begin
	writeln('1');
end;

IF (x = 1) THEN

begin
	writeln('0');
end;}

end.


uses
sysutils,strutils, math;

var

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

begin

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

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


var

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

begin

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

x:= b * d;

writeln(x);

end.


var

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

begin

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

x:= b * d;

writeln(x);

end.


uses
sysutils,math,strutils;

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

begin

//mod 1000000007;

readln(n);

read(x);
readln(y);

read(a);
readln(b);

read(c);
readln(d);

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

x:= x - (2*x);

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


var
 d,t,s:double;
begin
 readln(d,t,s);
 if s*t>=d then write('Yes')
  else write('No');
end.

Score : 100 points

Problem Statement

Takahashi is meeting up with Aoki.

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

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

Will he arrive in time?

Constraints

1 \leq D \leq 10000

1 \leq T \leq 10000

1 \leq S \leq 10000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

D T S

Output

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

Sample Input 1

1000 15 80

Sample Output 1

Yes

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

Sample Input 2

2000 20 100

Sample Output 2

Yes

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

Sample Input 3

10000 1 1

Sample Output 3

No

He will be late.


var
 d,t,s:double;
begin
 readln(d,t,s);
 if t/s<=t then write('Yes')
  else write('No');
end.


var
  d,t,s:int64;
begin
  readln(d,t,s);
  if t*s>=d then writeln('Yes') else writeln('No');
end.


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


var
  s,t:ansistring;
 function sum(x:ansistring):longint;
  var
    i,j,ans,max:longint;
    y:ansistring;
  begin
    max:=0;
    for i:=1 to length(s)-length(x)+1 do
      begin
        y:=copy(s,i,length(x));ans:=0;
        for j:=1 to length(x) do if x[j]=y[j] then inc(ans);
        if ans>max then max:=ans;
      end;
    exit(max);
  end;
begin
  readln(s);
  readln(t);
  writeln(length(t)-sum(t));
end.

Score : 200 points

Problem Statement

Given are two strings S and T.

Let us change some of the characters in S so that T will be a substring of S.

At least how many characters do we need to change?

Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.

Constraints

The lengths of S and T are each at least 1 and at most 1000.

The length of T is at most that of S.

S and T consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the minimum number of characters in S that need to be changed.

Sample Input 1

cabacc
abc

Sample Output 1

1

For example, changing the fourth character a in S to c will match the second through fourth characters in S to T.

Since S itself does not have T as its substring, this number of changes - one - is the minimum needed.

Sample Input 2

codeforces
atcoder

Sample Output 2

6


var
  n,x,t,s:int64;
begin
  readln(n,x,t);
  if n mod x=0 then s:=n div x else s:=n div x+1;
  writeln(s*t);
end.

Score : 100 points

Problem Statement

Takahashi loves takoyaki - a ball-shaped snack.

With a takoyaki machine, he can make at most X pieces of takoyaki at a time, taking T minutes regardless of the number of pieces to make.

How long does it take to make N takoyaki?

Constraints

1 \leq N,X,T \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X T

Output

Print an integer representing the minimum number of minutes needed to make N pieces of takoyaki.

Sample Input 1

20 12 6

Sample Output 1

12

He can make 12 pieces of takoyaki in the first 6 minutes and 8 more in the next 6 minutes, so he can make 20 in a total of 12 minutes.

Note that being able to make 12 in 6 minutes does not mean he can make 2 in 1 minute.

Sample Input 2

1000 1 1000

Sample Output 2

1000000

It seems to take a long time to make this kind of takoyaki.


program bt;

var s:ansistring;
    t,i:longint;

begin
   readln(s);
   t:=0;
   for i:=1 to length(s) do t:=t+(ord(s[i])-48);
   if (t mod 9=0) then write('Yes') else write('No');
   readln;
end.

Score : 200 points

Problem Statement

An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9.

Determine whether N is a multiple of 9.

Constraints

0 \leq N < 10^{200000}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a multiple of 9, print Yes; otherwise, print No.

Sample Input 1

123456789

Sample Output 1

Yes

The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.

Sample Input 2

0

Sample Output 2

Yes

Sample Input 3

31415926535897932384626433832795028841971693993751058209749445923078164062862089986280

Sample Output 3

No


var s:string;
begin
readln(s);
if (s='RRR') then writeln(3);
if (s='RRS') then writeln(2);
if (s='RSR') then writeln(1);
if (s='RSS') then writeln(1);
if (s='SRR') then writeln(2);
if (s='SRS') then writeln(1);
if (s='SSR') then writeln(1);
if (s='SSS') then writeln(0);
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.


//fpc 3.0.4

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:=i+1 to n-1 do
     for k:=j+1 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.


program bt;

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

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

Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

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

Sample Input 1

6 2 4

Sample Output 1

2

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

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

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

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

Sample Input 2

7 4 3

Sample Output 2

1

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

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

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

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.


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

Score : 100 points

Problem Statement

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

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

Constraints

-40 \leq X \leq 40

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

25

Sample Output 1

No

Sample Input 2

30

Sample Output 2

Yes


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


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

Score : 200 points

Problem Statement

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

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

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

Constraints

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

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

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

Sample Input 1

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

Sample Output 1

3

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

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

Sample Output 3

6


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.


{$R-,S-,Q-,I-,O+}
var n,l,r,ans:longint;s:ansistring;
begin
  readln(n);
  readln(s);
  ans:=0;
  l:=1;
  r:=n;
  while l<r do begin
    while (l<=n) and (s[l]='R') do inc(l);
    while (1<=r) and (s[r]='W') do dec(r);
    if l>=r then break else
    begin
      inc(ans);
      inc(l);
      dec(r);
    end;
  end;
  writeln(ans);
end.

Score : 400 points

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

N
c_{1}c_{2}...c_{N}

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the 1-st and 3-rd stones from the left, resulting in RWWR.

Change the color of the 4-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3


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

Score: 100 points

Problem Statement

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

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

From 400 through 599: 8-kyu

From 600 through 799: 7-kyu

From 800 through 999: 6-kyu

From 1000 through 1199: 5-kyu

From 1200 through 1399: 4-kyu

From 1400 through 1599: 3-kyu

From 1600 through 1799: 2-kyu

From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

400 \leq X \leq 1999

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

725

Sample Output 1

7

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

Thus, 7 is the correct output.

Sample Input 2

1600

Sample Output 2

2

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

Thus, 2 is the correct output.


program bt;

var x,a:integer;

begin
   readln(x);
   a := 0;
   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;
   if (a>0) then write(a);
   readln;
end.


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

Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

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

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

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

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

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

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

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

Sample Input 1

7 2 5
3

Sample Output 1

Yes

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

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

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

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

Sample Input 2

7 4 2
3

Sample Output 2

No

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


program bt;

var 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]:=0;
       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 n,i,t:integer;
    a:array[1..1000] of integer;

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

Score : 200 points

Problem Statement

We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i.

How many squares i satisfy both of the following conditions?

The assigned number, i, is odd.

The written integer is odd.

Constraints

All values in input are integers.

1 \leq N, a_i \leq 100

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \cdots a_N

Output

Print the number of squares that satisfy both of the conditions.

Sample Input 1

5
1 3 4 5 7

Sample Output 1

2

Two squares, Square 1 and 5, satisfy both of the conditions.

For Square 2 and 4, the assigned numbers are not odd.

For Square 3, the written integer is not odd.

Sample Input 2

15
13 76 46 15 50 98 93 77 31 43 84 90 6 24 14

Sample Output 2

3


program jss;
var
    n, i, AC, WA, TLE, RE : longint;
    s : ansistring;
begin
    readln(n);
    AC := 0;
    WA := 0;
    TLE := 0;
    RE := 0;
    for i := 1 to n do begin
        readln(s);
        if s = 'AC' then
            AC += 1
        else if s = 'WA' then
            WA += 1
        else if s = 'TLE' then
            TLE += 1
        else if s = 'RE' then
            RE += 1;
    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 calc;
var
    a : longint;
begin
    readln(a);
    writeln(a + a*a + a*a*a);
end.

Score : 100 points

Problem Statement

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

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

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

Sample Input 1

2

Sample Output 1

14

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

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

Sample Input 2

10

Sample Output 2

1110


program bt;

var a :longint;

begin
   readln(a);
   write(a+a*a+a*a*a);
   readln;
end.


program main;
var n : integer;

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


program minorchange;
var
    s, t : ansistring;
    i, mismatch : longint;
begin
    readln(s);
    readln(t);
    mismatch := 0;
    for i := 1 to length(s) do begin
        if s[i] <> t[i] then
            mismatch += 1;
    end;
    writeln(mismatch);
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 i, n : longint;
    s, t : string;

begin
  readln(s);
  readln(t);
  n := 0;
  for i := 1 to length(s) do
    if s[i] <> t[i] then
      inc(n);
  writeln(n);
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;
    if res = 0 then writeln('-1') else writeln(a - 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.


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;
    if res = a then writeln('-1') else writeln(a - res);
    ending:
end.


program hi;
var c: char;

begin
    readln(c);
    if (ord(c)<= 90) then
        writeln('A')
    else
        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
    a : char;

begin
    readln(a);

    if (ord(a) >= ord('a')) then
        writeln('a')
    else
        writeln('A');
end.


program mixjuice;
var
    cheapest : array[1..1000] of longint;
    current, n, k, i, j, total : longint;
begin
    read(n, k);
    readln;
    for i := 1 to k do
        cheapest[i] := 1000;
    total := 0;

    for i := 1 to n do begin
        read(current);
        for j := 1 to i do begin
            if current < cheapest[j] then begin
                cheapest[j] := current;
                break;
            end;
        end;
    end;

    for i := 1 to k do
        total += cheapest[i];
    writeln(total);
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 mixjuice;
var
    cheapest : array[1..1000] of longint;
    current, n, k, i, j, total : longint;
begin
    read(n, k);
    readln;
    for i := 1 to k do
        cheapest[i] := 1000;
    total := 0;

    for i := 1 to n do begin
        read(current);
        for j := 1 to i do begin
            if current < cheapest[j] then begin
                cheapest[j] := current;
                break;
            end;
        end;
    end;

    for i := 1 to k do
        total += cheapest[i];
        writeln(cheapest[i], ' ', total);
    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 := sum + a[i];

    writeln(sum);
end.


var
	N,T:int64;
begin
	read(N);
	dec(N);
	T:=26;
	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


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

Score : 500 points

Problem Statement

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

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

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

What is xor?

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

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

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

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

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

Constraints

All values in input are integers.

2 \leq N \leq 200000

N is even.

0 \leq a_i \leq 10^9

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

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print a line containing N integers separated with space.

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

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

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

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

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

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

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

Thus, this output is consistent with the given information.


program main;
var a : array[1..5] of integer;
    i : integer;
begin
  for i := 1 to 5 do begin
    read(a[i]);
  end;
  if (a[i] = 0) then writeln(i);
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 fivevar;
var
    i, x : longint;
begin
    for i := 1 to 5 do begin
        read(x);
        if x = 0 then
            break;
    end;
    writeln(i);
end.


program main;
var i, t : integer;
    n : array [1..5] of integer;

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


program ct;
var
    i, x, y : longint;
begin
    read(x, y);
    readln;
    if y mod 2 = 0 then begin
        if (y >= (x * 2)) and (y <= (x * 4)) then begin
            for i := 1 to x do begin
                if y - 4 >= 0 then
                    y -= 4
                else if y - 2 >= 0 then
                    y -= 2
            end;
            if y = 0 then
                writeln('Yes')

            else
                writeln('No')
        end
        else
            writeln('No')
    end
    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;
    if y mod 2 = 0 then begin
        if (y > (x * 2)) and (y < (x * 4)) then begin
            for i := 1 to x do begin
                if y - 4 >= 0 then
                    y -= 4
                else if y - 2 >= 0 then
                    y -= 2
            end;
            if y = 0 then
                writeln('Yes')

            else
                writeln('No')
        end
        else
            writeln('No')
    end
    else
        writeln('No');
end.


var
  x,y:longint;
begin
  readln(x,y);
  if odd(x*4-y) then begin writeln('No');exit;end;
  if x*4-y<0 then begin writeln('No');exit;end;
  if odd(y-x*2) then begin writeln('No');exit;end;
  if y-x*2<0 then begin writeln('No');exit;end;
  writeln('Yes');
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;
begin
readln(a,v);
readln(b,w);
readln(t);
if (w>=v) or (abs(b-a)>t*(v-w))
   then writeln('NO')
   else 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


var a,b,v,w,t: int64;
begin
readln(a,v);
readln(b,w);
readln(t);
if (w>=v) or (b-a>t*(v-w))
   then writeln('NO')
   else writeln('YES')
end.


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


var n : int64;
    i : int64;
    ct,ans,j : longint;
begin
    readln(n);
    i := 2;
    ans := 0;
    while i * i <= n do begin
        if n mod i = 0 then begin
            ct := 0;
            while n mod i = 0 do begin
                n := n div i;
                inc(ct);
            end;
            j := 1;
            while j <= ct do begin
                ct := ct - j;
                inc(j);
                inc(ans);
            end;
        end;
        inc(i);
    end;
    if n <> 1 then inc(ans);
    writeln(ans);
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


Score : 100 points

Problem Statement

In this problem, we use the 24-hour clock.

Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.)
He has decided to study for K consecutive minutes while he is up.
What is the length of the period in which he can start studying?

Constraints

0 \le H_1, H_2 \le 23

0 \le M_1, M_2 \le 59

The time H_1 : M_1 comes before the time H_2 : M_2.

K \ge 1

Takahashi is up for at least K minutes.

All values in input are integers (without leading zeros).

Input

Input is given from Standard Input in the following format:

H_1 M_1 H_2 M_2 K

Output

Print the length of the period in which he can start studying, as an integer.

Sample Input 1

10 0 15 0 30

Sample Output 1

270

Takahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.
It takes 30 minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is 270 minutes, so we should print 270.

Sample Input 2

10 0 12 0 120

Sample Output 2

0

Takahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes 120 minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print 0.


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('bom')
                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;
  if n in [2,4,5,7,9] then writeln('hon')
  else if n in [0,1,6,8] then writeln('pon')
  else if n in [3] then writeln('bon');
end.


program main;
var
    n : integer;
begin
    readln(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.


var
  n, digits: Integer;
  measure: String;

begin
  read(n);

  n := n mod 10;

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

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

  else
  begin
    measure := 'hon';
  end;

  write(measure);

end.


program main;
var n : longint;
    s : string;

begin
  readln(n);
  readln(s);
  if n >= length(s) then
    writeln(s)
  else
    writeln(copy(s, 1, n)+'...');
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 hi;
var
    k: integer;
    s: string;

begin
    readln(k);
    readln(s);
    if (length(s) <= k) then
        writeln(s)
    else
        writeln(copy(s, 1, k), '...');
end.


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

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


var
  k: Integer;
  s, dots: String;

begin
  readln(k);
  readln(s);

  dots := '...';

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

  writeln(s);

end.


var
  a, b, h, m, angle: double;
  distance: double;

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

  angle := Abs((30 * h) - (5.5 * m));

  distance := Sqrt((sqr(a) + sqr(b)) - (2 * (a) * (b) * Cos(angle * pi / 180)));

  writeln(distance);

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.


var
  a, b, h, m, distance, angle: Double;

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

  angle := abs(((30 * h) - (5.5 * m)));

  distance := sqrt((sqr(a) + sqr(b)) - (2 * (a) * (b) * Cos(angle * pi / 180)));

  writeln(distance);

end.


var
  a, b, h, m, distance, angle: Double;

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

  angle := ((30 * h)-(5.5 * m));

  distance := sqrt((sqr(a) + sqr(b)) - (2 * (a)*(b) * Cos(angle)));

  writeln(distance);

end.


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


type X=record a,b:int64;f:Boolean;end;
type SortDataType=X;
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
	if a.a<>b.a then SortCmp:=a.a<b.a else if a.b<>b.b then SortCmp:=a.b<b.b else SortCmp:=False;
end;
const M=1000000007;
var
	N,i,j,sz:Longint;
	f:Boolean;
	a,b,g,tmp,u,v,ans,O:int64;
	Ar:Array[1..200000]of X;
function gcd(a,b:int64):int64;
begin
	if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
begin
	read(N);
	O:=M-1;
	sz:=0;
	for i:=1 to N do begin
		read(a,b);
		if(a=0)and(b=0)then inc(O)else begin
			g:=gcd(a,b);
			a:=a div g;
			b:=b div g;
			if(a<0)or((a=0)and(b>0))then begin
				a:=-a;
				b:=-b;
			end;
			f:=False;
			if b<0 then begin
				tmp:=a;
				a:=-b;
				b:=tmp;
				f:=True;
			end;
			inc(sz);
			Ar[sz].a:=a;
			Ar[sz].b:=b;
			Ar[sz].f:=f;
		end;
	end;
	Sort(Ar,sz);
	i:=1;
	ans:=1;
	while i<=sz do begin
		j:=i;
		u:=1;
		v:=1;
		while(i<=sz)and(Ar[i].a=Ar[j].a)and(Ar[i].b=Ar[j].b)do begin
			if Ar[i].f then u:=u*2 mod M else v:=v*2 mod M;
			inc(i);
		end;
		ans:=ans*(u+v-1)mod M;
	end;
	writeln((ans+O)mod M);
end.

Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

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

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479


program regist;
var
    s, t : string;
    i : longint;
    align : boolean;
begin
    readln(s);
    readln(t);
    align := true;
    for i := 1 to length(s) do
        if t[i] <> s[i] then
            align := false;
    if align then
        writeln('Yes')
    else
        writeln('No');
end.

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

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

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

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

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

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

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

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

Sample Input 2

snuke
snekee

Sample Output 2

No

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

Sample Input 3

a
aa

Sample Output 3

Yes


var
	s,t:string;
begin
	readln(s);
    readln(t);
    if pos(s,t)<>1 then writeln('No') else writeln('Yes');
end.


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


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


program main;
var
    n, k, i, j, t1, t2, ans : integer;
    e : array[1..100] of boolean;
begin
    readln(n, k);

    for i := 1 to n do
        e[i] := true;

    ans := n;
    for i := 1 to k do begin
        readln(t1);
        for j := 1 to t1 do begin
            read(t2);
            if (e[t2]) then begin
                e[t2] := false;
                ans := ans - 1;
            end;
        end;
    end;

    writeln(ans);
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
	i,j:integer;
    arr:array[1..1000] of integer;
    n,k,d,input:integer;
begin
	readln(n,k);
    for i:=1 to n do arr[i]:=0;
    for i:=1 to k do begin
    	readln(d);
        for j:=1 to d do begin
        	read(input);
            inc(arr[input]);
        end;
    end;
    input:=0;
    for i:=1 to n do begin
    	if arr[i]=0 then input:=input+1;
    end;
    writeln(input);
end.


var
	N,M,i,u,v,cnt:Longint;
	H:Array[1..100000]of Longint;
	ok:Array[1..100000]of Boolean;
begin
	read(N,M);
	for i:=1 to N do read(H[i]);
	for i:=1 to M do begin
		read(u,v);
		if H[u]>=H[v]then ok[v]:=True;
		if H[v]>=H[u]then ok[u]:=True;
	end;
	for i:=1 to N do if not ok[i]then inc(cnt);
	writeln(cnt);
end.

Score : 300 points

Problem Statement

There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.

Obs. i is said to be good when its elevation is higher than those of all observatories that can be reached from Obs. i using just one road.
Note that Obs. i is also good when no observatory can be reached from Obs. i using just one road.

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
H_1 H_2 ... H_N
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Print the number of good observatories.

Sample Input 1

4 3
1 2 3 4
1 3
2 3
2 4

Sample Output 1

2

From Obs. 1, you can reach Obs. 3 using just one road. The elevation of Obs. 1 is not higher than that of Obs. 3, so Obs. 1 is not good.

From Obs. 2, you can reach Obs. 3 and 4 using just one road. The elevation of Obs. 2 is not higher than that of Obs. 3, so Obs. 2 is not good.

From Obs. 3, you can reach Obs. 1 and 2 using just one road. The elevation of Obs. 3 is higher than those of Obs. 1 and 2, so Obs. 3 is good.

From Obs. 4, you can reach Obs. 2 using just one road. The elevation of Obs. 4 is higher than that of Obs. 2, so Obs. 4 is good.

Thus, the good observatories are Obs. 3 and 4, so there are two good observatories.

Sample Input 2

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

Sample Output 2

3


var
	X,A,B:int64;
begin
	read(X);
	A:=1;
	while True do begin
		B:=-A;
		while B<=A do begin
			if A*A*A*A*A-B*B*B*B*B=X then begin
				writeln(A,' ',B);
				exit;
			end;
			inc(B);
		end;
		inc(A);
	end;
end.

Score : 400 points

Problem Statement

Give a pair of integers (A, B) such that A^5-B^5 = X.
It is guaranteed that there exists such a pair for the given integer X.

Constraints

1 \leq X \leq 10^9

X is an integer.

There exists a pair of integers (A, B) satisfying the condition in Problem Statement.

Input

Input is given from Standard Input in the following format:

X

Output

Print A and B, with space in between.
If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

A B

Sample Input 1

33

Sample Output 1

2 -1

For A=2 and B=-1, A^5-B^5 = 33.

Sample Input 2

1

Sample Output 2

0 -1


program main;
var k, a, b, x : integer;
begin
	readln(k);
    readln(a, b);

    x := b - a;

    if b = a
        then x := 1;

    if x >= k
        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 main;
var
    K, A, B, i : integer;
    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 found then
    writeln('OK')
else
    writeln('NG');
end.


var
	x, y, z : integer;
	i : integer;
    ok : boolean;
begin
	ok := false;
    i := x;
	readln(x);
    readln(y, z);
    while i <= z do
    begin
    	if (i >= y) and (i <= z) then
        	ok := true;
        i := i + x;
    end;
    if ok then
    	writeln('OK')
    else
    	writeln('NG');
end.


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


var
	K,A,B:Longint;
begin
	read(K,A,B);
	dec(A);
	if A div K<>B div K then writeln('OK')else writeln('NG');
end.


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


program main;
var x, i : int64;
    year : integer;
begin
	readln(x);
    i := 100;
    year := 0;

    while i < x do begin
        i := trunc(i * 1.01);
        year := year + 1;
    end;

    writeln(year);
end.

Score : 200 points

Problem Statement

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

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

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

Constraints

101 \le X \le 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

103

Sample Output 1

3

The balance after one year is 101 yen.

The balance after two years is 102 yen.

The balance after three years is 103 yen.

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

Sample Input 2

1000000000000000000

Sample Output 2

3760

Sample Input 3

1333333333

Sample Output 3

1706


var
	a, cnt, x : int64;

begin
	a := 100;
    cnt := 0;
    readln(x);
    while (a < x) do
    begin
    	a := trunc(a * 1.01);
        cnt := cnt + 1;
    end;
    writeln(cnt);
end.


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

    writeln(count);
end.


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


var X,N,C:int64;
begin
read(X);
N:=100;
C:=0;
while N<X do begin
inc(N,N div 100);
inc(C);
end;
writeln(C);
end.


var
	A,B,C,N:int64;
begin
	read(A,B,N);
	C:=B-1;
	if C>N then C:=N;
	writeln(A*C div B);
end.

Score : 400 points

Problem Statement

Given are integers A, B, and N.

Find the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N.

Here floor(t) denotes the greatest integer not greater than the real number t.

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

Print the maximum possible value of floor(Ax/B) - A × floor(x/B) for a non-negative integer x not greater than N, as an integer.

Sample Input 1

5 7 4

Sample Output 1

2

When x=3, floor(Ax/B)-A×floor(x/B) = floor(15/7) - 5×floor(3/7) = 2. This is the maximum value possible.

Sample Input 2

11 10 9

Sample Output 2

9


program train;
var
    s, w : longint;
begin
    read(s, w);
    if w >= s
        then write('unsafe')
        else write('safe');
end.

Score : 100 points

Problem Statement

There are S sheep and W wolves.

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

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

Constraints

1 \leq S \leq 100

1 \leq W \leq 100

Input

Input is given from Standard Input in the following format:

S W

Output

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

Sample Input 1

4 5

Sample Output 1

unsafe

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

Sample Input 2

100 2

Sample Output 2

safe

Many a sheep drive away two wolves.

Sample Input 3

10 10

Sample Output 3

unsafe


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


program main;
var
	a,b : int64;
begin
	readln(a,b);
    if a>b
    	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 hi;
type ars = array[1..200000] of string[10];
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.

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;
        if i1 <= m then
            while i1 <= m do begin
                tmp[i] := a[i1];
                inc(i1); inc(i);
            end
        else
            while i2 <= r do begin
                tmp[i] := a[i2];
                inc(i2); inc(i);
            end;
        for i := l to r do
            a[i] := tmp[i];
    end;
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..10000] of string;
    t : boolean;
begin
    c := 0;
    t := true;
    readln(n);
    for i := 1 to n do begin
        readln(a[i]);
        if i > 1 then
        for j := 1 to i-1 do
            if a[i] = a[j]
            then t := false;
        if t = true
        then inc(c)
        else t:=true;
    end;
    writeln(c);
end.


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

var
    n, i, count : longint;
    list : arr;
    listofnew : arr;
    k : string;
    new : boolean;

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);
    listofnew[1] := list[1];
    count := 1;
    for i := 1 to n do begin
        new := true;
        for k in listofnew do begin
            if k = list[i] then begin
                new := false;
                break;
            end
        end;
        if new then begin
            count += 1;
            listofnew[count] := list[i]
        end;
    end;
    writeln(count);
end.


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

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

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

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

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


program gacha;
var
    n, i, j, count : longint;
    list : array[1..200000] of string ;
    listofnew : array[1..200000] of string;
    temp, k : string;
    new : boolean;
begin
    readln(n);
    for i := 1 to n do
        readln(list[i]);

    for i := 1 to n - 1 do begin
        for j := 1 to n - i do begin
            if list[j] > list[j + 1] then begin
                temp := list[j];
                list[j] := list[j + 1];
                list[j + 1] := temp;
            end;
        end;
    end;

    listofnew[1] := list[1];
    count := 1;
    for i := 1 to n do begin
        new := true;
        for k in listofnew do begin
            if k = list[i] then begin
                new := false;
                break;
            end
        end;
        if new then begin
            count += 1;
            listofnew[count] := list[i]
        end;
    end;
    writeln(count);
end.


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


program HelloWorld;
var
    i, x, m, n : integer;
begin
    readln(m, n);
    for i := 1 to n do begin
        read(x);
        m := m - x;
    end;
    if m >= 0
        then writeln(m)
        else writeln(-1);
end.


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

    for i := 1 to m do begin
        read(temp);
        n -= temp;
    end;

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


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


var N,i,X,S,A:Longint;
begin
read(X,N);
for i:=1 to N do begin
read(A);
inc(S,A);
end;
if S>X then writeln(-1)else writeln(X-S);
end.


Uses math;
Var n,m,i,a:Longint;
    sum:Int64;
Begin
    Readln(n,m);
    For i:=1 to m do begin
        Read(a);
        sum:=sum+a;
    End;
    Writeln(max(n-sum,-1));
End.


var
	i,n,input:longint;
    arr: array [1..200005] of integer;
begin
	readln(n);
    for i:=1 to n do arr[i]:=0;
    for i:=1 to n-1 do begin
    	read(input);
        inc(arr[input]);
    end;
    for i:=1 to n do writeln(arr[i]);
end.

Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

1 \leq A_i < i

Input

Input is given from Standard Input in the following format:

N
A_2 ... A_N

Output

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

Sample Input 1

5
1 1 2 2

Sample Output 1

2
2
0
0
0

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

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

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

Sample Input 2

10
1 1 1 1 1 1 1 1 1

Sample Output 2

9
0
0
0
0
0
0
0
0
0

Sample Input 3

7
1 2 3 4 5 6

Sample Output 3

1
1
1
1
1
1
0


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


var
	n, k : integer;
    a : array[0..200005] of integer;
    i : integer;

begin
	readln(n);
    for i := 2 to n do
    begin
    	read(k);
        a[k] := a[k] + 1;
    end;
    writeln;
    for i := 1 to n do
    	writeln(a[i]);
end.


program main;
var
  n, i, a : LongInt;
  cnt : array[1..200000] of LongInt;
begin
  for i := 1 to n do
    cnt[i] := 0;

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

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


var n,i,m:longint;
    a:array[0..200000]of longint;
begin
  readln(n);
  for i:=2 to n do
  begin
    read(m);
    inc(a[m]);
  end;
  for i:=1 to n do
    write(a[i],' ');
end.


var n, i, x : longint;
    cnt : array of longint;

begin
    readln(n);
    setlength(cnt, n);
    for i := low(cnt) to high(cnt) do cnt[i] := 0;
    for i := 1 to n - 1 do
    begin
        read(x);
        inc(cnt[x - 1]);
    end;
    for i := low(cnt) to high(cnt) do writeln(cnt[i]);
end.


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


type SortDataType=Longint;
function SortCmp(const x,y: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;
var
	N,i,j,k:Longint;
	A:Array[1..2000]of int64;
	id:Array[1..2000]of Longint;
	dp:Array[1..2001,1..2001]of int64;
	ans:int64;
function SortCmp(const x,y:SortDataType):Boolean;
begin
	SortCmp:=A[x]>A[y];
end;
procedure chmax(var a:int64;b:int64);
begin
	if a<b then a:=b;
end;
begin
	read(N);
	for i:=1 to N do begin
		id[i]:=i;
		read(A[i]);
	end;
	Sort(id,N);
	for i:=1 to N do for j:=1 to i do begin
		k:=N+1-(i-j);
		chmax(dp[j+1,k],dp[j,k]+A[id[i]]*abs(id[i]-j));
		chmax(dp[j,k-1],dp[j,k]+A[id[i]]*abs(id[i]-(k-1)));
	end;
	for i:=1 to N+1 do chmax(ans,dp[i,i]);
	writeln(ans);
end.

Score : 500 points

Problem Statement

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

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

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

Find the maximum total happiness points the children can earn.

Constraints

2 \leq N \leq 2000

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum total happiness points the children can earn.

Sample Input 1

4
1 3 4 2

Sample Output 1

20

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

Sample Input 2

6
5 5 6 1 1 1

Sample Output 2

58

Sample Input 3

6
8 6 9 1 2 1

Sample Output 3

85