Plus One

Practice this coding question on Coding Gurukul.

Problem statement

An archive counter stores a positive integer as separate decimal digit cells, with the most significant digit first. After the next document arrives, the counter must advance by one even when the value is too large for a built-in integer type. Your task Add one to the number represented by the digit array and output the resulting digits from most significant to least significant. Important details Carry may pass through several trailing nines. If every digit is nine, the result needs one additional cell. Preserve internal zeroes and do not interpret the input as n separate counters. Worked example The cells 4, 9, 9 represent 499. Adding one gives 500, so the new cells are 5, 0, 0.

Input format

The first line contains n. The next line contains n space-separated integers; for n = 0 this line may be empty.

Output format

Print the resulting digit cells separated by spaces.

Constraints

1 <= n <= 100; digits are 0 through 9; the first digit is nonzero.

Sample input

3
4 9 9

Sample output

5 0 0

Sign in to run or submit a solution in C++, Java or Python.