Free Candies

Little Bob is playing a game. He wants to win some candies in it - as many as possible. There are 4 piles, each pile contains N candies. Bob is given a basket which can hold at most 5 candies. Each time, he puts a candy at the top of one pile into the basket, and if there’re two candies of the same color in it, he can take both of them outside the basket and put them into his own pocket. When the basket is full and there are no two candies of the same color, the game ends. If the game is played perfectly, the game will end with no candies left in the piles. For example, Bob may play this game like this (N = 5): Step1 Initial Piles Step2 Take one from pile #2 Piles Basket Pocket 134 1567 2333 2 nothing 4986 8721 Step4 Take one from pile #3 Piles Basket Pocket 14 167 2333 2 3 5 nothing 4986 8721 Step6 Put two candies into his pocket Piles Basket Pocket 14 167 233 25 apairof3 4986 8721 Piles Basket Pocket 1234 1567 2333 nothing nothing 4986 8721 Step3 Take one from pile #2 Piles Basket 134 167 2333 2 5 4986 8721 Step5 Take one from pile #2 Piles Basket 14 167 233 2 3 3 5 4986 8721 Pocket nothing Pocket nothing Note that different numbers indicate different colors, ‘Seems so hard...’ Bob got very much puzzled. How most? Input The input will contain not more than 10 test cases. Each integer n(1 ≤ n ≤ 40) representing the height of the piles. In the following n lines, each line contains four integers xi1 , xi2 , xi3 , xi4 (in the range 1..20). Each integer indicates the color of the corresponding candy. The test case containing n = 0 will terminate the input, you should not give an answer to this case. Output Output the number of pairs of candies that the cleverest little child can take home. Print your answer in a single line for each test case. there are 20 kinds of colors numbered 1..20. many pairs of candies could he take home at test case begins with a line containing a single

2/2 Sample Input 5 1234 1567 2333 4986 8721 1 1234 3 1234 5678 1234 0 Sample Output 8 0 3