Darts for Programmers
시간 제한2초메모리 제한2048 MB
고정된 20개 웨지 판에서 세 개의 다트 웨지 번호가 주어질 때, 다트 사이 세 원호 중 웨지 값 합이 최대인 것을 계산합니다.
문제
After a long day of programming challenges, you decide to relax with your friends by playing darts. The only problem is that none of your friends (nor the author) have any clue how scoring works! Rather than try to learn, you simply devise your own rules. The rules you come up with are as follows:
- Each player throws darts at the board on their turn.
- The score for that player's turn is the largest sum of the wedge numbers around the dart board between two circularly adjacent darts, including the wedges the darts land in.
- If two darts land in the same wedge, , the sum around the dartboard from to is .
- If all three darts land in the same wedge, the score for that turn is the number of the wedge they all land in.
- Nobody is accurate enough to hit the bullseye, so we can safely ignore it.
For example, if your darts land in wedges , , and on your turn, you would calculate the sum around the dart board from wedge through wedge (), the sum around the dart board from wedge through wedge () and the sum around the dart board from wedge through wedge (). The sum around the dart board from wedge through wedge is the largest sum, so your score would be points.
The order of the wedges on the dartboard, starting from the top and going clockwise, is , , , , , , , , , , , , , , , , , , , .
입력
The first line contains a single integer , representing the number of players.
The subsequent lines each contain three () space-separated integers , , and (in that order). Each represents the wedge number that the dart for that player landed in.
출력
The output should contain lines. Each line should contain the score for the corresponding player, in the same order in which they appear in the input.
제한
- .
- All is guaranteed to be between and , inclusive.