-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1.java
More file actions
37 lines (30 loc) · 853 Bytes
/
Main1.java
File metadata and controls
37 lines (30 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.*;
public class Main1 {
public static long countPairs(long[] arr) {
long even = 0, odd = 0;
for (long x : arr) {
if (x % 2 == 0) {
even++;
} else {
odd++;
}
}
long evnsum = (even * (even - 1)) / 2;
long oddsum = (odd * (odd - 1)) / 2;
return evnsum + oddsum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
// Your code goes here
int n = sc.nextInt();
long arr[] = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
}
long res = countPairs(arr);
System.out.println(res);
}
}
}