QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17943. Triangular Chocolate Packaging (Sweet)

Statistics

Coco's chocolate shop is planning to sell a special Valentine's Day product consisting of chocolates shaped like three regular hexagons joined together in a triangle. Coco wants to pack these chocolates into a triangular mold made of $\frac{N(N+1)}{2}$ regular hexagons of the same size, filling it completely. To make it look more attractive, she decided to wrap the chocolates pointing upward in red and the chocolates pointing downward in blue. Once the product is packaged, one can only see whether each individual hexagon is red or blue from the outside, but it is impossible to tell which cells belong to the same chocolate piece.

Hanbyeol, who visited Coco's shop, was looking at the finished products and noticed one that appeared to contain chocolates of a different shape. Let's help Hanbyeol find out which product is incorrect and inform Coco.

Input

The first line contains the side length $N$ of the triangular mold. $(1 \le N \le 5\,000)$

The next $N$ lines contain the arrangement of red and blue hexagons without spaces. Red is represented by R and blue by B. The $i$-th line contains the characters corresponding to the $i$ hexagons in that row, given in order from left to right. $(1 \le i \le N)$

Output

If the given arrangement can be divided into upward-pointing red triangles and downward-pointing blue triangles without any gaps or overlaps, output 1; otherwise, output 0 on a single line.

Examples

Input 1

2
R
RR

Output 1

1

Input 2

4
R
RR
RBR
RRRR

Output 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.