Chef and calculation

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Every Friday Chef and his N  1 friends go for a party. At these parties, they play board games. This Friday, they are playing a game named "Boats! Boats! Boats!". In this game players have to transport cookies between Venice and Constantinople. Each player has a personal storage. The players are numbered from 1 to N, Chef is numbered 1. Rules for determining a winner are very difficult, therefore Chef asks you to write a program, which will determine who is a winner.
There are 6 types of cookies. For each cookie in the storage player gets 1 point. Also player gets additional points if he packs his cookies in some boxes as follows:
 A box containing 4 different types of cookies fetches 1 additional point.
 A box containing 5 different types of cookies fetches 2 additional points.
 A box containing 6 different types of cookies fetches 4 additional points.
For each player, you know the number of cookies in his storage (denoted by c[i]), also the types of cookies in the storage given denoted by type[i][j].
Your task is to determine the winner of this game. Output "tie" if there are two or more players with same maximum score, "chef" if only Chef has a maximum score, winner's index in all other cases.
Input
The first line of input contains a single integer T denoting the number of test cases. This will be followed by T test cases.
The first line of each test case contains an integer N denoting the number of players.
The second line of each test case contains an integer c[i] denoting the number of cookies in the ith storage, followed by c[i] spaceseparated integers type[i][j] which denote the type if jth cookie in the storage ith.
Output
For each test case, output a single line containing the answer as specified in the statement.
Constraints and Subtasks
Subtask #1 : (20 points) 1 ≤ T ≤ 10
 1 ≤ N ≤ 100
 1 ≤ c[i] ≤ 100
 1 ≤ type[i][j] ≤ 3
 1 ≤ T ≤ 10
 1 ≤ N ≤ 100
 1 ≤ c[i] ≤ 100
 1 ≤ type[i][j] ≤ 6
Example
Input: 3 2 6 1 2 3 4 5 6 9 3 3 3 4 4 4 5 5 5 2 5 2 3 4 5 6 7 1 1 2 2 3 3 4 3 4 1 1 2 3 4 1 2 2 3 4 1 2 3 3 Output: chef 2 tie
Explanation
Example case 1.
Chef has total 6 cookie, so he gets 6 points for that. Also, he can put all his cookies (as they are all distinct) in a bag of size 6. It will fetch him additional 4 points. So, Chef's total points will be 10.
The second player has 9 cookies, he gets 9 points for that. Other than this, he can't create a bag with either 4, 5 or 6 distinct cookies. So, his final score is 9.
10 > 9  Chef wins.
Example case 2.
Chef has 5 + 2 (a bag with 5 different cookies) = 7.
The second player has 7 + 1(a bag with 4 different cookies) = 8.
7 < 8  the second player wins.
Example case 3.
Every player has 4 cookies and can't create any bag of sweets. So, it's a tie.
Author:  omelyanenko 
Tester:  dpraveen 
Editorial  http://discuss.codechef.com/problems/RESCALC 
Tags  adhoc, basicmath, bitset, easy, omelyanenko, sept16 
Date Added:  26072016 
Time Limit:  0.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions