Fair Rations
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
N people with B[i] loaves. Each operation gives 1 loaf to person i and 1 to neighbor (i-1 or i+1). Find minimum loaves to make all counts even, or return 'NO'.
Example: B=[2,3,4,5,6] → Person 1 has 3 (odd) → Give to person 1 and 2: [2,4,4,5,6] → Person 3 has 5 (odd) → Give to person 3 and 4: [2,4,4,6,6] → All even. Total: 4 loaves distributed.
Input format
First line: N. Second line: N space-separated integers (initial loaves).
Output format
The minimum number of loaves (as string) or 'NO'.
Constraints
2 ≤ N ≤ 1000, 1 ≤ B[i] ≤ 10