Under construction

Still being built. Things may change

Team Tic Tac Toe

Interview

Time limit2sMemory limit512 MB

Summary
Given a filled 3x3 board of letters, count single cows that own a full line and two-cow teams that together own a line with both letters present.
Level

Easy3 of 10

Topics
Brute force, Implementation, Hash map, Array
Solved
No attempts yet

Problem

Farmer John owns 26 cows. Their names all start with different letters of the alphabet, so Farmer John refers to each cow by her first initial, a character in the range A…ZA \ldots Z.

The cows have recently become fascinated by tic-tac-toe. They dislike that only two cows can play at a time, so they invented a variant where many cows play at once. The board is 3×33 \times 3, just like regular tic-tac-toe, but instead of Xs and Os every square holds a single character in the range A…ZA \ldots Z: the initial of the cow who claims that square.

The cows fill in all nine squares and then get confused about who won. As in regular tic-tac-toe, a cow who has claimed an entire row, column, or diagonal by herself can claim victory alone. Since that looks unlikely with so many players, the cows also allow teams of two. A team of two cows can claim victory if some row, column, or diagonal consists only of characters belonging to those two cows, and the characters of both cows appear in that line.

Count how many individual cows can claim victory and how many two-cow teams can claim victory. The same square may be used in several different claims to victory.

Input

The input consists of three lines, each of which is three characters in the range A…ZA \ldots Z.

Output

Output two lines. On the first line, print the number of individual cows who can claim victory. On the second line, print the number of two-cow teams that can claim victory.

Note

In the first example no single cow can claim victory. Cows C and X team up and win on the diagonal running from the top left to the bottom right, whose letters are C, X, C. Cows X and O team up and win on the middle row.

There are two diagonals, one from the top left to the bottom right and one from the top right to the bottom left. That gives 8 lines to check: 3 rows, 3 columns and 2 diagonals.

Examples3

  1. Example 1

    Input
    COW
    XXO
    ABC
    
    Expected output
    0
    2
    
  2. Example 2

    Input
    ZZZ
    ZZZ
    ZZZ
    
    Expected output
    1
    0
    
  3. Example 3

    Input
    AAA
    BBB
    CCC
    
    Expected output
    3
    0