Problem:


A: Union Ball

Problem Statement

There are N balls in a box. The i-th ball is labeled with a positive integer A_i.

You can interact with balls in the box by taking actions under the following rules:

 If integers on balls in the box are all odd or all even, you cannot take actions anymore.

 Otherwise, you select arbitrary two balls in the box and remove them from the box. Then, you generate a new ball labeled with the sum of the integers on the two balls and put it into the box.

For given balls, what is the maximum number of actions you can take under the above rules?

Input

N
A_1 A_2 ... A_N

 The first line gives an integer N representing the initial number of balls in a box.

 The second line contains N integers, the i-th of which is the integer on the i-th ball.

Constraints

 1 \leq N \leq 2 \times 10^5

 1 \leq A_i \leq 10^9

 Inputs consist only of integers.

Output

Output the maximum number of actions you can take in one line.

Sample Input 1

3
4 5 6

Output for Sample Input 1

2

First, you select and remove balls labeled with 4 and 5, respectively, and add a ball labeled with 9.
Next, you select and remove balls labeled with 6 and 9, respectively, and add a ball labeled with 15.
Now, the balls in the box only have odd numbers. So you cannot take any actions anymore. The number of actions you took is two, and there is no way to achieve three actions or more. Thus the maximum is two and the series of the above actions is one of the optimal ways.

Sample Input 2

4
4 2 4 2

Output for Sample Input 2

0

You cannot take any actions in this case.



Sample input:
3
4 5 6


Sample output:
2

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]
c0 = 0
c1 = 0
for i in range(n):
        if arr[i] % 2 == 1:
                c1 = c1 + 1
        else:
                c0 = c0 + 1
if c0 == 0 or c1 == 0:
        print(0)
else:
        if c1 % 2 == 0:
                print(n-2)
        else:
                print(n-1)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n = I()
    a = LI()
    s = sum([i%2 for i in a])
    if s in (0,n):
        print(0)
    else:
        print(n-2+(s%2))
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

p, q = 0, 0
for i in a:
    if i % 2 == 0:
        p += 1
    else:
        q += 1
    
if p == 0 or q == 0:
    print(0)
    exit()

res = p

if q % 2 == 0:
    res += 2 * max(q // 2 - 1, 0)
else:
    res += (q // 2) * 2

print(res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
even = 0
odd = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
if even == 0 or odd == 0:
    print(0)
elif odd % 2 == 1:
    print(N - 1)
else:
    print(N - 2)

Submission status: Accepted

Solution code:
n=int(input())
*a,=map(int,input().split())
o=e=0
for i in a:
    if i%2:
        o+=1
    else:
        e+=1
if not o or not e:
    print(0)
elif o%2:
    print(n-1)
else:
    print(n-2)