#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#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 MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&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);
}
double dmax(double a,double b){
    return a>b?a:b;
}

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 intpow(int a, int b){
    int i, c=1;
    rep(i, b){
        c *= a;
    }
    return c;
}

int main(void){
    int i, j, n, m=31, ans=-1, eval[2], f=0;             //0<m<41
    n = in();
    int x[n], y[n], d[31];                               //0<d_i<10^12+1
    rep(i,n){
        x[i] = in();                                     //x+y=u, x-y=v
        y[i] = in();                                     //u_i+1=x_i+y_i±d_i, v_i+1=x_i-y_i±d_i
        eval[i%2] = (x[i]+y[i])%2;
        if(i>0&&eval[0]!=eval[1]) f = 1;
    }
    if(f==0){
        if((x[0]+y[0])%2==0) m++;
        print(m);
        rep(i, 31){
            if((x[0]+y[0])%2!=0||i>0){
                d[i] = intpow(2, i);
                printf("%d ", d[i]);
            }
            else d[i]=0;
        }
        printf("\n");
        int u[32], v[32];

        rep(i, n){
            u[31]=x[i]+y[i]+intpow(2, 31)-1;              //u[30]=2*(d_a+d_b+...d_c)-2^31+1
            v[31]=x[i]-y[i]+intpow(2, 31)-1;              //v[30]=2*(d_a'+d_b'+...d_c')-2^31+1
            int a[31], b[31];                             //a[j]:d_jの正負, b[j]:d_jの正負
            rep(j, 31){
                if(abs(u[31-j]-d[30-j])<=d[30-j]){
                    a[30-j]=1;
                }
                else a[30-j]=-1;
                if(abs(v[i]-d[30-j])<=d[30-j]){
                    b[30-j]=1;
                }
                else b[30-j]=-1;
                u[30-j] = u[31-j]-d[30-j]*a[30-j];
                v[30-j] = v[31-j]-d[30-j]*b[30-j];
            }
            int x_1[32], y_1[32];
            for(j=1;j<32;j++){
                u[j]=u[j-1]+a[j-1]*d[j-1];
                v[j]=v[j-1]+a[j-1]+d[j];
                x_1[j]=u[j]+v[j];
                y_1[j]=u[j]-v[j];
                if(x_1[j]-x_1[j-1]<0) printf("L");
                else if(x_1[j]-x_1[j-1]>0) printf("R");
                else if(y_1[j]-y_1[j-1]<0) printf("D");
                else if(y_1[j]-y_1[j-1]>0) printf("U");
            }
            printf("\n");
        }
    }
    if(f==1) print(ans);
    return 0;
}

Score : 600 points

Problem Statement

Snuke is introducing a robot arm with the following properties to his factory:

The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i-1 and Joint i. The length of Section i is d_i.

For each section, its mode can be specified individually. There are four modes: L, R, D and U. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint i will be determined as follows (we denote its coordinates as (x_i, y_i)):

(x_0, y_0) = (0, 0).

If the mode of Section i is L, (x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1}).

If the mode of Section i is R, (x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1}).

If the mode of Section i is D, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i}).

If the mode of Section i is U, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i}).

Snuke would like to introduce a robot arm so that the position of Joint m can be matched with all of the N points (X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N) by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint m to each point (X_j, Y_j).

Constraints

All values in input are integers.

1 \leq N \leq 1000

-10^9 \leq X_i \leq 10^9

-10^9 \leq Y_i \leq 10^9

Partial Score

In the test cases worth 300 points, -10 \leq X_i \leq 10 and -10 \leq Y_i \leq 10 hold.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

Output

If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print -1.

m
d_1 d_2 ... d_m
w_1
w_2
:
w_N

m and d_i are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, 1 \leq m \leq 40 and 1 \leq d_i \leq 10^{12} must hold. Also, m and d_i must all be integers.

w_j is a string of length m that represents the way to bring Joint m of the robot arm to point (X_j, Y_j).
The i-th character of w_j should be one of the letters L, R, D and U, representing the mode of Section i.

Sample Input 1

3
-1 0
0 3
2 -1

Sample Output 1

2
1 2
RL
UU
DR

In the given way to bring Joint m of the robot arm to each (X_j, Y_j), the positions of the joints will be as follows:

To (X_1, Y_1) = (-1, 0): First, the position of Joint 0 is (x_0, y_0) = (0, 0). As the mode of Section 1 is R, the position of Joint 1 is (x_1, y_1) = (1, 0). Then, as the mode of Section 2 is L, the position of Joint 2 is (x_2, y_2) = (-1, 0).

To (X_2, Y_2) = (0, 3): (x_0, y_0) = (0, 0), (x_1, y_1) = (0, 1), (x_2, y_2) = (0, 3).

To (X_3, Y_3) = (2, -1): (x_0, y_0) = (0, 0), (x_1, y_1) = (0, -1), (x_2, y_2) = (2, -1).

Sample Input 2

5
0 0
1 0
2 0
3 0
4 0

Sample Output 2

-1

Sample Input 3

2
1 1
1 1

Sample Output 3

2
1 1
RU
UR

There may be duplicated points among (X_j, Y_j).

Sample Input 4

3
-7 -3
7 3
-3 -7

Sample Output 4

5
3 1 4 1 5
LRDUL
RDULR
DULRD


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

int main(){
  int i,j,l;
  int k=0;
  int r;
  char s[256];
  char t[256];
  char p;
  char q;

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

  r = strlen(s);

  for(i=r-1; i>=0; i--){
    if(s[i]!=t[i]){
      l=i;
      p=s[i];
      q=t[i];
      for(j=r-1; j>=0; j--){
        if(s[j]==q){
          s[j]=p;
        }else if(s[j]==p){
          s[j]=q;
        }
      }
    }
  }

  for(i=0; i<=r-1; i++){
    if(s[i]!=t[i]){
      k++;
    }
  }
  //printf("%d\n",k);
  if(k==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  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 strings S and T consisting of lowercase English letters.

You can perform the following operation on S any number of times:

Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.

Determine if S and T can be made equal by performing the operation zero or more times.

Constraints

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

|S| = |T|

S and T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

If S and T can be made equal, print Yes; otherwise, print No.

Sample Input 1

azzel
apple

Sample Output 1

Yes

azzel can be changed to apple, as follows:

Choose e as c_1 and l as c_2. azzel becomes azzle.

Choose z as c_1 and p as c_2. azzle becomes apple.

Sample Input 2

chokudai
redcoder

Sample Output 2

No

No sequences of operation can change chokudai to redcoder.

Sample Input 3

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3

Yes

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 <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int n,x,i,tmp,flag=0,count=0,a[110]={};
    scanf("%d %d",&n,&x);
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    do{ flag=0;
        for(i=0; i<n-1; i++){
            if(a[i]>a[i+1]){
                tmp=a[i];
                a[i]=a[i+1];
                a[i+1]=tmp;
                flag=1;
            }
        }
    }while(flag==1);
    i=0;
    flag=0;
    while(x-a[i]>=0){
        x-=a[i];
        count++;
        i++;
        flag=1;
        if(i>=n){
            flag=2;
            break;
        }
    }
    if(flag==2 && x>0){
        printf("%d",n-1);
        return 0;
    }
    if(flag==2){
        printf("%d",n);
        return 0;
    }
    printf("%d",count);
    return 0;
}

Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.


/*

結果:
*/
#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; }

//A:AC
//int main() {
//	int A = in();
//	int B = in();
//	int c;
//	int d;
//	int flg = 0;
//
//	for (c = 1; c <= 3; c++) {
//		d = (A*B*c) % 2;
//		if (d == 1) { flg = 1; }
//	}
//	if (flg) {
//		printf("%s\n", "Yes");
//	}
//	else {
//		printf("%s\n", "No");
//	}
//
//
//
//#ifdef DEBUGF
//	getch();
//#endif
//	return 0;
//	}

//B:AC
//int main() {
//
//	char w[100][11];
//	int n, i, j;
//	scanf("%d", &n);
//	for (i = 0; i<n; ++i)scanf("%s", w[i]);
//	for (i = 0; i<n - 1; ++i) {
//		for (j = i + 1; j<n; ++j) {
//			if (!strcmp(w[i], w[j])) {
//				puts("No");
//				return 0;
//			}
//		}
//	}
//	for (i = 1; i<n; ++i) {
//		if (w[i - 1][strlen(w[i - 1]) - 1] != w[i][0]) {
//			puts("No");
//			return 0;
//		}
//	}
//	puts("Yes");
//
//#ifdef DEBUGF
//	getch();
//#endif
//	return 0;
//	}

//C:AC
///// /////////////////////////////////////////////
///// <summary>
///// ユークリッドの互除法
/////機　能：ユークリッドの互除法によりa,bの最大公約数を求める
/////戻り値: 最大公約数、(自然数以外が指定されたときは-1)
///// </summary>
///// /////////////////////////////////////////////
//int euclid(int a, int b)
//{
//	int temp;
//	if (a < b) { temp = a; a = b; b = temp; }
//	if (b < 1) return -1;
//	if (a % b == 0) return b;
//	return euclid(b, a % b);
//}
//
//int main() {
//	int N, X,A[100000];
//	int a, b,ans;
//	scanf("%d%d", &N, &X);
//	for (int i = 0; i < N; i++) {
//		scanf("%d", &A[i]);
//	}
//	a = abs(X - A[0]);
//	if (N > 1) {
//		for (int i = 0; i < N-1; i++) {
//			b = abs(X - A[i+1]);
//			a = euclid(a, b);
//		}
//	}
//	ans = a;
//	print(a);
//
//#ifdef DEBUGF
//	getch();
//#endif
//	return 0;
//}

//D
int A[500][500] = { 0 };
int ans[250000][4] = { 0 };

int main() {
	int H, W;
	int n = 0;
	scanf("%d%d", &H, &W);
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			scanf("%d", &A[h][w]);
		}
	}

	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W - 1; w++) {
			if (A[h][w] % 2) {

				A[h][w + 1] += A[h][w];

				n++;
				ans[n][0] = h;
				ans[n][1] = w;
				ans[n][2] = h;
				ans[n][3] = w + 1;
			}
		}
	}
	for (int h = 0; h < H - 1; h++) {
		if (A[h][W - 1] % 2) {
			A[h + 1][W] += A[h][W - 1];

			n++;
			ans[n][0] = h;
			ans[n][1] = W;
			ans[n][2] = h + 1;
			ans[n][3] = W;
		}
	}

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

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

Score : 400 points

Problem Statement

There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j).

In Cell (i, j), a_{ij} coins are placed.

You can perform the following operation any number of times:

Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.

Maximize the number of cells containing an even number of coins.

Constraints

All values in input are integers.

1 \leq H, W \leq 500

0 \leq a_{ij} \leq 9

Input

Input is given from Standard Input in the following format:

H W
a_{11} a_{12} ... a_{1W}
a_{21} a_{22} ... a_{2W}
:
a_{H1} a_{H2} ... a_{HW}

Output

Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:

N
y_1 x_1 y_1' x_1'
y_2 x_2 y_2' x_2'
:
y_N x_N y_N' x_N'

That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations.

In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i').

Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.

Sample Input 1

2 3
1 2 3
0 1 1

Sample Output 1

3
2 2 2 3
1 1 1 2
1 3 1 2

Every cell contains an even number of coins after the following sequence of operations:

Move the coin in Cell (2, 2) to Cell (2, 3).

Move the coin in Cell (1, 1) to Cell (1, 2).

Move one of the coins in Cell (1, 3) to Cell (1, 2).

Sample Input 2

3 2
1 0
2 1
1 0

Sample Output 2

3
1 1 1 2
1 2 2 2
3 1 3 2

Sample Input 3

1 5
9 9 9 9 9

Sample Output 3

2
1 1 1 2
1 3 1 4


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

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

Score : 100 points

Problem Statement

Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.

Constraints

2\leq K\leq 100

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).

Sample Input 1

3

Sample Output 1

2

Two pairs can be chosen: (2,1) and (2,3).

Sample Input 2

6

Sample Output 2

9

Sample Input 3

11

Sample Output 3

30

Sample Input 4

50

Sample Output 4

625


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

return 0;
}


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

int main(void){
    int k;
    scanf("%d",&k);
    printf("%d\n",(k/2)*(k-k/2));
	return 0 ;
}


main(){int a,b,c,d;scanf("%d%d%d%d",&a,&c,&b,&d);printf("%d %d %d %d",b+c-d,b+d-a,a+c-d,b+c-a);}

Score : 200 points

Problem Statement

There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.
(Assume that the positive x-axis points right, and the positive y-axis points up.)

Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).

Given x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.

Constraints

|x_1|,|y_1|,|x_2|,|y_2| \leq 100

(x_1,y_1) ≠ (x_2,y_2)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

x_1 y_1 x_2 y_2

Output

Print x_3,y_3,x_4 and y_4 as integers, in this order.

Sample Input 1

0 0 0 1

Sample Output 1

-1 1 -1 0

(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.
Note that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.

Sample Input 2

2 3 6 6

Sample Output 2

3 10 -1 7

Sample Input 3

31 -41 -59 26

Sample Output 3

-126 -64 -36 -131


Score : 300 points

Problem Statement

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

Constraints

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

N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Sample Input 1

3 2

Sample Output 1

9

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

Sample Input 2

5 3

Sample Output 2

1

Sample Input 3

31415 9265

Sample Output 3

27

Sample Input 4

35897 932

Sample Output 4

114191


#include <stdio.h>

int main()
{
	int	n;
	int	i;

	scanf("%d %d", &n, &i);
	printf("%d\n", n-i+1);

	return 0;
}

Score : 100 points

Problem Statement

There is an N-car train.

You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."

Constraints

1 \leq N \leq 100

1 \leq i \leq N

Input

Input is given from Standard Input in the following format:

N i

Output

Print the answer.

Sample Input 1

4 2

Sample Output 1

3

The second car from the front of a 4-car train is the third car from the back.

Sample Input 2

1 1

Sample Output 2

1

Sample Input 3

15 11

Sample Output 3

5


/*ex5_3
  kt125 */

#include<stdio.h>
#define SIZE 100

int main(void){
    int height, width, //縦、横
        count, //'.'をカウントする変数
        i=0, j=0, k=0, //カウンタ変数
        row_del_num, //消去する行の数
        col_del_num, //消去する列の数
        height_ans, //答えとなる配列の縦の長さ
        width_ans, //答えをなる配列の横の長さ
    	col_del[SIZE], //消去する列の番号を記憶する配列
        row_del[SIZE];  //消去する行の番号を記憶する配列

    char board[SIZE][SIZE], //与えられたマス目の配列
         ans_row[SIZE * SIZE], //答えとなるマス目の文字を一列に並べた配列
    	 ans[SIZE][SIZE];  //答えとなる配列

    scanf("%d %d", &height, &width);

    for(i=0; i < height;i++){
        for (j=0; j < width; j++){
            scanf(" %c", &board[i][j]);
        }
    }

    for(i=0; i < height; i++){
        for(j=0; j < width; j++){
            if(board[i][j]== '.'){
                count++;
            }
        }
        if (count == width){ //i行が全て'.'だった場合
            row_del[k] = i; //配列の最初から順に用いるためにkを使う
            k++;
        }
        count = 0; //各行ごとにリセット
    }
    row_del_num = k; //消去する行の数

    k = 0; //リセット

    for(i=0; i < width; i++){
        for(j=0; j < height; j++){
            if(board[j][i]== '.'){
                count++;
            }
        }
        if (count == height){ //i列が全て'.'だった場合
            col_del[k] = i;
            k++;
        }
      	count = 0; //各列ごとにリセット
    }

    col_del_num = k; //消去する列の数

    for(i=0; i < row_del_num; i++){
        for (j=0; j < width; j++){
            board[row_del[i]][j] = 'o'; //消去する行の文字を'o'に置き換える
        }
    }
    for(i=0; i < col_del_num; i++){
        for (j=0; j < height; j++){
            board[j][col_del[i]] = 'o'; //消去する列の文字を'o'に置き換える
        }
    }
    k = 0; // リセット

    for(i=0; i < height; i++){
        for(j=0; j < width; j++){
            if (board[i][j] != 'o'){ //'o'を飛ばす
                ans_row[k] = board[i][j];
              	k++;
            }
        }
    }

    height_ans = height - row_del_num; //答えとなる配列の縦の長さ
    width_ans = width - col_del_num; //答えとなる配列の横の長さ

    for(i=0; i < height_ans; i++){
        for(j=0; j < width_ans;j++){
            ans[i][j] = ans_row[j + i * (width_ans)]; //一次元の配列をマス目に合うように二次元に直す
        }
    }

    for(i=0; i < height_ans;i++){
        for (j=0; j < width_ans; j++){
            printf("%c", ans[i][j]); //マス目をprint
        }
        printf("\n");
    }
    return 0;
}

Score : 200 points

Problem Statement

There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.

Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:

Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.

It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#


/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);

    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が少なくとも1マスも含まれる行のみ実行
        if(br[i] == 1){
            // このfor文が実行される行には黒が少なくとも1マス含まれている
            for(j = 0; j < col; j++){
                // 黒が少なくとも1マスも含まれる列のみ実行
                if(bc[j] == 1){
                    // マス目を出力
                    printf("%c", sq[i][j]);
                }
            }
            // 改行を出力
            printf("\n");
        }
    }
    return 0;
}


#if 0
cat <<EOF >mistaken-paste
#endif
// thx Ebi-chan!

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#define _USE_MATH_DEFINES

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

#define BIG 2000000007
#define VERYBIG 20000000000000007LL

#define MOD 1000000007
#define FOD  998244353
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 1048576

#ifdef __cplusplus
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <functional>
#include <array>

using std::queue;
using std::priority_queue;
using std::stack;
using std::tuple;
using std::set;
using std::map;
using std::vector;
using std::greater;
using std::pair;
using std::string;
using std::get;

template <typename T, typename U>
pair<T, U> operator+(pair<T, U> l, pair<T, U> r) {
	return pair<T, U>(l.first + r.first, l.second + r.second);
}

#endif

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	sll a;
	sll b;
	sll c;
} hwllc;

typedef struct {
	hwll a;
	hwll b;
} linell;

typedef struct {
	double a;
	double b;
} hwreal;

ull n, m;
ull h, w;
ull k;
ull q;
sll va, vb, vc, vd, ve, vf;
ull ua, ub, uc, ud, ue, uf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull umax (ull x, ull y) {
	return (x > y) ? x : y;
}

sll smin (sll x, sll y) {
	return (x < y) ? x : y;
}

sll smax (sll x, sll y) {
	return (x > y) ? x : y;
}

ull gcd (ull x, ull y) {
	if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}

ull bitpow (ull a, ull x, ull modulo) {
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= modulo;
		}
		x /= 2;
		a = (a * a) % modulo;
	}
	return result;
}

ull divide (ull a, ull b, ull modulo) {
	return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}

ull udiff (ull a, ull b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

sll sdiff (sll a, sll b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

int bitcount (ull n) {
	int result = 0;
	while (n) {
		if (n & 1) result++;
		n /= 2;
	}
	return result;
}

#define BEGCMP(NAME) int32_t NAME (const void *left, const void *right)
#define DEFLR(TYPE) TYPE l=*(TYPE*)left,r=*(TYPE*)right
#define CMPRET(L, R) if((L)<(R))return-1;if((L)>(R))return+1

// int32_t pullcomp (const void *left, const void *right) {
// 	ull l = *(ull*)left;
// 	ull r = *(ull*)right;
// 	if (l < r) {
// 		return -1;
// 	}
// 	if (l > r) {
// 		return +1;
// 	}
// 	return 0;
// }
BEGCMP(pullcomp){
	DEFLR(ull);
	CMPRET(l, r);
	return 0;
}
BEGCMP(prevcomp){
	DEFLR(sll);
	CMPRET(r, l);
	return 0;
}
BEGCMP(psllcomp){
	DEFLR(sll);
	CMPRET(l, r);
	return 0;
}
BEGCMP(pcharcomp){
	DEFLR(char);
	CMPRET(l, r);
	return 0;
}
BEGCMP(pdoublecomp){
	DEFLR(double);
	CMPRET(l, r);
	return 0;
}

int32_t pstrcomp (const void *left, const void *right) {
	char* l = *(char**)left;
	char* r = *(char**)right;

	return strcmp(l, r);
}

BEGCMP(phwllABcomp){
	DEFLR(hwll);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}
BEGCMP(phwllREVcomp){
	DEFLR(hwll);
	CMPRET(l.b, r.b);
	CMPRET(l.a, r.a);
	return 0;
}
BEGCMP(ptriplecomp){
	DEFLR(hwllc);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	CMPRET(l.c, r.c);
	return 0;
}
BEGCMP(ptripleREVcomp){
	DEFLR(hwllc);
	CMPRET(l.b, r.b);
	CMPRET(l.a, r.a);
	CMPRET(l.c, r.c);
	return 0;
}
BEGCMP(ptripleCABcomp){
	DEFLR(hwllc);
	CMPRET(l.c, r.c);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}
BEGCMP(phwrealcomp){
	DEFLR(hwreal);
	CMPRET(l.a, r.a);
	CMPRET(l.b, r.b);
	return 0;
}

int32_t pquadcomp (const void *left, const void *right) {
	linell l = *(linell*)left;
	linell r = *(linell*)right;

	sll ac = phwllABcomp(&(l.a), &(r.a));
	if (ac) return ac;
	sll bc = phwllABcomp(&(l.b), &(r.b));
	if (bc) return bc;

	return 0;
}
int32_t pfracomp (const void *left, const void *right) {
	hwllc l = *(hwllc*)left;
	hwllc r = *(hwllc*)right;

	CMPRET(l.a * r.b, l.b * r.a);
	return 0;
}

bool isinrange (sll left, sll x, sll right) {
	return (left <= x && x <= right);
}

bool isinrange_soft (sll left, sll x, sll right) {
	return (left <= x && x <= right) || (left >= x && x >= right);
}

sll a[N_MAX + 5];
// ull a[N_MAX + 5];
// sll a[3001][3001];
sll b[N_MAX + 5];
// ull b[N_MAX + 5];
// sll b[3001][3001];
sll c[N_MAX + 5];
sll d[N_MAX + 5];
sll e[N_MAX * 4];
char s[N_MAX + 1];
// char s[3010][3010];
char t[N_MAX + 1];
// char t[3010][3010];
char u[N_MAX + 1];
hwll xy[N_MAX * 2 + 5];
hwllc tup[N_MAX + 5];
// sll table[3005][3005];
ull gin[N_MAX];
// here we go

ull seg[524288], base = 262144;

ull update (ull v, ull x) {
	v += base;
	for (seg[v] = (seg[v] + x) % MOD; v; v >>= 1) seg[v >> 1] = (seg[v] + seg[v ^ 1]) % MOD;
}
ull find (ull l, ull r) {
	ull x = 0;
	for ((l += base), (r += base); l < r; (l >>= 1), (r >>= 1)) {
		if (l % 2) x += seg[l++];
		if (r % 2) x += seg[--r];
	}
	return x %= MOD;
}

ull solve () {
	sll i, j, ki, li;
	// ull result = 0;
	sll result = 0;
	double dresult = 0;
	// ull maybe = 0;
	sll maybe = 0;
	// ull sum = 0;
	sll sum = 0;
	sll item;
	sll *dpcell;

	if (m == 1) {
		puts("1");
		return 0;
	}

	ull len = 0;
	i = j = 0;
	while (i < n) {
		while (j < m && a[i] > b[j]) j++;

		if (j == m) break;
		if (j) {
			sll r = b[j] - a[i];
			sll l = a[i] - b[j - 1];

			xy[len++] = (hwll){l, r};
			// printf("%lld %lld...\n", l, r);
		}
		i++;
	}
	qsort(xy, len, sizeof(hwll), phwllREVcomp);
	i = j = 0;
	while (i < len) {
		++j;

		sll v = xy[i].b;
		while (i < len && xy[i].b == v) {
			xy[i].b = -j;
			i++;
		}
	}
	qsort(xy, len, sizeof(hwll), phwllABcomp);

	update(0, 1);

	sll rmax = 0;
	for (i = 0; i < len; i++) {
		if (i && xy[i - 1].a == xy[i].a && xy[i - 1].b == xy[i].b) continue;

		sll r = -xy[i].b;
		// printf("%lld %lld\n", xy[i].a, xy[i].b);

		update(r, find(0, r));
		if (rmax < r) {
			// update(r, 1);
			rmax = r;
		}

		// printf("%lld: %lld\n", r, seg[base + r]);
	}

	result = find(0, base);

	printf("%lld\n", result);
	// printf("%.15lf\n", dresult);
	// puts(s);

	return 0;

	success:
	// puts("YES");
	puts("Yes");
	// printf("%llu\n", result);
	// puts("0");
	// puts("First");
	return 0;

	fail:
	// puts("NO");
	// puts("No");
	// puts("0");
	puts("-1");
	// puts("-1 -1 -1");
	// puts("Second");
	return 1;
}

int32_t main (int argc, char *argv[]) {
	int32_t i, j;

	n = 5;
	m = 0;

	// scanf("%llu%llu", &h, &w);
	scanf("%llu%llu", &n, &m);
	// scanf("%llu", &k, &n, &m);
	// scanf("%llu%llu", &h, &w);
	// scanf("%llu", &q);
	// scanf("%lld", &va, &vb, &vc, &vd);
	// va--;
	// vb--;
	// scanf("%llu%llu%llu%llu", &ua, &ub, &uc, &ud, &ue);
	// scanf("%s", s);
	// scanf("%s", t);
	// scanf("%s", u);
	// scanf("%llu", &k);
	// scanf("%lld", &m);
	// for (i = 0; i < n; i++) {
	// 	scanf("%lld", &a[i]);
	// 	// scanf("%lld", &d[i]);
	// }
	// scanf("%llu", &q);
	for (i = 0; i < n; i++) {
		// scanf("%lld%lld", &xy[i].a, &xy[i].b);
		// scanf("%lld%lld%lld", &tup[i].a, &tup[i].b, &tup[i].c);
		// scanf("%lld", &c[i]);

		scanf("%lld", &a[i]);
		// scanf("%lld", &b[i]);
		// scanf("%lld", &c[i]);
		// scanf("%lld", &d[i]);
		// a[i]--;
		// b[i]--;
		// c[i]--;
		// d[i]--;
		// xy[i].a--;
		// xy[i].b--;
		// tup[i].a--;
		// tup[i].b--;
	}
	// scanf("%llu", &m);
	for (i = 0; i < m; i++) {
		// scanf("%lld%lld", &a[i], &b[i]);
		scanf("%lld", &b[i]);
		// a[i]--;
		// b[i]--;
		// scanf("%lld", &c[i]);
		// scanf("%lld", &d[i]);
		// scanf("%lld", &e[i]);
		// c[i]--;
		// d[i]--;
	}

	// for (i = 0; i < q; i++) {
	// 	// scanf("%lld%lld", &xy[i].a, &xy[i].b);
	// 	scanf("%lld", &c[i]);
	// 	// xy[i].a--;
	// 	// xy[i].b--;
	// }

	// for (i = 0; i < n; i++) {
	// 	for (j = 0; j < m; j++) {
	// 		scanf("%lld", &table[i][j]);
	// 		// table[i][j]--;
	// 	}
	// }
	// for (i = 0; i < h; i++) {
	// 	scanf("%s", s[i]);
	// }
	// scanf("%llu", &q);

	solve();

	return 0;
}

Score : 900 points

Problem Statement

There are N robots and M exits on a number line.
The N + M coordinates of these are all integers and all distinct.
For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i.
Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.

Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:

Increment the coordinates of all the robots on the number line by 1.

Decrement the coordinates of all the robots on the number line by 1.

Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit.
Snuke will continue performing operations until all the robots disappear.

When all the robots disappear, how many combinations of exits can be used by the robots?
Find the count modulo 10^9 + 7.
Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.

Constraints

1 \leq N, M \leq 10^5

1 \leq x_1 < x_2 < ... < x_N \leq 10^9

1 \leq y_1 < y_2 < ... < y_M \leq 10^9

All given coordinates are integers.

All given coordinates are distinct.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.

Sample Input 1

2 2
2 3
1 4

Sample Output 1

3

The i-th robot from the left will be called Robot i, and the j-th exit from the left will be called Exit j.
There are three possible combinations of exits (the exit used by Robot 1, the exit used by Robot 2) as follows:

(Exit 1, Exit 1)

(Exit 1, Exit 2)

(Exit 2, Exit 2)

Sample Input 2

3 4
2 5 10
1 3 7 13

Sample Output 2

8

The exit for each robot can be chosen independently, so there are 2^3 = 8 possible combinations of exits.

Sample Input 3

4 1
1 2 4 5
3

Sample Output 3

1

Every robot uses Exit 1.

Sample Input 4

4 5
2 5 7 11
1 3 6 9 13

Sample Output 4

6

Sample Input 5

10 10
4 13 15 18 19 20 21 22 25 27
1 5 11 12 14 16 23 26 29 30

Sample Output 5

22


/* main */
#include <stdio.h>
int main() {
	int n, c, r = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		c = 0;
		if (n % 2)continue;
		for (int j = 1; j <= i; j++)if (i%j == 0)c++;
		if (c == 8)r++;
	}
	printf("%d", r);
	return 0;
}

Score: 200 points

Problem Statement

The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

Constraints

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

Input

Input is given from Standard Input in the following format:

N

Output

Print the count.

Sample Input 1

105

Sample Output 1

1

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.

Sample Input 2

7

Sample Output 2

0

1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.


#include <stdio.h>

int main(viod)
{
        int n,a,i,j,s=0;

        scanf("%d",&n);

        for(i=1;i<=n;i++){
                a=0;
                for (j=1; j<=i;j++){
                        if (n%j==0)
                                a++;
                }
                if(a==8)
                        s++;
        }

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

        return 0;
}


#include<stdio.h>

int main()
{
    int num,tem,res=0;
    scanf("%d",&num);
    for(int i=1;i<=num;i++)
    {
        tem=0;
        if(i%2==1)
        {

            for(int j=1;j<=i;j++)
            {
            if(i%j==0)
            {
                tem++;
            }
            }
            if(tem==8) res++;
        }
    }
    printf("%d\n",res);
    return 0;
}


#include<stdio.h>
int main(){
  long long int a,b=0;
  char s[101];
  scanf("%s",s);
  scanf("%lld",&a);
  while(s[b]!='\0'){
    if(s[b]!='1'||b+1==a){
      printf("%c",s[b]);
      break;
    }
    b++;
  }
  return 0;}

Score: 300 points

Problem Statement

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.
You are interested in what the string looks like after 5 \times 10^{15} days. What is the K-th character from the left in the string after 5 \times 10^{15} days?

Constraints

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

K is an integer between 1 and 10^{18} (inclusive).

The length of the string after 5 \times 10^{15} days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5 \times 10^{15} days.

Sample Input 1

1214
4

Sample Output 1

2

The string S changes as follows:

Now: 1214

After one day: 12214444

After two days: 1222214444444444444444

After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444

The first five characters in the string after 5 \times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.

Sample Input 2

3
157

Sample Output 2

3

The initial string is 3. The string after 5 \times 10^{15} days consists only of 3.

Sample Input 3

299792458
9460730472580800

Sample Output 3

2


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

#define N 100

int main() {
	static char s[N + 1];
	int n, i;
	long long k;

	scanf("%s%lld", s, &k);
	n = strlen(s);
	for (i = 0; i < n && s[i] == '1'; i++)
		k--;
	printf("%c\n", k <= 0 ? '1' : s[i]);
	return 0;
}


#include <stdio.h>

int main() {
  int N, M, Q;
  int L[M], R[M];
  int p, q;

  int i, j;
  int count;

  scanf("%d %d %d", &N, &M, &Q);

  for (i = 0; i < M; i++) {
    scanf("%d %d", &L[i], &R[i]);
  }

  for (i = 0; i < Q; i++) {
    scanf("%d %d", &p, &q);
    count = 0;
    for (j = 0; j < M; j++) {
      if (p <= L[j] && R[j] <= q) {
        count++;
      }
    }
    printf("%d\n", count);
  }

  return 0;
}

Score: 400 points

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).
Takahashi the king is interested in the following Q matters:

The number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.

Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

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

M is an integer between 1 and 200 \ 000 (inclusive).

Q is an integer between 1 and 100 \ 000 (inclusive).

1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)

1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q

Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.

Sample Input 1

2 3 1
1 1
1 2
2 2
1 2

Sample Output 1

3

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.

Sample Input 2

10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2

1
1

The first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.
The second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.

Sample Input 3

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

Sample Output 3

7
9
10
6
8
9
6
7
8
10


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

Score : 100 points

Problem Statement

Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.
When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

Constraints

1 \leq N,K \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

Sample Input 1

7 3

Sample Output 1

1

When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.

Sample Input 2

100 10

Sample Output 2

0

The crackers can be distributed evenly.

Sample Input 3

1 1

Sample Output 3

0


#include <stdio.h>

int main(void){
	int k, n;
	scanf("%d %d", &n, &k);
	if(n % k == 0)
		printf("0\n");
	else
		printf("1\n");
	return 0;
}


#include<stdio.h>

main()
{
    int n,flag=0,i,j;
    scanf("%d",&n);
    if(n%4==0)
        printf("Yes");
    else if(n%7==0)
        printf("Yes");
    else
    {
        for(i=1;i<10;i++)
        {
            for(j=1;j<10;j++)
            {
            if((4*i+7*j)==n)
            {
                flag=1;
                break;
            }
            }
        }
        if(flag)
            printf("yes");
            else
                printf("No");

    }
}

Score : 200 points

Problem Statement

La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.
Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.

Constraints

N is an integer between 1 and 100, inclusive.

Input

Input is given from Standard Input in the following format:

N

Output

If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.

Sample Input 1

11

Sample Output 1

Yes

If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.

Sample Input 2

40

Sample Output 2

Yes

If you buy ten cakes, the total will be 4 \times 10 = 40 dollars.

Sample Input 3

3

Sample Output 3

No

The prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than 3 dollars, so there is no such way.


#include<stdio.h>

int main(void)
{
	int n, i = 0, j = 0;
	if (scanf("%d", &n) == 1);

	if (n == 7)
	{
		printf("Yes\n");
		return 0;
	}

	while (i <= n)
	{
		i += 4;
		while (i + j <= n)
		{
			if (i + j == n)
			{
				printf("Yes\n");
				return 0;
			}
			j += 7;
		}
		j = 0;
	}
	printf("No\n");
	return 0;
}


#include <stdio.h>

int main(void)
{
        int n,a,b,i;

        scanf("%d",&n);

        a=n;

        if ((n%7==0)||(n%4==0)){
                printf("Yes\n");
                return 0;
        }

        else if (n<4){
                printf("No\n");
                return 1;
        }

        for (i=1;i>0;i++){
                a=a-4;
                if (a%7==0){
                        printf("Yes\n");
                        return 0;
                }
                if (a<7)
                        break;
        }

        printf("No\n");

        return 0;
}


/*
cat <<EOF >mistaken-paste
*/

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#define _USE_MATH_DEFINES

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

#define BIG 2000000007
#define VERYBIG 2000000000000007LL

#define MOD 1000000007
#define FOD  998244353
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 1000000
#define M_MAX 200000

#ifdef __cplusplus
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <string>

using std::queue;
using std::priority_queue;
using std::stack;
using std::tuple;
using std::set;
using std::map;
using std::vector;
using std::greater;
using std::pair;
using std::string;

#endif

typedef struct {
	int32_t a;
	int32_t b;
} hw;

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	sll a;
	sll b;
	sll c;
} hwllc;

typedef struct {
	hwll a;
	hwll b;
} linell;

ull n, m;
ull h, w;
ull k;
ull q;
sll va, vb, vc, vd, ve, vf;
ull ua, ub, uc, ud, ue, uf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
char ch, dh;

ull umin (ull x, ull y) {
	return (x < y) ? x : y;
}

ull umax (ull x, ull y) {
	return (x > y) ? x : y;
}

sll smin (sll x, sll y) {
	return (x < y) ? x : y;
}

sll smax (sll x, sll y) {
	return (x > y) ? x : y;
}

ull gcd (ull x, ull y) {
	if (x < y) {
		return gcd(y, x);
	} else if (y == 0) {
		return x;
	} else {
		return gcd(y, x % y);
	}
}

ull bitpow (ull a, ull x, ull modulo) {
	ull result = 1;
	while (x) {
		if (x & 1) {
			result *= a;
			result %= modulo;
		}
		x /= 2;
		a = (a * a) % modulo;
	}
	return result;
}

ull divide (ull a, ull b, ull modulo) {
	return (a * bitpow(b, modulo - 2, modulo)) % modulo;
}

ull udiff (ull a, ull b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

sll sdiff (sll a, sll b) {
	if (a >= b) {
		return a - b;
	} else {
		return b - a;
	}
}

int bitcount (ull n) {
	int result = 0;
	while (n) {
		if (n & 1) result++;
		n /= 2;
	}
	return result;
}

// double distance (sll x1, sll y1, sll x2, sll y2) {
// 	double xdist2, ydist2, origindist, dist;

// 	xdist2 = (x1 - x2) * (x1 - x2);
// 	ydist2 = (y1 - y2) * (y1 - y2);
// 	return sqrt(xdist2 + ydist2);
// }

int32_t pullcomp (const void *left, const void *right) {
	ull l = *(ull*)left;
	ull r = *(ull*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

int32_t psllcomp (const void *left, const void *right) {
	sll l = *(sll*)left;
	sll r = *(sll*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

int32_t pcharcomp (const void *left, const void *right) {
	char l = *(char*)left;
	char r = *(char*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

int32_t pdoublecomp (const void *left, const void *right) {
	double l = *(double*)left;
	double r = *(double*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

int32_t pstrcomp (const void *left, const void *right) {
	char* l = *(char**)left;
	char* r = *(char**)right;

	return strcmp(l, r);
}

int32_t phwllABcomp (const void *left, const void *right) {
	hwll l = *(hwll*)left;
	hwll r = *(hwll*)right;
	if (l.a < r.a) {
		return -1;
	}
	if (l.a > r.a) {
		return +1;
	}
	if (l.b < r.b) {
		return -1;
	}
	if (l.b > r.b) {
		return +1;
	}
	return 0;
}

int32_t phwllREVcomp (const void *left, const void *right) {
	hwll l = *(hwll*)left;
	hwll r = *(hwll*)right;
	if (l.b < r.b) {
		return -1;
	}
	if (l.b > r.b) {
		return +1;
	}
	if (l.a < r.a) {
		return -1;
	}
	if (l.a > r.a) {
		return +1;
	}
	return 0;
}

int32_t ptriplecomp (const void *left, const void *right) {
	hwllc l = *(hwllc*)left;
	hwllc r = *(hwllc*)right;

	if (l.a < r.a) {
		return -1;
	}
	if (l.a > r.a) {
		return +1;
	}
	if (l.b < r.b) {
		return -1;
	}
	if (l.b > r.b) {
		return +1;
	}
	if (l.c < r.c) {
		return -1;
	}
	if (l.c > r.c) {
		return +1;
	}
	return 0;
}

bool isinrange (sll left, sll x, sll right) {
	return (left <= x && x <= right);
}

bool isinrange_soft (sll left, sll x, sll right) {
	return (left <= x && x <= right) || (left >= x && x >= right);
}

sll a[N_MAX];
// sll a[3001][3001];
sll b[N_MAX];
// sll b[3001][3001];
sll c[N_MAX];
// sll d[N_MAX];
// sll e[N_MAX];
char s[N_MAX + 1];
// char s[3010][3010];
char t[N_MAX + 1];
// char t[3010][3010];
// hwll xy[N_MAX];
// sll table[1000][1000];

bool ok[N_MAX];

ull solve () {
	sll i, j, ki, li;
	ull result = 0;
	// sll result = 0;
	double dresult = 0;
	// ull maybe = 0;
	sll maybe = 0;
	// ull sum = 0;
	sll sum = 0;
	sll item;
	ull *dpcell;

	for (i = 0; i <= n; i++) {
		ok[i] = false;
		if (i == 0) ok[i] = true;
		if (i >= 4 && ok[i - 4]) ok[i] = true;
		if (i >= 7 && ok[i - 7]) ok[i] = true;
	}
	if (ok[n]) {
		goto success;
	} else {
		goto fail;
	}

	// printf("%lld\n", result);
	// printf("%.15lf\n", dresult);
	// puts(s);

	return 0;

	success:
	// puts("YES");
	puts("Yes");
	// printf("%llu\n", result);
	// puts("0");
	// puts("AC");
	return 0;

	fail:
	// puts("NO");
	puts("No");
	// puts("0");
	// puts("-1");
	// puts("-1 -1 -1");
	// puts("WA");
	return 1;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	// scanf("%llu", &n, &m);
	// scanf("%llu", &k, &n, &m);
	// scanf("%llu%llu", &h, &w);
	scanf("%lld", &va, &vb, &vc, &vd);
	// scanf("%llu%llu", &ua, &ub, &uc, &ud);
	// scanf("%llu", &q);
	// scanf("%s", s);
	// scanf("%s", t);
	// for (i = 0; i < n; i++) {
	// 	// scanf("%lld%lld", &xy[i].a, &xy[i].b);
	// 	scanf("%lld", &a[i]);
	// 	scanf("%lld", &b[i]);
	// 	// scanf("%lld", &c[i]);
	// 	// scanf("%lld", &d[i]);
	// 	// a[i]--;
	// 	// b[i]--;
	// 	// c[i]--;
	// }
	// scanf("%llu", &m, &k);
	// scanf("%llu", &q);
	// for (i = 0; i < k; i++) {
	// 	scanf("%lld", &e[i]);
	// 	e[i]--;
	// 	scanf("%lld", &d[i]);
	// }

	// for (i = 0; i < n; i++) {
	// 	for (j = 0; j < n; j++) {
	// 		scanf("%llu", &table[i][j]);
	// 	}
	// }
	// for (i = 0; i < h; i++) {
	// 	scanf("%s", &s[i]);
	// }

	solve();

	return 0;
}


Score : 300 points

Problem Statement

Given an integer N, find the base -2 representation of N.

Here, S is the base -2 representation of N when the following are all satisfied:

S is a string consisting of 0 and 1.

Unless S = 0, the initial character of S is 1.

Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N.

It can be proved that, for any integer M, the base -2 representation of M is uniquely determined.

Constraints

Every value in input is integer.

-10^9 \leq N \leq 10^9

Input

Input is given from Standard Input in the following format:

N

Output

Print the base -2 representation of N.

Sample Input 1

-9

Sample Output 1

1011

As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.

Sample Input 2

123456789

Sample Output 2

11000101011001101110100010101

Sample Input 3

0

Sample Output 3

0


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

/*以下便利なマクロを定義する。*/

#define rep(i, min, max) for(i=min; i<=max; i=i+1)

#define if_forall(i, min, max, prop)\
\
	rep(i, min, max)\
	{\
		if(!(prop))\
		{\
			break;\
		}\
	}\
\
	if(i==max+1)\

#define if_exists(i, min, max, prop)\
\
	rep(i, min, max)\
	{\
		if(prop)\
		{\
			break;\
		}\
	}\
\
	if(i<max+1)\

#define sum(i, min, max, sequence, answer)\
{\
	answer=0;\
	rep(i, min, max)\
	{\
		answer=answer+sequence;\
	}\
}\

#define prod(i, min, max, sequence, answer)\
{\
	answer=1;\
	rep(i, min, max)\
	{\
		answer=answer*sequence;\
	}\
}\

/*以下便利な関数を定義する。*/

void fill_int(int array[], int min, int max, int element)
{
	int i=min;

	rep(i, min, max)
	{
		array[i]=element;
	}

}

void fill_char(char array[], int min, int max, char element)
{
	int i=min;

	rep(i, min, max)
	{
		array[i]=element;
	}

}

void  swap_int(int* x, int* y)
{
    int  tmp;

    tmp = *x;
    *x = *y;
    *y = tmp;
}

void  swap_int_array(int x[], int y[], int min, int max)
{
	int i;

    rep(i, min, max)
	{
		swap_int(&x[i], &y[i]);
	}
}

void  swap_char(char* x, char* y)
{
    char  tmp;

    tmp = *x;
    *x = *y;
    *y = tmp;
}

void  swap_char_array(char x[], char y[], int min, int max)
{
	int i;

    rep(i, min, max)
	{
		swap_char(&x[i], &y[i]);
	}
}

void reverse_char(char array[], int min, int max)
{
	int i;

	rep(i, min, (min+max)/2)
	{
		swap_char(&array[i], &array[min+max-i]);
	}
}

int max_int(int var1, int var2)
{
	int answer=var1;

	if(answer<var2)
	{
		answer=var2;
	}

	return answer;
}

int min_int(int var1, int var2)
{
	int answer=var1;

	if(answer>var2)
	{
		answer=var2;
	}

	return answer;
}

long int pow_int(int base, unsigned int exponent)
{
	long int answer=1;

	answer=(long int)pow((double)base, (double)exponent);

	return answer;
}

long int pow_int_mod(int base, unsigned int exponent, int mod)
{
	long int answer=1;
	while (exponent>0)
	{
		if (exponent&1)
		{
			answer=(answer*(base%mod))%mod;
			if(answer==0)
			{
				break;
			}
		}
		base=(base*base)%mod;
		exponent=exponent>>1;
	}
	return answer;
}

unsigned long int factorial(unsigned int num)
{
	unsigned int i=0;
	unsigned long int answer=1;
	rep(i, 2, num)
	{
		answer=answer*i;
	}
	return answer;
}

unsigned long int factorial_mod(unsigned int num, int mod)
{
	unsigned int i=0;
	unsigned long int answer=1;
	rep(i, 2, num)
	{
		answer=(answer*(i%mod))%mod;
		if(answer==0)
		{
			break;
		}
	}
	return answer;
}

unsigned long int combination(unsigned int n, unsigned int k)
{
	unsigned int i=0;
	unsigned long int numerator=1;
	unsigned long int denominator=1;

	k=min_int(k, n-k);

	rep(i, 2, k)
	{
		numerator=numerator*(n+1-i);
		denominator=denominator*i;
	}
	return numerator/denominator;
}

double combination_general(double alpha, unsigned int k)
{
	unsigned int i;
	double numerator=1;
	unsigned long int denominator=1;

	rep(i, 1, k)
	{
		numerator=numerator*(alpha+1-i);
		denominator=denominator*i;
	}
	return numerator/denominator;
}

int gcd(int a, int b)
{
	if(a<b)
	{
		swap_int(&a, &b);
	}

	int r=a%b;

	while(r!=0)
	{
		a=b;
		b=r;
		r=a%b;
	}

	return b;
}

int lcm(int a, int b)
{
	return (a/gcd(a, b))*b;
}

int order(long int num)
{
	int answer=-1;
	while(num!=0)
	{
		num=num/10;
		answer=answer+1;
	}
	return answer;
}

long int convert_adic_int(char num[], unsigned int p_adic, unsigned int q_adic)
{
	int i=0;
	long int answer=0;
	bool sgn=0;
	long int tmp=strtol(num, NULL, p_adic);

	if(tmp<0)
	{
		sgn=1;
		tmp=-tmp;
	}

	while(tmp>0)
	{
		answer=answer+(tmp%q_adic)*pow_int(10, i);
		tmp=tmp/q_adic;
		i=i+1;
	}

	if(sgn==0)
	{
		return answer;
	}
	else
	{
		return -answer;
	}
}

void convert_adic_char(char num[], unsigned int p_adic, unsigned int q_adic)
{
	int i=0;
	int mod[32]={0};
	bool sgn=0;
	int digit=0;
	long int tmp=strtol(num, NULL, p_adic);

	if(tmp<0)
	{
		sgn=1;
		tmp=-tmp;
	}

	while(tmp>0)
	{
		mod[i]=tmp%q_adic;

		digit=i;
		tmp=tmp/q_adic;
		i=i+1;
	}

	fill_char(num, 0, strlen(num)-1, '\0');

	if(sgn==1)
	{
		num[0]='-';
	}

	rep(i, 0, digit)
	{
		if(mod[i]<10)
		{
			num[sgn+digit-i]='0'+mod[i];
		}
		else if(mod[i]<q_adic)
		{
			num[sgn+digit-i]='a'+(mod[i]-10);
		}
	}
}

int sum_digit(int num)
{
	int answer=0;
	num=abs(num);

	while(num>0)
	{
		answer=answer+num%10;
		num=num/10;
	}
	return answer;
}

int count_mod(int min, int max, int num)
{
	if(min>0)
	{
		return max/num-(min-1)/num;
	}
	else if(min==0)
	{
		return max/num+1;
	}
	else
	{
		return -1;
	}
}

void shift_char(char array[], int min, int max, int num)
{
	int i;

	for(i=max; i>=min; i=i-1)
	{
		array[i+num]=array[i];
	}

	rep(i, min, min+num-1)
	{
		array[i]='\0';
	}
}

void convert_char(char array[], int min, int max, char pre, char post)
{
	int i=min;

	rep(i, min, max)
	{
		if(array[i]==pre)
		{
			array[i]=post;
		}
	}
}

void sort_asc_int(int array[], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(array[i]>array[j])
			{
				swap_int(&array[i], &array[j]);
			}
		}
	}
}

void sort_des_int(int array[], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(array[i]<array[j])
			{
				swap_int(&array[i], &array[j]);
			}
		}
	}
}

void sort_asc_char_dic(char array[], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(strcmp(&array[i], &array[j])>0)
			{
				swap_char(&array[i], &array[j]);
			}
		}
	}
}

void sort_asc_char_array_dic(int size, char array[][size], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(strcmp(array[i], array[j])>0)
			{
				swap_char_array(array[i], array[j], 0, size-1);
			}
		}
	}
}

void sort_des_char_dic(char array[], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(strcmp(&array[i], &array[j])<0)
			{
				swap_char(&array[i], &array[j]);
			}
		}
	}
}

void sort_des_char_array_dic(int size, char array[][size], int min, int max)
{
	int i, j;

	rep(i, min, max)
	{
		rep(j, i+1, max)
		{
			if(strcmp(array[i], array[j])<0)
			{
				swap_char_array(array[i], array[j], 0, size-1);
			}
		}
	}
}

int max_int_array(int array[], int min, int max)
{
	int i;
	int answer;

	answer=array[min];

	for(i=min+1; i<=max; i=i+1)
	{
		answer=max_int(answer, array[i]);
	}

	return answer;
}

void max_int_array_num(int array[], int min, int max, int answer[])
{
	int i=min;
	int count=0;
	int max_value=max_int_array(array, min, max);

	fill_int(answer, 0, max-min, -1);

	rep(i, min, max)
	{
		if(array[i]==max_value)
		{
			answer[count]=i;
			count=count+1;
		}
	}
}

int min_int_array(int array[], int min, int max)
{
	int i;
	int answer;

	answer=array[min];

	for(i=min+1; i<=max; i=i+1)
	{
		answer=min_int(answer, array[i]);
	}

	return answer;
}

void min_int_array_num(int array[], int min, int max, int answer[])
{
	int i=min;
	int count=0;
	int min_value=min_int_array(array, min, max);

	fill_int(answer, 0, max-min, -1);

	rep(i, min, max)
	{
		if(array[i]==min_value)
		{
			answer[count]=i;
			count=count+1;
		}
	}
}

int max_char_array_dic(int size, char array[][size], int min, int max)
{
	int i;
	int answer=min;

	rep(i, min+1, max)
	{
		if(strcmp(array[answer], array[i])<0)
		{
			answer=i;
		}
	}

	return answer;
}

int min_char_array_dic(int size, char array[][size], int min, int max)
{
	int i;
	int answer=min;

	rep(i, min+1, max)
	{
		if(strcmp(array[answer], array[i])>0)
		{
			answer=i;
		}
	}

	return answer;
}

int sum_array(int array[], int min, int max)
{
	int i=min;
	int answer=0;

	rep(i, min, max)
	{
		answer=answer+array[i];
	}

	return answer;
}

bool detect_int(int array[], int min, int max, int element)
{
	int i;
	bool answer=0;

	if_exists(i, min, max, array[i]==element)
	{
		answer=1;
	}

	return answer;
}

bool detect_char(char array[], int min, int max, char element)
{
	int i;
	bool answer=0;

	if_exists(i, min, max, array[i]==element)
	{
		answer=1;
	}
	return answer;
}

bool detect_char_array(char array[], int min, int max, char element[], int start, int goal)
{
	int i, j;
	bool answer=0;

	if(goal-start<=max-min)
	{
		rep(i, min, max-(goal-start))
		{
			if_forall(j, start, goal, array[i+j-start]==element[j])
			{
				answer=1;
				break;
			}
		}
	}

	return answer;
}

int count_differentelement_int(int array[], int min, int max)
{
	int i=min;
	int pickup[max];
	fill_int(pickup, 0, max, 0);
	int answer=0;

	rep(i, min, max)
	{
		if(detect_int(pickup, 0, answer-1, array[i])==0)
		{
			pickup[answer]=array[i];
			answer=answer+1;
		}
	}

	return answer;
}

int count_differentelement_char(char array[], int min, int max)
{
	int i=min;
	char pickup[max];
	fill_char(pickup, 0, max, '\0');
	int answer=0;

	rep(i, min, max)
	{
		if(detect_char_array(pickup, 0, answer-1, array, i, i)==0)
		{
			pickup[answer]=array[i];
			answer=answer+1;
		}
	}

	return answer;
}

int count_equalelement_int(int array[], int min, int max, int element)
{
	int i;
	int answer=0;

	rep(i, min, max)
	{
		if(array[i]==element)
		{
			answer=answer+1;
		}
	}

	return answer;
}

int count_equalelement_char(char array[], int min, int max, char element)
{
	int i;
	int answer=0;

	rep(i, min, max)
	{
		if(array[i]==element)
		{
			answer=answer+1;
		}
	}

	return answer;
}

int count_equalelement_char_array(int size, char array[][size], int min, int max, char element[])
{
	int i;
	int answer=0;

	rep(i, min, max)
	{
		if(strcmp(array[i], element)==0)
		{
			answer=answer+1;
		}
	}
	return answer;
}

void scanf_int_array(int array[], int min, int max)
{
	int i;
	rep(i, min, max)
	{
		scanf("%d", &array[i]);
	}
}

void scanf_int_array_2(int array1[], int array2[], int min, int max)
{
	int i;
	rep(i, min, max)
	{
		scanf("%d %d", &array1[i], &array2[i]);
	}
}

void scanf_int_array_3(int array1[], int array2[], int array3[], int min, int max)
{
	int i;
	rep(i, min, max)
	{
		scanf("%d %d %d", &array1[i], &array2[i], &array3[i]);
	}
}

void scanf_char_array(char array[], int num)
{
	scanf("%s", array);
	shift_char(array, 0, strlen(array)-1, num);
}

void printf_int_array(int array[], int min, int max)
{
	int i;
	rep(i, min, max)
	{
		printf("%d\n", array[i]);
	}
}

void printf_char_array(char array[], int min, int max)
{
	int i;
	for(i=min; i<=max; i=i+1)
	{
		printf("%c", array[i]);
	}
}

int main()
{
	int i;
	char S[11];
	scanf("%s", S);
	int l=strlen(S);

	bool cond=1;
	int count=0;

	if(S[0]!='A')
	{
		cond=0;
	}
	if(!(0x61<=S[1] && S[1]<=0x7a))
	{
		cond=0;
	}
	rep(i, 2, l-2)
	{
		if(S[i]=='C')
		{
			count=count+1;
		}
		else if(!(0x61<=S[i] && S[i]<=0x7a))
		{
			cond=0;
		}

		if(count>1)
		{
			cond=0;
		}
		if(cond==0)
		{
			break;
		}
	}
	if(!(0x61<=S[l-1] && S[l-1]<=0x7a))
	{
		cond=0;
	}

	if(cond==1)
	{
		printf("AC\n");
	}
	else
	{
		printf("WA\n");
	}

	return 0;
}

Score : 200 points

Problem Statement

You are given a string S. Each character of S is uppercase or lowercase English letter.
Determine if S satisfies all of the following conditions:

The initial character of S is an uppercase A.

There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).

All letters except the A and C mentioned above are lowercase.

Constraints

4 ≤ |S| ≤ 10 (|S| is the length of the string S.)

Each character of S is uppercase or lowercase English letter.

Input

Input is given from Standard Input in the following format:

S

Output

If S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.

Sample Input 1

AtCoder

Sample Output 1

AC

The first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.

Sample Input 2

ACoder

Sample Output 2

WA

The second letter should not be C.

Sample Input 3

AcycliC

Sample Output 3

WA

The last letter should not be C, either.

Sample Input 4

AtCoCo

Sample Output 4

WA

There should not be two or more occurrences of C.

Sample Input 5

Atcoder

Sample Output 5

WA

The number of C should not be zero, either.


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

int main(int argc, char const *argv[])
{
    char s[10];
    int len, count, i;
    scanf("%s", s);
    len = strlen(s);
    if (s[0] != 'A')
    {
        printf("WA\n");
        return 0;
    }

    count = 0;
    for (i = 1; i < len - 1; i++)
    {
        if (('A' <= s[i]) && (s[i] <= 'Z'))
        {
            count++;
        }
    }
    if (count != 1)
    {
        printf("WA\n");
        return 0;
    }

    count = 0;
    for (i = 2; i < len - 2; i++)
    {
        if (s[i] == 'C')
        {
            count++;
        }
    }
    if (count != 1)
    {
        printf("WA\n");
        return 0;
    }

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


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

int main() {
  char s[10];
  int l = 0;
  scanf("%s", s);
  l = strlen(s);
  if (s[0] != 'A') {
    printf("WA");
    exit(1);
  }

  int i = 0;
  int t = 0;
  for (i = 2; i < l-1; i++) {
    if (s[i] == 'C') {
      t++;
    }
  }

  if (t != 1) {
    printf("WA");
    exit(1);
  }
  t = 0;
  for (i = 0; i < l; i++) {
    if (s[i] <= 'Z') {
      t++;
    }
  }

  if (t == 2) {
    printf("AC");
  }
  else {
    printf("WA");
  }
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

signed main(){
	int N, i, j;
	char *S = (char *)malloc(sizeof(char) * 100002);
	scanf("%s", &S[1]);
	for(N = 0; S[N] != '\0'; N++){}
	N--;
	int *dpA = (int *)malloc(sizeof(int) * (N + 1));
	int *dpAB = (int *)malloc(sizeof(int) * (N + 1));
	int *dpABC = (int *)malloc(sizeof(int) * (N + 1));
	dpA[0] = 0;
	dpAB[0] = 0;
	dpABC[0] = 0;
	for(i = 1, j = 0; i <= N; i++){
		if(S[i] == 'A'){
			dpA[i] = MOD(dpA[i - 1] + power(3, j));
		}
		else if(S[i] == '?'){
			dpA[i] = MOD(3 * dpA[i - 1] + power(3, j));
			j++;
		}
		else{
			dpA[i] = MOD(dpA[i - 1]);
		}
	}
	for(i = 1; i <= N; i++){
		if(S[i] == 'B'){
			dpAB[i] = MOD(dpAB[i - 1] + dpA[i - 1]);
		}
		else if(S[i] == '?'){
			dpAB[i] = MOD(3 * dpAB[i - 1] + dpA[i - 1]);
		}
		else{
			dpAB[i] = MOD(dpAB[i - 1]);
		}
	}
	for(i = 1; i <= N; i++){
		if(S[i] == 'C'){
			dpABC[i] = MOD(dpABC[i - 1] + dpAB[i - 1]);
		}
		else if(S[i] == '?'){
			dpABC[i] = MOD(3 * dpABC[i - 1] + dpAB[i - 1]);
		}
		else{
			dpABC[i] = MOD(dpABC[i - 1]);
		}
	}
/*	printf("dpA:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", dpA[i]);
	}
	printf("\n");
	printf("dpAB:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", dpAB[i]);
	}
	printf("\n");
	printf("dpABC:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", dpABC[i]);
	}
	printf("\n");
*/	printf("%lld\n", dpABC[N]);
	return 0;
}

Score : 400 points

Problem Statement

The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:

1 ≤ i < j < k ≤ |T| (|T| is the length of T.)

T_i = A (T_i is the i-th character of T from the beginning.)

T_j = B

T_k = C

For example, when T = ABCBC, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.

You are given a string S. Each character of S is A, B, C or ?.

Let Q be the number of occurrences of ? in S. We can make 3^Q strings by replacing each occurrence of ? in S with A, B or C. Find the sum of the ABC numbers of all these strings.

This sum can be extremely large, so print the sum modulo 10^9 + 7.

Constraints

3 ≤ |S| ≤ 10^5

Each character of S is A, B, C or ?.

Input

Input is given from Standard Input in the following format:

S

Output

Print the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.

Sample Input 1

A??C

Sample Output 1

8

In this case, Q = 2, and we can make 3^Q = 9 strings by by replacing each occurrence of ? with A, B or C. The ABC number of each of these strings is as follows:

AAAC: 0

AABC: 2

AACC: 0

ABAC: 1

ABBC: 2

ABCC: 2

ACAC: 0

ACBC: 1

ACCC: 0

The sum of these is 0 + 2 + 0 + 1 + 2 + 2 + 0 + 1 + 0 = 8, so we print 8 modulo 10^9 + 7, that is, 8.

Sample Input 2

ABCBC

Sample Output 2

3

When Q = 0, we print the ABC number of S itself, modulo 10^9 + 7. This string is the same as the one given as an example in the problem statement, and its ABC number is 3.

Sample Input 3

????C?????B??????A???????

Sample Output 3

979596887

In this case, the sum of the ABC numbers of all the 3^Q strings is 2291979612924, and we should print this number modulo 10^9 + 7, that is, 979596887.


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

int main(void)
{
  int a[3];
  int dist[3];
  int remain[2];
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  dist[0]=abs(a[0]-a[1]);
  dist[1]=abs(a[1]-a[2]);
  dist[2]=abs(a[0]-a[2]);

  int max=dist[0];

  for(int i=1;i<=2;i++){
    if(dist[i]>max){
      remain[i-1]=max;
      max=dist[i];
    }
    remain[i-1]=dist[i];
  }
  printf("%d\n",remain[0]+remain[1]);
  return 0;
}

Score : 100 points

Problem Statement

You have three tasks, all of which need to be completed.

First, you can complete any one task at cost 0.

Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.

Here, |x| denotes the absolute value of x.

Find the minimum total cost required to complete all the task.

Constraints

All values in input are integers.

1 \leq A_1, A_2, A_3 \leq 100

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

Print the minimum total cost required to complete all the task.

Sample Input 1

1 6 3

Sample Output 1

5

When the tasks are completed in the following order, the total cost will be 5, which is the minimum:

Complete the first task at cost 0.

Complete the third task at cost 2.

Complete the second task at cost 3.

Sample Input 2

11 5 5

Sample Output 2

6

Sample Input 3

100 100 100

Sample Output 3

0


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

int main(void) {
  int a[3];
  int i = 0,min = 10000,max = 0;
  for (i = 0;i < 3;++i) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < 3;++i) {
    if (a[i] < min) {
      min = a[i];
    }
  }
  for (i = 0;i < 3;++i) {
    if (a[i] > max) {
      max = a[i];
    }
  }
  printf("%d",abs(max - min));
  return 0;
}


#include <stdio.h>

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

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

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

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

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

    return 0;

}

Score : 200 points

Problem Statement

Takahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.

Takahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from the left is a_i.
If two slimes of the same color are adjacent, they will start to combine themselves. Because Takahashi likes smaller slimes, he has decided to change the colors of some of the slimes with his magic.

Takahashi can change the color of one slime to any of the 10000 colors by one spell.
How many spells are required so that no slimes will start to combine themselves?

Constraints

2 \leq N \leq 100

1 \leq a_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of spells required.

Sample Input 1

5
1 1 2 2 2

Sample Output 1

2

For example, if we change the color of the second slime from the left to 4, and the color of the fourth slime to 5, the colors of the slimes will be 1, 4, 2, 5, 2, which satisfy the condition.

Sample Input 2

3
1 2 1

Sample Output 2

0

Although the colors of the first and third slimes are the same, they are not adjacent, so no spell is required.

Sample Input 3

5
1 1 1 1 1

Sample Output 3

2

For example, if we change the colors of the second and fourth slimes from the left to 2, the colors of the slimes will be 1, 2, 1, 2, 1, which satisfy the condition.

Sample Input 4

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

Sample Output 4

4


int main(void) {
int  t, i;
	long long reft,r,x,y,s,k;
	scanf("%d", &t);
	long long  a[300], b[300], c[300], d[300];
	for (i = 0; i <= t-1; i++) {
		scanf("%lld", &a[i]);
		scanf("%lld", &b[i]);
		scanf("%lld", &c[i]);
		scanf("%lld", &d[i]);

	}

	for (i = 0; i <= t-1; i++) {
		if (a[i] < b[i]) printf("No\n");
		else if (b[i] > d[i]) printf("No\n");
		else if (b[i]-1 <= c[i]) printf("Yes\n");
		else {
				reft = a[i]%b[i];

			if (reft > c[i]) printf("No\n");
			else {
								x = d[i];
				y = b[i];

				r = x % y;
				while (r != 0) {
					x = y;
					y = r;
					r = x % y;
				}

				c[i]=c[i]-reft;
                                b[i]=b[i]-reft;
                                k=c[i]%y;
                                s=(c[i]-k)/y;

				if ((s+1)*y<b[i]) printf("No\n");
				else printf("Yes\n");

			}

		}

	}
	return 0;
}

Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were A cans of juice in stock in the morning.
Snuke buys B cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are C or less cans, D new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of T queries.

Constraints

1 \leq T \leq 300

1 \leq A, B, C, D \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T

In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.

Output

Print T lines. The i-th line should contain Yes if Snuke can buy apple juice indefinitely in the i-th query; No otherwise.

Sample Input 1

14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1

No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 6
→D x

In the second query, the number of cans of juice in stock changes as follows:

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 15
→D 8
→N 8
→D 1
→N 10
→D 3
→N 12
→D 5
→N 14
→D 7
→N 7
→D 0
→N 9
→D 2
→N 11
→D …

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

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

Sample Output 2

No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No


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

int main(){

    int n,number,menor=1000000001,maior=0;

    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%d",&number);
        if(number<=menor){
            menor=number;
        }
        if(number>=maior){
            maior=number;
        }
    }
    printf("%d\n",maior-menor);

    return 0;
}

Score : 200 points

Problem Statement

You are given an integer sequence A of length N.
Find the maximum absolute difference of two elements (with different indices) in A.

Constraints

2 \leq N \leq 100

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum absolute difference of two elements (with different indices) in A.

Sample Input 1

4
1 4 6 3

Sample Output 1

5

The maximum absolute difference of two elements is A_3-A_1=6-1=5.

Sample Input 2

2
1000000000 1

Sample Output 2

999999999

Sample Input 3

5
1 1 1 1 1

Sample Output 3

0


#include<stdio.h>

int main() {
	int n, a[100], max, min, i;
	if (scanf("%d", &n) == 0) return 1;
	for (i = 0; i < n; i++) if (scanf("%d", &a[i]) == 0) return 1;
	max = 0; min = 1000000000;
	for (i = 0; i < n; i++) {
		if (max < a[i]) max = a[i];
		if (min > a[i]) min = a[i];
	}
	printf("%d", max - min);
	return 0;
}


#include <stdio.h>

int main(){
	int n,i,max=0,nmax=1000000000,a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %d",&a[i]);
		if(a[i]>=max)max=a[i];
		if(a[i]<=nmax)nmax=a[i];
	}
	printf("%d\n",max-nmax);
	return 0;
}


#include <stdio.h>

int main(void){
  int n, m, s;
  m=10;
  scanf("%d",&n);
  for(int i=1;i<10;i++){
    s += n%m *10/m;
    m*=10;
  }

  if(n%s==0){
    printf("yes");
  }else{
    printf("no");
  }
}

Score : 100 points

Problem Statement

There is always an integer in Takahashi's mind.

Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.

The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.

Find the integer in Takahashi's mind after he eats all the symbols.

Constraints

The length of S is 4.

Each character in S is + or -.

Input

Input is given from Standard Input in the following format:

S

Output

Print the integer in Takahashi's mind after he eats all the symbols.

Sample Input 1

+-++

Sample Output 1

2

Initially, the integer in Takahashi's mind is 0.

The first integer for him to eat is +. After eating it, the integer in his mind becomes 1.

The second integer to eat is -. After eating it, the integer in his mind becomes 0.

The third integer to eat is +. After eating it, the integer in his mind becomes 1.

The fourth integer to eat is +. After eating it, the integer in his mind becomes 2.

Thus, the integer in Takahashi's mind after he eats all the symbols is 2.

Sample Input 2

-+--

Sample Output 2

-2

Sample Input 3

----

Sample Output 3

-4


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

int main(void){
    char str[] ="++++";

    int N = 0;

    for(int i=0; i<4 ; i++){

        if('+' == str[i]){
            N++;
        }else{
            N--;
        }

    }

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

}


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

    int n;
    int sum=0;

    scanf("%d",&n);

    while(n){
        sum+=n%10;
        n/=10;
    }

    if(n%sum==0){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;

}

Score : 200 points

Problem Statement

Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(101) = 1 + 0 + 1 = 2.

Given an integer N, determine if S(N) divides N.

Constraints

1 \leq N \leq 10^9

Input

Input is given from Standard Input in the following format:

N

Output

If S(N) divides N, print Yes; if it does not, print No.

Sample Input 1

12

Sample Output 1

Yes

In this input, N=12.
As S(12) = 1 + 2 = 3, S(N) divides N.

Sample Input 2

101

Sample Output 2

No

As S(101) = 1 + 0 + 1 = 2, S(N) does not divide N.

Sample Input 3

999999999

Sample Output 3

Yes


#include<stdio.h>

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

  while(n){
    sum += n%10;
    //printf("%d ",sum);
    n = n/10;
  }

  if(m%sum==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
  long long n;
  char m[12];
  int a;
  scanf("%lld",&n);

  sprintf(m,"%lld",n);

  for(int i=0;i<strlen(m);i++){
    a+=(int)m[i]-48;
    printf("%d\n",a);
  }

  if(n%a==0){
    printf("Yes");
  }else{
    printf("No");
  }
}


#include <stdio.h>
int main(void)
{
	int n;
	int s = 0;
	int roop = 0;

	scanf("%d", &n);

	while (roop < 9){
		s = s + (n % 10);
		n /= 10;
		roop++;
	}

	if (n / s == 0){
		printf("Yes\n");
	}

	else {
		printf("No\n");
	}

	return 0;
}


#include <stdio.h>

int main(void) {

  int n,k;
  scanf("%d %d", &n, &k);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int place1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      place1 = i;
      break;
    }
  }
  int answer = (place1+1)/(k-1);
  answer += (n-place1)/(k-1);
  printf("%d\n", answer);

  return 0;
}

Score : 300 points

Problem Statement

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times.
Find the minimum number of operations required.
It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

2 \leq K \leq N \leq 100000

A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Sample Input 1

4 3
2 3 1 4

Sample Output 1

2

One optimal strategy is as follows:

In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4.

In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.

Sample Input 2

3 3
1 2 3

Sample Output 2

1

Sample Input 3

8 3
7 3 1 8 4 6 2 5

Sample Output 3

4


#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a > 8 || b > 8){
        printf(":(");
    }else{
        printf("Yay!");
    }
}

Score: 100 points

Problem Statement

E869120's and square1001's 16-th birthday is coming soon.

Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.

E869120 and square1001 were just about to eat A and B of those pieces, respectively,

when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".

Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

Constraints

A and B are integers between 1 and 16 (inclusive).

A+B is at most 16.

Input

Input is given from Standard Input in the following format:

A B

Output

If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.

Sample Input 1

5 4

Sample Output 1

Yay!

Both of them can take desired number of pieces as follows:

Sample Input 2

8 8

Sample Output 2

Yay!

Both of them can take desired number of pieces as follows:

Sample Input 3

11 4

Sample Output 3

:(

In this case, there is no way for them to take desired number of pieces, unfortunately.


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

int main(){

	long int A, B, sum;

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

	if (A <= 8 && B <= 8)
		printf("Yay!\n");
	else
		printf(":(\n");

	return 0;
}


#include <stdio.h>

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

	if (a>=8||b>=8)
	{
		printf(":(");
	} else if(a+b<=16||a+b>=0) {printf("Yay!");}
	else printf(":(");

	return 0;
}


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

int main(void)
{
	int A, B;

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

	if(A <= 8 && B <= 8) printf("Yay!");
	else printf(":(");

	return 0;
}


#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b) printf("Yay!\n");
    else printf(":(\n");
    return 0;
}


#include <stdio.h>

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

scanf("%d",&n);

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

    while(b < n)
    {
    while(NUM[b] % 2 == 0){
    	NUM[b] = NUM[b] / 2;
    	a++;
    }
    b++;
}
printf("%d",b);

	return 0;
}

Score: 300 points

Problem Statement

As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.

Snuke, an employee, would like to play with this sequence.

Specifically, he would like to repeat the following operation as many times as possible:

For every i satisfying 1 \leq i \leq N, perform one of the following: "divide a_i by 2" and "multiply a_i by 3".
Here, choosing "multiply a_i by 3" for every i is not allowed, and the value of a_i after the operation must be an integer.

At most how many operations can be performed?

Constraints

N is an integer between 1 and 10 \ 000 (inclusive).

a_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 a_3 ... a_N

Output

Print the maximum number of operations that Snuke can perform.

Sample Input 1

3
5 2 4

Sample Output 1

3

The sequence is initially {5, 2, 4}. Three operations can be performed as follows:

First, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.

Next, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.

Finally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.

Sample Input 2

4
631 577 243 199

Sample Output 2

0

No operation can be performed since all the elements are odd. Thus, the answer is 0.

Sample Input 3

10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776

Sample Output 3

39


#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 300

	int anX[10000];

int main() {

	int i=0;
	int j=0;
	int nNumber=0;
	int nOpe=0;
	int nTemp=0;

	// read line 1
    scanf("%d", &nNumber);
	// read line 2
	for(i=0; i<nNumber; i++) {
        scanf("%d", &anX[i]);
	}
	for(i=0; i<nNumber; i++) {
		nTemp=anX[i];
        while(nTemp%2==0){
			nTemp=nTemp/2;
			nOpe++;
		}
	}

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

    return 0;
}


#include<stdio.h>
int main()
{
	int n;
	long int a, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%ld", &a);
		while (!(a&1))
		{
			ans++;
			a = a >> 1;
		}
	}
	printf("%ld", ans);
	return 0;
}


Score : 100 points

Problem Statement

Decades have passed since the beginning of AtCoder Beginner Contest.

The contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?

In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.

You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

Constraints

1 \leq N \leq 1998

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

Sample Input 1

999

Sample Output 1

ABC

The 999-th round of AtCoder Beginner Contest is labeled as ABC999.

Sample Input 2

1000

Sample Output 2

ABD

The 1000-th round of AtCoder Beginner Contest is labeled as ABD001.

Sample Input 3

1481

Sample Output 3

ABD

The 1481-th round of AtCoder Beginner Contest is labeled as ABD482.


#include <stdio.h>
int main (){
	int a,b,c,d,high;
	scanf("%d %d",&a ,&b);
	c=b-a;//takasa
	high=0;
	for (d=1;d<=c;d++){
		high+=d;
	}
	high-=b;
	printf("%d",high);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(void){
int a,b;
int snow=0;
int tall=0;
int count=1;
int aa=0,bb=0;
int takasa[1001];
int flag=0;
takasa[0]=1;
scanf("%d %d",&a,&b);
printf("%d\n",(b-a)*(b-a+1)/2-b);

}

Score : 200 points

Problem Statement

In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.

It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.

Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.

Assume also that the depth of the snow cover is always at least 1 meter.

Constraints

1 \leq a < b < 499500(=1+2+3+...+999)

All values in input are integers.

There is no input that contradicts the assumption.

Input

Input is given from Standard Input in the following format:

a b

Output

If the depth of the snow cover is x meters, print x as an integer.

Sample Input 1

8 13

Sample Output 1

2

The heights of the two towers are 10 meters and 15 meters, respectively.
Thus, we can see that the depth of the snow cover is 2 meters.

Sample Input 2

54 65

Sample Output 2

1


#include <stdio.h>

int main (void) {
    int a, b;
    scanf("%d %d", &a, &b);
    int n = b - a;
    int sum = 0;

    for ( int i = 1; i <= n; i++ ) {
        sum += i;
    }
    printf("%d", sum - b);

    return 0;
}


#include <stdio.h>

void hiku(int *x){
	int i = 1;
	do
	{
		*x = *x - i;
		i++;
	} while(*x > 0);
}

int main(void){
	int a, b;

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

	printf("%d\n", -a);

	return 0;
}


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

int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  long long min=0;
  int A, B, C, K;
//  int sosu[20000]={};
  int i,j,k;
  int flag=0;
  int cnt =0;
  int next_cnt = 0;
  int tmp_cnt =0;
  int tmp_next_cnt = 0;

//    int k=0;

  scanf("%d %d", &A, &B);
  //printf("%d\n", A);

  for(i=0;i<999;i++){
    cnt = cnt +i;
    next_cnt = cnt + (i+1);
    //printf("%d",cnt );
      for(j=0;j<cnt;j++){
         tmp_cnt = cnt;
         tmp_next_cnt = next_cnt;
         if ( ( ( tmp_cnt - j ) == A ) && ( ( tmp_next_cnt - j ) == B ) ){
           printf("%d", j);
           return 0;
        }

      }

}

return 0;
}


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


#include <stdio.h>

int main(){
	int N;

	scanf("%d", &N);

	int i = 0;
	for(;;i++){
		if(N == 0) break;
		if(N >= 9)	N %= 9;
		else if(N >= 6)	N %= 6;
		else N--;
	}
	printf("%d", i);
}

Score : 300 points

Problem Statement

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

1 yen (the currency of Japan)

6 yen, 6^2(=36) yen, 6^3(=216) yen, ...

9 yen, 9^2(=81) yen, 9^3(=729) yen, ...

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

Constraints

1 \leq N \leq 100000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If at least x operations are required to withdraw exactly N yen in total, print x.

Sample Input 1

127

Sample Output 1

4

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

Sample Input 2

3

Sample Output 2

3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.

Sample Input 3

44852

Sample Output 3

16


#include <stdio.h>

int main(){
    int e;
    int x;
    int er;
    int is;
    int es;
    int data;
    is=0;
    es=0;
    data=100000;
    scanf("%d",&e);
        for(int i=2;i<e-2;i++){
            is=0;
            es=0;
            x=i;
            er=e-x;
            while(x>0){
                is=is+x%10;
                x=x/10;
            }
            while(er>0){
                es=es+er%10;
                er=er/10;
            }
            if(is+es<data){
                data=is+es;
            }
        }
    printf("%d\n",data);
    return 0;
}

Score : 200 points

Problem Statement

Takahashi has two positive integers A and B.

It is known that A plus B equals N.
Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).

Constraints

2 ≤ N ≤ 10^5

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B".

Sample Input 1

15

Sample Output 1

6

When A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the value in question.

Sample Input 2

100000

Sample Output 2

10


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

	if ((A + B)>(A - B) && (A + B)>(A * B))
		printf("%d\n", (A+B));
else if ((A - B)>(A + B) && (A - B)>(A*B))
		printf("%d\n", (A-B));
	else
		printf("%d\n", (A*B));
}

Score : 100 points

Problem Statement

You are given two integers A and B.
Find the largest value among A+B, A-B and A \times B.

Constraints

-1000 \leq A,B \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the largest value among A+B, A-B and A \times B.

Sample Input 1

3 1

Sample Output 1

4

3+1=4, 3-1=2 and 3 \times 1=3. The largest among them is 4.

Sample Input 2

4 -2

Sample Output 2

6

The largest is 4 - (-2) = 6.

Sample Input 3

0 0

Sample Output 3

0


#include <stdio.h>

int main(){
    int A, B;
    int add, sub, mul;

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

    add = A + B;
    sub = A - B;
    mul = A * B;

    if(add >= sub && add >= mul){
        printf("%d\n", add);
    } else if (sub >= mul){
        printf("%d\n", sub);
    } else {
        printf("%d\n", mul);
    }

    return 0;
}


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

}


#include<stdio.h>

    // SUB ID: UG02-53-20-001

int main()
{

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

    if(A+B>=A-B&&A+B>=A*B)
        printf("%d",A+B);
    else if(A+B>=A-B&&A+B>=A*B)
        printf("%d",A+B);
    else if(A-B>=A+B&&A-B>=A*B)
        printf("%d",A-B);
    else if(A*B>=A+B&&A*B>=A-B)
        printf("%d",A*B);

    return 0;
}


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

    max = a*b;
    if(a+b>=max) {
        max = a+b;
        if(a-b>=max) {
            max = a-b;
        }
    }
    printf("%d", max);
}


#include<stdio.h>
const int maxn = 100;
typedef long long LL;
int mp[36];
char a[105];
int vis[28];
int main(){
	int n;
	scanf("%d",&n);
	getchar();
	gets(a);
	int ans = 0,pos = 0;
	for(int i = 0;i<n;i++){
		mp[a[i]-'a']++;
		pos = 0;
		for(int k = 0;k<28;k++)
			vis[k] = 0;
		for(int j = i+1;j<n;j++){
			if(vis[a[j]-'a']) continue;
			if(mp[a[j]-'a']) {
				vis[a[j]-'a'] = 1;
				pos++;
			}
		}
		if(pos > ans) ans = pos;
	}
	printf("%d\n",ans);
	return 0;
}

Score : 200 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Constraints

2 \leq N \leq 100

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the largest possible number of different letters contained in both X and Y.

Sample Input 1

6
aabbca

Sample Output 1

2

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.

Sample Input 2

10
aaaaaaaaaa

Sample Output 2

1

However we divide S, only a will be contained in both X and Y.

Sample Input 3

45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir

Sample Output 3

9


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

	return 0;
}

Score : 100 points

Problem Statement

Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.
Two people can directly communicate when the distance between them is at most d meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

Constraints

1 ≤ a,b,c ≤ 100

1 ≤ d ≤ 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a b c d

Output

If A and C can communicate, print Yes; if they cannot, print No.

Sample Input 1

4 7 9 3

Sample Output 1

Yes

A and B can directly communicate, and also B and C can directly communicate, so we should print Yes.

Sample Input 2

100 10 1 2

Sample Output 2

No

They cannot communicate in this case.

Sample Input 3

10 10 10 1

Sample Output 3

Yes

There can be multiple people at the same position.

Sample Input 4

1 100 2 10

Sample Output 4

Yes


#include <stdio.h>

int dif(int a,int b){

	return a > b ? a-b : b-a;
}

int main(void){
	int a, b, c, d, di;

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

	di = dif(a,c);

    if(di <= d) printf("Yes");
	else if(di > d && di <=2*d){
		dif(a,b)<=d && dif(b,c)<=d ? printf("Yes") : printf("No");
	}
	else printf("No");

	return 0;
}


#include<stdio.h>

int main(void){

  int X;

  scanf("%d", &X);

  int b[11]={2,3,5,7,11,13,17,19,23,29,31};
  int p=0;

  int ans=0, pow=0, dif=1000, buf=1000;

  if(X <= 3){
    printf("1\n");
    return 0;
  }

  for(int i=0; i < 11 && b[i]*b[i] <= X; i++){
    pow = b[i]*b[i];

    for(p=2; pow <= X; p++){
      buf = X - pow;

      if(buf == 0){
        printf("%d\n", X);
        return 0;
      }else if(buf < dif){
        ans = pow;
        dif = buf;
      }

      pow = pow * b[i];
    }
  }

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

  return 0;

}

Score : 200 points

Problem Statement

You are given a positive integer X.
Find the largest perfect power that is at most X.
Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

Constraints

1 ≤ X ≤ 1000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the largest perfect power that is at most X.

Sample Input 1

10

Sample Output 1

9

There are four perfect powers that are at most 10: 1, 4, 8 and 9.
We should print the largest among them, 9.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

999

Sample Output 3

961