#K40977. Even Sum Pairs

    ID: 26762 Type: Default 1000ms 256MiB

Even Sum Pairs

Even Sum Pairs

Even Sum Pairs

You are given an array of integers. Your task is to count the number of distinct pairs \((i, j)\) such that \(1 \leq i < j \leq N\) and the sum of the two elements is even. A sum is even if both numbers are even or both numbers are odd. The answer for each test case can be computed using the formula:

$$\binom{even\_count}{2} + \binom{odd\_count}{2}$$

where \(even\_count\) is the number of even elements and \(odd\_count\) is the number of odd elements in the array.

You need to process multiple test cases from standard input.

inputFormat

The input is read from standard input and has the following format:

  • The first line contains a single integer \(T\), the number of test cases.
  • For each test case:
    • The first line contains a single integer \(N\) — the size of the array.
    • The second line contains \(N\) space-separated integers representing the array elements.

outputFormat

For each test case, output a single line with one integer — the number of valid pairs \((i, j)\) such that the sum of the two elements is even.

## sample
1
5
1 2 3 4 5
4

</p>