forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairRations.java
More file actions
36 lines (34 loc) · 825 Bytes
/
FairRations.java
File metadata and controls
36 lines (34 loc) · 825 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int B[] = new int[N];
for(int B_i=0; B_i < N; B_i++){
B[B_i] = in.nextInt();
}
int count=0;
int even=0;
for(int i=0;i<N;i++){
if(B[i]%2!=0){
if(i+1<N){
count+=2;
B[i]+=1;
B[i+1]+=1;
even+=1;
}
}
else{
even++;
}
}
if(even==N)
System.out.println(count);
else
System.out.println("NO");
}
}