var
i,N,x,T:Longint;
A:Array[0..100000]of Longint;
begin
read(N);
for i:=1 to N do begin read(x);inc(A[x]);end;
if N mod 2=1 then if A[0]=1 then T:=1 else T:=0 else T:=1;
i:=N mod 2+1;
while i<N do begin
if A[i]=2 then T:=T*2 mod 1000000007 else T:=0;
inc(i,2);
end;
writeln(T);
end.


var a:char;
const vocal:set of char=['A','a','E','e','I','i','O','o','U','u'];
begin readln(a);
if a in vocal then writeln('vowel') else writeln('consonant'); end.

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

Score : 100 points

Problem Statement

Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u.

Constraints

c is a lowercase English letter.

Input

The input is given from Standard Input in the following format:

c

Output

If c is a vowel, print vowel. Otherwise, print consonant.

Sample Input 1

a

Sample Output 1

vowel

Since a is a vowel, print vowel.

Sample Input 2

z

Sample Output 2

consonant

Sample Input 3

s

Sample Output 3

consonant

Submitted source-code file size, in bytes.

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

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


var s:ansistring;
begin
  readln;
  while not eof do
  begin
    readln(s);
    writeln(s,chr(13),s);
  end;
end.


var
  ch:char;
  x:string;
  n,m,i,j:longint;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      x:='';
      for j:=1 to m do begin read(ch);x:=x+ch;end;
      writeln(x);
      writeln(x);
    end;
end.


var
  ch:char;
  x:string;
  n,m,i,j:longint;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      x:='';
      for j:=1 to m do begin read(ch);x:=x+ch;end;
      write(x,x);
    end;
end.


var i:Byte;s:String[100];begin readln();for i:=1 to 100 do begin readln(s);writeln(s);writeln(s)end;end.


var s:String[100];
begin readln();
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
end.


var i:Longint;s:String[100];
begin readln();
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
readln(s);writeln(s);writeln(s);
end.


var i:Longint;s:String[100];begin readln();for i:=1 to 100 do begin readln(s);writeln(s);writeln(s)end;end.


var a,i:Longint;s:String[100];begin readln(a);for i:=1 to a do begin readln(s);writeln(s);writeln(s)end;end.


var a,b,i:Longint;s:String[100];begin readln(a,b);for i:=1 to a do begin readln(s);writeln(s);writeln(s)end;end.


var a:array[1..201,1..201] of char;
    n,m,i,j:byte;
begin
readln(n,m);
for i:=1 to n do begin
  for j:=1 to m do read(a[i,j]); readln; end;
for i:=1 to n*2 do begin
  for j:=1 to m do write(a[(i+1)div 2,j]); writeln; end;
end.


var a,b:array[1..201,1..201] of char;
    n,m,i,j:byte;
begin
readln(n,m);
for i:=1 to n do begin
  for j:=1 to m do read(a[i,j]); readln; end;
for i:=1 to n*2 do begin
  for j:=1 to m do write(a[i,j]); writeln;
  for j:=1 to m do write(a[i,j]); writeln;  end;
end.


program D;
    var N,K,L:int64;
    var root:array[1..250005]of int64;
    var size:array[1..250005]of int64;
    var colr:array[1..250005]of int64;
    var i,j,p,q:longint;
    function FindRoot(_:int64):int64;
    begin
        if root[_]=_ then exit(_) else exit(FindRoot(root[_]));
    end;
    procedure Merge(_x,_y:int64);
        var x,y:int64;
    begin
        x:=FindRoot(_x);
        y:=FindRoot(_y);
        if x<>y then
            if size[x]<size[y] then
            begin
                root[x]:=y;
                size[y]:=size[y]+size[x];
            end
            else
            begin
                root[y]:=x;
                size[x]:=size[y]+size[x];
            end;
    end;
begin
    readln(N,K,L);
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;
    for i:=1 to K do
    begin
        readln(p,q);
        Merge(p,q);
    end;
    for i:=1 to N do colr[i]:=FindRoot(i);
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;
    for i:=1 to L do
    begin
        readln(p,q);
        if colr[p]=colr[q] then Merge(p,q);
    end;
    for i:=1 to N do write(size[FindRoot(i)],' ');
end.

Score : 400 points

Problem Statement

There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.

We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define connectivity by railways similarly.

For each city, find the number of the cities connected to that city by both roads and railways.

Constraints

2 ≦ N ≦ 2*10^5

1 ≦ K, L≦ 10^5

1 ≦ p_i, q_i, r_i, s_i ≦ N

p_i < q_i

r_i < s_i

When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)

When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)

Input

The input is given from Standard Input in the following format:

N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L

Output

Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.

Sample Input 1

4 3 1
1 2
2 3
3 4
2 3

Sample Output 1

1 2 2 1

All the four cities are connected to each other by roads.

By railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.

Sample Input 2

4 2 2
1 2
2 3
1 4
2 3

Sample Output 2

1 2 2 1

Sample Input 3

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

Sample Output 3

1 1 2 1 2 2 2


program D;
    var N,K,L:longint;
    var root:array[1..200005]of longint;
    var size:array[1..200005]of longint;
    var colr:array[1..200005]of longint;
    var i,j,p,q:longint;
    function FindRoot(_:longint):longint;
    begin
        if root[_]=_ then exit(_) else exit(FindRoot(root[_]));
    end;
    procedure Merge(_x,_y:longint);
        var x,y:longint;
    begin
        x:=FindRoot(_x);
        y:=FindRoot(_y);
        if x<>y then
            if size[x]<size[y] then
            begin
                root[x]:=y;
                size[y]:=size[y]+size[x];
            end
            else
            begin
                root[y]:=x;
                size[x]:=size[y]+size[x];
            end;
    end;
begin
    readln(N,K,L);
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;
    for i:=1 to K do
    begin
        readln(p,q);
        Merge(p,q);
    end;
    for i:=1 to N do colr[i]:=FindRoot(i);
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;
    for i:=1 to L do
    begin
        readln(p,q);
        if colr[p]=colr[q] then Merge(p,q);
    end;
    for i:=1 to N do write(size[FindRoot(i)],' ');
end.


program D;
    var N,K,L:longint;
    var root:array[1..100005]of longint;
    var size:array[1..100005]of longint;
    var colr:array[1..100005]of longint;
    var i,j,p,q:longint;
    function FindRoot(_:longint):longint;
    begin
        if root[_]=_ then exit(_) else exit(FindRoot(root[_]));
    end;
    procedure Merge(_x,_y:longint);
        var x,y:longint;
    begin
        x:=FindRoot(_x);
        y:=FindRoot(_y);
        if x<>y then
            if size[x]<size[y] then
            begin
                root[x]:=y;
                size[y]:=size[y]+size[x];
            end
            else
            begin
                root[y]:=x;
                size[x]:=size[y]+size[x];
            end;
    end;
begin
    readln(N,K,L);
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;
    for i:=1 to K do
    begin
        readln(p,q);
       {Merge(p,q);}
    end;
 {   for i:=1 to N do
    begin
        colr[i]:=FindRoot(i);
    end;
    for i:=1 to N do
    begin
        root[i]:=i;
        size[i]:=1;
    end;    }
    for i:=1 to L do
    begin
        readln(p,q);
       { if colr[p]=colr[q] then Merge(p,q);}
    end;
  { for i:=1 to N-1 do write(size[FindRoot(i)],' ');
    writeln(size[FindRoot(N)])}
end.


var
a,b,x,i,k,s:longint;
begin
read(a,b,x);
for i:=a to b do
 begin
  k:=i;
  if k mod x=0 then inc(s);
 end;
 writeln(s);
 end.

Score : 200 points

Problem Statement

You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?

Constraints

0 ≤ a ≤ b ≤ 10^{18}

1 ≤ x ≤ 10^{18}

Input

The input is given from Standard Input in the following format:

a b x

Output

Print the number of the integers between a and b, inclusive, that are divisible by x.

Sample Input 1

4 8 2

Sample Output 1

3

There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.

Sample Input 2

0 5 1

Sample Output 2

6

There are six integers between 0 and 5, inclusive, that are divisible by 1: 0, 1, 2, 3, 4 and 5.

Sample Input 3

9 9 2

Sample Output 3

0

There are no integer between 9 and 9, inclusive, that is divisible by 2.

Sample Input 4

1 1000000000000000000 3

Sample Output 4

333333333333333333

Watch out for integer overflows.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,b,x:Int64;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(a);
    Read(b);
    Readln(x);

    Writeln(b div x - (a-1) div x );
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


var
 n,x,i:longint;
 ans,now:int64;
 a:array[0..100001] of longint;
begin
 readln(n,x);
 for i:=1 to n do
  read(a[i]);
 for i:=1 to n do
  begin
   if now+a[i]<=x then now:=a[i]
    else
     begin
      ans:=ans+now+a[i]-x;
      now:=a[i]-(now+a[i]-x);
     end;
  end;
 writeln(ans);
end.

Score : 300 points

Problem Statement

There are N boxes arranged in a row.
Initially, the i-th box from the left contains a_i candies.

Snuke can perform the following operation any number of times:

Choose a box containing at least one candy, and eat one of the candies in the chosen box.

His objective is as follows:

Any two neighboring boxes contain at most x candies in total.

Find the minimum number of operations required to achieve the objective.

Constraints

2 ≤ N ≤ 10^5

0 ≤ a_i ≤ 10^9

0 ≤ x ≤ 10^9

Input

The input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the minimum number of operations required to achieve the objective.

Sample Input 1

3 3
2 2 2

Sample Output 1

1

Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2).

Sample Input 2

6 1
1 6 1 2 0 4

Sample Output 2

11

For example, eat six candies in the second box, two in the fourth box, and three in the sixth box.
Then, the number of candies in each box becomes (1, 0, 1, 0, 0, 1).

Sample Input 3

5 9
3 1 4 1 5

Sample Output 3

0

The objective is already achieved without performing operations.

Sample Input 4

2 0
5 5

Sample Output 4

10

All the candies need to be eaten.


var n,x,y,z,i,j,k,ans:longint;
a:array[1..1000000]of longint;
begin
    readln(n,x);
    for i:=1 to n do
    begin
        read(a[i]);
    end;
    for i:=1 to n-1 do
    begin
  //  writeln(i);
        if a[i]+a[i+1]>x then
        begin
            if (i+2<=n)then
            begin
                if a[i+2]+a[i+1]>x then
                begin
                    y:=a[i+1]-(x-a[i]);
                    z:=a[i+1]-(x-a[i+2]);
                    if y>z then
                    begin
                       ans:=ans+y;
                       if y>a[i+1] then
                       begin
                           a[i+2]:=a[i+1]-(y-ans);
                           a[i+1]:=0;
                       end
                       else a[i+1]:=a[i+1]-y;
                    end
                    else
                    begin
                        ans:=ans+z;
                      //  writeln('2');
                        if z>a[i+1] then
                        begin
                           a[i+2]:=a[i+2]-(z-a[i+1]);
                           a[i+1]:=0;
                        end
                        else a[i+1]:=a[i+1]-z;
                    end;
                end;
            end
            else
            begin
                y:=a[i+1]+a[i]-x;
                if a[i+1]-y<=0 then
                begin
                    a[i]:=a[i]-(y-a[i+1]);
                    a[i+1]:=0;
                end
                else
                  a[i+1]:=a[i+1]-y;
                ans:=ans+y;
            end;
        end;
    end;
  //  for i:=1 to n do
  //    write(a[i],' ');
    writeln(ans);
end.


var n,x,y,z,i,j,k,ans:longint;
a:array[1..1000000]of longint;
begin
    readln(n,x);
    for i:=1 to n do
    begin
        read(a[i]);
    end;
    for i:=1 to n-1 do
    begin
  //  writeln(i);
        if a[i]+a[i+1]>x then
        begin
            if (i+2<=n)then
            begin
                if a[i+2]+a[i+1]>x then
                begin
                    y:=a[i+1]-(x-a[i]);
                    z:=a[i+1]-(x-a[i+2]);
                    if y>z then
                    begin
                       ans:=ans+y;
                       if y>a[i+1] then
                       begin
                           a[i+2]:=a[i+1]-(y-ans);
                           a[i+1]:=0;
                       end
                       else a[i+1]:=a[i+1]-y;
                    end
                    else
                    begin
                        ans:=ans+z;
                      //  writeln('2');
                        if z>a[i+1] then
                        begin
                           a[i+2]:=a[i+1]-(z-ans);
                           a[i+1]:=0;
                        end
                        else a[i+1]:=a[i+1]-z;
                    end;
                end;
            end
            else
            begin
                y:=a[i+1]+a[i]-x;
                if a[i+1]-y<=0 then
                  a[i]:=a[i]-(a[i+1]-y);

                a[i+1]:=a[i+1]-y;
                ans:=ans+y;
            end;
        end;
    end;
    writeln(ans);
end.


var n,x,i,j,sum,sum2:longint;
    o:array[1..100000]of longint;
    o2:array[1..100000]of longint;
begin
readln(n,x);
read(o[1]);
o2[1]:=o[1];
for i:=2 to n do
begin
  read(o[i]);
  o2[i]:=o[i];
  if o[i]+o[i-1]>x then
    begin
    sum:=sum+o[i]+o[i-1]-x;
    o[i]:=o[i]-(o[i]+o[i-1]-x);
    if o[i]<0 then
    begin
      o[i-1]:=o[i-1]+o[i];
      o[i]:=0;
    end;
    end;
end;
for j:=n downto 2 do
begin
  if o2[j]+o2[j-1]>x then
  begin
    sum2:=sum2+o2[j]+o2[j-1]-x;
    o2[j-1]:=o2[j-1]-(o2[j]+o2[j-1]-x);
    if o2[j-1]<0 then
    begin
      o2[j]:=o2[j]+o2[j-1];
      o2[j-1]:=0;
    end;
  end;
end;
if sum<sum2 then
writeln(sum2)
else
writeln(sum);
end.


program taskJ;
var n,x,i,j,sum,sum2:longint;
    o:array[1..100000]of longint;
    o2:array[1..100000]of longint;
begin
readln(n,x);
read(o[1]);
o2[1]:=o[1];
for i:=2 to n do
begin
  read(o[i]);
  o2[i]:=o[i];
  if o[i]+o[i-1]>x then
    begin
    sum:=sum+o[i]+o[i-1]-x;
    o[i]:=o[i]-(o[i]+o[i-1]-x);
    if o[i]<0 then
    begin
      o[i-1]:=o[i-1]+o[i];
      o[i]:=0;
    end;
    end;
end;
for j:=n downto 2 do
begin
  if o2[j]+o2[j-1]>x then
  begin
    sum2:=sum2+o2[j]+o2[j-1]-x;
    o2[j-1]:=o2[j-1]-(o2[j]+o2[j-1]-x);
    if o2[j-1]<0 then
    begin
      o2[j]:=o2[j]+o2[j-1];
      o2[j-1]:=0;
    end;
  end;
end;
for i:=1 to n do
write(o[i],' ');
writeln();
for j:=1 to n do
write(o2[i],' ');
writeln();
if sum<sum2 then
writeln(sum2)
else
writeln(sum);
end.


var cc : array [0..100000] of int64 ;
    n,a,b,c,d,e,f,g : longint;
    h,i,j,k,x,sum : int64 ;
begin
 readln(n,x);
// writeln(sum,cc[1]:2,cc[2]:2,cc[3]:2);
 for a:=1 to n do
  read(cc[a]);
// writeln(sum,cc[1]:2,cc[2]:2,cc[3]:2);
 for b:=1 to n-1 do
  begin
// writeln(j,sum:2,cc[1]:2,cc[2]:2,cc[3]:2);
   j:=x;
   if cc[b]+cc[b+1]>j then
    begin
    if cc[b]>j then
     begin
      sum:=sum+(cc[b]-j);
      cc[b]:=cc[b]-(cc[b]-j) ;
     end;
    if cc[b]+cc[b+1]>j then
    begin
     k:=cc[b]+cc[b+1];
     if k-cc[b+1]<=j then
      begin
       sum:=sum+(k-j);
       cc[b+1]:=cc[b+1]-(k-j);
      end
     else if k-cc[b+1]>j then
      begin
       sum:=sum+cc[b+1];
       k:=k-cc[b+1];
       cc[b+1]:=0;
       sum:=sum+(k-j);
      end;
{    if cc[b+1]-j>=0 then
     begin
      sum:=sum+(cc[b+1]-j);
      writeln('hey',sum);
      cc[b+1]:=j;
     end
    else
     begin

      sum:=sum+cc[b+1];
      j:=j-cc[b+1];
      cc[b+1]:=0;
      sum:=sum+j;
      cc[b]:=cc[b]-j;

     end; }
    end;
//    writeln(sum);
   end;
  end;
 writeln(sum);
end.


var
n,i:longint;
x,o:int64;
a:array [0..100001] of int64;
begin
readln(n,x);
for i := 1 to n do
begin
read(a[i]);
if a[i]>x then
begin
o:=o+(a[i]-x);
a[i]:=x;
end;
end;
for i := 1 to n-1 do
begin
if a[i]+a[i+1]>x then
begin
o:=o+(a[i]+a[i+1]-x);
a[i+1]:=x-a[i];
end;
end;
writeln(o);
end.


var
  n:string;
begin
  readln(n);
  if n[1]=n[length(n)] then
    begin
      if odd(length(n)) then writeln('Second')
        else writeln('First');
    end
    else
      begin
        if odd(length(n)) then writeln('First')
         else writeln('Second');
      end;
end.

Score : 500 points

Problem Statement

There is a string s of length 3 or greater.
No two neighboring characters in s are equal.

Takahashi and Aoki will play a game against each other.
The two players alternately performs the following operation, Takahashi going first:

Remove one of the characters in s, excluding both ends. However, a character cannot be removed if removal of the character would result in two neighboring equal characters in s.

The player who becomes unable to perform the operation, loses the game. Determine which player will win when the two play optimally.

Constraints

3 ≤ |s| ≤ 10^5

s consists of lowercase English letters.

No two neighboring characters in s are equal.

Input

The input is given from Standard Input in the following format:

s

Output

If Takahashi will win, print First. If Aoki will win, print Second.

Sample Input 1

aba

Sample Output 1

Second

Takahashi, who goes first, cannot perform the operation, since removal of the b, which is the only character not at either ends of s, would result in s becoming aa, with two as neighboring.

Sample Input 2

abc

Sample Output 2

First

When Takahashi removes b from s, it becomes ac.
Then, Aoki cannot perform the operation, since there is no character in s, excluding both ends.

Sample Input 3

abcab

Sample Output 3

First


var
        s:string;
begin
        if s[1]=s[length(s)] then
        begin
                if length(s) mod 2=1 then writeln('Second')
                else writeln('First');
        end
        else
        begin
                if length(s) mod 2=0 then writeln('Second')
                else writeln('First');
        end;
end.


var
 st:string;
begin
  readln(st);
  if st[1]=st[length(st)] then
    begin
      if odd(length(st)) then writeln('Second')
        else writeln('First');
    end
    else
    begin
      if not(odd(length(st))) then writeln('Second')
        else writeln('First');
    end
end.


var
 st:string;
begin
  readln(st);
  if st[1]=st[length(st)] then
    begin
      if odd(length(st)) then writeln('Second')
        else writeln('first');
    end
    else
    begin
      if not(odd(length(st))) then writeln('Second')
        else writeln('first');
    end
end.


var
 s:ansistring;
begin
 read(s);
 if (s[1]='a') or (s[length(s)]='a') then writeln('First')
 else writeln('Second');
 end.


var
	n,i,x:Longint;
	ans,a,b:int64;
begin
	read(n,x,a);
	if a>x then begin
		ans:=a-x;
		a:=x;
	end;
	for i:=2 to n do begin
		read(b);
		if a+b>x then begin
			inc(ans,a+b-x);
			dec(b,a+b-x);
		end;
		a:=b;
	end;
	writeln(ans);
end.


var
	n,i,x:Longint;
	ans,a,b:int64;
begin
	read(n,x,a);
	if a>x then begin
		ans:=x-a;
		a:=x;
	end;
	for i:=2 to n do begin
		read(b);
		if a+b>x then begin
			inc(ans,a+b-x);
			dec(b,a+b-x);
		end;
		a:=b;
	end;
	writeln(ans);
end.


program C;
    var N,x,i:longint;
    var a:array [1..120000] of longint;
    var u,v,ans:longint;
begin
    readln(N,x);ans:=0;
    for i:=1 to N do read(a[i]);
    for i:=2 to N do
    begin
        u:=a[i-1];v:=a[i];
        if u+v>x then
        begin
            if v>=u+v-x then a[i]:=x-u
            else
            begin
                a[i]:=0;
                a[i-1]:=x;
            end;
            ans:=ans+u+v-x;
        end;
    end;
    writeln(ans);
end.


var s:string;n:Longint;
begin
readln(s);
n:=length(s);
if(n mod 2=1)xor(s[1]=s[n])then writeln('Second')else writeln('First');
end.


var
  i:longint;
  s,c:ansistring;
  t:char;
begin
  readln(s);
  c:=s;
  for i:=1 to length(c) div 2 do
   begin
     t:=c[i];
     c[i]:=c[length(c)-i+1];
     c[length(c)-i+1]:=t;
   end;
  for i:=1 to length(c) do
   begin
     if c[i]='b' then begin c[i]:='d';continue; end;
     if c[i]='d' then begin c[i]:='b';continue; end;
     if c[i]='p' then begin c[i]:='q';continue; end;
     if c[i]='q' then begin c[i]:='p';continue; end;
   end;
  if s=c then writeln('Yes')
         else writeln('No');
end.

Score : 100 points

Problem Statement

You are given a string S consisting of letters b, d, p and q.
Determine whether S is a mirror string.

Here, a mirror string is a string S such that the following sequence of operations on S results in the same string S:

Reverse the order of the characters in S.

Replace each occurrence of b by d, d by b, p by q, and q by p, simultaneously.

Constraints

1 \leq |S| \leq 10^5

S consists of letters b, d, p, and q.

Input

The input is given from Standard Input in the following format:

S

Output

If S is a mirror string, print Yes. Otherwise, print No.

Sample Input 1

pdbq

Sample Output 1

Yes

Sample Input 2

ppqb

Sample Output 2

No


var i,n:longint;
    a,b:ansistring;
begin
  readln(a);
  n:=length(a);
  for i:=1 to n do b:=a[i]+b;
  for i:=1 to n do
  if b[i]='b' then b[i]:='d'
  else if b[i]='d' then b[i]:='b'
  else if b[i]='p' then b[i]:='q'
  else b[i]:='p';
  if a=b then writeln('Yes')
  else writeln('No');
end.


var i,n:longint;
    a,b:string;
begin
  readln(a);
  n:=length(a);
  for i:=1 to n do b[n-i+1]:=a[i];
  for i:=1 to n do
  if b[i]='b' then b[i]:='d'
  else if b[i]='d' then b[i]:='b'
  else if b[i]='p' then b[i]:='q'
  else b[i]:='p';
  if a=b then writeln('Yes')
  else writeln('No');
end.


var s,s1:string;
    i,len:longint;
begin
 readln(s);
 len:=length(s);
 for i:=1 to len do
 case s[i] of
  'b':s1:='d'+s1;
  'd':s1:='b'+s1;
  'p':s1:='q'+s1;
  'q':s1:='p'+s1;
 end;
 if (s=s1) then writeln('Yes') else writeln('No');
end.


var s,st:ansistring;
    len,i:longint;
    t:char;
begin
  readln(s); st:=s;
  len:=length(s);
  if (len mod 2=1) then begin writeln('No');exit;end;
  for i:=1 to len div 2 do
  begin
   t:=s[i];s[i]:=s[len-i+1];s[len-i+1]:=t;
  end;
  for i:=1 to len do
  begin
    if s[i]='b' then s[i]:='d' else
    if s[i]='d' then s[i]:='b' else
    if s[i]='p' then s[i]:='q' else
    s[i]:='p';
  end;
  if s=st then writeln('Yes') else writeln('No');
end.


var s,st:ansistring;
    len,i:longint;
    t:char;
begin
  readln(s); st:=s;
  len:=length(s);
  if (len mod 2=1) then begin writeln(1);exit;end;
  for i:=1 to len div 2 do
  begin
   t:=s[i];s[i]:=s[len-i+1];s[len-i+1]:=t;
  end;
  for i:=1 to len do
  begin
    if s[i]='b' then s[i]:='d' else
    if s[i]='d' then s[i]:='b' else
    if s[i]='p' then s[i]:='q' else
    s[i]:='p';
  end;
  if s=st then writeln('Yes') else writeln('No');
end.


var i,j,k:longint;
    first,last:string;
    ch:array[char]of char;
begin
  readln(first);
  last:=first;
  for i:=1 to length(last) do
  last[i]:=first[length(first)-i+1];
  ch['p']:='q';
  ch['q']:='p';
  ch['b']:='d';
  ch['d']:='b';
  for i:=1 to length(last) do
  last[i]:=ch[last[i]];
  if first=last then write('Yes') else write('No');
end.


var
        s,s1,s2:ansistring;
        i,l:longint;
begin
        readln(s);
        s2:=s;
        l:=length(s);
        for i:=1 to l do begin
                if s[i]='b' then begin
                        s[i]:='d';
                        continue;
                end;
                if s[i]='d' then begin
                        s[i]:='b';
                        continue;
                end;
                if s[i]='p' then begin
                        s[i]:='q';
                        continue;
                end;
                if s[i]='q' then begin
                        s[i]:='q';
                        continue;
                end;
        end;
        for i:=l downto 1 do s1:=s1+s[i];
        if s1=s2 then writeln('Yes') else writeln('No');
end.


var
        s,s1:ansistring;
        i,l:longint;
begin
        readln(s);
        l:=length(s);
        for i:=1 to l do begin
                if s[i]='b' then begin
                        s[i]:='d';
                        continue;
                end;
                if s[i]='d' then begin
                        s[i]:='b';
                        continue;
                end;
                if s[i]='p' then begin
                        s[i]:='q';
                        continue;
                end;
                if s[i]='q' then begin
                        s[i]:='q';
                        continue;
                end;
        end;
        for i:=l downto 1 do s1:=s1+s[i];
        if s1=s then writeln('Yes') else writeln('No');
end.


var
        s,s1:ansistring;
        i,l:longint;
begin
        readln(s);
        l:=length(s);
        for i:=1 to l div 2 do begin
                if s[i]='b' then begin
                        s[i]:='d';
                        continue;
                end;
                if s[i]='d' then begin
                        s[i]:='b';
                        continue;
                end;
                if s[i]='p' then begin
                        s[i]:='q';
                        continue;
                end;
                if s[i]='q' then begin
                        s[i]:='q';
                        continue;
                end;
        end;
        for i:=l downto 1 do s1:=s1+s[i];
        if s1=s then writeln('Yes') else writeln('No');
end.


var
        s,s1,s2:ansistring;
        i,l:longint;
begin
        readln(s);
        l:=length(s);
        for i:=1 to l div 2 do begin
                if s[i]='b' then begin
                        s[i]:='d';
                        continue;
                end;
                if s[i]='d' then begin
                        s[i]:='b';
                        continue;
                end;
                if s[i]='p' then begin
                        s[i]:='q';
                        continue;
                end;
                if s[i]='q' then begin
                        s[i]:='q';
                        continue;
                end;
        end;
        for i:=1 to l div 2 do s1:=s1+s[i];
        for i:=l downto l div 2+1 do s2:=s2+s[i];
        if s1=s2 then writeln('Yes') else writeln('No');
end.


var
  s:ansistring;
  i,j,n,k,m,t:longint;
begin
  readln(s);
  k:=length(s);
  if k mod 2<>0 then
  begin
    writeln('No');
    halt;
  end;
  for i:=1 to k div 2+1 do
  begin
    t:=abs(ord(s[i])-ord(s[k-i+1]));
    if (t<>1)and(t<>2) then
    begin
      writeln('No');
      halt;
    end;
  end;
  writeln('Yes');
end.


var
 n,i:longint;
 a:array[0..100] of qword;
begin
 read(n);
 a[0]:=2;
 for i:=1 to n do a[i]:=a[i-1]*2+2;
 writeln(a[n]);
end.

Score : 100 points

Problem Statement

We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2:

Operation:
Cut the rope at two positions to obtain three cords, each with a length of a positive integer.
Among these, discard one with the longest length and one with the shortest length, and keep the remaining one.

Let f(N) be the maximum possible number of times to perform this operation, starting with a cord with the length N.

You are given a positive integer X. Find the maximum integer N such that f(N)=X.

Constraints

1 \leq X \leq 40

Input

The input is given from Standard Input in the following format:

X

Output

Print the value of the maximum integer N such that f(N)=X.

Sample Input 1

2

Sample Output 1

14


var a:array[1..41]of qword;
    n,i:longint;
 begin
  readln(n);
  a[1]:=2;
  for i:=2 to n do
   a[i]:=a[i-1]*2+2;
  writeln(a[n+1]);
 end.


var
	N,i,j:Longint;
	A:Array[1..100,1..99]of Longint;
begin
	read(N);
	if N=2 then begin
		writeln(-1);
		exit;
	end;
	if N mod 2=1 then begin
		for i:=1 to N-1 do A[N,i]:=i;
		i:=1;
		while i<=N-1 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
	end else begin
		i:=1;
		while i<=N-2 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
		for j:=1 to N-3 do begin
			A[N-1,j]:=j;
			A[N,j]:=j;
		end;
		A[N-1,N-2]:=N;
		A[N,N-1]:=N-1;
		A[N-1,N-1]:=N-2;
		A[N,N-2]:=N-2;
	end;
	for i:=1 to N do begin
		for j:=1 to N-1 do begin
			writeln(A[i,j]);
		end;
	end;
end.

Score : 100 points

Problem Statement

There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.

During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.

If any two persons look at each other during the challenge, the challenge ends in failure.

Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.

Constraints

2 \leq N \leq 100

Input

The input is given from Standard Input in the following format:

N

Output

If there exists no way to be successful in the challenge, print -1.

If there exists a way to be successful in the challenge, print any such way in the following format:

A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}

where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.

Judging

The output is considered correct only if all of the following conditions are satisfied:

1 \leq A_{i,j} \leq N

For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.

Let X = A_{i, j}, then A_{X, j} \neq i always holds.

Sample Input 1

7

Sample Output 1

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

Sample Input 2

2

Sample Output 2

-1


var
  a,b,c,d,e,ch:char;
  n,m,i,j:longint;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      for j:=1 to m do
        begin
          read(a,b,c,d,e);
          read(ch);
          if c='u' then
            begin
              writeln(char(64+j),i);
              exit;
            end;
        end;
      readln;
    end;
  writeln('NO');
end.

Score : 100 points

Problem Statement

There is a grid with H rows and W columns.

The square at the i-th row and j-th column contains a string S_{i,j} of length 5.

The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from A through the W-th letter of the alphabet.

Exactly one of the squares in the grid contains the string snuke. Find this square and report its location.

For example, the square at the 6-th row and 8-th column should be reported as H6.

Constraints

1≦H, W≦26

The length of S_{i,j} is 5.

S_{i,j} consists of lowercase English letters (a-z).

Exactly one of the given strings is equal to snuke.

Input

The input is given from Standard Input in the following format:

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

Output

Print the labels of the row and the column of the square containing the string snuke, with no space inbetween.

Sample Input 1

15 10
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snuke snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake
snake snake snake snake snake snake snake snake snake snake

Sample Output 1

H6

Sample Input 2

1 1
snuke

Sample Output 2

A1


var
  a,b,c,d,e,ch:char;
  n,m,i,j:longint;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      for j:=1 to m do
        begin
          read(a,b,c,d,e);
          read(ch);
          if (a='s') and (b='n') and (c='u') and (d='k') and (e='e') then
            begin
              writeln(char(64+j),i);
              exit;
            end;
        end;
      readln;
    end;
end.


var
  a:array[0..10000006] of int64;
  n,s:int64;
  i:longint;
begin
  readln(n);
  for i:=1 to n do
    begin
      inc(s,i);
      a[i]:=i;
      if s>n then break;
    end;
  s:=s-n;
  for i:=1 to n do if (a[i]<>s) and (a[i]<>0) then writeln(a[i]);
end.

Score : 300 points

Problem Statement

The problem set at CODE FESTIVAL 20XX Finals consists of N problems.

The score allocated to the i-th (1≦i≦N) problem is i points.

Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve.

As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him.

Determine the set of problems that should be solved.

Constraints

1≦N≦10^7

Partial Score

200 points will be awarded for passing the test set satisfying 1≦N≦1000.

Additional 100 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

N

Output

Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line.

If there exists more than one such set, any of them will be accepted.

Sample Input 1

4

Sample Output 1

1
3

Solving only the 4-th problem will also result in the total score of 4 points, but solving the 1-st and 3-rd problems will lower the highest score of a solved problem.

Sample Input 2

7

Sample Output 2

1
2
4

The set \{3,4\} will also be accepted.

Sample Input 3

1

Sample Output 3

1


var i,k,n:longint;
begin
read(n);
while n>0 do begin
inc(k);
dec(n,k);
end;
for i:=1 to -n-1 do writeln(i);
for i:=1-n to k do writeln(i);
end.


var i,k,n:longint;
begin
read(n);
while k*(k+1)<n*2 do inc(k);
dec(n,k*(k+1)div 2);
for i:=1 to -n-1 do writeln(i);
for i:=1-n to k do writeln(i);
end.


var i,k,n:longint;
begin
read(n);
k:=round(sqrt(2*n));
while k*(k+1)<n*2 do inc(k);
while k*(k-1)>=2*N do dec(k);
dec(n,k*(k+1)div 2);
for i:=1 to k do if i<>-n then writeln(i);
end.


var
	N,i,a:Longint;
	x:int64;
	p:Array[1..20000]of Longint;
begin
	read(N);
	for i:=1 to N do begin
		writeln((N+1)*i);
		read(a);
		p[a]:=i;
	end;
	for i:=1 to N do begin
		x:=N+1;
		writeln(x*(N-i)+p[i]);
	end;
end.

Score : 400 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions:

1 \leq a_i, b_i \leq 10^9 for all i

a_1 < a_2 < ... < a_N

b_1 > b_2 > ... > b_N

a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}

Constraints

2 \leq N \leq 20,000

p is a permutation of the set {1, 2, ..., N}

Input

The input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space.

It can be shown that there always exists a solution for any input satisfying the constraints.

Sample Input 1

2
1 2

Sample Output 1

1 4
5 4

a_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.

Sample Input 2

3
3 2 1

Sample Output 2

1 2 3
5 3 1

Sample Input 3

3
2 3 1

Sample Output 3

5 10 100
100 10 1


var s,t:ansistring;
    i,j,cnt,k:longint;
    b:boolean;
begin
  readln(s);
  cnt:=0;
  b:=false;
  k:=1;
  for i:=1 to length(s) do begin
    if (s[i]<>s[i+1]) then delete(s,i,1);
  end;
  while (b=false) do begin
    b:=true;
    for i:=k to length(s) do begin
      if (s[1]<>s[i]) then begin
        b:=false;
        break;
      end;
    end;
    if (b=false) then begin
      if s[i]='W' then begin
        insert('W',s,1);
        for j:=2 to i do begin
          if s[j]='B' then s[j]:='W';
        end;
      end
      else begin
        insert('B',s,1);
        for j:=2 to i do begin
          if s[j]='W' then s[j]:='B';
        end;
      end;
      k:=i;
      inc(cnt);
    end
    else break;
  end;
  writeln(cnt);
end.

Score : 300 points

Problem Statement

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

1 ≦ |S| ≦ 10^5

Each character in S is B or W.

Input

The input is given from Standard Input in the following format:

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Sample Input 1

BBBWW

Sample Output 1

1

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.

In either way, Jiro's purpose can be achieved by placing one stone.

Sample Input 2

WWWWWW

Sample Output 2

0

If all stones are already of the same color, no new stone is necessary.

Sample Input 3

WBWBWBWBWB

Sample Output 3

9


var s:ansistring;
    i,j,cnt,k:longint;
    b:boolean;
begin
  readln(s);
  cnt:=0;
  b:=false;
  k:=1;
  while (b=false) do begin
    b:=true;
    for i:=k to length(s) do begin
      if (s[1]<>s[i]) then begin
        b:=false;
        break;
      end;
    end;
    if (b=false) then begin
      if s[i]='W' then begin
        insert('W',s,1);
        inc(cnt);
        for j:=2 to i do begin
          if s[j]='B' then s[j]:='W';
        end;
        k:=i;
      end
      else begin
        insert('B',s,1);
        inc(cnt);
        for j:=2 to i do begin
          if s[j]='W' then s[j]:='B';
        end;
        k:=i;
      end;
    end
    else break;
  end;
  writeln(cnt);
end.


var
  s:string;
  i,cnt:longint;
begin
  readln(s);
  cnt:=0;
  for i:=1 to length(s)-1 do
    if (s[i]<>s[i+1]) then
      inc(cnt);
  writeln(cnt);
end.


var

  s : ansistring;
  i, cnt : longint;
  b : boolean;

begin

  readln(S);
  b := true;
  cnt := 0;

  for i := 1 to length(s)-1 do
  begin
    if s[i] <> s[i+1] then
      b := false;
  end;

  if b = true then
  begin
    writeln(0);
    halt;
  end
  else
    for i := 1 to length(s)-1 do
      if ((s[i] = 'B') and (s[i+1] = 'W')) or ((s[i] = 'W') and (s[i+1] = 'B')) then
        inc(cnt);

  writeln(cnt);

end.


var

  s : ansistring;
  i, cntw, cntb : longint;
  b : boolean;

begin

  readln(S);
  b := true;
  cntw := 0;
  cntb := 0;

  for i := 1 to length(s)-1 do
  begin
    if s[i] <> s[i+1] then
      b := false;
  end;

  if b = true then
    writeln(0)
  else
  begin
    for i := 1 to length(s)-1 do
    begin
      if (s[i] = 'B') and (s[i+1] = 'W') then
        inc(cntw)
      else
        if (s[i] = 'W') and (s[i+1] = 'B') then
          inc(cntb);
    end;
  end;
  writeln(cntw + cntb);

end.


var s,tmp:ansistring;
    i,count:longint;
begin
    readln(s);
    tmp:=s[1];
    for i:=2 to length(s) do
    begin
        if tmp<>s[i] then
            inc(count);
        tmp:=s[i];
    end;
    writeln(count);
end.


var i,lens:longint; s:ansistring;

begin
   readln(s);
   lens:=length(s);
   i:=1;
   while (pos('BB',s)<>0) or (pos('WW',s)<>0) do begin
      while s[i]=s[i+1] do begin
	     delete(s,i+1,1);
	   end;
	   inc(i);
	end;
	lens:=length(s);
	writeln (lens-1);
end.


var n,m,i,j,ans:longint;
    s:string;
begin
readln(s);
for i:=2 to length(s) do begin
  if s[i]<>s[i-1] then inc(ans);
end;
writeln(ans);
end.


// luogu-judger-enable-o2
var
	i,l,r,mid,n:longint;
	a:array[1..1000001] of longint;

function check(k:longint):longint;
var	i:longint;
begin
	if ((a[n-1]<=k)and(a[n]<=k))or((a[n+1]<=k)and(a[n]<=k)) then exit(0);
	if ((a[n-1]>k)and(a[n]>k))or((a[n+1]>k)and(a[n]>k)) then exit(1);
	for i:=1 to n-1 do begin
		if ((a[n-i-1]<=k)and(a[n-i]<=k))or((a[n+i+1]<=k)and(a[n+i]<=k)) then exit(0);
		if ((a[n-i-1]>k)and(a[n-i]>k))or((a[n+i+1]>k)and(a[n+i]>k)) then exit(1);
	end;
	if a[1]>k then exit(1) else exit(0);
end;

begin
	readln(n);
	for i:=1 to 2*n-1 do read(a[i]);
	l:=1;
	r:=2*n-1;
	while l<r-1 do begin
		mid:=(l+r) shr 1;
		//writeln(l,' ',r);
		if check(mid)=0 then begin
			//writeln(mid);
			r:=mid
		end
		else l:=mid;
	end;
	writeln(r);
end.

Score : 1300 points

Problem Statement

We have a pyramid with N steps, built with blocks.
The steps are numbered 1 through N from top to bottom.
For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally.
The pyramid is built so that the blocks at the centers of the steps are aligned vertically.

A pyramid with N=4 steps

Snuke wrote a permutation of (1, 2, ..., 2N-1) into the blocks of step N.
Then, he wrote integers into all remaining blocks, under the following rule:

The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b, or to the lower left or lower right of b.

Writing integers into the blocks

Afterwards, he erased all integers written into the blocks.
Now, he only remembers that the permutation written into the blocks of step N was (a_1, a_2, ..., a_{2N-1}).

Find the integer written into the block of step 1.

Constraints

2≤N≤10^5

(a_1, a_2, ..., a_{2N-1}) is a permutation of (1, 2, ..., 2N-1).

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{2N-1}

Output

Print the integer written into the block of step 1.

Sample Input 1

4
1 6 3 7 4 5 2

Sample Output 1

4

This case corresponds to the figure in the problem statement.

Sample Input 2

2
1 2 3

Sample Output 2

2


var
 n,m,i,sum,j,p:longint;
 a,b:array[0..10001] of longint;
 f:array[0..10001,0..10001] of boolean;
begin
 readln(n,m);
 for i:=1 to m do
  begin
   readln(a[i],b[i]);
   f[a[i],b[i]]:=true;
   inc(sum);
  end;
 i:=1;
 while i<=m+p do
  begin
   for j:=1 to n do
    if f[b[i],j] then
     if f[j,a[i]]=false then
      begin
       inc(p);f[j,a[i]]:=true; inc(sum);
       a[m+p]:=j; b[m+p]:=a[i];
      end;inc(i);
  end;
 writeln(sum);
end.

Score : 1700 points

Problem Statement

We have a grid with N rows and N columns.
The cell at the i-th row and j-th column is denoted (i, j).

Initially, M of the cells are painted black, and all other cells are white.
Specifically, the cells (a_1, b_1), (a_2, b_2), ..., (a_M, b_M) are painted black.

Snuke will try to paint as many white cells black as possible, according to the following rule:

If two cells (x, y) and (y, z) are both black and a cell (z, x) is white for integers 1≤x,y,z≤N, paint the cell (z, x) black.

Find the number of black cells when no more white cells can be painted black.

Constraints

1≤N≤10^5

1≤M≤10^5

1≤a_i,b_i≤N

All pairs (a_i, b_i) are distinct.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print the number of black cells when no more white cells can be painted black.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

3

It is possible to paint one white cell black, as follows:

Since cells (1, 2) and (2, 3) are both black and a cell (3, 1) is white, paint the cell (3, 1) black.

Sample Input 2

2 2
1 1
1 2

Sample Output 2

4

It is possible to paint two white cells black, as follows:

Since cells (1, 1) and (1, 2) are both black and a cell (2, 1) is white, paint the cell (2, 1) black.

Since cells (2, 1) and (1, 2) are both black and a cell (2, 2) is white, paint the cell (2, 2) black.

Sample Input 3

4 3
1 2
1 3
4 4

Sample Output 3

3

No white cells can be painted black.


var
  s:string;
  i,min,max:longint;
begin
  readln(s);
  min:=length(s);
  max:=1;
  for i:=1 to length(s) do
  begin
   if s[i]='C' then if i<min then min:=i;
   if s[i]='F' then if i>max then max:=i;
   end;
  if max>min then writeln('Yes') else writeln('No');
end.

Score : 100 points

Problem Statement

This contest is CODEFESTIVAL, which can be shortened to the string CF by deleting some characters.

Mr. Takahashi, full of curiosity, wondered if he could obtain CF from other strings in the same way.

You are given a string s consisting of uppercase English letters.
Determine whether the string CF can be obtained from the string s by deleting some characters.

Constraints

2 ≤ |s| ≤ 100

All characters in s are uppercase English letters (A-Z).

Input

The input is given from Standard Input in the following format:

s

Output

Print Yes if the string CF can be obtained from the string s by deleting some characters.
Otherwise print No.

Sample Input 1

CODEFESTIVAL

Sample Output 1

Yes

CF is obtained by deleting characters other than the first character C and the fifth character F.

Sample Input 2

FESTIVALCODE

Sample Output 2

No

FC can be obtained but CF cannot be obtained because you cannot change the order of the characters.

Sample Input 3

CF

Sample Output 3

Yes

It is also possible not to delete any characters.

Sample Input 4

FCF

Sample Output 4

Yes

CF is obtained by deleting the first character.


Var s,x:ansistring;
    n,i:longint;
Begin
        readln(s);
        for i:=1 to length(s) do
        Begin
                if s[i] in ['C','F'] then
                Begin
                        x:=x+s[i];
                end;

                if pos('CF',x)<>0 then
                Begin
                        write('Yes');
                        halt;
                end;
        end;
        write('No');
end.


var s:string;
i:integer;
c,f:boolean;
begin
c:=false;
f:=false;
read(s);
for i:=1 to length(s) do
begin
if s[i]='C' then c:=true;
if s[i]='F' then f:=true;
if not(c) then f:=false;
end;
if c=f then writeln('Yes') else writeln('No');
end.


var
	s,s1 : ansistring;
	i : longint;
begin
	readln(s1);
	s := '';
	for i := length(s1) downto 1 do s := s + s1[i];
	//writeln(s);
	if (pos('C',s) > pos('F',s)) and (pos('C',s) <> 0) and (pos('F',s) <> 0) then writeln('Yes')
	else writeln('No');
end.


var s:string;
    i,len,x,y,ans:longint;
begin
    readln(s);
    len:=length(s);
    for i:=1 to len do
    begin
        if (x>=y+1) then
        begin
            inc(y);
            if (s[i]='g') then inc(ans);
        end
        else begin inc(x); if (s[i]='p') then dec(ans); end;
    end;
    writeln(ans);
end.

Score : 300 points

Problem Statement

AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of N turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:

(※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock).

Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.

(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)

With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.

The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in p, TopCoDeer will play Paper in the i-th turn.

Constraints

1≦N≦10^5

N=|s|

Each character in s is g or p.

The gestures represented by s satisfy the condition (※).

Input

The input is given from Standard Input in the following format:

s

Output

Print the AtCoDeer's maximum possible score.

Sample Input 1

gpg

Sample Output 1

0

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

Sample Input 2

ggppgggpgg

Sample Output 2

2

For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of 2, which is the maximum possible score.


var
  i,x,y,t:longint;
  s:ansistring;
begin
  readln(s);
  x:=0;y:=0;t:=0;
  for i:=1 to length(s) do
   if x=y then
     begin
       x:=x+1;
       if s[i]='p' then t:=t-1;
     end
    else
     begin
       y:=y+1;
       if s[i]='g' then t:=t+1;
     end;
  writeln(t);
end.


var i,j,n,m,x,y,ans:longint;
    a:string;
begin
  readln(a);
  n:=length(a);
  for i:=1 to n do
  if x=y then
  begin
    inc(x);
    if a[i]='p' then dec(ans);
  end
  else
  begin
    inc(y);
    if a[i]='g' then inc(ans);
  end;
  writeln(ans);
end.


var s:string;
    i,len,x,y,ans:longint;
begin
 readln(s);
 len:=length(s);
 for i:=1 to len do
 begin
  if (x>=y+1) then begin inc(y); if (s[i]='g') then inc(ans); end
  else begin inc(x); if (s[i]='p') then dec(ans); end;
 end;
 writeln(ans);
end.


var
 i,ss,s1,s2:longint;
 s:string;
begin
 readln(s);
 for i:=1 to length(s) do
  if s1=s2 then begin if s[i]='p' then dec(ss); inc(s1); end
  else begin if s[i]='g' then inc(ss); inc(s2); end;
 writeln(ss);
end.


var
s,s1:string;
i,j,c,x,y:longint;
begin
read(s);
for i:=1 to length(s) do
begin
if x=y then begin inc(x); if s[i]='p' then dec(c);end
else
 begin
inc(y);
if s[i]='g' then inc(c);
end;
end;
writeln(c);
end.


Uses math;
var
	n,i,x,y:Longint;
	a,b,c:int64;
begin
	readln(n);
	a:=1;
	for i:=1 to n do begin
		readln(x,y);
        c:=Max((a-1)div x,(b-1)div y)+1;
		a:=c*x;
		b:=c*y;
	end;
	writeln(a+b);
end.

Score : 300 points

Problem Statement

AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.

Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

Constraints

1≦N≦1000

1≦T_i,A_i≦1000 (1≦i≦N)

T_i and A_i (1≦i≦N) are coprime.

It is guaranteed that the correct answer is at most 10^{18}.

Input

The input is given from Standard Input in the following format:

N
T_1 A_1
T_2 A_2
:
T_N A_N

Output

Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

Sample Input 1

3
2 3
1 1
3 2

Sample Output 1

10

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

Sample Input 2

4
1 1
1 1
1 5
1 100

Sample Output 2

101

It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.

Sample Input 3

5
3 10
48 17
31 199
231 23
3 2

Sample Output 3

6930


Uses math;
var
	n,i,x,y:Longint;
	a,b,c,d:int64;
begin
	read(n);
	a:=1;
	b:=1;
	for i:=1 to n do begin
		read(x,y);
        c:=Max((a-1)div x,(b-1)div y)+1;
		a:=c*x;
		b:=c*y;
	end;
	writeln(a+b);
end.


var n,a,b,x,y,p,q,tmp,tmp1,tmp2,tmp3:int64;
function gcd(a,b:int64):int64; begin if b=0 then exit(a); exit(gcd(b,a mod b)); end;
procedure exgcd(a,b:int64; var x,y:int64);
  var t:int64;
  begin
    if b=0 then begin
      x:=tmp; y:=0; exit;
    end;
    exgcd(b,a mod b,x,y);
    t:=x; x:=y; y:=t-a div b*y;
    //x:=x mod p; y:=y mod q;
  end;
begin
  //assign(input,'a.in'); reset(input);
  readln(n); a:=1; b:=1;
  while (n>0) do begin
    dec(n); readln(p,q); tmp:=-a*q+b*p;
   // writeln(a,' ',b);
    exgcd(q,p,x,y);
    tmp1:=(x mod p+p) mod p; tmp2:=y+(x-tmp1) div p*q;
    if (tmp2>0) then begin
      tmp3:=tmp2 mod q-q;
      x:=tmp1-(tmp3-tmp2) div q*p;
      y:=tmp3;
    end else begin x:=tmp1; y:=tmp2; end;
    a:=a+x; b:=b-y;
  end;
  writeln(a+b);
  //close(input);
end.


var s:String;t:String='CODEFESTIVAL2016';
i,c:Longint;
begin
readln(s);
for i:=1 to 16 do if s[i]<>t[i] then inc(c);
writeln(c);
end.

Score : 100 points

Problem Statement

CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.

He intended to write CODEFESTIVAL2016 on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.

So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to CODEFESTIVAL2016.

Find the minimum number of iterations for the rewrite operation.

Constraints

S is 16 characters long.

S consists of uppercase and lowercase alphabet letters and numerals.

Input

Inputs are provided from Standard Input in the following form.

S

Output

Output an integer representing the minimum number of iterations needed for the rewrite operation.

Sample Input 1

C0DEFESTIVAL2O16

Sample Output 1

2

The second character 0 must be changed to O and the 14th character O changed to 0.

Sample Input 2

FESTIVAL2016CODE

Sample Output 2

16


        {$mode objfpc}
        {$coperators on}
const
        sz=round(1e5)+100;
type
    Tnode = ^node;
    node  =
        record
            c:array['_'..'z'] of Tnode;
            cnt:longint;
        end;
var
    s:array[1..sz]of string;
    n,q,cur:longint;
    kth,ans:array[1..sz]of longint;
    a:array[1..sz]of ansistring;
    nod,root:Tnode;
    count:array[0..sz,'_'..'z','_'..'z']of longint;

function min(const x,y:longint):longint; begin if x<=y then exit(x) else exit(y); end;
function max(const x,y:longint):longint; begin if x>=y then exit(x) else exit(y); end;
procedure spaw(var nod:Tnode);
var i:char;
    begin
        new(nod);
        nod^.cnt:=0;
        for i:='_' to 'z' do nod^.c[i]:=nil;
    end;

procedure enter;
var i : integer;
    begin
        readln(n);
        for i:=1 to n do
            begin
                readln(a[i]);
                a[i]:=a[i]+'_';
            end;
        readln(q);
        for i:=1 to q do
            begin
                read(kth[i]);
                readln(s[i]);
                delete(s[i],1,1);
            end;
    end;
procedure update(const a:ansistring);
var ch,rr:char;
    i:longint;
    begin
        nod:=root;
        for i:=1 to length(a) do
            begin
                ch:=a[i];
                if nod^.c[ch]=nil then spaw(nod^.c[ch]);
                nod := nod^.c[ch];
                inc(nod^.cnt);
            end;
    end;
procedure updateElement(p:longint);
var i:longint;
    ch,rr:char;
    begin
        nod:=root;
        for i:=1 to length(a[p]) do
            begin
                ch:=a[p][i];
                for rr:='_' to 'z' do if (rr<>ch)and(nod^.c[rr]<>nil) then
                    count[p][ch][rr] += nod^.c[rr]^.cnt;
                nod:=nod^.c[ch];
            end;
    end;
procedure Build();
var i:longint;
    begin
        spaw(root);
        for i:=1 to n do
            begin
                update(a[i]);
            end;
        for i:=1 to n do
            begin
                updateElement(i);
            end;
    end;
procedure doQuerry(const s:string; kth:longint);
var i,j:longint;
    begin
        for i:=1 to 26 do
            for j:=1 to i-1 do ans[cur] += count[kth,s[i],s[j]];
        for i:=1 to 26 do ans[cur] += count[kth,s[i],'_'];
        ans[cur]+=1;
    end;
procedure solve;
var i: integer;
    begin
        Build();
        for i:=1 to q do
            begin
                cur:=i;
                doQuerry(s[i], kth[i]);
            end;
    end;
procedure print();
var i:longint;
    begin
        for i:=1 to q do
            writeln(ans[i]);
    end;
begin
        enter(); solve(); print();
end.


        {$mode objfpc}
        {$coperators on}
program Lexicographical_disorder________________________CODE_FESTIVAL_2016_qual_B____________________________________________________________;
const
        {$ifdef online_judge}
            fi = '';
            fo = '';
        {$else}
            fi = 'lex.inp';
            fo = 'lex.out';
        {$endif}
        sz=round(1e5)+100;
type
    Tnode = ^node;
    node  =
        record
            c:array['_'..'z'] of Tnode;
            cnt:longint;
        end;
var
    s:array[1..sz]of string;
    n,q,cur:longint;
    kth,ans:array[1..sz]of longint;
    a:array[1..sz]of ansistring;
    nod,root:Tnode;
    count:array[0..sz,'_'..'z','_'..'z']of longint;

function min(const x,y:longint):longint; begin if x<=y then exit(x) else exit(y); end;
function max(const x,y:longint):longint; begin if x>=y then exit(x) else exit(y); end;
procedure spaw(var nod:Tnode);
var i:char;
    begin
        new(nod);
        nod^.cnt:=0;
        for i:='_' to 'z' do nod^.c[i]:=nil;
    end;

procedure enter;
var i : integer;
    begin
        readln(n);
        for i:=1 to n do
            begin
                readln(a[i]);
                a[i]:=a[i]+'_';
            end;
        readln(q);
        for i:=1 to q do
            begin
                read(kth[i]);
                readln(s[i]);
                delete(s[i],1,1);
            end;
    end;
procedure update(const a:ansistring);
var ch,rr:char;
    i:longint;
    begin
        nod:=root;
        for i:=1 to length(a) do
            begin
                ch:=a[i];
                if nod^.c[ch]=nil then spaw(nod^.c[ch]);
                nod := nod^.c[ch];
                inc(nod^.cnt);
            end;
    end;
procedure updateElement(p:longint);
var i:longint;
    ch,rr:char;
    begin
        nod:=root;
        for i:=1 to length(a[p]) do
            begin
                ch:=a[p][i];
                for rr:='_' to 'z' do if (rr<>ch)and(nod^.c[rr]<>nil) then
                    count[p][ch][rr] += nod^.c[rr]^.cnt;
                nod:=nod^.c[ch];
            end;
    end;
procedure Build();
var i:longint;
    begin
        spaw(root);
        for i:=1 to n do
            begin
                update(a[i]);
            end;
        for i:=1 to n do
            begin
                updateElement(i);
            end;
    end;
procedure doQuerry(const s:string; kth:longint);
var i,j:longint;
    begin
        for i:=1 to 26 do
            for j:=1 to i-1 do ans[cur] += count[kth,s[i],s[j]];
        for i:=1 to 26 do ans[cur] += count[kth,s[i],'_'];
        ans[cur]+=1;
    end;
procedure solve;
var i: integer;
    begin
        Build();
        for i:=1 to q do
            begin
                cur:=i;
                doQuerry(s[i], kth[i]);
            end;
    end;
procedure print();
var i:longint;
    begin
        for i:=1 to q do
            writeln(ans[i]);
    end;
begin
        enter(); solve(); print();
end.


var
i,n,x,y:Longint;
begin
read(n);
for i:=1 to n do begin
read(x,y);
if x mod 2=1 then writeln(127*(x-1)+y)else writeln(127*x-y);
end;
end.

Score : 100 points

Problem Statement

A professor invented Cookie Breeding Machine for his students who like cookies very much.

When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine,
it consumes the cookie and generates two cookies with the taste of y and (x XOR y).

Here, XOR represents Bitwise Exclusive OR.

At first, there is only one cookie and the taste of it is D .

Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times.

Put one of the cookies into the machine.

Input a non-negative integer less than or equal to 127 on the machine.

Constraints

1 \leq T \leq 1000

1 \leq N_t \leq 1000 (1 \leq t \leq T)

1 \leq D_t \leq 127 (1 \leq t \leq T)

Input

The input is given from Standard Input in the following format:

T
N_1 D_1
:
N_T D_T

The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1.

Each test case is given on the next T lines.

In the t-th test case ( 1 \leq t \leq T ),
N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space.

Output

For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line.

Sample Input 1

3
3 1
4 108
1 10

Sample Output 1

255
400
10

On the 1st test case, if the machine is used as follows, three cookies with the taste of 61, 95 and 99 are generated.
Since the sum of these values is maximum among all possible ways, the answer is 255.

Put the cookie with the taste of 1 and input an integer 60 on the machine, lose the cookie and get two cookies with the taste of 60 and 61.

Put the cookie with the taste of 60 and input an integer 99 on the machine, lose the cookie and get two cookies with the taste of 99 and 95.

On the 3rd test case, the machine may not be used.


var   s:ansistring;   i,sum,cnt:longint;
begin
    readln(s);
    for i:=1 to length(s) do
      begin
          if s[i]='S' then inc(sum);
            if s='T' then
              begin
                if (sum<>0)then begin dec(sum);inc(cnt);end;
              end;
      end;
   writeln(length(s)-cnt);
end.

Score : 300 points

Problem Statement

We have a string X, which has an even number of characters. Half the characters are S, and the other half are T.

Takahashi, who hates the string ST, will perform the following operation 10^{10000} times:

Among the occurrences of ST in X as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.

Find the eventual length of X.

Constraints

2 ≦ |X| ≦ 200,000

The length of X is even.

Half the characters in X are S, and the other half are T.

Partial Scores

In test cases worth 200 points, |X| ≦ 200.

Input

The input is given from Standard Input in the following format:

X

Output

Print the eventual length of X.

Sample Input 1

TSTTSS

Sample Output 1

4

In the 1-st operation, the 2-nd and 3-rd characters of TSTTSS are removed.
X becomes TTSS, and since it does not contain ST anymore, nothing is done in the remaining 10^{10000}-1 operations.
Thus, the answer is 4.

Sample Input 2

SSTTST

Sample Output 2

0

X will eventually become an empty string: SSTTST ⇒ STST ⇒ ST ⇒ ``.

Sample Input 3

TSSTTTSS

Sample Output 3

4

X will become: TSSTTTSS ⇒ TSTTSS ⇒ TTSS.


var   s:ansistring;
begin
    readln(s);
    while (s<>'')and(pos('ST',s)<>0)do delete(s,pos('ST',s),2);
     writeln(length(s));
end.


var   s:ansistring;
begin
    readln(s);
    while (s<>'')and(pos('ST',s)<>0)do delete(s,pos('ST',s),1);
     writeln(length(s));
end.


var i,t:Longint;
s:String;
begin
readln(s);
for i:=1 to length(s)do begin
if s[i]='S'then inc(t)else if t>0 then dec(t);
end;
writeln(t*2);
end.


var s:ansistring;
i:longint;
begin
//assign(input,'str.in');reset(input);
//assign(output,'str.out');rewrite(output);
readln(s);
i:=length(s);
while i>=3 do
  begin
  if s[i-1]+s[i]='ST' then
    begin
    delete(s,i-1,2);
    i:=i-1;
    end;
  i:=i-1;
  end;
if (s[1]+s[2]='ST') and (length(s)=2) then
  writeln(0)
else
  begin
  while pos('ST',s)>0 do
    delete(s,pos('ST',s),2);
  writeln(length(s));
  end;
close(input);close(output);
end.


var
 s:ansistring;
 k:longint;
begin
 readln(s);
 k:=pos('ST',s);
 while k<>0 do
  begin
   delete(s,k,2);
   k:=pos('ST',s);
  end;
 writeln(length(s));
end.


 var
   s:ansistring;
   x:longint;
begin
       readln(s);
       while(true) do
        begin
                x:=pos('ST',s);
                if(x=0)then break;
                delete(s,x,2);

        end;
      writeln(length(s));
end.


var n,c,i:Longint;a:array[1..100000]of Longint;
begin
read(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do if i=a[a[i]]then inc(c);
writeln(c div 2);
end.

Score : 200 points

Problem Statement

There are N rabbits, numbered 1 through N.

The i-th (1≤i≤N) rabbit likes rabbit a_i.
Note that no rabbit can like itself, that is, a_i≠i.

For a pair of rabbits i and j (i＜j), we call the pair (i，j) a friendly pair if the following condition is met.

Rabbit i likes rabbit j and rabbit j likes rabbit i.

Calculate the number of the friendly pairs.

Constraints

2≤N≤10^5

1≤a_i≤N

a_i≠i

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the number of the friendly pairs.

Sample Input 1

4
2 1 4 3

Sample Output 1

2

There are two friendly pairs: (1，2) and (3，4).

Sample Input 2

3
2 3 1

Sample Output 2

0

There are no friendly pairs.

Sample Input 3

5
5 5 5 5 1

Sample Output 3

1

There is one friendly pair: (1，5).


program abc045a;
Uses sysutils;
var a,b,h:String;
begin
	readLn(a);
	readLn(b);
	readLn(h);
	writeLn(((StrToInt(a)+StrToInt(b))*(StrToInt(h)))/2);
end.

Score : 100 points

Problem Statement

You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.

An example of a trapezoid

Find the area of this trapezoid.

Constraints

1≦a≦100

1≦b≦100

1≦h≦100

All input values are integers.

h is even.

Input

The input is given from Standard Input in the following format:

a
b
h

Output

Print the area of the given trapezoid. It is guaranteed that the area is an integer.

Sample Input 1

3
4
2

Sample Output 1

7

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

Sample Input 2

4
4
4

Sample Output 2

16

In this case, a parallelogram is given, which is also a trapezoid.


var N,i,j:Longint;
x,p,ans,now:int64;
A:Array[1..2000]of int64;
begin
read(N,x);
for i:=1 to N do read(A[i]);
ans:=10000000000000000;
for j:=0 to N do begin
p:=A[1];
now:=j*x;
for i:=1 to N do begin
inc(now,A[i]);
if(i<N)and(A[i]>A[i+1])then A[i]:=A[i+1];
end;
if ans>now then ans:=now;
if A[N]>p then A[N]:=p;
end;
writeln(ans);
end.

Score : 400 points

Problem Statement

Snuke lives in another world, where slimes are real creatures and kept by some people.
Slimes come in N colors. Those colors are conveniently numbered 1 through N.
Snuke currently has no slime. His objective is to have slimes of all the colors together.

Snuke can perform the following two actions:

Select a color i (1≤i≤N), such that he does not currently have a slime in color i, and catch a slime in color i. This action takes him a_i seconds.

Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i (1≤i≤N-1) will become color i+1, and the color of a slime in color N will become color 1. This action takes him x seconds.

Find the minimum time that Snuke needs to have slimes in all N colors.

Constraints

2≤N≤2,000

a_i are integers.

1≤a_i≤10^9

x is an integer.

1≤x≤10^9

Input

The input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Find the minimum time that Snuke needs to have slimes in all N colors.

Sample Input 1

2 10
1 100

Sample Output 1

12

Snuke can act as follows:

Catch a slime in color 1. This takes 1 second.

Cast the spell. The color of the slime changes: 1 → 2. This takes 10 seconds.

Catch a slime in color 1. This takes 1 second.

Sample Input 2

3 10
100 1 100

Sample Output 2

23

Snuke can act as follows:

Catch a slime in color 2. This takes 1 second.

Cast the spell. The color of the slime changes: 2 → 3. This takes 10 seconds.

Catch a slime in color 2. This takes 1 second.

Cast the soell. The color of each slime changes: 3 → 1, 2 → 3. This takes 10 seconds.

Catch a slime in color 2. This takes 1 second.

Sample Input 3

4 10
1 2 3 4

Sample Output 3

10

Snuke can act as follows:

Catch a slime in color 1. This takes 1 second.

Catch a slime in color 2. This takes 2 seconds.

Catch a slime in color 3. This takes 3 seconds.

Catch a slime in color 4. This takes 4 seconds.


program ec12;
var
	n,m,i,j:longint;
	a:array[1..501,1..501] of longint;
	c:char;
begin
	readln(n,m);
	for i:=1 to n do
	begin
		if i mod 2=1 then
		begin
			for j:=1 to m do
			a[i,j]:=1;
		end
		else
		begin
			for j:=1 to m do
			a[i,j]:=2;
		end;
	end;
	for i:=1 to n do
	a[i,1]:=1;
	for i:=1 to n do
	a[i,m]:=2;
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			read(c);
			if c='#' then
			a[i,j]:=3;
		end;
		readln;
	end;
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			if (a[i,j]=1) or (a[i,j]=3) then
			write('#')
			else
			write('.');
		end;
		writeln;
	end;
	writeln;
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			if (a[i,j]=2) or (a[i,j]=3) then
			write('#')
			else
			write('.');
		end;
		writeln;
	end;
end.

Score : 700 points

Problem Statement

Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.

Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.

Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.

Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.

You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is #, otherwise a_{ij} is .. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is ..

Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.

Constraints

3≤H,W≤500

a_{ij} is # or ..

If i=1,H or j=1,W, then a_{ij} is ..

At least one of a_{ij} is #.

Input

The input is given from Standard Input in the following format:

H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}

Output

Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:

The first H lines should describe the positions of the red cells.

The following 1 line should be empty.

The following H lines should describe the positions of the blue cells.

The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.

Sample Input 1

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

Sample Output 1

.....
#####
#....
#####
.....

.###.
.#.#.
.#.#.
.#.#.
.....

One possible pair of the set of the positions of the red cells and the blue cells is as follows:

Sample Input 2

7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............

Sample Output 2

.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............

.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............

One possible pair of the set of the positions of the red cells and the blue cells is as follows:


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  i,j,min:Integer;
  w:string;
  sw:Char;
  beau:Boolean;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(w);

    for i := 1 to Length(w) do begin
      min := i;
      for j := i+1 to Length(w) do begin
        if w[j] < w[min] then
        min := j;
      end;
      sw:=w[i];
      w[i]:=w[min];
      w[min]:=sw;
    end;

    beau:=True;
    if Length(w) mod 2 = 1 then
      beau:=false
    else begin
      i:=1;
      while i<Length(w) do
        if w[i]=w[i+1] then
          i:=i+2
        else begin
          beau:=false;
          Break;
        end;
    end;

    if beau then
      Writeln('Yes')
    else
      Writeln('No');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Score : 200 points

Problem Statement

Let w be a string consisting of lowercase letters.
We will call w beautiful if the following condition is satisfied:

Each lowercase letter of the English alphabet occurs even number of times in w.

You are given the string w. Determine if w is beautiful.

Constraints

1 \leq |w| \leq 100

w consists of lowercase letters (a-z).

Input

The input is given from Standard Input in the following format:

w

Output

Print Yes if w is beautiful. Print No otherwise.

Sample Input 1

abaccaba

Sample Output 1

Yes

a occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.

Sample Input 2

hthth

Sample Output 2

No


var
	n,A,i,j,k,x:Longint;
	dp:array[0..9999]of int64;
begin
	read(n,A);
	dp[n*A]:=1;
	for k:=1 to n do begin
		read(x);
		for j:=0 to 4999 do begin
			dp[5000-i+j]:=dp[i+j];
			if(j-x+A>=0)and(j-x+A<5000)then inc(dp[5000-i+j],dp[i+j-x+A]);
		end;
		i:=5000-i;
	end;
	writeln(dp[i+n*A]-1);
end.

Score : 300 points

Problem Statement

Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i.
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.
In how many ways can he make his selection?

Constraints

1 \leq N \leq 50

1 \leq A \leq 50

1 \leq x_i \leq 50

N,\,A,\,x_i are integers.

Partial Score

200 points will be awarded for passing the test set satisfying 1 \leq N \leq 16.

Input

The input is given from Standard Input in the following format:

N A
x_1 x_2 ... x_N

Output

Print the number of ways to select cards such that the average of the written integers is exactly A.

Sample Input 1

4 8
7 9 8 9

Sample Output 1

5

The following are the 5 ways to select cards such that the average is 8:

Select the 3-rd card.

Select the 1-st and 2-nd cards.

Select the 1-st and 4-th cards.

Select the 1-st, 2-nd and 3-rd cards.

Select the 1-st, 3-rd and 4-th cards.

Sample Input 2

3 8
6 6 9

Sample Output 2

0

Sample Input 3

8 5
3 6 2 8 7 6 5 9

Sample Output 3

19

Sample Input 4

33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Sample Output 4

8589934591

The answer may not fit into a 32-bit integer.


var
	n,s,b,t,c,ans,i:int64;
function f(b,n:int64):int64;
var t,c:int64;
begin
	t:=n;
	c:=0;
	while t>0 do begin
		c:=c+t mod b;
		t:=t div b;
	end;
	f:=c;
end;
begin
	read(n,s);
	if n=s then begin
		writeln(n+1);
		exit;
	end;
	i:=1;
	ans:=n+s;
	while i*i<=n do begin
		if(i>1)and(f(i,n)=s)and(ans>i)then ans:=i;
		if n div i>1 then begin
			t:=f(n div i,n);
			if(t<=s)and((s-t)mod i=0)then begin
				b:=n div i-(s-t)div i;
				if(b>1)and(f(b,n)=s)and(ans>b)then ans:=b;
			end;
		end;
		inc(i);
	end;
	if ans=n+s then writeln(-1)else writeln(ans);
end.

Score : 500 points

Problem Statement

For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows:

f(b,n) = n, when n < b

f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b

Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b,
and n \ {\rm mod} \ b denotes the remainder of n divided by b.

Less formally, f(b,n) is equal to the sum of the digits of n written in base b.
For example, the following hold:

f(10,\,87654)=8+7+6+5+4=30

f(100,\,87654)=8+76+54=138

You are given integers n and s.
Determine if there exists an integer b (b \geq 2) such that f(b,n)=s.
If the answer is positive, also find the smallest such b.

Constraints

1 \leq n \leq 10^{11}

1 \leq s \leq 10^{11}

n,\,s are integers.

Input

The input is given from Standard Input in the following format:

n
s

Output

If there exists an integer b (b \geq 2) such that f(b,n)=s, print the smallest such b.
If such b does not exist, print -1 instead.

Sample Input 1

87654
30

Sample Output 1

10

Sample Input 2

87654
138

Sample Output 2

100

Sample Input 3

87654
45678

Sample Output 3

-1

Sample Input 4

31415926535
1

Sample Output 4

31415926535

Sample Input 5

1
31415926535

Sample Output 5

-1


var
	n,s,b,t,c,ans,i:int64;
function f(b,n:int64):int64;
var t,c:int64;
begin
	t:=n;
	c:=0;
	while t>0 do begin
		c:=c+t mod b;
		t:=t div b;
	end;
	f:=c;
end;
begin
	read(n,s);
	i:=1;
	ans:=n+b;
	while i*i<=n do begin
		if(i>1)and(f(i,n)=s)and(ans>i)then ans:=i;
		if n div i>1 then begin
			t:=f(n div i,n);
			if(t<=s)or((s-t)mod i=0)then begin
				b:=n div i+(s-t)div i;
				if(b>1)and(f(b,n)=s)and(ans>b)then ans:=b;
			end;
		end;
		inc(i);
	end;
	if ans=n+b then writeln(-1)else writeln(ans);
end.


var x:array[1..10000]of longint;
n,i,j:longint;
temp,cnt:longint;
begin
    readln(n);
    cnt:=0;
    for i:=1 to n do
    begin
        readln(x[i]);
    end;
    for i:=1 to n-1 do
    begin
        if x[i]<x[i+1] then
        begin
            temp:=x[i];
            x[i]:=x[i+1];
            x[i+1]:=temp;
            inc(cnt);
        end;
    end;
    writeln(cnt);
end.

Score : 600 points

Problem Statement

Snuke got an integer sequence of length N from his mother, as a birthday present. The i-th (1 ≦ i ≦ N) element of the sequence is a_i. The elements are pairwise distinct.
He is sorting this sequence in increasing order.
With supernatural power, he can perform the following two operations on the sequence in any order:

Operation 1: choose 2 consecutive elements, then reverse the order of those elements.

Operation 2: choose 3 consecutive elements, then reverse the order of those elements.

Snuke likes Operation 2, but not Operation 1. Find the minimum number of Operation 1 that he has to perform in order to sort the sequence in increasing order.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9

If i ≠ j, then A_i ≠ A_j.

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of times Operation 1 that Snuke has to perform.

Sample Input 1

4
2
4
3
1

Sample Output 1

1

The given sequence can be sorted as follows:

First, reverse the order of the last three elements. The sequence is now: 2,1,3,4.

Then, reverse the order of the first two elements. The sequence is now: 1,2,3,4.

In this sequence of operations, Operation 1 is performed once. It is not possible to sort the sequence with less number of Operation 1, thus the answer is 1.

Sample Input 2

5
10
8
5
3
2

Sample Output 2

0


var
n,o,i,j,tmp:longint;
a:array [0..100001] of longint;
c:array [0..1000000001] of boolean;
begin
readln(n);
for i := 1 to n do
begin
readln(a[i]);
if i mod 2=0 then c[a[i]]:=true;
end;
for i := 1 to n-1 do
begin
for j := 1 to n-i do
begin
if a[j]>a[j+1] then
begin
tmp:=a[j];
a[j]:=a[j+1];
a[j+1]:=tmp;
end;
end;
end;
for i := 1 to n do
begin
if (i mod 2 =0) <> c[a[i]] then o:=o+1;
end;
writeln(o div 2);
end.


program unbalanced;
uses crt;
var
s: String;
a,b,x,i: Integer ;
cek: Boolean;
begin
cek:= false;
  ReadLn(s);
  a:=Length(s);
  b:=3;
  for i:=1 to (a-2) do
  x:=1;
    begin
    if (s[i]=s[i+1]) or (s[i]=s[i+2])
    or (s[i+1]=s[i+2])
    then WriteLn(i,' ',i+2);
    cek:=true;
    end;
if cek = false then WriteLn(-1,' ',-1);
end.

Score : 400 points

Problem Statement

Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

Constraints

2 ≦ |s| ≦ 10^5

s consists of lowercase letters.

Partial Score

200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.

Input

The input is given from Standard Input in the following format:

s

Output

If there exists no unbalanced substring of s, print -1 -1.

If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.

Sample Input 1

needed

Sample Output 1

2 5

The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

Sample Input 2

atcoder

Sample Output 2

-1 -1

The string atcoder contains no unbalanced substring.


var
  a,b:longint;
begin
  readln(a,b);
  if (a>0) or ((abs(b)-abs(a)) mod 2<>0) then writeln('Positive')
    else if (a=0) or (b=0) or ((a<0) and (b>0)) then writeln('Zero')
           else writeln('Negative');
end.

Problem Statement

You are given two integers a and b (a≤b). Determine if the product of the integers a, a+1, …, b is positive, negative or zero.

Constraints

a and b are integers.

-10^9≤a≤b≤10^9

Partial Score

In test cases worth 100 points, -10≤a≤b≤10.

Input

The input is given from Standard Input in the following format:

a b

Output

If the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.

Sample Input 1

1 3

Sample Output 1

Positive

1×2×3=6 is positive.

Sample Input 2

-3 -1

Sample Output 2

Negative

(-3)×(-2)×(-1)=-6 is negative.

Sample Input 3

-1 1

Sample Output 3

Zero

(-1)×0×1=0.


uses math;
var
  i,j,k,n,m,a,b,c,x,y:longint;
begin
     read(a,b);
if (a<=0) and (b>=0) then writeln('Zero')
  else if (a>=0)and(b>=0) then writeln('Positive')
   else if (a<0)and((b-a+1) mod 2=0) then writeln('Positive')
     else writeln('Negative');
  end.


var
 a,b:int64;
begin
 readln(a,b);
 if (a<=0) and (b>=0) then writeln('Zero')
  else if (a<0) and (b<0) and (abs(a-b) mod 2=0) then writeln('Negative')
   else writeln('Positive');
end.


var
 n,a,b,i:longint;
begin
 read(a,b); n:=1;
 for i:=a to b do
  if i=0 then begin writeln('Zero'); halt; end
   else if i<0 then n:=-n;
 if n=1 then writeln('Positive')
  else writeln('Negative');
end.


var n,i,tot,min:longint;
s:array[1..100000] of longint;
begin
    readln(n);
    min:=maxlongint;
    for i:=1 to n do begin
        read(s[i]);
        if s[i]<min then min:=s[i];
    end;
    for i:=1 to n do begin
        if s[i]=min then inc(tot);
    end;
    if ((tot mod 2+min mod 2+n mod 2) mod 2=0) or ((tot mod 2)*(min mod 2)*(n mod 2)=0) then writeln('First')
    else writeln('Second');
end.

Problem Statement

There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies.

Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of the following two operations:

Choose a pile with the largest number of candies remaining, then eat all candies of that pile.

From each pile with one or more candies remaining, eat one candy.

The player who eats the last candy on the table, loses the game. Determine which player will win if both players play the game optimally.

Constraints

1≤N≤10^5

1≤a_i≤10^9

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 … a_N

Output

If Snuke will win, print First. If Ciel will win, print Second.

Sample Input 1

2
1 3

Sample Output 1

First

At the beginning of the game, pile 2 contains the most candies. If Snuke eats all candies of this pile, Ciel has no choice but to eat the last candy.

Sample Input 2

3
1 2 1

Sample Output 2

First

If Snuke eats one candy from each pile, Ciel is again left with the last candy.

Sample Input 3

3
1 2 3

Sample Output 3

Second


var a:array[0..100010]of longint;
    x,i,n,c:longint;

procedure qsort(x,y:longint);
var i,j,m,t:longint;
begin
    i:=x; j:=y; m:=a[(x+y)div 2];
    repeat
         while a[i]<m do inc(i);
         while a[j]>m do dec(j);
         if i<=j then begin
             t:=a[i]; a[i]:=a[j]; a[j]:=t;
             inc(i); dec(j);
         end;
    until i>j;
    if i<y then qsort(i,y);
    if x<j then qsort(x,j);
end;

begin
    read(n);
    for i:=1 to n do read(a[i]);
    qsort(1,n);
    for i:=n downto 1 do begin
        if i<=a[n-i+1] then begin
            c:=n-i;
            repeat
                 inc(x);
                 dec(c);
            until a[c]<i;
            if x mod 2=0 then writeln('First') else begin
                x:=a[n-i+1]-i+1;
                if x mod 2=0 then writeln('First')
                else writeln('Second');
            end;
            break;
        end;
    end;
end.


var a:array[0..100]of longint;
    n,i,j,t,s:longint;
begin
  readln(n);
  for i:=1 to 2*n do
    read(a[i]);
  for i:=1 to 2*n do
    for j:=i+1 to 2*n do
      if a[i]>a[j] then
      begin
        t:=a[i];a[i]:=a[j];a[j]:=t;
      end;
  for i:=1 to n do
    inc(s,a[2*i-1]);
  writeln(s);
end.

Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135


var
  n,i,j,t,s,s1:longint;
  a:array[1..200] of longint;
begin
  readln(n);
  for i:=1 to n*2 do read(a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if a[i]>a[j] then
        begin
          t:=a[i]; a[i]:=a[j]; a[j]:=t;
        end;
  for i:=1 to n*2 do if odd(n) then inc(s,a[i]) else inc(s1,a[i]);
  if s<s1 then writeln(s) else writeln(s1);
end.