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

int main(void){

	int a, b, v, w, t;
	bool f = false;

	scanf("%d %d", &a, &v);
	scanf("%d %d", &b, &w);

	for(int i = 0; i < t; i++){
		if(a-b <= v*i - w*i){
			f = true;
			break;
		}
	}

	if(f){
		printf("YES");
	}

	else{
		printf("NO");
	}

	return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

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

1 \leq V,W \leq 10^9

1 \leq T \leq 10^9

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A V
B W
T

Output

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

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO


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

int main(void) {
	long int a,v,b,w,t;
	scanf("%ld%ld",&a,&v);
	scanf("%ld%ld",&b,&w);
	scanf("%ld",&t);
	if(b-a > 0){
		if(((b+w*t) - (a+v*t))<= 0){
			printf("YES");
		}else{
			printf("NO");
		}
	}
	else if(a-b > 0){
		if((b-w*t) - (a-v*t) >= 0){
			printf("YES");
		}
		else{
			printf("NO");
			}
	}
	return 0;
}

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

Submitted source-code file size, in bytes.

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

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


#include<stdio.h>
int main()
{
  long A,B,V,W,T;
  scanf("%ld %ld %ld %ld %ld",&A,&V,&B,&W,&T);
  if((V*T)>=(W*T+(B-A)))
     printf("YES");
  else
     printf("NO");
   return 0;
     }


#include <stdio.h>

int main(void)
{
  int A = 0;
  int B = 0;
  int V = 0;
  int W = 0;
  int T = 0;

  scanf("%d %d", &A, &V);
  scanf("%d %d", &B, &W);
  scanf("%d", &T);

  if ( (A + V * T) >= (B + V * T) ) {
    printf("YES");
  }
  else {
    printf("NO");
  }
  return 0;
}


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

int main() {
	int n, k,*a,*b;
	scanf("%d%d", &n, &k);
	a = (int*)malloc(n * sizeof(int));
	b = (int*)malloc(n * sizeof(int));
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < k; i++) {
		int flag = 1;
		for (int j = 0; j < n; j++) {
			int l = fmaxf(0, j - a[j]);
			int r = fminf(n - 1, j + a[j]);
			b[j]++;
			if (r + 1 < n) b[r + 1]--;
		}
		for (int j = 0; j < n - 1; j++) b[j + 1] += b[j];
		for (int j = 0; j < n; j++) {
			a[j] = b[j];
			if (a[j] != n) flag = 0;
		}
		if (flag==1) break;
	}
	for (int i = 0; i < k; i++) scanf("%d", a[i]);

	return 0;
}

Score : 500 points

Problem Statement

We have N bulbs arranged on a number line, numbered 1 to N from left to right.
Bulb i is at coordinate i.

Each bulb has a non-negative integer parameter called intensity.
When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5.
Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row:

For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i.

Find the intensity of each bulb after the K operations.

Constraints

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

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

0 \leq A_i \leq N

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format:

A{'}_1 A{'}_2 \ldots A{'}_N

Sample Input 1

5 1
1 0 0 1 0

Sample Output 1

1 2 2 1 2

Initially, only Bulb 1 illuminates coordinate 1, so the intensity of Bulb 1 becomes 1 after the operation.
Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2, so the intensity of Bulb 2 becomes 2.

Sample Input 2

5 2
1 0 0 1 0

Sample Output 2

3 3 4 4 3


#include <stdio.h>

#define LENGTH 256

int main() {
  char input[LENGTH];
  int a, b, ans;
  fgets(input, LENGTH, stdin);
  sscanf(input, "%d %d", &a, &b);
  ans = a * b;
  printf("%d \n", ans);
}

Score : 100 points

Problem Statement

Compute A \times B.

Constraints

1 \leq A \leq 100

1 \leq B \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Sample Input 1

2 5

Sample Output 1

10

We have 2 \times 5 = 10.

Sample Input 2

100 100

Sample Output 2

10000


#include<stdio.h>

int main(void){
int A, B, ans;
ans = A*B;
printf("%d\n", ans);
return 0;
}


Score : 400 points

Problem Statement

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

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

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

z divides N;

z is different from all integers chosen in previous operations.

Then, replace N with N/z.

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

Constraints

All values in input are integers.

1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

24

Sample Output 1

3

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

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

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

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

Sample Input 2

1

Sample Output 2

0

We cannot apply the operation at all.

Sample Input 3

64

Sample Output 3

3

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

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

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

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

Sample Input 4

1000000007

Sample Output 4

1

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

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

Sample Input 5

997764507000

Sample Output 5

7


Score : 200 points

Problem Statement

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

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

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

Constraints

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

T consists of P, D, and ?.

Input

Input is given from Standard Input in the following format:

T

Output

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

Sample Input 1

PD?D??P

Sample Output 1

PDPDPDP

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

Sample Input 2

P?P?

Sample Output 2

PDPD


Score: 100 points

Problem Statement

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

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

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

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

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

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

Constraints

N is a positive integer not exceeding 999.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

16

Sample Output 1

pon

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

Sample Input 2

2

Sample Output 2

hon

Sample Input 3

183

Sample Output 3

bon


#include <stdio.h>

int main(){
  int n,i;

  scanf("%d",&n);
  i = n % 10;
  //printf("%d",i);

  if(i == 3)
    printf("bon\n");
  else if(i == 0 || i == 1 || i == 6 || i == 8)
    printf("pon\n");
  else
    printf("hon\n");

  return 0;
}


#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  int units = N % 10;

  switch (units) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
            puts("hon");
            break;
    case 3:
            puts("bon");
            break;
    default:
            puts("pon");
            break;
  }
  return 0;
}


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

int main()
{

    int k;
    scanf("%d",&k);
    char s[200];
    scanf("%s",s);

    if(strlen(s)<=k)
    {
        printf("%s\n",s);
    }
    else
    {
        char ans[200];

        strncpy(ans,s,k);
        ans[k]=('.');
        ans[k+1]=('.');
        ans[k+2]=('.');

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

    return 0;
}

Score: 200 points

Problem Statement

We have a string S consisting of lowercase English letters.

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

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

Constraints

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

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Sample Input 1

7
nikoandsolstice

Sample Output 1

nikoand...

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

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

Sample Input 2

40
ferelibenterhominesidquodvoluntcredunt

Sample Output 2

ferelibenterhominesidquodvoluntcredunt

The famous quote from Gaius Julius Caesar.


#include<stdio.h>
#include<string.h>
int main()
{
  int K; char S[110];
  scanf("%d\n",&K);
  for(int i=0;i<110;i++){
    scanf("%c",&S[i]);
  }
  if(strlen(S)<=K){
    printf("%s",S);
  }else{
    for(int i=0;i<K;i++){
      printf("%c",S[i]);
    }
    printf("...");
  }
}


#include <stdio.h>
#include <string.h>
int main(){
  int K,i,l;
  scanf("%d",&K);
  char S[101];
  scanf("%s",S);
  for(i=0;i<101;i++){
    if(S[i]=='\0'){
      l=i;
      break;
    }
  }
  if(K>=l) printf("%s",S);
  else{
    for(i=0;i<K;i++) printf("%c",S[i]);
    printf("...");
  }
  return 0;
}


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

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 dn(const void*a,const void*b){return*(int*)b-*(int*)a;}

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){
  double a,b,h,m;
  scanf("%lf%lf%lf%lf",&a,&b,&h,&m);

  double pi=3.14159265358979;
  /*

  時計の中心と文字盤の0を結んだ線を基準線と呼ぶことにします．

  時計の中心と文字盤のh(0<=h<12)を結んだ線と基準線が作る角の大きさx(0<=x<180)は
  度数法で(30*h)と表すことができます．

  また，m分(0<=m<60)の時の長針と基準線が作る角の大きさy(0<=y<180)は
  度数法で(6*m)と表すことができます．

  これらをまとめてh時m分の時の長針と短針が作る角の大きさは
  abs(30*h-6*m)と表すことができそうです(これが180を超える場合は360から引いてやればいいです)

  が，短針は時間が変わったら30度一気に動くわけではなく，60分かけて30度を動いていくので，それも考慮しなければなりません．

  つまり，30*(m/60)=m/2をxに足してやる必要があります．

  改めて，h時m分の時の長針と短針が作る角の大きさzは
  abs(30*h+m/2-6*m)と表すことができます．

  ここで余弦定理を用いて求める長さが欲しいわけですが，注意しなければいけないのは
  sin(z)の引数(渡してあげるzのこと)は度数法ではなく弧度法でないといけません．

  pi==180\degreeであるのでpi:180==?:zの式を?について解くと
  ?=z*pi/180であることがわかります．

  以上のことより，答えは

  a*a+b*b-2*a*b*cos(z*pi/180)

  となります．

  */

  //0<=h<12にする
  if(h>=12){
    h-=12;
  }

  //hは基準線とそれが作る角度
  h=30*h+m/2;

  //mは基準線とそれが作る角度
  m*=6;

  double z=h-m;

  //この部分，なんでこんな実装をしているかというと，
  //abs(h-m)を渡してやったら誤差で消えるケースがあったので
  //こういう実装をしました．
  if(z<0){
    z*=-1;
  }

  if(z>180){
    z=360-z;
  }

  z=z*pi/180;

  double ans=a*a+b*b-2*a*b*cos(z);

  printf("%.16lf\n",sqrt(ans));

  return 0;
}

Score: 300 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq A, B \leq 1000

0 \leq H \leq 11

0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

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

Sample Input 1

3 4 9 0

Sample Output 1

5.00000000000000000000

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

Sample Input 2

3 4 10 40

Sample Output 2

4.56425719433005567605

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


/* ex4_1
   YSK722 */

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

int main(void){
    double short_hand, long_hand, hour, minute, ans;
    scanf("%lf %lf %lf %lf", &short_hand, &long_hand, &hour, &minute);
    /* 余弦定理を用いる
       cos(-x) = cos(x)より、回転角の大小は考えない */
    ans = sqrt(
              pow(short_hand, 2) + pow(long_hand, 2) \
              - 2 * short_hand * long_hand * cos(M_PI*(hour/6.0 - minute/30.0))
          );
    printf("%lf", ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    double a,b,h,m,ans;
    scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
    ans=sqrt((b*b)+(a*a)-2*b*a*cos((h*60-11*m)*3.14159265358979/360));
    printf("%lf",ans);
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    long double a,b,h,m,A,B,C,ans;
    scanf("%Lf%Lf%Lf%Lf",&a,&b,&h,&m);
    A=(30.0*h)+(m/2.0);
    B=360.0-(6*m);
    C=360-(A+B);
    ans=(b*b)+(a*a)-2*b*a*cos(C);
    ans=sqrt(ans);
    printf("%Lf",ans);
}


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

int main(void){

    int A,B,H,M;
    double ACB,ans;
    scanf("%d %d %d %d", &A, &B, &H, &M);

    ACB = fabsl(M_PI/360*(60*H-11*M));

    if(ACB>=M_PI){
        ACB = 2*M_PI - ACB;
    }

    ans = sqrt(A*A+B*B-2*A*B*cos(ACB));

    printf("%f", ans);

    return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
int A,B,H,M;
double Angle,result=0,Cos,re;
  scanf("%d %d %d %d",&A,&B,&H,&M);
  Angle=0.5*(60*H - 11*M);
  Cos=cos(Angle)*(22/7)/180;
  result=pow(A,2) + pow(B,2) - 2*A*B*Cos;
  re=sqrt(result);
  printf("%f",re);
  return 0;
}


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

int main(void)
{
  int a,b,h,m;
  scanf("%ld %ld %ld %ld", &a, &b, &h, &m);
  double deg,c;
  deg = fabs(30*h+0.5*m-6*m);
  if(deg>180){
    deg = 360-deg;
  }
  c=sqrt(a*a+b*b-2*a*b*cos(deg*3.14159265/180));
  printf("%f\n", c);
  return 0;
}


/* A - Registration */

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

int main(void){
  char S[10], T[11], s[11], i;
  scanf("%s", S);
  scanf("%s", T);
  for(i = 0; i < strlen(S); i++){
    s[i] = T[i];
  }
  // s[i] = '\0';
  if(strcmp(S, s) == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}

Score : 100 points

Problem Statement

Takahashi wants to be a member of some web service.

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

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

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

Constraints

S and T are strings consisting of lowercase English letters.

1 \leq |S| \leq 10

|T| = |S| + 1

Input

Input is given from Standard Input in the following format:

S
T

Output

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

Sample Input 1

chokudai
chokudaiz

Sample Output 1

Yes

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

Sample Input 2

snuke
snekee

Sample Output 2

No

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

Sample Input 3

a
aa

Sample Output 3

Yes


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

int main(){
  char s[10], t[11];
  int tn, sn;

  scanf("%s", s);
  scanf("%s", t);
  if(strlen(s) != (strlen(t)-1)){
    printf("No\n");
    return 0;
  }else if(strstr(t, s) == NULL){
    printf("No\n");
    return 0;
  }else if(s[0] != t[0]){
    printf("No\n");
    return 0;
  }else{
    printf("Yes\n");
  }

  return 0;
}


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

int main(void){
	char s[11], t[12], u[11];
	int i, x=0;

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

	for(i=0; s[i]!=0; i++){
		if(s[i] != t[i]){
			x=1;
			break;
		}
	}

	if(x == 1){
		printf("No");
	}else{
		printf("Yes");
	}

	return 0;
}


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

int main() {
    char S[10],T[11];
    int len_S,len_T;

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

    len_S = strlen(S);
    len_T = strlen(T);
    if (len_T != len_S + 1 || len_S < 1 || len_S > 10){
        printf("No\n");
    }else{
        if (strncmp(S,T,len_S) == 0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }

    return 0;
}


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

int main(void)
{
  char s[10],t[10];
  scanf("%s", s);
  scanf("%s", t);
  t[10] = t[strlen(s)-2];
  if(strcmp(s,t) == 0){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


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

Score : 200 points

Problem Statement

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

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

Constraints

All values in input are integers.

0 \leq A, B, C

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

Input

Input is given from Standard Input in the following format:

A B C K

Output

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

Sample Input 1

2 1 1 3

Sample Output 1

2

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

Sample Input 2

1 2 3 4

Sample Output 2

0

Sample Input 3

2000000000 0 0 2000000000

Sample Output 3

2000000000


#include<stdio.h>
#include<string.h>
int main(){
  int a,b,c,k;
  int i,j;

  scanf("%d %d %d %d",&a,&b,&c,&k);
  if(a<=k){
   printf("%d\n",k);
  }else if(a+b<=k&&a+b+c<k){
   printf("%d\n",a);
  }else{
    printf("%d\n",a+a+b-k);
  }

 return 0;
}


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


Score : 600 points

Problem Statement

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

An empty string;

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

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

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

Constraints

1 \leq N \leq 10^6

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

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

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

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

Sample Input 1

2
)
(()

Sample Output 1

Yes

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

Sample Input 2

2
)(
()

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes

Sample Input 4

3
(((
)
)

Sample Output 4

No


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

  char S[3];
  scanf("%s",S);
  if(strcmp(S,"ABC") == 0){
    printf("ARC");
  }else{
    printf("ABC");
  }
  return 0;
}

Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

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

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

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

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

ABC

Sample Output 1

ARC

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


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

int main(void)
{
    char B[4] = "ABC";
    char R[4] = "ARC";
    char S[3];
    scanf("%s", S);

    if (strcmp(S, R) == 0) {
        printf("%s\n", B);
    }
    else {
        printf("%s\n", R);
    }

    return S;
}


#include<stdio.h>
int main()
{
    char S[4];
    scanf("%s",&S);
    int c=0;
    for(int i=0;i<3;i++)
    {
        if(S[i+1]=='B')
            c=1;
    }
    if(c==1)
        printf("ARC\n");
    else
        printf("ABC\n");

    return 0;
}


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long

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


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

int main(void)
{
    char S[4];
    scanf("%s", S);

    if (strcmp("ABC", S) == 0) {
        printf("ARC");
    }
    else {
        printf("ABC");
    }

    return 0;
}


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

int main() {
	char s[3];
	scanf("%s", s);
	if(strcmp(s,"ABC") == 0) printf("ARC");
	if(strcmp(s,"ARC") == 0) printf("ABC");
}


#include <stdio.h>

int main(void){

  int v[100];
  for(int i=0;i<100;i++){
    v[i]=0;
  }
  int n,k;
  scanf("%d%d", &n, &k);
  for(int i=0;i<k;i++){
    int d;
    scanf("%d",&d);
    for(int j=0;j<d;j++){
      int a;
      scanf("%d",&a);
      v[a-1]=1;
    }
  }

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

  return 0;
}

Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 100

1 \leq d_i \leq N

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the answer.

Sample Input 1

3 2
2
1 3
1
3

Sample Output 1

1

Snuke 1 has Snack 1.

Snuke 2 has no snacks.

Snuke 3 has Snack 1 and 2.

Thus, there will be one victim: Snuke 2.

Sample Input 2

3 3
1
3
1
3
1
3

Sample Output 2

2


#include <stdio.h>

int main(void){

    int N,K;
    int i,j,kai;
    scanf("%d %d",&N,&K);

    int flag[N],l;

    for(l=0;l<N;l++){
        flag[l]=0;
    }

    for(i=0;i<K;i++){
        scanf("%d",&kai);
        int arr[kai];
        for(j=0;j<kai;j++){
            scanf("%d",&arr[j]);
            flag[arr[j]-1]=1;
        }
    }
    int count=0,m;
    for(m=0;m<N;m++){
        if(flag[m]==0){
            count++;
        }
    }

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

}


Score : 300 points

Problem Statement

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

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

How many good observatories are there?

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq H_i \leq 10^9

1 \leq A_i,B_i \leq N

A_i \neq B_i

Multiple roads may connect the same pair of observatories.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of good observatories.

Sample Input 1

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

Sample Output 1

2

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

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

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

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

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

Sample Input 2

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

Sample Output 2

3


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

int main(){

 long long int N,M;
  scanf("%lld %lld",&N,&M);

/*
  char A[];
  scanf("%s",A);
  */

  long long int H[N+1];
  int i;
  for(i=1;i<=N;i++){
   scanf("%lld ",&H[i]);
   }

  double T[N+1];
    for (i=1;i<=N;i++){
      T[N]=1;
    }
  long long int A,B;
  for(i=1;i<=M;i++){
   scanf("%lld %lld",&A,&B);
   if (H[A] < H[B]){
     if(T[B]!=-1){
     T[A] = -1;
     T[B] = 1;
     }
     else{
     T[A] = -1;
     }
   }
   else if (H[A] > H[B]){
     if(T[A]!=-1){
     T[B] = -1;
     T[A] = 1;
     }
     else{
     T[B] = -1;
     }

   }
   else{
     T[A] = -1;
     T[B] = -1;

   }

   }

long long int counter;
counter = 0;
for (i=1;i<=N;i++){
  if(T[i]>=0){
    counter +=1;
  }
}
printf("%lld",counter);

 return(0);
 }


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

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)100000000)

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

static UF_Node uf_Node[1000000];

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

static void sha1(const char* str, uint64_t len, uint32_t* hash) {
    if (len == 0) {
        len = (uint64_t)strlen(str);
    }

    uint32_t h[5] = { 0x67452301 ,0xEFCDAB89 ,0x98BADCFE ,0x10325476 ,0xC3D2E1F0 };

    uint32_t w[80];
    for (uint64_t i = 0; i < 16; i++) {
        w[i] = 0;
    }
    for (uint64_t i = 0; i < len; i++) {
        w[i / 4] |= (uint32_t)(str[i]) << ((i % 4) * 8);
    }
    w[15] = (uint32_t)len * 8;

    for (uint64_t i = 16; i < 80; i++) {
        const uint32_t v = w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16];
        w[i] = (v << 1) | (v >> 31);
    }

    uint32_t a = h[0];
    uint32_t b = h[1];
    uint32_t c = h[2];
    uint32_t d = h[3];
    uint32_t e = h[4];

    for (uint64_t i = 0; i < 80; i++) {
        uint32_t f = 0;
        uint32_t k = 0;
        if (i < 20) {
            f = (a & b) | (~b & d);
            k = 0x5A827999;
        }
        else if (i < 40) {
            f = b ^ c ^ d;
            k = 0x6ED9EBA1;
        }
        else if (i < 60) {
            f = (b & c) | (b & d) | (c & d);
            k = 0x8F1BBCDC;
        }
        else {
            f = b ^ c ^ d;
            k = 0xCA62C1D6;
        }

        const uint32_t t = ((a << 5) | (a >> 27)) + f + e + k + w[i];
        e = d;
        d = c;
        c = (b << 30) | (b >> 2);
        b = a;
        a = t;
    }

    h[0] = h[0] + a;
    h[1] = h[1] + b;
    h[2] = h[2] + c;
    h[3] = h[3] + d;
    h[4] = h[4] + e;

    hash[4] = h[0];
    hash[3] = h[1];
    hash[2] = h[2];
    hash[1] = h[3];
    hash[0] = h[4];
}

#define MOD_VAL (UINT64_C(1000000007))

typedef struct {
    uint64_t strListSize;
    char str[10][11];
} HMap;

static HMap hMap[1000000];

static uint64_t H[100000];

static bool isGoodPeak[100000];

int main(void) {
    uint64_t N, M;

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

        isGoodPeak[i] = true;
    }
    for (uint64_t i = 0; i < M; i++) {
        uint64_t A, B;
        scanf("%"PRIu64"%"PRIu64, &A, &B);
        A--;
        B--;

        if (H[A] < H[B]) {
            isGoodPeak[A] = false;
        }
        else if (H[A] == H[B]) {
            isGoodPeak[A] = false;
            isGoodPeak[B] = false;
        }
        else {
            isGoodPeak[B] = false;
        }
    }

    uint64_t cnt = 0;
    for (uint64_t i = 0; i < N; i++) {
        if (isGoodPeak[i]) {
            cnt++;
        }
    }

    printf("%"PRIu64, cnt);

    return 0;
}


#include<stdio.h>
int keisan(long long int a,long long int b){
	return a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b;
}
int main(void){
	long long int x,a,b;
	int temp=0;
	scanf("%lld",&x);
	do{
		for(long long int i=1;i<x+1;i++){
			if(x%i==0){
				for(long long int j=0;j<i;j++){
					a=j;
					b=j-i;
					if((a-b)*keisan(a,b)==x){
						temp=1;
						break;
					}
				}
			}
			if(temp==1){
				break;
			}
		}
	}while(temp==0);
	printf("%lld %lld",a,b);
}

Score : 400 points

Problem Statement

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

Constraints

1 \leq X \leq 10^9

X is an integer.

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

Input

Input is given from Standard Input in the following format:

X

Output

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

A B

Sample Input 1

33

Sample Output 1

2 -1

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

Sample Input 2

1

Sample Output 2

0 -1


#include <stdio.h>

#define int64 long long

int main()
{
  int64 nn;
  scanf("%lld", &nn);
  int64 aa[nn][2], tmp, cnt = 0;
  for(int64 ii = 0;ii < nn;ii++)
  {
    scanf("%lld", &tmp);
    if(tmp <= 200000)
    {
      aa[cnt][0] = ii;
      aa[cnt][1] = tmp;
      cnt++;
    }
  }
  int64 ans = 0;
  for(int64 ii = 0;ii < cnt - 1;ii++)
  {
    for(int64 jj = ii + 1;jj < cnt;jj++)
    {
      if(aa[jj][0] - aa[ii][0] == aa[jj][1] + aa[ii][1])
      {
        ans++;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Score: 500 points

Problem Statement

You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.

There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i.

According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction.

The absolute difference of their attendee numbers is equal to the sum of their heights.

There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above?

P.S.: We cannot let you know the secret.

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the number of pairs satisfying the condition.

Sample Input 1

6
2 3 3 1 3 1

Sample Output 1

3

A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.

A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.

A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.

No other pair satisfies the condition, so you should print 3.

Sample Input 2

6
5 2 4 2 8 8

Sample Output 2

0

No pair satisfies the condition, so you should print 0.

Sample Input 3

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

Sample Output 3

22


#include <stdio.h>

int main(){
	int k,a,b;
	int flag = 0;
	scanf("%d",&k);
	scanf("%d %d",&a,&b);
		for(int i=a;i<=b;i++){
			if(i%k==0){
				flag = 1;
			}
		}
		flag== 1 ? puts("OK") : puts("NG");

	return 0;
}

Score: 100 points

Problem Statement

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

If he can achieve the objective, print OK; if he cannot, print NG.

Constraints

All values in input are integers.

1 \leq A \leq B \leq 1000

1 \leq K \leq 1000

Input

Input is given from Standard Input in the following format:

K
A B

Output

If he can achieve the objective, print OK; if he cannot, print NG.

Sample Input 1

7
500 600

Sample Output 1

OK

Among the multiples of 7, for example, 567 lies between 500 and 600.

Sample Input 2

4
5 7

Sample Output 2

NG

No multiple of 4 lies between 5 and 7.

Sample Input 3

1
11 11

Sample Output 3

OK


#include<stdio.h>
int main(void)
{
  int k,a,b;
  scanf("%d %d %d",&k,&a,&b);
  for(int i=a;i<=b;i++){
    if(i%k==0){
      puts("OK");
      return 0;
    }
  }
  puts("NG");
  return 0;
}


#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  int K,A,B;
  long cnt = 0;
  scanf("%d", &K);
  scanf("%d %d", &A, &B);
  if (K == 1) {
    printf("OK\n");
    return 0;
  }
  if (A == B) {
    if ((A / K )*K == A) {
      printf("OK\n");
    } else {
      printf("NG\n");
    }
    return 0;

  }
  int c;
  if (A % K == 0) {
    c = (A / K);
  } else {
    c = (A / K) + 1;
  }
    int d = B / K;
    if (c <= d) {
      printf("OK\n");
    } else {
      printf("NG\n");
    }
    return 0;
  }


# include <stdio.h>
int main(void){
    int k,a,b,i;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    for(i=0;i<1000;i++){
        if(i*k>b){
            printf("NG");
            return 0;
        }else if(i*k>=a && i*k<=b){
            printf("OK");
            return 0;
        }
    }
}


#include<stdio.h>

int main(void){
  int k,a,b,i;
  scanf("%d %d %d", &k, &a, &b);
  if(k == 1)
    printf("OK");
  else if(k > b)
    printf("NG");
  else if(k <= b - a)
    printf("OK");
  else {
    for(i=a;i<b;i++){
      if(i%k == 0){
        printf("OK");
        break;
      }
      else if(i == b)
        printf("NG");
    }
  }
  return 0;
}


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

int main()
{
	ll X;
	scanf("%lld", &X);
	ll a = 100;
	ll i = 0;
	while (a < X)
	{
		a = ((ll)a*1.01);
		i++;
	}
	printf("%lld",i);
	return (0);
}

Score : 200 points

Problem Statement

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

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

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

Constraints

101 \le X \le 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

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

Sample Input 1

103

Sample Output 1

3

The balance after one year is 101 yen.

The balance after two years is 102 yen.

The balance after three years is 103 yen.

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

Sample Input 2

1000000000000000000

Sample Output 2

3760

Sample Input 3

1333333333

Sample Output 3

1706


#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long

int main(void) {
	ll x,y = 100;
	scanf("%ld", &x);
	for (int i = 1;; i++) {
		y += y / 100;
		if (y >= x) {
			printf("%d\n", i);
			return 0;
		}
	}
}


#include <stdio.h>
int main(void){
    //変数定義
    int N;//N文字
    int M;//M種類
    int Q;//フィルターの数
    int point = 0;//現在のポイント
    int maxpoint = 0;//最大のポイント
    scanf("%d %d %d",&N,&M,&Q);//１行目入力
    int f[Q][4];//フィルター格納用配列、0~(Q-1)
    int l[N];//数列格納用配列、0~(N-1)
    //入力プログラム
    for(int i=0;i<Q;i++){//Q回繰り返す
    	scanf("%d %d %d %d",&f[i][0],&f[i][1],&f[i][2],&f[i][3]);//１行読み取り
    }
    //ループ＆数列作成
    //N文字の数列
    //初期化
    for(int i=1;i<=N;i++){
    	l[i-1]=i;
    }
    while(l[0]!=M-N+1){
        //printf("%d %d %d\n",l[0],l[1],l[2]);
    	//点数計算処理
    	point = 0;
    	for(int i=0;i<Q;i++){//Q回繰り返す
    	    //printf("%d %d %d %d",f[i][0],f[i][1],f[i][2],f[i][3]);
    		if(l[f[i][1]-1]-l[f[i][0]-1]==f[i][2]){
    		    //printf("*\n");
    			point += f[i][3];
    		}else{
    		    //printf("\n");
    		}
    	}
    	if(maxpoint<=point)
          	maxpoint = point;

    	//新規数列作成処理
    	//各n文字目について処理
    	for(int i=N-1;i>=0;i--){
    		if(i==N-1){
    			if(l[i]<M){//右端の数がMより小さいなら
    			l[i]++;
    			break;
    			}
    		}else{
    			if(l[i]<l[i+1]){//右端の数がMより小さいなら
           			l[i]++;
           			break;
           		}
           	}
    	}
    }
    printf("%d",maxpoint);
}

Score : 300 points

Problem Statement

Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).

Consider a sequence A satisfying the following conditions:

A is a sequence of N positive integers.

1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.

Let us define a score of this sequence as follows:

The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)

Find the maximum possible score of A.

Constraints

All values in input are integers.

2 ≤ N ≤ 10

1 \leq M \leq 10

1 \leq Q \leq 50

1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )

0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )

(a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)

1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )

Input

Input is given from Standard Input in the following format:

N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q

Output

Print the maximum possible score of A.

Sample Input 1

3 4 3
1 3 3 100
1 2 2 10
2 3 2 10

Sample Output 1

110

When A = \{1, 3, 4\}, its score is 110. Under these conditions, no sequence has a score greater than 110, so the answer is 110.

Sample Input 2

4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Sample Output 2

357500

Sample Input 3

10 10 1
1 10 9 1

Sample Output 3

1


#include<stdio.h>
int n,m,q,max;
int A[15];
int ai[55],bi[55],ci[55],di[55];
int check(){
	int ans=0;
	for(int i=1;i<=q;i++) if(A[bi[i]]-A[ai[i]]==ci[i]) ans+=di[i];
	return ans;
}
void make(int i,int t){
	if(i==n+1){
		int x=check();
		if(x>max) max=x;
		return ;
	}
	for(int j=t;j<=m;j++){
		A[i]=j;
		make(i+1,j);
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d%d",&ai[i],&bi[i],&ci[i],&di[i]);
	}
	make(1,1);
	printf("%d",max);
	return 0;
}


#include<stdio.h>
#include<math.h>
int main(void){
  int a,b,c,d;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  int e[c];
  for(int x=c;x>0;x--){
    e[c-x]=floor(a*x/b)-a*floor(x/b);
  }
  d=e[0];
  for(int i=0;i<c;i++){
      if(e[i]>=d){
          d-e[i];
      }else{
          d=d;
      }
  }
  printf("%d",d);
  return 0;
}

Score : 400 points

Problem Statement

Given are integers A, B, and N.

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

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

Constraints

1 ≤ A ≤ 10^{6}

1 ≤ B ≤ 10^{12}

1 ≤ N ≤ 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B N

Output

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

Sample Input 1

5 7 4

Sample Output 1

2

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

Sample Input 2

11 10 9

Sample Output 2

9


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

int main()
{
	long long int Point;
	long long int PointMax = 0;
	long long int X = 1;
	long long int A, B, N;

	scanf("%lld%lld%lld", &A, &B, &N);

	while (X <= N) {
		Point = floor(A*X / B) - A * floor(X / B);
		if (Point > PointMax) {
			PointMax = Point;
		}
		X++;
	}

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

	return 0;
}


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

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

  ans = floor( ( a * x ) / b ) - a * floor( x / b );

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


#include <stdio.h>

int main()
{
    int n, m;

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        printf("%d %d\n", (n / 2) - m + i, (n / 2) + m - i + 1);
    }
    return 0;
}

Score : 500 points

Problem Statement

You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)
N players will participate in this competition, and they are given distinct integers from 1 through N.
The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive).
You cannot assign the same integer to multiple playing fields.
The competition consists of N rounds, each of which proceeds as follows:

For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.

Then, each player adds 1 to its integer. If it becomes N+1, change it to 1.

You want to ensure that no player fights the same opponent more than once during the N rounds.
Print an assignment of integers to the playing fields satisfying this condition.
It can be proved that such an assignment always exists under the constraints given.

Constraints

1 \leq M

M \times 2 +1 \leq N \leq 200000

Input

Input is given from Standard Input in the following format:

N M

Output

Print M lines in the format below.
The i-th line should contain the two integers a_i and b_i assigned to the i-th playing field.

a_1 b_1
a_2 b_2
:
a_M b_M

Sample Input 1

4 1

Sample Output 1

2 3

Let us call the four players A, B, C, and D, and assume that they are initially given the integers 1, 2, 3, and 4, respectively.

The 1-st round is fought by B and C, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 2, 3, 4, and 1, respectively.

The 2-nd round is fought by A and B, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 3, 4, 1, and 2, respectively.

The 3-rd round is fought by D and A, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 4, 1, 2, and 3, respectively.

The 4-th round is fought by C and D, who has the integers 2 and 3, respectively. After this round, A, B, C, and D have the integers 1, 2, 3, and 4, respectively.

No player fights the same opponent more than once during the four rounds, so this solution will be accepted.

Sample Input 2

7 3

Sample Output 2

1 6
2 5
3 4


#include <stdio.h>

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

int matukisu[271828];

int aru[271828];

int main(void) {
	int N, M;
	int i;
	int gen;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		matukisu[i] = i + 1;
	}
	for (gen = 1; ; gen++) {
		int ng = 0;
		for (i = N - 1; i > 0; i--) {
			int pos = (int)(randint() % (i + 1)); /* ごめん */
			int temp = matukisu[pos];
			matukisu[pos] = matukisu[i];
			matukisu[i] = temp;
		}
		for (i = 0; i < M; i++) {
			int tomatu = matukisu[i * 2] - matukisu[i * 2 + 1];
			if (tomatu < 0) tomatu = -tomatu;
			if (aru[tomatu] == gen || aru[N - tomatu] == gen) {
				ng = 1;
				break;
			}
		}
		if (!ng) {
			for (i = 0; i < M; i++) {
				printf("%d %d\n", matukisu[i * 2], matukisu[i * 2 + 1]);
			}
			break;
		}
	}
	return 0;
}

/*

123**321
23**3211
3**32112
**321123
*321123*

NG

7 3のケース
1 6 -> 5 2
2 5 -> 3 4
3 4 -> 1 6

8 3にすると
1 8 -> 7 1
2 7 -> 5 2
3 6 -> 3 5

5が被るのでNG

1 7 -> 6 2
2 6 -> 4 4
3 5 -> 2 6

NG

1 6 -> 5 3
2 5 -> 3 5
3 4 -> 1 7

NG

*/


#include <stdio.h>

int main(void) {
  int w;
  int s;
  scanf("%d, %d", &s, &w);
  if(w >= s) {
    printf("unsafe");
  } else {
    printf("safe");
  }
  return 0;
}

Score : 100 points

Problem Statement

There are S sheep and W wolves.

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

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

Constraints

1 \leq S \leq 100

1 \leq W \leq 100

Input

Input is given from Standard Input in the following format:

S W

Output

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

Sample Input 1

4 5

Sample Output 1

unsafe

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

Sample Input 2

100 2

Sample Output 2

safe

Many a sheep drive away two wolves.

Sample Input 3

10 10

Sample Output 3

unsafe


#include<stdio.h>
#include<string.h>
int main(void)
{
  int i, j;
  int n,sum = 0;
  scanf("%d",&n);
  char s[n][10], t[20];
  for(i = 0 ; i < n ; i++){
    scanf("%s", s[i]);
    sum++;
  }
  for(i=1 ; i < n ; i++){
    for(j = 1 ; j < n ; j++){
      if(strcmp(s[j-1], s[j]) > 0){
        strcpy(t, s[j-1]);
        strcpy(s[j-1], s[j]);
        strcpy(s[j], t);
      }
    }
    if(s[i] == s[i+1])
      sum--;
  }
  printf("%d", sum);
  return 0;
}

Score : 300 points

Problem Statement

You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.

How many kinds of items did you get?

Constraints

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

S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print the number of kinds of items you got.

Sample Input 1

3
apple
orange
apple

Sample Output 1

2

You got two kinds of items: apple and orange.

Sample Input 2

5
grape
grape
grape
grape
grape

Sample Output 2

1

Sample Input 3

4
aaaa
a
aaa
aa

Sample Output 3

4


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

int main(void)
{
  int N, counter = 0, count1, kind = 1;
  scanf("%d",&N);

  char S[N][15];
  while(counter < N){
    scanf("%s",S[counter]);
    counter++;
  }

  for(count1 = 0; count1 < N; count1++){
    printf("%s\n",S[count1]);
  }

  for(count1 = 1; count1 < N; count1++){
    if(strcmp(S[0],S[count1]) != 0){
        kind++;
    }
  }

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

  return 0;
}


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

int cmp(const void *a, const void *b){
    char *left_char = (char *)a;
  char *right_char = (char *)b;
  return strcmp(left_char, right_char);
}

int main(void){
    int n;
    char s[200005][10];
    int dif=1;
    scanf("%d",&n);

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

    qsort(s,n,sizeof(char)*10,cmp);

    for(int i=1;i<n;i++){
        if(strcmp(s[i-1],s[i])!=0){dif++;}
    }
    printf("%d\n",dif);
    return 0;
}


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

static int compareFunction(const void *lhs, const void *rhs) {
  // 昇順(char)
  return strcmp(lhs, rhs);
}

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

  char kind[amount][11];
  for (int i = 0; i < amount; i += 1) {
    scanf("%s", *(kind + i));
  }
  // ソートして同じ種類のものを固める
  qsort(kind, amount, sizeof(*kind), compareFunction);

  // 1つ目の種類に関しては絶対カウント1するので1から始める
  // 同じので固まっていても違うものが出てきて初めてインクリメントなのでこれでOK
  // たとえ全部同じでも1が正解だし
  int output = 1;

  // index + 1 との比較になるため、i < amount - 1 が条件
  for (int i = 0; i < amount - 1; i += 1) {
    // 並べ替え後の1つ目2つ目...を比較して違っていたらカウントをインクリメント
    if (strcmp(*(kind + i), *(kind + i + 1)) != 0) {
      output += 1;
    }
  }

  printf("%d", output);
  printf("%c", '\n');

  return 0;
}


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

int main(){
    int n,i,j,count=0,tmp=0;
    char s[300000][1000]={};
    char token[1000]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(token);
    for (i=0; i<n; i++) fgets(s[i], sizeof(s[i]), stdin);
    for (i=0; i<n-1; i++) {
        tmp=0;
        for (j=i+1; j<n; j++) {
            if (strcmp(s[j], s[i])==0){
                tmp++;
                break;
            }
        }
        if (tmp==0) count++;
    }
    printf("%d",count);
    return 0;
}


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

static int cmpfunc(const void *lhs, const void *rhs)
{
    return strcmp(lhs, rhs);
}

int main ()
{
  int N;
  scanf("%d",&N);
  char S[N][11];

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

  }
qsort(S, N, sizeof(S[0]), cmpfunc);
 int count = 1;
 for (int i = 0;i<N-1;i++)
 {
 	if (strcmp(S[i],S[i+1])!=0)count++;
 }
  printf("%d",count);

 return 0;
}


#include<stdio.h>

int main(){

    int day;
    int homework;
    int homework_day[10001];
    int i=0;
    int homework_day_ruiseki=0;
    int play=0;

    scanf("%d%d",&day,&homework);

    while(i < homework){
        scanf("%d",&homework_day[i]);
        i++;
    }

    i = 0;

    while(i < homework){
        homework_day_ruiseki += homework_day[i];
        i++;
    }

    play = day - homework_day_ruiseki;

    if(play <= -1)play = -1;

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

    return 0;
}

Score : 200 points

Problem Statement

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints

1 \leq N \leq 10^6

1 \leq M \leq 10^4

1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or -1.

Sample Input 1

41 2
5 6

Sample Output 1

30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.

Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.

Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9


#include<stdio.h>
int main() {
	int N, M,i,AM;
	int A[1000];

	scanf("%d", &N);
	scanf("%d", &M);
	for (i = 0; i < M; i++) {
		scanf("%d",&A[i]);
	}
  for(i=0;i<M;i++){
    AM+=A[i];
    }
  if(AM==0){
    printf("0");
  }

  if(AM>N){
      printf("-1");
  }
  if(AM<N){
    printf("%d",N-AM);
  }
  return 0;
}


#include<stdio.h>
#include<math.h>
int n,m,all,a[10100];
int main(){
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i){
		scanf("%d",&a[i]);
		all+=a[i];
	}
	if(all>n){
		printf("-1");
	}
	else{
		printf("%d",n-all);
	}
	return 0;
}


Score : 300 points

Problem Statement

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

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

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

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

Constraints

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

1 \leq A_i < i

Input

Input is given from Standard Input in the following format:

N
A_2 ... A_N

Output

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

Sample Input 1

5
1 1 2 2

Sample Output 1

2
2
0
0
0

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

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

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

Sample Input 2

10
1 1 1 1 1 1 1 1 1

Sample Output 2

9
0
0
0
0
0
0
0
0
0

Sample Input 3

7
1 2 3 4 5 6

Sample Output 3

1
1
1
1
1
1
0


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

int main()
{
    int N;
    int *A;
    scanf("%d\n", &N);

    A = (int *)malloc((N-1)* sizeof(int));

   int i=0;
   while(scanf("%d",&A[i])==1)
   {
      i++;
    }

   int sum;
   for(int k=1; k<=N; k++)
   {
     sum = 0;
     for(int j=0; j<(N-1); j++)
     {
       if(A[j]==k)
       {
         sum ++;
       }
       else if(A[j]>k)
       {
         break;
       }

     }
     printf("%d\n",sum);
   }

   return 0;
}


#include <stdio.h>

int main(){
    int N, buf;
    scanf("%d", &N);
    int A[300000] = {};
    for(int i=0; i<N-1; i++){
        scanf("%d", &buf);
        A[buf]++;
    }
    for(int i=1; i<=N; i++){
        printf("%d\n", A[i]);
    }
    return 0;
}


#include <stdio.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)
#define INF (long long int)(9223372036854775807)
#define IINF (int)(2147483647)

int n, a, s[200000];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &a);
    s[a - 1]++;
  }
  for (int i = 0; i < n; i++) {
    printf("%d\n", s[i]);
  }
}


#include<stdio.h>

int main(void)
{
  long long int n,k,sum1=0,sum2=0,sum3=0,i,j;

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

  for(i=k;i<=n;i++){

    sum1 = i*(i-1)/2;

    sum2 = i*(2*n-i+1)/2;

    sum3+=(sum2-sum1+1);
  }

  printf("%lld", sum3%1000000007);

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

long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[524288];
long long invfact[524288];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<524288;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[524287]=modular_inverse(factorial[524287]);
  for(i=524286;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

int main(void){
  cfact();
  long long i,j,n,m,k,a[524288],b,c,h,w,r=0,l,t;
  long long st,fi;
  scanf("%lld%lld",&n,&k);
  for(i=k;i<=n+1;i++){
    st=llsankaku(i-1);
    fi=llsankaku(n)-llsankaku(n-i);
    //printf("%lld %lld\n",st,fi);
    r+=(fi-st)+1;
    r%=mod;
  }
  printf("%lld\n",r);
  return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
typedef long long ll;
int compare_int(const void* a, const void* b){
		return *(int*)b - *(int*)a;
}

int LorR(ll left, ll right, ll n) {
	if (right +left >= n*2) { return 1; }
	else { return 0; }//遠い方を指す
}

int main() {
	ll i, n, l, r, a[2020][2];//活発度,元々いた座標
	ll ans=0;
	for (i = 0; i < 2020; i++) { a[i][0] = 0; a[i][1] = 0; }
	scanf("%lld", &n);
	for (i = 1; i <= n; i++) {
		a[i][1] = i;
		scanf("%lld", &a[i][0]);
	}
	qsort(a, n, sizeof(a[0]), compare_int);
	l = 0; r = n+1;
	for (i = 1; i <= n; i++) {
		if (LorR(l, r, a[i][1]) == 1) {
			ans += a[i][0] * (r - 1 - a[i][1]);
			r--;
		}
		else {
			ans += a[i][0] * (a[i][1] - l + 1);
			l++;
		}
	}
	printf("20", ans);
}

Score : 500 points

Problem Statement

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

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

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

Find the maximum total happiness points the children can earn.

Constraints

2 \leq N \leq 2000

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum total happiness points the children can earn.

Sample Input 1

4
1 3 4 2

Sample Output 1

20

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

Sample Input 2

6
5 5 6 1 1 1

Sample Output 2

58

Sample Input 3

6
8 6 9 1 2 1

Sample Output 3

85


#include<stdio.h>

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

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    if(i%3==0);
    else if(i%5==0);
    else if(i%15==0);
    else
      sum=sum+i;
  }

  printf("%d",sum);

  return 0;
}

Score : 200 points

Problem Statement

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

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

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

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

If none of the above holds, a_i=i.

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

Constraints

1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

15

Sample Output 1

60

The first 15 terms of the FizzBuzz sequence are:

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

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

Sample Input 2

1000000

Sample Output 2

266666333332

Watch out for overflow.


#include <stdio.h>
int main(void){
  int n,i;
  long num=0;
  scanf("%d",&n);
 for(i=1;i<=n;i++){
   if(i%3!=0 && i%5!=0)
     num=i+1;
 }
  printf("%ld\n",num);
  return 0;
}


#include <stdio.h>
signed main(){
    int N;
    int i;
    long long sum=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++){
        if(i%3!=0){
            if(i%5!=0){
              sum+=i;
            }
        }
    }
    printf("%lld\n",sum);
    return(0);
}


#include <stdio.h>

int main (){
  long int N,Fizz, Buzz, FizzBuzz, sum;
  scanf("%d",&N);
  Fizz = 3*(N/3)*(N/3 + 1)/2;
  Buzz = 5* (N/5)*(N/5 + 1)/2;
  FizzBuzz = 15 * (N/15) * (N/15 + 1)/2;
  sum = N*(N+1)/2-Fizz-Buzz+FizzBuzz;
  printf("%d",sum);
  return 0;
}


#include<stdio.h>

int main(void)
{
    int i,N;

    scanf("%d",&N);
    long long a=0;
    for(i=1;i<=N;i++){
        if((i%3!=0)&&(i%5!=0)) a+=i;}
    printf("%lld\n",a);
    return 0;
}


#include<stdio.h>
int main(void){
  long int sc,loop,n;
  long int sum;
  scanf("%ld",&sc);
  sum=0;
  for(loop=1;loop<=sc;loop++){
    n=loop;
      if(loop%3==0 || loop%5==0 || loop%15==0){
          n=0;
      }
      sum+=n;
  }
  printf("%ld",sum);
  return 0;
}


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

    long long int N,i,sum=0;
    scanf("%lld",&N);
    for(i=0;i<=N;i++){

        if(i%3 == 0 || i%5 == 0){
            sum += i;
        }

    }
    printf("%lld\n",sum);

    return 0;

}


#include <stdio.h>

int main(){
   int i,n;
   long s;

   scanf("%d",&n);
   s=0;
   for (i=1;i<=n;i++)
   if (i%3==0 || i%5==0) continue;
   else                  s+=i;
   printf("%ld\n",s);
   return 0;
}


#include <stdio.h>

typedef unsigned long long int ULLI;

int main()
{
	int n;
	ULLI sum = 0;

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		if (i % 15 != 0 && i % 5 != 0 && i % 3 != 0)
			sum += i;
	}

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

	return 0;
}


 #include<stdio.h>
 int main(void)
 {
     int N,K,s,t;
     scanf("%d%d",&N,&K);
     if(N%K==0) printf("0\n");

     if(N%K!=0){
      while(N>K)
       N+=-K;

     if(N<K-N) printf("%d\n",N);
     else    printf("%d\n",K-N);
     }

     return 0;
 }

Score : 300 points

Problem Statement

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

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

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

Constraints

0 ≤ N ≤ 10^{18}

1 ≤ K ≤ 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

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

Sample Input 1

7 4

Sample Output 1

1

Initially, N=7.

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

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

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0


#include <stdio.h>
long chan(long a,long b){
    if (a > b)
    {
        return a - b;

    }
    else
        return b - a;
}

int main()
{
    long a, b,c;
    scanf("%ld %ld", &a, &b);
    if(b==1){
        a = 1;
    }
    else if (a>chan(a, b)){
        while (1)
        {
            c = chan(a, b);
            if(c>=a)
                break;
            else
                a = c;
        }
    }
    if(a==b)
        a = 0;
    printf("%ld\n", a);
}


#include<stdio.h>
int main(){
    int k, head = 1, tail = 10;
    long long x, p, queue[k + 1];
    for(int i = 1; i < 10; i++) queue[i] = i;
    scanf("%d",&k);
  	if (k < 10){
      printf("%d\n",k);
      return 0;
    }
    while (tail <= k){
        x = queue[head++];
        p = x % 10;
        if (p != 0) queue[tail++] = 10 * x + p - 1;
        queue[tail++] = 10 * x + p;
        if (p != 9) queue[tail++] = 10 * x + p + 1;
    }
    printf("%lld\n",queue[k]);
    return 0;
}

Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.


#include<stdio.h>
#define N_MAX 200000

int hantei(long a,long b[],long c){
  for(long y=0;y<c;y++){
    if(b[y]==a)return 0;
  };
  return 1;
};

int main(){
  int magic=1;
  long N,K,C,m,p=0;
  char kago;
  char S[N_MAX]={};
  long hako[N_MAX]={};
  scanf("%ld %ld %ld",&N,&K,&C);
  scanf("%s",S);
  for(long a=0;a<N;a++){
    if(magic==0){
      if(hantei(a,hako,K))continue;
    };
    printf("%ld日目を検査中\n",a+1);
    kago=S[a];
    S[a]='x';
    m=0;
    while(m<=K){
      if(m==K){
        if(magic)magic--;
        break;
      };
      if(p>N-1){
        printf("%ld\n",a+1);
        break;
      }
      else if(S[p]=='o'){
       if(magic)hako[m]=p;
        p+=C+1;
        m++;
      }
      else if(S[p]=='x'){
        p++;
      };
    };
    S[a]=kago;
    p=0;
  };
};

Score : 500 points

Problem Statement

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

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

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

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

Find all days on which Takahashi is bound to work.

Constraints

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

1 \leq K \leq N

0 \leq C \leq N

The length of S is N.

Each character of S is o or x.

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

Input

Input is given from Standard Input in the following format:

N K C
S

Output

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

Sample Input 1

11 3 2
ooxxxoxxxoo

Sample Output 1

6

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

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

Thus, he is bound to work on Day 6.

Sample Input 2

5 2 3
ooxoo

Sample Output 2

1
5

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

Sample Input 3

5 1 0
ooooo

Sample Output 3

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

Sample Input 4

16 4 3
ooxxoxoxxxoxoxxo

Sample Output 4

11
16


#include <stdio.h>
int main (){
	char kata[5];
	scanf("%s", kata);
	if (kata[2] != kata[3] && kata[4] != kata[5]){
		printf("No");
	}
	else {
		printf("Yes");
	}
	return 0;
}

Score : 100 points

Problem Statement

A string of length 6 consisting of lowercase English letters is said to be coffee-like if and only if its 3-rd and 4-th characters are equal and its 5-th and 6-th characters are also equal.

Given a string S, determine whether it is coffee-like.

Constraints

S is a string of length 6 consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S is coffee-like, print Yes; otherwise, print No.

Sample Input 1

sippuu

Sample Output 1

Yes

In sippuu, the 3-rd and 4-th characters are equal, and the 5-th and 6-th characters are also equal.

Sample Input 2

iphone

Sample Output 2

No

Sample Input 3

coffee

Sample Output 3

Yes


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

int main(){

    char S[7];
    scanf("%[a-z ]s", S);

    if(S[2]==S[3] && S[4]==S[5])
        printf("yes");
    else
        printf("no");

return 0;
}


#include<stdio.h>
int main(){
    char S[256];
    scanf("%s",S);
    if(S[2]==S[3]&&S[4]==S[5]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


#include<stdio.h>

int main(void){
    char c[7];
    scanf("%s",c);
    if(c[2] == c[3] && c[4] == c[5]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


#include <stdio.h>

int main(void) {

  int money;
  int i, j;

  scanf("%d", &money);

  i=money/500;
  j=(money%500)/5;

  printf("%d\n", 1000*i+5*j);

  return 0;
}

Score : 200 points

Problem Statement

Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)

Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?

(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)

Constraints

0 \leq X \leq 10^9

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the maximum number of happiness points that can be earned.

Sample Input 1

1024

Sample Output 1

2020

By exchanging his money so that he gets two 500-yen coins and four 5-yen coins, he gains 2020 happiness points, which is the maximum number of happiness points that can be earned.

Sample Input 2

0

Sample Output 2

0

He is penniless - or yenless.

Sample Input 3

1000000000

Sample Output 3

2000000000

He is a billionaire - in yen.


#include <stdio.h>

int main(void)
{

	int K;
	int N;
	int A[100];
	scanf("%d %d",&K ,&N);

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

	printf("%d",K/2);
	return 0;
}

Score : 300 points

Problem Statement

There is a circular pond with a perimeter of K meters, and N houses around them.

The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.

When traveling between these houses, you can only go around the pond.

Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Constraints

2 \leq K \leq 10^6

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

0 \leq A_1 < ... < A_N < K

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K N
A_1 A_2 ... A_N

Output

Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Sample Input 1

20 3
5 10 15

Sample Output 1

10

If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.

Sample Input 2

20 3
0 5 15

Sample Output 2

10

If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.


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

int		main()
{
	int		A, K, N;
	int		*meter;
	int		sum, dis, max, num, i;

	i = 0;
	sum = 0;
	max = 0;
	dis = 0;
	scanf("%d %d\n", &K, &N);
	meter = (int *)malloc(sizeof(int) * (N + 2));
	while (i <= N)
	{
		if (i < N)
			scanf("%d \n", &meter[i]);
		else
			meter[i] = K;
		if (i)
			dis = meter[i] - meter[i - 1];
		if (dis > max)
		{
			max = dis;
			num = i;
		}
		sum += dis;
		i++;
	}
	sum -= meter[num] - meter[num - 1];
	printf("%d\n", sum);
	return (0);
}


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

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

int main()
{
    int k,n,a[200000];

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

    int i,j;

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

    qsort(a,n,sizeof(int),asc);

    long long ans = 0,max = 0;
    for (i = 0; i < n - 1; i++)
    {
        ans += a[i + 1] - a[i];
        if(a[i + 1] - a[i] > max)max = a[i + 1] - a[i];
    }
    ans += k - a[n - 1];
    if(k - a[n - 1] > max)max = k - a[n - 1];

    printf("%lld",ans - max);
}


Score : 400 points

Problem Statement

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

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

There is an edge between Vertex X and Vertex Y.

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

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

Constraints

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

1 \leq X,Y \leq N

X+1 < Y

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

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

Sample Input 1

5 2 4

Sample Output 1

5
4
1
0

The graph in this input is as follows:

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

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

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

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

Sample Input 2

3 1 3

Sample Output 2

3
0

The graph in this input is as follows:

Sample Input 3

7 3 7

Sample Output 3

7
8
4
2
0
0

Sample Input 4

10 4 8

Sample Output 4

10
12
10
8
4
1
0
0
0


#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

typedef struct List {
	struct List *next;
	int v, size, id;
	long long count;
} list;

list *adj[200001] = {}, e[400001];
long long fact[200001], fact_inv[200001];

long long recursion(int k)
{
	if (e[k^1].count > 0) return e[k^1].count;
	else e[k^1].count = 1;

	int u = e[k].v, w = e[k^1].v, tmp;
	list *p;
	for (p = adj[u]; p != NULL; p = p->next) {
		if (p->v == w) continue;
		recursion(p->id);
		e[k^1].size += e[(p->id)^1].size;
	}
	for (p = adj[u], tmp = e[k^1].size; p != NULL; p = p->next) {
		if (p->v == w) continue;
		e[k^1].count = e[k^1].count * e[(p->id)^1].count % Mod * fact[tmp] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[tmp - e[(p->id)^1].size] % Mod;
		tmp -= e[(p->id)^1].size;
	}
	e[k^1].size++;
	return e[k^1].count;
}

int main()
{
	int i, N, u, w;
	scanf("%d", &N);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].count = 0;
		e[i*2+1].count = 0;
		e[i*2].size = 0;
		e[i*2+1].size = 0;
		e[i*2].id = i * 2;
		e[i*2+1].id = i * 2 + 1;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}

	int flag[200001] = {}, q[200001], head, tail;
	long long ans[200001], tmp;
	list *p;
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	for (head = 0, tail = 1, q[0] = 1, flag[1] = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u], ans[u] = 1, tmp = N - 1; p != NULL; p = p->next) {
			ans[u] = ans[u] * recursion(p->id) % Mod * fact[tmp] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[tmp - e[(p->id)^1].size] % Mod;
			tmp -= e[(p->id)^1].size;
			if (flag[p->v] == 0) {
				flag[p->v] = 1;
				q[tail++] = p->v;
			}
		}
		for (p = adj[u]; p != NULL; p = p->next) {
			if (p->count == 0) {
				p->count = div_mod(ans[u], e[(p->id)^1].count * fact[N-1] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[N-1-e[(p->id)^1].size], Mod);
				p->size = N - e[(p->id)^1].size;
			}
		}
	}
	for (i = 1; i <= N; i++) printf("%lld\n", ans[i]);
	fflush(stdout);
	return 0;
}

Score : 600 points

Problem Statement

We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:

Consider writing a number on each vertex in the tree in the following manner:

First, write 1 on Vertex k.

Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:

Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.

Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).

Constraints

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

1 \leq a_i,b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

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

Sample Input 1

3
1 2
1 3

Sample Output 1

2
1
1

The graph in this input is as follows:

For k=1, there are two ways in which we can write the numbers on the vertices, as follows:

Writing 1, 2, 3 on Vertex 1, 2, 3, respectively

Writing 1, 3, 2 on Vertex 1, 2, 3, respectively

Sample Input 2

2
1 2

Sample Output 2

1
1

The graph in this input is as follows:

Sample Input 3

5
1 2
2 3
3 4
3 5

Sample Output 3

2
8
12
3
3

The graph in this input is as follows:

Sample Input 4

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

Sample Output 4

40
280
840
120
120
504
72
72

The graph in this input is as follows:


#include<stdio.h>

int main(){
  int n,m;

  scanf("%d %d",&n, &m);
  printf("%d\n", (n+m)*(n+m-1)-n*m);
  return 0;
}

Score : 100 points

Problem Statement

We have N+M balls, each of which has an integer written on it.

It is known that:

The numbers written on N of the balls are even.

The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.

It can be shown that this count does not depend on the actual values written on the balls.

Constraints

0 \leq N,M \leq 100

2 \leq N+M

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

2 1

Sample Output 1

1

For example, let us assume that the numbers written on the three balls are 1,2,4.

If we choose the two balls with 1 and 2, the sum is odd;

If we choose the two balls with 1 and 4, the sum is odd;

If we choose the two balls with 2 and 4, the sum is even.

Thus, the answer is 1.

Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL i,ans=1,a;
  char S[110]={0};
  scanf("%s",S);
  a=strlen(S);
  rep(i,(a-1)/2){
    if(S[i]!=S[(a-1)/2-i-1])ans=0;
    if(S[a-1-i]!=S[(a-1)/2+1+i])ans=0;
  }
  rep(i,a){
    if(S[i]!=S[a-1-i])ans=0;
  }
  YN(ans);

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

Score : 200 points

Problem Statement

A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:

S is a palindrome.

Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome.

The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome.

Determine whether S is a strong palindrome.

Constraints

S consists of lowercase English letters.

The length of S is an odd number between 3 and 99 (inclusive).

Input

Input is given from Standard Input in the following format:

S

Output

If S is a strong palindrome, print Yes;
otherwise, print No.

Sample Input 1

akasaka

Sample Output 1

Yes

S is akasaka.

The string formed by the 1-st through the 3-rd characters is aka.

The string formed by the 5-th through the 7-th characters is aka.
All of these are palindromes, so S is a strong palindrome.

Sample Input 2

level

Sample Output 2

No

Sample Input 3

atcoder

Sample Output 3

No