-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoddphotos.java
55 lines (44 loc) · 1.31 KB
/
oddphotos.java
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
ID: siyonaona
LANG: JAVA
TASK: input arrives from the terminal / stdin
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class oddphotos { // ZERO IS EVEN 1 IS ODD
static int groupCounter(int odd, int even){
int diff = odd - even;
int total = even + odd;
if(diff == 0){
return total;
} else if (diff == 1) {
return total - 2;
} else if (diff == 2){
return total - 1;
} else if(even > odd){
return (2 * odd) + 1;
} else {
return groupCounter(odd - 2, even + 1);
}
}
static ArrayList<Integer> evenCows = new ArrayList<>();
static ArrayList<Integer> oddCows = new ArrayList<>();
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int N = sc.nextInt();
for(int i = 0; i < N; i++){
int cow = sc.nextInt();
if(cow % 2 == 0){
evenCows.add(cow);
} else {
oddCows.add(cow);
}
}
int cowE = evenCows.size();
int cowO = oddCows.size();
System.out.println(groupCounter(cowO, cowE));
}
}