CF65B.Harry Potter and the History of Magic

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.

So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.

Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 20112011 , or strictly before than 10001000 . To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.

输入格式

The first input line contains an integer nn ( 1<=n<=10001<=n<=1000 ). It represents the number of dates in Harry's notes. Next nn lines contain the actual dates y1y_{1} , y2y_{2} , ..., yny_{n} , each line contains a date. Each date is a four-digit integer ( 1000<=yi<=99991000<=y_{i}<=9999 ).

输出格式

Print nn numbers z1z_{1} , z2z_{2} , ..., znz_{n} ( 1000<=zi<=20111000<=z_{i}<=2011 ). They are Ron's resulting dates. Print each number on a single line. Numbers ziz_{i} must form the non-decreasing sequence. Each number ziz_{i} should differ from the corresponding date yiy_{i} in no more than one digit. It is not allowed to change the first digit of a number into 00 . If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).

输入输出样例

  • 输入#1

    3
    1875
    1936
    1721
    

    输出#1

    1835
    1836
    1921
    
  • 输入#2

    4
    9999
    2000
    3000
    3011
    

    输出#2

    1999
    2000
    2000
    2011
    
  • 输入#3

    3
    1999
    5055
    2000
    

    输出#3

    No solution
    
首页