Description
Mr. l recently played pineapple II with his sleeping buddy. He wanted to collect a prop in it: Rune.
The rune has a level. Assume It is 1-5;
There is a rule that three I-level runtimes can synthesize an I + 1 level runner-up (Level 5 can no longer be merged)
What Xiao L does is: he uses N numbers of different levels in different occupations to paint monsters of different levels. Some of them have some runtimes, now he wants to transfer all these characters to an account and then merge them slowly;
There is another strange thing: When I use different numbers to brush, the same rune on the same number can only have one, maybe 0.
Assume that all N accounts are numbered 1-N, and their logon order is sequential according to 1-N;
The merging rule is as follows: if there are only one token at the same level, only one token is retained. If there are three identical ones, the token is merged once;
He will synthesize the token every time he transfers the token;
Now the question is: If he can collect all types of runtimes, will it be completed when he first transfers the number?
-
Input
-
the first line of the input contains an integer N, indicating that there are n numbers. N cannot exceed 10000.
each row of N rows contains five integers, indicating the number of bij (0 <= BIJ) in the J rune on the I.
-
Output
-
if it is possible to collect the data, output the minimum number.
if you cannot collect all data, output-1.
-
Sample Input
-
3
-
0 0 1 1 1
-
1 1 0 0 0
-
1 1 0 1 1
-
Sample output
-
2
-
Prompt
-
binary
simulated questions
# include
# include
using namespace STD; int main () {int A [5]; int temp [5]; int number; int count; int I, T, J; CIN> Number; for (I = 0; I <5; I ++) {CIN> A [I] ;}for (t = 1; t
temp [I]; for (j = 4; j> 0; j --) {A [J] = A [J] + temp [J]; if (a [J] = 4) {A [J-1] ++; A [J] = 1 ;}} A [0] + = temp [0]; for (I = 0; I <5; I ++) {if (a [I]> = 1) Count ++; If (COUNT = 5) break;} If (COUNT = 5) {printf ("% d \ n", t + 1); break;} else {continue;} If (t = number) printf ("-1 \ n") ;}