Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

1419. A Game with Numbers

Problem code: NGM

Nikifor and Trofim play the following game: they write some integer smaller then 2000000000 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 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.


Added by:Roman Sol
Date:2006-05-05
Time limit:1s
Source limit:50000B
Languages:All except: ERL JS PERL 6
Resource:ZCon 2007

hide comments
2012-03-05 10:40:53 Jason Shi
How to do it in the best way?
2012-03-03 16:33:11 JVRohit
interesting indeed
2011-08-28 11:26:34 Michael T
@Unnati: Basically limits are parts of the problems.

Last edit: 2011-08-29 14:41:22
2011-08-28 07:15:39 Unnati Gupta
I got "time limit exceed"
but my program is correct..
2011-06-13 20:57:35 Kunal Kapadia
Juzz read the Game Theory Tutorial on Topcoder :)

Last edit: 2011-06-13 20:58:04
2011-05-26 16:36:48 simon
way too easy
2011-05-15 17:23:40 forever@lone
very easy problem should be move to tutorial section
2011-04-13 16:01:08 wu xingbo
see some game theory and back-ward induction
2011-03-27 06:23:14 bashrc is back
Is 0 a valid move?
2011-03-17 15:21:46 Jason
very interesting...
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.