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

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

int N;
int Parts[3][100000];

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

  scanf("%ld", &N);

  for (i = 0; i < 3; i++) {
    for (j = 0; j < N; j++) {
      scanf("%d", &Parts[i][j]);
    }
    qsort(Parts[i], N, sizeof(int), compare_int);
  }

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      for(k = 0; k < N; k++){
        if(Parts[2][i] > Parts[1][j] && Parts[1][j] > Parts[0][k]){
          sum++;
        }
      }
    }
  }

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


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
   int a,b,c;
 printf("输入R,G(0≤R,G≤4500):\n");
 scanf("%d%d",&a,&b );
 c=2*b-a;
 printf("%d",c);

 return 0;

 }

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

Score : 100 points

Problem Statement

Takahashi is a user of a site that hosts programming contests.

When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:

Let the current rating of the user be a.

Suppose that the performance of the user in the contest is b.

Then, the new rating of the user will be the avarage of a and b.

For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.

Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.

Find the performance required to achieve it.

Constraints

0 \leq R, G \leq 4500

All input values are integers.

Input

Input is given from Standard Input in the following format:

R
G

Output

Print the performance required to achieve the objective.

Sample Input 1

2002
2017

Sample Output 1

2032

Takahashi's current rating is 2002.

If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.

Sample Input 2

4500
0

Sample Output 2

-4500

Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.

Submitted source-code file size, in bytes.

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

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


#include<stdio.h>
int main(){
int a,b,i,n,q=0,m=0,r,p,l;
scanf("%d %d",&a,&b);
p=1;
while(p<=b){
    q++;
    p=p*2;
    if(q==a){
        break;
    }
}r=a-q;
l=(b*r+p);
   printf("%d",l);
return 0;
}

Score : 200 points

Problem Statement

Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:

Operation A: The displayed value is doubled.

Operation B: The displayed value increases by K.

Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

Constraints

1 \leq N, K \leq 10

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the minimum possible value displayed in the board after N operations.

Sample Input 1

4
3

Sample Output 1

10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

Sample Input 2

10
10

Sample Output 2

76

The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 8 → 16 → 26 → 36 → 46 → 56 → 66 → 76.

By the way, this contest is AtCoder Beginner Contest 076.


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

int main()
{
	int i, N;

	scanf("%d", &N);

	int a[11];
	int t[11];

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

	for (i = 0; i < N; i++) {
		if (a[i] % 2 == 0) {
			t[i] = 2;
		}
		else t[i] = 1;
	}

	int seki=1;

	for (i = 0; i < N; i++) {
		seki*= t[i];
	}

	int p=1;

	for (i = 0; i < N; i++) {
		p *= 3;
	}

	printf("%d", p - seki);
}

Score : 200 points

Problem Statement

We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are similar when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N).

In particular, any integer sequence is similar to itself.

You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N.

How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?

Constraints

1 \leq N \leq 10

1 \leq A_i \leq 100

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the number of integer sequences that satisfy the condition.

Sample Input 1

2
2 3

Sample Output 1

7

There are seven integer sequences that satisfy the condition:

1, 2

1, 4

2, 2

2, 3

2, 4

3, 2

3, 4

Sample Input 2

3
3 3 3

Sample Output 2

26

Sample Input 3

1
100

Sample Output 3

1

Sample Input 4

10
90 52 56 71 44 8 13 30 57 84

Sample Output 4

58921


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

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

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

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

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

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

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

int main(void){
    int i,j,n,m,k,a[524288],b,c,h,w,r=1,l,t;
    double d;
    char s[524288];
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      if(a[i]%2==0){r*=2;}
    }
    printf("%d\n",pow(3,n)-r);
    return 0;
}


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

int main()
{
    int n;
    scanf("%d", &n);
    int all = pow(3, n);
    //printf("%d\n", all);
    int cur;
    int bad = 1;
    for(int i = 0; i < n; i++){
       scanf("%d", &cur);
       if(!(cur % 2)){
           bad *= 2;
       }
    }
    //printf("%d\n", bad);
    printf("%d", all - bad);
    return 0;
}


#include <stdio.h>

int main(void) {
	long N;
	scanf("%ld", &N);
	for (long h = 1; h <= 3500; h++) {
		for (long n = 1; n <= 3500; n++) {
			if (4 * h * n - N * n - N * h <= 0) continue;
			if (N * h * n % (4 * h * n - N * n - N * h)) continue;
			long w = N * h * n / (4 * h * n - N * n - N * h);
			printf("%ld %ld %ld", h, n, w);
			return 0;
		}
	}
	return 0;
}

Score : 300 points

Problem Statement

You are given an integer N.

Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.

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

Constraints

It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.

Inputs

Input is given from Standard Input in the following format:

N

Outputs

Print a triple of positive integers h, n and w that satisfies the condition, in the following format:

h n w

Sample Input 1

2

Sample Output 1

1 2 2

4/2 = 1/1 + 1/2 + 1/2.

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

It is allowed to use an integer exceeding 3500 in a solution.

Sample Input 3

4664

Sample Output 3

3498 3498 3498


#include <stdio.h>

int main(int argc, char *argv[])
{
	int n,a;
	scanf("%d%d",&n,&a);
	printf("%d%d\n",n*n-a);
	return 0;
}

Score : 100 points

Problem Statement

We have an N \times N square grid.

We will paint each square in the grid either black or white.

If we paint exactly A squares white, how many squares will be painted black?

Constraints

1 \leq N \leq 100

0 \leq A \leq N^2

Inputs

Input is given from Standard Input in the following format:

N
A

Outputs

Print the number of squares that will be painted black.

Sample Input 1

3
4

Sample Output 1

5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.

Sample Input 2

19
100

Sample Output 2

261

Sample Input 3

10
0

Sample Output 3

100

As zero squares will be painted white, all the squares will be painted black.


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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    uint A, B, C, D, E, F;
    scanf("%u %u %u %u %u %u", &A, &B, &C, &D, &E, &F);
    A *= 100, B *= 100;
    double max = 0.0;
    uint s_water = 0, suger_in = 0;
    uint a, b, c, d;

    REP(a, F/A + 1){
        REP(b, (F - a * A)/B + 1){
            REP(c, (F - a * A - b * B)/C + 1){
                REP(d, (F - a * A - b * B - c * C)/D + 1){

                    uint water = A * a + B * b;
                    uint suger = c * C + d * D;
                    if((a > 0 || b > 0) && a * A + b * B + c * C + d * D <= F){
                        if( 100 * suger <= E * water && max < 1.0 * suger/(1.0 * suger + 1.0 * water)){
                            max = 1.0 * suger/(1.0 * suger + 1.0 * water);
                            s_water = suger + water;
                            suger_in = suger;
                        }
                    }

                }
            }
        }
    }
    printf("%u %u\n", s_water, suger_in);
    return 0;
}

Score : 300 points

Problem Statement

Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.

Operation 1: Pour 100A grams of water into the beaker.

Operation 2: Pour 100B grams of water into the beaker.

Operation 3: Put C grams of sugar into the beaker.

Operation 4: Put D grams of sugar into the beaker.

In our experimental environment, E grams of sugar can dissolve into 100 grams of water.

Snuke will make sugar water with the highest possible density.

The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.

We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

A, B, C, D, E and F are all integers.

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.

We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:

If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.

If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934


#include<stdio.h>
int main()
{
    int i,h,len,j,n;
    h=3;
        scanf("%d",&i);
        j=i%10;
        n=i/10;
        if(j==9||n==9){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }

    return 0;
}

Score : 100 points

Problem Statement

It is September 9 in Japan now.

You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

Constraints

10≤N≤99

Input

Input is given from Standard Input in the following format:

N

Output

If 9 is contained in the decimal notation of N, print Yes; if not, print No.

Sample Input 1

29

Sample Output 1

Yes

The one's digit of 29 is 9.

Sample Input 2

72

Sample Output 2

No

72 does not contain 9.

Sample Input 3

91

Sample Output 3

Yes


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

int main()
{
    int N, b1, b2;
    scanf("%2d",&N);
    b1 = N/10;
    b2 = N%10;
    if (b1 == 9 || b2 == 9)
    {
        printf("YES\n\n");
        printf("The one's digit of %d is 9.\n",N);
    }
    else
    {
        printf("NO\n\n");
        printf("%d does not contain 9.\n",N);
    }
    return 0;
}


Score : 300 points

Problem Statement

You are playing the following game with Joisino.

Initially, you have a blank sheet of paper.

Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.

Then, you are asked a question: How many numbers are written on the sheet now?

The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Constraints

1≤N≤100000

1≤A_i≤1000000000(=10^9)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print how many numbers will be written on the sheet at the end of the game.

Sample Input 1

3
6
2
6

Sample Output 1

1

The game proceeds as follows:

6 is not written on the sheet, so write 6.

2 is not written on the sheet, so write 2.

6 is written on the sheet, so erase 6.

Thus, the sheet contains only 2 in the end. The answer is 1.

Sample Input 2

4
2
5
5
2

Sample Output 2

0

It is possible that no number is written on the sheet in the end.

Sample Input 3

6
12
22
16
22
18
12

Sample Output 3

2


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

unsigned com(const void* a, const void* b){
    return *(unsigned*)a - *(unsigned*)b;
}

int main(void){
    int n;
    scanf("%d", &n);
    unsigned a[n];
    for(int i=0;i<n;i++){
        scanf("%u", &a[i]);
    }
    qsort((void*)a, n, sizeof(unsigned int), com);
    int m=0, p=0;
    for(unsigned k=a[0];k<=a[n-1];k++){
        for(int j=0;j<n;j++){
            if(a[j]==k){
                m++;
            }
        }
        if(m%2){
            p++;
        }
        m = 0;
    }
    printf("\n%d", p);
    return 0;
}


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

Score : 100 points

Problem Statement

We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.

How many grams of sand will the upper bulb contains after t seconds?

Constraints

1≤X≤10^9

1≤t≤10^9

X and t are integers.

Input

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

X t

Output

Print the number of sand in the upper bulb after t second.

Sample Input 1

100 17

Sample Output 1

83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

Sample Input 2

48 58

Sample Output 2

0

All 48 grams of sand will be gone, resulting in 0 grams.

Sample Input 3

1000000000 1000000000

Sample Output 3

0


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STR_LEN 100000
void fun(char *,char *);
void fun(char *str1,char *str2)
{
    int i,j=0;
    for(i=0;str1[i]!='\0';i=i+2)
    {
        str2[j++]=str1[i];
    }
    str2[j]='\0';
}
int main()
{
    char s1[STR_LEN+1]={0};
    char s2[STR_LEN+1]={0};
    scanf("%s",s1);
    fun(s1,s2);
    printf("%s\n",s2);
    return 0;
}

Score : 200 points

Problem Statement

You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.

Constraints

Each character in s is a lowercase English letter.

1≤|s|≤10^5

Input

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

s

Output

Print the string obtained by concatenating all the characters in the odd-numbered positions.

Sample Input 1

atcoder

Sample Output 1

acdr

Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.

Sample Input 2

aaaa

Sample Output 2

aa

Sample Input 3

z

Sample Output 3

z

Sample Input 4

fukuokayamaguchi

Sample Output 4

fkoaaauh


#include <stdio.h>

#define MAX 100000

int main(void)
{
	int n, i, a, a_max;
	int b[MAX] = { 0 };
	int max;

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

		if(a_max < a)
			a_max = a;

		b[a]++;

		if(a > 0)
			b[a-1]++;
		if(a < MAX-1)
			b[a+1]++;
	}

	for(max=0,i=0; i<a_max+1; i++){
		if(max < b[i])
			max = b[i];
	}

	printf("%d", max);

	return 0;
}

Score : 300 points

Problem Statement

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

1≤N≤10^5

0≤a_i<10^5 (1≤i≤N)

a_i is an integer.

Input

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

N
a_1 a_2 .. a_N

Output

Print the maximum possible number of i such that a_i=X.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1


#include<stdio.h>

int N,num[100000];

int check(int cnum){
  int cnt=0,i;
  for(i=0;i<N;i++){
    if(cnum==num[i] || cnum==num[i]+1 || cnum==num[i]-1)
      cnt++;
  }
  return cnt;
}

int main(){
  int i,j,max=1;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&num[i]);

  for(i=0;i<N;i++){
    if(max < check(num[i]))
      max=check(num[i]);
  }
  printf("%d\n",max);
  return 0;
}


Score : 500 points

Problem Statement

You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.

You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.

You can perform this operation at most once.

How many different strings can you obtain?

Constraints

1 \leq |A| \leq 200,000

A consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

A

Output

Print the number of different strings you can obtain by reversing any substring in A at most once.

Sample Input 1

aatt

Sample Output 1

5

You can obtain aatt (don't do anything), atat (reverse A[2..3]), atta (reverse A[2..4]), ttaa (reverse A[1..4]) and taat (reverse A[1..3]).

Sample Input 2

xxxxxxxxxx

Sample Output 2

1

Whatever substring you reverse, you'll always get xxxxxxxxxx.

Sample Input 3

abracadabra

Sample Output 3

44


#include <stdio.h>

int main() {
	int X, A, B;
	scanf("%d %d %d", &X, &A, &B);
	A - X < B - X ? printf("A"): printf("B");
	return 0;
}

Score : 100 points

Problem Statement

Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer to Snuke's residence.

Here, the distance between two points s and t on a number line is represented by |s-t|.

Constraints

1 \leq x \leq 1000

1 \leq a \leq 1000

1 \leq b \leq 1000

x, a and b are pairwise distinct.

The distances between Snuke's residence and stores A and B are different.

Input

Input is given from Standard Input in the following format:

x a b

Output

If store A is closer, print A; if store B is closer, print B.

Sample Input 1

5 2 7

Sample Output 1

B

The distances between Snuke's residence and stores A and B are 3 and 2, respectively.
Since store B is closer, print B.

Sample Input 2

1 999 1000

Sample Output 2

A


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

Score : 100 points

Problem Statement

You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

Constraints

100≤N≤999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is a palindromic number, print Yes; otherwise, print No.

Sample Input 1

575

Sample Output 1

Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

Sample Input 2

123

Sample Output 2

No

N=123 becomes 321 when read backward, so it is not a palindromic number. You should print No.

Sample Input 3

812

Sample Output 3

No


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007

//最大公約数
long long gcd(long long a, long long b){
    //a>bになるように入れ替え
    if(a<b){
        long tmp=a;
        a=b;
        b=tmp;
    }

    //ユークリッドの互除法
    if(a%b==0) return b;
    return gcd(b,a%b);
}

//最小公倍数
long long lcm(long long a,long long b){
    return a*(b/gcd(a,b));
}

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

    //A[0]~A[N-1]に格納する
    long long* T;
    NEW(T,N);
    for(int i=0;i<N;i++){
        scanf("%lld",&T[i]);
    }

    long long ans=1;
    for(int i=0;i<N;i++){
        ans=lcm(ans,T[i]);
    }
    printf("%lld\n",ans);

    return 0;
}

Score : 300 points

Problem Statement

We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

Constraints

1≤N≤100

1≤T_i≤10^{18}

All input values are integers.

The correct answer is at most 10^{18} seconds.

Input

Input is given from Standard Input in the following format:

N
T_1
:
T_N

Output

Print the number of seconds after which the hand of every clock point directly upward again.

Sample Input 1

2
2
3

Sample Output 1

6

We have two clocks. The time when the hand of each clock points upward is as follows:

Clock 1: 2, 4, 6, ... seconds after the beginning

Clock 2: 3, 6, 9, ... seconds after the beginning

Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

Sample Input 2

5
2
5
10
1000000000000000000
1000000000000000000

Sample Output 2

1000000000000000000


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    char s[128];
    scanf("%s",s);
    printf("%c%d%c\n",s[0],strlen(s)-2,s[strlen(s)-1]);
    return 0;
}

Score : 200 points

Problem Statement

The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.

You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

Constraints

3 ≤ |s| ≤ 100 (|s| denotes the length of s.)

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the abbreviation of s.

Sample Input 1

internationalization

Sample Output 1

i18n

Sample Input 2

smiles

Sample Output 2

s4s

Sample Input 3

xyz

Sample Output 3

x1z


Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


Score : 800 points

Problem Statement

Let N be a positive even number.

We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N).
Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.

First, let q be an empty sequence.
Then, perform the following operation until p becomes empty:

Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.

When p becomes empty, q will be a permutation of (1, 2, ..., N).

Find the lexicographically smallest permutation that can be obtained as q.

Constraints

N is an even number.

2 ≤ N ≤ 2 × 10^5

p is a permutation of (1, 2, ..., N).

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

Print the lexicographically smallest permutation, with spaces in between.

Sample Input 1

4
3 2 4 1

Sample Output 1

3 1 2 4

The solution above is obtained as follows:

p

q

(3, 2, 4, 1)

()

↓

↓

(3, 1)

(2, 4)

↓

↓

()

(3, 1, 2, 4)

Sample Input 2

2
1 2

Sample Output 2

1 2

Sample Input 3

8
4 6 3 2 8 5 7 1

Sample Output 3

3 1 2 7 4 6 8 5

The solution above is obtained as follows:

p

q

(4, 6, 3, 2, 8, 5, 7, 1)

()

↓

↓

(4, 6, 3, 2, 7, 1)

(8, 5)

↓

↓

(3, 2, 7, 1)

(4, 6, 8, 5)

↓

↓

(3, 1)

(2, 7, 4, 6, 8, 5)

↓

↓

()

(3, 1, 2, 7, 4, 6, 8, 5)


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int fun(int );
int fun(int N)
{
    int i;
    for(i=0;;i++)
    {
        if(pow(2,i+1)>N)
        {
            break;
        }
    }
    return pow(2,i);
}
int main()
{
    int N,s;
    scanf("%d",&N);
    s=fun(N);
    printf("%d\n",s);
    return 0;
}

Score : 200 points

Problem Statement

Takahashi loves numbers divisible by 2.

You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.

Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.

For example,

6 can be divided by 2 once: 6 -> 3.

8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.

3 can be divided by 2 zero times.

Constraints

1 ≤ N ≤ 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

7

Sample Output 1

4

4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.

Sample Input 2

32

Sample Output 2

32

Sample Input 3

1

Sample Output 3

1

Sample Input 4

100

Sample Output 4

64


#include<stdio.h>
int main(void)
{
  int n,i,ans = 0,new_ans = 0;
  int true_i,memo_i;

   scanf("%d", &n);

  for(i = 1; i <= n; i++){
   ans = 0;
   memo_i = i;
    while((memo_i % 2) == 0){
      ans++;
      memo_i /= 2;
    }
    if(ans > new_ans){
     new_ans = ans;
     true_i = i;
    }
  }
    printf("%d", true_i);

  return 0;
}


#include<stdio.h>

int main(void)
{
	int n;
	int c;
	int m;
	int k;

	m = 0;
	c = 0;
	scanf("%d", &n);

	for(k = n; k > 0; k--){
		while(k % 2 == 0){
			c++;
			k /= 2;
		if(m < c){
			m = c;
		}
		}
	}
	printf("%d", m);
	return 0;
}


Score : 300 points

Problem Statement

In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.

There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.

Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.

Help him.

Constraints

3 ≤ N ≤ 200 000

1 ≤ M ≤ 200 000

1 ≤ a_i < b_i ≤ N

(a_i, b_i) \neq (1, N)

If i \neq j, (a_i, b_i) \neq (a_j, b_j).

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

POSSIBLE

Sample Input 2

4 3
1 2
2 3
3 4

Sample Output 2

IMPOSSIBLE

You have to use three boat services to get to Island 4.

Sample Input 3

100000 1
1 99999

Sample Output 3

IMPOSSIBLE

Sample Input 4

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

Sample Output 4

POSSIBLE

You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5.


#include <stdio.h>
int main(void){
	int n,m,i;
	scanf("%d%d",&n,&m);
	int a,b,b1[n],b2[n];
	for(i=0;i<n;i++){b1[i]=0;b2[i]=0;}
	for(i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		if(a==1)	b1[b] = 1;
		if(b==n)	b2[a] = 1;
	}
	for(i=0;i<n;i++){
		if(b1[i]==1 && b2[i]==1){
			printf("POSSIBLE");
			return 0;
		}
	}

	printf("IMPOSSIBLE");
	return 0;
}


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

unsigned long long MAX;

int main()
{
	FILE *fp;
	char file_name[30];

	char in[30];
	char c;
	unsigned long long BALL_BOX[100000];
	unsigned long long K;
	unsigned long long x, y, bk, remainder;
	int N;
	int i;

/*
	printf("読み込むファイル名を入力して下さい。\n");
	fgets(in, sizeof(in), stdin);
	in[strlen(in) - 1] = '\0';
	sprintf(file_name, "%s", in);

	if( (fp = fopen(file_name, "r")) == NULL){
		printf("file open error\n");
		exit(1);
	}
*/
	fgets(in, sizeof(in), stdin);
	sscanf(in, "%d %lld", &N, &K);

	i = MAX = 0;
	while((c = getc(stdin)) && i < N){
		if(isdigit(c)){
			ungetc(c, stdin);
			fscanf(stdin, "%lld", &BALL_BOX[i]);
			if(BALL_BOX[i] > MAX)
				MAX = BALL_BOX[i];
			i++;
		}
	}

//	fclose(fp);

	// 最大公約数を求める
	for(i = 0; i < N - 1; i++){
		if(i == 0)
			x = BALL_BOX[i];

		y = BALL_BOX[i + 1];

		if(x < y){
			bk = x;
			x = y;
			y = bk;
		}

		// ユークリッド互除法
		while( (remainder = x % y) != 0){
			x = y;
			y = remainder;
		}

		x = y;
	}

/*
	printf("MAX = %lld\n", MAX);
	for(i = 0; i < N; i++){
		printf("%lld ", BALL_BOX[i]);
	}
	printf("\n");
*/

	if(K % x == 0 && K <= MAX)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");

	return 0;
}

Score : 300 points

Problem Statement

There is a box containing N balls. The i-th ball has the integer A_i written on it.
Snuke can perform the following operation any number of times:

Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.

Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

1 \leq K \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE; if it is not possible, print IMPOSSIBLE.

Sample Input 1

3 7
9 3 4

Sample Output 1

POSSIBLE

First, take out the two balls 9 and 4, and return them back along with a new ball, abs(9-4)=5.
Next, take out 3 and 5, and return them back along with abs(3-5)=2.
Finally, take out 9 and 2, and return them back along with abs(9-2)=7.
Now we have 7 in the box, and the answer is therefore POSSIBLE.

Sample Input 2

3 5
6 9 3

Sample Output 2

IMPOSSIBLE

No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE.

Sample Input 3

4 11
11 3 7 15

Sample Output 3

POSSIBLE

The box already contains 11 before we do anything. The answer is therefore POSSIBLE.

Sample Input 4

5 12
10 2 8 6 4

Sample Output 4

IMPOSSIBLE


#include<stdio.h>

int main(){
        int a,b;
   do{
            scanf("%d",&a);
        }while(a<1);
        do{
            scanf("%d",&b);
        }while(b<1 || b>100);
        int c=(a+b)%3;
        if(c==0) printf("Possible");
        else printf("Impossible");
    return 0;
}

Score : 100 points

Problem Statement

Snuke is giving cookies to his three goats.

He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).

Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

Constraints

1 \leq A,B \leq 100

Both A and B are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.

Sample Input 1

4 5

Sample Output 1

Possible

If Snuke gives nine cookies, each of the three goats can have three cookies.

Sample Input 2

1 1

Sample Output 2

Impossible

Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.


#include<stdio.h>

int main(void) {
	int N, K;
	int i, j;

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

	int I[N];

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

	for(i = 1; i < N+1; i++) {
		j = i;
		while(j >= 1 && I[j-1] > I[j]) {
			int tmp = I[j-1];
			I[j-1] = I[j];
			I[j] = tmp;
			j--;
		}
	}

	int sum = 0;
	for(i = N-1; i > N-1-K; i--) {
		sum = sum + I[i];
	}
	printf("%d",sum);

	printf("\n");

	return 0;
}

Score : 200 points

Problem Statement

Snuke has N sticks.
The length of the i-th stick is l_i.

Snuke is making a snake toy by joining K of the sticks together.

The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

Constraints

1 \leq K \leq N \leq 50

1 \leq l_i \leq 50

l_i is an integer.

Input

Input is given from Standard Input in the following format:

N K
l_1 l_2 l_3 ... l_{N}

Output

Print the answer.

Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

Sample Input 2

15 14
50 26 27 21 41 7 42 35 7 5 5 36 39 1 45

Sample Output 2

386


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

int main(int argc, char *argv[])
{
    int i, N;
    long long sum = 0, a = 0, b = 0, min = LLONG_MAX;
    static long long list[2*100000];
    scanf("%d", &N);

    for ( i = 0; i < N; i++ ){
        scanf("%lld", &list[i]);
        sum += list[i];
    }
    for ( i = 0; i < N-1; i++ ){
        a += list[i];
        b = sum - a;
        if ( min > abs(a-b) ){
            min = abs(a-b);
        }
    }
    printf("%lld\n", min);
    return 0;
}

Score : 300 points

Problem Statement

Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.

They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.

Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

Constraints

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

-10^{9} \leq a_i \leq 10^{9}

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{N}

Output

Print the answer.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Sample Input 2

2
10 -10

Sample Output 2

20

Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10, y=-10, and thus |x-y|=20.


#include<stdio.h>
#include<math.h>
int main(void)
{
    long long n,i,x,num=0,num1=0,num2;
    scanf("%d",&n);
    long long a[n];
    for(i=0;i<n;i++)
    {
        scanf("%LLd",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        num+=a[i];
    }
    x=abs(num-2*a[0]);
    for(i=0;i<n-1;i++)
    {
        num1+=a[i];
        num2=num-num1;
        if(abs(num1-num2)<x)    x=abs(num1-num2);
    }
        printf("%LLd",x);
        return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d %d %d",&a,&b,&c);
    if(1>=a,b,c&&a,b,c<=10000)
    {
        d=a+b;
        e=a+c;
        f=b+c;
        if(d<=e,f)
        {
            printf("%d",d);
        }
        else if(e<=d,f)
        {
            printf("%d",d);
        }
        else if(f<=e,d)
        {
            printf("%d",f);
        }
    }
}

Score : 100 points

Problem Statement

Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.

He has very high awareness of safety, and decides to buy two bells, one for each hand.

The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.
Find the minimum total price of two different bells.

Constraints

1 \leq a,b,c \leq 10000

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print the minimum total price of two different bells.

Sample Input 1

700 600 780

Sample Output 1

1300

Buying a 700-yen bell and a 600-yen bell costs 1300 yen.

Buying a 700-yen bell and a 780-yen bell costs 1480 yen.

Buying a 600-yen bell and a 780-yen bell costs 1380 yen.

The minimum among these is 1300 yen.

Sample Input 2

10000 10000 10000

Sample Output 2

20000

Buying any two bells costs 20000 yen.


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

     if(b<=c)

       {
           min = a+b;
       printf("%d",min);
       }

     else
      {
         min = a+c;
       printf("%d",min);
      }
   }
   return 0;
}


   #include <stdio.h>

   int main(void) {
       int sum1, sum2, sum3;
       int a, b, c;

       scanf("%d %d %d" , &a, &b, &c);

       sum1 = a + b;
       sum2 = b + c;
       sum3 = c + a;

       if(sum1 < sum2 && sum1 < sum3) {
          printf("%d\n",sum1);
       }else if(sum2 < sum1 && sum2 < sum3){
          printf("%d\n",sum2);
       }else if(sum3 < sum1 && sum3 < sum2){
          printf("%d\n",sum3);
       }else if(sum1 == sum2 && sum2 == sum3){
          printf("%d\n",sum1);
       }
   return 0;
}


#include <stdio.h>
int main(void){
   int a, b, c;
   int min1, min2;
   scanf("%d%d%d", &a, &b, &c);

   if(a<=b){
      if(b<=c){
         min1 = a;
         min2 = b;
      }else{min1 = a;
            min2 = c;
      }
   }else{if(a<=c){
         min1 = b;
         min2 = a;
      }else{min1 = b;
            min2 = c;
      }
   }
   printf("minPrice = %d\n", min1+min2);
   return 0;
}


Score : 300 points

Problem Statement

You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.

The i-th operation is as follows:

Append a_i to the end of b.

Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

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

0 \leq a_i \leq 10^9

n and a_i are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print n integers in a line with spaces in between.
The i-th integer should be b_i.

Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3

After step 1 of the first operation, b becomes: 1.

After step 2 of the first operation, b becomes: 1.

After step 1 of the second operation, b becomes: 1, 2.

After step 2 of the second operation, b becomes: 2, 1.

After step 1 of the third operation, b becomes: 2, 1, 3.

After step 2 of the third operation, b becomes: 3, 1, 2.

After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.

After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.

Thus, the answer is 4 2 1 3.

Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

As shown above in Sample Output 1, b becomes 3, 1, 2 after step 2 of the third operation. Thus, the answer is 3 1 2.

Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7


#include <stdio.h>
#include <malloc.h>

int main()
{
    long *a = (long int*)malloc(300000 * sizeof(long int));
	long *b = (long int*)malloc(300000 * sizeof(long int));
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
    }
    for(j=0,i=n-1;i>=0;i=i-2)
    {
        b[j]=a[i];
        j++;
    }
    if(n%2==0)
    {

    for(i=i+1;i<n;i=i+2)
    {
        b[j]=a[i];

        j++;
    }
    }
    else
    {
    for(i=i+3;i<n;i=i+2)
    {
        b[j]=a[i];

        j++;

    }
    }

    for(j=0;j<n;j++)
    {
        printf("%ld ",b[j]);
    }

    return 0;
}


#include<stdio.h>
int main()
{
   long n;
   int i;
   int a[200000];
   scanf("%ld",&n);
   for( i=0;i<n;i++)
         scanf("%d",&a[i]);
   int flag=n%2;
  if(flag==0)
      {
         for(i=n-1;i>0;i-=2)
              printf("%d",a[i]);
          for(i=0;i<n;i+=2)
              printf("%d",a[i]);
     }
   else{
      for(i=n-1;i>=0;i+=2)
           printf("%d",a[i]);
      for(i=1;i<n;i+=2)
          printf("%d",a[i]);
}
   return 0;
}


#include <stdio.h>
int main()
{
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    if((b-a)<=x)
    {
        if(b>a || a==b)
        {
            printf("safe");
        }
        else if(a>b)
        {
            printf("delicious");
        }
    }
    else
    {
        printf("dangerous");
    }
    return 0;
}

Score : 100 points

Problem Statement

Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.

Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.

Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.

Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

Constraints

1 ≤ X,A,B ≤ 10^9

Input

Input is given from Standard Input in the following format:

X A B

Output

Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

Sample Input 1

4 3 6

Sample Output 1

safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.

Sample Input 2

6 5 1

Sample Output 2

delicious

He ate the food by the "best-by" date. It was delicious for him.

Sample Input 3

3 7 12

Sample Output 3

dangerous

He ate the food five days after the "best-by" date. It was harmful for him.


#include <stdio.h>
int main()
{
    int x,a,b;
    while (scanf("%d %d %d",&x,&a,&b)!=EOF)
    {
        if((b-a)>x) printf("dangerous\n");
        else
        {
            if((b-a)<=x&&b>a)
                printf("safe\n");
            else
                printf("delicious\n");
        }
    }
    return 0;
}


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

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

          if(b <= a){
              printf("delicious");
          }else if((b-a) <= x ){
              printf("safe");
          }else{
              printf("dangerous");
          }
        }


Score : 300 points

Problem Statement

Snuke has N dogs and M monkeys. He wants them to line up in a row.

As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.

How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

Constraints

1 ≤ N,M ≤ 10^5

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of possible arrangements, modulo 10^9+7.

Sample Input 1

2 2

Sample Output 1

8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

Sample Input 2

3 2

Sample Output 2

12

Sample Input 3

1 8

Sample Output 3

0

Sample Input 4

100000 100000

Sample Output 4

530123477


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

double fact(int in){
  double out=1;
  int i;
  for(i=1; i<=in; ++i){
    out *=i;
    if (out >=1000000007){
      out = fmod(out, 1000000007);
    }
  }
  return out;
}

int main(void){
  int n, m;
  double na, ma;
  scanf("%d%d", &n, &m);
  if (n-m  > 1 || m-n >1) {
    printf("%d\n", 0);
    return 0;
  }
  na = fact(n);
  ma = fact(m);
  if (n==m){
    printf("%1.0f\n", fmod(na*ma*2, 1000000007));
  } else{
    printf("%1.0f\n", fmod(na*ma, 1000000007));
  }
  return 0;
}


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

double fact(int in){
  double out=1;
  int i;
  for(i=1; i<=in; ++i){
    out *=i;
  }
  return out;
}

int main(void){
  int n, m;
  double na, ma;
  scanf("%d%d", &n, &m);
  if (n-m  > 1 || m-n >1) {
    printf("%d\n", 0);
    return 0;
  }
  na = fact(n);
  ma = fact(m);
  if (n==m){
    printf("%1.0f\n", fmod(na*ma*2, 1000000007));
  } else{
    printf("%1.0f\n", fmod(na*ma, 1000000007));
  }
  return 0;
}


#include <stdio.h>
#include <math.h>
/* 条件
N = M or N + 1 = M or N  = M  + 1 の場合のみ
同種は並びあうことがない

それ以外は0を返す

方針 組み合わせで解けそう

(i) N = M のとき

*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int main(void){
    int mode = pow(10,9) + 7;
    int N,M;
    int ans;
    scanf("%d",&N);
    scanf("%d",&M);
    if(N == M){
        ans = factorial(N) * factorial(M) * 2;
        printf("%d¥n",ans % mode);
    }
    else if((N + 1) == M || N == (M + 1)){
        ans = factorial(N) * factorial(M);
        printf("%d¥n",ans % mode);
    }
    else{
        printf("0¥n");
    }
    return 0;
}


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

#define N	200000
#define M	200000
#define N_	(1 << 18)	/* N_ = pow2(ceil(log2(M))) */

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

int ll[N], rr[N];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return ll[i] - ll[j];
}

int sum[N_ * 2], suf[N_ * 2], n_;

void pul(int i) {
	int l = i << 1, r = i << 1 | 1;

	sum[i] = sum[l] + sum[r];
	suf[i] = max(suf[r], suf[l] + sum[r]);
}

void build(int n) {
	int i;

	n_ = 1;
	while (n_ < n)
		n_ <<= 1;
	for (i = 1; i < n - 1; i++)
		sum[n_ + i] = -1;
	for (i = n_ - 1; i > 0; i--)
		pul(i);
}

void update(int i) {
	i += n_;
	suf[i] = max(sum[i]++, 0);
	while (i > 1)
		pul(i >>= 1);
}

int main() {
	static int ii[N];
	int n, m, i, l, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &ll[i], &rr[i]);
		ii[i] = i;
	}
	qsort(ii, n, sizeof *ii, compare);
	build(m + 2);
	ans = 0;
	for (l = 0, i = 0; l <= m; l++) {
		while (i < n && ll[ii[i]] == l)
			update(rr[ii[i++]]);
		ans = max(ans, suf[1] - l);
	}
	printf("%d\n", ans);
	return 0;
}

Score : 1000 points

Problem Statement

There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i.

N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i-th person wishes to sit in a chair whose coordinate is not greater than L_i, or not less than R_i. Naturally, only one person can sit in the same chair.

It may not be possible for all of them to sit in their favorite chairs, if nothing is done.
Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions.

Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs.

Constraints

1 ≤ N,M ≤ 2 × 10^5

0 ≤ L_i < R_i ≤ M + 1(1 ≤ i ≤ N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
:
L_N R_N

Output

Print the minimum required number of additional chairs.

Sample Input 1

4 4
0 3
2 3
1 3
3 4

Sample Output 1

0

The four people can sit in chairs at the coordinates 3, 2, 1 and 4, respectively, and no more chair is needed.

Sample Input 2

7 6
0 7
1 5
3 6
2 7
1 6
2 6
3 7

Sample Output 2

2

If we place additional chairs at the coordinates 0 and 2.5, the seven people can sit at coordinates 0, 5, 3, 2, 6, 1 and 2.5, respectively.

Sample Input 3

3 1
1 2
1 2
1 2

Sample Output 3

2

Sample Input 4

6 6
1 6
1 6
1 5
1 5
2 6
2 6

Sample Output 4

2


#include<stdio.h>
int main() {
	int max=0, min=1000000;
	int n;
	int s[100005];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &s[i]);
		if (max < s[i])max = s[i];
		if (min > s[i])min = s[i];
	}
	if (max - min >= 2) { printf("No"); return 0; }
	if(max==min&&n<2*max) { printf("No"); return 0; }else if(max == min && n >=2 * max){ printf("Yes"); return 0; }

}

Score : 700 points

Problem Statement

There are N cats.
We number them from 1 through N.

Each of the cats wears a hat.
Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me."

Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

Constraints

2 ≤ N ≤ 10^5

1 ≤ a_i ≤ N-1

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.

Sample Input 1

3
1 2 2

Sample Output 1

Yes

For example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.

Sample Input 2

3
1 1 2

Sample Output 2

No

From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color.
Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color.
Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.

Sample Input 3

5
4 3 4 3 4

Sample Output 3

No

Sample Input 4

3
2 2 2

Sample Output 4

Yes

Sample Input 5

4
2 2 2 2

Sample Output 5

Yes

Sample Input 6

5
3 3 3 3 3

Sample Output 6

No


#include<stdio.h>
int main()
{
  int r,g,b;

  scanf("%d %d %d", &r, &g, &b);
  if ((2*g + b)%4 == 0)
    printf("YES");
  else
    printf("NO");

   return 0;
}

Score : 100 points

Problem Statement

AtCoDeer has three cards, one red, one green and one blue.

An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.

We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.

Is this integer a multiple of 4?

Constraints

1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

Sample Input 1

4 3 2

Sample Output 1

YES

432 is a multiple of 4, and thus YES should be printed.

Sample Input 2

2 3 4

Sample Output 2

NO

234 is not a multiple of 4, and thus NO should be printed.


#include<stdio.h>
int main(void){
	int r,g,b,sum;
	scanf("%d",&r);
	scanf("%d",&g);
	scanf("%d",&b);
	sum=r*100+g*10+b;
	if(sum%4==0){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}


#include <stdio.h>
#define g getchar()
int main(){
g,g,puts(((g-'0')*2+(g,g-'0'))%4?"NO":"YES");}


Score : 300 points

Problem Statement

In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:

Rating 1-399 : gray

Rating 400-799 : brown

Rating 800-1199 : green

Rating 1200-1599 : cyan

Rating 1600-1999 : blue

Rating 2000-2399 : yellow

Rating 2400-2799 : orange

Rating 2800-3199 : red

Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.

Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.

Find the minimum and maximum possible numbers of different colors of the users.

Constraints

1 ≤ N ≤ 100

1 ≤ a_i ≤ 4800

a_i is an integer.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

Sample Input 1

4
2100 2500 2700 2700

Sample Output 1

2 2

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.

Sample Input 2

5
1100 1900 2800 3200 3200

Sample Output 2

3 5

The user with rating 1100 is "green", the user with rating 1900 is blue and the user with rating 2800 is "red".

If the fourth user picks "red", and the fifth user picks "blue", there are three different colors. This is one possible scenario for the minimum number of colors.

If the fourth user picks "purple", and the fifth user picks "black", there are five different colors. This is one possible scenario for the maximum number of colors.

Sample Input 3

20
800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990

Sample Output 3

1 1

All the users are "green", and thus there is one color.


#include <stdio.h>
int main(){
	int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, j=0;
	int ans = 0;
	int n, rate;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &rate);
		if(rate < 400) a++;
		else if(rate < 800) b++;
		else if(rate < 1200) c++;
		else if(rate < 1600) d++;
		else if(rate < 2000) e++;
		else if(rate < 2400) f++;
		else if(rate < 2800) g++;
		else if(rate < 3200) h++;
		else j++;
	}
	if(a) ans++;
	if(b) ans++;
	if(c) ans++;
	if(d) ans++;
	if(e) ans++;
	if(f) ans++;
	if(g) ans++;
	if(h) ans++;
	printf("%d %d\n", (ans ? ans : 1), ans + j);
}


#include <stdio.h>

int main(void){
    int A, B, s;
    scanf("%d %d", &A, &B);
    s = A + B;
    if(s>=10){
        printf("error\n");
        return 0;
    }

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

Score : 100 points

Problem Statement

You are given two integers A and B as the input. Output the value of A + B.

However, if A + B is 10 or greater, output error instead.

Constraints

A and B are integers.

1 ≤ A, B ≤ 9

Input

Input is given from Standard Input in the following format:

A B

Output

If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

Sample Input 1

6 3

Sample Output 1

9

Sample Input 2

6 4

Sample Output 2

error


#include <stdio.h>
int main(void){
    // Here your code !
    int A,B;

    scanf("%d %d",&A,&B);
    if(A+B >= 10){
        printf("error\n");
    }else{
        printf("%d\n",A+B);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(void)
{
	char	*s = (char *)malloc(27);
	int		i = 0;
	int		j;
	s[0] = '\0';
	scanf("%s",s);
	while(s[i]!='\0')
	{
		j=i+1;
		while(s[j] != '\0')
		{
			if (s[i] == s[j])
			{
				printf("no");
				return (0);
			}
			j++;
		}
		i++;
	}
	printf("yes");
  return (0);
}

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

Constraints

2 ≤ |S| ≤ 26, where |S| denotes the length of S.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If all the characters in S are different, print yes (case-sensitive); otherwise, print no.

Sample Input 1

uncopyrightable

Sample Output 1

yes

Sample Input 2

different

Sample Output 2

no

Sample Input 3

no

Sample Output 3

yes


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

int main() {
    char s[27],ans[4]="yes";
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        for(int m=1;m<strlen(s)-i;m++){
            strcpy(ans,s[i]==s[i+m]?"no":ans);
        }
    }
    printf("%s\n",ans);
    return 0;
}


#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;

#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

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

int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る

//#define pai  3.1415926535
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))

int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}

int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}

#pragma endregion

//// 109 C-Skip
#define _abs(a,b)   ((a<b)?b-a:a-b)
//#define _MAX 1000000001
//static int a[_MAX];
//int main(void) {
//	int n, x, x1;
//	int   min = _MAX, min1 = _MAX, ans;
//
//
//	scanf("%d %d", &n, &x1);
//
//	for (int i = 1; i <= n; i++) {
//		scanf("%d", &x);
//		min = _min(_abs(x1, x), min);
//		min1 = min;
//	}
//
//	if (min1 != _MAX)
//		ans = i_gcd(min1, min);
//	else ans = min;
//	printf("%d\n", ans);
//
//	return 0;
//}
//

//
//int main(void) {
//
//	double x,y,tmp,x1, x2, x3, y1, y2, y3;
//
//	scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
//
//	x = _max(_abs(x2,x1), _max(_abs(x3, x1), _abs(x2, x3)));
//	y = _max(_abs(y2, y1), _max(_abs(y3, y1), _abs(y2, y3)));
//
//	printf("x %lf y %lf\n", x ,y);
//
//	tmp =  (_abs(x2, x1) * _abs(y2, y1)) / 2.0;
//	tmp += (_abs(x2, x3) * _abs(y2, y3)) / 2.0;
//	tmp += (_abs(x1, x3) * _abs(y1, y3)) / 2.0;
//
//	printf("tmp %lf x*y %lf\n",tmp,x*y);
//	printf("%.3lf\n", (double)x * y - tmp);
//	return 0;
//}

//ABC 075 C-Bugged
static int a[101];
int main(void) {
	int n, i, ans = 0;

	scanf("%d", &n);

	int tmp = 0, tmp1 = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		tmp  += a[i] % 10;
		tmp1 += a[i] % 2;
		ans  += a[i];
	}
	if (!tmp) {   //全て１０で割り切れる
		printf("0\n"); return 0;
	}
	if (ans % 10) { //１０で割り切れない
		printf("%d\n", ans); return 0;
	}

	unsigned int  bit = 1 << n;
	ans = 0;
	for (unsigned int k = 0; k < bit; k++) {
		tmp = 0;

		for (i = 0; i < n; i++) {
			if ((k >> i) & 1)
				tmp += a[i];
		}
		//		printf("\n%d ",tmp);
		if (tmp % 10)
			ans = _max(ans, tmp);
	}
	printf("%d\n", ans);
	return 0;
}

Score : 300 points

Problem Statement

You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.

However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

Constraints

All input values are integers.

1 ≤ N ≤ 100

1 ≤ s_i ≤ 100

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the maximum value that can be displayed as your grade.

Sample Input 1

3
5
10
15

Sample Output 1

25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.

Sample Input 2

3
10
10
15

Sample Output 2

35

Your grade will be 35 if all the questions are answered correctly, and this grade will be displayed correctly.

Sample Input 3

3
10
20
30

Sample Output 3

0

Regardless of whether each question is answered correctly or not, your grade will be a multiple of 10 and displayed as 0.


#include<stdio.h>

int main(void){
  int a,i,j,sum=0,temp;
  int score[100];
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&score[i]);
    sum+=score[i];
  }
  for(i=0;i<a-1;i++){
    for(j=i+1;j<a;j++){
      if(score[i]>score[j]){
        temp=score[i];
        score[i]=score[j];
        score[j]=temp;
      }
    }
  }
  i=0;
  while(i<a){
    if((sum%10)!=0)
      break;
    sum-=score[i];
    i++;
  }
  printf("%d\n",sum);
  return 0;
}


Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.

Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:

Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.

At least how many explosions do you need to cause in order to vanish all the monsters?

Constraints

All input values are integers.

1 ≤ N ≤ 10^5

1 ≤ B < A ≤ 10^9

1 ≤ h_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N A B
h_1
h_2
:
h_N

Output

Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.

Sample Input 1

4 5 3
8
7
4
2

Sample Output 1

2

You can vanish all the monsters in two explosion, as follows:

First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.

Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.

Sample Input 2

2 10 4
20
20

Sample Output 2

4

You need to cause two explosions centered at each monster, for a total of four.

Sample Input 3

5 2 1
900000000
900000000
1000000000
1000000000
1000000000

Sample Output 3

800000000


Score : 100 points

Problem Statement

Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

Constraints

x and y are integers.

1 ≤ x < y ≤ 12

Input

Input is given from Standard Input in the following format:

x y

Output

If x and y belong to the same group, print Yes; otherwise, print No.

Sample Input 1

1 3

Sample Output 1

Yes

Sample Input 2

2 4

Sample Output 2

No


Score : 200 points

Problem Statement

You are given a image with a height of H pixels and a width of W pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the i-th row from the top and j-th column from the left is a_{ij}.

Put a box around this image and output the result. The box should consist of # and have a thickness of 1.

Constraints

1 ≤ H, W ≤ 100

a_{ij} is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

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

Output

Print the image surrounded by a box that consists of # and has a thickness of 1.

Sample Input 1

2 3
abc
arc

Sample Output 1

#####
#abc#
#arc#
#####

Sample Input 2

1 1
z

Sample Output 2

###
#z#
###


Score : 400 points

Problem Statement

There is a bar of chocolate with a height of H blocks and a width of W blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.

Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.
Find the minimum possible value of S_{max} - S_{min}.

Constraints

2 ≤ H, W ≤ 10^5

Input

Input is given from Standard Input in the following format:

H W

Output

Print the minimum possible value of S_{max} - S_{min}.

Sample Input 1

3 5

Sample Output 1

0

In the division below, S_{max} - S_{min} = 5 - 5 = 0.

Sample Input 2

4 5

Sample Output 2

2

In the division below, S_{max} - S_{min} = 8 - 6 = 2.

Sample Input 3

5 5

Sample Output 3

4

In the division below, S_{max} - S_{min} = 10 - 6 = 4.

Sample Input 4

100000 2

Sample Output 4

1

Sample Input 5

100000 100000

Sample Output 5

50000


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

int mins(int x, int y, int z)
{
int min = x;
int max =x;
if (y < min) min = y;
if (z < min) min = z;
if (y > max) max = y;
if (z > max) max = z;
return max-min;
}

int main(){
int H,W,i,j,k,l,S;
scanf("%d %d",&H,&W);

j=(H/3)*W;
k=(H-H/3)/2*W;
l=W*H-j-k;
S=mins(j,k,l);

for(i=0;i<2;i++){
j=(H/3+i)*W;
k=W/2*(H-H/3-i);
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}

for(i=0;i<2;i++){
j=(W/3+i)*H;
k=(W-W/3-i)/2*H;
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}

for(i=0;i<2;i++){
j=(W/3+i)*H;
k=H/2*(W-W/3-i);
l=W*H-j-k;
if(mins(j,k,l)<S) S=mins(j,k,l);
}

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


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

Score : 100 points

Problem Statement

You are given three integers A, B and C.
Determine whether C is not less than A and not greater than B.

Constraints

-100≤A,B,C≤100

A, B and C are all integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

If the condition is satisfied, print Yes; otherwise, print No.

Sample Input 1

1 3 2

Sample Output 1

Yes

C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.

Sample Input 2

6 5 4

Sample Output 2

No

C=4 is less than A=6, and thus the output should be No.

Sample Input 3

2 2 2

Sample Output 3

Yes


#include <stdio.h>

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

    int a, b, s = 0;
    for (int n = 0; n < N; n++) {
        scanf("%d %d", &a, &b);
        s += b;
        if (K <= s) {
            printf("%d", a);
            return 0;
        }
    }
}

Score : 300 points

Problem Statement

There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

Constraints

1≤N≤10^5

1≤a_i,b_i≤10^5

1≤K≤b_1…+…b_n

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Sample Input 1

3 4
1 1
2 2
3 3

Sample Output 1

3

The resulting array is the same as the one in the problem statement.

Sample Input 2

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Sample Output 2

1


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

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

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

struct edge {
    int src;
    int dst;
    int64_t npoint;
};

#define VERTEX_MAX 1000
#define EDGE_MAX 2000
#define INF (1LL<<50)

int main(void) {
    int vs, es;
    struct edge edges[EDGE_MAX];
    get_int2(&vs, &es);
    int i, j;
    for(i = 0; i < es; i++) {
        int src, dst, np;
        get_int3(&src, &dst, &np);
        // 1-indexed -> 0-indexed
        src--; dst--;
        // directed graph
        edges[i] = (struct edge){src, dst, -np};
    }

    static int64_t min_dist[VERTEX_MAX];
    for(i = 0; i < vs; i++) {
        min_dist[i] = INF;
    }
    min_dist[0] = 0;
    // bellman
    for(i = 0; i < vs; i++) {
        int flag = 0;
        for(j = 0; j < es; j++) {
            struct edge e = edges[j];
            if(min_dist[e.src] == INF) continue;
            int64_t new = min_dist[e.src] + e.npoint;
            if(min_dist[e.dst] > new) {
                flag = 1;
                min_dist[e.dst] = new;
            }
        }
        if(!flag) break;
    }

    // check negative cycle( by bellman-ford algorithm )
    int check_negative[VERTEX_MAX]; // default=0
    for(i = 0; i < vs; i++) {
        for(j = 0; j < es; j++) {
            struct edge e = edges[j];
            int64_t new = min_dist[e.src] + e.npoint;
            if(min_dist[e.dst] > new) {
                check_negative[e.dst] = 1;
                min_dist[e.dst] = new;
            }
            if(check_negative[e.src]) {
                check_negative[e.dst] = 1;
            }
        }
    }

    if(check_negative[vs-1]) {
        printf("inf\n");
    } else {
        printf("%lld\n", -min_dist[vs-1]);
    }

    return 0;
}

Score : 400 points

Problem Statement

There is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.

Initially, the piece is placed at vertex 1, and the score of the player is set to 0.
The player can move the piece as follows:

When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.

The player can end the game only when the piece is placed at vertex N.
The given graph guarantees that it is possible to traverse from vertex 1 to vertex N.

When the player acts optimally to maximize the score at the end of the game, what will the score be?
If it is possible to increase the score indefinitely, print inf.

Constraints

2≤N≤1000

1≤M≤min(N(N-1),2000)

1≤a_i,b_i≤N (1≤i≤M)

a_i≠b_i (1≤i≤M)

a_i≠a_j or b_i≠b_j (1≤i<j≤M)

-10^9≤c_i≤10^9 (1≤i≤M)

c_i is an integer.

In the given graph, there exists a path from vertex 1 to vertex N.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print inf.

Sample Input 1

3 3
1 2 4
2 3 3
1 3 5

Sample Output 1

7

There are two ways to move the piece to vertex N=3:

vertex 1 → vertex 2 → vertex 3 : score 4+3=7

vertex 1 → vertex 3 : score 5

Thus, the maximum possible score at the end of the game is 7.

Sample Input 2

2 2
1 2 1
2 1 1

Sample Output 2

inf

It is possible to increase the score indefinitely by alternating between vertex 1 and 2.

Sample Input 3

6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000

Sample Output 3

-5000000000


#include<stdio.h>

int main(){
	long ans=0;
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a==b&&b==c)puts("-1");
	else {
		while(a%2==0&&b%2==0&&c%2==0){
			long aa=a/2,bb=b/2,cc=c/2;
			a=0,b=0,c=0;
			a=bb+cc;
			b=cc+aa;
			c=aa+bb;
			ans++;
		}
		printf("%ld\n",ans);
	}
	return 0;
}

Score : 300 points

Problem Statement

Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below:

Each person simultaneously divides his cookies in half and gives one half to each of the other two persons.

This action will be repeated until there is a person with odd number of cookies in hand.

How many times will they repeat this action?
Note that the answer may not be finite.

Constraints

1 ≤ A,B,C ≤ 10^9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times the action will be performed by the three people, if this number is finite.
If it is infinite, print -1 instead.

Sample Input 1

4 12 20

Sample Output 1

3

Initially, Takahashi, Aoki and Snuke have 4, 12 and 20 cookies. Then,

After the first action, they have 16, 12 and 8.

After the second action, they have 10, 12 and 14.

After the third action, they have 13, 12 and 11.

Now, Takahashi and Snuke have odd number of cookies, and therefore the answer is 3.

Sample Input 2

14 14 14

Sample Output 2

-1

Sample Input 3

454 414 444

Sample Output 3

1


#include "stdio.h"

int main(){

	int a,b,c,a1,b1,c1;

	scanf("%d %d %d",&a,&b,&c);

	int count=0;

	while(1){
		if((a%2==1)||(b%2==1)||(c%2==1)){
			break;
		}

		if((a==b)&&(a==c)){
			count=-1;
			break;
		}

		a1=a,b1=b,c1=c;//can i group together for one row?//ok

		a=(b1+c1)/2;
		b=(c1+a1)/2;
		c=(a1+b1)/2;//can i group together with the above//ok

		count++;
	}

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


Score : 100 points

Problem Statement

You are given three strings A, B and C. Check whether they form a word chain.

More formally, determine whether both of the following are true:

The last character in A and the initial character in B are the same.

The last character in B and the initial character in C are the same.

If both are true, print YES. Otherwise, print NO.

Constraints

A, B and C are all composed of lowercase English letters (a - z).

1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

rng gorilla apple

Sample Output 1

YES

They form a word chain.

Sample Input 2

yakiniku unagi sushi

Sample Output 2

NO

A and B form a word chain, but B and C do not.

Sample Input 3

a a a

Sample Output 3

YES

Sample Input 4

aaaaaaaaab aaaaaaaaaa aaaaaaaaab

Sample Output 4

NO


int main(){
    char str[27]={'\0'};
    scanf("%s",str);
    int flag=0;
    for(int i=0;i<strlen(str);i++){
        for(int j=i+1;j<strlen(str);j++)
        if(str[i]==str[j]){printf("no");flag=1;break;}
        if(flag==1)break;
    }
    if(flag==0)printf("yes");
    return 0;
    }


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

 long int a,b,c,i;
  scanf("%ld %ld %ld",&a,&b,&c);
  for(i=1;i<=b;i++)
  {
      if(i*a%b==c)
      {
          printf("YES");
      }else{
          printf("NO");
      }

  }
    return 0;
}

Score : 200 points

Problem Statement

We ask you to select some number of positive integers, and calculate the sum of them.

It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.

Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.

If the objective is achievable, print YES. Otherwise, print NO.

Constraints

1 ≤ A ≤ 100

1 ≤ B ≤ 100

0 ≤ C < B

Input

Input is given from Standard Input in the following format:

A B C

Output

Print YES or NO.

Sample Input 1

7 5 1

Sample Output 1

YES

For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.

Sample Input 2

2 2 1

Sample Output 2

NO

The sum of even numbers, no matter how many, is never odd.

Sample Input 3

1 100 97

Sample Output 3

YES

You can select 97, since you may select multiples of 1, that is, all integers.

Sample Input 4

40 98 58

Sample Output 4

YES

Sample Input 5

77 42 36

Sample Output 5

NO


#include<stdio.h>
#define MAX 10000000
int main(){
    int a,b,c;
    int m=1;
    scanf("%d%d%d",&a,&b,&c);
    for(m=1;m<=MAX;m++){
        if(m*a%b==c){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}


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

int main(){
  char s1[10],s2[10],s3[10];
  scanf("%s %s %s", &s1,&s2,&s3);

  char RYAKUGO[3+1];
  memset(RYAKUGO,'\0',sizeof(RYAKUGO));
  RYAKUGO[0] = toupper(s1[0]);
  RYAKUGO[1] = toupper(s2[0]);
  RYAKUGO[2] = toupper(s3[0]);
  printf("%s",RYAKUGO);
}

Score : 100 points

Problem Statement

You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.
Print the acronym formed from the uppercased initial letters of the words.

Constraints

s_1, s_2 and s_3 are composed of lowercase English letters.

1 ≤ |s_i| ≤ 10 (1≤i≤3)

Input

Input is given from Standard Input in the following format:

s_1 s_2 s_3

Output

Print the answer.

Sample Input 1

atcoder beginner contest

Sample Output 1

ABC

The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.

Sample Input 2

resident register number

Sample Output 2

RRN

Sample Input 3

k nearest neighbor

Sample Output 3

KNN

Sample Input 4

async layered coding

Sample Output 4

ALC


// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a[11], b[11], c[11];
  scanf("%s%s%s", a, b, c);
  printf("%c%c%c\n", a[0] - 32, b[0] - 32, c[0] - 32);
  return 0;
}


#include<stdio.h>

int main(void)
{
  int a, b = 0;

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

  if(a > b) printf("GREATER\n");
  else if(a < b)  printf("LESS\n");
  else  printf("EQUAL\n");

  return 0;
}

Score : 200 points

Problem Statement

You are given two positive integers A and B. Compare the magnitudes of these numbers.

Constraints

1 ≤ A, B ≤ 10^{100}

Neither A nor B begins with a 0.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print GREATER if A>B, LESS if A<B and EQUAL if A=B.

Sample Input 1

36
24

Sample Output 1

GREATER

Since 36>24, print GREATER.

Sample Input 2

850
3777

Sample Output 2

LESS

Sample Input 3

9720246
22516266

Sample Output 3

LESS

Sample Input 4

123456789012345678901234567890
234567890123456789012345678901

Sample Output 4

LESS


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

#define P 1000000007

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

int main(void){
	int n, i;
	int a[100001];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}
	int n1=0, n2=0;
	{
		int sum=0;
		int f=0;
		for(i=0; i<n; i++){
			sum += a[i];
			if(f){
				if(sum<=0){n1=n1+1-sum; sum=1;}
			}else{
				if(sum>=0){n1=n1+1+sum; sum=-1;}
			}
			f=!f;
		}
	}
	{
		int sum=0;
		int f=1;
		for(i=0; i<n; i++){
			sum += a[i];
			if(f){
				if(sum<=0){n2=n2+1-sum; sum=1;}
			}else{
				if(sum>=0){n2=n2+1+sum; sum=-1;}
			}
			f=!f;
		}
	}
	printf("%ld\n", n1<n2?n1:n2);
}

Score : 300 points

Problem Statement

You are given an integer sequence of length N. The i-th term in the sequence is a_i.
In one operation, you can select a term and either increment or decrement it by one.

At least how many operations are necessary to satisfy the following conditions?

For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero.

For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term.

Constraints

2 ≤ n ≤ 10^5

|a_i| ≤ 10^9

Each a_i is an integer.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print the minimum necessary count of operations.

Sample Input 1

4
1 -3 1 0

Sample Output 1

4

For example, the given sequence can be transformed into 1, -2, 2, -2 by four operations. The sums of the first one, two, three and four terms are 1, -1, 1 and -1, respectively, which satisfy the conditions.

Sample Input 2

5
3 -6 4 -5 7

Sample Output 2

0

The given sequence already satisfies the conditions.

Sample Input 3

6
-1 4 3 2 -5 4

Sample Output 3

8


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

#define N 150000
#define MAX 1500000

int main(void) {
  int n;  //数列の長さ（要素の数）
  long sum1 = 0;  //奇数番目の要素の合計値
  long sum2 = 0;  //偶数番目の要素の合計値
  long tmp; //1, -1の繰り返し計算用temp
  long lcount = 0;  //奇数+, 偶数-のパターン
  long rcount = 0;  //奇数-, 偶数+のパターン
  long a[N]; //入力各要素（数字）
  char input[MAX];  //入力文字列
  int i = 0,j = 0;  //for文用（jは使ってない）
  int cp = 0,tcp = 0; //tp, input用の何文字目かを示すカウンタ
  char tp[12];  //入力処理用のtemp
  tp[12] = '\0';  //初期化
  fgets(input, MAX, stdin);
  n = atoi(input);  //nに入力を受け取る

  fgets(input, MAX, stdin);  //各要素を受け取る

  //printf("%s\n",input);
  for(i = 0; i < n;  i++){
    while(input[cp] != ' ' && input[cp] != '\n'){ //スペースまで入力を切る
      tp[tcp] = input[cp];
      tcp++;
      cp++;
    }
    tp[tcp] = '\0';
    tcp = 0;
    cp++;
    a[i] = atoi(tp);
    //printf("i:%d tp:%s a[%d]:%d\n",i,tp,i,a[i]);

  }
  //init
/*  for(i = 0; i < n; i++){ //要素を偶奇番目毎に足し合わせる
    if(i % 2 == 0) sum2 += a[i];
    else sum1 += a[i];
    //printf("%d %d %d %d\n",i,a[i],sum1,sum2 );
  }*/
  tmp = 0;
/*  if(sum1 == sum2){
    if(a[0] < 0){
      sum1++;
    }else{
      sum2++;
    }
  }*/
  for(i = 0; i < n; i++){ //偶数番目が-1以下になるまで引いて操作カウントをインクリメント
      if(i % 2 == 0){
        tmp += a[i];
        if(tmp > -1){
          lcount += tmp + 1;
          tmp = -1;
          //printf("hoge1\n" );
        }
      } else {  //奇数番目が1以上になるまで足して操作カウントをインクリメント
        tmp += a[i];
        if(tmp < 1){
          lcount += 1 - tmp;
          tmp = 1;
          //printf("hoge2\n" );
        }
      }
  }
  tmp = 0;
  for(i = 0; i < n; i++){ //奇数番目が-1以下になるまで引いて操作カウントをインクリメント
      if(i % 2 == 1){
        tmp += a[i];
        if(tmp > -1){
          rcount += tmp + 1;
          tmp = -1;
          //printf("hoge3\n" );
        }
      } else {  //偶数番目が1以上になるまで足して操作カウントをインクリメント
        tmp += a[i];
        if(tmp < 1){
          rcount += 1 - tmp;
          tmp = 1;
          //printf("hoge4\n" );
        }
      }
  }
  printf("%ld\n",lcount > rcount?rcount:lcount);  //l>rならr, そうでないならl（rの砲方が小さいならr）
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)

void fill(int a[],int b,int c){
 	for(int i=0;i<b;i++) a[i]=c;
 	return;
}

int comp(const void *a,const void *b){
    return *(int*)a - *(int*)b;
}
int a[100000];
int main(void)
{
    int n,i,ans=1;
    int size=0;
    scanf("%d",&n);
    FOR(i,0,n){
        scanf("%d",&a[size]);
        if(size>0&&a[size]==a[size-1]) size--;
        size++;
    };
    for(i=0;i<size-2;){
        if(a[i+1]-a[i]>0&&a[i+2]-a[i+1]<0) ans++,i+=2;
        else if(a[i+1]-a[i]<0&&a[i+2]-a[i+1]>0) ans++,i+=2;
        else i++;
    }
    printf("%d\n",ans);
 	return 0;
}

Score : 300 points

Problem Statement

You are given an array A of length N.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide A into?

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Each A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible number of subarrays after division of A.

Sample Input 1

6
1 2 3 2 2 1

Sample Output 1

2

One optimal solution is to divide the array into [1,2,3] and [2,2,1].

Sample Input 2

9
1 2 1 2 1 2 1 2 1

Sample Output 2

5

Sample Input 3

7
1 2 3 2 1 999999999 1000000000

Sample Output 3

3


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

Score : 100 points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

Determine whether the arrangement of the poles is beautiful.

Constraints

1 \leq a,b,c \leq 100

a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.

Sample Input 1

2 4 6

Sample Output 1

YES

Since 4-2 = 6-4, this arrangement of poles is beautiful.

Sample Input 2

2 5 6

Sample Output 2

NO

Since 5-2 \neq 6-5, this arrangement of poles is not beautiful.

Sample Input 3

3 2 1

Sample Output 3

YES

Since 1-2 = 2-3, this arrangement of poles is beautiful.


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

int main(void) {
    char o[51], *e[51];
    char pw[101];

    scanf("s", o);
    scanf("s", e);

    for(int i = 0; i < strlen(o) + strlen(e); i++) {
        int indexO = 0, indexE = 0;
        if(i % 2 == 0) {
           pw[i] =  o[indexO];
           indexO++;
        }
        if(i % 2 == 1) {
           pw[i] =  e[indexE];
           indexE++;
        }
    }
}


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

int main(void)
{

  int a, b, c;
  scanf("%d, %d, %d", &a, &b, &c);

  int p, q;
  p = b-a;
  q = c-b;

  if(p==q)
    {
      printf("YES");
    }
  else
    printf("NO");

  return 0;
}


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

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

int main(void) {
	int n;
	char str[50][51];

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

	qsort(str[0],strlen(str[0]),sizeof(char),compare);

	for (int i = 1;i < n;i++) {
		for (int j = 0;j < strlen(str[0]);j++) {
			bool flag = false;
			if (str[0][j] == ' ') {
				continue;
			}
			for (int k = 0;k < strlen(str[i]);k++) {
				if (str[0][j] == str[i][k]) {
					str[i][k] = ' ';
					flag = true;
					break;
				}
			}
			if (!flag) {
				str[0][j] = ' ';
			}
		}
	}

	for (int i = 0;i < strlen(str[0]);i++) {
		if (str[0][i] != ' '){
			printf("%c",str[0][i]);
		}
	}
	printf("\n");

	return 0;
}

Score : 300 points

Problem Statement

Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.

He will receive a headline which contains one of the strings S_1,...,S_n tomorrow.
He is excited and already thinking of what string he will create.
Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.

Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains.
If there are multiple such strings, find the lexicographically smallest one among them.

Constraints

1 \leq n \leq 50

1 \leq |S_i| \leq 50 for every i = 1, ..., n.

S_i consists of lowercase English letters (a - z) for every i = 1, ..., n.

Input

Input is given from Standard Input in the following format:

n
S_1
...
S_n

Output

Print the lexicographically smallest string among the longest strings that satisfy the condition.
If the answer is an empty string, print an empty line.

Sample Input 1

3
cbaa
daacc
acacac

Sample Output 1

aac

The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth.
Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.

Sample Input 2

3
a
aa
b

Sample Output 2

The answer is an empty string.