Skip to main content
Back to problems
Codeforces
Easy
Math
Number Theory
Lucky Year

Find the first year strictly greater than a given year whose digits are all different.

Acceptance 0%
Problem Statement

You are given a year yy. Your task is to find the smallest year greater than yy such that all digits in the year are pairwise distinct.

A year is called lucky if no digit appears more than once in its decimal representation. Starting from y+1y+1, check years in increasing order until you find the first lucky one.

Input Format

A single integer yy (1y1091 \le y \le 10^9).

Output Format

Print the minimum year strictly greater than yy whose decimal digits are all distinct.

Constraints

  • 1y1091 \le y \le 10^9
  • The answer always exists within the reasonable range for the problem setting.
Examples
Sample cases returned by the problem API.

Example 1

Input

1987

Output

2013

Explanation

1988, 1989, 1990, ..., 2012 all contain repeated digits. The first year after 1987 with all distinct digits is 2013.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.