Rune of 1379 pineapple II

Source: Internet
Author: User
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") ;}
     
    
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.