QOJ.ac

QOJ

Limite de temps : 0.5 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#16942. Staircase for Olympiad Participants

Statistiques

At the Sirius Educational Center, students use various staircases for gathering and informal communication. The number of participants in the informatics olympiad significantly exceeds the number of participants in any other educational program, and there are no suitable staircases for them among the existing ones. Therefore, the facility management team decided to build a new staircase using a special template.

The template is a table with $h$ rows and $w$ columns, numbered from top to bottom and from left to right, respectively. Each cell of the table contains a number — either zero or one. A staircase can only be made from those cells of the table that contain a one.

The resulting staircase is formed by a set of cells containing ones that are located in several consecutive rows of the table. The set of selected cells in each row of the staircase must be a continuous segment. Furthermore, in each subsequent row included in the staircase, there must be no fewer cells selected than in the previous row, which is located directly above it, and the leftmost selected cells in each row must be located in the same column.

Below is an example of a staircase.

Find the maximum number of cells that form a staircase in the given table.

Input

The first line of the input contains two integers $h$ and $w$ ($1 \le h, w \le 2 \cdot 10^5$, $h \cdot w \le 4 \cdot 10^6$) — the number of rows and columns of the table, respectively.

Each of the following $h$ rows contains $w$ characters, each of which is 0 or 1 — the numbers written in the cells of the table.

Output

Output a single integer — the maximum number of cells that form a staircase.

Subtasks

Subtask Points Constraints Required Subtasks
1 25 $h, w \le 50$ -
2 25 $h, w \le 400$ 1
3 25 $h \cdot w \le 200\,000$ 1, 2
4 25 - 1, 2, 3

Examples

Input 1

6 4
0011
1101
0111
1110
0111
0100

Output 1

8

Note

The figure below shows the drawing for the first example. The staircase consisting of the maximum possible number of table cells is marked in gray.

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.