1040 - Tetris Battle   

Description

 

Tetris Battle is a hot and funny game on the pastedGraphic.pdf that you can train your skill and challenge your friend. 

At the last of the story, you will receive the name that “God of Tetris” and everybody’s respecting. But this problem is not about Tetris Battle. 

We will talk the other funny game, “Step Mania”!

pastedGraphic_1.pdf

Step Mania” is an engine of the music game.

For each meter, there is four floating up arrows, and we can use keyboard to “hit” it on fixed positions. And there is a system for rewarding, we called “Combo” if you hit arrows in continued meter and get extra score.

NOW there is a new “Step Mania EX” had at most 10 arrows you should hit for each meter.(It’s OK because the keyboard has 108 keys and you have ten fingers.)

You are an extreme player of the “Step Mania” and you can hit every arrow in every meter!

But your keyboard is so bad that is unlike your skill, it cannot detect the continued hits on same key.

Now there is a score for a song in “Step Mania EX”, what score you will have?


PS1. You have gotten one point if you hit an arrow and (#theNumberOfCombo-1) for bonus.

PS2. If the computer does not detect any arrow in a meter, the number of combo will be reset.

PS3. Though you will get higher score if you do not hit some arrow, you still hit EVERY arrow  because the spirit of “Step Mania” tell you not to do it!

PS4. At fact, it not yet sells.

PS5. You can buy the keyboard called “RealForce” and you can win the game easily though it’s  very expensive.


HINT: Each arrow hiting will have its bonus score.

For sample data,

you will get score as following:

1 0 0 1

0 2 2 0

0 X 0 1

1 X 1 0

 

HINT2:

If there a meter contains no arrow, you will not hit any key and the number of combos will be same such that it can be higher when you have a nice hiting in next meter.

 

Input

 There is multiple dataset, for each data:

The first line contains two integers n, m , which mean the number of meters and the number of the arrow type. (0 < n ≤ 105, 0 < m ≤ 10)

The line 2 to the line n+1, each line has m numbers split by space means the arrows if the number is 1.


Output

Print out a line contains the number of the score for each dataset.


 

Sample Input  Download

Sample Output  Download

Tags




Discuss