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

struct node{
	void *data;
	struct node *next;
	struct node *prev;
};

struct point{
	int x;
	int y;
};

typedef struct node *NodePointer;

NodePointer nil;

void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void deleteNode(NodePointer t){
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t->data);
	free(t);
}

void backInsert(void *p,int len){
	NodePointer t;
	t = malloc(sizeof(struct node));
	t->data = malloc(len);
	memcpy(t->data,p,len);
	t->next = nil;
	t->prev = nil->prev;
	t->prev->next = t;
	nil->prev = t;
}

void deleteFirst(){
	NodePointer t = nil->next;
	if(t == nil){
		return;
	}
	deleteNode(t);
}

void deleteAll(){
	NodePointer t = nil->next;
	while(t != nil){
		deleteNode(t);
	}
}

void pop(void *np,int len){
	memcpy(np,nil->next->data,len);
	deleteFirst();
}

int main(int argc, char **argv)
{
	int *square;
	char temp[1000];
	int count = 0;
	int r = 0;
	int c = 0;
	int i = 0;
	int j = 0;
	struct point dif[4] = {{0,-1},{1,0},{0,1},{-1,0}};

	scanf("%d%d",&r,&c);
	init();

	square = malloc(sizeof(int) * (r * c));

	for(i = 0;i < r;i++){
		scanf("%s",temp);
		for(j = 0;j < c;j++){
			if(temp[j] == '#'){
				square[i * c + j] = 0;
				struct point *blackPoint = malloc(sizeof(struct node));
				blackPoint->x = j;
				blackPoint->y = i;
				backInsert(blackPoint,sizeof(blackPoint));
			}
			else{
				square[i * c + j] = -1;
			}
		}
	}

	while(nil->next != nil){
		struct point currentPoint;
		pop(&currentPoint,sizeof(currentPoint));
		struct point nextPoint;

		for(i = 0;i < 4;i++){
			nextPoint.x = currentPoint.x + dif[i].x;
			nextPoint.y = currentPoint.y + dif[i].y;
			// if((nextPoint.y) * c + (nextPoint.x) < 0 || r * c < (nextPoint.y) * c + (nextPoint.x) ||
			// 	(nextPoint.x) == c || (nextPoint.x) == -1){
			// }
			if((0 <= nextPoint.x) && (nextPoint.x <= (c-1)) &&
					(0 <= nextPoint.y) && (nextPoint.y <= (r-1)) && (square[nextPoint.y * c + nextPoint.x] == -1)){
				struct point pointP;
				pointP.x = nextPoint.x;
				pointP.y = nextPoint.y;
				backInsert(&pointP,sizeof(pointP));
				square[(nextPoint.y) * c + (nextPoint.x)] = square[(currentPoint.y * c) + currentPoint.x] + 1;
				count = square[(nextPoint.y) * c + (nextPoint.x)];
				// printf("%d\n",(((nextPoint.y) * c)));
				// printf("%d\n",((nextPoint.x)));
				// printf("\n");
			}

		}

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

	//deleteAll();
	free(nil);
	return 0;
}


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

typedef enum {false, true} bool;

int main(void)
{
    int H, W;
    int HxW;
    bool *A;
    int *Q;
    char c;
    int i, j;
    int front, rear;
    int ctr;
    bool flag;

    scanf("%d%c%d%c", &H, &c, &W, &c);

    HxW = H*W;

    A = (bool*)malloc(sizeof(bool)*HxW);
    Q = (int*)malloc(sizeof(int)*HxW);

    front = rear = 0;

    for(i=0; i<H; i++)
    {
        for(j=0; j<W; j++)
        {
            scanf("%c", &c);

            if(c == '.')
                A[i*H+j] = false;
            else
            {
                A[i*H+j] = true;
                Q[rear++] = i*H+j;
            }
        }
        scanf("%c", &c);
    }

    ctr = 0;

    while(front != rear)
    {
        flag = false;

        i = rear-front;

        while(i-- > 0)
        {

            if(Q[front]%W > 0 && Q[front]-1 >= 0 && !A[Q[front]-1])
            {
                A[Q[front]-1] = true;
                Q[rear++] = Q[front]-1;

                flag = true;
            }

            if((Q[front]+1)%W > 0 && Q[front]+1 < HxW  && !A[Q[front]+1])
            {
                A[Q[front]+1] = true;
                Q[rear++] = Q[front]+1;

                flag = true;
            }

            if(Q[front]-W >= 0 && !A[Q[front]-W])
            {
                A[Q[front]-W] = true;
                Q[rear++] = Q[front]-W;

                flag = true;
            }

            if(Q[front]+W < HxW  && !A[Q[front]+W])
            {
                A[Q[front]+W] = true;
                Q[rear++] = Q[front]+W;

                flag = true;
            }

            front++;
        }

        if(flag)
            ctr++;
    }

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

    free(A);
    free(Q);

    //system("pause");

    return 0;
}

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

Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3

Submitted source-code file size, in bytes.

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

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


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

int check(char **s, int h, int w, int hei, int wid) {
    int end = (h > w) ? h : w;
    int a = 0, b = 0, c = 0;
    for (int i=1; i<=end; i++) {
        for (int j=-i; j<=i; j++) {
            if (((c = wid+j) > w-1) || (c < 0)) continue;
            if (!((a = hei+i-abs(j)) > h-1)) {
                if (s[a][c] == '#') return i;
            }
            if (!((b = hei-i+abs(j)) < 0)) {
                if (s[b][c] == '#') return i;
            }
        }
    }
    return -1;
}

int main() {
    int h = 0, w = 0;
    scanf("%d %d\n", &h, &w);
    char s[h][w+2];
    char *s_ch[h];
    for (int i=0; i<h; i++) {
        fgets(s[i], w+2, stdin);
        s_ch[i] = s[i];
    }
    int max = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (s[i][j] == '.') {
                int buf = check(s_ch, h, w, i, j);
                if (buf > max) max = buf;
            }
        }
    }
    printf("%d\n", max);
    return 0;
}


#include<stdio.h>

int main() {
   int N,r,tmp;
   int max = 1;
   scanf("%d",&N);
   int A[N];
   for(int i = 0; i < N; i++) {
      scanf("%d",&A[i]);
   }
   for(int i = 0; i < N-1; i++) {
      for(int j = i+1; j < N; j++) {
         if(A[i] < A[j]) {
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
         }
         r = A[i] % A[j];
         while(r != 0) {
            A[i] = A[j];
            A[j] = r;
            r = A[i] % A[j];
         }
         if(max < A[j]) {
            max = A[j];
         }
      }
   }
   for(int i = 0; i < N ; i++) {
      if(A[i] % max != 0) {
         A[i] = max;
      }
   }
   printf("%d\n",max);
}

Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.


#include<stdio.h>
#include<math.h>
long gcd(long a,long b){
 // printf("%ld %ld\n",a,b);
if(a<b){
  long w=a;
  a=b;
  b=w;
}

  if(a%b!=0)return gcd(b,a%b);
  else return b;
}
int main(void){
int n;
  scanf("%d",&n);
  long a[n];
  for(int i=0;i<n;i++){
   	scanf("%ld",&a[i]);
  }
  long l[n],r[n];
  l[0]=a[0];
 // printf("%ld ",l[0]);
  for(int i=1;i<n;i++){
	l[i]=gcd(l[i-1],a[i]);
   // printf("%ld ",l[i]);
  }
  //printf("\n");
  r[n-1]=a[n-1];
  //printf("%ld ",r[n-1]);
  for(int i=1;i<n;i++){
	r[n-1-i]=gcd(r[n-i],a[n-1-i]);
  //  printf("%ld ",r[n-1-i]);
  }
 // printf("\n");
  long max=1000000001;
  for(int i=0;i<n;i++){
    long yaku;
    if(i==0)yaku=r[i+1];
    else if(i==n-1)yaku=l[n-1-i];
    else yaku=gcd(l[i-1],r[i+1]);
    if(yaku<max)max=yaku;
  }
  printf("%ld",max);

      return 0;
    }


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int a[100005],b[100005];
int fun(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
void px(int x,int y)
{
    if(x>=y) return;
    int mid=(x+y)/2;
    px(x,mid);
    px(mid+1,y);
    int z=x,k=mid+1,ans=0;
    while(z<=mid&&k<=y)
    {
        if(a[z]<=a[k])
        b[ans++]=a[z++];
        else
            b[ans++]=a[k++];
    }
    for(int i=z;i<=mid;i++)
        b[ans++]=a[i];
    for(int i=k;i<=y;i++)
        b[ans++]=a[i];
    for(int i=x,j=0;i<=y;i++)
        a[i]=b[j++];
}
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    int vp[n];
    for(int i=0;i<n;i++)
        scanf("%d",&vp[i]);
    if(n==2)
        goto end;

    if(fun(vp[0])==1)
    {
        int m=vp[0];
        vp[0]=vp[2];
        vp[2]=m;
    }
    if(fun(vp[1])==1)
    {
        int m=vp[1];
        vp[1]=vp[2];
        vp[2]=m;
    }
    int x=vp[0],y=vp[1];
    while(x%y)
        {
            int z=y;
            y=x%y;
            x=z;
        }
        a[ans++]=y;
    for(int i=2;i<n;i++)
    {
        x=y;
        y=vp[i];
        if(x<y)
        {
            int z=x;
            x=y;
            y=z;
        }
        while(x%y)
        {
            int z=y;
            y=x%y;
            x=z;
        }

        a[ans++]=y;

    }
    px(0,n-2);
   end: if(n==2)
    {
        vp[0]=vp[0]<vp[1]?vp[1]:vp[0];
        printf("%d",vp[0]);
    }
       else
        printf("%d",a[1]);

}


#include <stdio.h>

int gcd(a, b){
  if(a == 0 || b == 0) return a + b;
  if(b > a) return gcd(b, a);
  return gcd(b, a % b);
}

void update(int i, int x, int *seg, int k){
  seg[k - 1 + i] = x;
  while(k > 0){
    for(int j = 0; j < k/2; j++){
      seg[(k - 1 + 2 * j)/2] = gcd(seg[k - 1 + 2 * j], seg[k + 2 * j]);
    }
    k /= 2;
  }
  return;
}

int
main(int artc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int k = 1;
  while(n > k) k *= 2;
  int seg[500000] = {};
  for(int i = 0; i < n; i++){
    scanf("%d", &seg[k - 1 + i]);
  }

  int ans = 0; int temp;
  for(int i = 0; i < n; i++){
    temp = seg[k - 1 + i];
    update(i, 0, seg, k);
    ans = (ans > seg[0] ? ans : seg[0]);
    update(i, temp, seg, k);
  }

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

  return 0;
}


#include<stdio.h>

int max(int a,int b){

  if(a>b){
    return a;
  }else{
    return b;
  }

}

int gcd(int a,int b){
  int r,tmp;
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  r=a%b;
  while(r!=0){
  a=b;
  b=r;
  r=a%b;
}

  return b;
}

int main(void){
  int n;
  int a[12000];
  int i;
  int ans=0;
  int p[12000];
  int q[12000];
  int tmpg;
  int tmpt;
  int tmps;

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

  p[0]=a[0];
  tmpg=a[0];

  for(i=1;i<n-1;i++){
    tmpg=gcd(a[i],tmpg);
    p[i]=tmpg;
  }
  q[n-1]=a[n-1];
  tmpt=a[n-1];

  for(i=(n-2);i>0;i--){
    tmpt=gcd(a[i],tmpt);
    q[i]=tmpt;
    }

  ans=max(p[n-2],q[1]);

  for(i=1;i<n-1;i++){
      tmps=gcd(p[i-1],q[i+1]);
      if(tmps>ans){
        ans=tmps;
      }
  }

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

  return 0;
}


#include <stdio.h>

int main(){
	int i,j;
	int n;
	int a[100000];
	int good,koho,tujo=0,min=1000000001,max;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",a+i);
		if(a[0]!=a[i]){
			tujo=1;
		}
	}
	if(!tujo){
		printf("%d\n",a[0]);
		return 0;
	}
	for(i=0;i<n;i++){
		if(min>a[i]){
			min=a[i];
		}
		if(max<a[i]){
			max=a[i];
		}
	}
	max/=2;
	for(i=2;i<=min;i++){
		if(i>max){
			i=min;
		}
		good=0;
		for(j=0;j<n;j++){
			if(a[j]<i){
				break;
			}else if(a[j]%i==0){
				good++;
			}
		}
		if((n-good)<=1){
			koho=i;
		}
	}
	printf("%d\n",koho);
	return 0;
}


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

int main() {
    int N, i, j, finalcount=0;
    int max=1, min;

    int size;
    scanf("%d", &N);

    int A[N];

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

    for(i=0; i<N; ++i){
        if(max < A[i]) max = A[i];
    }

    min = max;

    for(i=0; i<N; ++i){
        if(min > A[i]) min = A[i];
    }

    if(max == min){
        printf("%d\n", A[0]);
    } else {

    size = max - min;
    size = max;
    printf("size = %d\n", size);

    int B[size];

    for(i=0; i <= size; ++i){
        B[i] = 0;
    }

    for(i=0; i <= size; ++i){
        for(j=0; j<N; ++j){
            if(A[j]%(i+1)==0) B[i]+=1;
        }
    }

    i=size+1;

    while(finalcount == 0){
        i -= 1;
        if(B[i] >= N-1) finalcount += 1;
    }

    printf("%d\n", i+1);
    return 0;

    }
}


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

int N;
long *arr;
long i;

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

long calc(long *a, long *b){
    long r = *a % *b;
    while(r!=0){
        *a = *b;
        *b = r;
        r = *a % *b;
    }
    return *b;
}

int main(int argc, char *argv[])
{
    long y;
    scanf("%ld",&N);
    arr = (long*)malloc(N*sizeof(long));
    for (i = 0; i < N; i++) scanf("%ld",&arr[i]);
    qsort(arr, N ,sizeof(long),asc);
    y = calc(&arr[N],&arr[N-1]);
    printf("%ld", y);
    return 0;
}


#include<stdio.h>

int main(void){
  int n,i,j,ans,count,max=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(max<a[i]) max=a[i];
  }
  for(i=1;i<=max;i++){
    count=0;
    for(j=0;j<n;j++){
      if(a[j]%i!=0) count++;
    }
    if(count<=1) ans=i;
  }
  printf("%d\n",ans);
  return 0;
}


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

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

long long gcd(long long a,long long b){
	if(a%b==0)return b;
	return gcd(b,a%b);
}

int main(){
	int n,i;
	long long a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	if(n==2){
		printf("%lld\n",(a[0]>a[1]?a[0]:a[1]));
		return 0;
	}
	qsort(a,n,sizeof(long long),compare_int);
	long long aa=a[0],at=a[1];
	for(i=2;i<n;i++)aa=gcd(aa,a[i]);
	for(i=2;i<n;i++)at=gcd(a[i],at);
	printf("%lld\n",(aa>at?aa:at));
	return 0;
}


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

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

	printf("%d",b/a>=c?c:b/a);
	return 0;
}

Score : 100 points

Problem Statement

Takahashi likes the sound when he buys a drink from a vending machine.

That sound can be heard by spending A yen (the currency of Japan) each time.

Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time.

How many times will he hear the sound?

Constraints

All values in input are integers.

1 \leq A, B, C \leq 100

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times Takahashi will hear his favorite sound.

Sample Input 1

2 11 4

Sample Output 1

4

Since he has not less than 8 yen, he will hear the sound four times and be satisfied.

Sample Input 2

3 9 5

Sample Output 2

3

He may not be able to be satisfied.

Sample Input 3

100 1 10

Sample Output 3

0


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


#include <stdio.h>

int main() {
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if ((B/A)>=C) {
        printf("%d",C);
    }else{
        printf("%d",(int)B/A);
    }
    return 0;
}


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


#include<stdio.h>
int main(void){
  int A,B,C,c;
  scanf("%d %d %d",&A,&B,&C);
  c=0;
  while(B>0){
    B-=A;
    c++;
  }
  if(c>=C){
    c=C;
  }
  printf("%d",c);
  return 0;
}


#include <stdio.h>

int main(void)
{

	int a,b,c,i;

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

	if(a>b)
	{
		printf("0");
		return 1;
	}

	for(i=1; i<=c; i++)
	{
		if(b>a)
		{
			b=b-a;
		}
		else
		{
			printf("%d",i);
			return 1;
		}
	}

	printf("%d",i);

	return 0;
}


#include<stdio.h>
int main(){
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  printf("%d\n",B/A);
  return 0;
}


#include <stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  int d = b / a;
  if(d > c) { printf("%d\n", c); }
  else { printf("%d\n", d); }
  return 0;
}


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


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

int main(){
    int i,k=0,n,o=0,z=0;
    char s[10001];
    scanf("%s",s);
    n=strlen(s);
    for(i=0;i<n;i++){
        if(s[i]=='0')z+=2;
        else o+=2;
    }
    if(z>o)printf("%d\n",o);
    else printf("%d\n",z);
    return 0;
}


/* ex2_1
    riverstone*/

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

#define LIM 100100 //limit of num
int chmin(int a, int b);

int main(void){
    int i;
    int num, depth[LIM];//variable for N and matrix for depths
    int dp[LIM];//matrix for Dynamic Programming

    //input
    scanf("%d", &num);
    for (i = 0; i < num; i++){
        scanf("%d", &depth[i]);
    }

    //initialization
    dp[0] = 0;
    dp[1] = abs(depth[0] - depth[1]);

    //Dynamic Programming
    for (i = 2; i < num; i++){
        dp[i]+=chmin(abs(depth[i] - depth[i - 2]) + dp[i - 2], abs(depth[i] - depth[i - 1]) + dp[i - 1]);
    }
    printf("%d\n", dp[num-1]);//output the result
    return 0;
}

//min funciton
int chmin(int a, int b) {
    if (a <= b)
        return a;
    else
        return b;
}

Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

4
10 30 40 20

Sample Output 1

30

If we follow the path 1 → 2 → 4, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

2
10 10

Sample Output 2

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 3

6
30 10 60 10 60 50

Sample Output 3

40

If we follow the path 1 → 3 → 5 → 6, the total cost incurred would be |30 - 60| + |60 - 60| + |60 - 50| = 40.


#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define min(a, b) ((a) < (b) ? (a) : (b))

int main(void)
{
    int n, h[100100];
    scanf("%d", &n);
    rep(i, n)
        scanf("%d", &h[i]);

    int dp[100100] = {0};
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; i++)
        dp[i] += min(abs(h[i] - h[i - 2]) + dp[i - 2], abs(h[i] - h[i - 1]) + dp[i - 1]);

    printf("%d\n", dp[n - 1]);
    return 0;
}


/*
 * FileName:     A_fix
 * CreatedDate:  2020-02-22 19:50:24 +0900
 * LastModified: 2020-02-24 18:47:09 +0900
 */

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

#define inf 10000000
int min(int s, int t){
    if(s<t){
        return s;
    }
    else{
        return t;
    }
}
int main(void){
    int N;
    scanf("%d",&N);
    int i,h[N],dp[N];
    for(i=0;i<N;i++){
        scanf("%d",&h[i]);
        dp[i] = inf;
    }
    dp[0] = 0;
    for(i=0;i<N-2;i++){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    printf("%d\n",dp[N-1]);
    return 0;
}


#include<stdio.h>
int min(int a,int b){
if(a>b){
  return b;}
else{
  return a;
}}
int mod(int l,int h){
if(l>h){
  return l-h;}
else{
  return h-l;
}}
int ans(int arr[],int n){
  int c=0;
  if(n==2)
  {
      c=mod(arr[n-1],arr[0]);
  }
  if(n>2){
c=min(ans(arr,n-1)+mod(arr[n-2],arr[n-1]),ans(arr,n-2)+mod(arr[n-1],arr[n-3]));}
return c;
}
int main(){
  int n;
  int a;
  scanf("%d",&n);
  int arr[n];
  for(int i=0;i<n;i++){
    scanf("%d",&arr[i]);}
  a=ans(arr,n);
  printf("%d",a);
return 0;
}


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

int n;
int h[10010];
int dp[10010];

int chmin(int a, int b)
{
	if (a > b)
		return b;
	return a;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		dp[i] = 100000;
		scanf("%d", h+i);
	}
	dp[0] = 0;
	dp[1] = h[1] - h[0];
	for (int i = 2; i < n; i++)
	{
		dp[i] = chmin(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
	printf("%d", dp[n - 1]);
	return 0;
}


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

const int inf = 2e9;

int n, k = 2;
int h[100100], dp[100100];

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

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &h[i]);
    for (int i = 0; i < n; i++) dp[i] = inf;
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = i - 1; j >= i - k && j >= 0; j--) {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    printf("%d\n", dp[n - 1]);
}


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

#define max(a,b) \
  ({ __typeof__ (a) _a = (a); \
      __typeof__ (b) _b = (b); \
    _a > _b ? _a : _b; })

#define min(a,b) \
  ({ __typeof__ (a) _a = (a); \
      __typeof__ (b) _b = (b); \
    _a < _b ? _a : _b; })

int f(int k, int *h, int *g) {
    if (k == 0) return 0;
    if (k < 0) return INT_MAX / 2;
    if (g[k] != -1) {
        g[k] = f(k - 1, h, g) + abs(h[k] - h[k - 1]);
        g[k] = min(g[k], f(k - 2, h, g) + abs(h[k] - h[k - 1]));
    }
    return g[k];
}

int main(int argc, const char * argv[]) {
    int i = 0;
    scanf("%i", &i);
    int *h = malloc(sizeof(int) * i);
    int *g = malloc(sizeof(int) * i);
    for (int j = 0; j < i; j++) {
        scanf("%i", &h[j]);
        g[j] = -1;
    }
    printf("%i", f(i, h, g));

    free(g);
    free(h);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define INF 1000000
int height[100000]={0};
int n;

int min(int a,int b){
  return a<b ? a : b ;
}
int solve (int i){
  if (i==n) {
    return 0;
  }
  if(i>n)
    return INF;
  int some1=abs(height[i]-height[i+1])+solve(i+1);
  int some2=abs(height[i]-height[i+2])+solve(i+2);
  return min(some1,some2);
}
int main() {

  scanf("%d",&n);
for (int i = 1; i <=n; i++) {
  scanf("%d",&height[i]);
}
printf("%d",solve(1));
return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(){
    int N ;
    scanf("%d",&N);
    int i;
    int *data;

    data = (int*)malloc(sizeof(int)*N);
    for(int i=0;i<N;i++){

        scanf("%d",&data[i]);
    }
    long *dP;
    dP = (long*)malloc(sizeof(long)*N);

    dP[0] = 0;
    dP[1] = abs(data[1]-data[0]);
    for(i=2;i<N;i++){
        if(abs(data[i-1]-data[i])>abs(data[i-2]-data[i])){
            dP[i] = dP[i-2]+abs(data[i-2]-data[i]);
        }else dP[i] = dP[i-1]+abs(data[i-1]-data[i]);
    }
    printf("%ld\n",dP[N-1]);

    return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
long N;
long  h[100001];
long  dp[100001];
long  INF = 100000;

int
chmin(long  *a, long b)
{
	 if (*a > b){
		 *a = b; //	printf("%ld\n",*a);
		 return 1;
	 }
	 return 0;
}

int
main(){
	long int i;
	scanf("%ld",&N);
	for(i=0;i<N;i++){
		scanf("%ld",&h[i]);
		dp[i]=INF;
	}

	dp[0]=0;

	#if 0
	for(i=0;i<N;++i){
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    #endif
    for (i = 1; i < N; ++i) {
        dp[i]=fmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) dp[i]=fmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

	//for(i=0;i<N;i++){
		printf("%ld\n",dp[N-1]);

	//}

 return 0;
}


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

int solv(int n, int *h) {
  int min, d;

  if (n == 1) {
    return 0;
  }
  min = abs(h[0] - h[1]) + solv(n - 1, h + 1);
  if (n - 2 >= 1) {
    d = abs(h[0] - h[2]) + solv(n - 2, h + 2);
    if (min > d) {
      min = d;
    }
  }

  return min;
}

int main(int argc, char **argv) {
  int n, i, h[10000];

  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; i++) {
      scanf("%d", h + i);
    }

    printf("%d\n", solv(n, h));
  }

  return 0;
}


Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq K \leq 100

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N K
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

5 3
10 30 40 50 20

Sample Output 1

30

If we follow the path 1 → 2 → 5, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

3 1
10 20 10

Sample Output 2

20

If we follow the path 1 → 2 → 3, the total cost incurred would be |10 - 20| + |20 - 10| = 20.

Sample Input 3

2 100
10 10

Sample Output 3

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 4

10 4
40 10 20 70 80 10 20 70 80 60

Sample Output 4

40

If we follow the path 1 → 4 → 8 → 10, the total cost incurred would be |40 - 70| + |70 - 70| + |70 - 60| = 40.


#include <stdio.h>

int abs(int a){
	if(a>0) return a;
	else return -1*a;
}
int min(int a,int b){
	if(a<b) return a;
	else return b;
}

int main(void) {
	int N=0, K=0;
	scanf("%d%d",&N,&K);
	int step[N];
	for(int i=0;i<N;i++){
		scanf("%d",&step[i]);
	}
	int dp[N];
	dp[0] = 0;
	dp[1] = abs(step[0]-step[1]);
	for(int i=2;i<N;i++){
		int m = 100000;
		//dp[i] = min(dp[i-1]+abs(step[i]-step[i-1]),dp[i-2]+abs(step[i]-step[i-2]));
		for(int j=min(i,K);j>0;j--){
		  m = min(m,dp[i-j]+abs(step[i]-step[i-j]));
		}
		dp[i] = m;
	}
	printf("%d",dp[N-1]);
	/*for(int i=0;i<N;i++){
		printf("%d\n",dp[i]);
	}*/
	return 0;
}


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

int main() {
    long int N,K;
    scanf("%d%d",&N,&K);
    long int h[N];
    long int dp[N];
    for (int i = 0; i <= N; i++) {
        scanf("%d",&h[i]);
    }
    for (int i = 0; i <= N; i++) {
        dp[i] = INFINITY;
    }
        dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int t = 1; t <= K; t++) {
          if(dp[i + t] > dp[i] + abs(h[i] - h[i + t])){
                dp[i + t] = dp[i] + abs(h[i] - h[i + t]);
          }
        }
    }

    printf("%d",dp[N-1]);
    return 0;
}


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

int main() {
    int N,K;
    scanf("%d%d",&N,&K);
    int h[N];
    int dp[N];
    for (int i = 0; i <= N; i++) {
        scanf("%d",&h[i]);
    }
    for (int i = 0; i <= N; i++) {
        dp[i] = 100000000;
    }
        dp[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int t = 1; t <= K; t++) {
          if(dp[i + t] > dp[i] + abs(h[i] - h[i + t])){
                dp[i + t] = dp[i] + abs(h[i] - h[i + t]);
          }
        }
    }

    printf("%d",dp[N-1]);
    return 0;
}


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

int main(void){
    int input[256];
    int n,k;
    scanf("%d", &n);
    scanf("%d", &k);

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

    int min[256];
    min[0] = 0;
    min[1] = abs(input[1] -input[0]);

    for(int i = 2; i < n; i++){
        int smaller = abs(input[i] - input[i-1]) + min[i-1];
        for(int j = 2;j <  k + 1; j++){
            if(i - j > -1){
                if(abs(input[i] - input[i - j]) + min[i-j] < smaller){
                    smaller = abs(input[i] - input[i - j]) + min[i-j];
                }
            }
        }
        min[i] = smaller;
    }

    printf("%d", min[n-1]);

}


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

#define INF 1E9

int n,k,*h;
long *dp;

int calcCost(int from,int to)
{
	if (h[from]>h[to]) return h[from] - h[to];
	return h[to] - h[from];
}

int myMin(int a,int b)
{
	return (a-b>0)?b:a;
}

void chMin(long *a,int b)
{
	if (*a>b) *a = b;
	return;
}

int main(void)
{
	int i,j;
	scanf("%d %d",&n,&k);
	h = (int *)malloc(sizeof(int) * n);
	for (i=0;i<n;i++) scanf("%d",&h[i]);

	dp = (long *)malloc(sizeof(long) * n);
	dp[0] = 0;
	for (i=1;i<n;i++) dp[i] = INF;

	for (i=1;i<n;i++) {
		for (j=1;j<=k;j++) {
			if (i-j<0) break;

			chMin(&dp[i],dp[i-j] + calcCost(i-j,i));
		}
	}

	printf("%ld\n",dp[n-1]);

	free(h);
	free(dp);
	return 0;
}


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

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

int main(void) {
	int n,W;
	scanf("%d%d",&n,&W);
	long long int w[n],v[n];
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&w[i],&v[i]);
	}
	long long int dp[101][100000];//ナップサック
	for(int i=0;i<n;i++){
		for(int j=0;j<=W;j++){
			if(j>=w[i]){
				dp[i+1][j] =max(dp[i][j-w[i]]+v[i],dp[i+1][j]);
			}
				dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
		}
	}
	printf("%lld",dp[n][W]);
}

Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^5

1 \leq w_i \leq W

1 \leq v_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.


/*
 * FileName:     D_fix_2
 * CreatedDate:  2020-05-17 16:56:52 +0900
 * LastModified: 2020-05-17 17:07:08 +0900
 */

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

long int dp_search(int *w,long int *v,int n,int W,int u){
    if(n==u){
        return 0;
    }
    if(W<w[u]){
        return dp_search(w,v,n,W,u+1);
    }
    long int s1 = dp_search(w,v,n,W-w[u],u+1)+v[u];
    long int s2 = dp_search(w,v,n,W,u+1);
    if(s1>s2){
        return s1;
    }
    else{
        return s2;
    }

}
int main(void){
    int n,W;
    scanf("%d %d",&n,&W);
    int *w = malloc(n*sizeof(int));
    long int *v = malloc(n*sizeof(int));
    for(int i=0;i<n;i++){
        scanf("%d %ld",w+i,v+i);
    }
    long int ans=0,tmp;
    for(int i=0;i<2;i++){
        tmp = dp_search(w,v,n,W,0);
        if(ans<tmp){
            ans = tmp;
        }
    }
    printf("%ld\n",ans);
    free(w);
    free(v);
    return 0;
}


#include<stdio.h>

#define nax 100009
#define nax2 109

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

int main(){
	long long W, peso[nax2],valor[nax2],n;
	long long dp[nax2][nax];

	scanf("%lld",&n);
	scanf("%lld",&W);
	for(int i = 0 ; i < n;i++){
		scanf("%lld %lld",&peso[i],&valor[i]);
	}

	//1ra entrada: posicion, 2da: peso actual (w hat)
	//Caso base:
	for(int i = 0 ; i < n;i++){
		dp[i][0] = 0;
	}

	for(int i = 1; i <=W;i++){//peso
		for(int j = 0; j < n ; j++){//posicion
			long long siEscojo = 0, noEscojo = 0;
			if(peso[j]<=i){
				if(j==0){
					siEscojo= valor[j];
				}else{
					siEscojo = valor[j] + dp[j-1][i-peso[j]];
				}
			}
			if(j!=0){
				noEscojo = dp[j-1][i];
			}
			dp[j][i] = max(siEscojo,noEscojo);
		}
	}

	printf("%lld",dp[n-1][W]);

	return 0;
}


#include <stdio.h>
#define Max(a,b) a>b?a:b
#define n_max 110
#define w_max 114514

long dp[n_max][w_max];
void init_dp(void);

int main(void){
    int n,w;
    scanf("%d%d",&n,&w);
    int weight[n_max];
    long value[n_max];
    for(int i=0;i<n_max;i++)
    {
        weight[i]=value[i]=0;
    }
    init_dp();

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

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(j>=weight[i])
            {
                dp[i+1][j]=Max(dp[i][j-weight[i]]+value[i],dp[i][j]);
            }
        }
    }

    long ans=0;
    for(int i=0;i<w;i++)
    {
        ans=Max(ans,dp[n][i]);
    }

    printf("%ld",ans);
}

void init_dp(void){
    for(int i=0;i<n_max;i++)
    {
        for(int j=0;j<w_max;j++)
        {
            dp[i][j]=0;
        }
    }
}


Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara


#include<stdio.h>
#include<string.h>
#define LEN 3000

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

int lcs[LEN][LEN]={0};
char word[LEN]="";

int main(void){
	int i;
	int j;
	int k;
	int s_len;
	int t_len;
	char s[LEN];
	char t[LEN];
	scanf("%s%s",s,t);
	s_len=strlen(s);
	t_len=strlen(t);
	for(i=0;i<s_len+1;i++){
		lcs[i][0]=0;
	}
	for(i=0;i<t_len+1;i++){
		lcs[0][i]=0;
	}
	for(i=1;i<s_len+1;i++){
		for(j=1;j<t_len+1;j++){
			if(s[i-1]==t[j-1]){
				lcs[i][j]=lcs[i-1][j-1]+1;
			}else{
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
			}
		}
	}
	i=s_len;
	j=t_len;
	k=1;
	while((i>0)&&(j>0)){
		if(lcs[i][j]==lcs[i][j-1]){
			j--;
		}else if(lcs[i][j]==lcs[i-1][j]){
			i--;
		}else{
			word[lcs[s_len][t_len]-k]=s[i-1];
			i--;
			j--;
			k++;
		}
	}
	printf("%s",word);
	return 0;
}


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

#define MAX     3333
char s[MAX], t[MAX];
int dp[MAX][MAX];

int max(int x, int y) {
    return (x > y) ? x : y;
}

int main() {
    scanf("%s", s);
    scanf("%s", t);
    int i, j;
    char *sub = malloc(sizeof(char) * MAX);
    sub += MAX;

    for (i = 0; i < strlen(s); i++) {
        for (j = 0; j < strlen(t); j++) {
            //printf("%d\n", (s[i] == t[j]));
            if (i == 0 && j == 0) dp[i][j] = (s[i] == t[j]);
            else if (i == 0) dp[i][j] = (s[i] == t[j]) ? 1 : dp[i][j - 1];
            else if (j == 0) dp[i][j] = (s[i] == t[j]) ? 1 : dp[i - 1][j];
            else dp[i][j] = (s[i] == t[j]) ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j - 1], max(dp[i - 1][j], dp[i][j - 1]));
            //printf("%d ", dp[i][j]);
        }
        //putchar('\n');

    }

    i--;
    j--;

    while (i >= 0 && j >= 0) {
        if (s[i] == t[j]) {
            *sub-- = s[i];
            i--;
            j--;
        }
        else if (i == 0 && j == 0) break;
        else if (i == 0) j--;
        else if (j == 0) i--;
        else if (dp[i - 1][j] > dp[i][j - 1]) i--;
        else j--;
    }

    printf("%s\n", sub + 1);

    //printf("%d\n", dp[i - 1][j - 1]);

}


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

    scanf("%d",&D);

    if(D==25) printf("Christmas\n");
    else if(D==24) printf("Christmas Eve\n");
    else if(D==23) printf("Christmas Eve Eve\n");
    else printf("Christmas Eve Eve Eve\n");

    return 0;
}

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


//a.c A-Chrisitmas Eve Eve Eve
#include<stdio.h>

int main(void){
    int d;
    scanf("%d",&d);
    if(d==25){
        printf("Christmas\n");
    }else if(d==24){
        printf("Christmas Eve\n");
    }else if(d==23){
        printf("Christmas Eve Eve\n");
    }else if(d==22){
        printf("Christmas Eve Eve Eve\n");
    }
    return 0;
}


#include<stdio.h>
int main(){
    int d;
    scanf("%d",&d);
    printf("Christmas");
    for(int i=d-25;i<0;i++){
        printf(" Eve");
    }
    return 0;
}


#include <stdio.h>

int main(void)
{
	int a,i;

	scanf("%d",&a);

	printf("Christmas");

	for(i=25-a;i>0;i--)printf(" Eve");
	printf("\n");

  return 0;
}


#include <stdio.h>
int main(){
 int a;
 scanf("%d",&a);
  if (a == 22)
    printf("Christmas Eve Eve Eve");
  else if (a == 23)
    printf("Christmas Eve Eve");
  else if (a == 24)
    printf("Christmas Eve");
  else
    printf("Christmas");
  return 0;

}


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

int main(void) {
  int d;

  if(scanf("%d", &d) == 1);

  if(d == 25) {
    printf("Christmas");
  } else if (d == 24) {
    printf("Christmas Eve");
  } else if (d == 23) {
    printf("Christmas Eve Eve");
  } else {
    printf("hristmas Eve Eve Eve");
  }

  return 0;
}


#include<stdio.h>
int main(){
    int D;
    scanf("%d",&D);
    if(D==25){
        printf("Christmas\n");
    }
     if(D==24){
        printf("Christmas Eve\n");
    }
     if(D==23){
        printf("Christmas Eve Eve\n");
    }
     if(D==22){
        printf("Christmas Eve Eve Eve\n");
    }
    return 0;
}


#include <stdio.h>

int main()
{
  int a;

  scanf("%d", &a);
  if (a == 25)
    puts("Christmas");
  if (a == 24)
    puts("Christmas Eve");
  if (a == 23)
    puts("Christmas Eve Eve");
  if (a == 22)
    puts("Christmas Eve Eve Eve");
  return 0;
}


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

int main(void){

	int n;
	char s1[] = "Christmas";
	char s2[] = "Christmas Eve";
	char s3[] = "Christmas Eve Eve";
	char s4[] = "Christmas Eve Eve Eve";

	scanf("%d",&n);

	switch(n){
		case 25:
			printf("%s",s1);
			break;
		case 24:
			printf("%s",s2);
			break;
		case 23:
			printf("%s",s3);
			break;
		case 22:
			printf("%s",s4);
			break;
	}

	return 0;
}


#include <stdio.h>
int main(void){
    int i, D, a[] = {21, 17, 13, 9};
    char *t = "Christmas Eve Eve Eve";
    scanf("%d", &D);
    for (i = 0; i < a[D - 22]; i++) {
        printf("%c", t[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>

int main(int argc, char const *argv[])
{
	int day;
	scanf("%d",&day);
	printf("Christmas");
	if(day == 24)	printf(" Eve\n");
	else if(day == 23)	printf(" Eve Eve\n");
	else if(day == 22)	printf(" Eve Eve Eve\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int n;
  scanf("%d",&n);
  if(n==25){
    printf("Christmas\n");
  }else if(n==24){
    printf("Christmas Eve\n");
  }else if(n==23){
    printf("Christmas Eve Eve\n");
  }else if(n==22){
    printf("Christmas Eve Eve Eve\n");
  }

  return 0;
}


#include <stdio.h>

#define size 128
#define ZNA 1
#define ZNB 2
#define ZNC 4
#define ZND 8

int readint();
inline int readint()
{
    register int t = 0;
    register char c;
    //int minus = 0;
    while((c = getchar()) < '-');
    //if (c == '-') minus = 1, c = getchar();
    c -= '0';
    do
    {
        t = t * 10 + c;
    }while((c = getchar() - '0') >= 0);
    //return minus ? (-t) : t;
    return t;
}

struct point
{
    int x;
    int y;
    int z;
    int f;
};

int main()
{
    int n, x1 = 0, x2 = 100, y1 = 0, y2 = 100, dx, dy, dz;
    struct point point[size];
    n = readint();
    for (int i = 0; i < n; i++)
    {
        point[i].x = readint();
        point[i].y = readint();
        point[i].z = readint();
        point[i].f = 0;
    }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
    {
        #define pout(i, x) (point[i].x <= x##1 || point[i].x >= x##2)
        if (pout(i, x) && pout(i, y) && pout(j, x) && pout(j, y))
            continue;
        dx = point[i].x - point[j].x;
        dy = point[i].y - point[j].y;
        dz = point[i].z - point[j].z;
        if (dx > 0)
        {
            if (dy > 0)
            {
                #define test(dx, dy, A, B, C, D) \
                if ((dx) + (dy) == dz) \
                { \
                    point[i].f = point[j].f = ZN##A|ZN##B|ZN##D; \
                } \
                else if ((dx) + (dy) == -dz) \
                { \
                    point[i].f = point[j].f = ZN##B|ZN##C|ZN##D; \
                } \
                else if ((dx) - (dy) == dz) \
                { \
                    point[i].f = point[j].f = ZN##A|ZN##C|ZN##D; \
                } \
                else if ((dx) - (dy) == -dz) \
                { \
                    point[i].f = point[j].f = ZN##A|ZN##B|ZN##C; \
                } \
                else if ((dx) > (dy)) \
                { \
                    point[i].f |= ZN##B|ZN##C; \
                    point[j].f |= ZN##A|ZN##D; \
                } \
                else if ((dx) < (dy)) \
                { \
                    point[i].f |= ZN##C|ZN##D; \
                    point[j].f |= ZN##A|ZN##B; \
                } \
                else \
                { \
                    point[i].f = ZN##B|ZN##C|ZN##D; \
                    point[j].f = ZN##A|ZN##B|ZN##D; \
                }
                test(dx, dy, A, B, C, D);
            }
            else
            {
                test(dx, -dy, D, C, B, A);
            }
        }
        else if (dx < 0)
        {
            if (dy > 0)
            {
                test(-dx, dy, B, A, D, C);
            }
            else if (dy < 0)
            {
                test(-dx, -dy, C, D, A, B);
            }
        }
        #define update(i) \
        _update(i, ZNB|ZNC|ZND, x2, y2, min, min) \
        _update(i, ZNA|ZNC|ZND, x1, y2, max, min) \
        _update(i, ZNA|ZNB|ZND, x1, y1, max, max) \
        _update(i, ZNA|ZNB|ZNC, x2, y1, min, max)
        #define _update(i, z, _x, _y, xm, ym) \
        if (point[i].f == (z)) \
            _x = xm(_x, point[i].x), _y = ym(_y, point[i].y);
        #define max(a, b) (a > b ? a : b)
        #define min(a, b) (a < b ? a : b)
        #define calc_h(i) (point[i].z + abssub(point[i].x, x) + abssub(point[i].y, y))
        #define abssub(a, b) ((a > b) ? (a - b) : (b - a))
        update(i)
        update(j)
    }
    for (int x = x1; x <= x2; x++)
        for (int y = y1; y <= y2; y++)
    {
        int h = calc_h(0);
        for (int i = 0; i < n; i++)
        {
            if (h != calc_h(i))
                goto next;
        }
        printf("%d %d %d", x, y, h);
        goto end;
        next:
        continue;
    }
    end:
    return 0;
}

#define ZNA 1
#define ZNB 2
#define ZNC 4
#define ZND 8

Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

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

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

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

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.


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

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

    int p[n][3];
    for (int i = 0; i < n; i++) {
        int x, y, h;
        scanf("%d %d %d", &x, &y, &h);
        p[i][0] = x;
        p[i][1] = y;
        p[i][2] = h;
    }

    int ans_x, ans_y, ans_h;
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int match = 0;
            for (int l = 0; l < n; l++) {
                int x = p[l][0], y = p[l][1], h = p[l][2];
                int tmp;
                if (l == 0) {
                    tmp = abs(x - i) + abs(y - j) + h;
                    if (tmp > 0) {
                        ans_h = tmp;
                    }
                    continue;
                }

                if (ans_h != 0 && ans_h != abs(x - i) + abs(y - j) + h) {
                    break;
                }

                if (l == n - 1) {
                    printf("%d %d %d\n", i, j, ans_h);
                    return 0;
                }
            }
        }
    }

    return 0;
}


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

int main(){
    int N;
    int h[110],x[110], y[110];
    int i, j, k;
    int hmax, hnow;

    scanf("%d", &N);

    for(i=0; i<N; i++){
        scanf("%d %d %d", &x[i], &y[i], &h[i]);
    }
    for(i=0; i<=100; i++){
        for(j=0; j<=100; j++){
            hmax = h[0] + abs(i-x[0]) + abs(j-y[0]);
            if(hmax < 1){
                break;
            }
            for(k=1; k<N; k++){
                hnow = hmax - abs(i-x[k]) - abs(j-y[k]);
                if(h[k] != hnow){
                    break;
                }
            }
            if(k>=N){
                break;
            }
        }
        if(k>=N){
            break;
        }
    }
    printf("%d %d %d", i, j, hmax);

    return 0;
}


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

int max(int a,int b){return a > b ? a:b;}
int sortmax(int h[],int n);
int hantei(int Cx,int Cy,int H,int N,int x[],int y[],int h[]);

int main(){
    /*入力*/
    int N;
    int m =scanf("%d",&N);
    int x[N],y[N],h[N];
    for(int i = 0;i < N;i++){
        int l = scanf("%d%d%d",&x[i],&y[i],&h[i]);
    }

    /*hのうち一番高いところはどこか調べる*/
    int arraynumber = sizeof(h)/sizeof(h[0]);
    int maxh = sortmax(h,arraynumber);

/*各Cx,Cy,Hについて全ての観測値に整合するかどうかを調べる。もしそうなるのが合ったらそれを出力する*/
    int Cx,Cy,H;
    for(H = maxh;;H++){
        for(int Cx = 0;Cx <= 100;Cx++){
            for(int Cy = 0;Cy <=100;Cy++){
                int mark = hantei(Cx,Cy,H,N,x,y,h);//ここで判定。一致したら１を返す。
                if(mark == 1){
                    printf("%d %d %d\n",Cx,Cy,H);
                    return 0;
                }
            }
        }
    }
    return 0;
}

int sortmax(int h[],int n){
    for(int i = 0;i < n;i++){
            h[0] = max(h[0],h[i]);
        }
    return h[0];
}

int hantei(int Cx,int Cy,int H,int N,int x[],int y[],int h[]){
    for(int i = 0;i < N;i++){
        int cal = H - abs(x[i] - Cx) - abs(y[i] - Cy);
        if(h[i] != max(cal,0))return 0;
    }
    return 1;
}


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

int main(void)
{
	int n, err, i, j, k, l, flag;
	long *x, *y, *h, H, H1;
	err = scanf("%d", &n);
	if ((err!=1) || (n<1)) exit(1);
	x = (long *)malloc(sizeof(long)*n);
	y = (long *)malloc(sizeof(long)*n);
	h = (long *)malloc(sizeof(long)*n);

	for (int i = 0; i < n; ++i)
	{
		err = scanf("%ld%ld%ld", &x[i], &y[i], &h[i]);
		if ((err!=3) || ((x[i]<0) || (x[i]>100)) ||  ((y[i]<0) || (y[i]>100)) || ((h[i]<0) || (h[i]>10e9))) exit(1);
	}

	for (int i = 0; i <= 100; ++i)
	{
		for (int j = 0; j <= 100; ++j)
		{
			l = 0;
			while (h[l] == 0) l++;
			H = h[l] + labs(x[l]-(long)i) + labs(y[l]-(long)j);
			for (int k = 0; k < n; ++k)
			{
				flag = 0;
				H1 = h[k] + labs(x[k]-(long)i) + labs(y[k]-(long)j);
				if (h[k] != 0)
				{
					if (H != H1)
					{
						flag = 1;
						break;
					}
				}else
				{
					if (H > H1)
					{
						flag = 1;
						break;
					}
				}
			}
			if (flag == 0)
			{
				printf("%d %d %ld\n", i, j, H);
				free(x);
				free(y);
				free(h);
				return 0;
			}
		}
	}
	return 0;
}


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

int main(){
		int n,i;
		scanf("%d",&n);
		long xyh[n][3];
		for(i=0;i<n;i++){
				scanf("%ld%ld%ld",&xyh[i][0],&xyh[i][1],&xyh[i][2]);
		}
		int cx,cy,flag=0;long h,tmp;
		for(cx=0;cx<=100;cx++){
				for(cy=0;cy<=100;cy++){
				//		printf("%d %d\n",cx,cy);
						flag=0;
						tmp-=1;
						for(i=0;i<n;i++){
						//		if(xyh[i][2]>0){
										h=xyh[i][2]+abs(xyh[i][0]-cx)+abs(xyh[i][1]-cy);
						/*		else if(tmp-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)>0){
										flag=1;
										break;
								}else h=tmp;*/
								if(xyh[i][2]==0){
										if(tmp!=-1){
												if(tmp-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy)>0)break;
										}

								}else{
										if(i==0){
												tmp=h;
										}
										if(tmp!=h){
												flag=1;
												break;
										}
								}
						}
								if(flag==0){
										printf("%d %d %ld",cx,cy,tmp);
										return 0;
								}
				}
/*						int tmp=xyh[i][2]-abs(xyh[j][0]-xyh[i][0])-abs(xyh[j][1]-xyh[i][1]);
						if(tmp<0)tmp=0;
						if(xyh[j][2]=!tmp)break;*/
		}
}


#include <stdio.h>

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

int main(){
  int N,i;
  scanf("%d",&N);
  int x[N];int y[N];int h[N];
  for(i=0;i<N;i++){
    scanf("%d%d%d",&x[i],&y[i],&h[i]);
  }
  int cx,cy,H;
  int j=0;
  int flag;

  for(cx=0;cx<=100;cx++){
      for(cy=0;cy<=101;cy++){
      flag=0;j=0;
      while(h[j]==0){j++;}
      H=h[j]+absl(x[j]-cx)+absl(y[j]-cy);

      if(1<=j){
        for(i=0;i<j;i++){
          if(H-absl(x[i]-cx)-absl(y[i]-cy)>0){
            flag=1;
            break;
          }
        }
      }
      if(flag==0&&j==N-1){
	printf("%d %d %d",cx,cy,H);
	return 0;
      }

      for(i=j+1;i<N;i++){
	if(h[i]==0){
	  if(H-absl(x[i]-cx)-absl(y[i]-cy)>0) {
	    flag=1;
	    break;
	  }
	}
	if(h[i]>0){
	  if(h[i] != H-absl(x[i]-cx)-absl(y[i]-cy)) {
	    flag=1;
	    break;
	  }
	}
      }
      if(flag==0){
	printf("%d %d %d",cx,cy,H);
	return 0;
      }
    }
  }
  return 0;
}


#include<stdio.h>

int N;
int x[100],y[100],h[100];

int check(int a,int b);

int ab(int x){
	if(x<0)return -x;
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}

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

	int H;
	for(int i=0;i<N;i++)scanf("%d%d%d",&x[i],&y[i],&h[i]);
	for(int i=0;i<=101;i++){
		for(int j=0;j<=101;j++){
			if(check(i,j)>0){
				H=check(i,j);
				printf("%d %d %d\n",i,j,H);
				return 0;
			}
		}
	}
}

int check(int a,int b){
	int H=1000100000;
	int bound=1000010000;
	for(int i=0;i<N;i++){
		int dist=ab(a-x[i])+ab(b-y[i]);
		if(h[i]==0){
			bound=min(bound,dist);
		} else {
			if(H<1000000001 && H!=dist+h[i])return 0;
			H=dist+h[i];
		}
		if(H<1000000001 && H>bound)return 0;
	}
	if(H>bound)H=bound;
	return H;
}


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

main() {
    int N;
    scanf("%d",&N);
    int x[N],y[N],h[N];
    int keep=-1;
    for (int i = 0; i < N; ++i){
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
        if(keep==-1 && h[i]!=0){
            keep=i;
        }
        if(h[i]==0){
            i--;
            N--;
        }
    }

    for (int X = 0; X <= 100; ++X) {
        for (int Y = 0; Y <= 100; ++Y) {
            for (int i = 0; i < N-1; ++i) {
                int tmp1=h[i]+abs(x[i]-X)+abs(y[i]-Y);
                int tmp2=h[i+1]+abs(x[i+1]-X)+abs(y[i+1]-Y);
                if(tmp1!=tmp2){
                    break;
                }
                if(i==N-2){
                    int H=h[keep]+abs(x[keep]-X)+abs(y[keep]-Y);
                    printf("%d %d %d",X,Y,H);
                    return 0;
                }
            }
        }
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279

void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}
int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main(void){
	int n;
	int x[101], y[101], h[101];
	int cx, cy, H=-1;
	int flag;
	scanf("%d", &n );
	for(int i=0;i<n;i++)	scanf("%d %d %d", &x[i], &y[i], &h[i]);

	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			H=-1;
			flag = 1;
			for(int k=0;k<n;k++){
				if(h[k]==0)	continue;
				else{
					H = h[k] + abs(i-x[k]) + abs(j-y[k]);
					break;
				}
			}
			if(H==-1){
				while(1){}
			}
			for(int k=0;k<n;k++){
				if(H != h[k] + abs(i-x[k]) + abs(j-y[k])){
					flag=0;
					break;
				}
			}
			if(flag==1){
				printf("%d %d %d", i,j,H);
				return 0;
			}

		}
	}

	return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
  long n;
  long x[101], y[101], h[101];
  long cx, cy, ch;
  long i,j,k,l;
  long minX=100, minY=100;
  long maxX=0, maxY=0;
  long maxH = 0;
  long hh[101], count;
  hh[0] = 0;

  scanf("%d",&n);
  for(k=1;k<=n;k++){
    scanf("%d %d %ld",&x[k],&y[k],&h[k]);
    /*
    if(minX>x[k])minX=x[k];
    if(minY>y[k])minY=y[k];
    if(maxX<x[k])maxX=x[k];
    if(maxY<y[k])maxY=y[k];
    */
  }
  l = 0;
  for(i=0;i<=100;i++){
    for(j=0;j<=100;j++){
      count = 0;
      for(k=1;k<=n;k++){
        hh[k] = abs(x[k]-i) + abs(y[k]-j) + h[k];
        if(hh[k]-hh[k-1]==0){
          count++;
        }
      }
      if(count==n-1){
        if(maxH<hh[1]){
          maxH=hh[1];
          cx = i;
          cy = j;
        }
      }
    }
  }
  printf("%d %d %d",cx,cy,maxH);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
long long max(long long x, long long y){return x<y?y:x;}
int main(void){
	int n,i,flag=0;
	int Cx,Cy;
	scanf("%d",&n);
	int x[n],y[n];
	long long h[n],H,hkari,hhh;
	for(i=0;i<n;i++)scanf("%d%d%lld",&x[i],&y[i],&h[i]);
	for(Cx=0;Cx<=100;Cx++){
		for(Cy=0;Cy<=100;Cy++){
			hhh = abs(x[0]-Cx)+abs(y[0]-Cy)+h[0];
			for(i=1;i<n;i++){
				hkari = abs(x[i]-Cx)+abs(y[i]-Cy)+h[i];
				if(hhh!=hkari)break;
			}
			if(i==n){
				flag=1;
				break;
			}
		}
		if(flag==1)break;
	}

	printf("%d %d %lld",Cx,Cy,hhh);
	return 0;
}


//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,b,c,r=0,l,t;
    int fi,fj;
    int x,y,h,map[128][128],fmap[128][128];
    double d;
    char s[524288];
    scanf("%d",&n);
    for(i=0;i<128;i++){
      for(j=0;j<128;j++){
        map[i][j]=-1;
      }
    }
    for(i=0;i<n;i++){
      scanf("%d%d%d",&x,&y,&h);
      map[x][y]=h;
    }
    for(i=0;i<=100;i++){
      for(j=0;j<=100;j++){
        fmap[i][j]=h+zt(i,x)+zt(j,y);
        r=1;
        for(fi=0;fi<=100;fi++){
          for(fj=0;fj<=100;fj++){
            fmap[fi][fj]=max(fmap[i][j]-zt(i,fi)-zt(j,fj),0);
            if(map[fi][fj]!=-1&&map[fi][fj]!=fmap[fi][fj]){r=0;break;}
          }
          if(r==0){break;}
        }
        if(r==1){
          printf("%d %d %d\n",i,j,fmap[i][j]);
          return 0;
        }
      }
    }
    printf("ERR\n");
    return 0;
}


#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  int max =0;
  for(int i =a;i<3;i++){
    for(int j=c;j!=i;j--){
      for(int m=c;m!=j && m!= i;m--){
         if(i*10+j+m > max){
           max = i*10+j+m;
         }
      }
    }
  }
  printf("%d",max);
}

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


#include <stdio.h>

int main()
{
  int a,b,c;
  scanf("%d %d %d",&b);
  if (a > b && c > b)
    printf("%d",a+c);
  else if (b > a && c > a)
    printf("%d",b+c);
  else
  	printf("%d",a+b);

}


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

int main(){
	int a, b, c;
	int max;
	scanf("%d %d %d\n", &a, &b, &c);
	if(a>b) max = a;
	else max = b;
	if(max<c) max = c;
	printf("%d\n", a + b +c + max * 9);
	return 0;
}


#include<stdio.h>
void swap(int *a, int *b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
void sort(int num[3]){
    if(num[1] > num[0]){
        swap(num, num+1);
    }
    if(num[2] > num[0]){
        swap(num, num+2);
    }
}
int main(){
    int num[3];
    scanf("%d %d %d", num, num+1, num+2);
    sort(num);
    printf("%d\n", num[0] * 10 + num[1] + num[2]);
    return 0;
}


#include <stdio.h>

int main(void)
{
    int a, b, c, max, mid, min;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);

    if (a <= b && a <= c && b <= c)
    {
        max = c;
        mid = b;
        min = a;
    }
    if (a <= b && a <= c && c <= b)
    {
        max = b;
        mid = c;
        min = a;
    }
    if (b <= a && b <= c && a <= c)
    {
        max = c;
        mid = a;
        min = b;
    }
    if (b <= a && b <= c && c <= a)
    {
        max = a;
        mid = c;
        min = b;
    }
    if (c <= a && c <= b && b <= a)
    {
        max = a;
        mid = b;
        min = c;
    }
    if (c <= a && c <= b && a <= b)
    {
        max = b;
        mid = a;
        min = c;
    }
    printf("%d", (max * 10 + mid) + min);
    return 0;
}


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

int max(int x, int y)
{
    if (x>=y) return x;
    else return y;
}

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int maxnum = max(a, max(b, c));
    int ans = a + b + c + maxnum*9;
    printf("%d\n", ans);
    return 0;
}


#include<stdio.h>

int main()
{
  int A, B, C, chan, r;
  scanf("%d %d %d", &A, &B, &C);

  if (B >= C)
  {
    chan = B;
      B = C;
      C = chan;
  }

  if (A >= B)
  {
    chan = A;
      A = B;
      B = chan;
  }

   if (A >= C)
  {
    chan = A;
      A = C;
      C = chan;
  }

  printf("%d", 10*C + A +B);

  return 0;
}


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


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
int max(int a, int b){return a>b?a:b;}
int min(int a, int b){return a<b?a:b;}
int gcd(int a, int b){return min(a,b)==0 ?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
long long llmax(long long a, long long b){return a>b?a:b;}
long long llmin(long long a, long long b){return a<b?a:b;}
long long llgcd(long long a, long long b){return min(a,b)==0 ?max(a,b):gcd(min(a,b),max(a,b)%min(a,b));}
int assort(const void *a, const void *b){return *(int*)a-*(int*)b;}
int dessort(const void *a, const void *b){return *(int*)b-*(int*)a;}
int llassort(const void *a, const void *b){return *(long long*)a-*(long long*)b;}
int lldessort(const void *a, const void *b){return *(long long*)b-*(long long*)a;}
int charassort(const void *a, const void *b){return strcmp((char*)a ,(char*)b);}
int chardessort(const void *a, const void *b){return strcmp((char*)b ,(char*)a);}
char lowcmp[26]="abcdefghijklmnopqrstuvwxyz";
char upcmp[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int ntoi(char c){return c-'0';}
int ltoi(char c){return c-'a';}
int utoi(char c){return c-'A';}
long long mod=1000000007;

int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\n",a+b+c+max(a,max(b,c))*9);
    return 0 ;
}


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

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);

int main()
{
	int A = 0, B = 0, C = 0;

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

	int X[3] = { A,B,C };

	int ans = 9 * Max(X, 3) + Sum(X, 3);

	return ans;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}


#include <stdio.h>

int main(){
	int num[3];
	int i,f,m;

	scanf("%d %d %d",&num[0],&num[1],&num[2]);

	for(i=0;i<3;i++){
		for(f=i+1;f<3;f++){
			if(num[i]<num[f]){
				m=num[i];
				num[i]=num[f];
				num[f]=m;
			}
		}
	}

	m=(num[0]*10)+num[1]+num[2];

	printf("%d",m);

	return 0;
}


#include <stdio.h>
int main() {
  int set[4], i;

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

  int X[set[0]], Y[set[1]], Z = set[2] - set[3];

  for (i = 0; i < set[0]; i++) {
    scanf("%d", &X[i]);
  }
  for (i = 0; i < set[1]; i++) {
    scanf("%d", &Y[i]);
  }

  int znum = set[2], xfl, yfl, flag = 0, j;

  for (i = 0; i < Z; i++) {
    znum++;
    xfl = 0;
    yfl = 0;
    for (j = 0; j < set[0]; j++) {
      if (znum > X[j]) {
        xfl++;
      }
    }
    for (j = 0; j < set[1]; j++) {
      if (znum <= Y[j]) {
        yfl++;
      }
    }
    if (xfl == set[0] || yfl == set[1]) {
      flag++;
    }
  }

  if (flag > 0) {
    printf("No War");
  } else {
    printf("War");
  }
}

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


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

	int N = 10;int M = 10;
	int X, Y;
	scanf("%d %d %d %d", &N,&M,&X,&Y);

	int x[200];
	int y[200];
	for (int i = 0;i < N;i++)scanf(" %d", &x[i]);
	for (int i = 0;i < M;i++)scanf(" %d", &y[i]);

	int xmax = -100;
	int ymin = 101;

	for (int i=0;i<N;i++)
	if (xmax < x[i]) xmax = x[i];

	for(int i=0;i<M;i++)
		if(ymin >y[i]) ymin = y[i];

	if (xmax >= ymin || X >= Y)printf("War");
	else printf("No War");

}


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

//scanf("%d",&x);
//printf("%d",x);
//for(i=0;i<N;i++){  }
//if( == ){  }else{  }
//while( ){  }

/*
int N, i;
int H[100];
scanf("%d", &N);
for (i = 0; i < N; i++) scanf("%s", &H[i]);
*/

int main()
{

	int N,M,X,Y,i,z;
	int x[201];
	int y[201];

	scanf("%d", &N);
	scanf("%d", &M);
	scanf("%d", &X);
	scanf("%d", &Y);

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

	int xmax = 0;
	int ymin = 100;

	for (i = 0; i < N; i++) {
		if (xmax < x[i]) xmax = x[i];
	}

	for (i = 0; i < M; i++) {
		if (ymin > y[i]) ymin = y[i];
	}

	if (ymin > xmax) {

		for (z = 1; z < 100; z++) {
			if (z > X || z <= Y) {
				printf("No War");
				return 0;
			}
		}

	}
	printf("War");

}


#include <stdio.h>
int max(int x[], int num){
    int m = -100;
    for(int i = 0; i < num; i++){
        if(m < x[i]){m = x[i];}
    }
    return m;
}

int min(int x[], int num){
    int m = 100;
    for(int i = 0; i < num; i++){
        if(m > x[i]){m = x[i];}
    }
    return m;
}

int main(void){
    int N, M, X, Y;
    scanf("%d %d %d %d", &N, &M, &X, &Y);
    int x[N+1];
    for(int i = 0; i < N; i++){
        scanf("%d", &x[i]);
    }
    x[N] = X;
    X = max(x, N+1);

    int y[M+1];
    for(int i = 0; i < M; i++){
        scanf("%d", &y[i]);
    }
    y[M] = Y;
    Y = min(y, M+1);
    if(X < Y){
        printf("%s ", "No");
    }
    printf("%s\n", "War");
    return 0;
}


#include <stdio.h>
int main (){
int i,j,n,m,x,y,a,b,max=-100,min=100;
  scanf ("%d%d%d%d",&n,&m,&x,&y);
for (i=0;i<n;i++){
scanf ("%d",&a);
  if (max<a){
 max=a;
  }
}
for (i=0;i<m;i++){
  scanf ("%d",&b);
 if (min>b){
 min=b;
  }
}
if (max>x && max<min && min<y+1){
printf ("No War");
}
  else {
  printf ("War");
  }
return 0;
}


#include <stdio.h>
int main (){
int i,j,n,m,x,y,a,b,max=-100,min=100;
  scanf ("%d%d%d%d",&n,&m,&x,&y);
for (i=0;i<n;i++){
scanf ("%d",&a);
  if (max<a){
 max=a;
  }
}
for (i=0;i<m;i++){
  scanf ("%d",&b);
 if (min>b){
 min=b;
  }
}
if (max>10 && max<min && min<21){
printf ("No War");
}
  else {
  printf ("War");
  }
return 0;
}


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

int main(){

  int i,j,k,tmp;
  int N,M,X,Y;
  scanf("%d %d %d %d",&N,&M,&X,&Y);
  int x[N],y[M];

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

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

  for (i=0; i<M; ++i) {
    for (j=i+1; j<M; ++j) {
      if (y[i] < y[j]) {
        tmp =  y[i];
        y[i] = y[j];
        y[j] = tmp;
      }
    }
  }

  for (i=0; i<N; ++i) {
    for (j=i+1; j<N; ++j) {
      if (x[i] > x[j]) {
        tmp =  x[i];
        x[i] = x[j];
        x[j] = tmp;
      }
    }
  }

  if(x[N-1] >= y[M-1]){
    puts("War");
  	return 0;
  }

  if(X > y[M-1] || Y < x[N-1] ){
    puts("War");
    return 0;
  }

  puts("No War");
  return 0;
}


#include <stdio.h>

int main(void){
  int N,M,X,Y;
  scanf("%d%d%d%d",&N,&M,&X,&Y);
  int x,y;
  int max = -101;
  int min = 101;

  for(int i = 0;i < N;i++){
    scanf("%d",&x);
    if(max < x){
      max = x;
    }
  }
  for(int i = 0;i < M;i++){
    scanf("%d",&y);
    if(min > y){
      min = y;
    }
  }

  for(int Z = min;Z > max;Z--){
    if(Z != X && Z != Y){
      if(max < min && Z > max){
        printf("No War\n");
        printf("%d %d %d",X,Z,Y);
        return 0;
      }
    }
  }

  printf("War\n");
  return 0;
}


#include <stdio.h>
int main(void){
    int n,m,a,b;
    int i,j;

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

    int aset[n],bset[m];
    int maxa=a,minb=b;
    for(i=0;i<n;i++){
        scanf("%d",&aset[i]);
        if(aset[i]>maxa){
            maxa=aset[i];
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&bset[j]);
        if(bset[j]<minb){
            minb=bset[j];
        }
    }

    if(maxa>=minb){
        printf("War\n");
    }else{
        printf("No War\n");
    }

    return 0;
}


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

int main(){
int i, j, k, a, b, c ,d;
int e[100000];
int f[100000];
int war = 0;
int po = 0;
int op = 0;

scanf("%d %d %d %d", &a, &b, &c, &d);
for(j = 0; j < a; j++){
scanf("%d", &e[j]);
}
for(j = 0; j < b; j++){
scanf("%d", &f[j]);
}

for(i = 0; i < a; i++){
  for(k = 0; k < b; k++){
    if(f[i] - e[j] < 1) war++;

  }
}

for(i = 0; i < a; i++){
  if(e[i] < c) po++;
}
for(i = 0; i < a; i++){
  if(f[i] > d) op++;
}

if (war == 0 && po == 0 && op ==0){
  printf("No War\n");
}else{
  printf("War\n");
}

  return 0;
}


#include<stdio.h>

int main(){

    int num,a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int i;
    int box1[a];
    int box2[b];
    for(i=0;i<a;i++){
        scanf("%d",&num);
        box1[i]=num;
    }
    while(a>0){
        for(i=0;i<a;i++){
            if(box1[i]<box1[i+1]){
                num = box1[i];
                box1[i] = box1[i+1];
                box1[i+1] = num;
            }
            a=a-1;
        }
    }
    for(i=0;i<b;i++){
        scanf("%d",&num);
        box2[i]=num;
    }

    while(b>0){
        for(i=0;i<b;i++){
            if(box2[i]>box2[i+1]){
                num = box2[i];
                box2[i] = box2[i+1];
                box2[i+1] = num;
            }
            b=b-1;
        }
    }

    if(box1[0]<box2[0]&&c<=box1[0]&&box2[0]<=d){
        printf("No War\n");
    }else{
        printf("War\n");
    }

    return 0;
}


#include <stdio.h>

int main(void){
  int N, M, X, Y, i, max, min;
  scanf("%d %d %d %d", &N, &M, &X, &Y);
  int x[N], y[M];
  for(i=0; i<N; i++){
    scanf("%d", &x[i]);
    if(i == 0){
      max = x[i];
    }else{
      if(max < x[i]){
        max = x[i];
      }
    }
  }
  for(i=0; i<M; i++){
    scanf("%d", &y[i]);
    if(i == 0){
      min = y[i];
    }else{
      if(min > y[i]){
        min = y[i];
      }
    }
  }
  if(min - max > 0 && min - X > 0 && Y - max >= 0){
    printf("No War\n");
  }else{
    printf("War\n");
  }
  return 0;
}


#include<stdio.h>
int main(){
  int n,m,x,y,max=-1000,min=1000,i;
  int xa,ya;
  scanf("%d%d%d%d",&n,&m,&x,&y);
  for(i=0;i<n;i++){
    scanf("%d",&xa);
    if(max<xa)max=xa;
  }
  for(i=0;i<m;i++){
    scanf("%d",&ya);
    if(min>ya)min=ya;
  }
  if(min>max && x<min && max<y)puts("No War");
  else puts("War");
  return 0;
}


#include<stdio.h>
int main()
{
    int n, m, x, y;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    int xx, yy;
    int maxx = -2000000000, miny = 2000000000;
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &xx);
        if (xx > maxx)
            maxx = xx;
    }
    for (i = 0; i < m; i++)
    {
        scanf("%d", &yy);
        if (yy < miny)
            miny = yy;
    }
    if (y < miny)
        miny = y;
    if (x > maxx)
        maxx = x;
    if (maxx < miny)
        printf("No War\n");
    else
        printf("War\n");
    return 0;
}


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

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

    if(a % 2 == 0 || b % 2 == 0){
        printf("No\n");
    }else if(a % 2 != 0 && b % 2 != 0){
        printf("Yes\n");
    }

}

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


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


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


#include <stdio.h>

int main(void){

  int A;
  int B;

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

  int K = A * B;

  if(K % 2 == 0){
    puts("Yes");
  }
  else{
    puts("No");
  }

  return 0;
}


#include<stdio.h>

int main(){
    int A, B;

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

    if((A*B)%2 == 0){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}


#include<stdio.h>

int main (){
  int a,b,c,i,temp;
  int flag = 0;

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

  for(i = 1;i < 4;i++){
    if(a * b * i % 2 != 0){
      flag = 1;
    }
  }

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

        return 0;

}


#include<stdio.h>

int main (){
  int a,b,c,i,temp;
  int flag = 0;

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

  for(i = 1;i < 4;i++){
    if(a * b * i % 2 != 0){
      temp = a * b * i % 2;
      printf("%d",temp);
      flag = 1;
    }
  }

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

        return 0;

}


#include <stdio.h>
#include<string.h>
int main(void) {
	// your code goes here
int a,b,i,flag,k;
scanf("%d%d",&a,&b);
flag=0;
i=(a>b)?b:a;
k=(a>b)?a:b;
for(i;i<=k;i++)
{
if((i*a*b)%2!=0)
{
flag=1;
}
}
if(flag==1)
{
printf("Yes");

}else{
printf("No");
}
return 0;
}


#include<stdio.h>
int main(){
	int a, b;
	scanf("%d %d",&a,&b);
	if (a*b%2==0)
		printf("No");
	else
		printf("Yes");

	return 0;
}


#include <stdio.h>

int main(void){
  int A, B;
  scanf("%d %d", &A, &B);
  if((A*B)%2 == 0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}


#include <stdio.h>

int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if((a*b)%2==0)printf("No");
  else printf("Yes");
}


/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stdbool.h>
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
/*
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; }
*/
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

int main() {
	int A = in();
	int B = in();
	int c;

	for (int i = 1; i = 3; i++) {
		if ((A*B*c) % 2) {
			printf("%s\n", "Yes");
		}
		else {
			printf("%s\n", "No");
		}
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
	}


#include <stdio.h>

int main(void)
{
  int A,B;

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

  if (A * B %2 == 0) {
    printf("No");
  } else {
    printf("Yes");
  }

  return 0;
}


#include <stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);

    if(A%2 == 0 || B%2 == 0){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}

int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N;
    scanf("%d",&N);
    char siri[N][12];
    rep(i,N){
        scanf("%s",siri[i]);
    }
    rep(i,N-1){
        if(siri[i][strlen(siri[i])-1]!=siri[i+1][0]){
            printf("No");
            return 0;
        }else{
            for(int j=0;j<i;j++){
                if(strcmp(siri[i],siri[j])==0){
                    printf("No");
                    return 0;
                }else{
                    ;
                }
            }
        }
    }
    for(int i=0;i<N-1;i++){
        if(strcmp(siri[N-1],siri[i])==0){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
}

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

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

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  char w[n+1][11],last;
  for(i=0;i<n;i++)
    scanf("%s",w[i]);
  for(i=0;i<n;i++){
    for(j=0;j<i;j++){
      if(strcmp(w[i],w[j])==0){
        puts("No");
        return 0;
      }
    }
    if(i!=0 && last!=w[i][0]){
      puts("No");
      return 0;
    }
    last=w[i][strlen(w[i])-1];
  }
  puts("Yes");
  return 0;
}


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

int main (int argc, char const *argv[])
{
    int64_t N;
    char W[100][11];
    int64_t ans = 0;

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (strcmp(W[i], W[j]) == 0) {
                puts("No");
                return 0;
            }
        }
    }

    for (int i = 0; i < (N - 1); i++) {
        size_t len;
        len = strlen(W[i]);
        if (W[i][len - 1] != W[i + 1][0]) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}


#include <string.h>
int main(void){
    int N;
    scanf("%d", &N);
    char w[N][11];
    int ans = 1;
    char w1 = '\0';
    char wl = '\0';
    for(int i = 0; i < N; i++){
        scanf("%s", w[i]);
        w1 = w[i][0];
        if(i > 0){
            if(w1 != wl){
                ans = 0;
            }
            for(int j = 0; j < i; j++){
                if(strcmp(w[j], w[i]) == 0){
                    ans = 0;
                    break;
                }
            }
        }
        wl = w[i][strlen(w[i]) - 1];
    }
    printf("%s\n", ans ? "Yes": "No");
    return 0;
}


# include <stdio.h>
# include <string.h>
int main ()
{
	char s[250][250],p[250];
	int flag=0,n,i,j,a;
    scanf ("%d",&n);
	gets(p);
	for ( i=1;i<=n;++i)
	   if (gets(s[i])==0)
	     break;
    for (i=1;i<n;++i)
       {
       	a=strlen(s[i])-1;
       	if (s[i+1][0]!=s[i][a]) break;
       	else
       	  {
       	  	for ( j=i+1;j<=n;++j)
       	        if (strcmp(s[i],s[j])==0)
				   flag=1;
		  }
	   }
	if (flag==1||i!=n)
	   printf ("No\n");
	else
	  printf ("Yes\n");
	return 0;
}


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

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

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

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

int gcd(int a, int b){
  if(a % b ==  0) return b;
  else gcd(b, a%b);

}

int main(){

  int n,x;
  scanf("%d %d",&n,&x);

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

  city[n] = x;
  qsort(city, n+1, sizeof(int), sort);

  int difference[100001];
  for(int i = 0; i < n; ++i){
    difference[i] = city[i+1] -city[i];
  }

  qsort(difference, n, sizeof(int), sort);

  int ans = 0;
  int tmp = difference[0];
  for(int i = 0; i < n; ++i){
    tmp = gcd(tmp,difference[i]);
    ans = max(ans,tmp);
  }

  printf("%d",ans);

  return 0;

}

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int Gcd(int x, int y) {
  if (y == 0) return x;
  return Gcd(y, x % y);
}

int main(void) {
  int N, X;
  int x[MAX];
  scanf("%d %d", &N, &X);
  rep(i, 0, N) {
    scanf("%d", &x[i]);
  }

  int dist[MAX]; // 出発地点からの距離
  rep(i, 0, N) {
    dist[i] = abs(x[i] - X);
  }

  // 最大公約数を計算
  int ans = 0;
  rep(i, 0, N) {
    ans = Gcd(ans, dist[i]);
  }
  printf("%d\n", ans);
  return 0;
}


/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
#define llMIN 999999999999999
#define llMAX -99999999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
int gcd(int x,int y){if(y==0)return x;if(x<y)swap(&x,&y);return gcd(y,x%y);}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    int N,X,x[200000];
    int d[200000];

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

    qsort(x,N+1,sizeof(int),asc);
    int min=MIN,min_i;
    for(int i=1;i<=N;i++){
        d[i-1]=x[i]-x[i-1];
        if(min>x[i]-x[i-1]){
            min=x[i]-x[i-1];
            min_i=i-1;
        }
    }
    int x1,y1,tmp;
    int max_gcd=MAX;
    for(int i=0;i<N;i++){
        if(min_i==i)continue;
        if(max_gcd<gcd(d[i],min)){
            max_gcd=gcd(d[i],min);
        }
    }
    printf("%d\n",max_gcd);
    return 0;

}


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

#define ROOP(i,n) for(i=0;i<n;i++)

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

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

int gdc(int a, int b) {
	if (a == 0 || b == 0) {
		return a + b;
	}
	if (a > b) {
		return gdc(a%b, b);
	} else {
		return gdc(a, b%a);
	}
}

int main(void) {
	int n, i, j;
	int X;
	n = getint();
	X = getint();
	int x[n];
	int diff[n];
	ROOP(i, n) {
		x[i] = getint();
		diff[i] = abs(x[i] - X);
	}

	int a, b;
	a = diff[0];
	for(i = 1; i < n; i++) {
		b = diff[i];
		a = gdc(a, b);
	}
	showint(a);
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


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

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

long gcd(long a, long b){
	if(a % b == 0)return b;
	return gcd(b, a % b);
}

long absl(long in){
	if(in < 0)return -in;
	return in;
}

int main(void){
	long n, x, in, res;
	scanf("%ld %ld", &n, &x);
	for(int i = 0; i < n; i++){
		scanf("%ld", &in);
		if(i == 0)res = absl(in - x);
		res = gcd(res, absl(in - x));
	}
	printf("%d\n", res);
	return 0;
}


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

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

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

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

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

	return result;
}

static size_t x[100000];

int main(void) {
	size_t N, X;

	scanf("%zu %zu\n", &N, &X);
	for (size_t idx = 0; idx < N; idx++) {
		scanf("%zu", &x[idx]);
		if (idx < N - 1) {
			scanf(" ");
		}
	}

	qsort(x, N, sizeof(size_t), compare_f);

	size_t minAbss = (size_t)UINT32_MAX;

	if (X < x[0]) {
		const size_t rightAbssX = x[0] - X;
		if (rightAbssX < minAbss) {
			minAbss = rightAbssX;
		}
	}
	else if (x[N - 1] < X) {
		const size_t leftAbssX = X - x[N - 1];
		if (leftAbssX < minAbss) {
			minAbss = leftAbssX;
		}
	}

	for (size_t idx = 0; idx < N - 1; idx++) {
		const size_t abss = x[idx + 1] - x[idx];
		if (abss < minAbss) {
			minAbss = abss;
		}
		if (x[idx] < X && X < x[idx + 1]) {
			const size_t leftAbssX = X - x[idx];
			if (leftAbssX < minAbss) {
				minAbss = leftAbssX;
			}
			const size_t rightAbssX = x[idx + 1] - X;
			if (rightAbssX < minAbss) {
				minAbss = rightAbssX;
			}
		}
	}

	size_t dCandidate = minAbss;
	while (1 < dCandidate) {
		bool isCommonDivisor = true;
		for (size_t idx = 0; idx < N; idx++) {
			const size_t abss = ABSS(X, x[idx]);
			if (abss%dCandidate != 0) {
				isCommonDivisor = false;
			}
		}
		if (isCommonDivisor) {
			break;
		}
		dCandidate--;
	}

	printf("%zu\n", dCandidate);

	return 0;
}


Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

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

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


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

int main(void)
{
	int d, n;

	scanf("%d%d", &d, &n);
	printf("%.f\n", pow(100, d) * n + (n == 100));

	return 0;
}


#include <stdio.h>

int main(){
  int D,N;
  int t=1;
  scanf("%d%d",&D,&N);
  for(int i=0;i<D;i++)t*=100;
  if(N==100)N++;
  printf("%d\n",t*N);

  return 0;
}


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

//SEÇÃO DE DECLARAÇÃO
int N,D;
int i;

//SEÇÃO DE COMANDOS

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

int resposta = N;

if (N>=100){
    if (D==0){
        printf ("%d\n",resposta+1);
        return 0;
    }

    if (D==1 && N==100){
        printf ("%d\n",resposta);
        return 0;
    }
}

for (i=0;i<D;i++){
    resposta=resposta*100;
}

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

return 0;}


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

int main()
{
    int N,D,i=0,temp;

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

    if(D==0){
        printf("%d",N);
    } else if(D==2){
        printf("%d",N*100^2);
    }else{
        printf("%d",(N^D)*100);
    }

    return 0;
}