Problem:
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

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>

#undef DEBUG

#define max(a, b)   ((a)>(b)? (a):(b))
#define min(a, b)   ((a)<(b)? (a):(b))

int
z_algo(char *S, int N, int *A)
{
    int i, j, k;
    int ret=0;

    A[0] = N;
    i=1;
    while(i<N) {
        j = 0;
        while (S[j]==S[i+j]) {
            j++;
        }
        A[i] = j;
        if (ret<j && i+1>j)
            ret = j;
#ifdef DEBUG
        printf("%s %s %d A[%d] = %d\n", S, S+i, j, i, j);
#endif
        if (j>0) {
            k=1;
#ifdef DEBUG
            printf("i %d j %d k %d\n", i, j, k);
#endif            
            while(i+k<N && k+A[k]<j) {
#ifdef DEBUG
                printf("## i %d j %d k %d A[%d] = A[%d] = %d\n", i, j, k, i+k, k, A[k]);
#endif                
                A[i+k] = A[k];
                if (ret<A[k] && i+k+1>A[k])
                    ret = A[k];
                k++;
            }
            i+=k;
            j-=k;
        }
        else {
            i++;
        }
    }
#ifdef DEBUG
    for (i=0; i<N; i++) {
        printf("%d ", A[i]);
    }
    printf("\n");
#endif    
        
    return ret;
}

int
main(int argc, char *argv[])
{
    int N;
    char S[5001];
    int len=0;
    int i;
    int A[5000];

    scanf("%d", &N);
    scanf("%s", S);
    
    for (i=0; i<N; i++) {
        len = max(z_algo(S+i, N-i, A), len);
        if(len==(N-i)/2)
            break;
    }
    printf("%d\n", len);
    
    return 0;
}