#TP0000049. Xóa hai phần tử (Delete Two Elements)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa hai phần tử (Delete Two Elements)
Delete Two Elements
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Monocarp has an array of non-negative integers . Let be the arithmetic mean of all elements:
The mean need not be an integer. Monocarp wants to remove exactly two elements at distinct positions so that the mean of the remaining elements is still .
Count all pairs of indices , , whose simultaneous removal leaves the arithmetic mean unchanged. Equal values at different positions still represent different removal choices.
Input
- The first line contains the integer , the original array length.
- The second line contains exactly non-negative integers in positional order.
Output
Print one integer: the number of choices of two distinct positions for which the arithmetic mean remains unchanged after removal.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
5
1 4 7 3 5
Output
2
Explanation
The array has sum and length , so its mean is . After removing two values, the three remaining numbers must sum to . Thus, the removed values must sum to . The two matching position pairs are , with , and , with . The answer is 2.