QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#22652. Morning Exercises

İstatistikler

Each morning, Farmer John leads his cows outside the barn for their morning calisthenics (fit cows give more milk). The cows are required to arrange themselves into two side-by-side lines of the same length. FJ has already set out a $2 x N$ ($1 \le N \le 100$) strip of pasture on which he wishes to conduct these exercises. Think of this strip as composed of $2N$ grid squares. Just when he thought everything was ready, he realized that he had overlooked the trees that grew in some of these squares. Of course, cows cannot stand on top of trees.

It is important for the purposes of the exercise that the cows be grouped tightly together, so FJ can't use other parts of the pasture. He has no choice but to split the cows into potentially multiple 2 x [something] groups and conduct the exercises for one group at a time. FJ likes conducting these exercises on larger groups of cows. Therefore, he wants to find the maximum number of cows he can take out into the pasture at once, while keeping in mind that the cows must occupy a contiguous $2 x K$ sub-strip ($K \le N$).

Input

  • Line 1: An integer, $N$
  • Lines $1..N+1$: Each line contains two space-separated integers that describe one 1 x 2 strip of pasture. A square has a 1 if there is a tree in that square and has a 0 if there is not. The sample input should make this clear.

Output

  • Line 1: An integer representing the number of cows that can participate in the exercise at once.

Examples

Input 1

7
0 0
1 0
1 1
0 0
0 0
0 0
0 1

Output 1

6

Input Details

A $2x7$ strip with four trees is specified.

Output Details

The biggest contiguous sub-strip that is free of trees is the $2x3$ one, which can hold $2*3 = 6$ cows.

Problem credits: Percy Liang, 2004

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.