TOE2 - Tic-Tac-Toe ( II )

In the game of tic-tac-toe, two players take turns marking squares of an initially empty 3 × 3 grid with either X’s or O’s. The first player always marks squares using X’s, whereas the second player always marks squares using O’s. If at any point during the game either player manages to mark three consecutive squares in a row, column, or diagonal with his/her symbol, the game terminates.

Given a board configuration, your goal is to determine whether the board configuration represents the possible final state of a valid tic-tac-toe game.

Input

The input test file will contain multiple cases. Each test case consists of a single line containing 9 characters, which represent the 9 squares of a tic-tac-toe grid, given one row at a time. Each character on the line will either be ‘X’, ‘O’ (the letter O), or ‘.’ (indicating an unfilled square). The end-of-file is marked by a single line containing the word “end”.

Output

For each input test case, write a single line containing either the word “valid” or “invalid” indicating whether the given board configuration is the final state of some possible tic-tac-toe game.

Example

Input:
XXXOO.XXX
XOXOXOXOX
OXOXOXOXO
XXOOOXXOX
XO.OX...X
.XXX.XOOO
OOXXXOOXO
end

Output:
invalid
valid
invalid
valid
valid
invalid
invalid

Added by:Camilo Andrés Varela León
Date:2006-12-14
Time limit:0.206s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Stanford Local 2006

hide comments
2014-07-23 19:55:25 Archit Jain
what make it different from TOE1???
final state when the whole grid is full a nd valid or is either won by any player
2014-07-23 18:05:22 Mukul Gupta
should i just print the answer or should i store it somewhere?
2014-07-16 11:27:01 broya
Finally ac after so many tries...:-)
2014-05-21 21:55:14 Manish Jindal
Read statement carefully.. (final state of some possible tic-tac-toe)
2013-05-24 18:18:27 devu
Exhausted in Making it Acc.... Phew...Worst Code Ever Written
2013-03-23 15:49:01 Vibhor Gaur
just a piece of cake........!!!!!!!!
2013-03-22 17:14:24 ahmed ashry
XXOOOXXOX why this case is valid?


Last edit: 2013-03-22 17:43:53
2012-11-28 16:11:42 strings
invalid it is @AC Srinivas

@ajax- maybe this helps:
XX.OOO..X valid
X.OOX...X valid
XXO.XOX.O invalid
just read the problem carefully

Last edit: 2012-11-28 16:12:40
2012-08-18 04:34:04 AC Srinivas
...
.X.
.O.
is this invalid since it is not the final state??

Last edit: 2012-08-18 04:34:58
2012-08-18 03:58:34 AC Srinivas
how is this question different from TOE1?

Last edit: 2012-08-18 04:34:46
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.