Marbles
Time limit1sMemory limit128 MB
Decide whether the given multiset of digits can be split into two equal halves with equal digit products.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Combinatorics
- Solved
- No attempts yet
Problem
Byteted and Bited started a game with marbles. An urn holds an even number of marbles, and every marble carries exactly one digit.
The rules are simple. The two of them take turns drawing one marble each at random from the urn, and the game ends when the urn is empty. The player whose own marbles have the larger product of digits wins. Since they draw one marble at a time in turns, each of them ends up with exactly half of the marbles, and the game is drawn when the two products are equal.
Both boys are ambitious and a draw pleases neither of them. Given the marbles the urn starts with, write a program that decides whether the game can end in a draw.
Input
The first line contains one integer (), the number of test cases.
Each of the next lines contains ten non-negative integers (), where is the number of marbles marked with the digit . In every test case the sum of the is even and positive.
Output
Print lines, one per test case, in the order of the input. Print TAK if the game can end in a draw and NIE otherwise. TAK is Polish for yes and NIE is Polish for no.