This page is still under construction.

Parts of this page are still being built. What you see may change.

XO

Interview

Time limit1sMemory limit1024 MB

Summary
Given the first N moves of a tic-tac-toe game, decide whether X or O moves next, whether X or O has won, or whether the game is a draw.
Level

Easy2 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

Križić-kružić is a game for two players. For those who do not know the rules, here is a short summary. Two players fill a table with nine empty cells arranged in three rows and three columns. Player X writes the letter X and player O writes the letter O. Starting with X, the players take turns choosing an empty cell and writing their mark in it. A player wins by writing three of their marks in a line: a row, a column, the main diagonal, or the anti-diagonal. The game ends at that moment. If no one manages this and all cells are filled, the game ends with no winner. For example, the figure shows seven moves that led to a win for the first player.

You are given a real game that has been played for N moves. Write a program that determines what follows the N-th move. The possible answers are:

  1. Player X continues the game by placing their mark in an empty cell.
  2. Player O continues the game by placing their mark in an empty cell.
  3. The game ended with a win for player X.
  4. The game ended with a win for player O.
  5. The game ended with no winner because no empty cells remain.

Input

The first line contains an integer N (0 ≤ N ≤ 9), the number of moves played.

Each of the next N lines contains a natural number P (1 ≤ P ≤ 9), the cell number where the player on turn wrote their mark. The top left cell is numbered 1 and the bottom right cell is numbered 9. See the figure in the problem statement.

Output

Print one natural number from 1 to 5 on a single line, the number of the possibility from the problem statement.

Hint

After three moves, it is player O's turn. After seven moves, the game ended with a win for player X. After nine moves, no empty cells remain and no one won, so the game ended with no winner.

Examples3

  1. Example 1

    Input
    3
    3
    1
    7
    
    Expected output
    2
    
  2. Example 2

    Input
    7
    3
    1
    7
    5
    9
    6
    8
    
    Expected output
    3
    
  3. Example 3

    Input
    9
    1
    2
    3
    4
    7
    5
    8
    9
    6
    
    Expected output
    5