Score : 400 points

Problem Statement

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

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

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

Constraints

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

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

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

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

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5


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.


Score : 200 points

Problem Statement

We have a board with H horizontal rows and W vertical columns of squares.
There is a bishop at the top-left square on this board.
How many squares can this bishop reach by zero or more movements?

Here the bishop can only move diagonally.
More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds:

r_1 + c_1 = r_2 + c_2

r_1 - c_1 = r_2 - c_2

For example, in the following figure, the bishop can move to any of the red squares in one move:

Constraints

1 \leq H, W \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H \ W

Output

Print the number of squares the bishop can reach.

Sample Input 1

4 5

Sample Output 1

10

The bishop can reach the cyan squares in the following figure:

Sample Input 2

7 3

Sample Output 2

11

The bishop can reach the cyan squares in the following figure:

Sample Input 3

1000000000 1000000000

Sample Output 3

500000000000000000


#include <stdio.h>

int main(void) {
	long long int h,w;
	scanf("%lld%lld",&h,&w);
	long long int ans;
	ans=h*w/2+h*w%2;

	printf("%lld",ans);
	// your code goes here
	return 0;
}


#include<stdio.h>
long long int main()
{
  int H,W;
  unsigned long long int A;
  scanf("%d %d",&H,&W);
  if(H*W%2==1){
    A=H*W*0.5;
    A=A+1;
    printf("%lld",A);
  }
  else{
    A=H*W*0.5;
    printf("%ld",A);
  }
  return 0;
}


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

int main(void) {
 long long int H,W;
 scanf("%lld %lld",&H,&W);
 long long int a = H*W;
 if (a>1){
 if (a%2==0)printf("%lld",a/2);
 else printf("%lld",(a+1)/2);
 }
 if (a==1)printf("1");
 return EXIT_SUCCESS;
}


main() {
  long long a, b; scanf("%lld%lld", &a, &b);
  printf("%lld\n", (a*b+1)>>1);
}


Score : 200 points

Problem Statement

You are visiting a large electronics store to buy a refrigerator and a microwave.

The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.

You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.

You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.

Constraints

All values in input are integers.

1 \le A \le 10^5

1 \le B \le 10^5

1 \le M \le 10^5

1 \le a_i , b_i , c_i \le 10^5

1 \le x_i \le A

1 \le y_i \le B

c_i \le a_{x_i} + b_{y_i}

Input

Input is given from Standard Input in the following format:

A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M

Output

Print the answer.

Sample Input 1

2 3 1
3 3
3 3 3
1 2 1

Sample Output 1

5

With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.

Sample Input 2

1 1 2
10
10
1 1 5
1 1 10

Sample Output 2

10

Note that you cannot use more than one ticket at a time.

Sample Input 3

2 2 1
3 5
3 5
2 2 2

Sample Output 3

6

You can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.


#include <stdio.h>

int main(void) {
  char buf[10];
  fgets(buf, 5, stdin);

  if(buf[0] == buf[1] && buf[0] == buf[2])
    puts("No");
  else
    puts("Yes");

  return 0;
}

Score : 100 points

Problem Statement

In AtCoder City, there are three stations numbered 1, 2, and 3.

Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i.

To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them.

Determine if there is a pair of stations that will be connected by a bus service.

Constraints

Each character of S is A or B.

|S| = 3

Input

Input is given from Standard Input in the following format:

S

Output

If there is a pair of stations that will be connected by a bus service, print Yes; otherwise, print No.

Sample Input 1

ABA

Sample Output 1

Yes

Company A operates Station 1 and 3, while Company B operates Station 2.

There will be a bus service between Station 1 and 2, and between Station 2 and 3, so print Yes.

Sample Input 2

BBA

Sample Output 2

Yes

Company B operates Station 1 and 2, while Company A operates Station 3.

There will be a bus service between Station 1 and 3, and between Station 2 and 3, so print Yes.

Sample Input 3

BBB

Sample Output 3

No

Company B operates all the stations. Thus, there will be no bus service, so print No.


#include <stdio.h>
int main(void)
{
    int N,A,B,s,n;
    scanf("%d%d%d",&N,&A,&B);
    s=N%(A+B);
    n=N/(A+B);
    if(s>=A)
        s==A;
    printf("%d\n",A*n+s);
    return 0;
}

Score : 200 points

Problem Statement

Takahashi has many red balls and blue balls. Now, he will place them in a row.

Initially, there is no ball placed.

Takahashi, who is very patient, will do the following operation 10^{100} times:

Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.

How many blue balls will be there among the first N balls in the row of balls made this way?

Constraints

1 \leq N \leq 10^{18}

A, B \geq 0

0 < A + B \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of blue balls that will be there among the first N balls in the row of balls.

Sample Input 1

8 3 4

Sample Output 1

4

Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls.

Sample Input 2

8 0 4

Sample Output 2

0

He placed only red balls from the beginning.

Sample Input 3

6 2 4

Sample Output 3

2

Among bbrrrr, there are two blue balls.


#include <stdio.h>

int main() {

    long long n, a, b, ans, cal;

    scanf("%ld %ld %ld", &n, &a, &b);

    ans = n / (a + b) * a;
    cal = n % (a + b);

    if(cal >= a) {
        ans = ans + a;
    }
    else {
        ans = ans + cal;
    }

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

    return 0;
}


#include<stdio.h>

int main()
{
	int n,a,b,i,l=0,m=0,s=0;

	scanf("%d%d%d",&n,&a,&b);
	for(i=0;s<n;i++){
		l+=a;
		m+=b;
		s+=l+m;
	}
	l+=n-s;
	printf("%d\n",l);
	return 0;
}


#include <stdio.h>

int main(void){
	int b = 0;
	int r = 0;
	int total = 0;
	int bTotal = 0;
	int n;

	scanf("%d%d%d", &n, &b, &r);
	while(total > n){
		total += b;
		bTotal += b;
		if(total > n){
			printf("%d\n", bTotal - total + n);
			break;
		}
		total += r;
		if(total > n){
			printf("%d\n", bTotal);
			break;
		}
	}

	return 0;
}


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

int main(){
 int a,b;
  scanf("%d %d",&a,&b);
  int c,d,e;
  float f,g,h;
  c=a/0.08;
  d=b/0.1;
  f=a/0.08;
  g=b/0.1;
  h=g-f;
    if(h>-10 && h<12.5){
      goto next;
    }else{
      printf("-1");

      return 0;
    }

    next:;
    if(c>d){
      e=a/0.08;
    }else{
      e=b/0.1;
    }
    printf("%d",e);
  }

Score : 300 points

Problem Statement

Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.)

Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer.

If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1.

Constraints

1 \leq A \leq B \leq 100

A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1.

Sample Input 1

2 2

Sample Output 1

25

If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is:

When the consumption tax rate is 8 percent: \lfloor 25 \times 0.08 \rfloor = \lfloor 2 \rfloor = 2 yen.

When the consumption tax rate is 10 percent: \lfloor 25 \times 0.1 \rfloor = \lfloor 2.5 \rfloor = 2 yen.

Thus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25.

Sample Input 2

8 10

Sample Output 2

100

If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is:

When the consumption tax rate is 8 percent: \lfloor 100 \times 0.08 \rfloor = 8 yen.

When the consumption tax rate is 10 percent: \lfloor 100 \times 0.1 \rfloor = 10 yen.

Sample Input 3

19 99

Sample Output 3

-1

There is no price before tax satisfying this condition, so print -1.


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

#define MODSIZE 300005

char queue[300005];

int main(){
  int head = 0;
  int tail = 0;
  int i,q;
  int com1,com2;
  char t[3];
  int rev = 0;

  scanf("%s", queue);
  scanf("%d", &q);
  tail++;
  for(i = 0;i < q;i++){
    scanf("%d", &com1);

    if(com1 == 1) rev++;

    else if(com1 == 2){
      scanf("%d", &com2);

      if(rev % 2 == 0){
      if(com2 == 1){
        head = (head + MODSIZE - 1) % MODSIZE;
        scanf("%s", t);
        queue[head] = t[0];
      }

      else if(com2 == 2){
        scanf("%s", t);
        queue[tail] = t[0];
        tail = (tail + 1) % MODSIZE;
      }
    }

    else{
      if(com2 == 2){
        head = (head + MODSIZE - 1) % MODSIZE;
        scanf("%s", t);
        queue[head] = t[0];
      }

      else if(com2 == 2){
        scanf("%s", t);
        queue[tail] = t[0];
        tail = (tail + 1) % MODSIZE;
      }
    }
    }
  }

    while(head != tail){
      printf("%c", queue[head]);
      head = (head + 1) % MODSIZE;
    }

  printf("\n");

  return 0;
}

Score : 400 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

Starting with this string, he will produce a new one in the procedure given as follows.

The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:

If T_i = 1: reverse the string S.

If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.

If F_i = 1 : Add C_i to the beginning of the string S.

If F_i = 2 : Add C_i to the end of the string S.

Help Takahashi by finding the final string that results from the procedure.

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

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

T_i = 1 or 2.

F_i = 1 or 2, if provided.

C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Sample Input 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

cpa

There will be Q = 4 operations. Initially, S is a.

Operation 1: Add p at the beginning of S. S becomes pa.

Operation 2: Reverse S. S becomes ap.

Operation 3: Add c at the end of S. S becomes apc.

Operation 4: Reverse S. S becomes cpa.

Thus, the resulting string is cpa.

Sample Input 2

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Sample Output 2

aabc

There will be Q = 6 operations. Initially, S is a.

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy


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

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(char *s, int q, int *t, int *f, char *c)
{
    int i, j;
    int top = 0;
    char pre[200001];
    char post[200001];
    char ppp[200001];

    bzero(pre, sizeof(pre));
    bzero(post, sizeof(post));

    for(i = 0; i < q; i++) {
        if(t[i] == 1) {
            top = 1 - top;
        }
        if(t[i] == 2) {
            if(f[i] == 1) {
                if(top == 0) {
                    pre[strlen(pre)] = c[i];
                } else {
                    post[strlen(post)] = c[i];
                }
            } else {
                if(top == 1) {
                    pre[strlen(pre)] = c[i];
                } else {
                    post[strlen(post)] = c[i];
                }
            }
        }
    }
    if(top == 0) {
        for(i = strlen(pre) - 1; i >= 0; i--)
            printf("%c", pre[i]);
        printf("%s%s", s, post);
    } else {
        j = 0;
        bzero(ppp, sizeof(ppp));
        for(i = strlen(post) - 1; i >= 0; i--)
            ppp[j++] = post[i];
        printf("%s", ppp);

        j = 0;
        bzero(ppp, sizeof(ppp));
        for(i = strlen(s) - 1; i >= 0; i--)
            ppp[j++] = s[i];
        printf("%s", ppp);

        printf("%s", pre);
    }
    printf("\n");
}

int
main(int argc, char *argv[])
{
    char S[100001];
    char tmp[100];
    int Q;
    int T[200000];
    int F[200000];
    char C[200000];
    int i;

#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    scanf("%s", S);
    scanf("%d", &Q);
    for(i = 0; i < Q; i++) {
        scanf("%d", T + i);
        if(T[i] == 2) {
            scanf("%d %c", F + i, C + i);
        }
    }

    solver(S, Q, T, F, C);
    return 0;
}


#include <stdio.h>
int main(void)
{
  int n, p, i, temp_num, left_end, right_end, num_of_divisible;
  char s[200001];

  scanf("%d %d", &n, &p);            // 標準入力からの値取得
  scanf("%s", s);                    // 標準入力からの値取得

  num_of_divisible = 0;
  for (left_end = 0; left_end < n; left_end++) {
    for (right_end = left_end; right_end < n; right_end++) {
      temp_num = 0;
      for (i = left_end; i <= right_end; i++) {
        temp_num = (temp_num * 10 +((int)s[i] - 48)) % p;
      }
      if (temp_num == 0) {
        num_of_divisible++;
      }
    }
  }

  printf("%d\n", num_of_divisible);   // 出力
  return 0;
}

Score : 500 points

Problem Statement

Takahashi has a string S of length N consisting of digits from 0 through 9.

He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten.

Here substrings starting with a 0 also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers.

Compute this count to help Takahashi.

Constraints

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

S consists of digits.

|S| = N

2 \leq P \leq 10000

P is a prime number.

Input

Input is given from Standard Input in the following format:

N P
S

Output

Print the number of non-empty (contiguous) substrings of S that are divisible by P when regarded as an integer written in base ten.

Sample Input 1

4 3
3543

Sample Output 1

6

Here S = 3543. There are ten non-empty (contiguous) substrings of S:

3: divisible by 3.

35: not divisible by 3.

354: divisible by 3.

3543: divisible by 3.

5: not divisible by 3.

54: divisible by 3.

543: divisible by 3.

4: not divisible by 3.

43: not divisible by 3.

3: divisible by 3.

Six of these are divisible by 3, so print 6.

Sample Input 2

4 2
2020

Sample Output 2

10

Here S = 2020. There are ten non-empty (contiguous) substrings of S, all of which are divisible by 2, so print 10.

Note that substrings beginning with a 0 also count.

Sample Input 3

20 11
33883322005544116655

Sample Output 3

68


#include<stdio.h>

int main(){
   int n;
   scanf("%d", &n);
   if(n%2 == 0){
      printf("%d", n/2);
   } else {
      printf("%d", n/2+1);
   }

   return 0;
}

Score : 100 points

Problem Statement

Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper.

At least how many sheets of paper does he need?

Constraints

N is an integer.

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

5

Sample Output 1

3

By printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the 2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3 sheets of paper.

Sample Input 2

2

Sample Output 2

1

Sample Input 3

100

Sample Output 3

50


#include <stdio.h>
int main(void){
  int N;
  int s;
  int o;
  scanf("%d",&N);
  s=N/2;
  o=N%2;
  if(o==1){
    s=s+1;
  }
  printf("%d\n",s);
  return 0;
}


Score : 200 points

Problem Statement

We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}.

The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet.

Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal.

Constraints

All values in input are integers.

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

A_{i_1, j_1} \neq A_{i_2, j_2} ((i_1, j_1) \neq (i_2, j_2))

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

A_{1, 1} A_{1, 2} A_{1, 3}
A_{2, 1} A_{2, 2} A_{2, 3}
A_{3, 1} A_{3, 2} A_{3, 3}
N
b_1
\vdots
b_N

Output

If we will have a bingo, print Yes; otherwise, print No.

Sample Input 1

84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30

Sample Output 1

Yes

We will mark A_{1, 1}, A_{2, 1}, A_{2, 2}, A_{3, 3}, and complete the diagonal from the top-left to the bottom-right.

Sample Input 2

41 7 46
26 89 2
78 92 8
5
6
45
16
57
17

Sample Output 2

No

We will mark nothing.

Sample Input 3

60 88 34
92 41 43
65 73 48
10
60
43
88
11
48
73
65
41
92
34

Sample Output 3

Yes

We will mark all the squares.


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

int main(void) {

	int A[3][3],N,b[100];
	int tate,yoko,naname1,naname2;
    int i,j,k;

    for(i=0;i<3;i++)
	   {scanf("%d %d %d",&A[i][0],&A[i][1],&A[i][2]);}
    scanf("%d",&N);
    for(i=0;i<N;i++) {scanf("%d",&b[i]);}

    //tate & yoko
    for(i=0;i<3;i++) {
    	tate=yoko=0;
    	for(j=0;j<3;j++){
    		for(k=0;k<N;k++){
    		   if(A[i][j]==b[k]) tate++;
    		   if(A[j][i]==b[k]) yoko++;
    		}
    	}
    	if((tate==3) || (yoko==3))
    	  {printf("Yes");return(0);}
    }

    //naname
    naname1=naname2=0;
    for(i=0;i<3;i++){
       for(k=0;k<N;k++) {
    	   if(A[i][i]   ==b[k]) naname1++;
    	   if(A[2-i][i] ==b[k]) naname2++;
       }
       if(naname1==3 || naname2==3)
       {printf("yes");return(0);}
    }
    printf("No");return(0);
 }


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

#define N 100005

typedef struct {
	int parent;
	int appaer;
	int member;
	int root;
	int visit;
}node_t;

node_t node[N] = { 0 };

void joint(int a, int b) {
	int a_root = root(a), b_root = root(b);

	if (a_root != b_root) {
		if (node[a_root].member >= node[b_root].member){
			node[b_root].parent = a_root;
			node[a_root].member += node[b_root].member;
			node[b_root].member = 0;
		}
		else {
			node[a_root].parent = b_root;
			node[b_root].member += node[a_root].member;
			node[a_root].member = 0;
		}
	}

}

int root(int node_n) {
	if (node[node_n].parent == 0)return node_n;
	else return root(node[node_n].parent);
}
int main(void) {
	int n, m, k;
	int a, b;
	int c, d;

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= n; i++)node[i].member = 1;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b);
		node[a].appaer++, node[b].appaer++;
			joint(a, b);
	}
	for (int i = 1; i <= n; i++)
		node[i].root = root(i);
	for (int i = 0; i < k; i++) {
		scanf("%d %d", &c, &d);
		if (node[c].root == node[d].root) {
			node[c].appaer++, node[d].appaer++;
		}
	}

	/*
	for (int i = 1; i <= n; i++) {
		printf("node[%d].root=%d\n", i, node[i].root);
	}
	for (int i = 1; i <= n; i++) {
		printf("node[%d].member=%d\n", i, node[i].member);
	}
	*/
	for (int i = 1; i <= n; i++) {
		if (node[node[i].root].member > 1)
			printf("%d ", node[node[i].root].member - node[i].appaer - 1);
		else printf("0 ");
	}
	return 0;
}

Score : 400 points

Problem Statement

An SNS has N users - User 1, User 2, \cdots, User N.

Between these N users, there are some relationships - M friendships and K blockships.

For each i = 1, 2, \cdots, M, there is a bidirectional friendship between User A_i and User B_i.

For each i = 1, 2, \cdots, K, there is a bidirectional blockship between User C_i and User D_i.

We define User a to be a friend candidate for User b when all of the following four conditions are satisfied:

a \neq b.

There is not a friendship between User a and User b.

There is not a blockship between User a and User b.

There exists a sequence c_0, c_1, c_2, \cdots, c_L consisting of integers between 1 and N (inclusive) such that c_0 = a, c_L = b, and there is a friendship between User c_i and c_{i+1} for each i = 0, 1, \cdots, L - 1.

For each user i = 1, 2, ... N, how many friend candidates does it have?

Constraints

All values in input are integers.

2 ≤ N ≤ 10^5

0 \leq M \leq 10^5

0 \leq K \leq 10^5

1 \leq A_i, B_i \leq N

A_i \neq B_i

1 \leq C_i, D_i \leq N

C_i \neq D_i

(A_i, B_i) \neq (A_j, B_j) (i \neq j)

(A_i, B_i) \neq (B_j, A_j)

(C_i, D_i) \neq (C_j, D_j) (i \neq j)

(C_i, D_i) \neq (D_j, C_j)

(A_i, B_i) \neq (C_j, D_j)

(A_i, B_i) \neq (D_j, C_j)

Input

Input is given from Standard Input in the following format:

N M K
A_1 B_1
\vdots
A_M B_M
C_1 D_1
\vdots
C_K D_K

Output

Print the answers in order, with space in between.

Sample Input 1

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

Sample Output 1

0 1 0 1

There is a friendship between User 2 and 3, and between 3 and 4. Also, there is no friendship or blockship between User 2 and 4. Thus, User 4 is a friend candidate for User 2.

However, neither User 1 or 3 is a friend candidate for User 2, so User 2 has one friend candidate.

Sample Input 2

5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5

Sample Output 2

0 0 0 0 0

Everyone is a friend of everyone else and has no friend candidate.

Sample Input 3

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

Sample Output 3

1 3 5 4 3 3 3 3 1 0


#include <stdio.h>

int main(void) {
	int N, R;
	if (scanf("%d%d", &N, &R) != 2) return 1;
	printf("%d\n", N >= 10 ? R : R + 100 * (10 - N));
	return 0;
}

Score : 100 points

Problem Statement

Takahashi is a member of a programming competition site, ButCoder.

Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.

The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inner Rating minus 100 \times (10 - K) when the member has participated in K contests.

Takahashi has participated in N contests, and his Displayed Rating is R. Find his Inner Rating.

Constraints

All values in input are integers.

1 \leq N \leq 100

0 \leq R \leq 4111

Input

Input is given from Standard Input in the following format:

N R

Output

Print his Inner Rating.

Sample Input 1

2 2919

Sample Output 1

3719

Takahashi has participated in 2 contests, which is less than 10, so his Displayed Rating is his Inner Rating minus 100 \times (10 - 2) = 800.

Thus, Takahashi's Inner Rating is 2919 + 800 = 3719.

Sample Input 2

22 3051

Sample Output 2

3051


#include <stdio.h>
int x,y,z;
int main(void){
  scanf("%d\n",&x);
  scanf("%d\n",&y);
  scanf("%d\n",&z);
  if((x==y&&x!=z)||(x==z&&x!=y)||(y==z&&y!=x))
     printf("Yes\n");
  else printf("No\n");
}

Score: 100 points

Problem Statement

A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.

You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.

Constraints

A, B, and C are all integers between 1 and 9 (inclusive).

Input

Input is given from Standard Input in the following format:

A B C

Output

If the given triple is poor, print Yes; otherwise, print No.

Sample Input 1

5 7 5

Sample Output 1

Yes

A and C are equal, but B is different from those two numbers, so this triple is poor.

Sample Input 2

4 4 4

Sample Output 2

No

A, B, and C are all equal, so this triple is not poor.

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d%d", &a, &b, &c);
  int ispoor= 0;
  if(a==b&&b!=c)ispoor= 1;
  if(b==c&&c!=a)ispoor= 1;
  if(c==a&&a!=b)ispoor= 1;
  if(ispoor) {
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


#include<stdio.h>
main()
{
    int i,n;
    int x=1;
    scanf("%d",&n);
    int arr[n];
    for(i=1;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=1;i<n;i++)
    {
        if(arr[i]%2==0&&arr[i]%5!=0&&arr[i]%3!=0)
        {
            x=0;
            break;
        }
    }
        if(x==1)
        printf("APPROVED");
        else if(x==0)
        printf("DENIED");
}

Score: 200 points

Problem Statement

You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.

According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:

All even numbers written on the document are divisible by 3 or 5.

If the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED.

Notes

The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5".
Here "if" and "or" are logical terms.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

If the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED.

Sample Input 1

5
6 7 9 10 31

Sample Output 1

APPROVED

The even numbers written on the document are 6 and 10.

All of them are divisible by 3 or 5, so the immigrant should be allowed entry.

Sample Input 2

3
28 27 24

Sample Output 2

DENIED

28 violates the condition, so the immigrant should not be allowed entry.


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

#define MAX(a,b) (a > b) ? a : b
#define MIX(a,b) (a < b) ? a : b

int Amax(int *p,int size){
   int _max = 0;
   for(int i = 0;i < size;i++)
      if(p[i] > _max)_max = p[i];
   return _max;
}

int main(){
   int n;scanf("%d",&n);
   char paper[200000][11];for(int i = 0;i < n;i++)scanf("%s",paper[i]);
   char tmp[11];
   int count[200000] ={0};
   int pointer;
   for(int i=1;i<n;i++){
      for(int j=1;j<n;j++){
         if(strcmp(paper[j-1], paper[j])>0){
            strcpy(tmp, paper[j-1]);
            strcpy(paper[j-1], paper[j]);
            strcpy(paper[j], tmp);
         }
      }
   }
   pointer = 0;
   for(int i = 0;i < n-1;i++){
      if (!(strcmp(paper[i],paper[i+1]))){
         count[pointer]++;
      }else {
         pointer = i+1;
      }
   }
   /*for(int i = 0;i < n;i++){
      printf("%d\n",count[i]);
      printf("%s\n",paper[i]);
   }*/

   int x = Amax(count,n);
   for(int i = 0;i < n;i++){
      if(count[i] == x)printf("%s\n",paper[i]);
   }
}

Score: 300 points

Problem Statement

We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.

Print all strings that are written on the most number of votes, in lexicographical order.

Constraints

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

S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.

The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


#define _CRT_SECURE_NO_WARNINGS

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))
#define SWAP(type, a, b) { const type tmp = a; a = b; b = tmp; }

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_u64_asc(const void* a, const void* b) {
    return *((uint64_t*)a) < *((uint64_t*)b) ? -1 : 1;
}

int compare_u64_desc(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

int compare_dp_asc(const void* a, const void* b) {
    return *((double*)a) < *((double*)b) ? -1 : 1;
}

int compare_str_asc(const void* a, const void* b) {
    return strcmp((char*)a, (char*)b);
}

static uint64_t modinvU64(const uint64_t a, const uint64_t m) {
    int64_t aa = (int64_t)a;
    const int64_t mm = (int64_t)m;
    int64_t b = mm;
    int64_t u = 1;
    int64_t v = 0;

    while (b != 0) {
        const int64_t t = aa / b;

        aa -= t * b;
        SWAP(uint64_t, aa, b);
        u -= t * v;
        SWAP(uint64_t, u, v);
    }

    u %= mm;
    if (u < 0) {
        u += m;
    }

    return (uint64_t)u;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static uint64_t powU64(const uint64_t base, const uint64_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powU64(base * base, exp / 2);
    }
    else {
        return base * powU64(base, exp - 1);
    }
}

static uint64_t powU64WMod(const uint64_t base, const uint64_t exp, const uint64_t m) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base % m;
    }

    if (exp % 2 == 0) {
        return powU64WMod(base * base % m, exp / 2, m);
    }
    else {
        return base * powU64WMod(base, exp - 1, m) % m;
    }
}

static size_t combSz(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64WMod(const uint64_t n, const uint64_t r, const uint64_t m) {
    uint64_t result = 1;
    uint64_t inv = 1;

    for (uint64_t i = 0; i < r; i++) {
        result = result * (n - i) % m;
        inv = inv * (i + 1) % m;
    }

    return result * modinvU64(inv, m) % m;
}

static uint64_t permU64(const uint64_t n) {
    uint64_t result = 1;

    for (uint64_t v = 2; v <= n; v++) {
        result *= v;
    }

    return result;
}

static uint64_t permU64WMod(const uint64_t n, const uint64_t m) {
    uint64_t result = 1;

    for (uint64_t v = 2; v <= n; v++) {
        result *= v;
        result %= m;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t popcntU64(uint64_t val) {
    uint64_t cnt = 0;

    while (val != 0) {
        if ((val & UINT64_C(0x1)) != 0) {
            cnt++;
        }

        val >>= UINT64_C(0x1);
    }

    return cnt;
}

typedef struct {
    uint64_t val;
}BHeap_Val;

#define BHEAP_VAL_TYPE BHeap_Val

#define BHEAP_INVALID_NODE ((size_t)100000000)

typedef struct {
    BHEAP_VAL_TYPE val;
} BHeap_Node;

struct _BHeap_Ctx {
    size_t size;
    int (*compare)(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node);
    void(*notifyNodeChange)(const struct _BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList);
    BHeap_Node* node;
};

typedef struct _BHeap_Ctx BHeap_Ctx;

static void bHeap_Init(BHeap_Ctx* const ctx, int(*compare)(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node), void(*notifyNodeChange)(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList), BHeap_Node* const nodes) {
    ctx->size = 0;
    ctx->compare = compare;
    ctx->notifyNodeChange = notifyNodeChange;
    ctx->node = nodes;
}

static void bHeap_Swap(BHeap_Ctx* const ctx, const size_t node0, const size_t node1) {
    const BHEAP_VAL_TYPE tmp = ctx->node[node0].val;
    ctx->node[node0].val = ctx->node[node1].val;
    ctx->node[node1].val = tmp;

    if (ctx->notifyNodeChange != NULL) {
        const size_t nodeList[2] = { node0,node1 };
        ctx->notifyNodeChange(ctx, 2, nodeList);
    }
}

static void bHeap_UpHeap(BHeap_Ctx* const ctx, const size_t nodeIdx) {
    if (nodeIdx == 0) {
        return;
    }

    const size_t parentIdx = (nodeIdx + 1) / 2 - 1;

    const int compareResult = ctx->compare(&(ctx->node[parentIdx].val), &(ctx->node[nodeIdx].val));

    if (0 < compareResult) {
        bHeap_Swap(ctx, nodeIdx, parentIdx);

        if (parentIdx != 0) {
            bHeap_UpHeap(ctx, parentIdx);
        }
    }
}

static void bHeap_DownHeap(BHeap_Ctx* const ctx, const size_t nodeIdx) {
    if (ctx->size - 1 <= nodeIdx) {
        return;
    }

    const size_t leftIdx = 2 * (nodeIdx + 1) - 1;

    if (leftIdx < ctx->size) {
        const int leftResult = ctx->compare(&(ctx->node[nodeIdx].val), &(ctx->node[leftIdx].val));

        size_t swapTarget = leftResult < 0 ? BHEAP_INVALID_NODE : leftIdx;

        const size_t rightIdx = leftIdx + 1;

        if (rightIdx < ctx->size) {
            const int rightResult = ctx->compare(&(ctx->node[nodeIdx].val), &(ctx->node[rightIdx].val));

            if (swapTarget == BHEAP_INVALID_NODE) {
                if (0 < rightResult) {
                    swapTarget = rightIdx;
                }
            }
            else {
                if (0 < rightResult) {
                    const int rightLeftResult = ctx->compare(&(ctx->node[leftIdx].val), &(ctx->node[rightIdx].val));

                    if (0 < rightLeftResult) {
                        swapTarget = rightIdx;
                    }
                }
            }
        }

        if (swapTarget != BHEAP_INVALID_NODE) {
            bHeap_Swap(ctx, nodeIdx, swapTarget);

            bHeap_DownHeap(ctx, swapTarget);
        }
    }
}

static void bHeap_Add(BHeap_Ctx* const ctx, const BHEAP_VAL_TYPE val) {
    ctx->node[ctx->size].val = val;

    ctx->size++;

    if (ctx->notifyNodeChange != NULL) {
        const size_t node = ctx->size - 1;
        ctx->notifyNodeChange(ctx, 1, &node);
    }

    bHeap_UpHeap(ctx, ctx->size - 1);
}

static void bHeap_RemoveTop(BHeap_Ctx* const ctx) {
    if (ctx->size == 0) {
        return;
    }

    if (ctx->size == 1) {
        ctx->size--;
        return;
    }

    ctx->node[0].val = ctx->node[ctx->size - 1].val;

    if (ctx->notifyNodeChange != NULL) {
        const size_t node = 0;
        ctx->notifyNodeChange(ctx, 1, &node);
    }

    ctx->size--;

    bHeap_DownHeap(ctx, 0);
}

static void bHeap_RemoveNode(BHeap_Ctx* const ctx, const size_t node) {
    if (node == ctx->size - 1) {
        ctx->size--;
    }
    else {
        ctx->node[node].val = ctx->node[ctx->size - 1].val;

        ctx->size--;

        if (ctx->notifyNodeChange != NULL) {
            ctx->notifyNodeChange(ctx, 1, &node);
        }

        bHeap_DownHeap(ctx, node);
        bHeap_UpHeap(ctx, node);
    }
}

static BHEAP_VAL_TYPE* bHeap_GetTopVal(const BHeap_Ctx* const ctx) {
    return ctx->size == 0 ? NULL : &(ctx->node[0].val);
}

typedef struct {
    uint64_t cnt;
    size_t* child;
    size_t numChild;
    size_t maxNumChild;
} Tree_Node;

#define TREE_INIT_ALLOC (128)

static Tree_Node tree_Node[200000];

static void tree_Init(const uint64_t N) {
    for (uint64_t i = 0; i < N; i++) {
        tree_Node[i].cnt = 0;
        tree_Node[i].numChild = 0;
        tree_Node[i].child = malloc(sizeof(size_t) * TREE_INIT_ALLOC);
        tree_Node[i].maxNumChild = TREE_INIT_ALLOC;
    }
}

static void tree_AddChild(const size_t parent, const size_t child) {
    if (tree_Node[parent].maxNumChild <= tree_Node[parent].numChild) {
        tree_Node[parent].child = realloc(tree_Node[parent].child, sizeof(size_t) * tree_Node[parent].maxNumChild * 2);
        tree_Node[parent].maxNumChild *= 2;
    }

    tree_Node[parent].child[tree_Node[parent].numChild] = child;
    tree_Node[parent].numChild++;
}

static BHeap_Node BN_Asc[200000];
static BHeap_Node BN_Desc[200000];

static int _bHeap_Compare_Asc(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node) {
    return parent->val <= node->val ? -1 : 1;
}

static int _bHeap_Compare_Desc(const BHEAP_VAL_TYPE* parent, const BHEAP_VAL_TYPE* node) {
    return parent->val >= node->val ? -1 : 1;
}

static size_t PBHeap_Asc_Idx[200000];
static size_t PBHeap_Desc_Idx[200000];

static void _bHeap_NotifyNodeChange_Asc(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList) {
    for (size_t i = 0; i < nodeListSize; i++) {
        PBHeap_Asc_Idx[ctx->node[nodeList[i]].val.val] = nodeList[i];
    }
}

static void _bHeap_NotifyNodeChange_Desc(const BHeap_Ctx* const ctx, const size_t nodeListSize, const size_t* const nodeList) {
    for (size_t i = 0; i < nodeListSize; i++) {
        PBHeap_Desc_Idx[ctx->node[nodeList[i]].val.val] = nodeList[i];
    }
}

#define UF_ROOT ((size_t)10000000)

typedef struct {
    size_t parent;
    uint64_t w;
    uint64_t v;
    uint64_t wSum;
    uint64_t vSum;
} UF_Node;

static UF_Node uf_Node[101];

static size_t uf_GetRoot(const size_t idx) {
    if (uf_Node[idx].parent == UF_ROOT) {
        return idx;
    }

    const size_t root = uf_GetRoot(uf_Node[idx].parent);

    uf_Node[idx].parent = root;

    return root;
}

static void uf_Merge(const size_t a, const size_t b) {
    const size_t aRoot = uf_GetRoot(a);
    const size_t bRoot = uf_GetRoot(b);

    if (aRoot != bRoot) {
        uf_Node[aRoot].parent = bRoot;

        uf_Node[bRoot].wSum += uf_Node[aRoot].wSum;
        uf_Node[bRoot].vSum += uf_Node[aRoot].vSum;
    }
}

#define MOD_VAL (UINT64_C(1000000007))

static char S[200000][11];

typedef struct {
    char S[11];
    uint64_t cnt;
} StrList;

static StrList sList[200000];
static uint64_t listSize = 0;

int compare_f(const void* a, const void* b) {
    const StrList* aP = (StrList*)a;
    const StrList* bP = (StrList*)b;

    if (aP->cnt > bP->cnt) {
        return -1;
    }
    else if (aP->cnt == bP->cnt) {
        return strcmp(aP->S, bP->S);
    }
    else {
        return 1;
    }
}

int main(void) {
    uint64_t N;

    scanf("%"PRIu64, &N);
    for (uint64_t i = 0; i < N; i++) {
        scanf("%s", S[i]);

        sList[i].cnt = 0;
    }

    qsort(S, (size_t)N, sizeof(char) * 11, compare_str_asc);

    uint64_t cnt = 1;

    for (uint64_t i = 1; i < N; i++) {
        if (strcmp(S[i], S[i - 1]) == 0) {
            cnt++;
        }
        else {
            sList[listSize].cnt = cnt;
            strcpy(sList[listSize].S, S[i - 1]);
            listSize++;

            cnt = 1;
        }
    }

    sList[listSize].cnt = cnt;
    strcpy(sList[listSize].S, S[N - 1]);
    listSize++;

    qsort(sList, (size_t)listSize, sizeof(StrList), compare_f);

    puts(sList[0].S);
    for (uint64_t i = 1; i < listSize; i++) {
        if (sList[i].cnt == sList[0].cnt) {
            puts(sList[i].S);
        }
        else {
            return 0;
        }
    }

    return 0;
}


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

   scanf("%d",&N);

   if(N%2 == 0)  printf("%d\n",N);

   else    printf("%d\n",2*N);
   return 0;
}

Score : 100 points

Problem Statement

We have A balls with the string S written on each of them and B balls with the string T written on each of them.

From these balls, Takahashi chooses one with the string U written on it and throws it away.

Find the number of balls with the string S and balls with the string T that we have now.

Constraints

S, T, and U are strings consisting of lowercase English letters.

The lengths of S and T are each between 1 and 10 (inclusive).

S \not= T

S=U or T=U.

1 \leq A,B \leq 10

A and B are integers.

Input

Input is given from Standard Input in the following format:

S T
A B
U

Output

Print the answer, with space in between.

Sample Input 1

red blue
3 4
red

Sample Output 1

2 4

Takahashi chose a ball with red written on it and threw it away.
Now we have two balls with the string S and four balls with the string T.

Sample Input 2

red blue
5 5
blue

Sample Output 2

5 4

Takahashi chose a ball with blue written on it and threw it away.
Now we have five balls with the string S and four balls with the string T.


#include <stdio.h>
#include <string.h>
int main(void)
{
  char S[11];

  char T[11];
  scanf("%s %s", S, T);

  int A = 0;

  int B = 0;
  scanf("%d %d", &A, &B);

  char U[11];
  scanf("%s", U);

   if(strcmp(S,U)==0){
    A = A-1;
    printf("%d %d", A, B);
  }
  else{
    B = B-1;
    printf("%d %d", A, B);
  }
  return 0;
}


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

    int i,j;
    char ar[1000],br[10000],cr[10000];

    scanf("%s%s",ar,br);
    scanf("%d%d",&i,&j);
    scanf("%s",cr);

    if(cr[0]=='r')
        printf("%d %d\n",i-1,j);
    else
        printf("%d %d\n",i,j-1);

    return 0;
}


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

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

int main(){
    int N;
    scanf("%d",&N);
    int A[N+1];
    int i,j,s=0,count=0;
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    qsort(A,N,sizeof(int), compare_int);

    for(i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Score : 300 points

Problem Statement

Given is a sequence of integers A_1, A_2, ..., A_N.
If its elements are pairwise distinct, print YES; otherwise, print NO.

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

If the elements of the sequence are pairwise distinct, print YES; otherwise, print NO.

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


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

int main(void){
    bool flag=false;
    int n,a[200000]={0},s;
    scanf("%d",&n);
    for(int b=0;b<n;b++){
        scanf("%d",&s);
        a[b]=s;
    }
    for(int c=0;c<n-1;c++){
        for(int d=c+1;d<=n;d++){
            if(a[c]==a[d]){
                flag=true;
            }
        }
    }
    if(flag){
        printf("NO");
    }else printf("YES");
}


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

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

int main() {
  int N,d,S[200001];
scanf("%d",&N);
for(int c=0;c<N;c++){
scanf("%d",&S[c]);
}
qsort(S, N, sizeof(int), compare_int);

for(d=0;d<N;d++){
if(S[d] == S[d+1]){
printf("NO");
break;
}
}
if(d == N){
  printf("YES");
          }

return 0;
}


#include<stdio.h>
int main() {
	int i, j,x,y;
	double tmp=0;
	double index=0;
	scanf("%d %d", &x, &y);
	int m[x];
	double z[x];
	for (i = 0;i < x;i++) {
		scanf("%d", &m[i]);
	}
	for (i = 0;i < x;i++) {
		z[i] = (double)(1 + m[i]) / 2;
	}
	for (i = 0;i < x;i++) {
		tmp += z[i];
		if (i >= y) {
			tmp -= z[i - y];
		}
		if (index < tmp) {
			index = tmp;
		}
	}
	printf("%.12f", index);
	return 0;
}

Score : 400 points

Problem Statement

We have N dice arranged in a line from left to right. The i-th die from the left shows p_i numbers from 1 to p_i with equal probability when thrown.

We will choose K adjacent dice, throw each of them independently, and compute the sum of the numbers shown. Find the maximum possible value of the expected value of this sum.

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

Print the maximum possible value of the expected value of the sum of the numbers shown.

Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

When we throw the third, fourth, and fifth dice from the left, the expected value of the sum of the numbers shown is 7. This is the maximum value we can achieve.

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

Regardless of which die we choose, the expected value of the number shown is 3.5.

Sample Input 3

10 4
17 13 13 12 15 20 10 13 17 11

Sample Output 3

32.000000000000


/*  AUTHOR: AKASH JAIN
*   EMAIL:  akash19jain@gmail.com
*   ID:     akash19jain
*   DATE:   09-02-2020 17:40:23
*/

// #include<algorithm>
// #include <bits/stdc++.h>
// using namespace std;

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define SCA(a,n)        for(long long i=0;i<n;i++)    scanf("%lld",&a[i]);
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define PFA(a,n)        for(long long i=0;i<n;i++)    printf("%lld ",a[i]); printf("\n");
#define PFN             printf("\n")
#define PFS(x)          printf("%s\n",x)
#define REP(i,n)        for(long long i=0;i<(n);++i)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);++i)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);--i)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((ll)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)           strlen(a)
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))
#define SWAP(a,b)       ll z=a;a=b;b=z
#define SWAPC(a,b)      char z=a;a=b;b=z
#define FLSH            fflush(stdout)
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1<<29;
const ll MOD = 1000000007;
const ll FMOD = 998244353;
const ll MAX = 10000000005;
const ll MIN = -10000000005;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
long long digits(long long n);
bool ispoweroftwo(long long n);
bool isvowel(char x);
ll chartoint(char ch);
ll CEIL(ll x,ll y);
ll FLOOR(ll x,ll y);

int main()
{
    ll n,k;
    SC2(n,k);
    ll arr[n];
    SCA(arr,n);
    //qsort(arr,n,sizeof(arr[0]),cmp);
    double ans=0;
    REP(i,k)
    {
        ll x=arr[i]*(arr[i]+1)/2;
        ans+=(1.0*x)/arr[i];
    }
    double max=ans;
    FOR(i,k+1,n-1)
    {
        ll x=arr[i]*(arr[i]+1)/2;
        ans+=(1.0*x)/arr[i];
        x=arr[i-k-1]*(arr[i-k-1]+1)/2;
        ans-=(1.0*x)/arr[i-k-1];
        if(max<ans)
            max=ans;

    }
    printf("%.10f\n",max);

    return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
    if( *(ll*)a - *(ll*)b < 0 ) return 1;
    if( *(ll*)a - *(ll*)b > 0 ) return -1;
        return 0;
}
long long maxv(long long a,long long b)
{
    if(a>b) return a;
        return b;
}
long long minv(long long a,long long b)
{
    if(a<b) return a;
        return b;
}
long long gcd(long long u,long long v)
{
    if (v == 0) return u;
       return gcd(v, u%v);
}
long long digits(long long n)    //to calculate no of digits in a number
{
    return floor(log10(n))+1;
}
bool ispoweroftwo(long long x)
{
    return x && (!(x&(x-1)));
}
bool isvowel(char x)
{
    return(x=='a' || x== 'e' ||x=='i' || x== 'o' || x=='u' );
}
ll chartoint(char ch)
{
    if(ch>='A' && ch<='Z') return(ch-'A');
    else if(ch>='0' && ch<='9') return (ch-'0');
    else if(ch>='a' && ch<='z') return (ch-'a');
    else return 0;
}
ll CEIL(ll x,ll y)
{
    if(x%y==0) return(x/y);
    else return(x/y +1);
}

ll FLOOR(ll x,ll y)
{
    if(x%y==0) return(x/y);
    else return(x/y -1);
}


#include<stdio.h>
int main()
{
int H,A,x;
scanf("%d%d",&H,&A);
if(H%A==0)
{
x=H/A;
}
else
{
 x=(H/A)+1;
}
printf("%d",x);
return 0; }

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

In one attack, Serval can decrease the monster's health by A.
There is no other way to decrease the monster's health.

Serval wins when the monster's health becomes 0 or below.

Find the number of attacks Serval needs to make before winning.

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

Print the number of attacks Serval needs to make before winning.

Sample Input 1

10 4

Sample Output 1

3

After one attack, the monster's health will be 6.

After two attacks, the monster's health will be 2.

After three attacks, the monster's health will be -2.

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


#include <stdio.h>

int main(void) {
  int H, N;
  int A[100];
  scanf("%d%d", &H, &N);
  int i;
  for (i=0; i<N; i++) {
    scanf("%d", &A[i]);
  }
  int sum = 0;
  for (i=0; i<N; i++) {
    sum += A[i];
  }
  if (sum >= H) {
    printf("yes");
  } else {
    printf("no");
  }
  return 0;
}


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

int main()
{
    long long int h, i, n, a, t = 0;
    scanf("%lld %lld", &h, &n);
    for (i = 0; i < n; i++)
    {
        scanf("%lld", &a);
        t += a;
    }
    if(t >= h)
        printf("Yes");
    else
        printf("No");
	return 0;
}

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.

Raccoon wins when the monster's health becomes 0 or below.

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

If Raccoon can win without using the same move twice or more, print Yes; otherwise, print No.

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

The monster's health will become 0 or below after, for example, using the second and third moves.

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


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

int main(void){
    int i = 0,h,n,sum = 0,a;

    scanf("%d%d",&h,&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum += a;
    }

    if(sum > h) printf("Yes\n");
    else printf("No\n");
}


#include <stdio.h>
int main(){
    int H,N,A[10001];
    scanf("%d %d",&H,&N);
    int i,sum;

    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    sum = 0;
    for(i = 0;i<N ;i++){
        sum = sum + A[i];
    }
    if(sum>=H){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


#include <stdio.h>

int main(void){
  int n, k;
  scanf("%d %d\n",&n ,&k);

  if(n <= k){
    printf("0\n");
    return(0);
  }

  long int h[k], sum=0;
  for (int i = 0; i < n; i++) {
    scanf("%ld\n", &h[i]);
    sum+=h[i];
  }

  for (int i = 0; i < k; i++) {
    for (int j = n-1; j > i; j--) {
      if(h[i]<h[j]){
        long int temp;

        temp = h[i];
        h[i] = h[j];
        h[j] = temp;
      }
    }
  }

  while(k>0){
    sum -= h[k-1];
    k--;
  }

  printf("%ld\n", sum);

  return(0);
}

Score : 300 points

Problem Statement

Fennec is fighting with N monsters.

The health of the i-th monster is H_i.

Fennec can do the following two actions:

Attack: Fennec chooses one monster. That monster's health will decrease by 1.

Special Move: Fennec chooses one monster. That monster's health will become 0.

There is no way other than Attack and Special Move to decrease the monsters' health.

Fennec wins when all the monsters' healths become 0 or below.

Find the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning when she can use Special Move at most K times.

Constraints

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

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

1 \leq H_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 ... H_N

Output

Print the minimum number of times Fennec needs to do Attack (not counting Special Move) before winning.

Sample Input 1

3 1
4 1 5

Sample Output 1

5

By using Special Move on the third monster, and doing Attack four times on the first monster and once on the second monster, Fennec can win with five Attacks.

Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.

Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


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

typedef long long ll;
typedef const void cv;
int downint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}

ll battle(ll hp){
  if(hp==1){
     return 1;
  }else{
    return battle(hp/2)*2+1;
  }

}
int main(void){
  ll h, result=0;
  scanf("%lld",&h);
  result=battle(h);
  printf("%lld",result);

  return 0;
}

Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775


#include <stdio.h>
int main()
{
	long long int a;
	long long int num = 1;
	long long int cnt = 0;
	scanf("%lld", &a);
	while (a >= 1)
	{
		a = a / 2;
		cnt = cnt + num;
		num = num * 2;
	}
	printf("%lld",cnt);
        return 0;
}


#include<stdio.h>

int main(void){
    long int h,num=1,cnt=0;
    scanf("%ld",&h);
    while(h>0){
        h/=2;
        cnt +=num;
        num*=2;
    }
    printf("%ld",cnt);
}


#include<stdio.h>

int main()
{
  int n, m;
  scanf("%d %d", &n, &m);

  if (m < n) {
    printf("No");
  } else {
    printf("Yes");
  }

  return 0;
}

Score : 100 points

Problem Statement

Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A.

The problem has N test cases, all of which must be passed to get an AC verdict.

Takahashi's submission has passed M cases out of the N test cases.

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

If Takahashi's submission gets an AC, print Yes; otherwise, print No.

Sample Input 1

3 3

Sample Output 1

Yes

All three test cases have been passed, so his submission gets an AC.

Sample Input 2

3 2

Sample Output 2

No

Only two out of the three test cases have been passed, so his submission does not get an AC.

Sample Input 3

1 1

Sample Output 3

Yes


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


#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a, &b);
    if(a==b)
    printf("yes");
    else
        printf("no");

return 0;
}


#include<stdio.h>

int main(void)
{
    int n,m;

    scanf("%d %d",n,m);

    if(n - m == 0)
    {
        printf("Yes\n");

    }
    else if(n - m < 0)
    {
        printf("No\n");
    }

    return 0;

}


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


#include <stdio.h>

int main(void)
{
  float a, b;

  scanf("%f", &a);
  scanf("%f", &b);

  if (a == b){
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


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


//なにを出力するかをしっかり確認する必要がある

/*	<limit.h>で範囲を確認できる
	int型サイズ4バイト	変換指定子d
	2147483647～-2147483648

	unsigned int型4バイト	変換指定子u
	4294967295～0

	long int型　8バイト	変換指定子ld
	9223372036854775807～-9223372036854775808

	unsigned long int 型 8バイト　変換指定子lu
	18446744073709551615～0

	short int型2バイト　変換指定子d
	32767～-32768

	unsigned short int型2バイト 変換指定子u
	65535～0

	long long int型
	LLまたはｌｌで表す、　unsignedは頭にuをつける

	配列はnを利用して宣言するわけだからnの格納後に宣言しなければならない

	アルゴリズム
	i番目の数字が1～i-1番目の任意の数字以下であるという条件を満たす
	整数iの個数を数える

	直観的な考え方
	1～i-1番目の全ての数字と比較する
	計算量が多くなりそう

	最小の数字を記録していく
	その最小の数字>=現在の数字
	ならば最小の数字を更新+count+1

*/
#include <stdio.h>
int main (void){
	int n, i;
	int count=0;
	int min =2000000;

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

		if(min < P[i]){
			//最初はどのような値でも条件を満たすことに注意
			if(i==0){
				count+=1;
			}
		}else{
			min = P[i];
			count+=1;
		}

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

Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

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

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1


#include <stdio.h>

int Mdigit(const int x) {
	if (99999 < x) {
		return x / 100000;
	}
	else if (9999 < x && x < 100000) {
		return x / 10000;
	}
	else if (999 < x && x < 10000) {
		return x / 1000;
	}
	else if (99 < x && x < 1000) {
		return x / 100;
	}
	else if (9 < x && x < 100) {
		return x / 10;
	}
	else {
		return x;
	}
}

int mdigit(const int x) {
	return x % 10;
}

int main() {
	int N, i, j, AM, Am;
	long ans = 0;
	long c[10][10];
	scanf("%d", &N);
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			c[i][j] = 0;
		}
	}

	for (i = 1; i <= N; i++) {
		c[Mdigit(i)][mdigit(i)]++;
	}

	//各Aに対して...
	for (i = 1; i <= N; i++) {
		AM = Mdigit(i);
		Am = mdigit(i);
		ans += c[Am][AM];
	}
	printf("%ld", ans);
	return 0;
}

Score : 400 points

Problem Statement

Given is a positive integer N.

Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:

When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

25

Sample Output 1

17

The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5), (6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

Sample Input 2

1

Sample Output 2

1

Sample Input 3

100

Sample Output 3

108

Sample Input 4

2020

Sample Output 4

40812

Sample Input 5

200000

Sample Output 5

400000008


#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
#define mprint(x) printf(FORMATCONVERSION(x),(x))
#define FORMATCONVERSION(x) _Generic((x),\
                                    int:"%d",unsigned int:"%u",\
                                    double:"%lf",long long int:"%lld",\
                                    unsigned long long int:"%llu",\
                                    char :"%c",char*:"%s")

#define mswap(x,y) _Generic((x),int:swap_int,unsigned int:swap_uint,\
                            long long:swap_ll,unsigned long long:swap_ull)(&(x),&(y))

void swap_int(int *a,int *b){int tmp = *a;*a = *b;*b= tmp;return;}
void swap_uint(unsigned int *a,unsigned int *b){unsigned int tmp = *a;*a = *b;*b= tmp;return;}
void swap_ll(long long *a,long long *b){long long tmp = *a;*a = *b;*b= tmp;return;}
void swap_ull(unsigned long long *a,unsigned long long *b){unsigned long long tmp = *a;*a = *b;*b= tmp;return;}

int main(void){
    int n;
    scanf("%d",&n);

    int handtpair[10][10] = {};

    int temp = 0;
    for(int i = 1;i <= n;i++){
        temp = i;
        while(temp >= 10)temp /= 10;
        if(temp != 0 && i % 10 != 0)++handtpair[temp][i % 10];
    }

    long long int ans = 0;
    temp = 0;
    for(int i = 0;i <= n;i++){
        temp = i;
        while(temp >= 10)temp /= 10;
        if(temp != 0 && i % 10 != 0)ans += handtpair[i % 10][temp];
    }
    mprint(ans);
    return 0;
}


//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(void){
  int i,j,n,m,k,a,b,c=0,h,w,r=0,l,t;
  scanf("%d%d%d",&h,&w,&n);
  printf("%d\n",ceil(n,max(h,w)));
  return 0;
}

Score : 100 points

Problem Statement

We have a grid with H rows and W columns, where all the squares are initially white.

You will perform some number of painting operations on the grid.
In one operation, you can do one of the following two actions:

Choose one row, then paint all the squares in that row black.

Choose one column, then paint all the squares in that column black.

At least how many operations do you need in order to have N or more black squares in the grid?
It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.

Constraints

1 \leq H \leq 100

1 \leq W \leq 100

1 \leq N \leq H \times W

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H
W
N

Output

Print the minimum number of operations needed.

Sample Input 1

3
7
10

Sample Output 1

2

You can have 14 black squares in the grid by performing the "row" operation twice, on different rows.

Sample Input 2

14
12
112

Sample Output 2

8

Sample Input 3

2
100
200

Sample Output 3

2


#include<stdio.h>
int main()
{
	long long m=1e9;
	int n,k,s;
	scanf("%d%d%d",&n,&k,&s);
	for(int i=0;i<n;i++)
	{
		if(i<k)
		{
			if(i==0)
			printf("%d",s);
			else
			printf(" %d",s);
		}
		else
		{
			if(s==m-1)
			printf(" %d",m);
			else
			printf(" %d",m-1);
		}
	}
	printf("\n");
	return 0;
}

Score : 400 points

Problem Statement

Given are three integers N, K, and S.

Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below.
We can prove that, under the conditions in Constraints, such a sequence always exists.

There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq N and A_l + A_{l + 1} + \cdots + A_r = S.

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N

1 \leq S \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K S

Output

Print a sequence satisfying the condition, in the following format:

A_1 A_2 ... A_N

Sample Input 1

4 2 3

Sample Output 1

1 2 3 4

Two pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement.

Sample Input 2

5 3 100

Sample Output 2

50 50 50 30 70


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

int main()
{
    char a;
    scanf("%c",&a);
    if(a!='z')
        printf("%c\n",a+1);
    else
        printf("%c\n",a);
    return 0;
}

Score : 100 points

Problem Statement

Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order.

Constraints

C is a lowercase English letter that is not z.

Input

Input is given from Standard Input in the following format:

C

Output

Print the letter that follows C in alphabetical order.

Sample Input 1

a

Sample Output 1

b

a is followed by b.

Sample Input 2

y

Sample Output 2

z

y is followed by z.


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

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

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

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  |
\****************************************/

int main(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int A[n];
  int B[n];
  for(int i=0;i<n;i++){
    A[i]=0;
    B[i]=0;
  }

  for(int i=0;i<m;i++){
    int p;
    scanf("%d",&p);
    p--;
    char s[20];
    scanf("%s",s);

    if(s[0]=='W'){
      if(A[p]==0){
        B[p]++;
      }
    }
    else{
      A[p]++;
    }
  }

  int ac=0;
  int pe=0;
  for(int i=0;i<n;i++){
    if(A[i]!=0){
      ac++;
      pe+=B[i];
    }
  }

  printf("%d %d\n",ac,pe);

  return 0;
}

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA).

The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.

The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WAs received before receiving an AC for the first time on that problem.

Find the numbers of Takahashi's correct answers and penalties.

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

Print the number of Takahashi's correct answers and the number of Takahashi's penalties.

Sample Input 1

2 5
1 WA
1 AC
2 WA
2 AC
2 WA

Sample Output 1

2 2

In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.

In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

Note that it is pointless to get an AC more than once on the same problem.

Sample Input 3

6 0

Sample Output 3

0 0


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
  int n;
  scanf("%d",&n);
  char s[n][111], t[111];
  int u[n], nyaa = 0;
  for(int i=0;i<n;i++){
    scanf("%s%d",s[i], &u[i]);
    nyaa += u[i];
  }
  scanf("%s",t);
  for(int i=0;i<n;i++){
    nyaa -= u[i];
    if(!strcmp(s[i], t))break;
  }
  printf("%d\n",nyaa);
  return 0;
}

Score : 200 points

Problem Statement

Niwango created a playlist of N songs.
The title and the duration of the i-th song are s_i and t_i seconds, respectively.
It is guaranteed that s_1,\ldots,s_N are all distinct.

Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.)
However, he fell asleep during his work, and he woke up after all the songs were played.
According to his record, it turned out that he fell asleep at the very end of the song titled X.

Find the duration of time when some song was played while Niwango was asleep.

Constraints

1 \leq N \leq 50

s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters.

s_1,\ldots,s_N are distinct.

There exists an integer i such that s_i = X.

1 \leq t_i \leq 1000

t_i is an integer.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
\vdots
s_{N} t_N
X

Output

Print the answer.

Sample Input 1

3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1

30

While Niwango was asleep, two songs were played: sixth and prelims.

The answer is the total duration of these songs, 30.

Sample Input 2

1
abcde 1000
abcde

Sample Output 2

0

No songs were played while Niwango was asleep.

In such a case, the total duration of songs is 0.

Sample Input 3

15
ypnxn 279
kgjgwx 464
qquhuwq 327
rxing 549
pmuduhznoaqu 832
dagktgdarveusju 595
wunfagppcoi 200
dhavrncwfw 720
jpcmigg 658
wrczqxycivdqn 639
mcmkkbnjfeod 992
htqvkgkbhtytsz 130
twflegsjz 467
dswxxrxuzzfhkp 989
szfwtzfpnscgue 958
pmuduhznoaqu

Sample Output 3

6348


#include<stdio.h>

int main(){
	char string[50][101],X[101];
	int time[50];
	int N,i,c=0;;
	int sleep=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%s %d",string[i],&time[i]);
	scanf("%s",&X[0]);
	for(i=0;i<N;i++){
		if(c==1)sleep+=time[i];
		if(strcmp(string[i],X)==0)c=1;
	}
	printf("%d\n",sleep);
	return 0;
}


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

#define max(a,b) ((a)>(b))?(a):(b);
#define min(a,b) ((a)>(b))?(b):(a);

int main(void)
{
	int cnt=0, nc=0, n;
	scanf("%d\n", &n);
	char s[51];
	char* sp = s;
	scanf("%s", sp);

	while (*sp)
	{
		if (nc+'A'==*sp)
		{
			nc++;
			if (nc + 'A' == 'C' + 1)
			{
				nc = 0;
				cnt++;
			}
		}
		else
		{
			nc = 0;
		}
		sp++;
	}

	printf("%d", cnt);
}

Score : 200 points

Problem Statement

We have a string S of length N consisting of uppercase English letters.

How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)?

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print number of occurrences of ABC in S as contiguous subsequences.

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

Two contiguous subsequences of S are equal to ABC: the 2-nd through 4-th characters, and the 7-th through 9-th characters.

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5


#include <stdio.h>

int main(void)
{

    int i_characterCount;
    int matchCount = 0;
    scanf("%d", &i_characterCount);

    char c_inputString[i_characterCount];
    scanf("%s", c_inputString);

    int index = 0;
    while (index < i_characterCount)
    {
        if (c_inputString[index] == 65)
        {
            index++;
            if (c_inputString[index] == 66)
            {
                index++;
                if (c_inputString[index] == 67)
                {
                    matchCount++;
                }
            }
        }
        index++;
    }

    printf("%d", matchCount);

}


#include <stdio.h>

int main()
{
	char A[20], B[20];

	scanf("%s %s", A, B);
	printf("%s%s\n", B, A);

	return 0;
}

Score : 100 points

Problem Statement

Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.

Constraints

S and T are strings consisting of lowercase English letters.

The lengths of S and T are between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S T

Output

Print the resulting string.

Sample Input 1

oder atc

Sample Output 1

atcoder

When S = oder and T = atc, concatenating T and S in this order results in atcoder.

Sample Input 2

humu humu

Sample Output 2

humuhumu


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

int main(void)
{
    char S[100] = {};
    char T[100] = {};

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

    printf("%s \n",strcat(T,S));
    return 0;
}


#include<stdio.h>
int main()
{
    char b[105],a[105];
    scanf("%s",&b);
    scanf("%s",&a);
    printf("%s%s\n",a,b);
    return 0;
}


#include <stdio.h>

int main()
{
  long long a,b,k;

  scanf("%lld%lld%lld",&a,&b,&k);

  if(k <= a)
    {a = a-k;}
  else if(k < a+b)
    {
      a = 0;
      b = b-(k-a);
    }
  else
    {
      a =0;
      b =0;
    }

  printf("%lld %lld",a,b );

return 0;
}

Score : 200 points

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:

If Takahashi has one or more cookies, eat one of his cookies.

Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.

If they both have no cookies, do nothing.

In the end, how many cookies will Takahashi and Aoki have, respectively?

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

He has two cookies, so he eats one of them.

Now he has one cookie left, and he eats it.

Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


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

int main()
{
    long long int a,b,k,i;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(k<=a)
    {
        printf("%lld %lld\n",k-a,b);
    }
    else if(k>a && k<=a+b )
    {
        printf("0 %lld\n",a+b-k);
    }
    else if(k>a+b)
    {
        printf("0 0\n");
    }
}


#include <stdio.h>

int main(void)
{
 long A,B,K;
 scanf("%ld%ld%ld",&A,&B,&K);

  if(A>=K){
    A=A-K;
    printf("%ld ",A);
    printf("%ld",B);
   }

  else if (A+B>=K){
           printf("0 ");
           printf("%ld\n",B-(K-A));
   }
  else {
       printf("0 ");
       printf("0\n");
  }
  return 0;
}


#include <stdio.h>

int main(void){

 long long int A, B, K;
  scanf("%lld %lld %lld",&A,&B,&K);
  if(K<A){
    printf("%lld %lld",A-K,B);
  }else if(K>A+B){
    printf("0 0");
  }
  else{
    printf("0 %lld",B-K+A);
  }

  return 0;
}


#include <stdio.h>

int main () {
  int a,b,k;
  scanf("%d%d%d", &a,&b,&k);

  if(k >= a+b)
   printf("0 0\n");

  if(k > a && k < a+b)
   printf("0 %d\n", b-(k-a));

  if(k <= a)
   printf("%d %d\n", a-k, b);

  return 0;
}


#include<stdio.h>
int main(){
  unsigned long int x,i,max=0,j;

  scanf("%ld",&x);
  i=x;
  if(x=0){
    max=0;
  }
  if(x=1){
    max=1;
  }
  if(x=2){
    max=2;
  }
  while(max==0){
    for(j=2;j<((i/2)+1);j++){
    if(i%j==0){
      i++;
      break;
    }
      else{
        if(j==(i/2)){
        max=i;

        }

      }
    }

  }

    printf("%ld",max);

}

Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

2 \le X \le 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003


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

int main(){
   char str1[256];
  char str2[256];
  char strmax[256];
 unsigned long long int i,N,K,R,S,P;       //a=strの10進数
  scanf("%lld %lld",&N,&K);

   scanf("%lld %lld %lld",&R,&S,&P);
   scanf("%s",str1);

unsigned long long int b,max=0,j,score=0,c=0,a=0;
  int str3[256];     //N桁３進数の数列（０グー１チョキ２パー）
  for(i=0;i<N;i++){
    str3[i]=0;
  }

  while(c<pow(3,N)){
  c++;
	   a=c;
    for(b=0;b<N;b++){
       if(str3[b]==str3[b-K]){
	 break;
      }
      if(a==0){
	str3[b]=0;
      }else
      if(a%3==0){
	str3[b]=0;
	a=a/3;
      }else
      if(a%3==1){
	str3[b]=1;
	a=a/3;
      }else
      if(a%3==2){
	str3[b]=2;
	  a=a/3;
      }

    }

     for(i=0;i<N;i++){
    if(str1[i]=='r'){
      if(str3[i]==2){
      score=score+P;
      }
    } else if(str1[i]=='s'){
	if(str3[i]==0){
	  score=score+R;

	}
      }
	else if(str1[i]=='p'){
	  if(str3[i]==1){
	    score=score+S;

	  }
	}

     }

     if(max<score){
       max=score;

     }
     score=0;
  next:;
  }

  printf("%lldでした",max);

}

Score : 400 points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

R points for winning with Rock;

S points for winning with Scissors;

P points for winning with Paper.

However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq N-1

1 \leq R,S,P \leq 10^4

N,K,R,S, and P are all integers.

|T| = N

T consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points.
We cannot earn more points, so the answer is 27.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996


//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse4")

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(void){
  long long i,j,n,m,k,a,b,c,h,w,r=0,l,t,lim,os;
  long long **dp=malloc(sizeof(long long*)*5555);
  long long **ndp=malloc(sizeof(long long*)*5555);
  long long **dx=malloc(sizeof(long long*)*5555);
  for(i=0;i<5555;i++){
    dp[i]=malloc(sizeof(long long)*5555);
    ndp[i]=malloc(sizeof(long long)*5555);
    dx[i]=malloc(sizeof(long long)*5555);
    for(j=0;j<5555;j++){
      dp[i][j]=0;
      ndp[i][j]=0;
      dx[i][j]=0;
    }
  }
  long long kr,gr;
  scanf("%lld%lld",&n,&m);
  for(i=1;i<=n;i++){
    dp[n-i][i]=1;
  }
  //for(j=0;j<4;j++){
  //  for(k=0;k<4;k++){
  //    fprintf(stderr,"[%lld]",dp[j][k]);
  //  }fprintf(stderr,"\n");
  //}fprintf(stderr,"\n");
  t=n/2;
  lim=n;
  for(i=1;i<=t;i++){
    for(j=0;j<=lim;j++){
      for(k=n;k>=0;k--){
        a=j;b=k-j;os=0;
        if(b<0){os=-b;a+=b;b=0;}
        if(a>=0){
          dx[a][b]+=dp[j][k];
          ndp[a][b]+=os*dp[j][k];
        }
      }
    }
    lim=n/i;
    kr=0;gr=0;
    for(j=lim;j>=0;j--){
      for(k=0;k<=n;k++){
        dx[j][k]%=m;
        ndp[j][k]+=dx[j][k];
        ndp[j][k]%=m;
        if(j!=0){
          ndp[j-1][k+1]+=ndp[j][k];
          dx[j-1][k+1]+=dx[j][k];
        }
        dp[j][k]=ndp[j][k];
        if(i==t && k!=0){
          kr+=dp[j][k];kr%=m;
          if(j==0){gr+=dp[j][k];gr%=m;}
        }
        ndp[j][k]=0;
        dx[j][k]=0;
      }
    }
    //for(j=0;j<4;j++){
    //  for(k=0;k<4;k++){
    //    fprintf(stderr,"[%lld]",dp[j][k]);
    //  }fprintf(stderr,"\n");
    //}fprintf(stderr,"\n");
  }
  if(n%2==1){printf("%lld\n",kr);}
  else{printf("%lld\n",gr);}
  return 0;
}

Score : 1200 points

Problem Statement

N problems have been chosen by the judges, now it's time to assign scores to them!

Problem i must get an integer score A_i between 1 and N, inclusive.
The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold.
Different problems can have the same score, though.

Being an ICPC fan, you want contestants who solve more problems to be ranked higher.
That's why, for any k (1 \le k \le N-1), you want the sum of scores of any k problems to be strictly less than the sum of scores of any k+1 problems.

How many ways to assign scores do you have? Find this number modulo the given prime M.

Constraints

2 \leq N \leq 5000

9 \times 10^8 < M < 10^9

M is a prime.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of ways to assign scores to the problems, modulo M.

Sample Input 1

2 998244353

Sample Output 1

3

The possible assignments are (1, 1), (1, 2), (2, 2).

Sample Input 2

3 998244353

Sample Output 2

7

The possible assignments are (1, 1, 1), (1, 2, 2), (1, 3, 3), (2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3).

Sample Input 3

6 966666661

Sample Output 3

66

Sample Input 4

96 925309799

Sample Output 4

83779


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int n,i;
    char s[100]={},t[100]={},ans[220]={};
    scanf("%d %s %s",&n,s,t);
    for(i=0; i<n; i++){
        ans[2*i]=s[i];
        ans[2*i+1]=t[i];
    }
    printf("%s",ans);
    return 0;
}

Score : 200 points

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints

1 \leq N \leq 100

|S| = |T| = N

S and T are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S T

Output

Print the string formed.

Sample Input 1

2
ip cc

Sample Output 1

icpc

Sample Input 2

8
hmhmnknk uuuuuuuu

Sample Output 2

humuhumunukunuku

Sample Input 3

5
aaaaa aaaaa

Sample Output 3

aaaaaaaaaa