#include<stdio.h>

long int max;

void set_data(long int data[], int n){
    for(int i = 0; i < n; i++){
        scanf("%ld", &data[i]);
    }
}

int calc_lcm(long int data[], int n){
    int lcm, judge = 1;
    max = data[0];
    for(int i = 0; i < n; i++){
        if(max < data[i]){
            max = data[i];
        }
    }
    for(int i = 1; i < max; i++){
        for(int j  = 0; j < n; j++){
            if(data[j] % i != 0){
                judge = 0;
                break;
            }
        }
        if(judge){
            lcm = i;
        }
    }
    return lcm;
}

long int calc_gcd(long int data[], int n){
    int lcm = calc_lcm(data, n), flag[max];
    for(int i = 0; i < n; i++){
        flag[data[i] - 1] = 1;
    }
    long int gcd = 1;
    for(int i = 0; i < n; i++){
        if(flag[data[i] - 1] == 1){
            gcd *= data[i];
            flag[data[i] - 1] = 0;
        }
    }
    return gcd / lcm;
}

void count_SCM(long int data[], int n, long int m){
    int cnt = 0, judge = 1;
    long int gcd = 1;
    gcd = calc_gcd(data, n);
    for(int i = 1; gcd * i <= m * 2; i += 2){
        for(int j = 0; j < n; j++){
            if((gcd * i) % data[j] != 0){
                judge = 0;
                break;
            }
        }
        if(judge == 1){
            cnt ++;
        }
    }
    printf("%d\n", cnt);
}

void print_array(long int data[], int n){
    for(int i = 0; i < n; i++){
        printf("%ld ", data[i]);
    }
    printf("\n");
}

int main(void){
    int n;
    long int m;
    scanf("%d""%ld", &n, &m);
    long int data[n];
    set_data(data, n);
    /*print_array(data, n);*/
    count_SCM(data, n, m);
    return 0;

}

Score : 400 points

Problem Statement

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

There exists a non-negative integer p such that X= a_k \times (p+0.5).

Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^9

2 \leq a_i \leq 10^9

a_i is an even number.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 ... a_N

Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Sample Input 1

2 50
6 10

Sample Output 1

2

15 = 6 \times 2.5

15 = 10 \times 1.5

45 = 6 \times 7.5

45 = 10 \times 4.5

Thus, 15 and 45 are semi-common multiples of A. There are no other semi-common multiples of A between 1 and 50, so the answer is 2.

Sample Input 2

3 100
14 22 40

Sample Output 2

0

The answer can be 0.

Sample Input 3

5 1000000000
6 6 2 6 2

Sample Output 3

166666667


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

#define N 1000

int main(void) {

//	int a=0,b=0;
//	float p=0,q=0;
	char str1[N],str2[N];

	scanf("%s %s", str1, str2);

	printf("%s%s", str2, str1);

	return 0;
}

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

Score : 100 points

Problem Statement

Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string.

Constraints

S and T are strings consisting of lowercase English letters.

The lengths of S and T are between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

S T

Output

Print the resulting string.

Sample Input 1

oder atc

Sample Output 1

atcoder

When S = oder and T = atc, concatenating T and S in this order results in atcoder.

Sample Input 2

humu humu

Sample Output 2

humuhumu

Submitted source-code file size, in bytes.

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

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


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

int main()
{
    long long int a,b,k,i;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(k<=a)
    {
        printf("%lld %lld\n",a-k,b);
    }
    else if(k>a && k<a+b )
    {
        printf("0 %lld\n",a+b-k);
    }
    else if(k>=a+b)
    {
        printf("0 0\n");
    }
}

Score : 200 points

Problem Statement

Takahashi has A cookies, and Aoki has B cookies.
Takahashi will do the following action K times:

If Takahashi has one or more cookies, eat one of his cookies.

Otherwise, if Aoki has one or more cookies, eat one of Aoki's cookies.

If they both have no cookies, do nothing.

In the end, how many cookies will Takahashi and Aoki have, respectively?

Constraints

0 \leq A \leq 10^{12}

0 \leq B \leq 10^{12}

0 \leq K \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the numbers of Takahashi's and Aoki's cookies after K actions.

Sample Input 1

2 3 3

Sample Output 1

0 2

Takahashi will do the following:

He has two cookies, so he eats one of them.

Now he has one cookie left, and he eats it.

Now he has no cookies left, but Aoki has three, so Takahashi eats one of them.

Thus, in the end, Takahashi will have 0 cookies, and Aoki will have 2.

Sample Input 2

500000000000 500000000000 1000000000000

Sample Output 2

0 0

Watch out for overflows.


#include<stdio.h>
int sosuu(int a)
{
  int k,sw;
  k=0;
  for(int i=2;i<a/2;++i)
  {
  if(a%i==0) {k++;}
  }
  if(k>0) sw=1;
  else sw=0;
return sw;
}
int main()
{
int n,cc;
  cc=0;
  scanf("%d",&n);

  while(cc==0)
  {
  if(sosuu(n)==0) cc++;
  else n++;
  }
  printf("%d",n);
return 0;}

Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

2 \le X \le 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003


#include<stdio.h>
#include<stdlib.h>
int main()
{
int j,n,i,c=0;
scanf("%d",&n);
for(i=n;i>=n;i++)
{
c=0;
for(j=2;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==0)
{
printf("%d",i);
exit(0);
}
}
}


#include <stdio.h>
int main() {
 int X,i;
 int j = 0;

scanf("%d",&X);
  if(X > 2){
    X = X - 1;
    do{
      X+=1;
      for(i=2;i<X;i++){
        printf("%d\n",X%i);
        if((X%i)==0) j = j+1;
        else;
      }
      printf("!%d",j);

    }while(j > 1);
  }
  else;

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


#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
int cmp(const void *x,const void *y){
    int64_t a=*(const int64_t*)x;
    int64_t b=*(const int64_t*)y;
    return a>b ?-1:a<b;
}
int N;
int64_t M,A[200000],A_ruiseki[200000];
int64_t gcount(int64_t* sum,int64_t target){
    int i;
    int64_t count=0;
    if(sum)
        *sum=0;
    for(i=0;i<N;i++){
        int ge=0,less=N-1;
        if(A[i]+A[0]<target)
            count+=0;
        else if(A[i]+A[N-1]>=target){
            count+=N;
            if(sum)
                (*sum)+=A[i]*N+A_ruiseki[N-1];
        }
        else{
            while(ge+1<less){
                int mid=ge+(less-ge)/2;
                if(A[i]+A[mid]>=target)
                    ge=mid;
                else{
                    less=mid;
                }
            }
            count+=ge+1;
            if(sum)
                (*sum)+=A[i]*(ge+1)+A_ruiseki[ge];
        }
    }
    return count;
}
int main(void){
    int i;
    int64_t less,ge=0,nyan,wa;
    if(scanf("%d%"SCNd64,&N,&M)!=2) return 1;
    for(i=0;i<N;i++){
        if(scanf("%"SCNd64,&A[i])!=1) return 1;
    }
    qsort(A,N,sizeof(*A),cmp);
    A_ruiseki[0]=A[0];
    for(i=1;i<N;i++)
        A_ruiseki[i]=A_ruiseki[i-1]+A[i];
    less=A[0]*2+1;
    while(less-1>ge){
        int64_t mid=ge+(less-ge)/2;
        if(gcount(NULL,mid)>=M)
            ge=mid;
        else
            less=mid;
    }
    nyan=gcount(&wa,ge);
    printf("%" PRId64 "\n",wa-(nyan-M)*ge);
    return 0;
}

Score : 500 points

Problem Statement

Takahashi has come to a party as a special guest.
There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i.

Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0).
A handshake will be performed as follows:

Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same).

Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y.

However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold:

Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q).

What is the maximum possible happiness after M handshakes?

Constraints

1 \leq N \leq 10^5

1 \leq M \leq N^2

1 \leq A_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the maximum possible happiness after M handshakes.

Sample Input 1

5 3
10 14 19 34 33

Sample Output 1

202

Let us say that Takahashi performs the following handshakes:

In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.

In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.

In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.

Then, we will have the happiness of (34+34)+(34+33)+(33+34)=202.

We cannot achieve the happiness of 203 or greater, so the answer is 202.

Sample Input 2

9 14
1 3 5 110 24 21 34 5 3

Sample Output 2

1837

Sample Input 3

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

Sample Output 3

8128170


#include<stdio.h>
int main(){
  int s,t; scanf("%d%d",&s,&t);
  printf("%d\n",6-s-t);
  return 0;
}

Score: 100 points

Problem Statement

Takahashi is solving quizzes. He has easily solved all but the last one.

The last quiz has three choices: 1, 2, and 3.

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

Print the correct choice for this problem.

Constraints

Each of the numbers A and B is 1, 2, or 3.

A and B are different.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the correct choice.

Sample Input 1

3
1

Sample Output 1

2

When we know 3 and 1 are both wrong, the correct choice is 2.

Sample Input 2

1
2

Sample Output 2

3


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

	char s[100], t[100];

	scanf("%s %s", &s, &t);
	int i;
	for (i = 0; i < n; i++)
		printf("%c%c", s[i], t[i]);
	return 0;
}

Score : 200 points

Problem Statement

Given are strings s and t of length N each, both consisting of lowercase English letters.

Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints

1 \leq N \leq 100

|S| = |T| = N

S and T are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S T

Output

Print the string formed.

Sample Input 1

2
ip cc

Sample Output 1

icpc

Sample Input 2

8
hmhmnknk uuuuuuuu

Sample Output 2

humuhumunukunuku

Sample Input 3

5
aaaaa aaaaa

Sample Output 3

aaaaaaaaaa


//C-Snack

#include <stdio.h>

int main(void) {
    long int a;
    long int b;
    scanf("%ld%ld", &a, &b);
    //printf("%d%d\n", a, b);
    long int i;
    for (i = 2;i <= b + 1;i++) {
        if ((a * i) % b == 0) {
            printf("%ld\n", a * i);
            break;
          }

      }
    return 0;

  }

Score : 300 points

Problem Statement

Takahashi is organizing a party.

At the party, each guest will receive one or more snack pieces.

Takahashi predicts that the number of guests at this party will be A or B.

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

We assume that a piece cannot be divided and distributed to multiple guests.

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

Sample Input 1

2 3

Sample Output 1

6

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000


#include <stdio.h>

int main() {
	long long int A, B;
	scanf("%lld%lld",&A,&B);
	long long int a = A, b = B, q = 1, c;
	if (a < b) {
		c = a;
		a = b;
		b = c;
	}
	while(q != 0) {
			q = a % b;
			a = b, b = q;
	}
	printf("%lld", A * B / a);
	return 0;
}


#include<stdio.h>

int main(){
 int a,b,ab,tmp,r;
  scanf("%d %d",&a,&b);
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  ab=a*b;
  r=b%a;
  while(r!=0){
    b=a;
    a=r;
    r=b%a;
  }
  printf("%d",ab/a);
  return 0;
}


Score : 500 points

Problem Statement

For an integer n not less than 0, let us define f(n) as follows:

f(n) = 1 (if n < 2)

f(n) = n f(n-2) (if n \geq 2)

Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

Constraints

0 \leq N \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of trailing zeros in the decimal notation of f(N).

Sample Input 1

12

Sample Output 1

1

f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080, which has one trailing zero.

Sample Input 2

5

Sample Output 2

0

f(5) = 5 × 3 × 1 = 15, which has no trailing zeros.

Sample Input 3

1000000000000000000

Sample Output 3

124999999999999995


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

Score : 100 points

Problem Statement

Given are three integers A_1, A_2, and A_3.

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Constraints

1 \leq A_i \leq 13 \ \ (i=1,2,3)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A_1 A_2 A_3

Output

If A_1+A_2+A_3 is greater than or equal to 22, print bust; otherwise, print win.

Sample Input 1

5 7 9

Sample Output 1

win

5+7+9=21, so print win.

Sample Input 2

13 7 2

Sample Output 2

bust

13+7+2=22, so print bust.


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

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

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

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

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

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

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

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

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(void){
  //srand(time(0));
  int i,j,n,m,k,a,b,c,h,w,r=0,l,t;
  scanf("%d%d%d",&n,&a,&b);
  if(n+a+b>=22){printf("bust\n");}
  else{printf("win\n");}
  return 0;
}


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

int	main(void)
{
  	char	s[101];
  	int		num;
  	int		len;
  	int		i;
  	int		count;

  	num = scanf("%s", s);
  	if (num != 1)
      	return (0);

  	len = strlen(s);

  	count = 0;
  	for (i=0; i<len/2 ; i++)
    {
      	if (s[i] != s[len - i - 1])
          	count++;
    }

  	printf("%d", count);

  	return (0);
}

Score : 200 points

Problem Statement

Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice.

Given is a string S. Find the minimum number of hugs needed to make S palindromic.

Constraints

S is a string consisting of lowercase English letters.

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

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of hugs needed to make S palindromic.

Sample Input 1

redcoder

Sample Output 1

1

For example, we can change the fourth character to o and get a palindrome redooder.

Sample Input 2

vvvvvv

Sample Output 2

0

We might need no hugs at all.

Sample Input 3

abcdabc

Sample Output 3

2


#include <stdio.h>
#include <string.h>
int main(void){
int count;
int n;
scanf("%d",&n);
count=0;
for(;;count++){
if((int)(count*1.08)==n){printf("%d\n",count);break;}
else if((int)(count*1.08)>n){printf(":(\n");break;}
}
return 0;
}

Score: 200 points

Problem Statement

Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.

The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer).

Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.

If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

Constraints

1 \leq N \leq 50000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If there are values that could be X, the price of the apple pie before tax, print any one of them.

If there are multiple such values, printing any one of them will be accepted.

If no value could be X, print :(.

Sample Input 1

432

Sample Output 1

400

If the apple pie is priced at 400 yen before tax, you have to pay 400 \times 1.08 = 432 yen to buy one.

Otherwise, the amount you have to pay will not be 432 yen.

Sample Input 2

1079

Sample Output 2

:(

There is no possible price before tax for which you have to pay 1079 yen with tax.

Sample Input 3

1001

Sample Output 3

927

If the apple pie is priced 927 yen before tax, by rounding down 927 \times 1.08 = 1001.16, you have to pay 1001 yen.


#include<stdio.h>

int main( void ){
    int i,x,a,cnt = 0;
    scanf("%d", &x);
    while(x >= 100){
        x -= 100;
        cnt ++;
    }
    if(x >= 0 && x <= cnt*5){
        printf("1\n");
    } else {
        printf("0\n");
    }
    return 0;
}

Score: 300 points

Problem Statement

AtCoder Mart sells 1000000 of each of the six items below:

Riceballs, priced at 100 yen (the currency of Japan) each

Sandwiches, priced at 101 yen each

Cookies, priced at 102 yen each

Cakes, priced at 103 yen each

Candies, priced at 104 yen each

Computers, priced at 105 yen each

Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.

(Ignore consumption tax.)

Constraints

1 \leq X \leq 100000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

Sample Input 1

615

Sample Output 1

1

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

Sample Input 2

217

Sample Output 2

0

No set of items costs 217 yen in total.


#include<stdio.h>

int cal(int A, int B, long int X, int r, int l){

    int digit =  0;
    int integer = (r + l) / 2;

    while(integer > 0){

        integer /= 10;
        digit += 1;
    }

    if(A*((r + l) / 2) + B*digit <= X){
        return 1;
    }else if(A*((r + l) / 2) + B*digit > X){
        return 0;
    }
}

int solve(int A, int B, long int X){

    int l = 0;
    int r = 1000000000;

    while(r != l){

        if(cal(A, B, X, r, l) == 1){
            l = (r + l) / 2 + 1;
        }else if(cal(A, B, X, r, l) == 0){
            r = (r + l) / 2;
        }
    }

    return l;
}

int main(void){

    int A, B;
    long int X;

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

    printf("%ld", solve(A, B, X));
}

Score : 100 points

Problem Statement

Given is a string S representing the day of the week today.

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

After how many days is the next Sunday (tomorrow or later)?

Constraints

S is SUN, MON, TUE, WED, THU, FRI, or SAT.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of days before the next Sunday.

Sample Input 1

SAT

Sample Output 1

1

It is Saturday today, and tomorrow will be Sunday.

Sample Input 2

SUN

Sample Output 2

7

It is Sunday today, and seven days later, it will be Sunday again.


Score : 200 points

Problem Statement

We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.

Shift each character of S by N in alphabetical order (see below), and print the resulting string.

We assume that A follows Z. For example, shifting A by 2 results in C (A \to B \to C), and shifting Y by 3 results in B (Y \to Z \to A \to B).

Constraints

0 \leq N \leq 26

1 \leq |S| \leq 10^4

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the string resulting from shifting each character of S by N in alphabetical order.

Sample Input 1

2
ABCXYZ

Sample Output 1

CDEZAB

Note that A follows Z.

Sample Input 2

0
ABCXYZ

Sample Output 2

ABCXYZ

Sample Input 3

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Sample Output 3

NOPQRSTUVWXYZABCDEFGHIJKLM


#include <stdio.h>
#define max 10001

int main() {
	int N,i=0;
	char s[max];
  	scanf("%d",&N);
  	scanf("%s",&s);
  	while(s[i]!='\0') {
      	if(i==max) {
        	return 0;
        }
    	s[i] += (char)N;
      	if(s[i]>'Z') {
        	s[i]-=26;
        }
      	printf("%c",s[i]);
      	i++;
    }
  	return 0;
}


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

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

    int flag;
    if(n%2 == 0){
        flag = n / 2;
    }else{
        flag = n/2 + 1;
    }
    int tmp = 0;
    int tmp1 = 0;
    int tmp2 = 0;
    int result = 0;

    int i = 0;
    for(i = 0; i < flag; i++){
        scanf("%d", &tmp);
        tmp1 += tmp;
    }

    for(i = 0; i < n - flag; i++){
        scanf("%d", &tmp);
        tmp2 += tmp;
    }

    result = abs(tmp1 - tmp2);

    printf("%d", result);

}

Score: 200 points

Problem Statement

Takahashi, who works at DISCO, is standing before an iron bar.
The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.

Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length.
However, this may not be possible as is, so he will do the following operations some number of times before he does the cut:

Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).

Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.

Find the minimum amount of money needed before cutting the bar into two parts with the same length.

Constraints

2 \leq N \leq 200000

1 \leq A_i \leq 2020202020

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_N

Output

Print an integer representing the minimum amount of money needed before cutting the bar into two parts with the same length.

Sample Input 1

3
2 4 3

Sample Output 1

3

The initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi can cut the bar equally after doing the following operations for 3 yen:

Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].

Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].

Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.

Sample Input 2

12
100 104 102 105 103 103 101 105 104 102 104 101

Sample Output 2

0


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int r;
    scanf("%d", &r);
    printf("%d", r * r);
}

Score : 100 points

Problem Statement

Given is an integer r.

How many times is the area of a circle of radius r larger than the area of a circle of radius 1?

It can be proved that the answer is always an integer under the constraints given.

Constraints

1 \leq r \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r

Output

Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer.

Sample Input 1

2

Sample Output 1

4

The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1.

Note that output must be an integer - for example, 4.0 will not be accepted.

Sample Input 2

100

Sample Output 2

10000


    #include <stdio.h>
    int main(){
    	int n;
      	scanf("%d" , &n);
      	char a[10000];
      	scanf("%s" , a);
      	int i = 0;
      if(n%2==1){
      	  printf("No");
          return 0;

      }
      for( i = 0 ; i < n/2 ; i++){
        	if(a[i] != a[n/2 + i]){
            	printf("No");
              	return 0;
        	}
        }
        printf("Yes");

    }

Score : 200 points

Problem Statement

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string T such that S = T + T.

Constraints

1 \leq N \leq 100

S consists of lowercase English letters.

|S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let T = abc, and S = T + T.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No


#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[101];
  scanf("%s",s);
  int half=n/2;
  int flg=1;

  for(int i=0;i<half;i++){
    if(s[i]!=s[i+half])flg=0;
  }
  if(flg && n!=1 && n%2==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return(0);

}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void swap(int *x,int *y){int tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
//next_permutation
//from https://qiita.com/Nikkely/items/0ddca51b3c0e60afbaab
int next_permutation(int *a,int n){
    int x=-1,y=-1;
    for(int i=n-2;i>=0;i--)if(a[i]<a[i+1]){x=i;break;}
    for(int i=n-1;x!=-1&&i>=0;i--)if(a[x]<a[i]){y=i;break;}
    if(x==-1||y==-1)return 1;
    swap(&a[x],&a[y]);
    qsort(&a[x+1],n-(x+1),sizeof(int),asc_cmp);
    return 0;
}

int factional(int x){
    int fact=1;
    for(int i=x;i>1;i--)fact*=i;
    return fact;
}

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

    int a[n];for(int i=0;i<n;i++)a[i]=i;
    double sum=0,tmp,x_sub,y_sub;
    do{
        tmp=0;
        for(int i=1;i<n;i++){
            x_sub=x[a[i]]-x[a[i-1]];
            y_sub=y[a[i]]-y[a[i-1]];
            tmp+=sqrt(pow(x_sub,2.0)+pow(y_sub,2.0));
        }
        //printf("%lf\n",tmp);
        sum+=tmp;
    }while(!next_permutation(a,n));

    printf("%.12lf\n",sum/factional(n));
    return 0;
}

Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387


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

#define N_MAX 8

int factorial(int n)
{
    if(n == 0)
    {
        return 1;
    }

    return factorial(n - 1) * n;
}

void main()
{
    int x[N_MAX], y[N_MAX];
    int i,j;
    int n;
    double sum = 0;

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

    for(i = 0; i < n - 1; i++)
    {
        for(j = i + 1; j < n; j++)
        {
            sum += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }
    printf("%lf", sum * (2 * n - 2)/(factorial(n)));

}


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

int main(void)
{
	long int i, j, index;
	long int n;
	long int sum;
	long int x[8];
	long int y[8];
	long int masu[8][8] = {{0}};
	double length = 0.0;

	scanf("%ld", &n);

	for(i = 0; i < n; i++) {
		scanf("%ld%ld", &x[i], &y[i]);
	}

	sum = 0;

	for(i = 0; i < n; i++) {
		for(j = 0; j < n; j++) {
			masu[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
			length += sqrt(masu[i][j]);
		}
	}

	//length = sqrt(sum);

	length /= n;

	printf("%.8lf", length);

	return 0;
}


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

typedef long long ll;

int a[100000];
int D[100000];

int comp(const void* x, const void* y){
    return D[*(int *)x] - D[*(int *)y];
}

int main(void){
    int N;
    ll ans = 1;
    ll node[10];
    ll via = 1;
    int cnt = 1;
    int node_sum = 1;
    node[0] = 1;

    scanf("%d", &N);
    int i;
    for(i = 0; i< N; i++){
        scanf("%d", &D[i]);
        a[i] = i;
    }
    if(D[0] != 0){
        printf("0");
        return 0;
    }
    qsort(a, N, sizeof(int), comp);
    if(D[a[1]] != 1){
        printf("0");
        return 0;
    }
    int j;
    for(i = 1; i < N; i++){
        if(cnt != D[a[i]] && cnt != 0){
            node[cnt] = i-node_sum;
            node_sum += node[cnt];
            cnt++;
        }
    }
    node[cnt] = i-node_sum;

    for(i = 1; i < N; i++){
        if(D[a[i-1]] != D[a[i]]){
            for(j = 0; j < node[D[a[i]]]; j++){
                via *= node[D[a[i-1]]];
            }
            ans *= via;
            via = 1;
        }

    }

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

Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll f(ll a){
  return a*(a+1)/2;
}
int main(void){
  char s[500001];
  scanf("%s",s);
  ll a[500000],cnt1=1,cnt2=0,ans=0;
  FOR(strlen(s)){
    if(s[i]!=s[i+1]){
      a[cnt2]=cnt1;
      cnt2++;
      cnt1=1;
    }else{
      cnt1++;
    }
  }
  for(ll i=0;i<cnt2;i+=2){
    ans+=f(max(a[i],a[i+1]))+f(min(a[i],a[i+1])-1);
  }
  PRL(ans+(s[0]=='>'&&s[strlen(s)-1]=='<'));
  return 0;
}

Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

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

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28


#include <stdio.h>

const int sup = 1 << 30;

typedef struct {
	int id;
	long long key;
} data;

typedef struct {
	data obj[100001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = h->size;
	data tmp;
	h->obj[(h->size)++] = x;
	while (1) {
		if (i == 0) break;
		else if (h->obj[i].key > h->obj[(i-1)/2].key) {
			tmp = h->obj[(i-1)/2];
			h->obj[(i-1)/2] = h->obj[i];
			h->obj[i] = tmp;
			i = (i - 1) / 2;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 0, j;
	data output = h->obj[0], tmp;
	h->obj[0] = h->obj[--(h->size)];
	while (1) {
		if (i * 2 + 1 >= h->size) break;
		else if (i * 2 + 2 >= h->size) j = i * 2 + 1;
		else if (h->obj[i*2+1].key > h->obj[i*2+2].key) j = i * 2 + 1;
		else j = i * 2 + 2;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, L[100001], R[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d %d", &(L[i]), &(R[i]));

	int min = R[1], argmin = 1;
	for (i = 2; i <= N; i++) {
		if (R[i] < min) {
			min = R[i];
			argmin = i;
		}
	}

	data d;
	max_heap h;
	h.size = 0;
	for (i = 1; i <= N; i++) {
		if (i == argmin) continue;
		d.key = (long long)L[i] * sup + R[i];
		push(d, &h);
	}

	long long ans = 0, l[2] = {L[argmin], h.obj[0].key / sup}, r[2] = {R[argmin], h.obj[0].key % sup};
	while (h.size > 0 && h.obj[0].key / sup > r[0]) {
		d = pop(&h);
		l[1] = (l[1] < d.key / sup)? d.key / sup: l[1];
		r[1] = (r[1] > d.key % sup)? d.key % sup: r[1];
	}
	while (h.size > 0) {
		l[0] = h.obj[0].key / sup;
		if (r[0] - l[0] + 1 + ((r[1] >= l[1])? r[1] - l[1] + 1: 0) > ans) ans = r[0] - l[0] + 1 + ((r[1] >= l[1])? r[1] - l[1] + 1: 0);
		while (h.size > 0 && h.obj[0].key / sup == l[0]) {
			d = pop(&h);
			r[1] = (r[1] > d.key % sup)? d.key % sup: r[1];
		}
	}
	l[0] = L[argmin];
	if (r[0] - l[0] + 1 + ((r[1] >= l[1])? r[1] - l[1] + 1: 0) > ans) ans = r[0] - l[0] + 1 + ((r[1] >= l[1])? r[1] - l[1] + 1: 0);

	int max = R[argmin] - L[argmin], argmax = argmin;
	for (i = 1; i <= N; i++) {
		if (R[i] - L[i] > max) {
			max = R[i] - L[i];
			argmax = i;
		}
	}
	if (argmax != argmin) {
		for (i = 1, max = 0; i <= N; i++) {
			if (i == argmax) continue;
			if (L[i] > max) max = L[i];
		}
		if (R[argmax] - L[argmax] + 1 + ((max <= min)? min - max + 1: 0) > ans) ans = R[argmax] - L[argmax] + 1 + ((max <= min)? min - max + 1: 0);
	}

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

Score : 600 points

Problem Statement

10^9 contestants, numbered 1 to 10^9, will compete in a competition.
There will be two contests in this competition.

The organizer prepared N problems, numbered 1 to N, to use in these contests.
When Problem i is presented in a contest, it will be solved by all contestants from Contestant L_i to Contestant R_i (inclusive), and will not be solved by any other contestants.

The organizer will use these N problems in the two contests.
Each problem must be used in exactly one of the contests, and each contest must have at least one problem.

The joyfulness of each contest is the number of contestants who will solve all the problems in the contest.
Find the maximum possible total joyfulness of the two contests.

Constraints

2 \leq N \leq 10^5

1 \leq L_i \leq R_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 R_1
L_2 R_2
\vdots
L_N R_N

Output

Print the maximum possible total joyfulness of the two contests.

Sample Input 1

4
4 7
1 4
5 8
2 5

Sample Output 1

6

The optimal choice is:

Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.

Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.

The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.

Sample Input 2

4
1 20
2 19
3 18
4 17

Sample Output 2

34

Sample Input 3

10
457835016 996058008
456475528 529149798
455108441 512701454
455817105 523506955
457368248 814532746
455073228 459494089
456651538 774276744
457667152 974637457
457293701 800549465
456580262 636471526

Sample Output 3

540049931


/* ex3_4
   key_tree */

#include <stdio.h>

// Nを1-9で割った商が1-9かつ余りが0になればよい
int main(void) {
  int N;
  scanf("%d", &N);
  int i = 1;
  // 1-9まで調べる
  while(i < 10){
    int quotient = N / i;
    int remainder = N % i;
    //商が1-9かつ余り0
    if(quotient >= 1 && quotient <= 9 && remainder == 0){
      printf("Yes\n");
      break;/*当てはまったらwhile脱出*/
	}
    i += 1;
  }
  if(i == 10){
    printf("No\n");
  }
  return 0;
}

Score : 200 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No.

Constraints

1 \leq N \leq 100

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No.

Sample Input 1

10

Sample Output 1

Yes

10 can be represented as, for example, 2 \times 5.

Sample Input 2

50

Sample Output 2

No

50 cannot be represented as the product of two integers between 1 and 9.

Sample Input 3

81

Sample Output 3

Yes


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

int main(void){
    int i, j, k, l, a[9][9], N, judge=0;
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            a[i][j]=i*j;
        }
    }
    scanf("%d", &N);
    for(k=1;k<=9;k++){
        for(l=1;l<=9;l++){
            if(N==a[k][l]){
                judge=1;
                break;
            }
        }
    }
    if(judge==1){
        printf("Yes");
    }else{
        printf("No");
    }
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    long long n,i,j;

    scanf("%lld",&n);
    long long tmp = n-1; //初期化
    long long ans_x = 1;
    long long ans_y = n;

    for(i = 1; i <= n/2 ; i++){
        if(n % i == 0){
            int syou = n/i;
            int sa = llabs(syou-i);
            if(sa < tmp){
                ans_x = i;
                ans_y = syou;
                tmp = sa;
//                printf("%lld %lld is best sa is %lld\n",ans_x,ans_y,tmp);
            }
        }
    }
    printf("%lld\n",ans_x + ans_y - 2);
    return 0;
}

Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.


#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846
int main(void){
  	float d = 180 / PI;
    int a, b, x;
    float p;
    scanf("%d %d %d",&a, &b, &x);
    if(x <= a*b*b/2){
        p = 180 / PI * atan2(2*x, a*b*b);
    }else{
        p = 180 / PI * atan2(2*(a*a*b-x), a*a*a);
    }
    printf("%f",p);
    return 0;
}

Score : 400 points

Problem Statement

Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.)

We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.

When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.

Constraints

All values in input are integers.

1 \leq a \leq 100

1 \leq b \leq 100

1 \leq x \leq a^2b

Input

Input is given from Standard Input in the following format:

a b x

Output

Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees.
Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

2 2 4

Sample Output 1

45.0000000000

This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees.

Sample Input 2

12 21 10

Sample Output 2

89.7834636934

This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.

Sample Input 3

3 1 8

Sample Output 3

4.2363947991

This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.


#include <stdio.h>
#include <math.h>
/*
c = 0.5 * sinC * de
sinC = c / (0.5 * de)
C = asin(c / (0.5 * de)))
 */
double Calc(int a, int b, int x){
  double c, d, e, f;
  c = (double) x / a;
  if(a * b * 0.5 >= c){
    d = b;
    f = 2 * c / d;
    e = sqrt(f * f + d * d);
    return 90 - asin(c / (0.5 * d * e)) / M_PI * 180;
  }else{
    d = 2 * c / a - b;
    f = b - d;
    e = sqrt(a * a + f * f);
    c -= 0.5 * a * b;
    return 90 - asin(c / (0.5 * d * e)) / M_PI * 180;
  }
}

int main(void){
  int a, b, x;
  scanf("%d %d %d", &a, &b, &x);
  printf("%f\n", Calc(a, b, x));
  return 0;
}


#include <stdio.h>

int main(void){
  int N = 0; // たこ焼きの個数
  int d[50]; // おいしさの値を格納する配列
  int heal_points_list[1225]; // 回復量を格納する配列
  int sum_heal_points = 0; // 回復量の総和

  // たこ焼きの個数を設定する
  printf("たこ焼きの個数を入力：");
  scanf("%d", &N);

  // たこ焼き達においしさ値を設定する
  for(int i = 0;i < N; i++) {
    printf("%d個目のたこ焼きのおいしさ値を設定：", i + 1);
    scanf("%d", &d[i]);
  }

  // 総当たり方式の実行回数を求める
  int calc_count = (N * (N - 1)) / 2;

  // 各たこ焼き同士の回復量を総当たり方式で計算する
  for(int i = 0; i < N; i++) {
    int num = i + 1;

    // i が配列の要素数と同じかそれ以上になった場合、numに ０を代入する
    if(calc_count <=  i + 1) num = 0;

    heal_points_list[i] = d[i] * d[num];
  }

  // 回復量の総和を計算する
  for(int i = 0; i < calc_count; i++) {
    sum_heal_points += heal_points_list[i];
  }

  // 出力
  printf("合計回復量：%d\n", sum_heal_points);

  return 0;
}

Score : 200 points

Problem Statement

It's now the season of TAKOYAKI FESTIVAL!

This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i.

As is commonly known, when you eat two takoyaki of deliciousness x and y together, you restore x \times y health points.

There are \frac{N \times (N - 1)}{2} ways to choose two from the N takoyaki served in the festival. For each of these choices, find the health points restored from eating the two takoyaki, then compute the sum of these \frac{N \times (N - 1)}{2} values.

Constraints

All values in input are integers.

2 \leq N \leq 50

0 \leq d_i \leq 100

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_N

Output

Print the sum of the health points restored from eating two takoyaki over all possible choices of two takoyaki from the N takoyaki served.

Sample Input 1

3
3 1 2

Sample Output 1

11

There are three possible choices:

Eat the first and second takoyaki. You will restore 3 health points.

Eat the second and third takoyaki. You will restore 2 health points.

Eat the first and third takoyaki. You will restore 6 health points.

The sum of these values is 11.

Sample Input 2

7
5 0 7 8 3 3 2

Sample Output 2

312


#include<stdio.h>
#include<stdlib.h>
main()
{
    int x,i,j,k,sum=0,a[100],fact;
    scanf("%d",&x);
    for(i=0;i<x;i++)
    {
    scanf("%d",&a[x]);
    }
    for(k=0;k<x;k++)
    {
        for(j=k+1;j<x;j++)
        {
            fact=a[k]*a[j];
            sum=sum+fact;
        }
    }
    printf("%d",sum);
}


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


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

int main(){
  int n;
  scanf("%d",&n);
  int sum=0;
  char *s;
  s=malloc(sizeof(char)*n);
  for(int i=0;i<n;i++){
    scanf("%d",s[i]);
    if(i=0){
      sum=1;
      continue;}
    if(s[i-1]!=s[i]){
      sum++;}
  }
  printf("%d\n",sum);
  return 0;
}

Score : 300 points

Problem Statement

There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i-th slime from the left has the color that corresponds to the i-th character of S.

Adjacent slimes with the same color will fuse into one larger slime without changing the color. If there were a slime adjacent to this group of slimes before fusion, that slime is now adjacent to the new larger slime.

Ultimately, how many slimes will be there?

Constraints

1 \leq N \leq 10^5

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the final number of slimes.

Sample Input 1

10
aabbbbaaca

Sample Output 1

5

Ultimately, these slimes will fuse into abaca.

Sample Input 2

5
aaaaa

Sample Output 2

1

All the slimes will fuse into one.

Sample Input 3

20
xxzaffeeeeddfkkkkllq

Sample Output 3

10


#include <stdio.h>
int main(void){
	int n, cnt=1;
  	scanf("%d",&n);
  	char s[n];
  	scanf("%s",s);
  	for(int i=1; i<n; i++){
		if(s[i] != s[i-1]) cnt++;
    }
  printf("%d\n",cnt);
  return 0;
}


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

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

	int count = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < i; j++){
			for (int k = 0; k < j; k++){
				if (L[i] < L[j] + L[k] && L[j] < L[k] + L[i]
						&& L[k] < L[i] + L[j]){
					++count;
				}
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23


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

Score : 100 points

Problem Statement

Given is an integer N.

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

Find the probability that a is odd.

Constraints

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the probability that a is odd.
Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

4

Sample Output 1

0.5000000000

There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \frac{2}{4} = 0.5.

Sample Input 2

5

Sample Output 2

0.6000000000

Sample Input 3

1

Sample Output 3

1.0000000000


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

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

  int N;
  double x;

  scanf("%d", &N);

  if(N % 2 == 0){
    printf("%.10f\n", 0.5);
  }else{
    x = (double)(N+1)/2/N;
    printf("%.10f\n", x);
  }

  return 0;
}


#include <stdio.h>

#ifdef DEBUG
#define DPRTF(x) printf x
#define TRACE (printf("%s:%s:%d\n", __FILE__, __func__, __LINE__))
#define ERR(x) (TRACE, (x))
#else
#define DPRTF(x)
#define TRACE
#define ERR(x) (x)
#endif

int main(int argc, char *argv[])
{
    int N;
    scanf("%d", &N);

    if (N % 2 == 0) {
        printf("0.5000000000\n");
    } else if (N == 1) {
        printf("1.0000000000\n");
    } else if (N % 2 == 1) {
        printf("0.6000000000\n");
    }

    return 0;
}


#include <stdio.h>

int main(void){
    int a;
    double d,b=0,c=0;
    scanf("%d",&a);
    c=a;
    b=a/2;
    b=b+1;
    d=b/c;
    printf("%lf\n",d);
    return 0;
}


#include<stdio.h>

int main(){
    int i,N;
    int cnt=0;
    scanf("%d",&N);
    for(i = 1 ; i <= N ; i++){
        if(i % 2 != 0){
            cnt++;
        }
    }
    printf("%f",(double)cnt/N);
    return 0;
}


#include <stdio.h>
long long detmax(long long x,long long y)
{
    if (x > y) {
      return x;
    } else {
      return y;
    }
}
long long detmin(long long x,long long y)
{
    if (x > y) {
      return y;
    } else {
      return x;
    }
}
long long detc(long long x,long long y)
{
    long long max = detmax(x,y);
    long long min = detmin(x,y);
    long long tmp;
    while(tmp != 0) {
        tmp = max - min;
        max = detmax(tmp,min);
        min = detmin(tmp,min);
    }
    return max;
}
int find(long long x)
{
    if (x == 2) {
        return 1;
    }
    for(int i=2;i<x;i++) {
        if (x%i==0) {
            return 0;
        }
    }
    return 1;
}

int main()
{
    long long a,b;
    scanf("%lli%lli",&a,&b);
    long long num = detc(a,b);
    int count=1;
    if (num == 1) {
        printf("%i",count);
        return 0;
    }
    for (long long i=2;i<num+1;i++) {
        if (num%i==0&&find(i)) {
            count++;
        }
    }
    printf("%i",count);
    return 0;
}

Score : 400 points

Problem Statement

Given are positive integers A and B.

Let us choose some number of positive common divisors of A and B.

Here, any two of the chosen divisors must be coprime.

At most, how many divisors can we choose?

Definition of common divisor

An integer d is said to be a common divisor of integers x and y when d divides both x and y.

Definition of being coprime

Integers x and y are said to be coprime when x and y have no positive common divisors other than 1.

Definition of dividing

An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x.

Constraints

All values in input are integers.

1 \leq A, B \leq 10^{12}

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of divisors that can be chosen to satisfy the condition.

Sample Input 1

12 18

Sample Output 1

3

12 and 18 have the following positive common divisors: 1, 2, 3, and 6.

1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1, 2, and 3, which achieve the maximum result.

Sample Input 2

420 660

Sample Output 2

4

Sample Input 3

1 2019

Sample Output 3

1

1 and 2019 have no positive common divisors other than 1.


// CPP program to print prime factors and their
// powers.
#include <stdio.h>
#include<math.h>
int sum = 0;

// function to calculate all the prime factors and
// count of every prime factor
void primecounter(int n)
{
    int count = 0;

    // count the number of times 2 divides
    while (!(n % 2)) {
        n >>= 1; // equivalent to n=n/2;
        count++;
    }

    // if 2 divides it
    if (count){
       // printf("%d %d\n",2,count);
        sum++;
    }
    // check for all the possible numbers that can
    // divide it
    for (long long i = 3; i <= sqrt(n); i += 2) {
        count = 0;
        while (n % i == 0) {
            count++;
            n = n / i;
        }
        if (count){
         //   printf("%d %d\n",i,count);
            sum++;
        }
    }

    // if n at the end is a prime number.
    if (n > 2){
       // printf("%d %d\n",n,1);
        sum++;
    }
}
int GCD(long long a,long long b)
{
    if(a%b==0)
        return b;
    else
        return GCD(b,a%b);
}
// driver program to test the above function
int main(void)
{
    long long int a,b;
    scanf("%d%d",&a,&b);
    int n = GCD(a,b) ;
    primecounter(n);
    printf("%d\n",sum+1);
    return 0;
}


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

void change(long* x, long* y){
    long z = *x;
    *x = *y;
    *y = z;
}

void gcd(long* x, long* y){
    long z;

    if (*x < *y){
        change(x, y);
    }

    while(*x % *y){
        z = *x % *y;
        *x = *y;
        *y = z;
    }
}

int main(){
    long a,b;
    int t = 1;

    scanf("%ld%ld", &a, &b);  //a > b

    gcd(&a, &b);

    for(long i = 2; i <= sqrt(b); i ++){
        if(b % i == 0){
            while(b % i == 0){
                b /= i;
            }

            t++;
        }
    }
    printf("%d",t);

    return 0;
}


#include <stdio.h>
#include <math.h>
static int a[100010],hantei[10010];

int gcd(int a, int b) {
  int t;    // �⏕�ϐ�
  while ( b != 0 ) {          // ������0�ɂȂ�܂�
    t = a%b; a = b; b = t;    // �������]�ɒu��������
  }
  return a;                   // ������0�ɂȂ����Ƃ��̈����GCD
}

int
main(){
	 int A,B,i;
	 int cnt=0;
	int K;
	scanf("%d %d",&A,&B);

	int tmp;
	if(B>A){tmp = A;
			A=B;
			B=tmp;
	}

	if(B==1){
		printf("1\n");return 0;
	}

	for(i=1;i<B;i++){
		if(A%i==0 && B%i==0)a[cnt++]=i;

	}
	int bb,j;
	for(i=1;i<cnt;i++){
		//printf("%d : ",a[i]);
		for(j=0;j<i;j++){

			/*if(a[i]==2){
				hantei[a[i]]=1;
			}
			else if (a[i]>2 && a[i]%2==1){*/
				bb = gcd(a[j],a[i]);
						hantei[bb]=1;//}
			//printf("%d(%d,%d) ,,,",bb,a[j],a[i]);

		}
	}
	//printf("\n");
	int ans =0;
	//printf("%dlllll\n",a[1]);
	//if(a[1]==0)ans++;

	for(i=0;i<cnt;i++){
		if(hantei[a[i]]){
			 int k,flag=0;
			 for( k=2;k<a[i];++k) {
    			if( a[i]%k==0 ) {
      			flag = 1;
      			break;
    		}
		  }
			if(flag==0)ans++;

		}
		//printf("(%d %d:%d),", a[i],hantei[a[i]],ans);
	}
	printf("%d\n",ans);
 return 0;
}


#include<stdio.h>
int main(void)
{
    char S[10];

    scanf("%s",S);

    if(S[0]=='S') printf("Cloudy\n");
    else if(S[0]=='C') printf("Rainy\n");
    else printf("Sunny\n");

    return 0;
}

Score: 100 points

Problem Statement

The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ...

Given is a string S representing the weather in the town today. Predict the weather tomorrow.

Constraints

S is Sunny, Cloudy, or Rainy.

Input

Input is given from Standard Input in the following format:

S

Output

Print a string representing the expected weather tomorrow, in the same format in which input is given.

Sample Input 1

Sunny

Sample Output 1

Cloudy

In Takahashi's town, a sunny day is followed by a cloudy day.

Sample Input 2

Rainy

Sample Output 2

Sunny


#include<stdio.h>
int main()
{
char a[6];
  scanf("%6s",a);
if(a[0]=='R') printf("Sunny");
else if(a[0]=='S') printf("Cloudy");
else if(a[0]=='C') printf("Rainy");
return 0;
}


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

int main(void)
{
  char weather[3][7] = {"Sunny","Cloudy","Rainy"};
  char today[7];
  int i;

  scanf("%s",today);

  for(i=0;i<3;i++){
    if(strcmp(today,weather[i])==0){
      i = (i+1)%3;
      break;
    }
  }
  printf("%s\n",weather[i]);

  return 0;
}


#include <stdio.h>
int main(){
  char s[10];
  scanf("%s",&s);
  if(s=="Sunny"){
    printf("Cloudy");
  }
  else if(s=="Cloudy"){
    printf("Rainy");
  }
  else if(s=="Rainy"){
    printf("Sunny");
  }
  else{
    printf("\n");
  }
  return 0;
}


#include<stdio.h>
int main(void){
    char S;
    scanf("$d",S);
    if(S='Sunny'){
        printf("Cloudy");
    }else if(S='Cloudy'){
        printf("Rainy");
    }else{
        printf("Sunny");
    }
    return 0;
}


#include <stdio.h>

int main()
{
  char S[40];
  scanf("%s", S);

  switch (S[0])
  {
    case 'S':
      printf("Cloudy\n");
      break;
    case 'C':
      printf("Rainy\n");
      break;
    case 'R':
      printf("Sunny\n");
      break;
  }
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void)
{
    char s[100];
    scanf("%s", s);
    int j = 1;
  	bool f1=false;
  	bool f2=false;
  if(strlen(s)>1){
    for (int i = 0,j=1; i < strlen(s)&&j < strlen(s); i += 2, j += 2)
    {
        if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
        {
        }else{
        	f1 = true;
        }
        if (s[j] == 'L' || s[j] == 'U' || s[j] == 'D')
        {
        }else{
        	f2 = true;
        }
    }

    if (f1 == false && f2 == false)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
  }else{
  	if(s[0] == 'R'){
		printf("No");
      return 0;
    }else{
    	printf("Yes");
      	return 0;
    }
  }
    return 0;
}

Score: 200 points

Problem Statement

Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character.

S is said to be easily playable if and only if it satisfies both of the following conditions:

Every character in an odd position (1-st, 3-rd, 5-th, \ldots) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th, \ldots) is L, U, or D.

Your task is to print Yes if S is easily playable, and No otherwise.

Constraints

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

Each character of S is L, R, U, or D.

Input

Input is given from Standard Input in the following format:

S

Output

Print Yes if S is easily playable, and No otherwise.

Sample Input 1

RUDLUDR

Sample Output 1

Yes

Every character in an odd position (1-st, 3-rd, 5-th, 7-th) is R, U, or D.

Every character in an even position (2-nd, 4-th, 6-th) is L, U, or D.

Thus, S is easily playable.

Sample Input 2

DULL

Sample Output 2

No

The 3-rd character is not R, U, nor D, so S is not easily playable.

Sample Input 3

UUUUUUUUUUUUUUU

Sample Output 3

Yes

Sample Input 4

ULURU

Sample Output 4

No

Sample Input 5

RDULULDURURLRDULRLR

Sample Output 5

Yes


#include <stdio.h>
int main(void){
char s[200];
int count,out=0;
scanf("%s",s);
for(count=0;;){
  if(s[count]=='\0'){break;}

      if(s[count]=='R'||s[count]=='D'||s[count]=='U'){}
      else{out++;}
count++;
if(s[count]=='\0'){break;}
      if(s[count]=='L'||s[count]=='D'||s[count]=='U'){}
      else{out++;}
      count++;
}
if(out==0){printf("Yes");}
else{printf("No");}

return 0;

}


Score : 200 points

Problem Statement

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

All values in input are integers.

2 \leq N \leq 20

1 \leq A_i \leq N

A_1, A_2, ..., A_N are all different.

1 \leq B_i \leq 50

1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Sample Input 1

3
3 1 2
2 5 4
3 6

Sample Output 1

14

Takahashi gained 14 satisfaction points in total, as follows:

First, he ate Dish 3 and gained 4 satisfaction points.

Next, he ate Dish 1 and gained 2 satisfaction points.

Lastly, he ate Dish 2 and gained 5 + 3 = 8 satisfaction points.

Sample Input 2

4
2 3 4 1
13 5 8 24
45 9 15

Sample Output 2

74

Sample Input 3

2
1 2
50 50
50

Sample Output 3

150


Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

B_i \geq \max(A_i, A_{i+1})

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53


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

int main()
{
    int A , B;
    scanf("%d %d",&A,&B);
     int count = 1;
     int min = INT_MAX;
     int c = A;
     if (A>B){printf("0");return 0;}
    while (1)
    {
         if (A==B)
            break;
          else if (A>B)
              break;
     A+=c;
     A--;
     count++;

    }

    printf("%d",count);

    return 0;
}

Score : 200 points

Problem Statement

Takahashi's house has only one socket.

Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.

One power strip with A sockets can extend one empty socket into A empty sockets.

Find the minimum number of power strips required.

Constraints

All values in input are integers.

2 \leq A \leq 20

1 \leq B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of power strips required.

Sample Input 1

4 10

Sample Output 1

3

3 power strips, each with 4 sockets, extend the socket into 10 empty sockets.

Sample Input 2

8 9

Sample Output 2

2

2 power strips, each with 8 sockets, extend the socket into 15 empty sockets.

Sample Input 3

8 8

Sample Output 3

1


#include<stdio.h>
int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  int sum=1,count=0;
  while(sum<y){
    sum+=x-1;
    count++;
  }
  printf("%d",count);
  return 0;
}


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

void init(char s[], int size)
{
	for (int i = 0; i < size; i++)
	{
		s[i] = '\0';
	}
}

int main(void)
{

	int a, b, d;
	int count = 1, i = 0;
	char c, temp[4];

	init(temp, 4);

	while ((c = getchar()) != '\n')
	{
		if (c != ' ')
		{
			temp[i] = c;
			i++;
		}
		else
		{
			a = atoi(temp);
			init(temp, 4);
			i = 0;
		}
	}

	b = atoi(temp);

	d = a;

	while (a < b)
	{
		d = d - 1 + a;
		count++;
	}

	printf("%d", count);

	return 0;
}


#include<stdio.h>

int main(void){
    int n,i,ans=0,count=0;
    scanf("%d",&n);
    long int h[n];
    for(i=0;i<n;i++){
        scanf("%ld",&h[i]);
    }
    for(i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            count++;
        }else{
            if(ans<=count){
                ans=count;
                count=0;
            }
        }
    }
    printf("%d",count);
    return 0;
}

Score : 300 points

Problem Statement

There are N squares arranged in a row from left to right.

The height of the i-th square from the left is H_i.

You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.

Find the maximum number of times you can move.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq H_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
H_1 H_2 ... H_N

Output

Print the maximum number of times you can move.

Sample Input 1

5
10 4 8 7 3

Sample Output 1

2

By landing on the third square from the left, you can move to the right twice.

Sample Input 2

7
4 4 5 6 6 5 5

Sample Output 2

3

By landing on the fourth square from the left, you can move to the right three times.

Sample Input 3

4
1 2 3 4

Sample Output 3

0


#include <stdio.h>

int main(){
  int i;
  scanf("%d",&i);
  printf("%d",i*(i-1)/2);
  return(0);
}

Score : 400 points

Problem Statement

For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}.

Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.

Find the maximum possible value of M_1 + M_2 + \cdots + M_N.

Constraints

N is an integer satisfying 1 \leq N \leq 10^9.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible value of M_1 + M_2 + \cdots + M_N.

Sample Input 1

2

Sample Output 1

1

When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1.

Sample Input 2

13

Sample Output 2

78

Sample Input 3

1

Sample Output 3

0


Score : 500 points

Problem Statement

N players will participate in a tennis tournament. We will call them Player 1, Player 2, \ldots, Player N.

The tournament is round-robin format, and there will be N(N-1)/2 matches in total.
Is it possible to schedule these matches so that all of the following conditions are satisfied? If the answer is yes, also find the minimum number of days required.

Each player plays at most one matches in a day.

Each player i (1 \leq i \leq N) plays one match against Player A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} in this order.

Constraints

3 \leq N \leq 1000

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

A_{i, j} \neq i

A_{i, 1}, A_{i, 2}, \ldots, A_{i, N-1} are all different.

Input

Input is given from Standard Input in the following format:

N
A_{1, 1} A_{1, 2} \ldots A_{1, N-1}
A_{2, 1} A_{2, 2} \ldots A_{2, N-1}
:
A_{N, 1} A_{N, 2} \ldots A_{N, N-1}

Output

If it is possible to schedule all the matches so that all of the conditions are satisfied, print the minimum number of days required; if it is impossible, print -1.

Sample Input 1

3
2 3
1 3
1 2

Sample Output 1

3

All the conditions can be satisfied if the matches are scheduled for three days as follows:

Day 1: Player 1 vs Player 2

Day 2: Player 1 vs Player 3

Day 3: Player 2 vs Player 3

This is the minimum number of days required.

Sample Input 2

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

Sample Output 2

4

All the conditions can be satisfied if the matches are scheduled for four days as follows:

Day 1: Player 1 vs Player 2, Player 3 vs Player 4

Day 2: Player 1 vs Player 3

Day 3: Player 1 vs Player 4, Player 2 vs Player 3

Day 4: Player 2 vs Player 4

This is the minimum number of days required.

Sample Input 3

3
2 3
3 1
1 2

Sample Output 3

-1

Any scheduling of the matches violates some condition.


#include<stdio.h>
int main(void)
{
	double n,a,p=0,i;
	scanf("%lf", &n);
	for(i=0; i<n; i++)
	{
		scanf("%lf", &a);
		p+=1.0/a;
	}
	printf("%f\n", 1.0/p);

	return 0;
}

Score : 200 points

Problem Statement

Given is a sequence of N integers A_1, \ldots, A_N.

Find the (multiplicative) inverse of the sum of the inverses of these numbers, \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}.

Constraints

1 \leq N \leq 100

1 \leq A_i \leq 1000

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print a decimal number (or an integer) representing the value of \frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Sample Input 1

2
10 30

Sample Output 1

7.5

\frac{1}{\frac{1}{10} + \frac{1}{30}} = \frac{1}{\frac{4}{30}} = \frac{30}{4} = 7.5.

Printing 7.50001, 7.49999, and so on will also be accepted.

Sample Input 2

3
200 200 200

Sample Output 2

66.66666666666667

\frac{1}{\frac{1}{200} + \frac{1}{200} + \frac{1}{200}} = \frac{1}{\frac{3}{200}} = \frac{200}{3} = 66.6666....

Printing 6.66666e+1 and so on will also be accepted.

Sample Input 3

1
1000

Sample Output 3

1000

\frac{1}{\frac{1}{1000}} = 1000.

Printing +1000.0 and so on will also be accepted.


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


//((a + b) / 2 + c) / 2 == (a + b + 2c) / 4
//上記より、後に回したほうが価値の毀損が少ない
//昇順にソートして前から生成していく

#include <stdio.h>

void qsort(int len, int seq[len], int f, int l);
float generate(int len, int seq[len]);

int main()
{
  int N;
  scanf("%d",&N);
  int v[N];
  int i;
  i = 0;
  while (i < N)
  {
    scanf("%d",&v[i]);
    i++;
  }
  qsort(N, v, 0, N - 1);
  printf("%f",generate(N, v));
}

//quicksort
void qsort(int len, int seq[len], int f, int l)
{
  int i;
  int j;
  i = f;
  j = l;
  int threshold;
  threshold = seq[(f + l) / 2];
  int tmp;
  while (1)
  {
    while (threshold > seq[i])
      i++;
    while (threshold < seq[j])
      j--;
 	if (i >= j)
      break;
    tmp = seq[i];
    seq[i] = seq[j];
    seq[j] = tmp;
    i++;
    j--;
  }
  if (f < i - 1)
    qsort(len, seq, f, i - 1);
  if (l > j + 1)
    qsort(len, seq, j + 1, l);
}

//生成
float generate(int len, int seq[len])
{
  int i;
  float material;
  i = 1;
  material = seq[0];
  while (i < len)
  {
    material = (material + seq[i]) / 2;
    i++;
  }
  return (material);
}

Score : 300 points

Problem Statement

You have a pot and N ingredients. Each ingredient has a real number parameter called value, and the value of the i-th ingredient (1 \leq i \leq N) is v_i.

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be (x + y) / 2 where x and y are the values of the ingredients consumed, and you can put this ingredient again in the pot.

After you compose ingredients in this way N-1 times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Constraints

2 \leq N \leq 50

1 \leq v_i \leq 1000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
v_1 v_2 \ldots v_N

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

Your output will be judged correct when its absolute or relative error from the judge's output is at most 10^{-5}.

Sample Input 1

2
3 4

Sample Output 1

3.5

If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values 3 and 4 is (3 + 4) / 2 = 3.5.

Printing 3.50001, 3.49999, and so on will also be accepted.

Sample Input 2

3
500 300 200

Sample Output 2

375

You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:

Use the ingredients of values 500 and 300 to produce an ingredient of value (500 + 300) / 2 = 400. The next composition will use this ingredient and the ingredient of value 200, resulting in an ingredient of value (400 + 200) / 2 = 300.

Use the ingredients of values 500 and 200 to produce an ingredient of value (500 + 200) / 2 = 350. The next composition will use this ingredient and the ingredient of value 300, resulting in an ingredient of value (350 + 300) / 2 = 325.

Use the ingredients of values 300 and 200 to produce an ingredient of value (300 + 200) / 2 = 250. The next composition will use this ingredient and the ingredient of value 500, resulting in an ingredient of value (250 + 500) / 2 = 375.

Thus, the maximum possible value of the last ingredient remaining is 375.

Printing 375.0 and so on will also be accepted.

Sample Input 3

5
138 138 138 138 138

Sample Output 3

138


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

int main(void){
	int N,i,j,v[55],temp,max=0,submax=0;
  	double ans;
  	scanf("%d",&N);
  	for(i=0;i<N;i++){
      scanf("%d",&v[i]);
    }
      /* sort */
      for(i=0;i<N;i++){
		for(j=i+1;j<=N-1;j++){
          if(v[i]>v[j]){
            temp = v[i];
            v[i] = v[j];
            v[j] = temp;
          }
        }
      }
      /* sort */
  submax= v[i-1];
  max = v[i];

  ans = (v[0]+v[1])/(double)2;
  if(N>=3){
  	for(i=2;i<=N-1;i++){
 	   ans = (ans + v[i])/(double)2;
 	 }
  }
  if(N%2!=0){
  	printf("%f",ans);
  }else{
      printf("%f",(submax+max)/(double)2);
    }
}


#include <stdio.h>

typedef struct {
    char sent[10000];
    int len;
}string;

string scan(){
    string word;
    char c;
    int i = 0;
    while((c = getchar()) != '\n'){
        word.sent[i] = c;
        i++;
    }
    word.sent[i + 1] = '\0';
    word.len = i;
    return word;
}

int judge(string s, string t){
    int ans = 1, i, j;
    for(i = 0; i < t.len; i++){
        for(j = 0; j < s.len; j++){
            if(s.sent[j] == t.sent[i]){
                break;
            }else if(j + 1 == s.len){
                ans = 0;
            }
        }
        if(ans){break;}
    }
    return ans;
}

void makeCountST(string s, string t){
    int count = 0, p_t = 0, i;
    while(1){
        for(i = 0; i < s.len; i++){
            if(p_t == t.len){
                goto RESULT;
            }else if(s.sent[i] == t.sent[p_t]){
                p_t++;
            }
            count++;
        }
    }
    RESULT:
    printf("%d", count);
}

int main(){
    string s, t;
    s = scan();
    t = scan();

    if(judge(s, t)){
        makeCountST(s, t);
    }else{
        printf("-1");
    }
}

Score : 500 points

Problem Statement

Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists.

Let s' be the concatenation of 10^{100} copies of s. t is a subsequence of the string {s'}_1{s'}_2\ldots{s'}_i (the first i characters in s').

Notes

A subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net, c, and contest.

Constraints

1 \leq |s| \leq 10^5

1 \leq |t| \leq 10^5

s and t consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

If there exists an integer i satisfying the following condition, print the minimum such i; otherwise, print -1.

Sample Input 1

contest
son

Sample Output 1

10

t = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest...), so i = 10 satisfies the condition.

On the other hand, t is not a subsequence of the string contestco (the first 9 characters in s'), so i = 9 does not satisfy the condition.

Similarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10.

Sample Input 2

contest
programming

Sample Output 2

-1

t = programming is not a substring of s' = contestcontestcontest.... Thus, there is no integer i satisfying the condition.

Sample Input 3

contest
sentence

Sample Output 3

33

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.


Score : 300 points

Problem Statement

Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition:

There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-1).

Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this order.

Constraints

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

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum positive integer K that satisfies the condition.

Sample Input 1

aabbaa

Sample Output 1

4

We can, for example, divide S into four strings aa, b, ba, and a.

Sample Input 2

aaaccacabaababc

Sample Output 2

12


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

#define MAXCHAR 200000

int numdivide;

void func(char str[])
{
    int i = 0;
    char temp[MAXCHAR] = "";
    char compare[MAXCHAR] = "";
    char cbuff;

    while ((cbuff = str[i]) != '\0')
    {
        // compare = compare + cbuff;
        sprintf(compare,"%s%c", compare, cbuff);
        if (strcmp(temp,compare))
        {
            printf("%s,%s\n",temp,compare);
            numdivide++;
            strcpy(temp,compare);
            compare[0] = '\0';
        }
        i++;
    }
}

int main(void)
{
    int c;
    int i = 0 ;
    char strinput[MAXCHAR];
    while ((c = getchar()) != EOF)
    {
        strinput[i] = c;
        printf("%c",c);
        i=i+1;
    }
    // printf("%d",i);
    strinput[i] = '\0';
    func (strinput);
    printf("%d", numdivide - 1);
    return 0;
}


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

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

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

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

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

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

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

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

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

char s[524288];

bool issame(int a,int b,int l){
  int i;
  for(i=0;i<l;i++){
    if(s[a+i]!=s[b+i]){return false;}
  }
  return true;
}

int main(void){
  int i,j,n,m,k,a[524288],b,c,h,w,r=0,l,t;
  int dp[524288][8]={0};
  scanf("%s",&s[1]);
  l=strlen(&s[1]);
  s[l+1]='*';
  for(i=1;i<=7;i++){
    dp[i][i]=1;
  }
  for(i=1;i<=l;i++){
    for(j=1;j<=min(i,7);j++){
      for(k=1;k<=7;k++){
        //printf("%d %d %d\n",i,j,k);
        if(i+k>l){break;}
        if(j!=k){
          dp[i+k][k]=max(dp[i][j]+1,dp[i+k][k]);
        }
        if(!issame(i-k+1,i+1,k)){
          dp[i+k][k]=max(dp[i][j]+1,dp[i+k][k]);
        }
      }
    }
  }
  for(i=1;i<8;i++){
    r=max(dp[l][i],r);
  }
  printf("%d\n",r);
  return 0;
}


#include <stdio.h>

int max(int a, int b, int c){

    int res = a;

    if(res < b){
        res = b;
    } else if(res < c){
        res = c;
    }

    return res;
}

int main(){
    int a, b;

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

    printf("%d", max(a + b, a - b, a * b));

}

Score : 100 points

Problem Statement

We have two integers: A and B.

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

Constraints

All values in input are integers.

-100 \leq A,\ B \leq 100

Input

Input is given from Standard Input in the following format:

A B

Output

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

Sample Input 1

-13 3

Sample Output 1

-10

The largest number among A + B = -10, A - B = -16, and A \times B = -39 is -10.

Sample Input 2

1 -33

Sample Output 2

34

The largest number among A + B = -32, A - B = 34, and A \times B = -33 is 34.

Sample Input 3

13 3

Sample Output 3

39

The largest number among A + B = 16, A - B = 10, and A \times B = 39 is 39.


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

Score : 200 points

Problem Statement

There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.

Among them, some K consecutive stones are painted black, and the others are painted white.

Additionally, we know that the stone at coordinate X is painted black.

Print all coordinates that potentially contain a stone painted black, in ascending order.

Constraints

1 \leq K \leq 100

0 \leq X \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K X

Output

Print all coordinates that potentially contain a stone painted black, in ascending order, with spaces in between.

Sample Input 1

3 7

Sample Output 1

5 6 7 8 9

We know that there are three stones painted black, and the stone at coordinate 7 is painted black. There are three possible cases:

The three stones painted black are placed at coordinates 5, 6, and 7.

The three stones painted black are placed at coordinates 6, 7, and 8.

The three stones painted black are placed at coordinates 7, 8, and 9.

Thus, five coordinates potentially contain a stone painted black: 5, 6, 7, 8, and 9.

Sample Input 2

4 0

Sample Output 2

-3 -2 -1 0 1 2 3

Negative coordinates can also contain a stone painted black.

Sample Input 3

1 100

Sample Output 3

100


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

int asc(const void* a, const void* b) {
    return *(char*)b - *(char*)a;
}
int main() {
    char str[100000][15] = { 0 };
    int n;
    long long ans = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", str[i]);
        qsort(str[i], 10, sizeof(char), asc);
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if(strcmp(str[i],str[j])==0)ans++;
        }
    }
    printf("%lld", ans);

    return 0;
}

Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.


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

int compare(const void *a, const void *b) {
    if (*(char *)a > *(char *)b) {
        return 1;
    } else if (*(char *)a < *(char *)b) {
        return -1;
    } else {
        return 0;
    }
}

int main(void) {
    int n;
    unsigned long count = 0;
    char s[100000][11];

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", s[i]);
        qsort((void *)s[i], 10, 1, compare);
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (strcmp(s[i], s[j]) == 0) {
                count++;
            }
        }
    }

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

    return 0;
}


Score : 200 points

Problem Statement

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

Sample Input 1

11

Sample Output 1

9

Among the positive integers less than or equal to 11, nine integers have an odd number of digits: 1, 2, \ldots, 9.

Sample Input 2

136

Sample Output 2

46

In addition to 1, 2, \ldots, 9, another 37 integers also have an odd number of digits: 100, 101, \ldots, 136.

Sample Input 3

100000

Sample Output 3

90909


Score: 100 points

Problem Statement

We have two distinct integers A and B.

Print the integer K such that |A - K| = |B - K|.

If such an integer does not exist, print IMPOSSIBLE instead.

Constraints

All values in input are integers.

0 \leq A,\ B \leq 10^9

A and B are distinct.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the integer K satisfying the condition.

If such an integer does not exist, print IMPOSSIBLE instead.

Sample Input 1

2 16

Sample Output 1

9

|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.

Sample Input 2

0 3

Sample Output 2

IMPOSSIBLE

No integer satisfies the condition.

Sample Input 3

998244353 99824435

Sample Output 3

549034394


#include <stdio.h>

int main()
{
int A,B,K,x,y;
scanf("%d %d",&A,&B);
K=(A*A-B*B)/(2*A-2*B);
x=abs(A-K);
y=abs(B-K);
if(A<=pow(10,9) && B<=pow(10,9) && A!=B && x==y){printf("%d\n",K);}
else{ printf("IMPOSSIBLE\n");}
return 0;
}


#include<stdio.h>
int main()
{
    int a,b,i,r,q,flag,p,m,n;
    scanf("%d %d",&a,&b);
    if(a>=b)
    {
        m=a;
        n=b;
    }
    else
    {
        m=b;
        n=a;
    }
    for(i=n;i<=m;i++)
    {
        r=a-i;
        q=b-i;
        if((r==q) || (r==-q) || (-r==q) || (-r==-q))
        {
            flag=0;
            p=i;
            break;
        }
        else flag=1;
    }
    if(flag==1) printf("IMPOSSIBLE");
    else printf("%d",p);
}


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

    int K = abs(A+B) / 2;
    if((A + B) % 2 == 0){
        printf("%d",K);
    }else{
        printf("IMPOSSIBLE");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll gcd(ll p,ll q){for(ll t;q;)t=p%q,p=q,q=t;return p;}
ll lcm(ll p,ll q){return p/gcd(p,q)*q;}
ll asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
// qsort(array, length, sizeof(int), asc);

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    if(a>b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int i;
    int j = 0;
    for( i=a; i<=b; i++){
        if(abs(a-i) == abs(b-i)){
            printf("%d\n", i);
            j++;
            break;
        }
    }

    if(j == 0){
        printf("IMPOSSIBLE\n");
    }
    return 0;
}