NGM - A Game with Numbers

no tags 

Nikifor and Trofim play the following game: they write some positive integer smaller than 2,000,000,000 and take turns one after another. Nikifor is the first to make a move. The turn is made by the following rule: from the written integer any non-zero digit is subtracted, and the new integer replaces the old one on the desk. For example for integer 40534, the next move can be: 40530, 40531 or 40529. The winner is the player who writes zero on the desk.

Write a program to decide who will win if both players do their best.

Input

The input contains the positive integer from which the game is started.

Output

In the first line you must write 1 if Nikifor wins and 2 otherwise. If Nikifor wins then in the second line you must output the move in the first turn which guarantees victory for him. If there are many such moves then output any of them.

Example

Input:
14

Output:
1
4

Author: Filimonenkov D.O.


hide comments
divyaprakash18: 2016-05-05 14:28:40

Whatta question !! Understand d question language and its a few lines code !! Really didn't thought it wud b this easy !!

lalit_nit: 2016-03-20 05:32:18

Finally Cleared from Todo list after 1 month ... Easy logic

try2catch: 2016-02-11 14:13:56

I didn't understand the language of the question. A non-zero digit mean <=9 .

Pranay Kumar: 2016-01-30 07:19:29

" If Nikifor wins then in the second line you must output the move in the first turn which guarantees victory for him" This line took away even the little bit of thinking from this question...

sharath_111: 2016-01-27 21:15:20

good logic,comments spoil ur thinking ability,don't read them...easy AC :)

uzumaki_75: 2016-01-15 17:55:29

AC in one go :)

dokz: 2016-01-06 06:51:43

Got WA at first, because I was outputing the first winning move for both players. Note that if player 2 is a winner, then you don't need output anything except for "2".

Last edit: 2016-01-06 06:51:52
akshayvenkat: 2015-12-25 07:30:31

Did the mistake of reading comments before thinking hard.

key part of the question is , "subtracting a non zero DIGIT".. So the maximum number that can be subtracted , is 9.

So if Nikifor arrives at a multiple of 10 integer after his first move, Trofim can only end up at a (multiple of 10 + 1) integer however hard he tries. Great logic (y) :)

Junaid: 2015-12-14 10:45:36

extremely easy problem ...AC in first attempt...;)

sumit suthar: 2015-11-14 06:55:30

Take it eazy. :)


Added by:Roman Sol
Date:2006-05-05
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ZCon 2007