Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!
ALGOR Contest: Round #2
Problem B · 100 points · ICPC rules

~/algor $ cat contests/round-2/B

B. Nearest palindrome

1000 ms 64 MB

A number that reads the same from left to right and from right to left is called a palindrome (for example, 7, 44, 12321). An integer n is given. Find the smallest palindrome not less than n.

Nearest palindrome: from n = 100 to the palindrome 101

Input

One integer n.

Output

One integer — the smallest palindrome equal to or greater than n.

Note

1 ≤ n ≤ 1 000 000

Examples

Input #1
123
Output #1
131
Input #2
7
Output #2
7

Sign in to submit a solution

Signing up is free and takes a minute.