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
Daniel Carvalho: 2015-02-18 00:03:57

@Mitch Schwartz: Thanks for the clarification. I might have read something like "[...]the first turn in which a move guarantees[...]", instead of what's actually written.

Mitch Schwartz: 2015-02-17 04:03:29

@Daniel Carvalho: 4 is a move (digit) that Nikifor can choose at the beginning in order to have a guaranteed win. The wording is basically ok, and you just interpreted it wrong because you didn't understand the underlying concepts. ("which guarantees victory" has to modify "move" and not "turn" -- it's the only sensible way to parse that sentence.)

Daniel Carvalho: 2015-02-17 03:00:00

I need a clarification due to ambiguity of problem. For the given example:
Turn - Player - Number (operation)
1 - Nik - 10 (14-4)
2 - Trof - 9 (10-1)
3 - Nik - 0 (9-9)
So Nik wins in 3 turns, and the turn which guarantees victory for him is 2. Can someone explain where does the 4 come from?

Mitch Schwartz: 2014-01-24 18:52:29

19 18 bytes is possible in AWK.

Last edit: 2014-01-24 18:57:37

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