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

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

  	if (d == 0 && n == 100) printf("101");
  	else printf("%d", (int)(pow(100, d) * n));
  	return 0;
}


#include <stdio.h>

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

  if(N == 100){
    printf("101");
  }else{
    printf("%d",N);
  }
  while(D > 0){
    printf("00");
    D--;
  }

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

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

Score: 200 points

Problem Statement

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

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

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

Constraints

D is 0, 1 or 2.

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

Input

Input is given from Standard Input in the following format:

D N

Output

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

Sample Input 1

0 5

Sample Output 1

5

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

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

Sample Input 2

1 11

Sample Output 2

1100

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

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

Sample Input 3

2 85

Sample Output 3

850000

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

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

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.


#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))
#define bool    _Bool
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; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

int main() {
	double D, N;
	scanf("%lf%lf", &D, &N);
	int ans;
	if (N != 100) {
		ans = (int)(pow(100, D)*N);
	}
	else if (D == 0) {
		ans = 101;
	}
	else if (D == 1) {
		ans = 10100;
	}
	else if (D == 2) {
		ans = 1010000;
	}

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

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


#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))
#define bool    _Bool
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; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

int main() {
	double D, N;
	scanf("%lf%lf", &D, &N);
	int ans;
	if (N != 100) {
		ans = (int)(pow(100, D)*N);
	}
	else if (D = 0) {
		ans = 101;
	}
	else if (D = 1) {
		ans = 10100;
	}
	else if (D = 2) {
		ans = 1010000;
	}

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

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


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

main()
{
  int D,N,i,s;
  scanf("%d%d",&D,&N);
  D = pow(100,D);
  for(i=0,s=0; i<N; i++)
    s += D;
  printf("%d\n",s);
}


#include <stdio.h>

int main(void){
	//abc100-B

	int D,N,num;
	int a=1;

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

	if(D==0){
		num=100*D+N;
		printf("%d\n",num);
	}else{
		for(int i;i<D;i++){
			a*=100;
		}
		num=a*N;
		printf("%d\n",num);
	}
	return 0;
}


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


#include <stdio.h>

int main(){
  int D, N, i, ans;
  scanf("%d %d", &D, &N);
  if(D==0) ans = 1;
  if(D==1) ans = 100;
  if(D==2) ans = 10000;

  if(N==100) printf("%d\n", 101*ans);
  else printf("%d\n", N*ans);

  return 0;
}


#include <stdio.h>

int main(void)
{
   int d,n;
   scanf("%d%d",&d,&n);
   if(d==0) printf("%d",n);
   else if(d==1) printf("%d",100*n);
   else if(d==2) printf("%d",10000*n);
   return 0;
}


#include <stdio.h>

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

  ans = 0;
  if(D == 0){
    printf("%d\n", N);
  }else if(D == 1){
    for(i = 0; i < N; i++){
      ans += 100;
    }
  }else{
    for(i = 0; i < N; i++){
      ans += 10000;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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


#include <stdio.h>

#if 0
int pow(int a, int n) {
	int i = n - 1;
	int ret = 1;
	while (i > 0)
		ret *= a;
	}
	return a;
}
#endif

int main(int argc, char** argv) {
	int i = 0;
	int ans = 1;
	int d, n;
	scanf("%d %d", &d, &n);

#if 1
	if (d == 0) {
		ans = n;
		printf("%d\n", ans);
		return 0;
	} else if (d == 1) {
		if (n != 100) {
			ans = n * 100;
		} else {
			ans = 10100;
		}
		printf("%d\n", ans);
		return 0;
	} else {
		if (n == 100) {
			ans = 1010000;
		} else {
			ans = n * 100;
		}
		printf("%d\n", ans);
		return 0;
	}
#else
	ans = pow(100, d) * n;
	printf("%d\n", ans);
#endif

	return 0;
}


#include<stdio.h>
int main(void){
  int n,d;
  scanf("%d %d",&n,&d);
  switch (n) {
    case 0: printf("%d",d); break;
    case 1: printf("%d",d*100); break;
    case 2: printf("%d",d*10000); break;
  }
  return 0;
}


#include <stdio.h>
#include <math.h>
int main (void){
        int A,B;
        scanf("%d",&A);
        scanf("%d",&B);
        printf("%d",B);
        if (A==1) {
          printf("00");
        }else if (A==2) {
          printf("0000");
        }
        printf("\n");
        return 0;
}


#include <stdio.h>
int main(){
 int a,b,c,x,i,j,k,count=0;
  scanf("%d¥n%d¥n%d¥n%d¥n",&a,&b,&c,&x);
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if(500*i+100*j+k*50==x)
        count++;
      }
    }
  }
 printf("%d",count);
    return 0;
}

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


#include<stdio.h>
int a,b,c,x;
int answer(){
  int ans=0;
  int i,j,k;
  for(i=0;i<=a;++i){
    for(j=0;j<=b;++j){
      for(k=0;k<c;++k){
        int tmp = i * 500 + j * 100 + k * 50;
		if(tmp == x) ans++;
      }
    }
  }
  return ans;
}
int main(void){
  scanf("%d %d %d",&a,&b,&c,&x);
  int ans=answer();
  printf("%d",ans);
  return 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 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;
}

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, j, k;
	int A, B, C;
	int X;
	scanf("%d %d %d %d", &A, &B, &C, &X);

	int count=0;

	rep(i, 0, A)
	{
		rep(j, 0, B)
		{
			k=X-500*i-100*j;
			if(0<=k && k/50<=C)
			{
				count=count+1;
			}
		}
	}

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

	return 0;
}


#include <stdio.h>

int main(){
  int a,b,c,x;

  if(scanf("%d",&a)==1);
  if(scanf("%d",&b)==1);
  if(scanf("%d",&c)==1);
  if(scanf("%d",&x)==1);

  int count = 0;
  int value;
  int i,j,k;
  for(i=0;i < a;i++){
    value = 500*i;
    for(j=0;j < b;j++){
      value = 500*i + 100*j;
      for(k=0;k < c;k++){
        value = 500*i + 100*j + 50*k;
        if(value==x)count++;
      }
    }
  }
  printf("%d",count);

  return 0;
}


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

int main()
{
  ll a, b, c, x, sum, ans = 0;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &x);
  for (int i = 0; i <= a; i++)
  {
    for (int j = 0; j <= b; j++)
    {
      for (int k = 0; k <= c; k++)
      {
        sum = 500 * i + 100 * j + 50 * k;
        if (sum == x)
          ans++;
      }
    }
  }
  printf("%lld\n", ans);
}


#include<stdio.h>

int main(void){
  int a,b;

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

  if((a * b) % 2 == 0) puts("Even");
  else puts("Odd");

  return 0;

}

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


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


#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a*b%2==0) printf("Even\n");
    else printf("Odd\n");
}


#include <stdio.h>

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


int main(){

  int a,b,c;

  do{
    scanf("%d %d",&a,&b);
  }while(a<1||b>10000);

  c = a*b;

  if(c%2==0)
    printf("Even");
  else
    printf("odd");

  return 0;

}


 #include<stdio.h>

int main(void){
	int a, b;
   (void)scanf("%d, %d", &a, &b);
  int c = a * b;
  if(c % 2 == 0){
    printf("Even");
  }
  else{
    printf("0dd");
  }

   return 0;
}


#include<stdio.h>

main(void){
	int a, b;
  scanf("%d,%d", &a, &b);
  int c = a * b;
  if(c % 2 == 0){
    printf("Even");
  }
  else{
    printf("0dd");
  }

   return 0;
}


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

    char s[12];
    char s1[6];
    char s2[6];

    fgets(s, 12, stdin);

    sscanf(s, "%s %s", s1, s2);

    int a=  atoi(s1);
    int b = atoi(s2);

    if(a % 2 == 1 && b%2==1){
        printf("Odd");
    }else{
        printf("Even");
    }

    return 0;

}


#include<stdio.h>
int main(void)
{
  int a,b;
  int flag=0;
  scanf("%d %d",&a,&b);
  int tmp=b;
  printf("%d\n",tmp);

  do{
    a*=10;
    b/=10;
  }while(b>0);
  tmp+=a;
  printf("%d\n",tmp);
  for(int i=0;i<=10000;i++){
    if(tmp==i*i){
      flag=1;
      break;
    }else{
      flag=0;
    }
  }
  if(flag==1){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


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

  if(s%2==0){
    printf("Even");
  }
  else{
    printf("Odd");
  }

  return 0;
}


#include<stdio.h>

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

  ans = a*b;

  if(ans%2==0){
    printf("Even\n");
  }else{
    printf("Odd\n");
  }

  return 0;
}


#include<stdio.h>

int main(void) {
    int a,b;

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

    if ((a * b) % 2) {
        printf("Odd\n");
    }
    else {
        printf("Even\n");
    }

    return 0;
}


#include<stdio.h>

void main() {
  int a,b;
  scanf("%d %d",&a,&b);
  if(a%2 == 0 || b%2 == 0) {
    printf("Odd\n");
  }else {
    printf("Even\n");
  }
  return 0;
}


#include<stdio.h>

// a>1;
// int b<1000;

int main(int argc, char const *argv[])
{
	int a, b;
//	printf("say something\n" );

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

if(c%2==0){
printf("even");
}else if(c%2 ==1){
printf("Odd");
}
	return 0;

}


#include<stdio.h>

int main()
{
    int b,c;

    // スペース区切りの整数の入力
    scanf("%d %d",&b,&c);

  	if ((b * c) % 2 == 0)
    {
      printf("Odd\n");
    }
  	else
    {
      printf("Even\n");
    }

    return 0;
}


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

int main(int argc, char **argv)
{
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    if (a * b % 2 == 0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }
    return EXIT_SUCCESS;
}


#include <stdio.h>

int main() {
  int a, b;
  scanf("%d%d",&a,&b);
  puts(a*b%2 ? "Odd" : "Even");
  return 0;
}


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

int main() {
  int a, b;
  if (scanf("%d %d", &a, &b) < 0) {
    exit(1);
  }
  int product = a * b;
  if (product % 2 == 0) {
	printf("Even");
  } else {
    printf("Odd");
  }
}


#include <stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if (a*b%2==1)
    printf("Odd\n");
  else
    printf("Even\n");

  return 0;
}


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


#include <stdio.h>

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


#include <stdio.h>
//#define DEBUG

int main()
{
	long int a,b;
	scanf("%ld%ld",&a,&b);
#ifdef DEBUG
	printf("%ld %ld\n",a,b);
#endif
	if((a*b)%2) printf("Odd\n");
	else        printf("Even\n");
	fflush(stdout);

	return 0;
}


#include <stdio.h>

int main(void){
 int a,b;
  sscanf("%d %d\n",&a,&b);
  if(a*b%2 == 0) printf("even");
  else printf("odd");

  return 0;
}


#include<stdio.h>

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	printf((a % 2 == 1 && b % 2 == 1) ? "Odd" : "Even");
	return 0;
}


#include <stdio.h>

int
main(){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a < 1 || 10000 < b)
    return 1;

  if( (a % 2) && (b % 2)  ){
    printf("Odd\n");
  } else {
    printf("Even\n");
  }

  return 0;
}


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


 #include<stdio.h>
 int main(){
    int a,b,product;
    printf("Enter the value of a and b :");
    scanf("%d%d", &a,&b);
    product=a*b;
    if(product%2==0){
        printf("The product is EVEN\n");
    }
    else{
            printf("The product is ODD\n");
    }
    return  0;
 }


#include <stdio.h>

int main(void){
    int a,b;

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

    if(a*b%2==1)
        printf("Odd\n");
    else
        printf("Even\n");
}


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


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

   int a,b;

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

   if((a*b)%2==0) printf("Even\n");

   else printf("Odd\n");

   return 0;
}


#include<stdio.h>
void main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a*b%2)
		puts("Odd");
	else
		puts("Even");
}


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


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


#include<stdio.h>

int main()
{
  int a,b,c;

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

  c=a*b;

  if (c%2==0)
    printf("Even\n");
  else printf("Odd\n");

  return 0;
}


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

int main(){
  char a[4];
  char b[4];
  char *c;
  int num;
  int d;
  scanf("%s",a);
  scanf("%s",b);
  c = strcat(a,b);
  num = atoi(c);

  d = (int)sqrt((double)num);
  if(d*d == num){
    printf("Yes");
  }else{
    printf("No");
  }
}


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


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


#include <stdio.h>

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

    if (a%2 == 0 || b%2 == 0){
        printf("Even\n");
    }
    else{
        printf("Odd\n");
    }
    return 0;
}


#include<stdio.h>

int main(void){
        long int n,y,i,j,k;

        scanf("%ld%ld",&n,&y);
        y=y/1000;
        k=y-n;

    for(i=0;i<=k;i++){
        for(j=0;j<=k;j++){
                if((k==i*9+j*4)){
                        if(n-i-j<0){continue;}
                    printf("%ld %ld %ld",i,j,(n-i-j));
                    return 0;

            }
        }
    }

        printf("-1 -1 -1");

        return 0;
}

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


#include <stdio.h>

int main(){
  int n, y;
  int i, j;
  int s = -1;
  int t = -1;
  int u = -1;

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

  for(i = 0; i <= n; i++){
    for(j = 0; j <= n - i; j++){
      if(y == (i * 10000 + j * 5000 + (n - i - j) * 1000)){
        s = i;
        t = j;
        u = n - i - j;
        goto loopend;
      }
    }
  }
  loopend:

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


#include <stdio.h>

int main(){
  int n, y;  scanf("%d %d", &n, &y);
  y /= 1000;

  for(int i=0; i<=n; i++){
    for(int j=0; j<=n-i; j++){
      int sum = i*10 + j*5 + (n-i-j)*1;
      if(sum == y){
	printf("%d %d %d\n", i, j, n-i-j);
	return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


#include<stdio.h>

int main(void)
{
	int n, total, yen;
	int x, y, z;
	int *px, *py, *pz;
	int i, j, k;
	int exitFrag = 0;

	x = y = z = -1;

	px = &x;
	py = &y;
	pz = &z;

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

	for (i = 0; i <= n; i++)
	{
		for ( j = 0; j <= n - i ; j++)
		{
			for ( k = 0; k <= n - i - j; k++)
			{
				yen = 1000 * i + 5000 * j + 10000 * k;
				if (yen == total)
				{
					*px = k;
					*py = j;
					*pz = i;
					exitFrag = 1;
				}
				if (yen > total) break;

				if (exitFrag) break;
			}
			if (exitFrag) break;
		}
		if (exitFrag) break;
	}

	printf("%d %d %d", x, y, z);

	return 0;
}


#include <stdio.h>

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

    int cnt10k = -1, cnt5k = -1, cnt1k = -1;

    for (int i = 0; i <= N; i++) {
        for(int j = 0; i + j <= N; j++) {
            int k = N - i + j;
            int sum = 10000 * i + 5000 * j + 1000 * k;

            if (sum == Y) {
                cnt10k = i;
                cnt5k = j;
                cnt1k = k;
            }
        }
    }

    printf("%d %d %d\n", cnt10k, cnt5k, cnt1k);
    return 0;
}


#include <stdio.h>

int main(void){

    int n, Y;
    int x = -1, y = -1, z = -1;

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

    for(int a = 0; a <= n; a++){
        for(int b = 0; b + a <= n; b++){
                int c = n - a - b;
                int sum = 10000 * a + 5000 * b + 1000 * c;
                if(sum == Y){
                    printf("%d %d %d\n", x, y, z);
                    return 0;
                }
        }
    }

    puts("-1 -1 -1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,m,i,num=0,c=0,sum=0;

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

    int tho[n+1],wield[n+1];

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

        if(num<tho[i])num=tho[i];
    }

    for(i=0; i<n; i++)
    {
        if(num<wield[i])
        {
            sum+=wield[i];
             c++;
            if(sum>=m)
            {
                 printf("%d\n",c);
                 break;
            }
        }
    }
    //printf("sum=%d  c=%d\n",sum,c);
    if(sum<m)
    {
        sum=m-sum;

        c+=sum/num;

        if(sum%num!=0)c++;

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

    return 0;

}


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

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

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

#define BIG 2000000007
#define VERYBIG 200000000000007LL

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

#define N_MAX 200000
#define M_MAX 1000

#ifdef __cplusplus
#include <queue>
#include <stack>

using namespace std; // I'm NOT gonna use C++ without compro. shit

typedef priority_queue<ull, vector<ull>, greater<ull> > upque123;
typedef priority_queue<ull, vector<ull> > upque321;
typedef priority_queue<sll, vector<sll>, greater<sll> > spque123;
typedef priority_queue<sll, vector<sll> > spque321;

#endif

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

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

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

typedef struct {
	ull s;
	ull t;
	int32_t c;
} struct_a;

typedef struct {
	int32_t from;
	int32_t to;
	sll cost;
} struct_b;

const hw vector8[8] = {
	{-1, -1},
	{-1,  0},
	{-1, +1},
	{ 0, -1},
	{ 0, +1},
	{+1, -1},
	{+1,  0},
	{+1, +1}
};

ull n, m;
ull h, w;
ull k;
ull vua, vub, vuc, vud, vue, vuf;
sll vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;
ull a[N_MAX];
// ull a[M_MAX];
// sll a[N_MAX];
// ull a[N_MAX][N_MAX];
// ull wall[N_MAX][N_MAX];
// double wall[N_MAX][N_MAX];
// ull b[N_MAX];
// ull b[M_MAX];
// sll b[N_MAX];
// ull b[N_MAX][N_MAX];
// sll b[N_MAX][N_MAX];
// ull c[N_MAX];
// ull c[M_MAX];
// sll c[N_MAX];
char s[N_MAX + 1];
// char t[N_MAX + 1];
// char s[N_MAX][M_MAX + 1];
// ull alphabets[26];

// ull dp[N_MAX];
// sll dp[N_MAX];
// bool dp[N_MAX];
// int32_t dp[N_MAX];
// ull dp[N_MAX * N_MAX];
// double dp[N_MAX];
// double dp[N_MAX][70][40][30];
// ull dq[N_MAX];
// ull dp[N_MAX + 1][M_MAX + 1];
// ull dq[M_MAX][N_MAX];
// sll dq[N_MAX];
// bool dq[N_MAX];
// double dq[N_MAX];
// hwll dp[N_MAX + 1][N_MAX + 1];
// struct_a dp[N_MAX + 1][N_MAX + 1];

// sll imos[N_MAX + 5];

// hw arr[N_MAX];
// hwll arr[N_MAX * 2];
// hw brr[M_MAX];
// linell arr[N_MAX][N_MAX];

// ull bitdp[1 << 8];

// ull digitdp[1001][   3][    2];
//           pos  less  carry
// ull digitdp[1001][    2];
//           pos  carry

// struct_a arr[N_MAX * 2];
// struct_b brr[N_MAX * 2];

void swap_adj (ull *a, ull *b) {
	if (*a != *b) {
		ull tmp = *b;
		*b = *a;
		*a = tmp;
	}
	return;
}

ull divide (ull a, ull b) {
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}

int32_t digits (ull x) {
	int32_t i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}

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

int32_t targetdig (ull x, int32_t index /* 1-indexed */) {
	// static...?
	int32_t posmax = digits(x);
	if (posmax < index) return -1;
	while (posmax > index) {
		posmax--;
		x /= 10;
	}
	return x % 10;
}

int32_t charcomp (const char left, const char right) {
	if (left < right) {
		return -1;
	} else if (left > right) {
		return +1;
	} else {
		return 0;
	}
}

int32_t pcharcomp (const void *left, const void *right) {
	char lval = *(char*)left;
	char rval = *(char*)right;
	return charcomp(lval, rval);
}

int32_t intcomp (const int32_t left, const int32_t right) {
	if (left < right) {
		return -1;
	} else if (left > right) {
		return +1;
	} else {
		return 0;
	}
}

int32_t pintcomp (const void *left, const void *right) {
	int lval = *(int*)left;
	int rval = *(int*)right;
	return intcomp(lval, rval);
}

int32_t ullcomp (const ull left, const ull right) {
	if (left < right) {
		return -1;
	} else if (left > right) {
		return +1;
	} else {
		return 0;
	}
}

int32_t pullcomp (const void *left, const void *right) {
	ull lval = *(ull*)left;
	ull rval = *(ull*)right;
	return ullcomp(lval, rval);
}

int32_t sllcomp (const sll left, const sll right) {
	if (left < right) {
		return -1;
	} else if (left > right) {
		return +1;
	} else {
		return 0;
	}
}

int32_t psllcomp (const void *left, const void *right) {
	sll lval = *(sll*)left, rval = *(sll*)right;
	return ullcomp(lval, rval);
}

int32_t hwllfraccomp (const hwll left, const hwll right) {
	return ullcomp(left.a * right.b, left.b * right.a);
}

int32_t phwAcomp (const hw *left, const hw *right) {
	return intcomp(left->a, right->a);
}

int32_t phwBcomp (const hw *left, const hw *right) {
	return intcomp(left->b, right->b);
}

int32_t phwABcomp (const hw *left, const hw *right) {
	int32_t x = phwAcomp(left, right);
	if (x) return x;
	return phwBcomp(left, right);
}

int32_t phwllAcomp (const hwll *left, const hwll *right) {
	return sllcomp(left->a, right->a);
}

int32_t phwllBcomp (const hwll *left, const hwll *right) {
	return sllcomp(left->b, right->b);
}

int32_t phwllABcomp (const hwll *left, const hwll *right) {
	int32_t x = phwllAcomp(left, right);
	if (x) return x;
	return phwllBcomp(left, right);
}

int32_t pstrAcomp (const struct_a *left, const struct_a *right) {
	int32_t x;
	if (x = ullcomp(left->t, right->t)) return x;
	if (x = ullcomp(left->s, right->s)) return x;
	if (x = intcomp(left->c, right->c)) return x;
	return 0;
}

int32_t bitlet (char c) {
	return (1 << (c - 'a'));
}

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

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

sll nibutanlobo (bool (*func)(sll arg), sll ok, sll ng) {
	while (sllabs(ok, ng) > 1) {
		sll med = (ok + ng) / 2;
		if (func(med)) {
			ok = med;
		} else {
			ng = med;
		}

		// printf("debug: [%lld %lld)\n", ok, ng);
	}

	if (!func(ok)) return ok * 2 - ng;
	return ok;
}

bool nextroute (int32_t arr[], int32_t n) {
	int32_t i = n - 1;
	int32_t j, x;

	while (i > 0 && arr[i - 1] > arr[i]) i--;
	if (i == 0) return false;

	x = n;
	for (j = i; j < n; j++) {
		if (arr[j] < arr[i - 1]) continue;
		if (x == n || arr[x] > arr[j]) x = j;
	}
	arr[i - 1] ^= arr[x];
	arr[x] ^= arr[i - 1];
	arr[i - 1] ^= arr[x];

	qsort(&arr[i], n - i, sizeof(int32_t), pintcomp);
	return true;
}

void printUquotient (ull left, ull right) {
	const int32_t digits = 20;

	printf("%llu.", left / right);
	left %= right;
	for (int32_t i = 0; i < digits; i++) {
		left *= 10;
		printf("%1d", left / right);
		left %= right;
	}
	puts("");

	return;
}

void printSquotient (sll left, sll right) {
	if (left * right < 0) putchar('-');
	printUquotient(sllabs(left, 0), sllabs(right, 0));

	return;
}

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

#ifdef __cplusplus

typedef struct {
	int32_t to;
	sll cost;
} edge;
typedef pair<sll, int32_t> P;

std::vector<edge> g[N_MAX];
void dijk_init (ull n, struct_b arr[]) {
	edge x;
	for (int32_t i = 0; i < n; i++) {
		x.to = arr[i].to;
		x.cost = arr[i].cost;
		g[arr[i].from].push_back(x);
	}
}

void dijkstra (int s, sll distance[]) {
	priority_queue<P, std::vector<P>, greater<P> > que; // (最短距離, 頂点番号)
	for (int32_t i = 0; i < n; i++) {
		distance[i] = BIG;
	}
	distance[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();

		sll v = p.second;
		if (distance[v] < p.first) continue;

		int32_t maxsize = g[v].size();
		for (int32_t i = 0; i < maxsize; i++) {
			edge e = g[v][i];
			if (distance[e.to] > distance[v] + e.cost) {
				distance[e.to] = distance[v] + e.cost;
				que.push(P(distance[e.to], e.to));
			}
		}
	}

	return;
}

#endif

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

ull solve () {
	sll i, j, ki, l;
	ull result = 0;
	// sll result = 0;
	// double result;
	ull sum = 0;
	// sll sum = 0;
	ull item;
	ull *dpcell;
	// qsortの際には"p"ullcompを使う

	k /= 1000;
	for (i = 0; i <= n; i++) {
		for (j = 0; i + j <= n; j++) {
			if (i * 10 + j * 5 + (n - i - j) == k) {
				printf("%lld %lld %lld\n", i, j, n - i - j);
				goto success;
			}
		}
	}
	goto fail;

	printf("%llu\n", result);
	// printf("%.12lf\n", result);
	// puts(s);

	return 0;

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

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

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

	// scanf("%lld%lld%lld%lld", &vsa, &vsb, &vsc, &vsd);
	// scanf("%llu%llu", &h, &w);
	scanf("%llu", &n, &m);
	scanf("%llu", &k, &n);
	// scanf("%llu%llu", &vua, &vub, &vuc, &vud, &vue);
	// scanf("%llu%llu%llu", &vsa, &vsb, &vsc);
	// scanf("%s", s);
	// scanf("%s", t);
	// scanf("%lld%lld", &vsa, &vsb);
	// for (i = 0; i < n; i++) {
	// 	scanf("%llu", &a[i]);
	// 	// a[i]--;
	// }

	// for (i = 0; i < k; i++) {
	// 	scanf("%d", &dp[i]);
	// 	dp[i]--;
	// }
	// for (i = 0; i < n; i++) {
	// 	scanf("%s", s[i]);
	// }
	// for (i = 0; i < h; i++) {
	// 	scanf("%llu", &a[i]);
	// }
	// for (i = 0; i < w; i++) {
	// 	scanf("%llu", &b[i]);
	// }
	// for (i = 0; i < n; i++) {
	// 	scanf("%lld%lld", &a[i], &b[i]);
	// }
	// for (i = 0; i < h; i++) {
	// 	for (j = 0; j < w; j++) {
	// 		scanf("%llu", &a[i][j]);
	// 	}
	// }

	solve();

	// for (i = 0; i < n; i++) {
	// 	// scanf("%llu%llu", &vua, &vub);
	// 	scanf("%s%s", s, t);
	// 	// scanf("%f%f%f", &vda, &vdb, &vdc);
	// 	// scanf("%s", s);
	// 	solve();
	// }

	// while (scanf("%llu%llu", &n, &k), n + k) {
	// 	for (i = 0; i < n; i++) {
	// 		scanf("%llu", &a[i]);
	// 	}
	// 	solve();
	// }

	return 0;
}


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

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

int main(void){
	int N,H,i,ans=0,m=0;
	scanf("%d%d",&N,&H);
	int a,b[N];
	for(i=0;i<N;i++){
		scanf("%d%d",&a,&b[i]);
		if(a>m) m=a;
	}
	qsort(b, N, sizeof(int), compare);
	i=0;
	while(b[i]>m && i<N && H>0){
		H-=b[i++];
		ans++;
	}
	if(H>0)	ans += (H+m-1)/m;

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

Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


#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 int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

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);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
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;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	int n=in(),h=in(),a[100000],b[100000],i,m=0,t,ans=0;
	rep(i,n){
		a[i]=in();
		b[i]=in();
		m=max(m,a[i]);
	}
	t=h;
	sort_r(b,n);
	for(i=0;i<n&&b[i]>=m;i++){
		ans++;
		t-=b[i];
		if(t<=0){
			print(ans);
			return 0;
		}
	}
	ans+=t/m+(!!(t%m));
	print(ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
struct node
{
  int b;
  struct node *next;
};
typedef struct node * NodePointer;
int main()
{
  int n,h,temp;
  int a,b[MAX];
  int count;
  int i,j,k;
  NodePointer p,newnode,head;
  head=malloc(sizeof(struct node));
  head->next=NULL;
  scanf("%d%d",&n,&h);
  for(i=0;i<n;i++)
    {
      scanf("%d",&temp);
      if(a<temp) a=temp;
      scanf("%d",&temp);
      for(p=head;p->next!=NULL;p=p->next)
	{
	  if(p->next->b<temp) break;
	}
      newnode=malloc(sizeof(struct node));
      newnode->b=temp;
      newnode->next=p->next;
      p->next=newnode;
    }
  p=head;
  for(count=0;h>0;count++)
    {
      if(p->next==NULL||p->next->b<a)
	{
	 if(h%a==0) count+=h/a;
	 else count+=h/a+1;
	 break;
	}
      h-=p->next->b;
      p=p->next;
    }
  printf("%d\n",count);
  return 0;
}


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

int compare_l(const void *p,const void *q){
	return*(int*)p-*(int*)q;
}

int main(){
	int h,x=0,z=0,n,i,max=0;

	scanf("%d %d",&n,&h);
	int a[n],b[n];

	for(i=0;i<=n-1;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(max<a[i]) max=a[i];
	}
	qsort((void*)b,n,sizeof(b[0]),compare_l);
	for(i=n-1;b[i]>=max;i--){
		x+=b[i];
		z++;
		if(x>=h){
			printf("%d",z);
			return 0;
		}
	}

	while(1){
		if(x>=h){
			printf("%d",z);
			return 0;
		}
		h-=max;
		z++;
	}
}


#include <stdio.h>
#include <stdlib.h>
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return b - a;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

int main(){
	int N, H, i, ans;
	scanf("%d%d", &N, &H);
	int *a = (int *)malloc(sizeof(int) * (N + 1));
	int *b = (int *)malloc(sizeof(int) * (N + 1));
	int maxa = 0;
	for(i = 0; i < N; i++){
		scanf("%d%d", &a[i], &b[i]);
		if(a[i] > maxa){
			maxa = a[i];
		}
	}
	b[N] = 0;
	sort(b, N);
	ans = 0;
	for(i = 0; i <= N; i++){
		if(H <= 0){
			printf("%d\n", ans);
			return 0;
		}
		else if(b[i] > maxa){
			H -= b[i];
			ans++;
		}
		else{
			printf("%d\n", ans + (H + maxa - 1) / maxa);
			return 0;
		}
	}
}


Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


#include<stdio.h>
int sum(int K){
  int a=0;
for(;K>0;K=K/10){
  a=a+K%10;
  }
  return a;
}
int main()
{
  int N,A,B,answer=0;
  scanf("%d %d %d",&N,&A,&B);
  for(;N>0;N=N-1){
    if(A<=sum(N)&&sum(N)<=B){
      answer=answer+N;
    }
  }
  printf("%d\n",answer);
  return 0;
}


#include<stdio.h>
int s(int i)
{
	int t=0;

	while(i>0){
		t+=i%10;
		i/=10;
	}
	return t;
}

int main()
{
	int n,a,b,t=0,i;

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

	for(i=1;i<=n;i++)
		if(a<=s(i)&&s(i)<=b)
			t+=i;
	printf("%d",t);
	return 0;
}


#include <stdio.h>

int Sum(int N);

int main(){
    int N, A, B, sum = 0;
    scanf("%d %d %d", &N, &A, &B);

    for(int i = 1; i <= N; i++){
        if(A <= Sum(i) && Sum(i) <= B){
            sum += i;
        }
    }

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

int Sum(int N){
    int sum = 0;

    for(int i = N; i > 0; i /= 10){
        sum += i % 10;
    }

    return sum;
}


#include<stdio.h>
int digit(long long int a)
{
    int i,j,b,s=0;
    for( ;a>0;)
    {
        b=a%10;
        s=s+b;
        a=a/10;
    }
    return s;
}
int main()
{
    long long int a,b,c,d,i,j,s=0;
    scanf("%lld%lld%lld",&a,&b,&c);
    for(i=1;i<=a;i++)
    {
        d=digit(i);
        if(d>=b && d<=c)s=s+i;
    }
    printf("%lld\n",s);
    return 0;
}


#include<stdio.h>
int main(void){
 int value;
 int sum=0;
 int min,max;
 int current=0;
 int temp=0;
 int i;
scanf("%d %d %d",&value,&min,&max);
for(i=1;i<=value;i++){
   while(temp>0){
       current+=temp%10;
       temp/=10;
   }
   if(current>=min && current<=max) sum+=current;
}
printf("%d",sum);
}


#include <stdio.h>

int digit_sum(int num) {
  int sum = 0;
  while(num > 0) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main(void) {
  int i, N, A, B;
  int sum = 0;
  scanf("%d %d %d", &N, &A, &B);
  for(i = 1; i <= N; ++i) {
    int k = digit_sum(i);
    if (A <= i && i <= B) sum += i;
  }
  printf("%d\n", sum);
  return 0;
}


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

    int i;
    int j;
    int ans=0;
    int wa=0;
    for(i=a;i<=n;i++){
        j=i;

        wa+=j%10;
        j=j/10;
        wa+=j%10;
        j=j/10;
        wa+=j%10;
        j=j/10;
        wa+=j%10;
        j=j/10;
        wa+=j%10;

        if(a<=wa && wa<=b){
            ans+=i;
        }
        wa =0;
    }
    printf("%d",ans);

    return 0;
}


#include <stdio.h>
int main(void){
   int i,count=0;
   char num[4];
   for(i=0;i<4;i++)
   num[i]=0;

    scanf("%s",&num);

    for(i=0;i<3;i++)
    if(num[i]=='1')
    count++;

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

Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


#include<stdio.h>
#include <math.h>
int main(void){
int N;
int counter,num;
int min=10000;
scanf("%d",&N);
for (counter=1; counter<=N; counter++) {

		scanf("%d",&num);
      int d=0;
      while(num %2 ==0){
        num /=2;
        ++d;
      }
   if(min>d)
      min=d;

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


#include <stdio.h>

int main()
{
	int count=0;
	char* ps = 0;
	scanf("%s",ps);

	while(*ps!='\0')
	{
		if(*ps=='1')
		{
			count++;
		}
		ps++;
	}
	printf("%d",count);
}


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

#define REP(i,n) for(i=0;i<n;i++)
#define ll long long

int main(void){
    int s1,s2,s3;

    printf("%d",s1+s2+s3);

    return 0;
}


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


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

int main(){
  	int count=0;
  	char s[4];

  scanf("%c %c %c",s[0],s[1],s[2]);

  if(s[0]=='1'){count++;}
  if(s[1]=='1'){count++;}
  if(s[2]=='1'){count++;}

  printf("%d",count);

  return(0);
}


#include <stdio.h>

int main(int argc, char *argv[]){
	int a = 0;
	int i;
	for(i=0;i<argc;i++){
		if(argv[1][i] == "1")a++;
	}
	printf("%d",a);

	return 0;
}


#include <stdio.h>

int main() {
	int n, cnt;

	scanf("%d", &n);
	cnt = 0;
	while (n > 0) {
		if (n % 10 == 1)
			cnt++;
		n /= 10;
	}
	printf("%d\n", cnt);
	return 0;
}


#include <stdio.h>

int main(void)
{
    char str[4]; int i, cnt = 0;
    scanf("%s", str);
    for(i = 0; i < 3; ++i) {
        if(str[i] == '1') { ++cnt; }
    }
    printf("%d\n", cnt);
    return 0;
}


#include <stdio.h>

int main(){

        int g;
        scanf("%d",&g);
        switch (g){
                case 000: printf("0\n"); break;
                case 001: printf("1\n"); break;
                case 010: printf("1\n"); break;
                case 011: printf("2\n"); break;
                case 100: printf("1\n"); break;
                case 101: printf("2\n"); break;
                case 110: printf("2\n"); break;
                case 111: printf("3\n"); break;

        }

        return 0;

}


#include<stdio.h>
int main(void)
{
	int x,a,b,c,ans;
	scanf("%d",&x);
	a=x%100;
	b=x%10;
	c=x%1;
	ans=a+b+c;
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>

int main()
{
	int N;
	unsigned long An[200];
    int result;

    // Nを取得
	scanf("%d", &N);

	// 黒板の整数を取得
    for (int i = 0; i < N ; i++)
    {
		scanf("%lu", &An[i]);
	}

    // 操作実行
    while(1){
        int end_flg = 0;
        for (int i = 0; i < N; i++)
        {
		    if(An[i] % 2 > 0)
            {
            	end_flg = 1;
            }
            else
			{
            	An[i] = An[i] / 2;
            }
        }
        if (end_flg == 1)
        {
        	break;
        }
        result++;
    }
    printf("%d", result);
	return 0;
}


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

int main(void) {
    int i;
    double S;
    int count=0, answer;

    scanf("%lf", &S);

    for(i=0; i<3; i++) {
        if((S/pow(10.0, 2-i))>=1) {
            S -= pow(10.0, 2-i);
            count += 1;
        }
    }

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

    return 0;
}


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

int main()
{

    char  s[4];
    int cnt=0;
  int i;
 // 整数の入力
    scanf("%s", s);
//    printf("%s\n",s);

  for(i=0;i < 3 ;i++ ){
//    printf("%c\n",s[i]);
    if(49 == s[i]){
     cnt = cnt + 1;
//     printf("%d\n",cnt);
              }
  }
     printf("%d\n", cnt);

    return 0;
}


#include<stdio.h>

#define NUM 3

int main(void)
{
        char a[NUM];
        scanf("%s",a);

        int i,num;
        num=0;

        for(i=0;a[i]!='\n';i++)         if(a[i]=='1')   num++;

        printf("%d",num);

        return 0;
}


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

#define MAX_LENGTH 50

void solve(char bigger[], char smaller[]);

int main()
{
    int n;
    char s_dash[MAX_LENGTH + 1];
    char t[MAX_LENGTH + 1];
    int ans;

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

    solve(s_dash, t);

    return 0;
}

void solve(char bigger[], char smaller[])
{
    size_t bigger_length;
    size_t smaller_length;
    bool isSubstring;
    char temp[MAX_LENGTH + 1];
    char smallest[MAX_LENGTH + 1];

    bigger_length = strlen(bigger);
    smaller_length = strlen(smaller);

    smallest[0] = '\0';
    for (int i = 0; i < (int)bigger_length; i++)
    {
	isSubstring = true;
	for (int j = 0; j < (int)smaller_length; j++)
	{
	    if (bigger[i + j] != '?' && bigger[i + j] != smaller[j])
	    {
		isSubstring = false;
		break;
	    }
	}

	if (isSubstring)
	{
	    for (int k = 0; k < (int)bigger_length; k++)
	    {
		if (k < i)
		{
		    if (bigger[k] == '?')
		    {
			temp[k] = 'a';
		    }
		    else
		    {
			temp[k] = bigger[k];
		    }
		}
		else if (k == i)
		{
		    for (int l = 0; l < (int)smaller_length; l++)
		    {
			temp[k + l] = smaller[l];
		    }
		}
		else if ((i + (int)smaller_length) < k)
		{
		    if (bigger[k] == '?')
		    {
			temp[k] = 'a';
		    }
		    else
		    {
			temp[k] = bigger[k];
		    }
		}
	    }
	    temp[(int)bigger_length] = '\0';

	    if (strcmp(smallest, "") == 0)
	    {
		strcpy(smallest, temp);
	    }
	    else if (strcmp(smallest, temp) < 0)
	    {
		strcpy(smallest, temp);
	    }
	}
    }

    if (strcmp(smallest, "") == 0)
    {
	printf("UNRESTORABLE\n");
    }
    else
    {
	printf("%s\n", smallest);
    }
}

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


#include<stdio.h>

int main(){
  char sd[100] = {};int sdcnt = 0;
  char t[100] = {};int tcnt = 0;
  int i = 0;
  int j = 0;
  int success = 0;
  int li = 0;
  int ok = 0;
  scanf(" %s",sd);
  scanf(" %s",t);
  for(i=0;i < 100;i++){
    if(sd[i] == '\0'){
      sdcnt = i;
      break;
    }
  }
  for(i=0;i < 100;i++){
    if(t[i] == '\0'){
      tcnt = i;
      break;
    }
  }
  if(tcnt > sdcnt){
    success = 0;
  }else{
    for(i=0;i<=sdcnt-tcnt;i++){
      ok=1;
      for(j=0;j<tcnt;j++){
        //printf("%c %c\n",sd[i+j],t[j]);
        if(sd[i+j] != t[j] && sd[i+j] != '?'){
          ok=0;
        }
      }
      if(ok){
        success = 1;
        li = i;
        //printf("#");
      }
    }
  }
  if(success){
    for(i=0;i<tcnt;i++){
      sd[i+li] = t[i];
    }
    for(i=0;i<sdcnt;i++){
      if(sd[i] == '?'){
        sd[i] = 'a';
      }
    }
    printf("%s",sd);
  }else{
    printf("UNRESTORABLE");
  }

  return 0;
}


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

int main(){
  int i,j,k=100;
  char S[1000000],T[51];
  scanf("%s",S);
  scanf("%s",T);
  if(strlen(S)>=strlen(T)){
  for(i=0;i<=strlen(S)-strlen(T);i++){
    k=i;
      for(j=0;j<strlen(T);j++){
        if(S[i+j]!=T[j] &&S[i+j]!='?'){
          k=10000000;
          break;
        }
        if(j==strlen(T)-1){
          break;
        }
      }
    if(j==strlen(T)-1){
          break;
        }
  }
  }
  else
    k=10000000;
  if(k==10000000){
    puts("UNRESTORABLE");
    return 0;
  }
  for(i=k;i<k+strlen(T);i++)
    S[i]=T[i-k];
  for(i=0;i<strlen(S);i++){
    if(S[i]=='?')
      S[i]='a';
  }
  printf("%s\n",S);
  return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char s[200000];
	char t[100];
	scanf("%s", s);
	scanf("%s", t);
	int aim;
	int ls, lt,i,flag=0;
	ls = strlen(s);
	lt = strlen(t);
	for (aim = ls - lt; aim > -1; aim--)
	{
		if (!flag)
		{
			flag = 1;
			for (i = 0; i < lt; i++)
			{
				if (s[aim + i] != '?'&&s[aim + i] != t[i])
				{
					flag = 0;
					break;
				}
			}
		}
		else
			break;
	}
	aim++;
	if (flag)
	{
		for (i = 0; i < aim; i++)
		{
			if (s[i] == '?')
				printf("a");
			else
				printf("%c", s[i]);
		}
		printf("%s", t);
		for (i = aim + lt; i < ls; i++)
		{
			if (s[i] == '?')
				printf("a");
			else
				printf("%c",s[i]);
		}
	}
	else
		printf("UNRESTORABLE");
	return 0;
}


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

int main() {

	char s_dash[51];
	char s[51];
	char t[51];

	int i = 0;
	int j = 0;
	int k = 0;
	int l = 0;
	int m = 0; // iは文章中の位置、jは検索文字列中の位置
	int len_s = 0;
	int x = 0;
	int len_t = 0;

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

//	printf("%s", s_dash);
//	printf("%s", t);

	strcpy(s, s_dash);

	len_s = strlen(s_dash);
	len_t = strlen(t);

	//printf("%d\n", len_s);
	char buf[51];
	char candi[51][51];
	int cnt = 0;
	//printf("%d\n", len_t);
	//printf("%d", i);

	if (len_s < len_t) {
		printf("UNRESTORABLE\n");
	}
	else {
		for (i = 0; i <= (len_s - len_t); i++) {
			j = 0;
			while(j < len_t) {
				if(s_dash[i+j] == t[j] || s_dash[i+j] == '?') {
					j++;
				}
				else {
					break;
				}
				if(j == len_t){
					// 条件を満たした文字列を保存する
					// 変数cntで、条件を満たした文字列が何個目かを保存しておく。
					// s_dashのiからi+kまでにおいて、'?'以外ならそのまま、'?'ならk番目をコピー
					for (l = 0; l < i; l++) {
						if(s_dash[l] == '?') {
							candi[cnt][l] = 'a';
						}
						else {
							candi[cnt][l] = s_dash[l];
						}
					}
					for (k = 0; k < len_t; k++) {
//						printf("%d", i+k);
						if(s_dash[i+k] == '?') {
							candi[cnt][i+k] = t[k];
						}
						else {
							candi[cnt][i+k] = s_dash[i+k];
						}
					}
					for (m = 0; m < ((len_s - 1) - (i+len_t-1)); m++) {
						//printf("%d\n", m+i+len_t);
						//printf("%s", s_dash[m+i+len_t]);
						if(s_dash[m+i+len_t] == '?') {
							candi[cnt][m+i+len_t] = 'a';
						}
						else {
							candi[cnt][m+i+len_t] = s_dash[m+i+len_t];
						}
					}
					cnt++;
				}
			}
		}

		if(cnt == 0) {
			printf("UNRESTORABLE\n");
		}
		else {
			// 変数x。
			// バッファbufの文字列とcandi[x]を比較して、辞書順手前のほうをbufに入れる。
			// xをインクリメント。
			for(x = 0; x < cnt; x++) {
				if (x == 0) {
					strcpy(buf, candi[0]);
				}
				else {
					if (strcmp(buf, candi[x]) > 0) {
						strcpy(buf, candi[x]);
					}
				}
			}
			printf("%s\n", buf);
		}
	}
	return 0;
}


#pragma warning(disable:4996)

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

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define c_cin(X) scanf("%c",&X);
#define ll_cin(X) scanf("%lld", &X)
#define ull_cin(X) scanf("%llu", &X)
#define lf_cin(X) scanf("%lf", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  s_coutc(X) printf("%s",X)

#define  c_cout(X) printf("%c",X)

#define  ll_cout(X) printf("%lld\n",X)
#define  ull_cout(X) printf("%llu\n",X)

typedef long long  ll;
typedef unsigned long long  ull;

#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0

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

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

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

int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

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

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

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

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

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

#pragma endregion

#define MAX 50
#define MAX1 51
static char  s[MAX][MAX];
static char  a[MAX1];
static struct _b {
	int x;
	int y;
} b[2500];
int _set(int x, int y, int n, int m);

int main(void) {
	int  i,j,c=0,n,m;
	i_cin2(n, m);
	for (i = 0; i < n; i++) {
		scanf("%s", a);
		for(j=0;j<m;j++){
			if (a[j] == '#') {
				s[i][j] = '#';
				b[c].x = i; b[c].y = j;
				c++;
			} else s[i][j] = '0';
		}

	}

	if(c<m*n){
		for (i = 0; i < c; i++) {
			_set(b[i].x, b[i].y, n, m);
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			printf("%c", s[i][j]);
		}
		printf("\n");
	}
	return 0;
}

struct _p {
    int  x;
	int  y;
} p[10]={-1,-1,-1,0,-1,1,
         0,-1,      0,1,
	     1,-1, 1,0, 1,1 };

int _set(int x, int y,int n,int m) {
	int i;
	for (i = 0; i < 8; i++) {
		if (x + p[i].x < 0|| x + p[i].x >= n)continue;
	    if (y + p[i].y < 0|| y + p[i].y >= m)continue;
		if (s[x + p[i].x][y + p[i].y] == '#')continue;
		s[x + p[i].x][y + p[i].y]++;
	}
	return 0;
}

//167-D
//static int a[200001];
//static int c[200001];
//int main(void) {
//	ll k,ps,pe,i,j=0,n,r;
//
//	ll_cin(n);
//	ll_cin(k);
//
//	for (i = 0; i < n; i++) {
//		i_cin(a[i]);
//		if ((ll)(i + 1) == k) {
//			ll_cout(c[i]); return 0;
//		}
//		if (c[i] == 1) {
//			ps = i;
//			pe = i - 1; break;
//		}
//		c[i]++;
//	}
//	k -= i;
//	r = (int)(k % (pe-ps))+ps;
//	i_cout(a[r]);
//	return 0;
//}

//
//167-C
//int main(void) {
//	int n,m,x,i,j;
//	int c[13][2], a[13][12];
//
//	i_cin3(n, m, x);
//	for (i = 0; i < n; i++) {
//		i_cin(c[i][0]); c[i][1] = i;
//		i_cins(m, a[i]);
//	}
//
//	qsort(c[0],n, 8, s_asort);
//	for (i = 0; i < n; i++) {
//
//	}
//	return 0;
//
//}

//#define _N 1000000000

//int main(void)
//{
//
//	int  n,i;
//	ull   tmp=1;
//
//	i_cin(n);
//
//	for (i = 1; i <= n; i++) {
//		if (!(tmp % ((ull)_N + 7)))
//			tmp = 1;
//		tmp *= (ull)i;
//	}
//	tmp %= ((ull)_N + 7);
//
//	ull_cout(tmp);
//	return 0;
//}

Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.

Sample Input 3

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

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310


#include <stdio.h>

int		main(void)
{
	int h,w;
	scanf("%d%d", &h, &w);
	char s[h][50];
	int i = 0;
	int j;
	while (i < h)
	{
		scanf("%s", s[i]);
		i++;
	}
	i = 0;
	int count;
	int k;
	int n;
	char c;
	while (i < h)
	{
		j = 0;
		while (j < w)
		{
			if (s[i][j] == '.')
			{
				k = i - 1;
				count = 0;
				while (k <= i + 1)
				{
					n = j - 1;
					while (n <= j + 1)
					{
						if (s[k][n] == '#')
							count++;
						n++;
					}
					k++;
				}
				s[i][j] = '0' + count;
			}
			j++;
		}
		i++;
	}
	i = 0;
	while (i < h)
	{
		printf("%s", s[i]);
		if (i != h - 1)
			printf("\n");
		i++;
	}
	return (0);
}


#include<stdio.h>
#include<string.h>
int main(void){
  int h,w,i,j,sum=0,up,side;
  scanf("%d %d",&h,&w);
  char str[h][w];
  for(i=0;i<h;i++){
    scanf("%s",&str[i]);
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(str[i][j]=='.'){
        sum=0;
        for(up=-1;up<=1;up++){
          for(side=-1;side<=1;side++){
            if(str[i+up][j+side]=='#'){
              sum++;
            }
          }
        }
        str[i][j]='0'+sum;
      }
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      printf("%c",str[i][j]);
    }
    printf("\n");
  }
  return 0;
}


/*
  B - Minesweeper
  http://abc075.contest.atcoder.jp/tasks/abc075_b
*/

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

int main(int argc, char const *argv[]) {

  int H,W;
  char S[50][50];
  int i,j,ii,jj;

  scanf("%d %d\n", &H,&W);
  for( i=0; i<H; i++ ){
    scanf("%s\n", S[i]);
  }

  for( i=0; i<H; i++ ){
    for( j=0; j<W; j++ ){
      if( S[i][j] == '.' ){
        S[i][j] = '0';
        for( ii=-1; ii<=1; ii++ ){
          for( jj=-1; jj<=1; jj++ ){
            if( (i+ii>=0) && (j+jj>=0) && (i+ii<H) && (j+jj<W) ){
              if( S[i+ii][j+jj] == '#' ){
                S[i][j]++;
              }
            }
          }
        }
      }
    }
  }

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

  return 0;
}


#include <stdio.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

int main(void){
    char po[114][114];
    int H,W;
    scanf("%d %d",&H,&W);
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        scanf(" %c",&po[i][j]);
    }
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        if(po[i][j]!='#'){
            int count=0;
            for(int k=max(0,i-1);k<min(i+2,H);k++)for(int l=max(0,j-1);l<min(j+2,W);l++){if(po[k][l]=='#')count++;}
            po[i][j]='0'+count;
        }
    }
    for(int i=0;i<H;i++){for(int j=0;j<W;j++){
        printf("%c",po[i][j]);
    }
    printf("\n");
    }
    return 0;
}


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

int main() {

    int n, l, r;
    scanf("%d", &n);
    int mysum = 0;

    for (int i = 0; i < n; i++) {
        scanf("%d %d", &l, &r);
        mysum += r - l + 1;

    }
    printf("%d", mysum);

    return 0;

}

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


#include <stdio.h>

int main(){
	int n,a,b;
	scanf("%d", &n);
	int cont = 0;
	for(int i = 0; i < n; i++){
		scanf("%d %d", &a, &b);
		cont += b - a + 1;
	}
	printf("%d\n", cont);
	return 0;
}


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

int main(){
    int n, total = 0, pos_inicial, pos_final;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d %d", &pos_inicial, &pos_final);
        if (pos_inicial == pos_final)
            total += 1;
        else
            total += abs(pos_final - pos_inicial) + 1;
    }
    printf("%d\n", total);
    return 0;
}


#include <stdio.h>

int main(){
  int n,count=0,j=0;
  scanf("%d",&n);
  int data[n];
  for(int i=0;i<n;i++){
     for(j=0;j<2;j++){
      scanf("%d",&data[j]);
    }
    count+=data[j-1]-data[j-2]+1;
  }
  printf("%d",count);

}


#include <stdio.h>
int main(){
  int n,r,l,s=0;
  for(scanf("%d",&n);n;n--){
    scanf("%d%d",&l,&r);
    s+=r-l+1;
  }
  printf("%d",s);
  return 0;
}


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


#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	int l[N], r[N];
	int i, j, k;
	for (i = 0; i < N; i++) {
		scanf("%d%d", &l[i], &r[i]);
	}
	int sum=0;
	for (i = 0; i < N; i++) {
		sum += r[i] - l[i] + 1;
	}
	printf("%d\n", sum);
	return 0;
}


#include "stdio.h"

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int l[N],r[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d%d",&l[i],&r[i]);
  }
  int ans=0;
  for (size_t i = 0; i < N; i++) {
    ans=ans+r[i]-l[i]+1;
  }
  printf("%d", ans);
  return 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 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(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(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_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_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 start, int goal)
{
	int i, j;
	bool answer=0;

	if(goal-start<=max-min)
	{
		for(i=min; i<=max-(goal-start); i=i+1)
		{
			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(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;
}

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()
{
	char i='a';
	char S[100001];
	scanf("%s", S);

	char ans='\0';

	rep(i, 'a', 'z')
	{
		if(detect_char(S, 0, strlen(S)-1, &i, 0, 0)==0)
		{
			ans=i;
			break;
		}
	}

	if(ans=='\0')
	{
		printf("None\n");
	}
	else
	{
		printf("%c\n", ans);
	}
	return 0;
}

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll alph[26]={0};
    char S[100100];
    ins(S);
    rep(i, strlen(S)) alph[S[i]-'a']++;
    rep(i, 26){
        if(!alph[i]){
            putchar('a'+i);
            return 0;
        }
    }
    puts("None");
    return 0;
}


#include <stdio.h>
int main(void){
char s[100005];
  int count;
  int flag[26];
  scanf("%s",s);
  for(count=0;;count++){
    if(s[count]=='\0'){break;}
  if(s[count]=='a'){flag[0]++;continue;}
    if(s[count]=='b'){flag[1]++;continue;}
    if(s[count]=='c'){flag[2]++;continue;}
    if(s[count]=='d'){flag[3]++;continue;}
    if(s[count]=='e'){flag[4]++;continue;}
    if(s[count]=='f'){flag[5]++;continue;}
    if(s[count]=='g'){flag[6]++;continue;}
    if(s[count]=='h'){flag[7]++;continue;}
    if(s[count]=='i'){flag[8]++;continue;}
    if(s[count]=='j'){flag[9]++;continue;}
    if(s[count]=='k'){flag[10]++;continue;}
    if(s[count]=='l'){flag[11]++;continue;}
    if(s[count]=='m'){flag[12]++;continue;}
    if(s[count]=='n'){flag[13]++;continue;}
    if(s[count]=='o'){flag[14]++;continue;}
    if(s[count]=='p'){flag[15]++;continue;}
    if(s[count]=='q'){flag[16]++;continue;}
    if(s[count]=='r'){flag[17]++;continue;}
    if(s[count]=='s'){flag[18]++;continue;}
    if(s[count]=='t'){flag[19]++;continue;}
    if(s[count]=='u'){flag[20]++;continue;}
    if(s[count]=='v'){flag[21]++;continue;}
    if(s[count]=='w'){flag[22]++;continue;}
    if(s[count]=='x'){flag[23]++;continue;}
    if(s[count]=='y'){flag[24]++;continue;}
    if(s[count]=='z'){flag[25]++;continue;}
  }
  if(flag[0]==0){printf("a");return 0;}
  if(flag[1]==0){printf("b");return 0;}
  if(flag[2]==0){printf("c");return 0;}
  if(flag[3]==0){printf("d");return 0;}
  if(flag[4]==0){printf("e");return 0;}
  if(flag[5]==0){printf("f");return 0;}
  if(flag[6]==0){printf("g");return 0;}
  if(flag[7]==0){printf("h");return 0;}
  if(flag[8]==0){printf("i");return 0;}
  if(flag[9]==0){printf("j");return 0;}
  if(flag[10]==0){printf("k");return 0;}
  if(flag[11]==0){printf("l");return 0;}
  if(flag[12]==0){printf("m");return 0;}
  if(flag[13]==0){printf("n");return 0;}
  if(flag[14]==0){printf("o");return 0;}
  if(flag[15]==0){printf("p");return 0;}
  if(flag[16]==0){printf("q");return 0;}
  if(flag[17]==0){printf("r");return 0;}
  if(flag[18]==0){printf("s");return 0;}
  if(flag[19]==0){printf("t");return 0;}
  if(flag[20]==0){printf("u");return 0;}
  if(flag[21]==0){printf("v");return 0;}
  if(flag[22]==0){printf("w");return 0;}
  if(flag[23]==0){printf("x");return 0;}
  if(flag[24]==0){printf("y");return 0;}
  if(flag[25]==0){printf("z");return 0;}
  printf("None");

return 0;
}


#include <stdio.h>
int main(void)
{
    char str[100000];
    char alf[25];

    for(int p=0;p<26;p++)
    {
        alf[p]=0;
    }
    scanf("%s",str);

    int count=0;
    while(str[count]!=NULL)
    {
        alf[str[count]-0x61-1]=1;
        count++;
    }
    count=0;
    char ans;
    int x=0;
    while(count<26 && x==0)
    {
        if(alf[count]==0)
        {
            ans=0x61+count+1;
            printf("%c\n",ans);
            x++;
        }
        count++;
    }
    if(x==0)
      printf("None");

}


#include <stdio.h>

main ()
{
	char str [256] ;
	char alf [26] ;
	char ans ;
	int count ;

	count = 0 ;
	while ( count < 26 )
	{
		alf [ count ] = 0 ;
		count++;
	}

	scanf ( "%s", str );

	count = 0 ;
	while ( str [ count ] != 0 )
	{
		alf [ str [ count ] - 0x61 ] = 1 ;
		count++;
	}

	count = 0 ;
	while ( count < 26 )
	{
		if ( alf [ count ] == 0 )
		{
			ans = 0x61 + count ;
			printf ( "%c\n", ans );
			return 0 ;
		}
		count++;
	}

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


#pragma warning(disable:4996)

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

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define c_cin(X) scanf("%c",&X);
#define ll_cin(X) scanf("%lld", &X)
#define ull_cin(X) scanf("%llu", &X)
#define lf_cin(X) scanf("%lf", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  s_coutc(X) printf("%s",X)

#define  c_cout(X) printf("%c",X)

#define  ll_cout(X) printf("%lld\n",X)
#define  ull_cout(X) printf("%llu\n",X)

typedef long long  ll;
typedef unsigned long long  ull;

#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0

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

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

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

int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

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

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

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

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

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

#pragma endregion

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

	i_cin(n);

	for (i = 0; i < n; i++) {
		i_cin(a);
		if (!(a % 4)) cnt++;
	}

	(cnt < n / 2)?printf("No\n"):printf("Yes\n");
	return 0;
}
//167-D
//static int a[200001];
//static int c[200001];
//int main(void) {
//	ll k,ps,pe,i,j=0,n,r;
//
//	ll_cin(n);
//	ll_cin(k);
//
//	for (i = 0; i < n; i++) {
//		i_cin(a[i]);
//		if ((ll)(i + 1) == k) {
//			ll_cout(c[i]); return 0;
//		}
//		if (c[i] == 1) {
//			ps = i;
//			pe = i - 1; break;
//		}
//		c[i]++;
//	}
//	k -= i;
//	r = (int)(k % (pe-ps))+ps;
//	i_cout(a[r]);
//	return 0;
//}

//
//167-C
//int main(void) {
//	int n,m,x,i,j;
//	int c[13][2], a[13][12];
//
//	i_cin3(n, m, x);
//	for (i = 0; i < n; i++) {
//		i_cin(c[i][0]); c[i][1] = i;
//		i_cins(m, a[i]);
//	}
//
//	qsort(c[0],n, 8, s_asort);
//	for (i = 0; i < n; i++) {
//
//	}
//	return 0;
//
//}

//#define _N 1000000000

//int main(void)
//{
//
//	int  n,i;
//	ull   tmp=1;
//
//	i_cin(n);
//
//	for (i = 1; i <= n; i++) {
//		if (!(tmp % ((ull)_N + 7)))
//			tmp = 1;
//		tmp *= (ull)i;
//	}
//	tmp %= ((ull)_N + 7);
//
//	ull_cout(tmp);
//	return 0;
//}

Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


// AtCoder Regular Contest 080 C - 4-adjacent
// 2018.1.11 bal4u

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

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int N, a;
	int i, n4, odd, ans;			// n4: 4の倍数

	odd = n4 = 0;
	N = in();
	for (i = 0; i < N; i++) {
		a = in();
		if (a & 1) odd++;
		else if (!(a & 3)) n4++;
	}
	ans = 0;
	if (n4 >= odd) ans = 1;
	else if (n4 == odd-1 && odd + n4 == N) ans = 1;
	puts(ans? "Yes": "No");
	return 0;
}