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 Scala (2.11.7) (judge verdict: Runtime Error)

import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  private[this] val S = "0" + in.next()


  //
  // a は bに含まれているか
  def contain(a: String, b: String): Boolean = {
    val B = 5570293
    val h = 1e9.toLong

    val al = a.length; val bl = b.length
    if (al > bl)
      return false

    // B の al 乗を計算
    var t = 1L
    for (_ <- 1 to al) {
      t *= B
      t %= h
    }

    // aとbの最初のal文字に関するハッシュ値を計算
    var ah = 0L; var bh = 0L
    for (i <- 0 until al)
      ah = (ah * B + a(i).toLong) % h
    for (i <- 0 until al)
      bh = (bh * B + b(i).toLong) % h

    // bの場所を1つずつ進めながらハッシュ値をチェック
    for (i <- 0 to bl-al) {
      if (ah == bh && a == b.substring(i, i+al))
        return true
      if (i + al < bl) {
        bh *= B
        bh %= h
        bh += b(i+al).toLong - b(i).toLong * t
        if(bh < 0)
          bh += h * 1000
        bh %= h
      }
    }

    false
  }


  private[this] def check(end: Int, begin: Int): Boolean = {
    val a = S.substring(begin, end+1)
    val b = S.substring(end+1, N+1)

    contain(a, b)
  }

  // 条件を満たす最大の値を返す
  private[this] def binarySearch(min: Int, max: Int, begin: Int): Int = {
    val mid: Int = (max + min) / 2
      (max - min) match{
      case 0 | 1 =>
        check(max, begin) match{
          case true  => max
          case false => min
        }
      case _ =>
        (check(mid, begin)) match{
          case true  => binarySearch(mid, max, begin)
          case false => binarySearch(min, mid, begin)
        }
    }
  }



  private[this] var ans = 0
  for (i <- 1 to N-1) {
    if (check(i, i)) {
      val tmp = binarySearch(i, i + (N-i) / 2, i) - (i-1)
      ans = Math.max(ans, tmp)
    }
  }
  println(ans)
}


class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}