You are playing a puzzle. The puzzle uses an upright board of H rows by 5 columns of cells, as in the figure below. Each cell holds one stone engraved with a digit from 1 to 9. When three or more stones in horizontally adjacent cells carry the same digit, those stones disappear. If stones sit above a cell whose stone disappeared, they drop down and fill the vacancy.

The puzzle proceeds in the following steps.
The score of the puzzle is the sum of the digits on the stones that disappeared.
Write a program that computes the score of a given placement of stones.

The input consists of several datasets. Each dataset has the following form.
Board height H
Stone placement of row 1
Stone placement of row 2
...
Stone placement of row H
The first line gives the height H (1≤H≤10) of the puzzle board. The next H lines give the stone placement of each row, from the top row down. A placement is five digits from 1 to 9 separated by a space, engraved on the five stones of that row in the same order.
The input ends with a line containing a single zero.
For each dataset, output the score on one line. An output line contains no characters other than the digits of the score.