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

#define mod 1000000007
#define limit 200001
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i = 0; i < n; i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
int up_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_int(const void *a, const void *b){return *(int*)b - *(int*)a;}
int up_char(const void *left, const void *right) {return strcmp((char *)left,(char *)right);}

int main(){
    int n,m,i,j,count=0;
    int h[100001];
    int a[100001];
    int b[100001];
    int flag[100001] = {0};

    scanf("%d %d",&n,&m);
    for(i = 1; i <= n; i++) scanf("%d",&h[i]);
    for(i = 1; i <= m; i++) scanf("%d %d",&a[i],&b[i]);

    for(i = 1; i <= m; i++){
        if(h[a[i]] > h[b[i]]){
            flag[b[i]]--;
//            printf("%d is bad\n",b[i]);
        }else if(h[a[i]] == h[b[i]]){
            flag[a[i]]--;
            flag[b[i]]--;
//            printf("%d and %d are bad\n",a[i],b[i]);
        }else{
            flag[a[i]]--;
//            printf("%d is bad\n",a[i]);
        }
    }
    for(i = 1; i <= n; i++){
        if(flag[i] == 0){
            count++;
//            printf("%d is good tower!\n",i);
        }
    }
//    for(i = 1; i <= n; i++) printf("%d ",flag[i]);
    printf("%d\n",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


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

Submitted source-code file size, in bytes.

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

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


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

typedef struct tagListNode {
  int H;     /* 高さ */
  int flag;	//goodなら1、badなら0
} SKY;

int main(void){
	SKY *S;
	int N,M,A,B;
	int i,ans;
	char str[100000];

	fgets(str, sizeof(str), stdin);
	N=atoi(strtok(str," "));
	M=atoi(strtok(NULL," "));

	S=(SKY*)calloc(N,sizeof(SKY));

	fgets(str, sizeof(str), stdin);
	S[0].H=atoi(strtok(str," "));
	S[0].flag=1;
	for(i=1;i<N;i++){
		S[i].H=atoi(strtok(NULL," "));
		S[i].flag=1;
	}

	for(i=0;i<M;i++){
		fgets(str, sizeof(str), stdin);
		A=atoi(strtok(str," "))-1;
		B=atoi(strtok(NULL," "))-1;
		if(S[A].H < S[B].H ){
			S[A].flag=0;
		}else{
			S[B].flag=0;
		}
	}

	ans=0;
	for(i=0;i<N;i++){
		if(S[i].flag == 1)ans++;
	}

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

	free(S);

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 1000000000
typedef long long ll;
ll ans[400]={0};
ll cal5(ll a){
    if(ans[a+200]==0) return ans[a+200] = a*a*a*a*a;
    else return ans[a+200];
}

int main(){
    ll X;
    scanf("%lld",&X);
    for(ll i=0;cal5(i)<=MAX;i++){
        for(ll j=0;cal5(i)-cal5(j)<=MAX;j++){
            if(cal5(i)-cal5(j)==X){
                printf("%lld %lld",i,j);
                return 0;
            }
        }
    }
    for(ll i=0;cal5(i)<=MAX;i++){
        for(ll j=0;cal5(i)-cal5(j)<=MAX;j--){
            if(cal5(i)-cal5(j)==X){
                printf("%lld %lld",i,j);
                return 0;
            }
        }
    }

}

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>

int	calc(int a, int b)
{
  	return (a*a*a*a*a - b*b*b*b*b);
}

int	main(void)
{
  	long long	x;
  	int a;
  	int b;

  	scanf("%lld", &x);

  	for (a = -1280; a <= 1280; a++)
      	for (b = -1280; b <= 1280; b++)
		  	if (x == calc(a, b))
            {
                printf("%d %d", a, b);
                return (0);
            }

  	return (0);
}


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

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

   if(k==1){
      printf("OK");
   }else if(a%k==0 || b%k==0){
      printf("OK");
   }else if(a/k==b/k){
      printf("NG");
   }else{
      printf("OK");
   }
   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(){
    int K;
    int A;
    int B;
    scanf("%d\n",&K);
    scanf("%d %d",&A,&B);
    if (A%K==0) {
        printf("OK\n");
    }
    if (A%K!=0) {
        while(A%K>=0){
            if(A>B){
            printf("NG\n");
                break;
            }
            if (A%K==0) {
                printf("OK\n");
                break;
              }
            A=A+1;
        }
    }
  return 0;
}


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

    int value = 0;

    int min = 0;

    int max = 0;

    char str[1000];

    scanf("%d%*c",&value);

    fgets(str,sizeof(str),stdin);

    sscanf(str,"%d %d",&min,&max);

    for (int i = min; i <= max; i++) {

        if (i % value == 0) {

            printf("%s\n","OK");

            return 0;

        }

    }

    printf("%s\n", "NG");

    return 0;
}


#include <math.h>
#include <stdio.h>
#include <string.h>
long long a;
double n = 100;
int count = 0;
int main(void) {
    scanf("%lld", &a);
    while (1) {
        n = n * 1.01;
        count++;
        if (n >= a) {
            printf("%d\n", count);
            break;
        }
    }
}

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>
int main(void){
  int x,a=100;
  int i=0;
  scanf("%ld",&x);
  while(a<x){
  a*=1.01;
  i++;
  }
  printf("%d",i);
  return 0;
 }


#include<stdio.h>
#include<math.h>
int main(void) {
	int i, X, kane = 100;

	scanf("%d", &X);

		for (i = 0; X>kane; i++) {
			kane = kane + kane/100;
		}

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

	return 0;
}


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

int main() {
        unsigned long long int X;
        int i;
        scanf("%lld", &X);

        i = 1;
        while(1) {
                if(powl(1.01, i) * 100 >= X) {
                        printf("%d\n", i);
                        return 0;
                }
                i++;
        }

        return 0;
}


#include <stdio.h>

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

  int a = 100;
  int i = 0;
  for(i = 0 ; i < 10e30;i++){
    if(a >= X){
      printf("%d",i);
      break;
    }
    a = a * 1.01;
  }

  return 0;
}


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


int main()
{
    long long int a,b,n;
    scanf("%lld %lld %lld",&a,&b,&n);
    if(a*b>0) printf("%lld",(a*n/b)-(a*(n/b)));
    if(a*b<0) printf("0");
    //if(a*b<0&&n>b) printf("%d",(a*(n/b))-(a*n/b));
}

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>
int main ()
{
     int S, W;
     scanf ("%d%d",&S,&W);
     if ( W>=S) {
             printf ("unsafe\n");
      }
      else  {
           printf ("safe\n");
      }
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>
int main()
{
     long long s,w;
    while(scanf("%lld %lld",&s,&w)!=EOF)
    {
        if(w>=s)
        {
            printf("unsafe\n");
            }
        else
        {
            printf("safe\n");
            }
        }
    return 0;
    }


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

int main(){

  int S = 0, W = 0;
  scanf("%d %d", &S, &W);

  if( S <= W ){
    printf("unsafe");
  }
  else{
    printf("safe");
  }

  return 0;
}


#include <stdio.h>

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

  if (s <= w) printf("unsafe\n");
  else printf("safe\n");

  return 0;
}


#include <stdio.h>

#define HASH 10007

typedef struct List {
	struct List *next;
	char s[11];
} list;

int hash_string(char* s)
{
	long long x = 0;
	int i;
	for (i = 0; s[i] != 0; i++) {
		x += s[i] - 'a';
		x = x << 5;
	}
	return x % HASH;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int h, i, j, N, count = 0;
	char S[11];
	list *p, *hash[HASH] = {}, d[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", S);
		h = hash_string(S);
		for (p = hash[h]; p != NULL; p = p->next) if (lex_smaller(p->s, S) == 0) break;
		if (p == NULL) {
			count++;
			for (j = 0; S[j] != 0; j++) d[i].s[j] = S[j];
			d[i].s[j] = 0;
			d[i].next = hash[h];
			hash[h] = &(d[i]);
		}
	}
	printf("%d\n", count);
	fflush(stdout);
	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 <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);
    return 0;
}


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

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

int main(void)
{
  int n, i, count = 1;
  char s[11];
  char S[200002][11];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    scanf("%s", S[i]);
  }
  qsort(S, n, 11, compare);
  for (i = 0; i < n - 1; i++)
  {
    if (!(strcmp(S[i], S[i + 1]) == 0))
    {
      count++;
    }
  } /*
    int *result = (int *)bsearch(s, S, count, 11, compare);
    if (result == NULL)
    {
      strcpy(S[count], s);
      count++;
      qsort(S, count, 11, compare);
    }
  }*/
  printf("%d\n", count);
  return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
 int N=0;
 char str[200000][10]={};
 int sum=0;
 int ck=0;
 scanf("%d",&N);

for(int i=0;i<N;i++){
    scanf("%s",str[i]);
}
for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){

        if(strcmp(str[i],str[j])==0){
            ck=1;
            break;
        }else{
        }
        // printf("hikaku%d=%d\n",i,j);
        // printf("%d\n",sum);
    }
    if(ck==0){
        sum=sum+1;
    }
    ck=0;

}
printf("%d",sum);

return 0;

}


#include<string.h>
#include<stdio.h>
int main(){
  long int n,cnt=0;
  char *str[200000][10];
  scanf("%ld",&n);
  for(int i=0;i<n;i++){
    scanf("%s",*str[i]);
  }
  for(int i=0;i<n;i++){
    for(int j=i-1;j>=0;j--){
      if(strcmp(*str[i],*str[j])==0){
        *str[i]='\0';
      }
    }
  }
  for(int i=0;i<n;i++){
    if(*str[i]!='\0')
      cnt++;
  }
  printf("%ld",cnt);
}


#include <stdio.h>

int main(void)
{
  int i, N, M;
  do{
    scanf("%d", &N);
  }while(1<=N && N<=1000000);

  do{
    scanf("%d", &M);
  }while(1<=N && N<=10000);

  int A[M];
  int L = 0;
  for(i=1; i<=M; i++){
    scanf("%d", &A[M]);
    L = L + A[M];
  }
  if(L > N)
    return -1;
  else
    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 dia, tarefa, resultado, count;
    scanf("%d%d\n", &dia, &tarefa);
    while(tarefa>0){
        tarefa -= 1;
        int option;
        scanf("%d", &option);
        count += option;
    }
    if(tarefa==0){
        resultado = dia - count;
    }else if(dia - count < 0){
        printf("-1");
    }
    printf("%d", resultado);
    return 0;
}


#include<stdio.h>
int main(void){
	int N,M,A,i,S=0;
	scanf("%d %d",&N,&M);
	for(i=1;i<=M;i++){
		scanf("%d",&A);
		S=S+A;
	}
	if(S<=N){
		printf("%d",N-S);
	}
	if(S>N){
		printf("-1");
	}
	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>

int main() {

    int n, c;
    scanf("%d", &n);
    int v[100005];

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

    }

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

    return 0;
}


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

int main(){
    unsigned long long sum=0;
    int n,k,i;
    char token[1000]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(strtok(token, " "));k=atoi(strtok(NULL, " "));
    for (i=k; i<=n+1; i++) {
        sum+=n*i-i*(i-1)+1;
        sum%=1000000007;
    }
    printf("%lld",sum%1000000007);
    return 0;
}


#include <stdio.h>
int main(){
int num;
scanf("%d",&num);
long long int ans=0;
for (int i=0;i<num;i++){
	if(i%3!=0&&i%5!=0){
	ans+=i;
	}
	else{

	}
}
printf("%lld",ans);
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.


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


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


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


#include<stdio.h>
int main(void) {
	int N,i,ans;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		if ((N % 3 == 0) || (N % 5 == 0)) {

		}
		else {
			ans = ans + i;
		}
	}
	printf("%d", ans);
	return 0;
}


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


#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int i, N;
  long long sum = 0;
  unused = scanf("%d", &N);

  for(i=0; i<N; i++){
    if(i%3!=0 && i%5!=0) sum += i;
  }
  printf("%lld", sum);

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef long long ll;
//#define p 1000000007

ll modpow(ll a,ll b,ll c)
{
  ll re=1;
  while(b>=1){
    if(b&1) re=re*a%c;
    a=a*a%c;
    b=b>>1;
  }

  return re;
}
void main(void)
{
  ll N,K,ans=0;
  ll p=1000000007;
  scanf("%lld %lld",&N,&K);
  ll T[K+1];
  for(ll i=K;i>=1;i--){
    T[i]=modpow((K/i),N,p);
    for(ll j=2;j<=(K/i);j++){
      T[i]-=T[i*j];
    }
  }

  for(ll i=i;i<=K;i++){
    ans+=(i*T[i])%p;
  }

  printf("%lld",ans);

}

Score : 500 points

Problem Statement

Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive).

There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.

Since this sum can be enormous, print the value modulo (10^9+7).

Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7).

Sample Input 1

3 2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

3 200

Sample Output 2

10813692

Sample Input 3

100000 100000

Sample Output 3

742202979

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


#include <stdio.h>

int main()
{
    unsigned long long int n, k;
    long long int tmp;
    int end;

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

    if (k == 1)
        n = 0;
    else {
        do {
            end = 0;
            tmp = n - 10000 * k;
            if (tmp > 0) {
                n = tmp;
                end = 1;
            }
        } while (end == 1);

        do {
            end = 0;
            tmp = (long long int)(n - k);
            if (tmp < 0)
                tmp *= -1;
            if (tmp < n) {
                n = (unsigned long long)tmp;
                end = 1;
            }
        } while (end == 1);
    }

    printf("%llu\n", 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>
int main(void)
{
  int n,k,m;
  scanf("%d",&n);
  scanf("%d",&k);
  n=n%k;
  m=n-k;
  if(m<0)
    m=-m;
  if(m<n)
    n=m;
  printf("%d",n);

  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define LINE_BUF_SIZE  1024

int main(void) {

  int i;
  long long int N,K;
  long long int t = 0;

  scanf("%lld %lld",&N,&K);
  t = N % K;
  if(t >= K - t){
      printf("%lld",K - t);
   }else{
      printf("%lld",t);
   }
  return 0;
}


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

int main(){
  int n, k;
  scanf("%d%d", &n, &k);
  int a, b;
  a = n % k;
  b = k - a;
  printf("%d\n", min(a, b));
}


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

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

        long long int tmp;
        while (1){
                tmp = n;
                n = abs(n-k);
                if (n >= tmp) {
                        n = tmp;
                        break;
                }
        }

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


#include<stdio.h>

int main(void)
{
    long long n,k;
    long long t=0;
    long long ans=0;

    scanf("%lld %lld",&n,&k);
    // printf("n=%lld k=%lld\n",n,k);

    t=n%k;
    // printf("t=%lld\n",t);

    if (t==0){
        ans=0;
    }else if (n<k){
        if ((k-n)<n)
            ans=k-n;
        else
            ans=n;
    }else{
        ans=k-t;
    }

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

}


#include <stdio.h>

long long gcd(long long a,long long b){long long r,tmp;if(a < b){tmp = a;a = b;b = tmp;}r = a % b;while(r != 0){a = b;b = r;r = a % b;}return b;}
long long lcm(long long a,long long b){long long r;r = gcd(a,b);r = a / r * b;return r;}

int main()
{
    long long n,k;

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

    printf("%lld",gcd(n,k));
}


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

#define max 100

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

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

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

    a=n%k;
    b=k-(n%k);

    if (a>b) {
        a=b;
    }

    printf("%lld", a);

    return 0;
}


#include<stdio.h>
long long abc(long long a,long long b)
{   long long c;
    c=a-b;
    if(c<0) c=-c;
    return c;
}
int main()
{  long long n,k,n1;
   int f=1;
   scanf("%lld%lld",&n,&k);
   if(n==0) printf("%lld",k);
   else if(k==1||k==n) printf("0");
   else
   {  if(n>k) n=n%k;
      else n=k%n;
      n1=n;
	  while(f)
      {
        n=abc(n,k);
        if(n1>n) n1=n;
        else
	    {  printf("%lld",n1);
	       f=0;
	    }
      }
   }
}


#include <stdio.h>

int main(){
	long long n, k, a, dummy;
	scanf("%lld %lld",&n,&k);
	a = n%k;
	dummy = a-k;
	if(dummy<0) dummy*=-1;
	if(dummy<a) printf("%lld",dummy);
	else printf("%lld",a);
}


#include<stdio.h>
#define enQue(x) (x*10 + (x%10))

long long int hoge(int k){
  long long int num;
  int i,j;
  long long int lunNum[k];
  if(k < 10) return k;
  for( i =0;i<9;i++){
    lunNum[i] = i+1;
  }
  i = 0;
  j = 9;
  while(j < k){
    num = lunNum[i];

    if(num % 10 != 0){
      lunNum[j] = enQue(num)-1;
      j++;
    }

    lunNum[j] = enQue(num);
    j++;

    if(num % 10 != 9){
      lunNum[j] = enQue(num)+1;
      j++;
    }
    i++;
  }
  return lunNum[k-1];
}

int main(){
  int k;
  scanf("%d",&k);
  printf("%lld",hoge(k));
}

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>

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

  long k = 2;
  long cnt = 0;
  long tmp;

  while (k < n)
  {
    tmp = n;
    if (tmp == 1)
    {
      cnt++;
    }
    else if (tmp % k == 0)
    {
      tmp = tmp / k;
    }
    else
    {
      tmp = tmp - k;
    }
    k++;
  }

  printf("%ld", cnt);
  return 0;
}

Score : 600 points

Problem Statement

Given is a positive integer N.

We will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.

Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K.

In how many choices of K will N become 1 in the end?

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of choices of K in which N becomes 1 in the end.

Sample Input 1

6

Sample Output 1

3

There are three choices of K in which N becomes 1 in the end: 2, 5, and 6.

In each of these choices, N will change as follows:

When K=2: 6 \to 3 \to 1

When K=5: 6 \to 1

When K=6: 6 \to 1

Sample Input 2

3141

Sample Output 2

13

Sample Input 3

314159265358

Sample Output 3

9


#include <stdio.h>
#include <stdlib.h>
int main(){
  int N;
  int K;
  int i = 0;
  scanf("%d", &N);
  for(K = 2; K <= N; ++K){
  	while(N > K){
    	if (N % K == 0){
          N = N/K;
        }
      	else{
          N = N - K;
        }
    }
    if(N = 1){
      i = i + 1;
    }
  }
  printf("%d", i);
  return 0;
}


#include<stdio.h>
int main(){
    char s[6],a,b,c,d;
    scanf("%s",s);
    a=s[2];b=s[3];c=s[4];d=s[5];
    if(c==d && a==b){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    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>

int main(void)
{
    int i = 0;
    char c[100];
    while (i<6)
    {
        scanf("%c",&c[i]);
        i++;
    }
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 a, b, c, d;
  printf("所持金：");
  scanf("%d",&a);
  b=a/500;
  c=a-b;
  d=c/5;
  printf("%d\n",b*1000+d*5);
  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(){
  long long n; scanf("%lld",&n);
  long long a = n/500;
  long long b = (n%500)/5;
  printf("%lld\n",a*100+b*5);
  return 0;
}


#include <stdio.h>

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

  if(n>=500){
      q=n/500;
      aux= n%500;
      printf("%d\n", q*1000+ 5*(aux/5) );
      return 0;
  }
  else{
    q=n/5;
    printf("%d\n", q*5);
  }
  return 0;
}


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

int main() {
  int x;
  scanf("%d", &x);
  long ans = 0;
  ans += 1000 * (x/500);
  x %= 500;
  ans += 5 * (x/5);
  printf("%ld\n", ans);
  return 0;
}


#include<stdio.h>

int count(int ver_num, int X, int Y, int k)
{
  int cnt = 0;
  int i, j, l, short_num;

  for(i = 0; i < ver_num - k; i++)
  {
    short_num = 1 + ver_num - Y;
    cnt++;

    for(j = 1; j <= k - 1; j++)
    {
      if((i + j) == X)
      {
        l = short_num - j;
        if(l > 0)
          cnt++;
      }
    }

    if(i == X)
    {
      l = short_num - k;
      if(l > 0)
          cnt++;
    }
  }

  return cnt;
}

int main()
{
  int ver_num, X, Y;
  int i, n;

  scanf("%d %d %d", &ver_num, &X, &Y);

  for(i = 1; i < ver_num - 1; i++)
  {
    n = count(ver_num, X, Y, i);
    printf("%d\n", n);
  }
}

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>

int main(){

double L;
  double l;
  scanf("%d",&L);
  l=L*L*L/27;

  printf("%f",l);

}

Score : 300 points

Problem Statement

Given is a positive integer L.
Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

Constraints

1 ≤ L ≤ 1000

L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.

Sample Input 1

3

Sample Output 1

1.000000000000

For example, a rectangular cuboid whose dimensions are 0.8, 1, and 1.2 has a volume of 0.96.

On the other hand, if the dimensions are 1, 1, and 1, the volume of the rectangular cuboid is 1, which is greater.

Sample Input 2

999

Sample Output 2

36926037.000000000000


#include <stdio.h>

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

    printf("%lf",(double)(l / 3) * (l / 3) * (l - l * 2 / 3));
}


#include<stdio.h>
int main ()
{
    int num[31],n,i;
    for(i=0;i<31;i++)
    {
        scanf("%d",&num[i]);
    }
    scanf("%d",&n);
    printf("The %d-th element is %d",n,num[n-1]);
    return 0;
}

Score : 100 points

Problem Statement

Print the K-th element of the following sequence of length 32:

1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

Constraints

1 \leq K \leq 32

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the K-th element.

Sample Input 1

6

Sample Output 1

2

The 6-th element is 2.

Sample Input 2

27

Sample Output 2

5

The 27-th element is 5.


#include <stdio.h>
#include <stdlib.h>
int main(int a, char **b) {
	int H, W; scanf("%d %d", &H, &W);
	a = H * ((W + W % 2) / 2) + (W % 2 == 1 ? ((H + H % 2) / 2) : 0);
	printf("%d", a);
	return 0;
}

Score : 200 points

Problem Statement

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

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

r_1 + c_1 = r_2 + c_2

r_1 - c_1 = r_2 - c_2

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

Constraints

1 \leq H, W \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H \ W

Output

Print the number of squares the bishop can reach.

Sample Input 1

4 5

Sample Output 1

10

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

Sample Input 2

7 3

Sample Output 2

11

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

Sample Input 3

1000000000 1000000000

Sample Output 3

500000000000000000


#include <stdio.h>

int main(void) {
    int N,A,B;
    int x,y;
    scanf("%d %d %d", &N, &A, &B);

    x = N/(A+B);
    y = N%(A+B);
    y = y > A ? A : y;

    x = A*x+y;
    printf("%d\n", x);

    return 0;
}

Score : 200 points

Problem Statement

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

Initially, there is no ball placed.

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

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

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

Constraints

1 \leq N \leq 10^{18}

A, B \geq 0

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

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

Sample Input 1

8 3 4

Sample Output 1

4

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

Sample Input 2

8 0 4

Sample Output 2

0

He placed only red balls from the beginning.

Sample Input 3

6 2 4

Sample Output 3

2

Among bbrrrr, there are two blue balls.


#include<stdio.h>
int main(void){
int r,b,n,i;
  scanf("%d%d%d",&n,&b,&r);
  if(b==0||n==b+r){
    printf("%d",b);
    return 0;
  }
  while(1){
    if(n>b+r){
    for(i=0;i<b;i++){
   b++;
      if(b==0||n==b+r) break;
    }
     for(i=0;i<r;i++){
   b++;
      if(n==b+r) break;
    }
    }}
      printf("%d",b);
      return 0;
    }


#include <stdio.h>

int main()
{
  int i, j;
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  int ab = a + b;
  int d = n / ab;
  int e = n % ab;
  if(e >= a){
    printf("%d\n", (d + 1) * a);
  }else{
    printf("%d\n", d * a + e);
  }

  return 0;
}


Score : 300 points

Problem Statement

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

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

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

Constraints

1 \leq A \leq B \leq 100

A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

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

Sample Input 1

2 2

Sample Output 1

25

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

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

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

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

Sample Input 2

8 10

Sample Output 2

100

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

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

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

Sample Input 3

19 99

Sample Output 3

-1

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


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

int main(void)
{
  int A,B,ans;
  double min_A,max_A,min_B,max_B;

  scanf("%d%d",&A,&B);

  min_A = A*12.5;
  min_B = B*10;
  max_A = (A+1)*12.5;
  max_B = (B+1)*10;

  if ((max_A <= min_B) || (max_B <= min_A))
    {
      ans = -1;
    }
  else
    {
      if(ceil(min_A) <= ceil(min_B))
	{
	  ans = min_B;
	}
      else
	{
	  ans = min_A;
	}
    }

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


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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main (){
   //ans * 0.08 = a
   //ans * 0.1 = b
   //ans = 10b
   //10b * 0.08 = a
   int a,b;scanf("%d %d",&a,&b);
   if(10*b*0.08 == a)printf("%d\n",10*b);
   else printf("-1");
   return 0;
}


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

Score : 100 points

Problem Statement

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

At least how many sheets of paper does he need?

Constraints

N is an integer.

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

5

Sample Output 1

3

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

Sample Input 2

2

Sample Output 2

1

Sample Input 3

100

Sample Output 3

50


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


// ABC 157-A
// 2020.3.1 bal4u

#include <stdio.h>

int main()
{
	int N;

	scanf("%d", &N);
	printf("%d\n", (N+1)/2);
	return 0;
}


#include <stdio.h>

int main(void)
{

    int i_inputBingoNum[9];
    int i_repeatNum;
    char c_bingoCheckFlag = 0;
    int i_checkNumFlag[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

    for (int index = 0; index < 9; index++)
    {
        scanf("%d", &i_inputBingoNum[index]);
    }

    scanf("%d", &i_repeatNum);

    int i_inputJudgeNum[i_repeatNum];

    for (int index = 0; index < i_repeatNum; index++)
    {
        scanf("%d", &i_inputJudgeNum[index]);
    }

    for (int index = 0; index < i_repeatNum; index++)
    {
        for (int index2 = 0; index2 < 9; index2++)
        {
            if (i_inputJudgeNum[index] == i_inputBingoNum[index2])
            {
                i_checkNumFlag[index2] = 1;
            }
        }
    }

    if ((i_checkNumFlag[0] == 1 && i_checkNumFlag[1] == 1 && i_checkNumFlag[2] == 1) ||
        (i_checkNumFlag[0] == 1 && i_checkNumFlag[3] == 1 && i_checkNumFlag[6] == 1) ||
        (i_checkNumFlag[0] == 1 && i_checkNumFlag[4] == 1 && i_checkNumFlag[8] == 1) ||
        (i_checkNumFlag[1] == 1 && i_checkNumFlag[4] == 1 && i_checkNumFlag[7] == 1) ||
        (i_checkNumFlag[2] == 1 && i_checkNumFlag[4] == 1 && i_checkNumFlag[6] == 1) ||
        (i_checkNumFlag[2] == 1 && i_checkNumFlag[5] == 1 && i_checkNumFlag[8] == 1) ||
        (i_checkNumFlag[3] == 1 && i_checkNumFlag[4] == 1 && i_checkNumFlag[5] == 1) ||
        (i_checkNumFlag[6] == 1 && i_checkNumFlag[7] == 1 && i_checkNumFlag[8] == 1))
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

}

Score : 200 points

Problem Statement

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

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

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

Constraints

All values in input are integers.

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

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

1 \leq N \leq 10

1 \leq b_i \leq 100

b_i \neq b_j (i \neq j)

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

We will mark nothing.

Sample Input 3

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

Sample Output 3

Yes

We will mark all the squares.


#include <stdio.h>
int main(void){
    int a, b, i;
    scanf("%d%d", &a, &b);
    i = (100 * (10 - a));
    printf("%d", b + i);
}

Score : 100 points

Problem Statement

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

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

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

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

Constraints

All values in input are integers.

1 \leq N \leq 100

0 \leq R \leq 4111

Input

Input is given from Standard Input in the following format:

N R

Output

Print his Inner Rating.

Sample Input 1

2 2919

Sample Output 1

3719

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

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

Sample Input 2

22 3051

Sample Output 2

3051


#include<stdio.h>
int main (){
  int N,R;
  scanf("%d %d",&N,&R);
  if(N>=10)
    printf("%d",R);
  else printf("%d",R+100*(10-N));
  return 0;
  }


/* ex3_3
    nnasy */

#include <stdio.h>

int main(void) {
    int number, baseNumber;    //整数変数の宣言
    scanf("%d %d", &number, &baseNumber);    //number, baseNumberに入力

    int count = 0;    //numberをbaseNumberで割れる回数(=numberをbaseNumber進数にした時の桁数)を表現する整数変数を宣言
    while (number>0){    //割れる回数(=count)を調べる
        number = number/baseNumber;
        count++;
    }
    printf("%d\n", count);    //求める桁数(=count)を出力

    return 0;
}

Score : 200 points

Problem Statement

Given is an integer N. Find the number of digits that N has in base K.

Notes

For information on base-K representation, see Positional notation - Wikipedia.

Constraints

All values in input are integers.

1 \leq N \leq 10^9

2 \leq K \leq 10

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of digits that N has in base K.

Sample Input 1

11 2

Sample Output 1

4

In binary, 11 is represented as 1011.

Sample Input 2

1010101 10

Sample Output 2

7

Sample Input 3

314159265 3

Sample Output 3

18


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

int main(){
    int N,K,i;
    scanf("%d %d",&N,&K);
    for(i=1;N>=pow(K,i);i++){
    }

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

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define BUFSIZE 10000
#include<math.h>
int N,K,m=1;

int cal(int n,int k){
	if(n/k >= k){
		m++;
		cal(n/k,k);
	}else{
		return 0;
	}
}

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

		cal(N,K);
	printf(" %d",m+1);
}


Score : 300 points

Problem Statement

There are N people living on a number line.

The i-th person lives at coordinate X_i.

You are going to hold a meeting that all N people have to attend.

The meeting can be held at any integer coordinate. If you choose to hold the meeting at coordinate P, the i-th person will spend (X_i - P)^2 points of stamina to attend the meeting.

Find the minimum total points of stamina the N people have to spend.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq X_i \leq 100

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print the minimum total stamina the N people have to spend.

Sample Input 1

2
1 4

Sample Output 1

5

Assume the meeting is held at coordinate 2. In this case, the first person will spend (1 - 2)^2 points of stamina, and the second person will spend (4 - 2)^2 = 4 points of stamina, for a total of 5 points of stamina. This is the minimum total stamina that the 2 people have to spend.

Note that you can hold the meeting only at an integer coordinate.

Sample Input 2

7
14 14 2 13 56 2 37

Sample Output 2

2354


#include<stdio.h>
int main()
{
  int t;
	scanf("%d",&t);
	int a[t],i;
	int sum1=0,sum2=0;
	for(i=0;i<t;i++)
	{
	scanf("%d",&a[i]);
	sum1+=a[i]*a[i];
	sum2+=a[i];
    }
    int s;
   if(sum2*1.0/t-sum2/t<=0.5) s=sum2/t;
   else                        s=sum2/t+1;
   printf("%d\n",sum1+t*s*s-2*s*sum2);
}


#include <stdio.h>

int main()
{
  int n, sum = 0, result = 10000000000;
  int i, p;
  int x[100];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x[i]);
  }
  for(p = 1; p < 101; p++){
    for(i = 0; i < n; i++){
      sum += (x[i] - p) * (x[i] - p);
      if(result <= sum){
        break;
      }
    }
    if(result > sum){
      result = sum;
    }
    sum = 0;
  }
  printf("%d\n", result);

  return 0;
}


#include <stdio.h>
#define MOD 1000000007
typedef long long ll;
ll modpow(ll a, ll n) {
	if (n == 0)
		return 1;
	if (n == 1)
		return (a % MOD);
	if (n % 2 == 1)
		return (a * modpow(a, n - 1) % MOD);
	ll t = modpow(a, n / 2);
	return (t * t % MOD);
}
ll comb(ll n, ll r) {
	ll res = 1;
	for (int i = n; i > n - r; i--) {
		res *= i;
		res %= MOD;
	}
	ll y = 1;
	for (int i = 2; i <= r; i++) {
		y *= i;
		y %= MOD;
	}
	y = modpow(y, MOD - 2);
	res = res * y % MOD;
	return res;
}
int main() {
	int n, a, b;
	ll ans = 1;
	scanf("%d%d%d", &n, &a, &b);
	ans = modpow(2, n) - 1 - comb(n, a) - comb(n, b);
	while (ans < 0) {
		ans += MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

Print the count modulo (10^9 + 7).


#include<stdio.h>

int main(void){
   int A,B,C;
   int cnt=0;
   scanf("%d %d %d",&A,&B,&C);
   if(A==B){
      cnt++;
   }
   if(B==C){
      cnt++;
   }
   if(A==C){
      cnt++;
   }
   if(cnt==1){
      printf("Yes");
   }else{
      printf("No");
   }
   return 0;
}

Score: 100 points

Problem Statement

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

A B C

Output

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

Sample Input 1

5 7 5

Sample Output 1

Yes

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

Sample Input 2

4 4 4

Sample Output 2

No

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

Sample Input 3

4 9 6

Sample Output 3

No

Sample Input 4

3 3 4

Sample Output 4

Yes


#include<stdio.h>

void main (void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
   printf(" 配列に入力した値は：%d, %d, %d\n", A, B, C);
  if((A!=B && A!=C &&B!=C) || (A==B && A==C))
    printf("No");
  else
    printf("Yes");
}


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

	    // 文字列の入力
	scanf("%d %d %d",&a, &b, &c);//AB

	if(a==b){
		if(b==c){
			printf("NO\n");
		return 0;
		}
		printf("YES\n");
		return 0;
	}

		else if(a==c){
		printf("YES\n");
		return 0;
	}

	else if(b==c){
		printf("YES\n");
		return 0;
	}

	else{
	printf("NO\n");

	return 0;
	}
}


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


#include <stdio.h>

int main() {
	int n, a;

	scanf("%d", &n);
	while (n--) {
		scanf("%d", &a);
		if (a % 2 == 0 && a % 3 && a % 5) {
			printf("DENIED\n");
			return 0;
		}
	}
	printf("APPROVED\n");
	return 0;
}

Score: 200 points

Problem Statement

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

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

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

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

Notes

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

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

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

Sample Input 1

5
6 7 9 10 31

Sample Output 1

APPROVED

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

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

Sample Input 2

3
28 27 24

Sample Output 2

DENIED

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


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

}


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

int main(){
	int n, i;
	char s[20003][11]={};
	scanf("%d", &n);
	for(i=0;i<n;i++)	scanf("%s", s[i]);

	qsort(s, n, 11, strcmp);

	int nums[20003];
	nums[0]=1;
	for(i=1;i<n;i++){
		if(strcmp(s[i-1], s[i])==0){
			nums[i]=nums[i-1]+1;
		}else{
			nums[i]=1;
		}
	}
	int max=0;
	for(i=0;i<n;i++){
		if(nums[i]>max){
			max=nums[i];
		}
	}

	for(i=0;i<n;i++){
		if(nums[i]==max){
			printf("%s\n", s[i]);
		}
	}

	return 0;
}

Score: 300 points

Problem Statement

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

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

Constraints

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

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

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

Input

Input is given from Standard Input in the following format:

N
S_1
:
S_N

Output

Print all strings in question in lexicographical order.

Sample Input 1

7
beat
vet
beet
bed
vet
bet
beet

Sample Output 1

beet
vet

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

Sample Input 2

8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo

Sample Output 2

buffalo

Sample Input 3

7
bass
bass
kick
kick
bass
kick
kick

Sample Output 3

kick

Sample Input 4

4
ushi
tapu
nichia
kun

Sample Output 4

kun
nichia
tapu
ushi


#include<stdio.h>
#include<string.h>
int main()
{
	char s[100];
	int i,len=0;
	scanf("%s",&s);
	len=strlen(s);
	for(i=0;i<len;i++){
		printf("x");
	}
	printf("\n");
	return 0;
}

Score : 200 points

Problem Statement

Given is a string S. Replace every character in S with x and print the result.

Constraints

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:

S

Output

Replace every character in S with x and print the result.

Sample Input 1

sardine

Sample Output 1

xxxxxxx

Replacing every character in S with x results in xxxxxxx.

Sample Input 2

xxxx

Sample Output 2

xxxx

Sample Input 3

gone

Sample Output 3

xxxx


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

int main()
{
    int i, n;
    char s[100];
    scanf("%s", s);
    n = strlen(s);
    for(i = 0; i < n; i++){
        printf("x");
    }
    printf("\n");
    return 0;
}


#include<stdio.h>
#include<stdbool.h>
int main(){
    int a1[1000]={false};
    int a2[1000]={false};
    int a3[1000]={false};
    int N;
    scanf("%d",&N);
    int a[N];
    bool f=true;
    for(int i=0;i<N;i++){
        scanf("%d",a+i);
        int x= a[i]/1000000;
        int y= (a[i]/1000)%1000;
        int z= a[i]%1000;
        if(a1[x] == true && a2[y] == true && a3[z] == true){
            f = false;
            break;
        }
        a1[x]=a2[y]=a3[z]=true;
    }
    if(f) printf("YES");
    else printf("NO");
    return 0;
}

Score : 300 points

Problem Statement

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

Constraints

2 ≤ N ≤ 200000

1 ≤ A_i ≤ 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

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

Sample Input 1

5
2 6 1 4 5

Sample Output 1

YES

The elements are pairwise distinct.

Sample Input 2

6
4 1 3 1 6 2

Sample Output 2

NO

The second and fourth elements are identical.

Sample Input 3

2
10000000 10000000

Sample Output 3

NO


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

int main(){

int A[200000],N,i=0,i2=0,t;
char st[200000][10],s;

/*数を入力*/
scanf("%d", &N);
if(N<2 || N>200000)return 0;//error
/*文字列入力*/
s=getchar();
while(1){
	if(i2>9 || i>N-1)break;//入力超過
   	st[i][i2]=getchar();
	if(st[i][i2]==' '){st[i][i2]='\n';i++;i2=0;}//次の行に入力
		else if(st[i][i2]=='\n'){break;}//入力終了
		else if(isdigit(st[i][i2])==0)break;//数字以外
		else
		i2++;//入力継続
}
/*文字列を数字に変換*/
for(i=0;i<N;i++){
A[i]=atoi(st[i]);
//printf("%d %s\n",A[i],st[i]);
}
/**バブルソートで昇順にし、同数があればNO表示で終了*/
for(i=0;i<N-1;i++){
	for(i2=N-1;i2>i;i2--){
		if(A[i2]<A[i2-1]){
			t=A[i2]; A[i2]=A[i2-1]; A[i2-1]=t;
		}else if(A[i2]==A[i2-1]){
			printf("NO\n"); return 0;
		}
	}
}

/*配列数を比較し、同じならYes 違うならNo*/
	printf("YES\n");
	return 0;
}


#include <stdio.h>

int main(){
   int n,flag=0;
   int a[200000];
   scanf("%d",&n);
   for(int i = 0;i < n;i++){
      scanf("%d",&a[i]);
   }
   for(int i = 0;i < n;i++){
      for(int j = i + 1;j < n;j++){
         //printf("%d %d\n",a[i],a[j]);
         if(a[i] == a[j]){
            flag = 1;
            break;
         }
      }
      if(flag == 1)break;
   }
   if(flag == 1) printf("No");
   else if(flag == 0) printf("Yes");
}


#include<stdio.h>
int main()
{
  long n,j;
  scanf("%ld",&n);
  long a[n];
  for(long i=0;i<n;i++)
  {
    scanf("%ld",&a[i]);
          }
  for(long i=0;i<n;i++)
  {
		for( j=i+1;j<n;j++)
        {
          if(a[i]==a[j])
          {
            goto skip;
          }
        }
  }
skip:
  printf("NO");
  if(j==n)
    printf("YES");
}


#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 MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#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 lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
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;}

int main(){
  LL N,i,ans=0;
  scanf("%lld",&N);
  LL A[N];
  FOR(i,0,N)scanf("%lld",&A[i]);
  qsort(A,N,sizeof(LL),lcmp);
  FOR(i,0,N-1)if(A[i]==A[i+1]){
    printf("NO");
    return 0;
  }
  printf("YES");

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


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

int main()
{
  int N, K,p[200000];
  double max, tmp, p2[200000];

  scanf("%d %d", &N, &K);

  for(int i=0;i<N;i++)
  {
      scanf("%d", &p[i]);
      p2[i] = (1 + p[i])/2.0;
  }

  max=0.0;
  for(int i=0;i<K;i++)
  {
    max += p2[i];
  }

  tmp = max;
  for(int i=K;i<N-K+1;i++)
  {
	tmp -= p2[i-K];
    tmp += p2[i];

    if (tmp > max) max=tmp;
  }

  printf("%lf", max);

  return 0;
}

Score : 400 points

Problem Statement

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

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

Constraints

1 ≤ K ≤ N ≤ 200000

1 ≤ p_i ≤ 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N

Output

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

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

Sample Input 1

5 3
1 2 2 4 5

Sample Output 1

7.000000000000

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

Sample Input 2

4 1
6 6 6 6

Sample Output 2

3.500000000000

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

Sample Input 3

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

Sample Output 3

32.000000000000


#include<stdio.h>
int main()
{
	int k,n,a[200000],sum=0,max=0;
	scanf("%d %d",&n,&k);
	int i,j;
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<=n-k;i++)
	{
		for(j=i;j<k+i;j++)
		{
			sum+=a[j];
		}
		if(sum>max)
		max=sum;
		sum=0;
	}
	double m;
	m=(max+k)/2.0;
	printf("%lf",m);
}


Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300


#include<stdio.h>

int main(){
    int H, A, c = 0;

    scanf("%d %d", &H, &A);

    while (H > 0) {
        H -= A;
        c++;
    }
    printf("%d\n", c);

	return 0;
}

Score : 100 points

Problem Statement

Serval is fighting with a monster.

The health of the monster is H.

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

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

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

Constraints

1 \leq H \leq 10^4

1 \leq A \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H A

Output

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

Sample Input 1

10 4

Sample Output 1

3

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

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

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

Thus, Serval needs to make three attacks to win.

Sample Input 2

1 10000

Sample Output 2

1

Sample Input 3

10000 1

Sample Output 3

10000


#include<stdio.h>
int main(void){
  int H,A,c;

  if (H%A == 0){
    c = H/A + 1;
  }
  else {
    c = H/A;
  }
  printf("%d",c);

  return 0;
}


#include <stdio.h>

int main()
{
int H,N,sum=0,i,a;
scanf("%d %d",&H,&N);

for(i=1;i<=N;i++)
{
    scanf("%d",&a);
    sum+=a;
}
if(sum>=H)
printf("Yes");
 else
    printf("No");

    return 0;
}

Score : 200 points

Problem Statement

Raccoon is fighting with a monster.

The health of the monster is H.

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

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

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

Constraints

1 \leq H \leq 10^9

1 \leq N \leq 10^5

1 \leq A_i \leq 10^4

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H N
A_1 A_2 ... A_N

Output

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

Sample Input 1

10 3
4 5 6

Sample Output 1

Yes

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

Sample Input 2

20 3
4 5 6

Sample Output 2

No

Sample Input 3

210 5
31 41 59 26 53

Sample Output 3

Yes

Sample Input 4

211 5
31 41 59 26 53

Sample Output 4

No


#include <stdio.h>

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

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

	for (a = 0; a <= n; a++) {
		scanf("%d", &i[a]);
		sum = sum + i[a];//必殺技の合計値を求める
	}

	if (h < sum) //必殺技の合計値より敵の体力が低い場合
	{
		printf("Yes\n");
	}
	else //必殺技の合計値より敵の体力が多い場合
	{
		printf("No\n");
	}

	return 0;
}


#include<stdio.h>
int main(){
    int h,n;
    int a[10000];
    int sum=0;
    scanf("%d %d",&h,&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        sum=sum+a[i];
    }
    if(h<=sum){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


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

int comp(const void * elem1, const void * elem2)
{
	int f = *((int*)elem1);
	int s = *((int*)elem2);
	if (f > s) return -1;
	if (f < s) return 1;
	return 0;
}

int main()
{
	long monsterNumber, specialAttacks, singleMonsterHealth;
	long monsterHealth[200000];
	float attackPower = 0;
	scanf("%d""%d",&monsterNumber, &specialAttacks);

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

	qsort(monsterHealth, sizeof(monsterHealth) / sizeof(*monsterHealth), sizeof(*monsterHealth),comp);

	for (int i = specialAttacks; i < monsterNumber; i++)
	{
		attackPower += monsterHealth[i];
	}

	printf("%f \n", attackPower);

	return 0;
}

Score : 300 points

Problem Statement

Fennec is fighting with N monsters.

The health of the i-th monster is H_i.

Fennec can do the following two actions:

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

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

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

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

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

Constraints

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

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

1 \leq H_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 ... H_N

Output

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

Sample Input 1

3 1
4 1 5

Sample Output 1

5

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

Sample Input 2

8 9
7 9 3 2 3 8 4 6

Sample Output 2

0

She can use Special Move on all the monsters.

Sample Input 3

3 0
1000000000 1000000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.


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

    int N,K;
    scanf("%d %d",&N,&K);
    long long int *h;
    h = (long long int *)malloc(sizeof(long long int)*N);
    for(int i=0;i<N;i++){
        scanf("%ld",&h[i]);
    }
    if(K>=N){
        printf("0");
    }else{
    //long long int tmp;
    for(int i=1;i<N;i++){
        //tmp = h[i];
        if(h[i-1]>h[i]){
            swap(&h[i-1],&h[i]);
        }
    }
    long long int attacktotal = 0;
    for(int i=0;i<N-K;i++){
        attacktotal += h[i];
    }
    if(attacktotal!=0){
        printf("%lld",attacktotal);
    }else{
    	printf("0");
    }
    }
    free(h);
    return 0;
}

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


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

int main()
{
    int n=0,k=0,h[200010];
    long long int i,maxs,counte=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
    }
    if(n<=k)
    {
        printf("%d",0);
    }
    else
    {
        while(k>0)
    {
        maxs=0;
        for(i=1;i<n;i++)
        {
            if(h[i]>maxs)
                maxs=i;
        }
        h[maxs]=0;
        k--;
    }
    for(i=0;i<n;i++)
    {
        counte=counte+h[i];
    }
    printf("%lld",counte);
    }
    return 0;
}


#include<stdio.h>
int main(){
  long long int m,n,k,l,sum=0,temp;
  scanf("%lld %lld",&m,&n);
  long long int a[m];
  if(n>=m){
    printf("0");
  }else{
        for(k=0;k<m;k++){
          scanf("%lld",&a[k]);
        }
        if(n==0){
            l=m-n;
            for(k=0;k<l;k++){
                sum+=a[k];
            }
            printf("%lld",sum);
        }else{
            for(k=0;k<m;k++){
              for(l=0;l<m-1;l++){
                if(a[l]>a[l+1]){
                  temp=a[l];
                  a[l]=a[l+1];
                  a[l+1]=temp;
                }
              }
            }
            l=m-n;
            for(k=0;k<l;k++){
              sum+=a[k];
            }
            printf("%lld",sum);
              }
      }
}


#include<stdio.h>

int main(void)
{
  int N,K,i=0;
  long cnt=0;
  int H[200000] = {0};

  scanf("%d %d",&N,&K);

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

  if(K>=N)
  {
    goto END;
  }
  else if(K == 0)
  {
    for(i=0;i<N;i++)
    {
      cnt += (long)H[i];
    }
    goto END;
  }

END:
  printf("%ld\n",cnt);

  return 0;
}


#include<stdio.h>
int main(void){
    long N,K,x,ans = 0;
    int n,i,j,k,tmp;
    scanf("%ld %ld",&N,&K);
    int H[N];
    for(n=0;n<N;n++){
        scanf("%d",&H[n]);
    }
    for (i=0; i<N; ++i) {
      for (j=i+1; j<N; ++j) {
        if (H[i] > H[j]) {
          tmp =  H[i];
          H[i] = H[j];
          H[j] = tmp;
        }
      }
    }

    if(N<=K){
        ans = 0;
    }else{
        x = N-K;
        for(k=0;k<x;k++){
            ans +=H[k];
        }
    }
    printf("%ld",ans);
    return 0;
}


#include <stdio.h>

int main()
{
	int m;
	int n;
	scanf("%d %d",&m,&n);
	if (m==n){
		printf ("Yes");
	}
	else {
		printf ("No");
	}

	return 0;
}

Score : 100 points

Problem Statement

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

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

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

Determine whether Takahashi's submission gets an AC.

Constraints

1 \leq N \leq 100

0 \leq M \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

3 3

Sample Output 1

Yes

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

Sample Input 2

3 2

Sample Output 2

No

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

Sample Input 3

1 1

Sample Output 3

Yes


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

          printf("Yes\n");

    else

          printf("No\n");

    return 0;
 }


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

}


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


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


#include<stdio.h>
int n,a[10][10],buf,ans=0;

int main(void)
{
    scanf("%d", &n);
    for (int i = 1; i <= n;i++){
        buf = i;
        while(buf>=10)
            buf /= 10;
        a[buf][i % 10]++;
    }
    for (int i = 0; i <10;i++)
        for (int j = 0; j <10;j++)
            ans += a[i][j] * a[j][i];
    printf("%d", ans);
    return 0;
}


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

Score : 200 points

Problem Statement

Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Constraints

1 \leq a \leq 9

1 \leq b \leq 9

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)

Sample Input 1

4 3

Sample Output 1

3333

We have two strings 444 and 3333. Between them, 3333 is the lexicographically smaller.

Sample Input 2

7 7

Sample Output 2

7777777


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


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
    int a,b;
    scanf("%d %d",&a, &b);
    if(b>a){
        int tep = b;
        b=a;
        a=tep;
    }
    for(int i=0;i<a;i++){
        printf("%d",b);
    }
}


#include <stdio.h>

int main(void){

  long n,k,s;
  scanf("%ld %ld %ld", &n, &k, &s);

  long other = s+1;
  if (other > 1000000000) {
    other = 1;
  }

  if (k != 0) {
    printf("%ld", s);
    for (long i = 1; i < k; i++) {
      printf(" %ld", s);
    }
    for (long i = k; i < n; i++) {
      printf(" %ld", other);
    }
  } else {
    printf("%ld", other);
    for (long i = 1; i < n; i++) {
      printf(" %ld", other);
    }
  }

  printf("\n");

  return 0;
}

Score : 400 points

Problem Statement

Given are three integers N, K, and S.

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

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

Constraints

1 \leq N \leq 10^5

0 \leq K \leq N

1 \leq S \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K S

Output

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

A_1 A_2 ... A_N

Sample Input 1

4 2 3

Sample Output 1

1 2 3 4

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

Sample Input 2

5 3 100

Sample Output 2

50 50 50 30 70


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

int main(){
   int n,k,s;
   scanf("%d%d%d", &n,&k,&s);
   for(int i=0;i<n;i++){
     if(s<1000000000){
     	if(i<k){
     		printf("%d", s);
        }else {
            printf("%d", s+1);
        }
      } else{
         if(i<k){
     		printf("%d", s);
        }else {
            printf(1);
        }
      }
      if(i!=n-1){
         	printf(" ");
      }
   }
	return 0;
}


#include<stdio.h>
#include<string.h>
struct tasks
{
    int a,d;
    char c;
    char wa[5],ac[5];

};
int main()
{
    int n,m,a,d;
    char c,wa[5];
    struct tasks task[100005];
    scanf("%d%d",&n,&m);
    int penalty=0,point=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&a);
        scanf("%c",&c);
        task[a].c=c;
        scanf("%s",&task[a].wa);

        if(task[a].wa[0]=='A'&&task[a].ac[0]!='C')
        {
            point++;
            task[a].wa[0]='O';
            strcpy(task[a].ac,"CC");
        }
        else if(task[a].wa[0]=='W'&&task[a].ac[0]!='C')
        {
            penalty++;
        }
    }
    printf("%d %d",point,penalty);
}

Score : 300 points

Problem Statement

Takahashi participated in a contest on AtCoder.

The contest had N problems.

Takahashi made M submissions during the contest.

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

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

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

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

Constraints

N, M, and p_i are integers.

1 \leq N \leq 10^5

0 \leq M \leq 10^5

1 \leq p_i \leq N

S_i is AC or WA.

Input

Input is given from Standard Input in the following format:

N M
p_1 S_1
:
p_M S_M

Output

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

Sample Input 1

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

Sample Output 1

2 2

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

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

Thus, he has two correct answers and two penalties.

Sample Input 2

100000 3
7777 AC
7777 AC
7777 AC

Sample Output 2

1 0

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

Sample Input 3

6 0

Sample Output 3

0 0


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

int N, M, p[100000];
char S[100000][2];

int cmp(const void* a, const void* b){
    return p[*(int*)a]-p[*(int*)b];
}

int partition(int *num, int start,int end, int p){
    int i = start, j = end;
    int temp = 0;
    while(i <= j){
        while(i <= end && num[i] <= p){
            i++;
        }
        while(j >= start && num[j] > p){
            j--;
        }

        if(i > j){
            break;
        }

        temp = num[i];
        num[i] = num[j];
        num[j] = temp;

    }
    return i;
}
void quicksort(int *num, int start, int end){
    if(start == end){
        return ;
    }
    int p = num[start];
    int flg = 0;
    int base = start;
    int k = 0;
    while(base <= end){
        if(num[base] < p){
            flg = 1;
            p = num[base];
            break;
        }else if(num[base] > p){
            flg = 1;
            break;
        }
        base++;
    }

    if(flg == 1){
        k = partition(num, start, end, p);
        quicksort(num, start, k-1);
        quicksort(num, k, end);
    }
}

int main(void){
    scanf("%d %d", &N, &M);
    int i;
    int a[100000];
    for(i=0;i<M;i++){
        scanf("%d %s", &p[i], S[i]);
        a[i] = i;
    }

    qsort(a, M, sizeof(int), cmp);

    int wa=0, ac=0;
    int cut=0;

    for(i=0; i<M; i++){
        if(i!=0){
            if(p[a[i]]!=p[a[i-1]]){
                quicksort(a, cut, i-1);
                cut = i;
            }
        }
    }

    quicksort(a, cut, M-1);

    int flg=0;

    if(S[a[0]][0]=='W'){
        wa++;
    }
    if(S[a[0]][0]=='A'){
        ac++;
        flg=1;
    }

    for(i=1; i<M; i++){
        if(p[a[i]]!=p[a[i-1]]){
            flg=0;
        }
        if(flg==0 && S[a[i]][0]=='W'){
            wa++;
        }
        if(flg==0 && S[a[i]][0]=='A'){
            ac++;
            flg=1;
        }
    }

    printf("%d %d", ac, wa);
    return 0;
}


#include <stdio.h>
int main()
{    int n,m,i,a[200005]={0},t;
     long countwa = 0, countac = 0;
    scanf("%d %d",&m,&n);
    getchar();
    for(i=0;i<n;i++)
    {   char s[3];
        scanf("%d %s",&t,s);
       if(!a[t] && t <= m && s[0] == 'A' && s[1] == 'C')  a[t]=1,countac++;
       if(!a[t] && t <= m && s[0] =='W' && s[1] == 'A')  countwa++;
    }
    printf("%ld %ld\n",countac,countwa);
    return 0;
}


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

int main()
{
  int ac=0;
  int wa=0;

  char str[5];
  int i,j,k;
  int n=0;
  int N=0;
  int M=0;
  scanf("%d %d",&N,&M);

  if( M == 0 ){
    printf("0 0\n");
  }
  else{

  n = 1;
  for(i=0;i<M;i++){
    scanf("%d %s",&j,str);
    if( i == 0 ){
      n = j;
    }
    if( j == n ){
      if( str[0] == 'W' ){
        wa++;
      }
      if( str[0] == 'A' ){
        ac++;
        n = n + 1;
      }
    }
    else{ }
  }

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

  }

  return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define LIM (1000000007)

void marge(int *, int);

int a[10010];
long long int c[10010];

int main(void)
{

    int n, k, i, ans = 0;
    scanf("%d %d", &n, &k);
    rep(i, n) scanf("%d", a + i);
    marge(a, n);
    c[0] = 1;
    rep2(i, 1, n - k + 1) c[i] = (c[i - 1] * (k - 1 + i) / i) % LIM;
    rep(i, n - k + 1) ans = (ans - (c[n - k - i] * a[i]) % LIM + LIM) % LIM;
    rep2(i, k - 1, n) ans = (ans + (c[i - k + 1] * a[i]) % LIM + LIM) % LIM;
    printf("%d", (ans + LIM) % LIM);
    return 0;
}

void marge(int *a, int n)
{

    if (n == 1)
        return;

    int *tmp;
    tmp = (int *)malloc((n) * sizeof(int));
    marge(a, n / 2);
    marge(a + n / 2, n - n / 2);

    for (int i = 0; i < n / 2; i++)
        tmp[i] = a[i];
    for (int i = n / 2; i < n; i++)
        tmp[i] = a[n / 2 + n - i - 1];

    int lp = 0, rp = n - 1, p = 0;
    int l3, r3;
    while (p < n)
    {
        l3 = tmp[lp];
        r3 = tmp[rp];
        if (l3 < r3)
        {
            a[p] = l3;
            lp++;
            p++;
        }
        else
        {
            a[p] = r3;
            rp--;
            p++;
        }
    }

    return;
}

Score : 500 points

Problem Statement

For a finite set of integers X, let f(X)=\max X - \min X.

Given are N integers A_1,...,A_N.

We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways.

Since the answer can be enormous, print it \bmod (10^9+7).

Constraints

1 \leq N \leq 10^5

1 \leq K \leq N

|A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 ... A_N

Output

Print the answer \bmod (10^9+7).

Sample Input 1

4 2
1 1 3 4

Sample Output 1

11

There are six ways to choose S: \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1s). The value of f(S) for these choices are 0,2,3,2,3,1, respectively, for the total of 11.

Sample Input 2

6 3
10 10 10 -10 -10 -10

Sample Output 2

360

There are 20 ways to choose S. In 18 of them, f(S)=20, and in 2 of them, f(S)=0.

Sample Input 3

3 1
1 1 1

Sample Output 3

0

Sample Input 4

10 6
1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0

Sample Output 4

999998537

Print the sum \bmod (10^9+7).


Score : 600 points

Problem Statement

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

2 \leq N \leq 50

0 \leq x_i \leq 1000

0 \leq y_i \leq 1000

The given N points are all different.

The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum radius of a circle such that all the N points are inside or on it.

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

Sample Input 1

2
0 0
1 0

Sample Output 1

0.500000000000000000

Both points are contained in the circle centered at (0.5,0) with a radius of 0.5.

Sample Input 2

3
0 0
0 1
1 0

Sample Output 2

0.707106781186497524

Sample Input 3

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Sample Output 3

6.726812023536805158

If the absolute or relative error from our answer is at most 10^{-6}, the output will be considered correct.


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 9223372036854775807
#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 MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL rou(LL a,LL d){if((a*10/d)%10<5)return a/d;else return a/d+1;}
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);}
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;}
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 ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}

void gra(double* gx,double* gy,LL x1,LL y1,LL x2,LL y2,LL x3,LL y3){*gx=(x1+x2+x3)/3.0,*gy=(y1+y2+y3)/3.0;}
void out(double* ox,double* oy,LL x1,LL y1,LL x2,LL y2,LL x3,LL y3){LL a=x1*x1+y1*y1,b=x2*x2+y2*y2,c=x3*x3+y3*y3,d=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);if(d==0)*ox=(MAX(x1,MAX(x2,x3))+MIN(x1,MIN(x2,x3)))/2.0,*oy=(MAX(y1,MAX(y2,y3))+MIN(y1,MIN(y2,y3)))/2.0;else *ox=(a*(y2-y3)+b*(y3-y1)+c*(y1-y2))/(2.0*d),*oy=(a*(x3-x2)+b*(x1-x3)+c*(x2-x1))/(2.0*d);}
void inn(double* ix,double* iy,LL x1,LL y1,LL x2,LL y2,LL x3,LL y3){double a=(x1-x3)*(x1-x3),b=(x2-x1)*(x2-x1),c=(x3-x2)*(x3-x2),d=(y1-y3)*(y1-y3),e=(y2-y1)*(y2-y1),f=(y3-y2)*(y3-y2),g=sqrt(c+f),h=sqrt(a+d),i=sqrt(b+e),j=g+h+i;if(x1==x2&&x2==x3&&y1==y2&&y2==y3)*ix=x1,*iy=y1;else *ix=(g*x1+h*x2+i*x3)/j,*iy=(g*y1+h*y2+i*y3)/j;}
void hoh(double* hx,double* hy,LL x1,LL y1,LL x2,LL y2,LL x3,LL y3){LL d=x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);if(d!=0)*hx=((x1*x2+y3*y3)*(y2-y1)+(x2*x3+y1*y1)*(y3-y2)+(x3*x1+y2*y2)*(y1-y3))/(double)d,*hy=((y1*y2+x3*x3)*(x1-x2)+(y2*y3+x1*x1)*(x2-x3)+(y3*y1+x2*x2)*(x3-x1))/(double)d;}
int dcmp(double a,double b,LL n){
  LL A=a*pow(10,n),B=b*pow(10,n);
  if(A>B)return 1;
  if(A<B)return -1;
  return 0;
}

int main(){
  LL N,i,j,k,l,flag;
  double ans=1000000.0,nx,ny,r;
  scanf("%lld",&N);
  LL x[N],y[N];
  FOR(i,0,N)scanf("%lld%lld",&x[i],&y[i]);
  if(N==2)ans=sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]))/2;
  else FOR(i,0,N)FOR(j,i+1,N)FOR(k,j+1,N){
    flag=0;
    out(&nx,&ny,x[i],y[i],x[j],y[j],x[k],y[k]);
    r=sqrt((nx-x[i])*(nx-x[i])+(ny-y[i])*(ny-y[i]));
    if(dcmp(ans,r,7)<=0)continue;
    FOR(l,0,N)if(dcmp(r,sqrt((nx-x[l])*(nx-x[l])+(ny-y[l])*(ny-y[l])),7)==-1)flag=1;
    if(flag==0)ans=r;
  }

  printf("%.16f\n",ans);
	return 0;
}


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

int main(void) {
    int n;
    scanf("%d", &n);
    char s[100*n];
    for (int i = 0; i < 100*n; i++) s[i] = '0';
    int t[n];
    for (int i = 0; i < n; i++) {
        char input[100];
        scanf("%s", input);
        for (int j = 0; j < strlen(input); j++) {
            s[j+100*i] = input[j];
        }
        scanf("%d", &t[i]);
    }
    char x[100];
    scanf("%s", x);

    int k = 0, flag = 0;
    while (flag == 0) {
        for (int i = 0; i < strlen(x); i++) {
            if (x[i] != s[k*100+i]) break;
            flag = 1;
        }
        k++;
    }
    int ans = 0;
    for (int i = k; i < n; i++) {
        ans += t[i];
    }
    printf("%d\n", ans);
    return 0;
}

Score : 200 points

Problem Statement

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

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

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

Constraints

1 \leq N \leq 50

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

s_1,\ldots,s_N are distinct.

There exists an integer i such that s_i = X.

1 \leq t_i \leq 1000

t_i is an integer.

Input

Input is given from Standard Input in the following format:

N
s_1 t_1
\vdots
s_{N} t_N
X

Output

Print the answer.

Sample Input 1

3
dwango 2
sixth 5
prelims 25
dwango

Sample Output 1

30

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

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

Sample Input 2

1
abcde 1000
abcde

Sample Output 2

0

No songs were played while Niwango was asleep.

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

Sample Input 3

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

Sample Output 3

6348


#include <stdio.h>

int main(void){
   int k,x,total;
   if(scanf("%d%d",&k,&x)>3){return -1;}
   total = 500 * k;

   if (total>=x){
      printf("yes\n");
   } else {
      printf("no\n");
   }
   return 0;
}

Score : 100 points

Problem Statement

Takahashi has K 500-yen coins. (Yen is the currency of Japan.)
If these coins add up to X yen or more, print Yes; otherwise, print No.

Constraints

1 \leq K \leq 100

1 \leq X \leq 10^5

Input

Input is given from Standard Input in the following format:

K X

Output

If the coins add up to X yen or more, print Yes; otherwise, print No.

Sample Input 1

2 900

Sample Output 1

Yes

Two 500-yen coins add up to 1000 yen, which is not less than X = 900 yen.

Sample Input 2

1 501

Sample Output 2

No

One 500-yen coin is worth 500 yen, which is less than X = 501 yen.

Sample Input 3

4 2000

Sample Output 3

Yes

Four 500-yen coins add up to 2000 yen, which is not less than X = 2000 yen.


#include <stdio.h>

int main() {
	int p = -1, r = 0, t = 0;
	char s[51];
	scanf("%*d %s", s);
	while(s[++p])
		if(s[p] == 'A' + t) {
			if(++t == 3) {
				r++;
				t = 0;
			}
		} else
			t = 0;
	printf("%d", r);
	return 0;
}

Score : 200 points

Problem Statement

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

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

Constraints

3 \leq N \leq 50

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

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

Sample Input 1

10
ZABCDBABCQ

Sample Output 1

2

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

Sample Input 2

19
THREEONEFOURONEFIVE

Sample Output 2

0

No contiguous subsequences of S are equal to ABC.

Sample Input 3

33
ABCCABCBABCCABACBCBBABCBCBCBCABCB

Sample Output 3

5