/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 本のひもがあり、ひも i の長さは A_i です。
異なるひもをちょうど 3 本選び、選んだひもをすべて同じ長さの切れ端に切り分けます。余りが出てはいけません。ただし、切れ端の長さは正の整数とし、これらの条件で選べる長さのうち最大のものを使います。切らずにそのまま残るひもも、切れ端 1 個と数えます。
得られる切れ端の総数が偶数となるような、ひも 3 本の選び方は何通りありますか。長さが同じでも、ひもの番号が異なれば区別します。選ぶ順序は区別しません。
制約
- 3 \leq N \leq 200000
- 1 \leq A_i \leq 1000000 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
- 1 行目には、ひもの本数 N が与えられる。
- 2 行目には、各ひもの長さ A_1,A_2,\ldots,A_N が空白区切りで与えられる。
出力
条件を満たすひも 3 本の選び方の個数を、整数で出力せよ。
入力例 1
3 1 1 2
出力例 1
1
入力例 2
3 2 2 2
出力例 2
0
入力例 3
4 1 2 3 4
出力例 3
2
入力例 4
6 2 2 4 4 8 8
出力例 4
6
入力例 5
3 1 1000000 999999
出力例 5
1
Score : 400 pts
Problem Statement
There are N ropes, and the length of rope i is A_i.
You will choose exactly 3 distinct ropes and cut all of the chosen ropes into pieces of the same length, with no leftovers. However, the length of each piece must be a positive integer, and you must use the maximum possible length that can be chosen under these conditions. A rope that remains uncut is also counted as 1 piece.
How many ways are there to choose 3 ropes such that the total number of pieces obtained is even? Two ropes with different indices are distinguished even if they have the same length. The order in which they are chosen does not matter.
Constraints
- 3 \leq N \leq 200000
- 1 \leq A_i \leq 1000000 (1 \leq i \leq N)
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
- The 1-st line contains the number of ropes N.
- The 2-nd line contains the lengths of the ropes A_1,A_2,\ldots,A_N, separated by spaces.
Output
Output the number of ways to choose 3 ropes that satisfy the condition as an integer.
Sample Input 1
3 1 1 2
Sample Output 1
1
Sample Input 2
3 2 2 2
Sample Output 2
0
Sample Input 3
4 1 2 3 4
Sample Output 3
2
Sample Input 4
6 2 2 4 4 8 8
Sample Output 4
6
Sample Input 5
3 1 1000000 999999
Sample Output 5
1