Problem :

https://www.hackerrank.com/challenges/fair-rations/problem


My Solution :

#!/usr/bin/env python3


def fair_rations(B):
    count = 0
    odd_index = -1
    for i, loaves in enumerate(B):
        if loaves % 2 == 1:
            if odd_index != -1:
                count += (i-odd_index)*2
                odd_index = -1
            else:
                odd_index = i
    if odd_index != -1:
        return 'NO'
    return count


N = int(input())
B = list(map(int, input().rstrip().split()))
result = fair_rations(B)
print(result)