CCC '13 S1 - From 1987 to 2013

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
Canadian Computing Competition: 2013 Stage 1, Junior #3, Senior #1

You might be surprised to know that 2013 is the first year since 1987 with distinct digits. The years 2013, 2015, 2016, 2017, 2018, 2019 each have distinct digits. 2012 does not have distinct digits, since the digit 2 is repeated.

Given a year, what is the next year with distinct digits?

Input Specification

The input consists of one integer Y (0 \le Y \le 10\,000), representing the starting year.

Output Specification

The output will be the single integer D, which is the next year after Y with distinct digits.

Sample Input 1


Output for Sample Input 1


Sample Input 2


Output for Sample Input 2



  • 0
    Alex_S  commented on Sept. 10, 2020, 6:10 p.m.

    Do not forget to take in consideration top range of the input. For example: 9999