-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFairRations.py
More file actions
43 lines (31 loc) · 793 Bytes
/
Copy pathFairRations.py
File metadata and controls
43 lines (31 loc) · 793 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
38
39
40
41
42
43
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'fairRations' function below.
#
# The function is expected to return a STRING.
# The function accepts INTEGER_ARRAY B as parameter.
#
def fairRations(B):
# Write your code here
total_loaves = 0
# Check if the sum of the initial loaves is even
if sum(B) % 2 != 0:
return "NO"
for i in range(len(B) - 1):
if B[i] % 2 != 0:
B[i] += 1
B[i + 1] += 1
total_loaves += 2
return str(total_loaves)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
N = int(input().strip())
B = list(map(int, input().rstrip().split()))
result = fairRations(B)
fptr.write(result + '\n')
fptr.close()