Sherlock, Watson and Ticket

0

0 votes
Medium
Problem

Sherlock and Watson are both best friend. They are fond of collecting lucky tickets, every ticket have 6 digits PNR number. A ticket is lucky if the sum of first three digits of PNR is equal to sum of last three digits of PNR.

For example, PNR no 162612 is lucky because sum of 1+6+2=9, and 6+1+2=9.

Since the PNR number of the ticket wasn’t lucky, Sherlock and Watson needs your help to find the next lucky ticket number.

For example, if Sherlock’s ticket number is 165901, then the next lucky ticket number is 165903.

Given Sherlock’s current ticket number, find and print the next lucky ticket number.

Input Format

  • The first line contains an integer, x, denoting the 6 digit number on the ticket.

Constraints

  • 100000<= x <=1000000-2

Output Format

  • For the given input find and print the next lucky ticket number.
Time Limit: 10
Memory Limit: 256
Source Limit:
Editor Image

?