-
Notifications
You must be signed in to change notification settings - Fork 0
/
CF248A.java
36 lines (34 loc) · 1.27 KB
/
CF248A.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
import java.util.Scanner;
public class CF248A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int leftClosed = 0;
int rightOpened = 0;
for(int i = 0; i < n; i++) {
int door = sc.nextInt();
if(door == 0) leftClosed++;
door = sc.nextInt();
if(door == 1) rightOpened++;
}
int ans = 0;
if((leftClosed == n && rightOpened == n) || (leftClosed == 0 && rightOpened == 0) || (leftClosed == n && rightOpened == 0) || (leftClosed == 0 && rightOpened == n)) {
ans = 0;
}
else {
if(leftClosed <= (n - leftClosed) && (leftClosed != 0 || leftClosed != n)) {
ans += leftClosed;
}
if(rightOpened < (n - rightOpened) &&(rightOpened != 0 || rightOpened != n)) {
ans += rightOpened;
} if(leftClosed > (n - leftClosed) && (leftClosed != 0 || leftClosed != n)) {
ans += (n -leftClosed);
}
if(rightOpened >= (n - rightOpened) &&(rightOpened != 0 || rightOpened != n)) {
ans += (n - rightOpened);
}
}
System.out.println(ans);
sc.close();
}
}