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
heyviv: 2020-06-03 18:16:12

number deducted cannot be more than 9

this_variable: 2020-05-27 20:43:58

Try for small test cases eg. from 2-3 random numbers between [10-30] and also don't forget to test for numbers divisible by 10 and also pay some atention to the example testcase why instead of having a option of 9 he deleted 4...u will get it :)

sakibmalik: 2020-05-27 12:14:39

Remember, You can subtract ANY digit from the no.,
I wasted lots of time thinking we can subtract digits only from given no, and that gave TLE after few cases using recursion.

akarsh_raj: 2020-04-22 08:42:05

basic aptitude question, crack the logic and it has a single line solution.

blackhat_130: 2020-04-05 00:27:40

It requires some time to think if you want it to be get done in o(1).

shouravahmed: 2020-03-29 16:57:47

very nice prob.. ❤️

mrmajumder: 2020-02-01 12:49:26

O(1) solution
Takes literally 0.0 sec to execute :)

tarun_28: 2019-12-03 16:22:07

5 lines of code in python :)

sanket17: 2019-07-07 14:11:17

use string in c++ otherwise python is always there

upendra17: 2019-06-25 09:41:07

Game of Nim


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