#include<stdio.h>
main(){
  char a,b,c;
  int i;
  int j = 0;
  scanf("%s%s%s", &a,&b,&c);
  if (a = "s"){
    j = j + 1;
  }
   if (b = "s"){
    j = j + 1;
  }
    if (c = "s"){
    j = j + 1;
  }
  printf("%d", j);
}

Score : 100 points

Problem Statement

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

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

Constraints

|S| = 3

Each character of S is S or R.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

RRS

Sample Output 1

2

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

Sample Input 2

SSS

Sample Output 2

0

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

Sample Input 3

RSR

Sample Output 3

1

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


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

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.


#include<stdio.h>
#include<stdlib.h>
long min(long x,long y){
return x>y?y:x;
}
int main(void){
long X,K,D;
  scanf("%ld,%ld,%ld",&X,&K,&D);
  X=abs(X);
  long st=min(K,X/D);
  K-=st;
  X-=st*D;
  if(K%2==0) printf("%ld¥n",X);
  else printf("%ld¥n",D-X);

  return 0;
}

Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

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

Sample Input 1

6 2 4

Sample Output 1

2

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

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

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

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

Sample Input 2

7 4 3

Sample Output 2

1

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

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

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

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.


#include <stdio.h>
#include <math.h>
#include <stdlib.h>

typedef long long ll;

#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main() {
	ll x, k, d;
	scanf("%lld %lld %lld", &x, &k, &d);

	x = llabs(x);
	ll r = x / d;
	ll q = x % d;
	ll ans;
	if (x - k * d >= 0) {
		ll min = MIN(llabs(x + k * d), llabs(x - k * d));
		ans = min;
	}
	else
	{
		if ((k - r) % 2 == 0)
		{
			ans = q;
		}
		else
		{
			ans = d - q;
		}
	}
	printf("%lld", ans);

	return 0;
}


#include<stdio.h>
int main()
{
    int n;

    scanf("%d",&n);

    if(n>=30) printf("Yes");

    else printf("No");

    return 0;
}

Score : 100 points

Problem Statement

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

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

Constraints

-40 \leq X \leq 40

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

25

Sample Output 1

No

Sample Input 2

30

Sample Output 2

Yes


#include <stdio.h>
int main(void){
int tem;
scanf("%d", &tem);
if(tem >=30) printf("Yes\n");
else printf("No\n");
return 0;
}


#include <stdio.h>

int main(){
  int a;

  scanf("%d", &a);
  if(a >= 30){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


#include <stdio.h>

int main() {
    long long d;
    int n, i, count = 0;
    int x[200000];
    int y[200000];

    scanf("%d %lld", &n, &d);
    for(i = 0; i < n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }

    for(i = 0; i < n; i++) {
        if(((long long)x[i] * x[i]) + ((long long)y[i] * y[i]) <= (long long)d * d) count++;
    }

    printf("%d", count);

    return 0;
}

Score : 200 points

Problem Statement

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

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

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

Constraints

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

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D
X_1 Y_1
\vdots
X_N Y_N

Output

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

Sample Input 1

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

Sample Output 1

3

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

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

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

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

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

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

Sample Input 2

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

Sample Output 2

7

Multiple points may exist at the same coordinates.

Sample Input 3

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

Sample Output 3

6


Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){

    int n;
    char c[max];
    int cnt=0, rcnt=0;;

    scanf("%d", &n);
    scanf("%s", c);

    //for (;;) {
        for (int i=0; i<n-1; i++) {
            if (c[i]=='W') {
                for (int j=n-1; j>i; j--) {
                    if (c[j]=='R') {
                        c[i]='R';
                        c[j]='W';
                        cnt++;
                        break;
                    }
                }
            }
        }
    //}

    printf("%d", cnt);

    return 0;
}

Score : 400 points

Problem Statement

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

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

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

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

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

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

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

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

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

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

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

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3


#include <stdio.h>

int fGrade(int x)
{
if(x>=1800) return 1;
else if(x>=1600) return 2;
else if(x>=1400) return 3;
else if(x>=1200) return 4;
else if(x>=1000) return 5;
else if(x>=800) return 6;
else if(x>=600) return 7;
else return 8;
}

int main(void)
{
  int x;
  scanf("%d", &x);
  printf("%d", fGrade(x));
  return 0;
}

Score: 100 points

Problem Statement

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

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

From 400 through 599: 8-kyu

From 600 through 799: 7-kyu

From 800 through 999: 6-kyu

From 1000 through 1199: 5-kyu

From 1200 through 1399: 4-kyu

From 1400 through 1599: 3-kyu

From 1600 through 1799: 2-kyu

From 1800 through 1999: 1-kyu

What kyu does M-kun have?

Constraints

400 \leq X \leq 1999

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

725

Sample Output 1

7

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

Thus, 7 is the correct output.

Sample Input 2

1600

Sample Output 2

2

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

Thus, 2 is the correct output.


#include<stdio.h>
int main()
{
	int a,b,c,k;
	int flag1=0,flag2=0;
	scanf("%d%d%d%d",&a,&b,&c,&k);

	while(a>=b&&k)
	{b=2*b;
	k--;
	}
	if(a<b){flag1=1;}
	while(b>=c&&k)
	{c=2*c;
	k--;
	}
	if(b<c){flag2=1;}
	if(flag1==1&&flag2==1)printf("Yes");
	else printf("No");
	return 0;
}

Score: 200 points

Problem Statement

M-kun has the following three cards:

A red card with the integer A.

A green card with the integer B.

A blue card with the integer C.

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

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

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

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

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

Determine whether the magic can be successful.

Constraints

1 \leq A, B, C \leq 7

1 \leq K \leq 7

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C
K

Output

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

Sample Input 1

7 2 5
3

Sample Output 1

Yes

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

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

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

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

Sample Input 2

7 4 2
3

Sample Output 2

No

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


#include<stdio.h>
int sum(int a,int b,int c){
 if(a>=b&&a>=c)
   return a;
  else if(b>=a&&b>=c)
    return b;
  else
    return c;
}

int main(){
  int a,b,c;
  scanf("%d",&a,&b,&c);
  printf("%d",sum(a,b,c));
  return 0;
}

Score : 100 points

Problem Statement

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

Constraints

All values in input are integers.

1 \leq L \leq R \leq 100

1 \leq d \leq 100

Input

Input is given from Standard Input in the following format:

L R d

Output

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

Sample Input 1

5 10 2

Sample Output 1

3

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

Sample Input 2

6 20 7

Sample Output 2

2

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

Sample Input 3

1 100 1

Sample Output 3

100


#include <stdlib.h>
#include <stdio.h>

int main(){
    int n;
    int i;
    int n1;
    int count = 0;
    scanf("%d",&n);
    int arr[n];
    for(i = 1; i <= n; i++){

        scanf("%d",&n1);
        arr[i] = n1;
}
    for(i = 1;i <=n; i++){

        if(i % 2 != 0 && arr[i] % 2 != 0){count++;}
}
    printf("%d",count);
    return EXIT_SUCCESS;
}

Score : 200 points

Problem Statement

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

How many squares i satisfy both of the following conditions?

The assigned number, i, is odd.

The written integer is odd.

Constraints

All values in input are integers.

1 \leq N, a_i \leq 100

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \cdots a_N

Output

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

Sample Input 1

5
1 3 4 5 7

Sample Output 1

2

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

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

For Square 3, the written integer is not odd.

Sample Input 2

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

Sample Output 2

3


#include <stdio.h>
#include <string.h>

int main(void) {
  int n, i;
  int a[10002] = {0};
  scanf("%d", &n);
  int x, y, z, aindex;

  for (x = 1; x <= n / 3; x++) {
    for (y = x; y <= n / 3; y++) {
      for (z = y; z <= n / 3; z++) {
        aindex = x * x + y * y + z * z + x * y + y * z + z * x;
        if (aindex < 10001) break;
        if (x == y && y == z) {
          // printf("aindex:%d x=%d, y=%d, z=%d\n", aindex,x,y,z);
          a[aindex] += 1;
        } else if (x == y || y == z || z == x) {
          a[aindex] += 3;
        } else
          a[aindex] += 6;
      }
    }
  }

  for (i = 1; i <= n; i++) {
    printf("%d\n", a[i]);
  }
  return 0;
}

Score : 300 points

Problem Statement

Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions:

1 \leq x,y,z

x^2 + y^2 + z^2 + xy + yz + zx = n

Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).

Constraints

All values in input are integers.

1 \leq N \leq 10^4

Input

Input is given from Standard Input in the following format:

N

Output

Print N lines. The i-th line should contain the value f(i).

Sample Input 1

20

Sample Output 1

0
0
0
0
0
1
0
0
0
0
3
0
0
0
0
0
3
3
0
0

For n=6, only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1.

For n=11, three triples, (1,1,2), (1,2,1), and (2,1,1), satisfy both of the conditions. Thus, f(6) = 3.

For n=17, three triples, (1,2,2), (2,1,2), and (2,2,1), satisfy both of the conditions. Thus, f(17) = 3.

For n=18, three triples, (1,1,3), (1,3,1), and (3,1,1), satisfy both of the conditions. Thus, f(18) = 3.


#include<stdio.h>
#include<string.h>
#include<math.h>

#define B_MAX 200001

char in_bit[200002];
int org_bit[200001];//先頭が最下位bit

long long int q_list[200001];//10進数
//int divid_list[200001];//q_listの余りから入れていく
int a_list[200001];//q_listの対

int main()
{
	int n, org_b = 0;
    long long int x = 1, x_p_m = 1, x_m_m = 1, x_p_f = 0, x_m_f = 0;

	scanf("%d", &n);
	scanf("%s", in_bit);

	for (int i = 0; i<n; i++)
	{
		if (in_bit[(n - 1) - i] == '0')
		{
			org_bit[i] = 0;
		}
		else {
			org_bit[i] = 1;
			org_b++;
		}

	}

    for (int i = 0; i<n; i++)
    {
        if (org_bit[i] == 1)
        {
            x_p_f += x_p_m;
            x_m_f += x_m_m;

            q_list[i] = -x_m_m;
        } else {
            q_list[i] = +x_p_m;
        }

        x_p_m *= 2;
        if (x_p_m > B_MAX)
         x_p_m = x_p_m % (org_b + 1);

        x_m_m *= 2;
        if (x_m_m > B_MAX)
        {
            if (org_bit != 1)
                x_m_m = x_m_m % (org_b - 1);
            else
                x_m_m = 0;
                a_list[i] = 0;
        }

    }

	for (int i = 0; i<n; i++)
	{
		long long int target;
        int answer = 1, tmp_bit;

		tmp_bit = org_b + 1 - 2 * org_bit[i];

        if (tmp_bit == 0)
        {

            target = 0;
        } else {
            if (org_bit[i] == 0)
            {
                target = ((q_list[i] + x_p_f) % (tmp_bit));
            } else {
                target = ((q_list[i] + x_m_f) % (tmp_bit));
            }

		    answer++;
        }

		while (target != 0)
		{
			int tmp_tmp_bit = 0;
            long long int tmp_tmp_target = target;

			for (; tmp_tmp_target > 0;)
			{
				tmp_tmp_bit += (1)&(tmp_tmp_target);
                tmp_tmp_target = tmp_tmp_target >> 1;
			}

			target = target % tmp_tmp_bit;
			answer++;
			tmp_bit = tmp_tmp_bit;
		}

		a_list[i] = answer;

	}

	for (int i = (n - 1); i >= 0; i--)
	{
		printf("%d\n", a_list[i]);
	}

	return 0;
}

Score : 400 points

Problem Statement

Let \mathrm{popcount}(n) be the number of 1s in the binary representation of n.
For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.

\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary.
For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted.
Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

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

X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Sample Input 1

3
011

Sample Output 1

2
1
1

X_1 = 7, which will change as follows: 7 \rightarrow 1 \rightarrow 0. Thus, f(7) = 2.

X_2 = 1, which will change as follows: 1 \rightarrow 0. Thus, f(1) = 1.

X_3 = 2, which will change as follows: 2 \rightarrow 0. Thus, f(2) = 1.

Sample Input 2

23
00110111001011011001110

Sample Output 2

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3


Score : 200 points

Problem Statement

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

The problem has N test cases.

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

See the Output section for the output format.

Constraints

1 \leq N \leq 10^5

S_i is AC, WA, TLE, or RE.

Input

Input is given from Standard Input in the following format:

N
S_1
\vdots
S_N

Output

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

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

Sample Input 1

6
AC
TLE
AC
AC
WA
TLE

Sample Output 1

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

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

Sample Input 2

10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC

Sample Output 2

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


#include <stdio.h>
#include <string.h>

int main(void) {
    char judge[4][4] = {"AC", "WA", "TLE", "RE"};
    int AC_count = 0;
    int WA_count = 0;
    int TLE_count = 0;
    int RE_count = 0;

    int i, n;
    int count = 0;
    if(scanf("%d", &n) == 1);
    if(n > 0 && n < 100000) {
        char str[n][4];
        for(i = 0; count < n; i++){
            if(scanf("%s", str[i]) == 1);
            if(strcmp(str[i], judge[0]) == 0) {
                AC_count++;
            } else if(strcmp(str[i], judge[1]) == 0) {
                WA_count++;
            } else if(strcmp(str[i], judge[2]) == 0) {
                TLE_count++;
            } else if(strcmp(str[i], judge[3]) == 0) {
                RE_count++;
            }
            count++;
        }

        printf("AC × %d\n", AC_count);
        printf("WA × %d\n", WA_count);
        printf("TLE × %d\n", TLE_count);
        printf("RE × %d\n", RE_count);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>

int  main(void)
{
  int n;
  char s[100010][5];
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%s",s[i]);
  }

  int ac;
  int wa;
  int tle;
  int re;
  for(int i=0;i<n;i++){
    if(strcmp(s[i],"AC")==0){
      ac++;
    }
    if(strcmp(s[i],"WA")==0){
      wa++;
    }
    if(strcmp(s[i],"TLE")==0){
      tle++;
    }
    if(strcmp(s[i],"RE")==0){
      re++;
    }
  }

  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);

  return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
    long int n, a=0, b=0, c=0, d=0;
    char s[100000];
    scanf("%ld", &n);
    for(int i=0; i<n; i++){
        scanf("%s", s[i]);
    }
    for(int i=0; i<n; i++){
        if(strcmp(s[i],"AC") == 0) a++;
        if(strcmp(s[i],"WA") == 0) b++;
        if(strcmp(s[i],"TLE") == 0) c++;
        if(strcmp(s[i],"RE") == 0) d++;
    }
    printf("AC x %ld", a);
    printf("WA x %ld", b);
    printf("TLE x %ld", c);
    printf("RE x %ld", d);
    return 0;
}


#include <stdio.h>
int main(){
    int a,b[200000],flag,c;
   long long int ans=0;
    scanf("%d",&a);
  for(int i=0;i<a;i++){
   scanf("%d",&b[i]);
  }
    do{
    flag=0;
    for(int i=0;i<a-1;i++){
   if(b[i]<b[i+1]) {
     c=b[i];
     b[i]=b[i+1];
     b[i+1]=c;
     flag++;
   }
  }
  }while(flag);

   ans+=b[0];
  for(int i=1;i<a-1;i++){
   ans+=b[(i+1)/2];
   }

  printf("%lld",ans);
  return 0;
}

Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6


#include <stdio.h>

void swap(int *a, int *b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int abs_int(int a)
{
	if (a >= 0) return a;
	return -a;
}

void merge_sort (int array[], int left, int right)
{
	int i, j, k, mid;
	int work[300000];

	if (left < right)
	{
		mid = (left + right) / 2;
		merge_sort(array, left, mid);
		merge_sort(array, mid+1, right);
		for (i = mid; i >= left; i--)
		{
			work[i] = array[i];
		}
		for (j = mid+1; j <= right; j++)
		{
			work[right-(j-(mid+1))] = array[j];
		}
		i = left; j = right;
		for (k = left; k <= right; k++)
		{
			if (abs_int(work[i]) > abs_int(work[j]))
			{
				array[k] = work[i++];
			}
			else
			{
				array[k] = work[j--];
			}
		}
	}
}

int main(void)
{
	int n, k;
	int a[300000];
	long long int ans = 1;
	long long int ans2 = 1, ans3 = 1;
	int i, j, l, f, f2, f3;

	scanf("%d%d", &n, &k);

	f = 1;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (a[i] > 0) f = 0;
	}

	merge_sort(a, 0, n - 1);

	if (n == k)
	{
		for (i = 0; i < k; i++)
		{
			ans *= a[i];
			ans %= 1000000007;
		}
	}
	else if (f == 1 && k % 2 == 1)
	{
		for (i = 0; i < k; i++)
		{
			ans *= a[n - 1 - i];
			ans %= 1000000007;
		}
	}
	else
	{
		for (i = 0; i < k; i++)
		{
			ans *= a[i];
			ans %= 1000000007;
		}
		if (ans < 0)
		{
			f2 = f3 = 0;
			for (i = k - 1; i >= 0; i++)
			{
				if (a[i] < 0 && f2 == 0)
				{
					f2 = 1;
					for (j = k; j > n; j++)
					{
						if (a[j] > 0)
						{
							for (l = 0; l < k; l++)
							{
								if (l == i) continue;
								ans2 *= a[l];
								ans2 %= 1000000007;
							}
							ans2 *= a[j];
							break;
						}
					}
				}
				else if(f3 == 0)
				{
					f3 = 1;
					ans3 = ans;
					for (j = k; j > n; j++)
					{
						if (a[j] < 0)
						{
							for (l = 0; l < k; l++)
							{
								if (l == i) continue;
								ans2 *= a[l];
								ans2 %= 1000000007;
							}
							ans2 *= a[j];
							break;
						}
					}
				}
			}
		}
	}

	ans %= 1000000007;
	if (ans < 0) ans += 1000000007;

	printf("%lld\n", ans);

	return 0;
}

Score : 500 points

Problem Statement

Given are N integers A_1,\ldots,A_N.

We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.

Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Constraints

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

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Sample Input 1

4 2
1 2 -3 -4

Sample Output 1

12

The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.

Sample Input 2

4 3
-1 -2 -3 -4

Sample Output 2

1000000001

The possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.

We print this value modulo (10^9+7), that is, 1000000001.

Sample Input 3

2 1
-1 1000000000

Sample Output 3

1000000000

The possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.

Sample Input 4

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Sample Output 4

999983200

Be sure to print the product modulo (10^9+7).


#include<stdio.h>
#include<math.h>
int main()
{
    int a;
    scanf("%d",&a);
    printf("%d",a+(a*a)+(a*a*a));
}

Score : 100 points

Problem Statement

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

Constraints

1 \leq a \leq 10

a is an integer.

Input

Input is given from Standard Input in the following format:

a

Output

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

Sample Input 1

2

Sample Output 1

14

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

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

Sample Input 2

10

Sample Output 2

1110


#include <stdio.h>

int main(){
    int a;
    printf("a=");
    scanf("%d", &a);
    if (1<=a && a<=10)
    {
        int b = a + a * a + a * a * a;
        printf("%d\n", b);
    }

    return 0;
}


//actdoer（A-计算）
#include <stdio.h>
int main()
{
	int a;
	scanf("%d",&a);
	printf("%d\n",a+a*a+a*a*a);
 }


#include <stdio.h>

int main(int argc, char *argv[]){
    int a, ans;
    scanf("%d",&a); //aの値を定義

    ans = a + a*a + a*a*a;

    printf("%d\n", ans);

    return 0;
}


#include <stdio.h>

int	main(int argc, char *argv[])
{
	int x;
	int ans;

	if(argc == 2 && argv[1][0] == '1' && argv[1][1] == '0')
	{
		printf("%d\n",1110);
	}
	else
	{
		x = (argv[1][0]) - 48;
		ans = x + (x * x) + (x * x * x);
		printf("%d\n",ans);
	}
	return (0);
}


#include<stdio.h>

int main(void)
{
  int a;

  scanf("%d", &a);

  printf("%d", a+a*a+a*a*a);

  return 0;

}


#include <stdio.h>
#include <string.h>

int main(void){

	char s[200000];
	char t[200000];
	int count;
	int len;

	scanf("%s", s);
	scanf("%s", t);

	count = 0;
	len = strlen(s);
	for (int i = 0; i < len; ++i)
	{
		if (s[i] != t[i])
		{
			count += 1;
		}
	}

	printf("%d\n", count);

	return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

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

S and T consists of lowercase English letters.

S and T have equal lengths.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print the answer.

Sample Input 1

cupofcoffee
cupofhottea

Sample Output 1

4

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

First, replace the sixth character c with h.

Second, replace the eighth character f with t.

Third, replace the ninth character f with t.

Fourth, replace the eleventh character e with a.

Sample Input 2

abcde
bcdea

Sample Output 2

5

Sample Input 3

apple
apple

Sample Output 3

0

No operations may be needed to achieve the objective.


#include<stdio.h>
#include<string.h>
#define MAX 2*10*10*10*10*10+1
int main(){
    char s[MAX], t[MAX];
    int  c = 1;
    int count =0;
    scanf("%s", s);
    scanf("%s", t);
    for(int i=0; i<strlen(s);i++){
        while(1){
            if(s[i]!=t[i]){
                t[i]++;
                if(c==1){
                     count++;
                     c = 0;
                }
            }
            c = 1;
            break;
        }
    }
    printf("%d\n", count);
}


#include <stdio.h>
#include <math.h>

int main(){
    char a[200000];
    char b[200000];

    scanf("%s", a);
    scanf("%s", b);

    int count = 0;
    for (int i = 0; i < sizeof(a); i++){
        if (a[i] != b[i]) count++;
        if (a[i] == '\0') break;
    }

    printf("%d", count);

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    char s[2560],t[2560];
    scanf("%s", s);
    scanf("%s", t);
    int a = 0;
    int b = 0;
    while(s[a] != '\0'){
        if(t[a] != s[a]){
            b++;
        }
        a++;
    }
    printf("%d\n", b);
    return 0;

}


#include <stdio.h>
#include <string.h>
int main(){
	char s[200001];
	char t[200001];
	int i;
	int l;
	int r;

	r = 0;
	scanf("%s", s);
	scanf("%s", t);
	l = strlen(s);

	for(i = 0; i < l; i++){
		if(s[i] != t[i]){
			r++;
		}
	}
	printf("%d\n", r);
	return 0;
}


#include <stdio.h>
#include <string.h>

int main(){

    char a[200001];
    char b[200001];

    int d = 0;
    int x;

    scanf("%s",a);
    scanf("%s",b);

    x = strlen(a);

    for(int i = 0;i < x; ++i){
        if(a[i] != b[i])
            ++d;
    }
    printf("%d\n",d);

    return 0;
}


#include<stdio.h>
#include<string.h>
int main(void)
{
	int cnt,len,i;
	char s[2000000],t[200000];
	scanf("%s",s);
	scanf("%s",t);
	len=0; cnt=0;
	len=strlen(s);
	for(i=0;i<len;i++){
		if(s[i]!=t[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


#include <stdio.h>
int main(){
    char a;
    scanf("%c", &a);
    if (a >= 'A' && a <= 'Z'){
        printf("A");
    }else{
        printf("a");
    }
    return 0;

}

Score : 100 points

Problem Statement

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

Constraints

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

Input

Input is given from Standard Input in the following format:

α

Output

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

Sample Input 1

B

Sample Output 1

A

B is uppercase, so we should print A.

Sample Input 2

a

Sample Output 2

a

a is lowercase, so we should print a.


#include<stdio.h>
signed main(){
   char a;
   scanf("%c",&a);
   if('a'<=a&&a<='z'){
       printf("a\n");
   }else{
       printf("A\n");
   }
    return(0);
}


#include<stdio.h>
#include<ctype.h>
int main(){
  char a;
  scanf("%c",&a);
  printf("%c\n",(isupper(a)?'A':'a'));
}


#include <stdio.h>

int main(){
    char p;
    scanf("%s",&p);

    if((p>='a')&&(p<='z')){
        printf("a");

    }
    else if ((p>='A')&&(p<='Z')){
        printf("A");
    }

    return 0;
}


#include<stdio.h>
int main(){
int n = 0,k = 0;
int p[1001];
int temp = 0;
scanf("%d %d", &n,&k);
for (int i = 0; i < n; i++)
{
scanf("%d", &p[i]);
for (int i = 0; i < k; i++)
{
    if (p[i] < p[i+1])
    {
        temp = temp + p[i];
    }
    else
    {
        temp = temp + p[i+1];
    }

}

}
printf("%d", temp);
    return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

1 \leq K \leq N \leq 1000

1 \leq p_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 p_2 \ldots p_N

Output

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

Sample Input 1

5 3
50 100 80 120 80

Sample Output 1

210

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

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

Sample Input 2

1 1
1000

Sample Output 2

1000


#include<stdio.h>
int main(void)
{
	char p[1001];
	int n,k,i,j,box,sum;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[i]>p[j]){
				box=p[i];
				p[i]=p[j];
				p[j]=box;
			}
		}
	}
	for(i=0;i<k;i++){
		sum=sum+p[1];
	}
printf(	"%d\n",sum);
return 0;
}


#include <stdio.h>

int main(void) {
	int n = 0;
	int k = 0;

	int p[1005] = { 0 };

	scanf("%d", &n);
	scanf("%d", &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
	}

	int min = 10000;
	int result = 0;
	int num = 0;
	for (int i = 0; i < k; i++) {
		min = 10000;
		for (int j = 0; j < n; j++)
		{
			if (p[j] < min && p[j]>0) {
				min = p[j];
				num = j;
			}
		}
		p[num] = 0;
		result += min;
	}

	printf("%d", result);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a,const void *b){
  return *(int *)a - *(int *)b;
}

int main(){
  int N=0,K=0;
  int sum=0;
  int p[1000]={0};

  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++) scanf("%d",&p[i]);
  qsort(p,N,sizeof(int),compare_int);
  for(int i=0;i<K;i++) sum += p[i];
  printf("%d\n",sum);

  return 0;
}


Score : 300 points

Problem Statement

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

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

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

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

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

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

and so on.

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

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

Now, Roger asks you:

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

Constraints

N is an integer.

1 \leq N \leq 1000000000000001

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

2

Sample Output 1

b

Sample Input 2

27

Sample Output 2

aa

Sample Input 3

123456789

Sample Output 3

jjddja


#include <stdio.h>
#include <stdlib.h>

#define ll long long
#define MD 1000000007
#define mod(n) ((n%MD+MD)%MD)
#define max(x, y) (x>y? x : y)
#define min(x, y) (x<y? x : y)
#define mul3(x, y, z) (mod(mod(x*y)*z))

ll perm(ll n, ll r){
    ll res = 1;
    for(ll i=0;i<r;i++){
        res = mod(res*(n-i));
    }
    return res;
}

ll modpow(ll x, ll y){
    ll res = 1;
    while(y>0){
        if(y&1) res = mod(res*x);
        x = mod(x*x);
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return modpow(n, MD-2);
}

ll fact[1000000*2] = {1};
ll factinv[1000000*2] = {1};
ll conb(ll n, ll r){
    return mul3(fact[n], factinv[r], factinv[n-r]);
}

ll pow25[1000000*2] = {1};
ll pow26[1000000*2] = {1};

int main(){
    ll K;
    char S[1000000];
    scanf("%lld%s", &K, S);
    // end input

    ll s_len = 0;
    for(;s_len<(ll)1e6;s_len++){
        if(!S[s_len]) break;
    }

    for(ll i=1;i<K+s_len;i++){
        fact[i] = mod(fact[i-1]*i);
        factinv[i] = inv(fact[i]);
        pow25[i] = mod(pow25[i-1]*25);
        pow26[i] = mod(pow26[i-1]*26);
    }

    ll ans = 0;
    for(ll i=K;i>=0;i--){
        ll t = mul3(conb(s_len+i-1, i), modpow(25, i), modpow(26, K-i));
        ans = mod(ans + t);
    }
    printf("%lld\n", ans);

    return 0;
}

Score: 600 points

Problem Statement

How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"?

The answer can be enormous, so print it modulo (10^9+7).

Constraints

K is an integer between 1 and 10^6 (inclusive).

S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

K
S

Output

Print the number of strings satisfying the condition, modulo (10^9+7).

Sample Input 1

5
oof

Sample Output 1

575111451

For example, we can obtain proofend, moonwolf, and onionpuf, while we cannot obtain oofsix, oofelevennn, voxafolt, or fooooooo.

Sample Input 2

37564
whydidyoudesertme

Sample Output 2

318008117


#if 0
cat <<EOF >mistaken-paste
#endif
// thx Ebi-chan!

// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("O3")

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define BIG 2000000007LL
#define VERYBIG 2000000000000000007LL
#define ULTRABIG 300000000000000000000LL

#define MOD 1000000007LL
#define FOD  998244353LL
#define HOD 1000000009LL
#define IOD  100000007LL
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 1048576

#ifdef __cplusplus
#include <queue>
#include <stack>
// #include <tuple>
#include <set>
#include <map>
#include <string>
#include <algorithm>
// #include <functional>
// #include <array>
#include <iostream>

using std::queue;
using std::priority_queue;
using std::stack;
// using std::tuple;
using std::set;
using std::map;
using std::vector;
using std::greater;
using std::pair;
using std::string;
// using std::get;
// using std::function;
// using std::array;
using std::cin;
using std::cout;
using std::endl;

template <typename T, typename U>
pair<T, U> operator+(pair<T, U> l, pair<T, U> r) {
	return pair<T, U>(l.first + r.first, l.second + r.second);
}

#endif

#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950
#endif

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	sll a;
	sll b;
	sll c;
} hwllc;

typedef struct {
	hwll a;
	hwll b;
} linell;

typedef struct {
	double a;
	double b;
} hwreal;

sll n, m;
sll h, w;
sll k;
sll q;
sll va, vb, vc, vd, ve, vf;
ull ua, ub, uc, ud, ue, uf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull umax (ull x, ull y) {
	return (x > y) ? x : y;
}

sll smin (sll x, sll y) {
	return (x < y) ? x : y;
}

sll smax (sll x, sll y) {
	return (x > y) ? x : y;
}

double dmin (double x, double y) {
	return (x < y) ? x : y;
}

double dmax (double x, double y) {
	return (x > y) ? x : y;
}

ull gcd (ull x, ull y) {
	if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}

ull bitpow (ull a, ull x, ull modulo) {
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= modulo;
		}
		x /= 2;
		a = (a * a) % modulo;
	}
	return result;
}

ull divide (ull a, ull b, ull modulo) {
	return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}

ull udiff (ull a, ull b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

sll sdiff (sll a, sll b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

int bitcount (ull n) {
	int result = 0;
	while (n) {
		if (n & 1) result++;
		n /= 2;
	}
	return result;
}

#define BEGCMP(NAME) int32_t NAME (const void *left, const void *right)
#define DEFLR(TYPE) TYPE l=*(TYPE*)left,r=*(TYPE*)right
#define CMPRET(L, R) if((L)<(R))return-1;if((L)>(R))return+1

// int32_t pullcomp (const void *left, const void *right) {
// 	ull l = *(ull*)left;
// 	ull r = *(ull*)right;
// 	if (l < r) {
// 		return -1;
// 	}
// 	if (l > r) {
// 		return +1;
// 	}
// 	return 0;
// }
BEGCMP(pullcomp){
	DEFLR(ull);
	CMPRET(l, r);
	return 0;
}
BEGCMP(prevcomp){
	DEFLR(sll);
	CMPRET(r, l);
	return 0;
}
BEGCMP(psllcomp){
	DEFLR(sll);
	CMPRET(l, r);
	return 0;
}
BEGCMP(pcharcomp){
	DEFLR(char);
	CMPRET(l, r);
	return 0;
}
BEGCMP(pdoublecomp){
	DEFLR(double);
	CMPRET(l, r);
	return 0;
}

int32_t pstrcomp (const void *left, const void *right) {
	char* l = *(char**)left;
	char* r = *(char**)right;

	return strcmp(l, r);
}

BEGCMP(phwllABcomp){
	DEFLR(hwll);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}
BEGCMP(phwllREVcomp){
	DEFLR(hwll);
	CMPRET(l.b, r.b);
	CMPRET(l.a, r.a);
	return 0;
}
BEGCMP(ptriplecomp){
	DEFLR(hwllc);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	CMPRET(l.c, r.c);
	return 0;
}
BEGCMP(ptripleREVcomp){
	DEFLR(hwllc);
	CMPRET(l.b, r.b);
	CMPRET(l.a, r.a);
	CMPRET(l.c, r.c);
	return 0;
}
BEGCMP(ptripleCABcomp){
	DEFLR(hwllc);
	CMPRET(l.c, r.c);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}
BEGCMP(phwrealcomp){
	DEFLR(hwreal);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}

int32_t pquadcomp (const void *left, const void *right) {
	linell l = *(linell*)left;
	linell r = *(linell*)right;

	sll ac = phwllABcomp(&(l.a), &(r.a));
	if (ac) return ac;
	sll bc = phwllABcomp(&(l.b), &(r.b));
	if (bc) return bc;

	return 0;
}
int32_t pfracomp (const void *left, const void *right) {
	hwll l = *(hwll*)left;
	hwll r = *(hwll*)right;

	CMPRET(l.a * r.b, l.b * r.a);
	return 0;
}
bool isinrange (sll left, sll x, sll right) {
	return (left <= x && x <= right);
}

bool isinrange_soft (sll left, sll x, sll right) {
	return (left <= x && x <= right) || (left >= x && x >= right);
}

void sw (sll *l, sll *r) {
	if (*l == *r) return;
	sll t = *l;
	*l = *r;
	*r = t;
}

void uw (ull *l, ull *r) {
	if (*l == *r) return;
	ull t = *l;
	*l = *r;
	*r = t;
}

ull frac[N_MAX * 10], invf[N_MAX * 10];
void f_init (sll n, sll m) {
	frac[0] = 1;
	for (sll i = 1; i <= n; i++) {
		frac[i] = frac[i - 1] * i % m;
	}

	invf[n] = divide(1, frac[n], m);
	for (sll i = n - 1; i >= 0; i--) {
		invf[i] = invf[i + 1] * (i + 1) % m;
	}
}
ull ncr (sll n, sll r, ull m) {
	if (n < 0 || r < 0 || n < r) return 0;
	return frac[n] * (invf[r] * invf[n - r] % m) % m;
}

sll a[N_MAX * 5];
// ull a[N_MAX + 5];
// sll a[3001][3001];
sll b[N_MAX * 5];
// ull b[N_MAX + 5];
// sll b[3001][3001];
sll c[N_MAX * 5];
sll d[N_MAX * 5];
sll e[N_MAX * 4];
char s[N_MAX + 1];
// char s[3010][3010];
char t[N_MAX + 1];
// char t[3010][3010];
char u[N_MAX + 1];
hwll xy[N_MAX * 4];
hwllc tup[N_MAX * 4];
// sll table[3005][3005];
sll table[2005][2005];
ull gin[N_MAX];
// here we go

ull parent[501910], size[501910], edges[501910];
void init (ull n) {
	for (sll i = 0; i < n; i++) {
		parent[i] = i;
		size[i] = 1;
	}
}
ull find (ull x) {
	if (parent[x] == x) return x;
	return parent[x] = find(parent[x]);
}
bool unite (ull v, ull u) {
	v = find(v);
	u = find(u);

	if (v == u) return false;

	if (size[v] < size[u]) {
		ull tmp = v;
		v = u;
		u = tmp;
	}
	size[v] += size[u];
	parent[u] = v;
	return true;
}

// sll dp[310][310][310];
sll dp[3010][3010][3];

sll solve () {
	sll i, j, ki, li;
	// ull result = 0;
	sll result = 0;
	double dresult = 0;
	// ull maybe = 0;
	sll maybe = 0;
	// ull sum = 0;
	sll sum = 0;
	sll item;
	sll *dpcell;

	n = strlen(s);
	if (k > n) k = n;

	// dp[0][0][0] = 1;
	// for (i = 0; i < n; i++) {
	// 	if (s[i] == '0') {

	// 		for (j = 0; j < n; j++) {
	// 			for (ki = 0; ki <= k; ki++) {
	// 				dp[i + 1][j + 1][ki] = dp[i][j][ki];
	// 			}
	// 		}

	// 	} else {

	// 		for (j = 0; j <= n; j++) {
	// 			for (ki = 0; ki <= k; ki++) {
	// 				dp[i + 1][0][ki] += dp[i][j][ki];
	// 				dp[i + 1][j][ki + 1] += dp[i][j][ki];
	// 			}
	// 		}

	// 		for (ki = 0; ki <= k; ki++) {
	// 			dp[i + 1][0][ki] %= FOD;

	// 			for (j = n; j >= 1; j--) {
	// 				dp[i + 1][j][ki] += dp[i + 1][j + 1][ki];
	// 				dp[i + 1][j][ki] %= FOD;
	// 			}
	// 		}

	// 	}
	// }

	// for (j = 0; j <= n; j++) {
	// 	for (ki = 0; ki <= k; ki++) {
	// 		result += dp[n][j][ki];
	// 	}
	// }
	// result %= FOD;

	for (i = 1; i <= 1000; i++) {
		if ((k * i) % 360 == 0) break;
	}
	result = i;

	printf("%lld\n", result);
	// printf("%.15f\n", dresult);
	// puts(s);

	return 0;

	success:
	// puts("YES");
	puts("Yes");
	// printf("%llu\n", result);
	// puts("0");
	// puts("First");
	return 0;

	fail:
	// puts("NO");
	// puts("No");
	// puts("0");
	puts("-1");
	// puts("-1 -1 -1");
	// puts("Second");
	return 1;
}

int32_t main (int argc, char *argv[]) {
	int32_t i, j;

	n = 3;
	m = 0;
	h = 5;

	// scanf("%llu", &m);
	// scanf("%lld", &w);
	// scanf("%lld%lld", &h, &w);
	// scanf("%lld%lld", &n, &m);
	// scanf("%lld", &k, &n, &m);
	// scanf("%llu%llu", &h, &w);
	// scanf("%lld", &q);
	// scanf("%lld%lld%lld%lld", &va, &vb, &vc, &vd);
	// va--;
	// vb--;
	// scanf("%llu%llu%llu%llu", &ua, &ub, &uc, &ud, &ue);
	// scanf("%s", s);
	// scanf("%s", t);
	// scanf("%s", u);
	scanf("%lld", &k);
	// scanf("%lld", &m);
	// scanf("%lld", &n);
	// for (i = 0; i < n; i++) {
	// 	// scanf("%s", s[i]);
	// 	scanf("%lld", &c[i]);
	// }
	// scanf(" %c", &ch);
	// scanf("%llu", &q);
	for (i = 0; i < 0; i++) {

		// scanf("%lld%lld", &xy[i].a, &xy[i].b);
		// scanf("%lld%lld%lld", &tup[i].a, &tup[i].b, &tup[i].c);
		// scanf("%lld", &c[i]);

		scanf("%lld", &a[i]);
		// scanf("%lld", &b[i]);
		// scanf("%lld", &c[i]);
		// scanf("%lld", &d[i]);
		// scanf("%lld", &e[i]);
		a[i]--;
		// b[i]--;
		// c[i]--;
		// d[i]--;
		// xy[i].a--;
		// xy[i].b--;
		// tup[i].a--;
		// tup[i].b--;
	}
	// scanf("%lld%lld", &va, &vb);
	// scanf("%llu", &m);
	// scanf("%llu", &q);
	// scanf("%s", t);
	// for (i = 0; i < n; i++) {
	// 	// scanf("%lld%lld", &xy[i].a, &xy[i].b);
	// 	// xy[i].a--;
	// 	// xy[i].b--;
	// 	// scanf("%lld", &a[i], &b[i]);
	// 	// scanf("%lld", &b[i]);
	// 	// a[i]--;
	// 	// b[i]--;
	// 	scanf("%lld", &c[i]);
	// 	// scanf("%lld", &d[i]);
	// 	// scanf("%lld", &e[i]);
	// 	c[i]--;
	// 	// d[i]--;
	// }

	// for (i = 0; i < q; i++) {
	// 	// scanf("%lld%lld", &xy[i].a, &xy[i].b);
	// 	scanf("%lld", &c[i]);
	// 	// xy[i].a--;
	// 	// xy[i].b--;
	// }

	// for (i = 0; i < h; i++) {
	// 	for (j = 0; j < w; j++) {
	// 		scanf("%lld", &table[i][j]);
	// 		// table[i][j]--;
	// 	}
	// }
	// for (i = 0; i < n; i++) {
	// 	scanf("%s", s[i]);
	// }
	// for (i = 0; i < n; i++) {
	// 	scanf("%s", t[i]);
	// }
	// scanf("%llu", &q);
	// for (i = 0; i < q; i++) {
	// 	scanf("%lld%lld%lld", &e[i], &c[i], &d[i]);
	// 	c[i]--;
	// }

	solve();

	return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

1 \leq X \leq 179

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

90

Sample Output 1

4

Takahashi's path is a square.

Sample Input 2

1

Sample Output 2

360


#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		a = a * a % p;
		n /= 2;
	}
	return res;
}
int main()
{
	long long int a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	long long int p = 998244353;
	long long int dp[2][3003];
	long long int i, j;
	for (i = 0; i < c; i++)
		dp[0][i] = 0;
	dp[0][a - 1] = modpow(b, (c - a), p);
	long long int s;
	for (i = b; i < d; i++)
	{
		s = 0;
		for (j = a - 1; j < c; j++)
		{
			dp[1][j] = (dp[0][j] * (j + 1) % p + s) % p * modpow(modpow(i, c - j - 1, p), p - 2, p) % p * modpow(i + 1, c - j - 1, p) % p;
			s = (s + dp[0][j]) % p;
		}
		for (j = a - 1; j < c; j++)
			dp[0][j] = dp[1][j];
	}
	long long int ans = 0;
	for (i = a - 1; i < c; i++)
		ans = (ans + dp[0][i]) % p;
	printf("%lld\n", ans);
	return 0;
}

Score : 600 points

Problem Statement

We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:

Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal".

If we choose "vertical", insert one row at the top of the grid, resulting in an (a+1) \times b grid.

If we choose "horizontal", insert one column at the right end of the grid, resulting in an a \times (b+1) grid.

Then, paint one of the added squares black, and the other squares white.

Assume the grid eventually has C horizontal rows and D vertical columns. Find the number of ways in which the squares can be painted in the end, modulo 998244353.

Constraints

1 \leq A \leq C \leq 3000

1 \leq B \leq D \leq 3000

A, B, C, and D are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of ways in which the squares can be painted in the end, modulo 998244353.

Sample Input 1

1 1 2 2

Sample Output 1

3

Any two of the three squares other than the bottom-left square can be painted black.

Sample Input 2

2 1 3 4

Sample Output 2

65

Sample Input 3

31 41 59 265

Sample Output 3

387222020


#include <stdio.h>

#define LENGTH 256

int main(void) {
  int x1 = 1;
  int x2 = 2;
  int x3 = 3;
  int x4 = 4;
  int x5 = 5;
  char input[LENGTH];
  while (1) {
    fgets(input, LENGTH-1, stdin);
    sscanf(input, "%d %d %d %d %d", &x1, &x2, &x3, &x4, &x5);
    if (x1 == 99) break;
    int n = 0;
    if (x1 == 0) n = 1;
    else if (x2 == 0) n = 2;
    else if (x3 == 0) n = 3;
    else if (x4 == 0) n = 4;
    else n = 5;
    printf("%d\n", n);
  }
  return 0;

}

Score : 100 points

Problem Statement

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

The variable x_i was initially assigned a value of i.

Snuke chose one of these variables and assigned it 0.

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

Find out which variable Snuke assigned 0.

Constraints

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

Input

Input is given from Standard Input in the following format:

x_1 x_2 x_3 x_4 x_5

Output

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

Sample Input 1

0 2 3 4 5

Sample Output 1

1

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

Sample Input 2

1 2 0 4 5

Sample Output 2

3


#include <stdio.h>

#define LENGTH 256

int main(void) {
    char input[LENGTH];
    int n[5];
    while (1) {
        printf("index: ");
        fgets(input, LENGTH-1, stdin);
        sscanf(input, "%d%d%d%d%d", &n[0],&n[1],&n[2],&n[3],&n[4]);

        for(int i=0;i<5;i++){
          if(n[i]==0){
            printf("%d\n",i+1);
          }
        }
    }
}


#include<stdio.h>
#include<string.h>
int main()
{
    int arr[10],x,i;

    for(i=1;i<=5;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            x=i;
        }
    }

    printf("%d\n",x);
    return 0;
}


#include <stdio.h>

int main(void) {
  int i,x,y,kame,turu,ans;
  i=0;
  x=0;
  y=0;
  kame=0;
  turu=0;
  ans=0;
  scanf("%d",&x);
  scanf("%d",&y);
  kame=(y-2*x)/2*4;
  turu=(y-kame)/2;
  if((x==1&&y==2)||(x==1&&y==4))
  {
    printf("Yes");
  }
  else if(turu%2==0&&y>turu&&turu>0)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
  return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

1 \leq X \leq 100

1 \leq Y \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

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

Sample Input 1

3 8

Sample Output 1

Yes

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

Sample Input 2

2 100

Sample Output 2

No

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

Sample Input 3

1 2

Sample Output 3

Yes

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


#include <stdio.h>
int main(){
    int x, y;

    scanf("%d %d",&x,&y);
    if(y%2==1){
      printf("No");
    }else if(y>=2*x && y<=4*x){
      printf("Yes");
    }else{
      printf("No");
    }
return 0;
}


#include <stdio.h>
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if(y%2==0&&2*x<=y&&y<=4*x)puts("Yes");
	else puts("No");
}


Score : 300 points

Problem Statement

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

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

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

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

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

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

Sample Input 3

100 0

Sample Output 3

100

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


#include<stdio.h>
#include<stdlib.h>
typedef  long long ll;

int cmpnum(const void * n1, const void * n2)
{
  if (*(int *)n1 > *(int *)n2)
  {
    return 1;
  }
  else if (*(int *)n1 < *(int *)n2)
  {
    return -1;
  }
  else
  {
    return 0;
  }
}

int main(void)
{

  int x,n;
  int p[200];
  int tmp[200];
  int k=0;
  int i=0;
  scanf("%d %d",&x,&n);
  if(n==0){
    printf("%d\n",x);
    return 0;
  }
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }

  qsort(p,n,sizeof(int), cmpnum);
  for(int j=1;j<=100;j++){

    if(p[i]!=j){
      tmp[k]=j;
      k++;
    }else if(i+1<n){
      i++;
    }
  }
  //
  // for(int i=0;i<k;i++){
  //   printf("%d ",tmp[i]);
  // }
  // puts(" ");

  int min=300;
  int min_ans;
  for(int i=0;i<k;i++){
    //  printf("%d\n",x-tmp[i]);
    if(abs(x-tmp[i])<min)
    min_ans=tmp[i];
    min=abs(x-tmp[i]);
  }

  printf("%d\n",min_ans);
  return 0;
}


#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

bool k[202];
int main(void){
	int x=nextint();
	int n=nextint();
	for(int i=0; i<n; i++){
		k[nextint()]=true;
	}
	if(!k[x]){
		printf("%d\n", x);
		return 0;
	}
	for(int i=1; i<n; i++){
		if(x-i<0 || !k[x-i]){
			printf("%d\n", x-i);
			return 0;
		}
		if(!k[x+i]){
			printf("%d\n", x+i);
			return 0;
		}
	}
}


Score : 100 points

Problem Statement

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

Constraints

3 \leq |S| \leq 20

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print your answer.

Sample Input 1

takahashi

Sample Output 1

tak

Sample Input 2

naohiro

Sample Output 2

nao


Score : 200 points

Problem Statement

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

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

Constraints

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

1 \leq V,W \leq 10^9

1 \leq T \leq 10^9

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

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

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD 1000000007
#define INF 1000000000000000000
#define PI 3.14159265359
#define ll long long
#define MYPOW_t int

int main(){
    ll a,b,v,w,t;
    scanf("%lld%lld",&a,&v);
    scanf("%lld%lld",&b,&w);
    scanf("%lld",&t);
    if (w>=v) printf("NO");
    else{
        if (t>=floor(labs(a-b)/(v-w))) printf("YES");
        else printf("NO");
    }
    return 0;
}
/*if (labs(a-b)%(v-w)==0) {}
 else printf("NO");*/


#include <stdio.h>
int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  printf("%d\n", a * b);
  return 0;
}

Score : 100 points

Problem Statement

Compute A \times B.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Sample Input 1

2 5

Sample Output 1

10

We have 2 \times 5 = 10.

Sample Input 2

100 100

Sample Output 2

10000


#include<stdio.h>
long long min(long long a,long long b){
  if(a>=b){return b;}
  else{return a;}
}

int main(){
  long long n;
  scanf("%lld",&n);

  int ans=0,flag,flag1=0;

  long long k=2;
  for(int i=1;i>=0;i++){
    if(n%k==0){
      ans+=1;
      n=n/k;
      k*=2;
    }
    else{break;}
  }

  for(int i=1;i>=0;i++){
    if(n%2==0){
      n=n/2;
    }
    else{break;}
  }

  if(n==1){
    printf("%d",ans);
    return 0;
  }

  for(long long p=3;p<=1000000;p++){
    flag=0;
    for(long long i=2;i<=min(1000,p-1);i++){
      if(p%i==0){
        flag=1;
        break;
      }
    }
    if(flag==0){
      flag1=1;
      k=p;
      for(int j=1;j>0;j++){
        if(n%k==0){
          ans+=1;
          n=n/k;
          k*=p;
        }
        else{break;}
      }
    }
  }

  printf("%d",ans);
  return 0;
}


#include<stdio.h>
int main()
{
        int a=0,b=0;

        scanf("%d%d",&a,&b);
        printf("%d",a*b);

        return 0;
};


#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\n",a*b);
  return 0;
}


#include <stdio.h>

int main(void) {
    int a,b;
    scanf ("%d %d", a, b);
    printf ("%d", a * b);
    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    long long int n = 0;
    int counter = 0;
    int tmp_counter = 0;

    scanf("%lld", &n);

    for (long long int i = 2; n != 1; i++)
    {
        tmp_counter = 0;

        while ((n%i) == 0)
        {
            n = n/i;
            tmp_counter ++;
        }

        for (int i = 1; tmp_counter >= i; i++)
        {
            counter ++;
            tmp_counter = tmp_counter - i;
        }

    }

    printf("%d", counter);

    return 0;
}

Score : 400 points

Problem Statement

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

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

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

z divides N;

z is different from all integers chosen in previous operations.

Then, replace N with N/z.

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

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

24

Sample Output 1

3

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

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

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

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

Sample Input 2

1

Sample Output 2

0

We cannot apply the operation at all.

Sample Input 3

64

Sample Output 3

3

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

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

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

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

Sample Input 4

1000000007

Sample Output 4

1

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

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

Sample Input 5

997764507000

Sample Output 5

7


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 1000004
typedef long long ll;
int main(){
    ll N;
    ll prime_index=0;
    ll prime_seq[MAX]={0};
    bool prime_flag[MAX];    //素数ならtrue;
    for(ll i=2;i<MAX;i++) prime_flag[i]=true;
    scanf("%lld",&N);
    //素数列作るよ
    for(ll i=2;i<MAX;i++){
        if(!prime_flag[i]) continue;
        for(ll j=2;i*j<MAX;j++)
            prime_flag[i*j]=false;
    }
    for(ll i=2;i<MAX;i++)
        if(prime_flag[i]) prime_seq[prime_index++]=i;
    //素数列作り終わったよ
    //素因数分解始まるよ
    ll prime_fac[MAX]={0};
    bool f=false;
    while(N!=1){
        ll i=0;
        while(N%prime_seq[i]!=0 && prime_index>i) i++;
        if(prime_index<=i){
            printf("%d",1);
            return 0;
        }
        N/=prime_seq[i];
        prime_fac[prime_seq[i]]++;
        f=true;
    }
    //素因数分解終わったよ

    //総和のテーブル作るよ
    ll table[100];
    table[1]=1;
    for(ll i=2;i<=100;i++)
        table[i]=table[i-1]+i;
    //総和のテーブル作り終わったよ
    ll ans=0;
    for(ll i=0;i<prime_index;i++){
        if(!prime_fac[prime_seq[i]]) continue;
        ll j=1;
        while(table[j]<=prime_fac[prime_seq[i]]) j++;
        j--;
        printf("%d\n",j);
        ans+=j;
    }
    printf("%lld",ans);
}


Score : 500 points

Problem Statement

There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i.
Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.

Notes

The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N in ascending order.

If N is odd, the median is x_{(N+1)/2};

if N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.

Constraints

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

1 \leq A_i \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the answer.

Sample Input 1

2
1 2
2 3

Sample Output 1

3

If X_1 = 1 and X_2 = 2, the median is \frac{3}{2};

if X_1 = 1 and X_2 = 3, the median is 2;

if X_1 = 2 and X_2 = 2, the median is 2;

if X_1 = 2 and X_2 = 3, the median is \frac{5}{2}.

Thus, the median can take three values: \frac{3}{2}, 2, and \frac{5}{2}.

Sample Input 2

3
100 100
10 10000
1 1000000000

Sample Output 2

9991


#include <stdio.h>
#include <math.h>

int main(void)
{
    int h1, m1, h2, m2, k, diff;

    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
    diff = abs((60*h2 + m2) - (60*h1 + m1)) - k;

    if(diff < 0)
        diff = 0;

    printf("%d", diff);

    return 0;
}

Score : 100 points

Problem Statement

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

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

Constraints

0 \le H_1, H_2 \le 23

0 \le M_1, M_2 \le 59

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

K \ge 1

Takahashi is up for at least K minutes.

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

Input

Input is given from Standard Input in the following format:

H_1 M_1 H_2 M_2 K

Output

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

Sample Input 1

10 0 15 0 30

Sample Output 1

270

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

Sample Input 2

10 0 12 0 120

Sample Output 2

0

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


#include <stdio.h>
#include <string.h>

int main(void)
{
char x[1000000];
scanf("%s", x);
for (int i = 0; i < strlen(x); i++) {
  if(x[i] !='?') {
      printf("%c", x[i]);
  } else {
      printf("D");
  }
}
return 0;
}

Score : 200 points

Problem Statement

For a string S consisting of the uppercase English letters P and D, let the doctoral and postdoctoral quotient of S be the total number of occurrences of D and PD in S as contiguous substrings. For example, if S = PPDDP, it contains two occurrences of D and one occurrence of PD as contiguous substrings, so the doctoral and postdoctoral quotient of S is 3.

We have a string T consisting of P, D, and ?.

Among the strings that can be obtained by replacing each ? in T with P or D, find one with the maximum possible doctoral and postdoctoral quotient.

Constraints

1 \leq |T| \leq 2 \times 10^5

T consists of P, D, and ?.

Input

Input is given from Standard Input in the following format:

T

Output

Print one string with the maximum possible doctoral and postdoctoral quotient among the strings that can be obtained by replacing each ? in T with P or D.
If there are multiple such strings, you may print any of them.

Sample Input 1

PD?D??P

Sample Output 1

PDPDPDP

This string contains three occurrences of D and three occurrences of PD as contiguous substrings, so its doctoral and postdoctoral quotient is 6, which is the maximum doctoral and postdoctoral quotient of a string obtained by replacing each ? in T with P or D.

Sample Input 2

P?P?

Sample Output 2

PDPD


#include <stdio.h>
#include <string.h>

int main(){
  char t[200005];  scanf("%s", t);
  for(int i=0; i<strlen(t)-1; i++){
    if(t[i] == '?'){
      if(t[i+1] == '?' || t[i+1] == 'P'){
	printf("D");
      }else if(t[i+1] == 'D'){
	printf("P");
      }
    }else{
      printf("%c", t[i]);
    }
  }
  if(t[strlen(t)-1] == '?'){
    printf("D\n");
  }else{
    printf("%c\n", t[strlen(t)-1]);
  }
  return 0;
}


Score: 100 points

Problem Statement

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

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

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

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

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

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

Constraints

N is a positive integer not exceeding 999.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

16

Sample Output 1

pon

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

Sample Input 2

2

Sample Output 2

hon

Sample Input 3

183

Sample Output 3

bon


#include <stdio.h>
#include <string.h>

int main()
{
int k;
  char string[105];
  scanf("%d", &k);
  scanf("%s", string);
  int len = strlen(string);

  for (int i = 0; i < k && i < len; i++)
  {
    printf("%c", string[i]);
  }

  if (len > k)
  {
     printf("...\n");
  }

	return 0;
}

Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

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

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

Constraints

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

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

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

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

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.


#include<stdio.h>
#include<string.h>
int main()
{
	int k;
	char s[101];

	scanf("%s",s);

	if(strlen(s)<=k)
		printf("%s\n",s);
	else{
		for(int i=0;i<k;i++)
			printf("%c",s[i]);
		printf("...\n");
	}
	return 0;
}


/* ex4_2
  key_tree */

#include <stdio.h>
#include <math.h>

int main(void){
    // 入力
    int length_A, length_B, time, minute;
    scanf("%d %d %d %d",&length_A, &length_B, &time, &minute);

    double time_angle, minute_angle, angle, ans;
    // 時針と分針の角度をラジアンで求める
    time_angle = 2 * M_PI* ((time + minute / 60.0)/12);
    minute_angle = 2 * M_PI * minute / 60.0;
    // 針同士のなす角度
    angle = fabs(minute_angle - time_angle);
    //　余弦定理
    ans = sqrt(pow(length_A, 2) + pow(length_B, 2)
          - 2 * length_A *length_B * cos(angle));

    // 小数点以下10桁を表示
    printf("%.10lf\n", ans);

    return 0;

}

Score: 300 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

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

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

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

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

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


#include <stdio.h>
#include <math.h>

int main()
{

    double a,b,h,m;
    scanf("%lf", &a);
    scanf("%lf", &b);
    scanf("%lf", &h);
    scanf("%lf", &m);
    double big = 0;
    double small = 0;//動きが。。

    big = 2.0 * M_PI * m / 60.0;
    small = 2.0 * M_PI * (h * 60 + m) / (60 * 12); //分で計算

    double ans = sqrt(a * a + b * b - 2 * a * b * cos(small - big));

    printf("%.13f", ans);

    printf("\n");
}


#include<stdio.h>
#include<stdlib.h>

int arl[100100];
int *ars[100100];
int ans[100100];

int queue[100100];
int qlen,qhead;

void enqueue(int n){
    queue[qhead+qlen > 100100 ? (qhead+qlen) % 100100 : qhead+qlen] = n;
    qlen++;
}

int dequeue(void){
    int ret = queue[qhead];
    qlen--;
    qhead = qhead+1 > 100100 ? (qhead+1) % 100100: qhead+1;
    return ret;
}

int main(void){
    register int i;
    int n,m;
    scanf("%d%d",&n,&m);
    int a[m],b[m];
    for(i = 0;i < m;i++)scanf("%d%d",&a[i],&b[i]);
    for(i = 0;i < m;i++){
        a[i]--;b[i]--;
        ars[a[i]] = realloc(ars[a[i]],arl[a[i]]+1);
        ars[b[i]] = realloc(ars[b[i]],arl[b[i]]+1);
        ars[a[i]][arl[a[i]]] = b[i];
        ars[b[i]][arl[b[i]]] = a[i];
        arl[a[i]]++;
        arl[b[i]]++;
    }
    for(i = 0;i < n;i++)ans[i] = -1;
    enqueue(0);
    while(qlen){
        int cur = dequeue();
        for(i = 0;i < arl[cur];i++)if(ans[ars[cur][i]] == -1){
            ans[ars[cur][i]] = cur;
            enqueue(ars[cur][i]);
        }
    }
    puts("Yes");
    for(i = 1;i < n;i++)printf("%d\n",ans[i]+1);
}

Score: 400 points

Problem Statement

There is a cave.

The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.

It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.

Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.

If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.

Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

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

1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)

A_i \neq B_i\ (1 \leq i \leq M)

One can travel between any two rooms by traversing passages.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

If there is no way to place signposts satisfying the objective, print No.

Otherwise, print N lines. The first line should contain Yes, and the i-th line (2 \leq i \leq N) should contain the integer representing the room indicated by the signpost in Room i.

Sample Input 1

4 4
1 2
2 3
3 4
4 2

Sample Output 1

Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:

Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.

Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \to 2 \to 1. This is the minimum number of passages possible.

Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \to 2 \to 1. This is the minimum number of passages possible.

Thus, the objective is satisfied.

Sample Input 2

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

Sample Output 2

Yes
6
5
5
1
1

If there are multiple solutions, any of them will be accepted.


#include<stdio.h>
#include <string.h>

int main (){
  char S[10],T[11];
  int count = 0;
  scanf("%s",S);
  scanf("%s",T);

  int S_length = sizeof S/sizeof S[0];
  for(int i = 0 ;i < S_length;i++){
     if(S[i] == T[i]){
        count++;
     }
  }

  if(count == S_length){
     printf("Yes");
  }else{
     printf("No");
  }

  return 0;
}

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

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

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

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

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

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

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

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

Sample Input 2

snuke
snekee

Sample Output 2

No

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

Sample Input 3

a
aa

Sample Output 3

Yes


#include<stdio.h>
int main(void) {
    int a, b, c, k,result;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if (k <= a) {
        result = k;
    }
    else if ((k > a) && (k <= a + b)) {
        result = a;
    }
    else {
        result = a - (k - a - b);
    }
    printf("%d\n", result);
    return 0;

}


#include <stdio.h>
#include <string.h>

int main(){
    char s[10], t[10];
    int lens, lent;
    int cnt=0, len;

    scanf("%s", s);
    scanf("%s", t);
    lens = strlen(s);
    lent = strlen(t);
    len = lent - lens;

    for(int i = 0; i < lens; i++){
        if(s[i] == t[i]){
            cnt++;
        }
    }
    if(cnt == lens && len == 1){
        printf("Yes");
    }else{
        printf("No");
    }
    }


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
    char S[11];
    char T[12];

    scanf("%s", S);
    scanf("%s", T);

    int len = strlen(S);

    int result = strncmp(S, T, len);

    if (result == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


//MD. HASNAIN ALI (UNSOLVED)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a<b? a:b)
#define SWAP(a,b) {       \
                    a=a+b;\
                    b=a-b;\
                    a=a-b;}
#define LL long long

int main()
{
    char x[11],y[11];
    int a,b,c=0,i;
    scanf("%s",x);
    scanf("%s",y);
    a=strlen(x);
    b=strlen(y);
    for(i=0;i<a;i++)
    {
        if(x[i]==y[i]) c++;
    }
    if(c==a) printf("Yes\n");
    else printf("No\n");

    return 0;
}


#include<stdio.h>

void main(void)
{
  long int a,b,c,k;
  long int result=0;
  scanf("%ld %ld %ld %ld",&a,&b,&c,&k);
  if(a>=k){
    result=a;
  }else if(a<k&&(a+b)>k){
    result=a;
  }else{
    result=0;
  }
  printf("%ld\n",result);
}

Score : 200 points

Problem Statement

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

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

Constraints

All values in input are integers.

0 \leq A, B, C

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

Input

Input is given from Standard Input in the following format:

A B C K

Output

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

Sample Input 1

2 1 1 3

Sample Output 1

2

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

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
void cin2(ll *a, ll *b){ scanf("%lld%lld",&(*a),&(*b)); }
void cin3(ll *a, ll *b, ll *c){ scanf("%lld%lld%lld",&(*a),&(*b),&(*c)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p  which meets  a[p]==val :1  >=:2   >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type);  return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1;  }
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i  which meets ai==x
ll count(ll a[], int l, int r, ll x){  int p = lower_bound(a,l,r,x,1);  return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) {  return strcmp( (char *)a , (char *)b ); }  // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

ll inv[200005],finv[200005],mod_fac[200005];
void makeinv(ll n){  inv[1]=1;finv[0]=finv[1]=1;  rep(i,2,n+1){  inv[i]= MOD2 - inv[MOD2%i] * (MOD2 / i) % MOD2;   finv[i] = finv[i - 1] * inv[i] % MOD2;  }  }
void make_mod_fac(ll n, ll mod){ ll x=1; mod_fac[0]=mod_fac[1]=x; rep(i,2,n+1){ x*=i%mod; x%=mod; mod_fac[i]=x; } }
ll mod_nck(ll n, ll k, ll mod){ return mod_fac[n]*finv[k]%mod*finv[n-k]%mod; }
ll modpow(ll r,ll n){  ll t=1,s=r;  while(n>0){ t = (n&1) ? t*s%MOD2 : t;  s=s*s%MOD2; n>>=1; }  return r?t:0;  }

int main(void){
    // fgets(s,sizeof(s),stdin);
    // char ;
    ll n,m,k;
    ll ans=0;
    cin(&n);
    cin(&m);
    cin(&k);
    makeinv(200003);
    make_mod_fac(200003,MOD2);
    // cin2(&,&);
    // cin3(&,&,&);
    // scanf("%s",);
    // ll [n];
    if(m==1){
        if(n==k+1) printf("1\n");
        else printf("0\n");
        return 0;
    }
    if(n==1){
        printf("%lld\n",m);
        return 0;
    }
    ll piv=m*modpow(m-1,n-1)%MOD2;
    // printf("%lld ",piv);
    rep(i,0,k+1){
        ans+= mod_nck(n-1,i,MOD2)*piv%MOD2;
        ans%=MOD2;
        // printf("%lld ",ans);
        piv=piv*inv[m-1]%MOD2;
    }

    printf("%lld\n",ans);
    // printf("%lld\n",modpow(0,150));
    return 0;
}

Score : 500 points

Problem Statement

There are N blocks arranged in a row. Let us paint these blocks.

We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.

Find the number of ways to paint the blocks under the following conditions:

For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.

There may be at most K pairs of adjacent blocks that are painted in the same color.

Since the count may be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

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

0 \leq K \leq N - 1

Input

Input is given from Standard Input in the following format:

N M K

Output

Print the answer.

Sample Input 1

3 2 1

Sample Output 1

6

The following ways to paint the blocks satisfy the conditions: 112, 121, 122, 211, 212, and 221. Here, digits represent the colors of the blocks.

Sample Input 2

100 100 0

Sample Output 2

73074801

Sample Input 3

60522 114575 7559

Sample Output 3

479519525


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#define MOD 1000000007

int *array;

int min(int a, int b) {
    return a<b?a:b;
}

int max(int a, int b) {
    return a>b?a:b;
}

int compare(const void* a, const void* b) {
    return *(int*)a-*(int*)b;
}

int cmp(const void *a, const void *b){
    int ia = *(int *)a;
    int ib = *(int *)b;
    return array[ia] < array[ib] ? -1 : array[ia] > array[ib];
}

int abs(int n) {
    if(n < 0)
        return n*(-1);
    return n;
}

void swap(int *a, int *b) {
    *a = (*a)^(*b);
    *b = (*a)^(*b);
    *a = (*a)^(*b);
}

int binSearch(int a[], int x, int l, int r) {
    if(r >= l) {
        int mid = l + ((r-l)>>1);
        if(a[mid] == x)
            return mid;
        if(a[mid] > x) {
            return binSearch(a, x, l, mid-1);
        }
        else if(a[mid] < x) {
            return binSearch(a, x, mid+1, r);
        }
    }
    return -1;
}

void testCase() {
    int i, n;
    if(scanf("%d", &n)) {
        // char s[1000001];
        int open=0, close=0;
        for(i=0;i<n;i++) {
            int x=0, y=0;
            char s[1000001];
            if(scanf("%s", s));
            int j=0;
            for(int k=0;s[k];k++) {
                if(s[k] == '(') {
                    j++;
                }
                else if(s[k] == ')') {
                    if(j > 0) {
                        j--;
                    }
                    else {
                        x++;
                    }
                }
            }
            y += j;
            if(i == 0) {
                open = y;
                close = x;
            }
            else {
                if(x == 0 && y != 0) {
                    close -= y;
                    if(close < 0) {
                        close=0;
                        open += (y-close);
                    }
                }
                else if(x != 0 && y == 0) {
                    open -= x;
                    if(open < 0) {
                        open=0;
                        close += (y-open);
                    }
                }
                else {
                    open += x;
                    close += y;
                }
            }
        }
        if(open == 0 && close == 0) {
            printf("Yes");
        }
        else
            printf("No");
    }
}

int main() {
    int t=1;
    // scanf("%d", &t);
    while(t--) {
        testCase();
        printf("\n");
    }
    return 0;
}

Score : 600 points

Problem Statement

A bracket sequence is a string that is one of the following:

An empty string;

The concatenation of (, A, and ) in this order, for some bracket sequence A ;

The concatenation of A and B in this order, for some non-empty bracket sequences A and B /

Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order?

Constraints

1 \leq N \leq 10^6

The total length of the strings S_i is at most 10^6.

S_i is a non-empty string consisting of ( and ).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No.

Sample Input 1

2
)
(()

Sample Output 1

Yes

Concatenating (() and ) in this order forms a bracket sequence.

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

4
((()))
((((((
))))))
()()()

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No


#include <stdio.h>

int main(){
	char s[4];
	scanf("%s",s);
	if(s[1]=='B'){
		puts("ARC");
	}
	else if(s[1]=='R'){
		puts("ABC");
	}
	return 0;
}

Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

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

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

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

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

ABC

Sample Output 1

ARC

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


#include <stdio.h>

int main(){
  char s[4];
  scanf("%s", s);
  if(s[1] == 'B') {
     printf("ARC\n");
  }else {
     printf("ABC\n");
  }
  return 0;
}


#include <stdio.h>
typedef long long ll;
typedef struct hoge{
    ll A;
    ll left;
    ll right;
}height;

int main(){
  ll N;
  ll ans=0;
  scanf("%lld",&N);
  height H[N];
  for(ll i = 0;i<N;i++){
    scanf("%lld",&H[i].A);
    H[i].left = i-H[i].A;
    H[i].right = i+H[i].A;
  }
  for(ll i = 0;i<N;i++) for(ll j = N-1;j>i;j--){
    if(H[i].right == H[j].left) ans++;
  }
  printf("%lld\n",ans);
  return 0;
}


#include<stdio.h>

int main(void) {

	char s[10];

	scanf("%s", s);

	if (s[0] == 'A'&&s[1] == 'B'&&s[2] == 'C') printf("ARC");
	else printf("ABC");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N , K;
 scanf("%d %d",&N,&K);
 int array[N+1];
 memset(array,0,sizeof(array[0])*(N+1));
 int d[K];
 for (int i = 0;i<K;i++)
 {
 	scanf("%d",&d[i]);
 	int A[d[i]];
    for (int j = 0;j<d[i];j++)
	{
	  scanf("%d",&A[j]);
	  array[A[j]]++;
	}
 }

 int count=0;
 for (int i=1;i<=N;i++)
 {
   if (array[i]==0)
	count++;
 }

 printf("%d",count);

   return 0;
}

Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 100

1 \leq d_i \leq N

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the answer.

Sample Input 1

3 2
2
1 3
1
3

Sample Output 1

1

Snuke 1 has Snack 1.

Snuke 2 has no snacks.

Snuke 3 has Snack 1 and 2.

Thus, there will be one victim: Snuke 2.

Sample Input 2

3 3
1
3
1
3
1
3

Sample Output 2

2


#include<stdio.h>

int main(void) {
	int i, j, n, k, d, scan, ans = 0;
	int sunuke[101];

	for (i = 0; i <= 100; ++i) {
		sunuke[i] = 0;
	}
	scanf("%d %d", &n, &k);
	for (i = 0; i < k; ++i) {
		scanf("%d", &d);
		for (j = 0; j < d; ++j) {
			scanf("%d", &scan);
			sunuke[scan]++;
		}
	}

	for (i = 1; i <= n; ++i) {
		if (sunuke[i] == 0) {
			ans++;
		}
	}
	printf("%d", ans);
	return 0;
}