시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
0.25 초 256 MB 64 25 23 47.917%

문제

0이 아닌 정수 N개가 주어졌을 때, 0이 아닌 정수 M이 다음 성질을 만족하면 M은 N개의 정수에 대해 신비로운 수라고 한다.

  • N개의 정수를 M으로 나눈 나머지가 모두 같다.

임의의 N개의 정수에 대해 신비로운 수는 적어도 하나 이상 존재한다. 예를 들어, 1은 N개의 정수와 상관없이 항상 신비로운 수이다.

N개의 수가 주어졌을 때, N개의 정수에 대해 신비로운 수 중에서 가장 큰 수를 구해보자.

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 두 줄로 이루어져 있고, 첫째 줄에 N, 둘째 줄에 N개의 정수가 주어진다.

출력

각각의 테스트 케이스마다 N개의 정수에 대한 가장 큰 신비로운 수를 출력한다. 만약 신비로운 수가 무한대로 발산하는 경우 "INFINITY"를 출력한다.

제한

  • 1 ≤ N ≤ 2,000
  • -109 ≤ N개의 정수 ≤ 109

예제 입력 1

4
5
2 4 6 8 10
5
162 72 54 63 57
5
-20 -30 -50 80 75
4
5 5 5 5

예제 출력 1

2
3
5
INFINITY

노트

임의의 정수 p를 0이 아닌 임의의 정수 q로 나눈 나머지는 0 ≤ p - a×q < q를 만족하는 유일한 정수 a에 따라서 정해진다. 이때 나머지는 p - a×q이다.

예를 들어, p = 7, q = 3인 경우 나머지는 1, p = -7, q = 3인 경우 나머지는 2이다.

W3sicHJvYmxlbV9pZCI6IjE3NDMzIiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVjMmUwXHViZTQ0XHViODVjXHVjNmI0IFx1YzIxOCIsImRlc2NyaXB0aW9uIjoiPHA+MFx1Yzc3NCBcdWM1NDRcdWIyY2MgXHVjODE1XHVjMjE4IE5cdWFjMWNcdWFjMDAmbmJzcDtcdWM4ZmNcdWM1YjRcdWM4NGNcdWM3NDQgXHViNTRjLCAwXHVjNzc0IFx1YzU0NFx1YjJjYyBcdWM4MTVcdWMy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