Problem:
Score : 200 points

Problem Statement

Kurohashi has never participated in AtCoder Beginner Contest (ABC).

The next ABC to be held is ABC N (the N-th ABC ever held).
Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.

What is the earliest ABC where Kurohashi can make his debut?

Constraints

100 \leq N \leq 999

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If the earliest ABC where Kurohashi can make his debut is ABC n, print n.

Sample Input 1

111

Sample Output 1

111

The next ABC to be held is ABC 111, where Kurohashi can make his debut.

Sample Input 2

112

Sample Output 2

222

The next ABC to be held is ABC 112, which means Kurohashi can no longer participate in ABC 111.
Among the ABCs where Kurohashi can make his debut, the earliest one is ABC 222.

Sample Input 3

750

Sample Output 3

777

Solution in Scala (2.11.7) (judge verdict: Runtime Error)

object Main{
	def main(args:Array[String]):Unit={
      var input = readLine
      var record:Map[Int,Int] = Map()
      for(i <- input){
        var tmp = i.toString.toInt
        var r = record.getOrElse(tmp,0)
        r+=1
        record+=(tmp -> r)
      }
      var keys = record.keySet.toArray.sorted.reverse
      var flag = true
      var res = ""
      if(keys.length==1){
        for(i <- 0 until 3) res += keys(0).toString
        flag = false
      }
      for(k <- 0 until keys.length if flag){
        if(k==0 && input.charAt(0).toString.toInt==keys(k)){
          for(i <- 0 until 3) res += keys(0).toString
          flag = false
        }
        if(keys(k)==input.charAt(0).toString.toInt){
          for(i <- 0 until 3) res += keys(k-1).toString
          flag = false
        }
      }
      println(res)
      
    }
}