B. Balls
time limit per test
1.5 seconds
memory limit per test
262 megabytes
input
standard input
output
standard output
Example
Input
2
1 1 1
1 2 1
Output
420