#include<stdio.h>
#define m 200000
int main()
{
    int a[m],i,n,sum1=0,sum2=0,sum3=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            sum1++;
        if(a[i]%2==0)
            sum2++;
    }
    sum3=n-sum2;
    if(n<=3&&sum1>=1)printf("Yes");
    else if(sum2==n||((sum1>=sum3-1)&&sum2==0))printf("Yes");
    else if(sum2==n||sum1>=sum3)printf("Yes");
    else printf("No");
    return 0;
}


#include<stdio.h>
int main()
{
    int x=0,y=0,z=0,n,i,p;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&p);
        if(p%4==0)
            z=z+1;
        if(p%2==0)
            y=y+1;
        else
            x=x+1;
    }
    y=y-z;
    if(n%2&&n!=3){
        if(z>=x-1)
        printf("Yes");
    else printf("No");
    }
    else if(n==3)
    {
        if(z>=1||y==3)
            printf("Yes");
        else
            printf("No");
    }
    else {if(z>=x)
        printf("Yes");
    else printf("No");}
    return 0;
}

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

Score : 400 points

Problem Statement

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

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

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

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

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

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

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

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes

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()
{
	int N,j_num=0,two_num=0,four_num=0;
	scanf("%d",&N);

	long long *a;
	a=(long long*)malloc(N*sizeof(long long));

	for(int i=0;i<N;i++)
	{
		scanf("&lld",&a[i]);

		if(a[i] & 1)
			j_num++;
		else if(!(a[i]%4))
			four_num++;
		else
			two_num++;
	}

	if(two_num==0 && j_num>(four_num+1))
		printf("No\n");
	else if(two_num && j_num>four_num)
		printf("No\n");
	else
		printf("Yes\n");

	return 0;
}


#include<stdio.h>
int main(){
	int A[200010],i,j,n,a=0,b=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&A[i]);
		if(A[i]%4==0) b++;
		if(A[i]%2!=0) a++;
	}
	if(a+b==n){
		if(a<=b+1) printf("Yes\n");
		else printf("No\n");
	}
	else{
		if(a<=b) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include <stdio.h>

int main(void){
  long long N, A, B;
  scanf("%lld%lld%lld", &N, &A, &B);

  if(A > B || (N == 1 && A != B)) printf("0\n");
  else if(N == 1 && A == B) printf("1\n");
  else printf("%lld\n", (B*(N-1)+A+1)-(A*(N-1)+B));

  return 0;
}

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//1.判断数据是否合理 2. 计算结果
int main()
{
   long int  n,k,t,min,max;
  scanf("%ld %ld %ld",&n,&k,&t);
  if(n<1||k>1e9||t>1e9||n>1e9)
  {
     printf("0\n");
      return 0;
  }
 if(k>=t||(n==1&&k!=0&&t!=0))
 {
     printf("0\n");
     return 0;
 }

  max=(n-1)*t+k;
  min =(n-1)*k+t;
  printf("%ld\n",max-min+1);
    return 0;
}


#include<stdio.h>

int main()
{
int n,i,j,sum=0,d;
 scanf("%d %d %d",&n,&i,&j);
 if(n==1){
    if(i!=j) sum=0;
    else sum=1;
 }
 if(n>1){
    if(i>j) sum=0;
    if(i==j) sum=1;
    else{
        d=j-i;
        sum=(n-2)*d+1;
    }
 }
printf("%d",sum);
return 0;
}


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

int main()
{
    long long n,a,b,num = 0;
    scanf("%lld %lld %lld",&n,&a,&b);
    if(n == 1)
    {
        if(a == b)
            num = 1;
        else
            num = 0;
    }
    else
    {
        if(a == b)
            num = 1;
        else
            num = (n - 2) * (b - a) + 1;
    }
    if(a > b)
        num = 0;
    printf("%d\n",num);
    return 0;
}


#include<stdio.h>

int main() {

	int n, a, b, m;

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

	if (a > b) {
		m = 0;
	}
	else if(a==b){
		if (n == 1) {
				m = 1;
			}
			else {
				m = 0;
			}
		}

		else{
			if(n>1){
			m = (b - a)*(n - 2) + 1;
		}
		else {
			m = 0;
		}
	}
	printf("%d\n", m);
	return 0;

}


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

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

    if( a <= b) ans = (unsigned long long int)(b-a)*(n-2)+1;
    if( n == 1 && a == b) ans =  1;
    else if( n == 1) ans = 0;
    printf("%llu\n", ans);
    return 0;
}


#include<stdio.h>

int main(void){
  long long N,A,B;
  long long i;
  long long max,min,ans;
  scanf("%lld%lld%lld",&N,&A,&B);
  if(A > B){
    ans = 0;
  }else if(N == 1 && A != B){
    ans = 0;
  }else{
    min = A*(N-1)+B;
    max = B*(N-1)+A;
    ans = max-min+1;
  }
  printf("%lld\n",ans);
  return 0;
}


Score : 500 points

Problem Statement

Let N be a positive integer.

There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').

Find the maximum possible score of a'.

Constraints

1 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Partial Score

In the test set worth 300 points, N ≤ 1000.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{3N}

Output

Print the maximum possible score of a'.

Sample Input 1

2
3 1 4 1 5 9

Sample Output 1

1

When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.

Sample Input 2

1
1 2 3

Sample Output 2

-1

For example, when a_1 are removed, a' will be (2, 3), which has a score of 2 - 3 = -1.

Sample Input 3

3
8 2 2 7 4 6 5 3 8

Sample Output 3

5

For example, when a_2, a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3), which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5.


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    char string[20000];

    //printf("Input the string:");
    scanf("%s",string);

    int count=0;
    int i=0;
    while(string[i]!='A'){
        i++;
    }
    while(string[i]!='Z'){
        i++;
        count++;
    }
    i++;
    int count2=0;
    while(string[i]=='Z'){
        count2++;
        i++;
    }

    printf("%d",count+1+count2);
    return 0;
}

Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

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

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int comp(const void * a, const void * b){
  return (*(int *)b) - (*(int *)a);
}
int main(){
	char *a = malloc(200001 * sizeof(char));
	int *sla = malloc(200000 * sizeof(int));
    int streak = 0, var = 0, counter = 0;
	scanf("%s", a);
	for (int i = 0; i < strlen(a); ++i){
		if ((a[i] == 'A') && (streak == 0)) streak = 1;
		if(streak == 1) ++counter;
		if ((a[i] == 'Z') && (streak == 1)){;
            sla[var] = counter;
            ++var;
		}
	}
	qsort(sla,var + 1,sizeof(sla[0]),comp);
    printf("%d\n", sla[0]);
    free(a);
    free(sla);
	return 0;
}


#include <string.h>
#include <stdio.h>
int main(void){
  char n[200000];
  scanf("%s", n);
  int a, i, x=0, y, temp=0;
  a=strlen(n);
  for(i=0;i<a;i++){
    if(n[i]=='A'&&temp==0){
      x=i;
      temp++;
    }else if(n[i]=='Z'&&temp==1){
      y=i;
    }
  }
  printf("%d\n", y-x+1);
  return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
  char a[200001];
  scanf("%s",a);
  printf("%d",strchr(a,'Z')-strchr(a,'A')+1);
  return 0;
}


#include<stdio.h>
int main(void)
{
	char s[200001];
	long long int i,j;
	long long int num;
	long long int max = 0;
	scanf("%s", s);
	for (i = 0; s[i] != '\0'; i++)
	{
		if (s[i] == 'A')
		{
			num = 0;
			for (i=i;s[i] != '\0'; i++)
			{
				num++;
				if (num > max) max = num;
				if (s[i] == 'Z'&&s[i+1]!='Z') break;
			}
		}
	}
	printf("%lld\n", max);
	return 0;
}


#include <stdio.h>
#include <string.h>
int main() {
    char str[200010];
    scanf("%s",str);
    int k;
    k=strrchr(str,'Z')-strchr(str,'A');
    printf("%d\n",k+1);
    return 0;
}


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

int main(void)
{
    long int k;
    char a[200001];
    scanf("%s",a);
    k = strrchr(a, 'Z') - strchr(a, 'A');
    printf("%ld\n",k+1);
    return 0;
}


/*
  B - A to Z String
  <http://abc053.contest.atcoder.jp/tasks/abc053_b>
*/

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

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

  char s[200001];
  int len, end, start;
  int i;

  scanf("%s", s);
  len = strlen(s);

  i = 0;
  while( i < len ){
    if ( s[i] == 'A' ) {
      start = i;
      break;
    }
    i++;
  }

  i = len - 1;
  while( i >= 0 ){
    if( s[i] == 'Z' ){
      end = i;
      break;
    }
    i--;
  }

  printf("%d\n", end - (start-1) );

  return 0;
}


#include <stdio.h>
#define rep(i, n) for (i = 0; i < n; i++)

int main() {
    int c, a = -1, z = -1, i;
    for (i = 0; (c = getchar()) != '\n'; i++) {
        if (c == 'A' && a == -1) a = i;
        if (c == 'Z' && z < i) z = i;
    }
    printf("%d\n", z - a + 1);
    return 0;
}


Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

Constraints

2≤K≤2500

0≤S≤3K

K and S are integers.

Input

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

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2

X = 0, Y = 2, Z = 0

X = 2, Y = 0, Z = 0

X = 0, Y = 1, Z = 1

X = 1, Y = 0, Z = 1

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.


#include <stdio.h>

int main(void)
{
        int x,y,z,k,s,i,j,c=0;
        scanf("%d%d",&k,&s);
        for(i=0;i<k;i++){
                for(j=0;j<k;j++){
                        z=s-x-y;
                        if(z<=0 && z<=k) c++;
                }
        }
        printf("%d\n",c);
        return 0;
}


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

int main(){

  int k,s,x,y,z,cont=0;

  scanf("%d%d",&k,&s);

  for(int x=0;x<=k;x++){
    if((x+y+z)==s){
      cont++;
      printf("%d\n",cont);
        return 0;
    }
    for(int y=0;y<=k;y++){
      if((x+y+z)==s){
        cont++;
        printf("%d\n",cont);
          return 0;
      }
      for(int z=0;z<=k;z++){
          if((x+y+z)==s)
            cont++;
      }
    }
  }
  printf("%d\n",cont);

    return 0;
}


#include <stdio.h>
#include<stdlib.h>
int main()
{
    int k,s,x,y,z,n=0;
    scanf("%d%d",&k,&s);
    for(x=0;x<=s;x++)
    for(y=0;y<=s;y++)
    {
        z=s-x-y;
            if(x+y+z==s&&z>=0&&3*k>s)
            {
                n++;
                printf("x=%d,y=%d,z=%d\n",x,y,z);
            }
            if(3*k==s)
                {
                printf("1");
                exit(0);
                 }
    }
    printf("%d\n",n);
    return 0;
}


#include <stdio.h>

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

int zero(int a){
  if( a < 0)return 0;
  return a;
}
int main(int argc, char const *argv[]) {
  int k,s;
  int x,y,z;
  int i,j,l;
  int count=0;
  scanf("%d %d", &k,&s);

  for(i = zero(s - 2*k);i<=k;i++){
    //if( s - i > 2*k)continue;
    for(j = zero(s - k - i);j<= min(k, s-i) ;j++){
      //if( s - i - j > k)continue;
      for(l = 0;l<=min(k, s - i -j);l++){
        if(s == i + j + l){
          count++;
          break;
        }
      }
    }
  }
  printf("%d\n",count );
  return 0;
}


#include<stdio.h>

int main(){
    int K,S,t=0;
    scanf("%d%d",&K,&S);
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
           if(i+j<=S && i+j+K>=S){
               t++;
           }
        }

    }
    printf("%d",t);

    return 0;
}


#include<stdio.h>

int main(){
    int K,S,t=0;
    scanf("%d%d",&K,&S);
    for(int i=0;i<=K;i++){
        if(i+K+K>=S){
        for(int j=0;j<=K;j++){
            if(i+j+K>=S){
            for(int l=0;l<=K;l++){
                if(i+j+l == S){
                    t++;
                }
            }
            }
        }
        }
    }
    printf("%d",t);

    return 0;
}


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

int main(void){
    int K, S;
    scanf("%d %d", &K, &S);
    int x, y, z;
    int count = 0;
    for(x=0; x<=K; x++) {
        for(y=x; y<=K; y++) {
            for(z=y; z<=K; z++) {
                if(x + y + z == S) {
                    if(x==y && y==z) {
                        count++;
                    }
                    else if((x!=y || y!=z) && ((x==y && y!=z) || (y==z && x!=y))) {
                        count +=3;
                    }
                    else {
                        count +=6;
                    }
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}


#include <stdio.h>

int main()
{
	int k, s;
	int x, y, z;
	long long ans = 0;

	scanf("%d %d", &k, &s);

	for (x = 0; x <= k; x++) {
		for (y = 0; y <= k; y++) {
			z = s - (x + y);

			if (z >= 0 && z <= k) {
				ans++;
			}
		}
	}

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

	return 0;
}


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

	int K,S,X,Y,Z,count=0;
	scanf("%d%d",&K,&S);

	for(Z=0;Z<=K;Z++){

		for(Y=0;Y<=K;Y++){

		for(X=0;X<=K;X++){
			if(X+Y+Z==S){
		count++;
			}
		}
		}
	}

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

	return 0;
}


#include <stdio.h>

int main(void){
  int k, s;
  scanf("%d %d", &k, &s);
  int num = 0;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      for(int z = 0; z <= k; z++){
	if(x + y + z == s) num++;
      }
    }
  }
  printf("%d\n", num);
  return 0;
}


#include<stdio.h>

int main(void)
{
  int k = 0,s = 0,z = 0,count = 0;
  scanf("%d%d",&k,&s);
  for(int x = 0;x <= k;++x)
  {
    for(int y = 0;y <= k;++y)
    {
      z = s - x - y;
      if(0 <= z && z <= k)
      {
        count++;
      }
    }
  }
  printf("%d",count);
  return 0;
}


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

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

	int x,y,z;
	int pattern=0;

	for(x=k;x>0;x--){
		for(y=s-x;y>=0;y--){
			if(y>k){
				continue;
			}

			if(y>x){
				continue;
			}

			z = s-x-y;
			if(z>y){
				break;
			}

			if(x==y && y==z){
				pattern+=1;
			}else if(x!=y && y!=z && x!=z){
				pattern+=6;
			}else{
				pattern+=3;
			}

		}
	}

	printf("%d",pattern);

	return 0;
}


#include <stdio.h>

int ans;
int num;
int ret = 0;

int main() {
  scanf("%d %d", &ans, &num);
  int i, j, k;
  for (i = 0; i <= ans; i++) {
    if (i == num) {
      ret++;
      break;
    }
    for (j = 0; j <= ans; j++) {
      if (i + j == num) {
        ret++;
        break;
      }
      for (k = 0; k <= ans; k++) {
        if (i + j + k == num) {
          ret++;
          break;
        }
      }
    }
  }

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


#include <stdio.h>

int main(){

	short k;
	short s;
   int x;
   int y;
   int z;
  int g=0;
	scanf("%d%d",&k,&s);
	for(x=0;x<=k;x++){

		for(y=0;y<=k;y++){
			for(z=0;z<=k;z++){

				if(x+y+z==s){

					g++;
				}
				}

		}

	}

	printf("%d",g);

	return 0;
}


#include <stdio.h>

int main (void)
{
    int x,y,z;
    int k;
    int s;
    int c = 0;
    int sab;
    scanf("%d",&k);
    scanf("%d",&s);
    sab = s;
        for(x=0; x<k+1; x++){
            s = sab - x;
            for(y=0; y<k+1; y++){
                for(z=0; z<k+1; z++){
                    if(y+z == s){
                        c++;
                    }
                }
            }
        }
    printf("%d\n",c);
    return 0;
}


#include <stdio.h>

int main(void) {
	int k, s;
	int x, y, z;
	int counter = 0;
	scanf("%d %d", &k, &s);
	for (x=0; x<=k; x++) {
		if (!(x<=s)) break;
		for (y=0; y<=k; y++) {
			if (!(x+y<=s)) break;
			for (z=0; z<=k; z++) {
				if (!(x+y+z<=s)) break;
				if (x+y+z==s) counter++;
			}
		}
	}
	printf("%d\n", counter);

	return 0;
}


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

int main(){
	int K,S;
	int X,Y,Z;
	int count=0;

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

	for(X=0;X<=K;X++){
		for(Y=0;Y<=K;Y++){
			for(Z=0;Z<=K;Z++){
				if(X+Y+Z==S){
					count++;
				}
			}
		}
	}
	printf("%d\n",count);

	return 0;
}


Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

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

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO


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

char S[100000], s[4][10] = { "dream", "dreamer", "erase", "eraser" };

int hikaku(int n) {
	int i, j, len;

	for (i = 0; i < 4; i++) {
		len = strlen(s[i]);
		for (j = 1; j <= len; j++) {
			if (s[i][len - j] != S[n - j]) break;
		}
		if (j > len) {
			break;
		}
	}

	if (j > len) {
		return n - j + 1;
	}
	else {
		return -1;
	}
}

int main() {
	int len;

	scanf("%s", S);

	len = strlen(S);

	do {
		len = hikaku(len);
	} while (len != -1 && len != 0);

	if (len == 0) {
		printf("YES");
	}
	else {
		printf("NO");
	}

	return 0;
}


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

int main() {
  char *buf=(char*)malloc(sizeof(char) * 20000);

  scanf("%[^\n]", buf);
  char* cur = buf;
  int length = strlen(buf);

  char l1[] = "dream";
  char l2[] = "dreamer";
  char l3[] = "erase";
  char l4[] = "eraser";
  int a1 = 5;
  int a2 = 7;
  int a3 = 5;
  int a4 = 6;

  while (length > 0) {
    if (strstr(cur, l4) == cur) {
      length -= a4;
      if(length <= 0) {
        break;
      }
      cur = cur + a4;
    } else if (strstr(cur, l3) == cur) {
      length -= a3;
      if(length <= 0) {
        break;
      }
      cur = cur + a3;
    } else if (strstr(cur, "dreamerase") == cur) {
      length -= a1;
      if(length <= 0) {
        break;
      }
      cur = cur + a1;
    } else if (strstr(cur, l2) == cur) {
      length -= a2;
      if(length <= 0) {
        break;
      }
      cur = cur + a2;
    } else if (strstr(cur, l1) == cur) {
      length -= a1;
      if(length <= 0) {
        break;
      }
      cur = cur + a1;
    } else {
      break;
    }
  }

  if (length == 0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[100005];
    int i=0, ans=0;
    scanf("%s", s);
    while(strncmp(&s[i], "\0", 1)!=0)
    {
        if(strncmp(&s[i], &s[i+1], 0)!=0 && strncmp(&s[i+1], "\0", 0)!=0) ans++;
    }
    printf("%d",ans);
    return 0;
}

Score : 300 points

Problem Statement

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

1 ≦ |S| ≦ 10^5

Each character in S is B or W.

Input

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

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Sample Input 1

BBBWW

Sample Output 1

1

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.

In either way, Jiro's purpose can be achieved by placing one stone.

Sample Input 2

WWWWWW

Sample Output 2

0

If all stones are already of the same color, no new stone is necessary.

Sample Input 3

WBWBWBWBWB

Sample Output 3

9


#include<stdio.h>
#include<string.h>
char srx[100001];
int main()
{
    gets(srx);
    int i,zjq=0;
    for(i=1;i<strlen(srx);i++)
    if(srx[i]!=srx[i-1])
    zjq++;
    printf("%d\n",zjq);
    return 0;
}


#include <stdio.h>

int main(){
char s[100000];
scanf("%s", s);
int i=0, count=0;

while(s[i+1]!= NULL){
	if(s[i] != s[i+1]) count++;
	i++;
}
printf("%d\n", count);
return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
	int l,n;
	scanf("%d %d",&l,&n);
	char s[100][101];
	char tmp[101];
  	//**s=malloc(n*sizeof(char*));
	/*for(int i=0;i<n;i++){
		s[i]=malloc((l+1)*sizeof(char));
	}
	char *tmp;
  	tmp=malloc((l+1)*sizeof(char));*/
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(int j=1;j<n;j++){
		for(int i=0;i<=n-j-1;i++){
			if(strcmp(s[i],s[i+1])>0){
				strcpy(tmp,s[i]);
				strcpy(s[i],s[i+1]);
				strcpy(s[i+1],tmp);
			}
		}
	}

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

Score : 200 points

Problem Statement

Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L.

She will concatenate all of the strings in some order, to produce a long string.

Among all strings that she can produce in this way, find the lexicographically smallest one.

Here, a string s=s_1s_2s_3...s_n is lexicographically smaller than another string t=t_1t_2t_3...t_m if and only if one of the following holds:

There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i.

s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.

Constraints

1 ≦ N, L ≦ 100

For each i, the length of S_i equals L.

For each i, S_i consists of lowercase letters.

Input

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

N L
S_1
S_2
:
S_N

Output

Print the lexicographically smallest string that Iroha can produce.

Sample Input 1

3 3
dxx
axx
cxx

Sample Output 1

axxcxxdxx

The following order should be used: axx, cxx, dxx.


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

int main(int argc, char *argv[])
{
  int N, L;
  char **S;

  int i, j, k, ii;
  char *tmp;

  scanf("%d%d", &N, &L);
  S = (char **)malloc(sizeof(char *)*N);
  for( i=0; i<N; i++) {
    S[i] = (char *)malloc(sizeof(char)*(L+1));
    scanf("%s", S[i]);
  }

  for( i=N-1; i; i--) {
    for( j=0; j<i; j++) {
      for( k=0; k<L; k++) {
        if( strcmp(S[j], S[j+1]) > 0 ) {
          tmp = S[j];
          S[j] = S[j+1];
          S[j+1] = tmp;
          break;
        }
      }
      //for( ii=0; ii<N; ii++)
      //  printf("%s ", S[ii]);
      //printf("\n");
    }
  }

  for( ii=0; ii<N; ii++)
    printf("%s", S[ii]);
  printf("\n");

  return 0;
}


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

int main(){
  int n,l,i=0;
  scanf("%d %d",&n,&l);
  char s[n][l];
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  qsort(s,n,l,strcmp);
  printf("%s\n",s[0]);
}


#include <stdio.h>
#include<string.h>
int main()
{
    char str[100][100];int n,l;
    scanf("%d %d",&n,&l);
    for(int i=0;i<n;i++)
    {
        scanf("%s",str[i]);
        str[i][l]='\0';
    }
    for(int i=0;i<n-1;i++)
    for(int j=0;j<n-1-i;j++)
    {
        if(strcmp(str[j],str[j+1])>0)
        {
            char temp[100];strcpy(temp,str[j]);
            strcpy(str[j],str[j+1]);
            strcpy(str[j+1],temp);
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%s",str[i]);
    }

    return 0;
}


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

#define N 500

int main(void)
{
	char s[N][N],a[N];
	int n,l,i,j;
	scanf("%d%d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(strcmp(s[j-1],s[j])>0){
				strcpy(a,s[j-1]);
				strcpy(s[j-1],s[j]);
				strcpy(s[j],a);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");
	return 0;
}


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


#include <stdio.h>
#include <string.h>
int main(){
  int n,l;
  scanf("%d%d",&n,&l);
  char s[n][l+1];
  char temp[l+1];
  for(int i=0;i<n;i++)scanf("%s",&s[i]);
  for(int i=0;i<n-1;i++)for(int j=0;j<n-1;j++){
    if(0>strcmp(s[j],s[j+1])){
      strcpy(temp,s[j]);
      strcpy(s[j],s[j+1]);
      strcpy(s[j+1],temp);
    }
  }
  for(int i=0;i<n;i++)printf("%s",s[i]);
  return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,j,l;
    char s[101][101],temp[101];
    scanf("%d%d",&n,&l);
    for(i=0;i<n;i++)
    {
        scanf("%s",&s[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(strcmp(s[i],s[j])>=1)
            {
                strcpy(temp,s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j] , temp);
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%s",s[i]);
    }
    return 0 ;

}


#include<stdio.h>
int l;
int han(char* a,char* b){
  int i;
  for(i=0;i<l;i++){
    if(a[i]>b[i])return -1;
    if(a[i]<b[i])return 1;
  }
  return 0;
}

int main(){
  int n,j,i;scanf("%d%d",&n,&l);
  char s[100][101];
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  int ans[100];
  for(i=0;i<n;i++)ans[i]=i;
  for(i=0;i<n;i++){
    for(j=0;j<n;i++){
      if(han(s[ans[i]],s[ans[j]])==-1){
        int tmp=i;
        i=j;
        j=tmp;
      }
    }
  }
  for(i=0;i<n;i++)printf("%s",s[ans[i]]);
  return 0;
}


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

int main() {
    int l, n;
    char s[101][101], tmp[101];

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

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

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