Problem list
Log in
#icpc00373 · ICPC GCPC 2023

Adolescent Architecture 2

Diamond III 2.0 s 2048 MB

Three years ago, you helped little Peter stack his toy blocks into a tower. Since then, he has extended his collection of toy blocks, which now features the following base shapes:

  • circle $a$ – a circle of radius $a$;
  • square $a$ – a square with side length $a$;
  • triangle $a$ – an equilateral triangle with side length $a$.

Here, $a$ may be any positive integer. The top shapes of each block are the same as their bottom shapes, so the blocks are cuboids, cylinders, and triangular prisms, respectively. Peter has an infinite supply of blocks of each shape and size.

Peter and his friend Amy are playing a two-player game, where the blocks need to be stacked on top of each other. Initially, some blocks are already placed on the floor. In each move, the current player must take a toy block from the infinite supply and put it on top of one of the existing stacks of blocks. The block may be rotated around its vertical axis before placing it. The outline of the new block must be strictly within the outline of the old block; the outlines are not allowed to touch. The first player who is unable to make a move loses the game.

Given the initial configuration, determine the number of winning moves for the first player.

Input

The input consists of:

  • One line with an integer $n$ ($1 \le n \le 1000$), the number of initial stacks.
  • $n$ lines, each with a string $s$ ($s$ is one of "circle", "square" or "triangle") and an integer $a$ ($1 \le a \le 10^9$), giving the topmost blocks of the initial stacks as described above.

Output

Output the number of winning moves for the first player.

Example 1

Input
2
circle 2
triangle 2
Output
2

Example 2

Input
2
circle 1
circle 2
Output
3

Example 3

Input
5
circle 123
triangle 456
square 789
square 789
triangle 555
Output
7

Example 4

Input
3
circle 299303201
square 79724391
triangle 437068198
Output
3

Example 5

Input
3
square 539715887
circle 518408351
triangle 348712924
Output
0
Source
ICPC GCPC 2023
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code