Polycarp has an array $a$ consisting of $n$ integers.

He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.

Formally:   If it is the first move, he chooses any element and deletes it;  If it is the second or any next move:   if the last deleted element was odd, Polycarp chooses any even element and deletes it;  if the last deleted element was even, Polycarp chooses any odd element and deletes it.   If after some move Polycarp cannot make a move, the game ends. 

Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.

Help Polycarp find this value.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2000$) — the number of elements of $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^6$), where $a_i$ is the $i$-th element of $a$.


-----Output-----

Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.


-----Examples-----
Input
5
1 5 7 8 2

Output
0

Input
6
5 1 2 4 6 3

Output
0

Input
2
1000000 1000000

Output
1000000

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
even = []
odd = []
for i in range(n):
	if l[i] % 2 != 0:
		odd.append(l[i])
	else:
		even.append(l[i])
d = min(len(odd), len(even))
if d == len(odd):
	e = sum(even[d + 1:])
else:
	e = sum(odd[d + 1:])
if abs(len(even) - len(odd)) <= 1:
	print(0)
else:
	print(e)


n = int(input())
a = list(map(int, input().split()))
even = 0
odd = 0
for i in range(n):
	if a[i] % 2 == 0:
		even = even + 1
	else:
		odd = odd + 1
a.sort()
count = 0
if even == odd:
	print('0')
elif even > odd:
	even = even - odd - 1
	for i in range(n):
		if a[i] % 2 == 0 and even > 0:
			even = even - 1
			count = count + a[i]
	print(count)
else:
	odd = odd - even - 1
	for i in range(n):
		if a[i] % 2 != 0 and odd > 0:
			odd = odd - 1
			count = count + a[i]
	print(count)


n = int(input())
l = list([int(x) for x in input().split()])
o = []
so = 0
e = []
se = 0
for i in l:
	if i % 2 == 0:
		se += 1
		e.append(i)
	else:
		so += 1
		o.append(i)
if se == so or abs(se - so) == 1:
	print('0')
elif len(o) > 0 and len(e) > 0:
	o.sort()
	e.sort()
	sum = 0
	if se >= so:
		for i in range(0, se - (so + 1)):
			sum += e[i]
	else:
		for i in range(0, so - (se + 1)):
			sum += o[i]
	print(sum)
else:
	o.sort()
	e.sort()
	if so > 0:
		print(sum(o) - o[so - 1])
	else:
		print(sum(e) - e[se - 1])


n = int(input())
arr = list(map(int, input().split()))
odd = []
odd_copy = []
even = []
even_copy = []
for elem in arr:
	if elem % 2 == 0:
		even.append(elem)
		even_copy.append(elem)
	else:
		odd.append(elem)
		odd_copy.append(elem)
even.sort()
odd.sort()
even_copy.sort()
odd_copy.sort()
if len(even) > 0:
	el = even.pop()
	while True:
		if el % 2 == 0:
			if len(odd) > 0:
				el = odd.pop()
			else:
				break
		elif len(even) > 0:
			el = even.pop()
		else:
			break
even_sum = sum(even + odd)
if len(odd_copy) > 0:
	el = odd_copy.pop()
	while True:
		if el % 2 == 0:
			if len(odd_copy) > 0:
				el = odd_copy.pop()
			else:
				break
		elif len(even_copy) > 0:
			el = even_copy.pop()
		else:
			break
odd_sum = sum(even_copy + odd_copy)
print(min(even_sum, odd_sum))


n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
s = 0
odd = []
even = []
for i in range(len(a)):
	s += a[i]
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
l = max(len(odd), len(even))
for i in range(l):
	if len(odd) == 0:
		if len(even) != 0:
			s -= even[0]
			even.pop(0)
		break
	if len(even) == 0:
		if len(odd) != 0:
			s -= odd[0]
			odd.pop(0)
		break
	s -= even[0]
	even.pop(0)
	s -= odd[0]
	odd.pop(0)
print(s)


n = int(input())
l = sorted(list(map(int, input().split())))
o = []
e = []
for i in range(len(l)):
	if l[i] % 2 == 0:
		e.append(l[i])
	else:
		o.append(l[i])
if len(o) == len(e):
	print('0')
	exit()
elif len(o) > len(e):
	o.remove(o[len(o) - 1])
else:
	e.remove(e[len(e) - 1])
while len(e) > 0 and len(o) > 0:
	e.remove(e[len(e) - 1])
	o.remove(o[len(o) - 1])
print(sum(e) + sum(o))


n = int(input())
l = [int(i) for i in input().split()]
ev = [i for i in l if i % 2 == 0]
odd = [i for i in l if i & 1]
oc = sum((i % 2 for i in l))
ec = sum((i % 2 == 0 for i in l))
if oc == ec or abs(oc - ec) == 1:
	print(0)
elif ec > oc:
	ev.sort()
	rem = ec - oc - 1
	print(sum(ev[0:rem]))
else:
	odd.sort()
	rem = oc - ec - 1
	print(sum(odd[0:rem]))


n = int(input())
a = [int(x) for x in input().split()]
e = []
o = []
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
e.sort()
o.sort()
if len(o) > len(e):
	o.pop()
	while len(e) > 0:
		e.pop()
		o.pop()
elif len(o) == len(e):
	while len(e) > 0:
		e.pop()
		o.pop()
else:
	e.pop()
	while len(o) > 0:
		o.pop()
		e.pop()
print(sum(o) + sum(e))


from sys import stdin
stdin.readline()
numbers = tuple(map(int, stdin.readline().rstrip().split(' ')))
even = sorted((number for number in numbers if number % 2 == 0))
odd = sorted((number for number in numbers if number % 2 == 1))
if len(even) == len(odd):
	print(0)
else:
	if len(even) > len(odd):
		(longer, shorter) = (even, odd)
	else:
		(longer, shorter) = (odd, even)
	print(sum(longer[:len(longer) - len(shorter) - 1]))


N = int(input())
arr = input()
arr = [int(x) for x in arr.split(' ')]
odd = []
even = []
for num in arr:
	if num % 2 == 0:
		even.append(num)
	else:
		odd.append(num)
even.sort(reverse=True)
odd.sort(reverse=True)
m = min(len(even), len(odd))
even = even[m:]
odd = odd[m:]
res = 0
if odd:
	odd = odd[1:]
	res = sum(odd)
elif even:
	even = even[1:]
	res = sum(even)
print(res)


def like_to_delete(lst):
	(odd, even) = (list(), list())
	for elem in lst:
		if elem % 2 == 0:
			even.append(elem)
		if elem % 2 != 0:
			odd.append(elem)
	(x, y) = (len(odd), len(even))
	if x == y:
		return 0
	elif x < y:
		y -= x
		y -= 1
		result = 0
		for i in range(y):
			result += sorted(even)[i]
		return result
	elif x > y:
		x -= y
		x -= 1
		result = 0
		for i in range(x):
			result += sorted(odd)[i]
		return result
n = int(input())
a = [int(j) for j in input().split()]
print(like_to_delete(a))


n = int(input())
ar = list(map(int, input().split()))
odd = [x for x in ar if x & 1]
even = [x for x in ar if x & 1 == 0]
odd.sort(reverse=True)
even.sort(reverse=True)
if len(odd) > len(even):
	print(sum(odd[len(even) + 1:]))
else:
	print(sum(even[len(odd) + 1:]))


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
n = iin()
a = lin()
ea = []
oa = []
for i in a:
	if i % 2 == 0:
		ea.append(i)
	else:
		oa.append(i)
l1 = len(ea)
l2 = len(oa)
ea.sort()
oa.sort()
ans = 0
if l1 > l2:
	x = l1 - l2 - 1
	ans += sum(ea[:x])
elif l1 < l2:
	x = l2 - l1 - 1
	ans += sum(oa[:x])
print(ans)


n = int(input())
a = list(map(int, input().split()))
e = []
o = []
for i in range(n):
	if not a[i] & 1:
		e.append(a[i])
	else:
		o.append(a[i])
e.sort(reverse=True)
o.sort(reverse=True)
ans = 0
if len(o) > len(e):
	for i in range(len(e)):
		o[i] = 0
	for i in range(len(e)):
		e[i] = 0
	for i in range(len(o)):
		if o[i] != 0:
			o[i] = 0
			break
	print(sum(o) + sum(e))
elif len(e) > len(o):
	for i in range(len(o)):
		e[i] = 0
	for i in range(len(o)):
		o[i] = 0
	for i in range(len(e)):
		if e[i] != 0:
			e[i] = 0
			break
	print(sum(o) + sum(e))
else:
	print('0')


n = int(input())
a = list(map(int, input().split()))
odd = [x for x in a if x % 2 == 1]
eve = [x for x in a if x % 2 == 0]
odd.sort()
eve.sort()
if abs(len(odd) - len(eve)) <= 1:
	print(0)
elif len(odd) < len(eve):
	x = len(eve) - len(odd) - 1
	print(sum(eve[:x]))
elif len(odd) > len(eve):
	x = len(odd) - len(eve) - 1
	print(sum(odd[:x]))


_ = int(input())
k = map(int, input().split())
ch = []
nch = []
for i in k:
	if i % 2 == 0:
		ch.append(i)
	else:
		nch.append(i)
diff = abs(len(ch) - len(nch))
if diff < 2:
	print(0)
	exit()
ch.sort(reverse=True)
nch.sort(reverse=True)
cut = min(len(ch), len(nch))
ch = ch[cut:]
nch = nch[cut:]
m = 0
if len(ch) > 0:
	m = ch[0]
if len(nch) > 0:
	m = max(m, nch[0])
print(sum(ch) + sum(nch) - m)


n = int(input())
a = list(map(int, input().split()))
a.sort()
m = len(a)
cnt = 0
b = []
c = []
for i in range(0, m):
	if a[i] % 2 == 0:
		b.append(a[i])
	else:
		c.append(a[i])
cntb = len(b)
cntc = len(c)
ans = 0
if abs(cntb - cntc) > 1:
	if cntb > cntc:
		for i in range(0, cntb - cntc - 1):
			ans += b[i]
	else:
		for i in range(0, cntc - cntb - 1):
			ans += c[i]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
odd = []
even = []
for i in arr:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
odd = sorted(odd)
even = sorted(even)
if abs(len(odd) - len(even)) <= 1:
	print(0)
elif len(odd) < len(even):
	print(sum(even[:len(even) - len(odd) - 1]))
else:
	print(sum(odd[:len(odd) - len(even) - 1]))


(n, l) = (int(input()), list(map(int, input().split())))
(odds, evens) = ([], [])
for i in l:
	if i % 2:
		odds.append(i)
	else:
		evens.append(i)
odds.sort()
evens.sort()
if len(odds) > len(evens):
	print(sum(odds[:len(odds) - len(evens) - 1]))
elif len(evens) > len(odds):
	print(sum(evens[:len(evens) - len(odds) - 1]))
else:
	print(0)


n = int(input())
l = [int(i) for i in input().split(' ')]
even = [i for i in l if i % 2 == 0]
odd = [i for i in l if i % 2 != 0]
n_even = len(even)
n_odd = len(odd)
if n_even > n_odd:
	n_even -= n_odd + 1
	n_odd = 0
else:
	n_odd -= n_even + 1
	n_even = 0
if n_even < 0:
	n_even = 0
if n_odd < 0:
	n_odd = 0
even.sort()
odd.sort()
rem_sum = sum(even[:n_even]) + sum(odd[:n_odd])
print(rem_sum)


n = int(input())
ints = list(map(int, input().split()))
even = []
odd = []
for i in ints:
	if i % 2 == 1:
		odd.append(i)
	else:
		even.append(i)
even.sort()
odd.sort()
if len(even) < len(odd):
	diff = len(odd) - len(even) - 1
	if diff > 0:
		print(sum(odd[0:diff]))
	else:
		print(0)
else:
	diff = len(even) - len(odd) - 1
	if diff > 0:
		print(sum(even[0:diff]))
	else:
		print(0)


import sys
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
n = int(input())
l = list(map(int, input().split()))
(o, e, p, q) = (0, 0, [], [])
for i in l:
	if i % 2:
		o += 1
		p.append(i)
	else:
		e += 1
		q.append(i)
if abs(o - e) <= 1:
	print(0)
elif o > e:
	p.sort()
	print(sum(p[:o - e - 1]))
else:
	q.sort()
	print(sum(q[:e - o - 1]))


x = int(input())
y = input().split(' ')
e = []
E = 0
o = []
O = 0
s = 0
for i in range(len(y)):
	if int(y[i]) % 2 == 0:
		e.append(int(y[i]))
		E += 1
	else:
		o.append(int(y[i]))
		O += 1
e = sorted(e)
o = sorted(o)
for i in range(abs(E - O) - 1):
	if E > O:
		s += e[i]
	elif O > E:
		s += o[i]
print(s)


n = int(input())
l = list(map(int, input().split()))
odd = []
even = []
for i in l:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
if abs(len(odd) - len(even)) == 1:
	print(0)
else:
	o = len(odd)
	e = len(even)
	if o > e:
		print(sum(odd[e + 1:]))
	elif e > o:
		print(sum(even[o + 1:]))
	else:
		print(0)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = 1
	for _ in range(t):
		n = int(input())
		arr = inar()
		odd = []
		even = []
		for i in range(n):
			if arr[i] % 2 == 0:
				even.append(arr[i])
			else:
				odd.append(arr[i])
		ans = 0
		if abs(len(odd) - len(even)) > 1:
			diff = abs(len(odd) - len(even))
			if len(odd) < len(even):
				even.sort()
				for i in range(diff - 1):
					ans += even[i]
			else:
				odd.sort()
				for i in range(diff - 1):
					ans += odd[i]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l = list(map(int, input().split()))
even = sorted([x for x in l if x % 2 == 0], reverse=True)
odd = sorted([x for x in l if x % 2], reverse=True)
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
	steps_even = len(odd)
	steps_odd = len(even)
elif len(odd) > len(even):
	steps_odd = len(even) + 1
	steps_even = len(even)
else:
	steps_odd = len(odd)
	steps_even = len(odd) + 1
total = sum(even[steps_even:]) + sum(odd[steps_odd:])
print(total)


import math

def min_left(n, arr):
	(even, odd) = ([], [])
	for x in arr:
		if x % 2 == 0:
			even.append(x)
		else:
			odd.append(x)
	even.sort()
	odd.sort()
	if len(even) == len(odd):
		return 0
	if len(even) < len(odd):
		return sum(odd[:len(odd) - len(even) - 1])
	else:
		return sum(even[:len(even) - len(odd) - 1])
n = int(input())
arr = list(map(int, input().split()))
print(min_left(n, arr))


times = int(input())
even = 0
final = 0
evenArray = [10000001] * times
oddArray = [10000001] * times
even = 0
odd = 0
numbers = input().split()
for counter in range(times):
	numbers[counter] = int(numbers[counter])
for count in range(times):
	if numbers[count] % 2 == 0:
		evenArray[even] = numbers[count]
		even += 1
	if numbers[count] % 2 == 1:
		oddArray[odd] = numbers[count]
		odd += 1
if even + 1 < odd:
	if times == 2:
		final = oddArray[0]
	else:
		oddArray.sort()
		for count in range(odd - even - 1):
			final = final + oddArray[count]
if odd + 1 < even:
	if times == 2:
		final = evenArray[0]
	else:
		evenArray.sort()
		for count in range(even - odd - 1):
			final = final + evenArray[count]
if even == odd or even == odd + 1 or odd == even + 1:
	final = 0
print(final)


input()
a = [*map(int, input().split())]
even = sorted(list(filter(lambda x: x % 2 == 0, a)), reverse=True)
odd = sorted(list(filter(lambda x: x % 2 != 0, a)), reverse=True)
if abs(len(even) - len(odd)) < 2:
	s = 0
else:
	k = min(len(even), len(odd))
	if len(even) == k:
		s = sum(odd[k + 1:])
	else:
		s = sum(even[k + 1:])
print(s)


input()
a = sorted(map(int, input().split()), reverse=True)
b = list(filter(lambda x: x % 2, a))
c = list(filter(lambda x: not x % 2, a))
while min(len(b), len(c)) != 0:
	del b[0]
	del c[0]
c.append(0)
print(sum(b + c) - (b + c)[0])


n = int(input())
array = list(map(int, input().split(' ')))
evens = []
odds = []
for i in array:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens.sort(reverse=False)
odds.sort(reverse=False)
if abs(len(evens) - len(odds)) <= 1:
	print(0)
	exit(0)
firstsum = 0
if len(evens) > len(odds):
	difflen = len(evens) - len(odds)
	print(sum(evens[:difflen - 1]))
else:
	difflen = len(odds) - len(evens)
	print(sum(odds[:difflen - 1]))


n = int(input())
a = [int(x) for x in input().split()]
b = sorted(list(filter(lambda x: x % 2 == 1, a)))
c = sorted(list(filter(lambda x: x % 2 == 0, a)))
b.reverse()
c.reverse()
lb = len(b)
lc = len(c)
if lb > lc + 1:
	print(sum(b[lc + 1:]))
elif lc > lb + 1:
	print(sum(c[lb + 1:]))
else:
	print(0)


def deletions(ar):
	p = 0
	o = []
	e = []
	for i in ar:
		if i % 2 == 1:
			o.append(i)
		else:
			e.append(i)
	if len(o) == len(e):
		return 0
	if len(o) > len(e):
		p = o[-1]
		while e:
			if p % 2 == 1:
				o.remove(p)
				p = max(e)
			else:
				e.remove(p)
				p = max(o)
		if len(o) >= 1:
			o.pop()
	else:
		p = e[-1]
		while o:
			if p % 2 == 1:
				o.remove(p)
				p = max(e)
			else:
				e.remove(p)
				p = max(o)
		if len(e) >= 1:
			e.pop()
	if o:
		return sum(o)
	else:
		return sum(e)
	return 0
n = int(input())
ar = list(map(int, input().split()))
print(deletions(sorted(ar)))


n = int(input())
t = list(map(int, input().split()))
even = []
odd = []
(e, o) = (0, 0)
for j in t:
	if j % 2 == 0:
		even.append(j)
		e += 1
	else:
		odd.append(j)
		o += 1
even.sort()
odd.sort()
if e < o:
	if e == 0:
		print(sum(odd[0:-1]))
	else:
		print(sum(odd[0:-(e + 1)]))
elif o < e:
	if o == 0:
		print(sum(even[0:-1]))
	else:
		print(sum(even[0:-(o + 1)]))
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
	if arr[i] % 2 == 1:
		odd.append(arr[i])
	else:
		even.append(arr[i])
if abs(len(odd) - len(even)) < 2:
	print(0)
else:
	odd.sort()
	even.sort()
	ans = 0
	if len(odd) > len(even):
		for i in range(len(odd) - len(even) - 1):
			ans += odd[i]
	else:
		for i in range(len(even) - len(odd) - 1):
			ans += even[i]
	print(ans)


_ = int(input())
array = list(map(int, input().split()))
even = sorted([e for e in array if e % 2 == 0], reverse=True)
odd = sorted([e for e in array if e % 2 == 1], reverse=True)
deleted = min(len(even), len(odd)) + 1
sum_rest = sum(even[deleted:]) + sum(odd[deleted:])
print(sum_rest)


n = int(input())
l = list(map(int, input().split()))
l = list(sorted(l, reverse=True))
p = []
d = []
for i in l:
	if i % 2 == 0:
		p.append(i)
	else:
		d.append(i)
if abs(len(p) - len(d)) <= 1:
	print(0)
elif len(p) > len(d):
	print(sum(p[len(d) + 1:]))
else:
	print(sum(d[len(p) + 1:]))


n = int(input())
numbers = list(map(int, input().split()))
odd = 0
even = 0
o = []
e = []
for i in numbers:
	if i % 2 != 0:
		odd += 1
		o.append(i)
	else:
		even += 1
		e.append(i)
e.sort()
o.sort()
result = 0
if abs(odd - even) <= 1:
	print(0)
	exit()
elif odd < even:
	for i in range(even - odd - 1):
		result += e[i]
else:
	for i in range(odd - even - 1):
		result += o[i]
print(result)


m = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
s = 0
o = 0
e = 0
while i < len(a):
	if a[i] % 2 != 0:
		o += 1
	else:
		e += 1
	i += 1
if e == o or e - o == 1 or o - e == 1:
	print(0)
elif o == 0 or e == 0:
	print(sum(a) - a[len(a) - 1])
elif o > e:
	t = o - e - 1
	i = 1
	j = 0
	while i <= t and j < len(a):
		if a[j] % 2 != 0:
			s += a[j]
			i += 1
		j += 1
	print(s)
else:
	t = e - o - 1
	i = 1
	j = 0
	while i <= t and j < len(a):
		if a[j] % 2 == 0:
			s += a[j]
			i += 1
		j += 1
	print(s)


n = int(input())
a = list(map(int, input().split()))
ch = []
nec = []
for x in a:
	if x % 2 == 0:
		ch.append(x)
	else:
		nec.append(x)
ch.sort()
nec.sort()
if len(ch) - 1 > len(nec):
	print(sum(ch[:len(ch) - len(nec) - 1]))
elif len(nec) - 1 > len(ch):
	print(sum(nec[:len(nec) - len(ch) - 1]))
else:
	print(0)


n = int(input())
nums = list(map(int, input().split()))
odds = [num for num in nums if num % 2 == 1]
evens = [num for num in nums if num % 2 == 0]
odds.sort(reverse=True)
evens.sort(reverse=True)
delete_even_cnt = min(len(evens), len(odds) + 1)
delete_odd_cnt = min(len(odds), delete_even_cnt)
ans1 = sum(odds[delete_odd_cnt:]) + sum(evens[delete_even_cnt:])
delete_odd_cnt = min(len(odds), len(evens) + 1)
delete_even_cnt = min(len(evens), delete_odd_cnt)
ans2 = sum(odds[delete_odd_cnt:]) + sum(evens[delete_even_cnt:])
ans = min(ans1, ans2)
print(ans)


import math
n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if arr[i] % 2 == 0:
		even.append(arr[i])
	else:
		odd.append(arr[i])
if abs(len(even) - len(odd)) <= 1:
	print(0)
	exit()
if len(even) > len(odd):
	even.sort(reverse=True)
	ans = 0
	for i in range(len(odd) + 1, len(even)):
		ans += even[i]
	print(ans)
	exit()
odd.sort(reverse=True)
ss = 0
for i in range(len(even) + 1, len(odd)):
	ss += odd[i]
print(ss)


import sys
amount = int(input())
array = [int(s) for s in input().split()]
even = []
odd = []
for i in range(len(array)):
	if array[i] % 2:
		odd.append(array[i])
	else:
		even.append(array[i])
odd = sorted(odd)
even = sorted(even)
sum_1 = 0
sum_2 = 0
if abs(len(odd) - len(even)) == 1 or len(odd) == len(even):
	print(0)
	sys.exit(0)
if len(odd) > len(even):
	print(sum(odd[:-len(even) - 1]))
else:
	print(sum(even[:-len(odd) - 1]))


n = int(input())
a = list(map(int, input().strip().split()))
a.sort()
even = 0
ev = []
od = []
odd = 0
s = 0
for i in a:
	if i % 2 == 0:
		even = even + 1
		ev.append(i)
	else:
		odd = odd + 1
		od.append(i)
if abs(even - odd) == 1 or even - odd == 0:
	print(0)
elif even > odd:
	for i in range(0, even - odd - 1):
		s = s + ev[i]
	print(s)
else:
	for i in range(0, odd - even - 1):
		s = s + od[i]
	print(s)


def main():
	n = int(input())
	array = list(map(int, input().split()))
	even = []
	odd = []
	for i in array:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	even.sort(reverse=True)
	odd.sort(reverse=True)
	even1 = even[:]
	odd1 = odd[:]
	even2 = even[:]
	odd2 = odd[:]
	k = min(len(even), len(odd))
	for i in range(k):
		even1.pop(0)
		odd1.pop(0)
	if even1:
		even1.pop(0)
	ans1 = sum(even1) + sum(odd1)
	for i in range(k):
		even2.pop(0)
		odd2.pop(0)
	if odd2:
		odd2.pop(0)
	ans = sum(even2) + sum(odd2)
	print(min(ans1, ans))
main()


n = int(input())
a = [int(x) for x in input().split(' ')]
evens = [x for x in a if x % 2 == 0]
odds = [x for x in a if x % 2 == 1]
evens.sort()
odds.sort()
E = len(evens)
O = len(odds)
if E > O:
	ans = sum(evens[:-(O + 1)])
elif E == O:
	ans = 0
else:
	ans = sum(odds[:-(E + 1)])
print(ans)


n = map(int, input().split())
arr = list(map(int, input().split()))
x1 = [a for a in arr if a % 2 == 0]
x2 = [a for a in arr if a % 2 != 0]
x1.sort()
x1 = x1[::-1]
x2.sort()
x2 = x2[::-1]
len_ = min(len(x1), len(x2))
x1 = x1[len_:]
x2 = x2[len_:]
if len(x1) == 0 and len(x2) == 0:
	print(0)
elif len(x1) == 0:
	print(sum(x2[1:]))
elif len(x2) == 0:
	print(sum(x1[1:]))
else:
	print(min(sum(x1 + x2[1:]), sum(x1[1:] + x2)))


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	even = []
	odd = []
	for v in a:
		if v & 1:
			odd += [v]
		else:
			even += [v]
	even.sort(reverse=True)
	ne = len(even)
	odd.sort(reverse=True)
	no = len(odd)
	if ne <= no:
		print(sum(odd[ne + 1:no]))
	else:
		print(sum(even[no + 1:ne]))


n = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ev = 0
od = 0
for i in range(n):
	if l[i] & 1 == 0:
		ev += 1
	else:
		od += 1
d = abs(ev - od)
if d == 0 or d == 1:
	print(0)
else:
	if ev < od:
		ge = ev
		go = ev + 1
	else:
		go = od
		ge = od + 1
	j = 0
	while ge > 0 or go > 0:
		if l[j] & 1 == 0:
			if ge > 0:
				ge -= 1
				l[j] = 0
		elif go > 0:
			go -= 1
			l[j] = 0
		j += 1
	print(sum(l))


from sys import stdin
n = int(stdin.readline().strip())
l = list(map(int, stdin.readline().split()))
co = 0
ce = 0
a = []
b = []
for i in range(n):
	if l[i] % 2 == 0:
		co += 1
		a.append(l[i])
	else:
		ce += 1
		b.append(l[i])
if co == ce or co - ce == 1 or ce - co == 1:
	print(0)
else:
	k = min(co, ce)
	a.sort(reverse=True)
	b.sort(reverse=True)
	if k != 0:
		for i in range(k):
			a.pop(0)
			b.pop(0)
	if len(a) > len(b):
		a.pop(0)
	else:
		b.pop(0)
	print(sum(a) + sum(b))


import sys
import math
import heapq
import bisect
from collections import defaultdict as dd
n = int(input())
l = [int(i) for i in input().split()]
o = []
e = []
for i in l:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
o.sort()
e.sort()
if len(e) > len(o):
	(o, e) = (e, o)
for i in range(len(e)):
	e.pop(-1)
	o.pop(-1)
if o:
	o.pop(-1)
print(sum(o))


input()
n = [int(x) for x in input().split()]
odd = []
even = []
for e in n:
	if e & 1 == 0:
		even += [e]
	else:
		odd += [e]
even = sorted(even)
odd = sorted(odd)

def solve():
	if len(even) == len(odd):
		return 0
	elif len(even) > len(odd):
		return sum(even[0:len(even) - 1 - len(odd)])
	else:
		return sum(odd[0:len(odd) - 1 - len(even)])
print(solve())


n = int(input())
l = list(map(int, input().split()))
c1 = c2 = 0
l1 = []
l2 = []
for i in l:
	if i % 2 == 0:
		c1 += 1
		l1.append(i)
	else:
		c2 += 1
		l2.append(i)
if c1 > c2 + 1:
	l1.sort()
	print(sum(l1[:c1 - c2 - 1]))
elif c2 > c1 + 1:
	l2.sort()
	print(sum(l2[:c2 - c1 - 1]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
odd = []
even = []
for i in l:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
lo = len(odd)
le = len(even)
if lo == le or lo == le + 1 or lo == le - 1:
	print(0)
else:
	if le > lo:
		diff = le - lo - 1
		ans = sum(even[:diff])
	else:
		diff = lo - le - 1
		ans = sum(odd[:diff])
	print(ans)


numero = int(input())
lista = input().split()
par = []
impar = []
s = 0
for i in range(len(lista)):
	s += int(lista[i])
	if int(lista[i]) % 2:
		par.append(int(lista[i]))
	else:
		impar.append(int(lista[i]))
par = sorted(par, reverse=True)
impar = sorted(impar, reverse=True)
ans = 2000000000
for j in range(0, 2):
	k = j
	l = 0
	r = 0
	t = 0
	while 1:
		if k:
			if l == len(par):
				break
			t += par[l]
			l += 1
		else:
			if r == len(impar):
				break
			t += impar[r]
			r += 1
		k = 1 - k
	ans = min(ans, s - t)
print(ans)


num = int(input())
x = [int(i) for i in input().split()]
(odd, even) = ([], [])
for i in x:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even = sorted(even)
odd = sorted(odd)
diff = len(even) - len(odd)
if diff > 1:
	print(sum(even[:diff - 1]))
elif diff < -1:
	print(sum(odd[:abs(diff) - 1]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
for i in l:
	if i % 2:
		o.append(i)
	else:
		e.append(i)
a = len(e)
b = len(o)
e.sort()
o.sort()
if a - b == 0:
	print(0)
elif b - a > 0:
	print(sum(o[:b - a - 1]))
else:
	print(sum(e[:a - b - 1]))


n = int(input())
a = [int(i) for i in input().split()]
e = []
o = []
for i in range(0, len(a)):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
if abs(len(e) - len(o)) <= 1:
	print(0)
else:
	e = sorted(e)
	o = sorted(o)
	if len(e) > len(o):
		f = e[0:len(e) - len(o) - 1]
		print(sum(f))
	else:
		f = o[0:len(o) - len(e) - 1]
		print(sum(f))


def parse_arr():
	return list(map(int, input().split(' ')))
n = int(input())
arr = parse_arr()
even = odd = 0
e = []
o = []
for num in arr:
	if num % 2 == 0:
		even += 1
		e.append(num)
	else:
		odd += 1
		o.append(num)
e = sorted(e)
o = sorted(o)
ans = 0
if even == odd or even + 1 == odd or odd + 1 == even:
	print(0)
	exit(0)
mini = min(even, odd)
e_ = max(even - mini, 0)
o_ = max(odd - mini, 0)
if e_ > 0:
	e_ -= 1
tmp = 0
for num in e:
	if e_ == 0:
		break
	else:
		tmp += num
		e_ -= 1
for num in o:
	if o_ == 0:
		break
	else:
		tmp += num
		o_ -= 1
ans = tmp
e_ = max(even - mini, 0)
o_ = max(odd - mini, 0)
if o_ > 0:
	o_ -= 1
tmp = 0
for num in e:
	if e_ == 0:
		break
	else:
		tmp += num
		e_ -= 1
for num in o:
	if o_ == 0:
		break
	else:
		tmp += num
		o_ -= 1
if tmp < ans:
	ans = tmp
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ch = [i for i in a if i % 2 == 0]
nch = [i for i in a if i % 2 == 1]
if len(ch) == len(nch):
	print(0)
else:
	if len(ch) > len(nch):
		s = sum(ch[:len(ch) - len(nch) - 1])
	else:
		s = sum(nch[:len(nch) - len(ch) - 1])
	print(s)


n = int(input())
a = list(map(int, input().split(' ')))
f = list(map(lambda x: x % 2 == 0, a))
e = f.count(True)
o = f.count(False)
r = e - o
if abs(r) < 2:
	print(0)
else:
	plus = []
	minus = []
	for i in a:
		if i % 2 == 0:
			plus.append(i)
		else:
			minus.append(i)
	if r > 0:
		plus.sort()
		print(sum(plus[:r - 1]))
	else:
		minus.sort()
		print(sum(minus[:abs(r) - 1]))


n = int(input())
b = list(map(int, input().split()))
c = []
d = []
for j in range(n):
	if b[j] % 2 == 0:
		c.append(b[j])
	else:
		d.append(b[j])
c.sort()
c.reverse()
d.sort()
d.reverse()
if len(c) > len(d):
	print(sum(c[len(d) + 1:]))
elif len(d) > len(c):
	print(sum(d[len(c) + 1:]))
else:
	print(0)


n = int(input())
A = list(map(int, input().split()))
evens = []
odds = []
for a in A:
	if a % 2 == 0:
		evens.append(a)
	else:
		odds.append(a)
evens.sort()
odds.sort()
if abs(len(evens) - len(odds)) < 2:
	print(0)
elif len(evens) > len(odds):
	print(sum(evens[:len(evens) - len(odds) - 1]))
else:
	print(sum(odds[:len(odds) - len(evens) - 1]))


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(even) == len(odd):
	print(0)
else:
	if len(even) > len(odd):
		ans = sum(a) - sum(odd)
		even = sorted(even, reverse=True)
		for i in range(len(odd) + 1):
			ans -= even[i]
	else:
		ans = sum(a) - sum(even)
		odd = sorted(odd, reverse=True)
		for i in range(len(even) + 1):
			ans -= odd[i]
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
odds = []
evens = []
for num in arr:
	if num % 2 == 0:
		evens.append(num)
	else:
		odds.append(num)
odds.sort()
evens.sort()
result = 0
if len(odds) > len(evens) + 1:
	result = sum(odds[:len(odds) - len(evens) - 1])
elif len(evens) > len(odds) + 1:
	result = sum(evens[:len(evens) - len(odds) - 1])
print(result)


n = int(input())
a = list(map(int, input().split()))
even = sorted([i for i in a if i % 2 == 0], reverse=True)
odd = sorted([i for i in a if i % 2 != 0], reverse=True)
s = sum(a)
r = s
k = min(len(even), len(odd))
r -= sum(even[:k])
r -= sum(odd[:k])
if len(odd) > k:
	r -= odd[k]
if len(even) > k:
	r -= even[k]
print(r)


n = int(input())
a = list(map(int, input().split()))
(chet, nechet) = (0, 0)
chet_a = []
nechet_a = []
for i in a:
	if i % 2 == 0:
		chet += 1
		chet_a.append(i)
	else:
		nechet += 1
		nechet_a.append(i)
m = None
if len(nechet_a) > len(chet_a):
	m = nechet_a
else:
	m = chet_a
if abs(chet - nechet) > 1:
	s = 0
	m.sort()
	for i in range(abs(chet - nechet) - 1):
		s += m[i]
	print(s)
else:
	print(0)


n = int(input())
L = list(map(int, input().split()))
L1 = sorted([k for k in L if k % 2 == 0])
L2 = sorted([k for k in L if k % 2])
while len(L1) != 0 and len(L2) != 0:
	L1.pop()
	L2.pop()
if len(L1) > 0:
	L1 = L1[:len(L1) - 1]
elif len(L2) > 0:
	L2 = L2[:len(L2) - 1]
print(sum(L1) + sum(L2))


import math
n = int(input())
ce = 0
co = 0
arr2 = []
arr3 = []
arr = list(map(int, input().split()))
arr.sort(reverse=True)
for k in arr:
	if k % 2 == 0:
		ce += 1
		arr2.append(k)
	else:
		co += 1
		arr3.append(k)
po = min(ce, co) + 1
if ce == co or ce - 1 == co or co - 1 == ce:
	print(0)
elif ce > co:
	ans = sum(arr2) - sum(arr2[0:po])
	print(ans)
else:
	ans = sum(arr3) - sum(arr3[0:po])
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
a1 = []
a2 = []
for el in arr:
	if el % 2 == 0:
		a2.append(el)
	else:
		a1.append(el)
if len(a1) < len(a2):
	ans = 0
	for i in range(len(a2) - len(a1) - 1):
		ans += a2[i]
else:
	ans = 0
	for i in range(len(a1) - len(a2) - 1):
		ans += a1[i]
print(ans)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ct = [l[x] for x in range(0, n) if l[x] % 2 == 0]
	ct2 = [l[x] for x in range(0, n) if l[x] % 2 != 0]
	if len(ct) > len(ct2):
		del ct[-1]
		for i in range(len(ct) - len(ct2), len(ct)):
			ct[i] = 0
		print(sum(ct))
	elif len(ct) < len(ct2):
		del ct2[-1]
		for i in range(len(ct2) - len(ct), len(ct2)):
			ct2[i] = 0
		print(sum(ct2))
	else:
		print(0)
solve()


a = int(input())
arr = list(map(int, input().split()))
odd = []
even = []
for i in arr:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd.sort()
even.sort()
ans = []
if len(odd) > len(even):
	ans = odd[:len(odd) - len(even)]
else:
	ans = even[:len(even) - len(odd)]
if len(ans) > 0:
	ans.pop()
print(sum(ans))


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
ans = 0
odd.sort()
even.sort()
if -1 <= len(odd) - len(even) <= 1:
	ans = 0
elif len(odd) > len(even):
	ans = sum(odd[:len(odd) - len(even) - 1])
else:
	ans = sum(even[:len(even) - len(odd) - 1])
print(ans)


n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a)
ch = []
nch = []
for i in range(n):
	if a1[i] % 2 == 0:
		ch.append(a1[i])
	else:
		nch.append(a1[i])
if len(ch) == len(nch) or abs(len(ch) - len(nch)) == 1:
	print(0)
elif len(ch) > len(nch):
	r = len(ch) - len(nch) - 1
	print(sum(ch[:r]))
else:
	r = len(nch) - len(ch) - 1
	print(sum(nch[:r]))


n = int(input())
x = input().split()
x = [int(i) for i in x]
a = []
b = []
a1 = []
b1 = []
suma = []
j = 0
mini = 0
for i in x:
	if int(i) % 2 == 0:
		b.append(i)
		b1.append(i)
	else:
		a.append(i)
		a1.append(i)
a = sorted(a)
b = sorted(b)
a1 = sorted(a1)
b1 = sorted(b1)
j = min(len(a), len(b))
for i in range(j):
	a.pop()
	b.pop()
if a != b:
	if a == []:
		b.pop()
	if b == []:
		a.pop()
tmp = sum(a) + sum(b)
mini = tmp
j = min(len(a1), len(b1))
for i in range(j):
	a1.pop()
	b1.pop()
tmp = sum(a1) + sum(b1)
if tmp < mini:
	mini = tmp
print(mini)


n = int(input())
l = list(map(int, input().split()))
odd = even = 0
oddm = []
evenm = []
for i in range(n):
	if l[i] % 2 == 0:
		even += 1
		evenm.append(l[i])
	else:
		odd += 1
		oddm.append(l[i])
oddm = sorted(oddm)
evenm = sorted(evenm)
if even == odd + 1 or even == odd - 1:
	print(0)
elif even > odd:
	print(sum(evenm[:even - odd - 1]))
elif odd > even:
	print(sum(oddm[:odd - even - 1]))
else:
	print(0)


def mp():
	return map(int, input().split())
n = int(input())
a = list(mp())
e = o = 0
for i in a:
	if i % 2 == 0:
		e += 1
	else:
		o += 1
a.sort()
if e >= o:
	t = 0
	cnt = e - o - 1
else:
	t = 1
	cnt = o - e - 1
r = 0
for i in a:
	if i % 2 == t and cnt > 0:
		cnt -= 1
		r += i
print(r)


a = int(input())
b = input()
p = b.split()
for i in range(len(p)):
	p[i] = int(p[i])
ch = 0
nch = 0
sch = 0
snch = 0
k = []
l = []
for i in range(len(p)):
	if p[i] % 2 == 0:
		ch = ch + 1
		sch = sch + p[i]
		k.append(p[i])
	elif p[i] % 2 == 1:
		nch = nch + 1
		snch = snch + p[i]
		l.append(p[i])
if abs(ch - nch) == 0:
	print(0)
else:
	if ch > nch:
		o = 0
		m = abs(ch - nch)
		while m != 1:
			o = o + min(k)
			k.remove(min(k))
			m = m - 1
	else:
		o = 0
		m = abs(ch - nch)
		while m != 1:
			o = o + min(l)
			l.remove(min(l))
			m = m - 1
	print(o)


import string, copy

def solution(n, a):
	a = sorted(a, reverse=True)
	odds = [i for i in a if i % 2 == 1]
	evens = [i for i in a if i % 2 == 0]
	if abs(len(odds) - len(evens)) <= 1:
		return 0
	l = min(len(odds), len(evens)) + 1
	return sum(odds[l:] + evens[l:])

def parser():
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	return (n, a)

def output(s):
	print(s)

def main():
	args = parser()
	result = solution(*args)
	output(result)
main()


n = int(input())
x = list(map(int, input().split()))
(odd_cnt, even_cnt) = (0, 0)
(odd, even) = ([], [])
for i in range(n):
	if x[i] % 2 == 0:
		even_cnt += 1
		even.append(x[i])
	else:
		odd_cnt += 1
		odd.append(x[i])
even.sort()
odd.sort()
if abs(odd_cnt - even_cnt) > 1:
	if even_cnt > odd_cnt:
		print(sum(even[:even_cnt - odd_cnt - 1]))
	else:
		print(sum(odd[:odd_cnt - even_cnt - 1]))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
(c1, c2) = (0, 0)
(l1, l2) = ([], [])
for i in range(n):
	if b[i] % 2 != 0:
		l1.append(b[i])
		c1 += 1
	else:
		l2.append(b[i])
		c2 += 1
if c1 == c2:
	print(0)
elif c1 > c2:
	t = 0
	for i in range(0, c1 - c2 - 1):
		t += l1[i]
	print(t)
else:
	k = 0
	for i in range(0, c2 - c1 - 1):
		k += l2[i]
	print(k)


n = int(input())
arr = list(map(int, input().split()))
evens = sorted([x for x in arr if x % 2 == 0], reverse=True)
odds = sorted([x for x in arr if x % 2 == 1], reverse=True)
if len(evens) == len(odds):
	print(0)
elif len(evens) > len(odds):
	print(sum(evens[len(odds) + 1:]))
else:
	print(sum(odds[len(evens) + 1:]))


N = int(input())
M = sorted(map(int, input().split()))
flag = 1
(odd, even) = ([], [])

def odd_even(n):
	if n % 2 == 0:
		return 'Even'
	else:
		return 'Odd'
for n in M:
	if odd_even(n) == 'Even':
		even.append(n)
	else:
		odd.append(n)

def max_del(M):
	M.pop(-1)
	return M
if len(even) > len(odd):
	flag = 1
elif len(even) < len(odd):
	flag = -1
elif min(even) > min(odd):
	flag = 1
else:
	flag = -1
while flag != 2:
	if flag == 1:
		even.pop(-1)
		flag *= -1
		if len(odd) == 0:
			flag = 2
	else:
		odd.pop(-1)
		flag *= -1
		if len(even) == 0:
			flag = 2
print(sum(odd) + sum(even))


I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
o = []
e = []
x = 0
y = 0
for i in l:
	if i % 2:
		o.append(i)
		x += 1
	else:
		e.append(i)
		y += 1
e.sort()
o.sort()
if abs(x - y) <= 1:
	print(0)
elif x > y:
	print(sum(o[:abs(y - x) - 1]))
else:
	print(sum(e[:abs(y - x) - 1]))


a = int(input())
s = [int(x) for x in input().split()]
s.sort(reverse=True)
e1 = []
e2 = []
for i in s:
	if i % 2 != 0:
		e1.append(i)
	else:
		e2.append(i)
if len(e1) == len(e2):
	print(0)
elif len(e1) < len(e2):
	print(sum(e2[len(e1) + 1:]))
else:
	print(sum(e1[len(e2) + 1:]))


import math
n = int(input())
o = []
e = []
s = list(map(int, input().split()))
for i in s:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
if abs(len(e) - len(o)) <= 1:
	print(0)
elif len(e) > len(o):
	k = len(e) - len(o) - 1
	e.sort()
	su = 0
	for i in range(k):
		su += e[i]
	print(su)
else:
	k = len(o) - len(e) - 1
	o.sort()
	su = 0
	for i in range(k):
		su += o[i]
	print(su)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(k, l) = ([], [])
for i in range(n):
	if a[i] % 2 == 1:
		k.append(a[i])
	else:
		l.append(a[i])
if abs(len(k) - len(l)) > 1:
	if len(k) > len(l):
		print(sum(k[:len(k) - len(l) - 1]))
	else:
		print(sum(l[:len(l) - len(k) - 1]))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
od = 0
b = []
ev = 0
c = []
for i in range(n):
	if a[i] % 2 == 0:
		ev += 1
		c.append(a[i])
	else:
		od += 1
		b.append(a[i])
if ev == od or ev + 1 == od or od + 1 == ev:
	print('0')
elif ev > od:
	c.sort()
	x = ev - od - 1
	print(sum(c[:x]))
else:
	b.sort()
	x = od - ev - 1
	print(sum(b[:x]))


n = int(input())
ar = list(map(int, input().strip().split(' ')))
lst1 = []
lst2 = []
for i in range(n):
	if ar[i] % 2 == 0:
		lst2.append(ar[i])
	else:
		lst1.append(ar[i])
lst1.sort(reverse=True)
lst2.sort(reverse=True)
n1 = len(lst1)
n2 = len(lst2)
if n1 == n2 or n1 == n2 + 1 or n2 == n1 + 1:
	print('0')
else:
	if n1 > n2:
		a = n2 + 1
		s = sum(lst1[a:])
	else:
		a = n1 + 1
		s = sum(lst2[a:])
	print(s)


def getSum(n, arr):
	eveAr = []
	oddAr = []
	for i in arr:
		if i % 2 == 0:
			eveAr.append(i)
		else:
			oddAr.append(i)
	eN = len(eveAr)
	oN = len(oddAr)
	eveAr.sort()
	oddAr.sort()
	if eN - oN > 1:
		s = eN - oN - 1
		res = sum(eveAr[:s])
	elif oN - eN > 1:
		s = oN - eN - 1
		res = sum(oddAr[:s])
	else:
		return 0
	return res
n = int(input())
arr = list(map(int, input().split()))
print(getSum(n, arr))


n = int(input())
Arr = sorted(list(map(int, input().split())))
evens = []
odds = []
for el in Arr:
	if el % 2 == 0:
		evens.append(el)
	else:
		odds.append(el)
evens.sort()
odds.sort()
i = 0
while evens and odds:
	if evens:
		evens.pop()
	if odds:
		odds.pop()
if evens:
	evens.pop()
if odds:
	odds.pop()
print(max(sum(evens), sum(odds)))


n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
even = [x for x in a if x % 2 == 0]
odd = [x for x in a if x % 2 == 1]
x = min(len(odd), len(even)) + 1
print(sum(odd[x:]) + sum(even[x:]))


n = int(input())
a = [int(i) for i in input().split()]
eve = []
odd = []
s = 0
a = sorted(a, reverse=True)
for i in a:
	if i % 2 == 0:
		eve.append(i)
	else:
		odd.append(i)
if len(eve) == len(odd):
	print(0)
elif min(len(eve), len(odd)) + 1 == max(len(eve), len(odd)):
	print(0)
else:
	no = min(len(eve), len(odd)) + 1
	odd = odd[::-1]
	eve = eve[::-1]
	if len(odd) > len(eve):
		while no > 0:
			odd.pop()
			no -= 1
		print(sum(odd))
	else:
		while no > 0:
			eve.pop()
			no -= 1
		print(sum(eve))


n = int(input())
a = list(map(int, input().split()))
ae = []
ao = []
for i in range(n):
	if a[i] % 2 == 0:
		ae.append(a[i])
	else:
		ao.append(a[i])
ae.sort()
ao.sort()
if len(ae) >= len(ao):
	while len(ao) != 0:
		ae.pop()
		ao.pop()
	if len(ae) > 0:
		ae.pop()
else:
	while len(ae) != 0:
		ao.pop()
		ae.pop()
	if len(ao) > 0:
		ao.pop()
sum = sum(ae) + sum(ao)
print(sum)


IN = input
rint = lambda : int(IN())
rlist = lambda : list(map(int, IN().split()))
n = rint()
a = []
b = []
for i in rlist():
	if i & 1:
		a.append(i)
	else:
		b.append(i)
a.sort()
b.sort()
s = 0

def upd(x):
	global s
	s = max(s, x)

def Try(a, b):
	t = min(len(a), len(b))
	upd(sum(a[-t - 1:]) + sum(b[-t - 1:]))
Try(a, b)
Try(b, a)
print(sum(a) + sum(b) - s)


n = int(input())
l = sorted(list(map(int, input().split())))
a = []
b = []
w = 0
c = 0
r = 0
for i in range(n - 1, -1, -1):
	if l[i] % 2 == 0:
		a.append(l[i])
	else:
		b.append(l[i])
c = min(len(a), len(b))
if len(a) != 0 and len(b) == 0:
	print(sum(l) - a[0])
elif len(b) != 0 and len(a) == 0:
	print(sum(l) - b[0])
elif abs(len(a) - len(b)) <= 1:
	print(0)
else:
	if c == len(a):
		r = sum(a[0:c]) + sum(b[0:c + 1])
	else:
		r = sum(a[0:c + 1]) + sum(b[0:c])
	print(sum(l) - r)


input()
a = [[], []]
for x in sorted(map(int, input().split())):
	a[x % 2] += (x,)
a.sort(key=len)
print(sum(a[1][:-len(a[0]) - 1]))


i = input()
data = input()
this_is = list(map(int, data.split()))
all = len(this_is)
(chet, nechet) = [[], []]
for i in this_is:
	if i % 2:
		nechet.append(i)
	else:
		chet.append(i)
n_chet = len(chet)
n_nechet = len(nechet)
if n_chet - n_nechet in [-1, 1, 0]:
	print(0)
elif n_nechet > n_chet:
	print(sum(sorted(nechet)[:-1 - n_chet]))
else:
	print(sum(sorted(chet)[:-1 - n_nechet]))


n = int(input())
a = list(map(int, input().split()))
mini = float('inf')
odd = sorted((i for i in a if i % 2 == 1))
even = sorted((i for i in a if i % 2 == 0))
while odd and even:
	odd.pop()
	even.pop()
if odd:
	odd.pop()
mini = min(mini, sum(odd) + sum(even))
odd = sorted((i for i in a if i % 2 == 1))
even = sorted((i for i in a if i % 2 == 0))
while even and odd:
	even.pop()
	odd.pop()
if even:
	even.pop()
mini = min(mini, sum(odd) + sum(even))
print(mini)


n = int(input())
a = list(map(int, input().split()))
eve = [x for x in a if x % 2 == 0]
odd = [x for x in a if x % 2 != 0]
eve.sort(reverse=True)
odd.sort(reverse=True)
point = min(len(eve), len(odd))
point += 1
ans = 0
if len(eve) > point:
	ans = sum(eve[point:])
elif len(odd) > point:
	ans = sum(odd[point:])
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
odd = [i for i in a if i & 1]
odd.sort(reverse=True)
even = [i for i in a if i & 1 == 0]
even.sort(reverse=True)
if len(odd) > len(even):
	print(s - sum(odd[:len(even) + 1]) - sum(even))
elif len(odd) < len(even):
	print(s - sum(even[:len(odd) + 1]) - sum(odd))
else:
	print(0)


n = int(input())
ai = list(map(int, input().split()))
even = [i for i in ai if i % 2 == 0]
odd = [i for i in ai if i % 2 != 0]
even.sort()
odd.sort()
if len(odd) > len(even):
	leftoverelements = len(odd) - len(even) - 1
	minimize_sum = 0
	i = 0
	while i < leftoverelements:
		minimize_sum += odd[i]
		i += 1
	print(minimize_sum)
elif len(even) > len(odd):
	leftoverelements = len(even) - len(odd) - 1
	minimize_sum = 0
	i = 0
	while i < leftoverelements:
		minimize_sum += even[i]
		i += 1
	print(minimize_sum)
else:
	print(0)


n = int(input())
lst = [int(i) for i in input().split()]
lst.sort(reverse=True)
no = 0
ne = 0
for i in lst:
	if i % 2 == 0:
		ne += 1
	else:
		no += 1
min1 = min([ne, no])
min1 = min1 + 1
no = 0
ne = 0
sum1 = 0
for i in lst:
	if i % 2 == 0 and ne < min1:
		ne += 1
	elif i % 2 == 0:
		sum1 = sum1 + i
	if i % 2 != 0 and no < min1:
		no += 1
	elif i % 2 != 0:
		sum1 = sum1 + i
print(sum1)


n = int(input())
nums = list(map(int, input().split()))
(odd, even) = ([], [])
for i in nums:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
if abs(len(odd) - len(even)) > 1:
	if len(odd) > len(even):
		t = len(odd) - len(even)
		ans = sum(odd[len(odd) - t + 1:])
	else:
		t = len(even) - len(odd)
		ans = sum(even[len(even) - t + 1:])
else:
	ans = 0
print(ans)


to = te = 0
n = int(input())
l = [*map(int, input().split())]
odd = []
even = []
for i in l:
	if i % 2 == 0:
		even.append(i)
		te += 1
	else:
		odd.append(i)
		to += 1
if to == te:
	print(0)
elif to > te:
	if to - 1 == te:
		print(0)
	else:
		odd.sort()
		print(sum(odd[:to - (te + 1)]))
elif te - 1 == to:
	print(0)
else:
	even.sort()
	print(sum(even[:te - (to + 1)]))


n = int(input())
numbers = input().split(' ')
par = []
impar = []
for i in range(n):
	if int(numbers[i]) % 2 == 0:
		par.append(int(numbers[i]))
	else:
		impar.append(int(numbers[i]))
par.sort()
impar.sort()
while True:
	if len(par) == len(impar) or len(par) + 1 == len(impar) or len(impar) + 1 == len(par):
		print(0)
		break
	elif len(impar) > len(par):
		for i in range(len(par) + 1):
			impar.pop()
		print(sum(impar))
		break
	elif len(par) > len(impar):
		for i in range(len(impar) + 1):
			par.pop()
		print(sum(par))
		break


n = int(input())
s = list(map(int, input().split()))
even = [i for i in s if i % 2 == 0]
odd = [i for i in s if i % 2 == 1]
even.sort()
odd.sort()
if len(even) >= len(odd):
	s = len(even) - len(odd) - 1
	if s <= 0:
		print(0)
		exit()
	else:
		print(sum([even[i] for i in range(s)]))
elif len(odd) >= len(even):
	s = len(odd) - len(even) - 1
	if s <= 0:
		print(0)
		exit()
	else:
		print(sum([odd[i] for i in range(s)]))


def main():
	n = int(input())
	s = [int(x) for x in input().split()]
	sum = 0
	sum1 = 0
	sum2 = 0
	for i in range(n):
		sum += s[i]
	arr1 = []
	arr2 = []
	for i in range(n):
		if s[i] % 2 == 0:
			arr2.append(s[i])
		else:
			arr1.append(s[i])
	arr1.sort()
	arr2.sort()
	arr1 = arr1[::-1]
	arr2 = arr2[::-1]
	if abs(len(arr1) - len(arr2)) <= 1:
		ans = 0
	elif len(arr1) == 0 or len(arr2) == 0:
		ans = sum - max(s)
	elif len(arr1) > len(arr2):
		for i in range(len(arr2)):
			sum1 += arr1[i]
			sum2 += arr2[i]
		ans = sum - sum1 - sum2
		ans -= arr1[len(arr2)]
	else:
		for i in range(len(arr1)):
			sum1 += arr1[i]
			sum2 += arr2[i]
		ans = sum - sum1 - sum2
		ans -= arr2[len(arr1)]
	print(ans)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A.sort()
even = []
odd = []
for i in range(N):
	if A[i] % 2 == 0:
		even.append(A[i])
	else:
		odd.append(A[i])
if abs(len(even) - len(odd)) <= 1:
	print(0)
else:
	ans = 0
	gap = abs(len(even) - len(odd)) - 1
	if len(even) > len(odd):
		for i in range(gap):
			ans += even[i]
	else:
		for i in range(gap):
			ans += odd[i]
	print(ans)


from sys import stdin, stdout
import cProfile, math
from collections import Counter, defaultdict
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys

class merge_find:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (20 - len(b)) + b
	return b

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True
factorial_modP = []

def warm_up_fac(MOD):
	nonlocal factorial_modP, fac_warmup
	if fac_warmup:
		return
	factorial_modP = [1 for _ in range(fac_warmup_size + 1)]
	for i in range(2, fac_warmup_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warmup = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	nonlocal fac_warmup, factorial_modP
	if not fac_warmup:
		warm_up_fac(MOD)
		fac_warmup = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
import heapq, itertools
pq = []
entry_finder = {}
REMOVED = '<removed-task>'

def add_task(task, priority=0):
	if task in entry_finder:
		remove_task(task)
	count = next(counter)
	entry = [priority, count, task]
	entry_finder[task] = entry
	heapq.heappush(pq, entry)

def remove_task(task):
	entry = entry_finder.pop(task)
	entry[-1] = REMOVED

def pop_task():
	while pq:
		(priority, count, task) = heapq.heappop(pq)
		if task is not REMOVED:
			del entry_finder[task]
			return task
	raise KeyError('pop from an empty priority queue')
memory = dict()

def clear_cache():
	nonlocal memory
	memory = dict()

def cached_fn(fn, *args):
	nonlocal memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_serach(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = False
testingMode = False
fac_warmup_size = 10 ** 5 + 100
optimiseForReccursion = True
from math import factorial

def main():
	n = get_int()
	li = get_list()
	even = [x for x in li if x % 2 != 0]
	odd = [x for x in li if x % 2 == 0]
	if abs(len(even) - len(odd)) < 2:
		print(0)
		return
	elif len(odd) > len(even):
		(odd, even) = (even, odd)
	even.sort()
	print(sum(even[:len(even) - len(odd) - 1]))
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


n = int(input())
a = list(map(int, input().split()))
ev = sorted(list(filter(lambda x: x % 2 == 0, a)))
od = sorted(list(filter(lambda x: x % 2 != 0, a)))
f = len(od) - len(ev)
if f > 0:
	print(sum(od[0:f - 1]))
elif f < 0:
	print(sum(ev[0:abs(f) - 1]))
else:
	print(0)


n = int(input())
s = list(map(int, input().split()))
s.sort()
s.reverse()
z = s[0]
g = 'None'
for i in range(1, n):
	if s[i] % 2 != z % 2:
		g = s[i]
		break
otv1 = [z]
otv2 = [g]
gr = [0]
if g != 'None':
	gr1 = [s.index(g)]
else:
	gr1 = []
for j in range(n):
	for i in range(n):
		if s[i] % 2 != z % 2 and i not in gr:
			z = s[i]
			gr.append(i)
			otv1.append(s[i])
			break
	if str(otv2[0]) != 'None':
		for i in range(n):
			if s[i] % 2 != g % 2 and i not in gr1:
				g = s[i]
				gr1.append(i)
				otv2.append(s[i])
				break
if str(otv2[0]) == 'None':
	otv2 = []
po = []
popo = []
for i in range(n):
	if i not in gr:
		po.append(s[i])
for i in range(n):
	if i not in gr1:
		popo.append(s[i])
print(min(sum(po), sum(popo)))


n = int(input())
s = str(input())
lt = s.split(' ')
l = []
for i in range(n):
	l.append(int(lt[i]))
odd = 0
even = 0
for i in l:
	if i % 2 == 0:
		even += 1
	else:
		odd += 1
summ = 0
if even == odd or abs(even - odd) == 1:
	print(summ)
else:
	mini = min(odd, even)
	temp = []
	if mini == odd:
		for i in l:
			if i % 2 == 0:
				temp.append(i)
		temp.sort()
		run = even - (odd + 1)
		for i in range(run):
			summ += temp[i]
		print(summ)
	else:
		for i in l:
			if i % 2 != 0:
				temp.append(i)
		temp.sort()
		run = odd - (even + 1)
		for i in range(run):
			summ += temp[i]
		print(summ)


import sys
from functools import reduce
from collections import defaultdict

def padOpt(ints):
	sInts = sorted(ints)[::-1]
	odd = []
	even = []
	for i in sInts:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	total = sum(sInts)
	k = min(len(odd), len(even))
	total -= sum(odd[0:k])
	total -= sum(even[0:k])
	n = 0
	if len(odd) > k:
		n = odd[k]
	if len(even) > k:
		if n < even[k]:
			n = even[k]
	total -= n
	print(total)

def io():
	totalIns = int(sys.stdin.readline(), 10)
	ints = [] * totalIns
	for i in sys.stdin.readline().strip().split():
		ints.append(int(i, 10))
	padOpt(ints)
io()


n = int(input())
l = [*map(int, input().split())]
e = [x for x in l if x & 1]
o = [x for x in l if not x & 1]
(a, b) = (len(e), len(o))
e.sort()
o.sort()
res = 0
if a < b:
	res = sum(o[:b - a - 1])
if b < a:
	res = sum(e[:a - b - 1])
print(res)


N = int(input())
A = list(map(int, input().split()))
odd = 0
even = 0
x = []
y = []
for a in A:
	if a % 2:
		odd += 1
		x.append(a)
	else:
		even += 1
		y.append(a)
x.sort()
y.sort()
if abs(odd - even) <= 1:
	ans = 0
elif even < odd:
	ans = sum(x[:odd - even - 1])
elif odd < even:
	ans = sum(y[:even - odd - 1])
print(ans)


import sys
f = sys.stdin
n = int(f.readline().rstrip())
ls = list(map(int, f.readline().rstrip().split()))
even = []
odd = []
for i in range(len(ls)):
	if ls[i] % 2 == 0:
		even.append(ls[i])
	else:
		odd.append(ls[i])
even.sort()
odd.sort()
le = len(even)
lo = len(odd)
sum = 0
if abs(le - lo) <= 1:
	print('0')
elif le > lo:
	l = le - lo - 1
	for i in range(l):
		sum += even[i]
	print(sum)
else:
	l = lo - le - 1
	for i in range(l):
		sum += odd[i]
	print(sum)


n = int(input())
a = list(map(int, input().split()))
chetarr = []
nechetarr = []
chet = 0
nechet = 0
for i in range(n):
	if a[i] % 2 == 0:
		chet += 1
		chetarr.append(a[i])
	else:
		nechet += 1
		nechetarr.append(a[i])
sum = 0
if chet == nechet or chet + 1 == nechet or chet - 1 == nechet:
	print(sum)
else:
	if chet > nechet:
		for i in range(chet - nechet - 1):
			sum += min(chetarr)
			chetarr.remove(min(chetarr))
	else:
		for i in range(nechet - chet - 1):
			sum += min(nechetarr)
			nechetarr.remove(min(nechetarr))
	print(sum)


t = int(input())
l = list(map(int, input().split()))
x = []
y = []
for i in l:
	if i % 2 == 0:
		x.append(i)
	else:
		y.append(i)
x.sort(reverse=True)
y.sort(reverse=True)
if len(x) == len(y) or len(x) - 1 == len(y) or len(x) + 1 == len(y):
	print('0')
elif len(x) > len(y):
	print(sum(x[len(y) + 1:len(x)]))
else:
	print(sum(y[len(x) + 1:len(y)]))


n = int(input())
a = sorted(map(int, input().split()))
even = [i for i in a if i % 2 == 0]
odd = [i for i in a if i % 2 != 0]
result = 0
if len(even) > len(odd):
	for i in range(abs(len(even) - len(odd)) - 1):
		result += even[i]
	print(result)
elif len(even) < len(odd):
	for i in range(abs(len(even) - len(odd)) - 1):
		result += odd[i]
	print(result)
else:
	print(0)


n = int(input())
value = []
value = list(map(int, input().strip().split()))
odd = []
even = []
sum = temp_sum = 0
for i in value:
	sum += i
	if i % 2 != 0:
		odd.append(i)
	else:
		even.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
lo = len(odd)
le = len(even)
length = min(lo, le)
for i in range(0, length):
	temp_sum += odd[0]
	odd.pop(0)
	temp_sum += even[0]
	even.pop(0)
if len(odd) != 0:
	temp_sum += odd[0]
elif len(even) != 0:
	temp_sum += even[0]
print(sum - temp_sum)


n = int(input().strip())
(even, odd) = ([], [])
for num in input().strip().split():
	num = int(num)
	if num % 2:
		odd.append(num)
	else:
		even.append(num)
len_diff = len(even) - len(odd)
if abs(len_diff) <= 1:
	print(0)
else:
	if len_diff < 0:
		target_nums = odd
	else:
		target_nums = even
	print(sum(sorted(target_nums)[:abs(len_diff) - 1]))


n = int(input())
arr = [int(x) for x in input().split()]
aO = []
aE = []
Co = 0
Ce = 0
for i in range(n):
	if arr[i] % 2 == 0:
		Ce += 1
		aE.append(arr[i])
	else:
		Co += 1
		aO.append(arr[i])
if Co == Ce:
	print(0)
	raise SystemExit
ans = 0
if Co > Ce:
	aO.sort()
	Co -= Ce + 1
	for i in range(Co):
		ans += aO[i]
else:
	aE.sort()
	Ce -= Co + 1
	for i in range(Ce):
		ans += aE[i]
print(ans)


n = int(input())
l = list(map(int, input().split()))
ao = []
ae = []
for i in range(len(l)):
	if l[i] % 2 == 0:
		ae.append(l[i])
	else:
		ao.append(l[i])
ae.sort()
ao.sort()
if len(ae) == len(ao):
	print('0')
elif len(ae) > len(ao):
	sum = 0
	for i in range(len(ae) - len(ao) - 1):
		sum += ae[i]
	print(sum)
else:
	sum = 0
	for i in range(len(ao) - len(ae) - 1):
		sum += ao[i]
	print(sum)


def giveMin(arr):
	oddC = evenC = 0
	arrOdd = []
	arrEv = []
	for num in arr:
		if num % 2 == 0:
			evenC += 1
			arrEv.append(num)
		else:
			oddC += 1
			arrOdd.append(num)
	if oddC == evenC or abs(oddC - evenC) == 1:
		return 0
	else:
		arrOdd.sort()
		arrEv.sort()
		if oddC > evenC:
			return sum(arrOdd[:oddC - evenC - 1])
		else:
			return sum(arrEv[:evenC - oddC - 1])
n = int(input())
arr = list(map(int, input().rstrip().split()))
print(giveMin(arr))


n = int(input().strip())
arr = list(map(int, input().strip().split()))
evens = []
odds = []
for i in arr:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
(le, lo) = (len(evens), len(odds))
if abs(le - lo) <= 1:
	print(0)
elif le > lo:
	evens.sort()
	print(sum(evens[:le - lo - 1]))
else:
	odds.sort()
	print(sum(odds[:lo - le - 1]))


input()
A = list(map(int, input().split()))
A.sort()
even_nums = []
odd_nums = []
for num in A:
	if num % 2 == 0:
		even_nums.append(num)
	else:
		odd_nums.append(num)
x = len(even_nums) - len(odd_nums)
if x == 0 or x == 1 or x == -1:
	print(0)
elif x > 0:
	print(sum(even_nums[0:x - 1]))
elif x < 0:
	x *= -1
	print(sum(odd_nums[0:x - 1]))


t = int(input())
cnt = 0
su = 0

def init(a):
	for p in range(len(a)):
		a[p] = int(a[p])
	return a
d = input().split()
d = init(d)
e = []
o = []
for i in range(len(d)):
	if d[i] % 2 == 0:
		e.append(d[i])
	else:
		o.append(d[i])
e = sorted(e)
o = sorted(o)
h = len(e) - len(o)
if abs(h) < 2:
	su = 0
elif h > 0:
	su = sum(e[:abs(h) - 1])
elif h < 0:
	su = sum(o[:abs(h) - 1])
print(su)


n = input()
a = input().split()
a = [int(i) for i in a]
a_odd = [i for i in a if i % 2 == 1]
a_even = [i for i in a if i % 2 == 0]
a_odd.sort()
a_even.sort()
if len(a_odd) > len(a_even) + 1:
	print(sum(a_odd[0:len(a_odd) - len(a_even) - 1]))
elif len(a_odd) + 1 < len(a_even):
	print(sum(a_even[0:len(a_even) - len(a_odd) - 1]))
else:
	print('0')


def calc(a, b):
	return sum(a) + sum(b[-(len(a) + 1):])
_ = int(input())
numbers = list(map(int, input().split()))
odds = sorted((x for x in numbers if x % 2 == 1))
evens = sorted((x for x in numbers if x % 2 != 1))
deleted = calc(odds, evens) if len(odds) < len(evens) else calc(evens, odds)
print(sum(numbers) - deleted)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN():
	return sys.stdin.readline().strip().split()

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5
n = int(input())
l = list(numIN())
e = []
o = []
for i in l:
	if i % 2:
		o.append(i)
	else:
		e.append(i)
if len(e) == len(o):
	print(0)
else:
	e.sort(reverse=True)
	o.sort(reverse=True)
	mn = min(len(e), len(o))
	x = e[mn:]
	y = o[mn:]
	if x:
		print(sum(x) - x[0])
	else:
		print(sum(y) - y[0])


n = int(input())
s = input().split()
A = [int(i) for i in s]
num_odd = []
num_even = []
len_odd = 0
len_even = 0
for i in A:
	if i % 2 == 0:
		num_even.append(i)
		len_even += 1
	else:
		num_odd.append(i)
		len_odd += 1
num_odd.sort(reverse=True)
num_even.sort(reverse=True)
if len_odd == len_even:
	print(0)
if len_odd > len_even:
	print(sum(A) - sum(num_even) - sum(num_odd[:len_even + 1]))
if len_odd < len_even:
	print(sum(A) - sum(num_odd) - sum(num_even[:len_odd + 1]))


n = int(input())
a = list(map(int, input().split()))
x = []
y = []
for i in a:
	if i % 2 == 0:
		x.append(i)
	else:
		y.append(i)
s = len(x) - len(y)
ans = 0
x.sort()
y.sort()
if s < -1:
	for i in range(0, abs(s) - 1):
		ans += y[i]
elif s > 1:
	for i in range(0, s - 1):
		ans += x[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in a:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
odd_count = len(odd)
even_count = len(even)
min_count = min(odd_count, even_count)
if abs(odd_count - even_count) <= 1:
	res = 0
else:
	res = sum(even[:-(min_count + 1)]) if odd_count <= even_count else sum(odd[:-(min_count + 1)])
print(res)


n = int(input())
a = [int(t) for t in input().split(' ')]
a.sort()
minsum = sum(a)
for pi in range(0, 2):
	p0 = [t for t in a if t % 2 == 0]
	p1 = [t for t in a if t % 2 == 1]
	pn = [p0, p1]
	p = pi
	while len(pn[p]):
		pn[p].pop()
		p = 1 - p
	minsum = min(minsum, sum(p0 + p1))
print(minsum)


n = int(input())
a = list(map(int, input().split()))
e = []
o = []
for i in range(len(a)):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
e = sorted(e)
o = sorted(o)
s = 0
if len(e) > len(o):
	d = len(e) - len(o)
	d -= 1
	for i in range(d):
		s += e[i]
	print(s)
elif len(e) < len(o):
	d = len(o) - len(e)
	d -= 1
	for i in range(d):
		s += o[i]
	print(s)
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
l2 = sorted(l)
l.sort()
l.reverse()
if l[0] % 2 == 0:
	flag = 1
	f2 = 1
else:
	flag = 0
	f2 = 0
l.pop(0)
k = 0
while len(l) != 0:
	if l[k] % 2 == flag:
		l.pop(k)
		flag = (flag + 1) % 2
		k = 0
		continue
	k += 1
	if k == len(l):
		break
s1 = sum(l)
k = 0
while len(l2) != 0:
	if l2[k] % 2 == f2:
		l2.pop(k)
		f2 = (f2 + 1) % 2
		k = 0
		continue
	k += 1
	if k == len(l2):
		break
s2 = sum(l2)
print(min(s1, s2))


n = int(input())
a = list(map(int, input().split()))
odd = 0
even = 0
odds = []
evens = []
for x in a:
	if x % 2:
		even += 1
		evens.append(x)
	else:
		odd += 1
		odds.append(x)
if odd - 1 > even:
	odds.sort()
	print(sum(odds[:odd - even - 1]))
	exit()
if even - 1 > odd:
	evens.sort()
	print(sum(evens[:even - odd - 1]))
	exit()
print(0)


n = int(input())
A = list(map(int, input().split()))
q1 = []
q2 = []
for i in A:
	if i % 2:
		q1.append(i)
	else:
		q2.append(i)
if abs(len(q1) - len(q2)) <= 1:
	print(0)
	exit(0)
if len(q1) < len(q2):
	q2.sort()
	print(sum(q2[:len(q2) - len(q1) - 1]))
else:
	q1.sort()
	print(sum(q1[:len(q1) - len(q2) - 1]))


n = int(input())
arr = [int(x) for x in input().split()]
even = []
odd = []
answer = 0
for number in arr:
	if number % 2 == 0:
		even.append(number)
	else:
		odd.append(number)
difference = int(abs(len(even) - len(odd)))
if difference != 1:
	if len(even) > len(odd):
		even.sort()
		for elem in range(difference - 1):
			answer += even[elem]
	else:
		odd.sort()
		for elem in range(difference - 1):
			answer += odd[elem]
print(answer)


(n, a) = (int(input()), list(map(int, input().split())))
(odd, even) = (sorted(filter(lambda x: x % 2, a)), sorted(filter(lambda x: x % 2 == 0, a)))
if len(odd) == len(even):
	print(0)
elif len(odd) > len(even):
	print(sum(odd[:len(odd) - len(even) - 1]))
else:
	print(sum(even[:len(even) - len(odd) - 1]))


n = int(input())
a = list(map(int, input().split()))
b = [[], []]
for x in a:
	b[x % 2].append(x)
b[0].sort()
b[1].sort()
if abs(len(b[0]) - len(b[1])) <= 1:
	print(0)
elif len(b[0]) > len(b[1]):
	print(sum(b[0][0:len(b[0]) - len(b[1]) - 1]))
else:
	print(sum(b[1][0:len(b[1]) - len(b[0]) - 1]))


a = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
B = []
C = []
b = 0
c = 0
for i in range(a):
	if A[i] % 2 == 0:
		B.append(A[i])
		b += 1
	else:
		C.append(A[i])
		c += 1
if b > c + 1:
	B = B[c + 1:b]
	print(sum(B))
elif c > b + 1:
	C = C[b + 1:c]
	print(sum(C))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
for i in range(n):
	if l[i] % 2 == 1:
		l1.append(l[i])
	else:
		l2.append(l[i])

def f(x, y):
	m = len(x)
	n = len(y)
	k = m - n - 1
	if k >= 1:
		x.sort()
		tmp = 0
		for i in range(k):
			tmp += x[i]
		return tmp
	else:
		return 0
if len(l1) > len(l2):
	print(f(l1, l2))
else:
	print(f(l2, l1))


n = int(input())
a = input().split()
a = [int(i) for i in a]
b = []
c = []
for i in a:
	b.append(i % 2)
if b.count(1) == b.count(0) or abs(b.count(0) - b.count(1)) == 1:
	print(0)
else:
	sum = 0
	cnt1 = b.count(1)
	cnt0 = b.count(0)
	if cnt0 > cnt1:
		c = [i for i in a if i % 2 == 0]
		for i in range(cnt0 - cnt1 - 1):
			sum += min(c)
			c.remove(min(c))
	else:
		c = [i for i in a if i % 2 == 1]
		for i in range(cnt1 - cnt0 - 1):
			sum += min(c)
			c.remove(min(c))
	print(sum)


n = int(input())
L = list(map(int, input().split()))
odd = [x for x in L if x & 1 == 1]
even = [x for x in L if x & 1 != 1]
k = max(0, abs(len(even) - len(odd)))
kL = odd if len(odd) > len(even) else even
kL.sort()
print(sum(kL[0:k - 1]) if k != 0 else 0)


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
odd.reverse()
even.reverse()
cnt = 1
for i in range(n):
	if a[i] == 0:
		cnt += 1
	if a[i] % 2 == 0:
		odd.append(a[i])
	else:
		even.append(a[i])
even.sort()
odd.sort()
n = len(odd)
m = len(even)
if abs(n - m) <= cnt:
	print(0)
	exit()
if m == 0:
	print(sum(odd) - odd[-1])
	exit()
elif n == 0:
	print(sum(even) - even[-1])
	exit()
if n > m:
	print(sum(odd[:n - m - 1]))
else:
	print(sum(even[:m - n - 1]))


import sys

def max_even(arr):
	index = -1
	for i in range(len(arr)):
		if arr[i] % 2 == 0:
			return i
	return index

def max_not_even(arr):
	index = -1
	for i in range(len(arr)):
		if arr[i] % 2 == 1:
			return i
	return index
size = int(input())
arr = sorted(list(map(int, input().split(' '))))
arr.reverse()
res = sys.maxsize
for start in (True, False):
	tmp = arr[:]
	while True:
		if start:
			even = max_even(tmp)
			if even == -1:
				break
			del tmp[even]
		if not start:
			not_even = max_not_even(tmp)
			if not_even == -1:
				break
			del tmp[not_even]
		start = not start
	if res > sum(tmp):
		res = sum(tmp)
print(res)


import sys
count = sys.stdin.readline().rstrip()
line = sorted([int(i) for i in sys.stdin.readline().rstrip().split(' ')])
evens = []
odds = []
for i in line:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
while len(odds) > 0 and len(evens) > 0:
	del odds[-1]
	del evens[-1]
print(sum(odds[:-1]) + sum(evens[:-1]))


def parity(arr):
	odds = []
	evens = []
	for i in arr:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	odds.sort()
	evens.sort()
	sum = 0
	if len(evens) > len(odds) + 1:
		for i in range(len(evens) - len(odds) - 1):
			sum = sum + evens[i]
	elif len(evens) + 1 < len(odds):
		for i in range(len(odds) - len(evens) - 1):
			sum = sum + odds[i]
	return sum
n = input()
arr = list(map(int, input().split()))
print(parity(arr))


a = int(input())
x = list(map(int, input().split()))
x = sorted(x)
gen = [x[i] for i in range(len(x)) if x[i] % 2 == 0]
gan = [x[i] for i in range(len(x)) if x[i] % 2 != 0]
ma = max(len(gen), len(gan))
mi = min(len(gen), len(gan))
if ma - mi == 1 or ma == mi:
	print(0)
	exit(0)
sums = 0
if len(gen) == ma:
	for i in range(ma - mi - 1):
		sums += gen[i]
	print(sums)
if len(gan) == ma:
	for i in range(ma - mi - 1):
		sums += gan[i]
	print(sums)


n = int(input())
a = list(map(int, input().split()))
o = [a[i] for i in range(n) if a[i] % 2 == 1]
e = [a[i] for i in range(n) if a[i] % 2 == 0]
o.sort()
e.sort()
if len(o) == len(e):
	print(0)
elif abs(len(o) - len(e)) == 1:
	print(0)
elif len(o) > len(e):
	print(sum(o[:len(o) - len(e) - 1]))
elif len(e) > len(o):
	print(sum(e[:len(e) - len(o) - 1]))


N = int(input())
s = list(map(int, input().split()))
odd = []
even = []
for i in s:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd = sorted(odd)
even = sorted(even)
if len(odd) > len(even):
	(odd, even) = (even, odd)
count = 0
while True:
	if count % 2 == 0:
		try:
			even.pop()
			count = 1 - count
		except:
			break
	else:
		try:
			odd.pop()
			count = 1 - count
		except:
			break
print(sum(odd) + sum(even))


n = int(input())
a = list(map(int, input().split()))
ch = []
nch = []
for elem in a:
	if elem % 2:
		nch.append(elem)
	else:
		ch.append(elem)
sum1 = 0
sum2 = 0
ch.sort()
nch.sort()
z = ch
x = nch
p = 1
while p != 0:
	if p % 2:
		try:
			ch.pop()
			p += 1
		except:
			break
	else:
		try:
			nch.pop()
			p += 1
		except:
			break
sum1 = sum(ch) + sum(nch)
p = 1
while p != 0:
	if p % 2:
		try:
			x.pop()
			p += 1
		except:
			break
	else:
		try:
			z.pop()
			p += 1
		except:
			break
sum2 = sum(x) + sum(z)
print(min(sum1, sum2))


n = int(input())
a = [int(i) for i in input().split()]
evens = [i for i in a if i % 2 == 0]
odds = [i for i in a if i % 2 == 1]
evens.sort()
evens = evens[::-1]
odds.sort()
odds = odds[::-1]
evenCount = len(evens)
oddCount = len(odds)
if evenCount == oddCount or abs(evenCount - oddCount) == 1:
	print(0)
elif evenCount > oddCount:
	print(sum(evens[oddCount + 1:]))
else:
	print(sum(odds[evenCount + 1:]))


input()
data = list(map(int, input().split()))
even = sorted((v for v in data if v % 2 == 0), key=lambda v: -v)
odd = sorted((v for v in data if v % 2 == 1), key=lambda v: -v)
n_even = len(even)
n_odd = len(odd)
if n_even == n_odd:
	print(0)
elif n_even > n_odd:
	print(sum(even[n_odd + 1:]))
else:
	print(sum(odd[n_even + 1:]))


import io, os
kk = lambda : map(int, input().split())
k2 = lambda : map(lambda x: int(x) - 1, input().split())
ll = lambda : list(kk())
(n, ls) = (int(input()), kk())
(odd, even) = ([], [])
for l in ls:
	if l & 1:
		odd.append(l)
	else:
		even.append(l)
odd.sort()
even.sort()
(l1, l2) = (len(odd), len(even))
if max(l1, l2) - min(l1, l2) < 2:
	print(0)
elif l1 > l2:
	print(sum(odd[:l1 - l2 - 1]))
else:
	print(sum(even[:l2 - l1 - 1]))


n = int(input())
In = input().split()
odd = [] * 0
even = [] * 0
answer = 0
for i in range(n):
	i = int(In[i])
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(odd) != len(even) or len(odd) != len(even) + 1 or len(odd) != len(even) - 1:
	odd.sort()
	even.sort()
	lenDeffer = abs(len(odd) - len(even))
	if len(odd) > len(even):
		for i in range(lenDeffer - 1):
			answer += odd[i]
	else:
		for i in range(lenDeffer - 1):
			answer += even[i]
print(answer)


n = int(input())
A = list(map(int, input().split()))
E = list()
O = list()
e = 0
o = 0
s = 0
for i in A:
	if i % 2 == 0:
		E.append(i)
		e += 1
	else:
		O.append(i)
		o += 1
E.sort()
O.sort()
E = E[::-1]
O = O[::-1]
if e > o:
	A.remove(E[0])
	E.pop(0)
	for i in range(0, o):
		A.remove(E[i])
		A.remove(O[i])
elif o > e:
	A.remove(O[0])
	O.pop(0)
	for i in range(0, e):
		A.remove(E[i])
		A.remove(O[i])
s = sum(A)
if e == o:
	s = 0
print(s)


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
a.sort()
for i in range(0, n):
	if a[i] & 1:
		odd.append(a[i])
	else:
		even.append(a[i])
if len(odd) == len(even):
	print(0)
elif len(odd) == len(even) - 1 or len(odd) - 1 == len(even):
	print(0)
elif max(len(odd), len(even)) == len(odd):
	diff = len(odd) - len(even) - 1
	print(sum(odd[0:diff]))
else:
	diff = len(even) - len(odd) - 1
	print(sum(even[0:diff]))


chet = []
nochet = []
n = int(input())
a = [int(x) for x in input().strip().split()]
for i in a:
	if i % 2 == 0:
		chet.append(i)
	else:
		nochet.append(i)
chet.sort()
nochet.sort()
summ = 0
ma = max(len(chet), len(nochet))
for i in range(ma):
	if len(chet) - i > len(nochet) + 1:
		summ += chet[i]
	elif len(nochet) - i > len(chet) + 1:
		summ += nochet[i]
print(summ)


n = int(input())
l = list(map(int, input().split()))
ch = 0
nech = 0
ach = []
anech = []
for i in range(n):
	if l[i] % 2 == 0:
		ach.append(l[i])
		ch += 1
	else:
		nech += 1
		anech.append(l[i])
if nech >= ch:
	anech.sort()
	ans = 0
	for i in range(nech - ch - 1):
		ans += anech[i]
	print(ans)
else:
	ach.sort()
	ans = 0
	for i in range(ch - nech - 1):
		ans += ach[i]
	print(ans)


n = int(input())
s = list(map(int, input().split()))
s.sort()
(ev, odd) = ([], [])
for x in s:
	if x % 2 == 0:
		ev.append(x)
	else:
		odd.append(x)
(p, q) = (len(ev), len(odd))
if p > q:
	print(sum(ev[:-q - 1]))
else:
	print(sum(odd[:-p - 1]))


n = int(input())
li = list(map(int, input().split()))
li1 = []
li2 = []
li.sort()
for i in li:
	if i % 2 == 0:
		li1.append(i)
	else:
		li2.append(i)
l1 = len(li1)
l2 = len(li2)
if l1 == l2 or abs(l1 - l2) == 1:
	print(0)
elif l1 > l2:
	m = l1 - l2 - 1
	print(sum(li1[0:m]))
elif l2 > l1:
	m = l2 - l1 - 1
	print(sum(li2[0:m]))


N = int(input())
a = list(map(int, input().split()))
odds = []
evens = []
for n in a:
	if n % 2 == 0:
		evens.append(n)
	else:
		odds.append(n)
odds.sort()
evens.sort()
lo = len(odds)
le = len(evens)
if abs(lo - le) < 1:
	print(0)
	exit(0)
if lo > le:
	print(sum(odds[0:lo - le - 1]))
else:
	print(sum(evens[0:le - lo - 1]))


t = int(input())
l = list(map(int, input().split()))
asum = sum(l)
ev = []
od = []
(eve, odd) = (0, 0)
for i in l:
	if i % 2 == 0:
		ev.append(i)
		eve += 1
	else:
		od.append(i)
		odd += 1
suml = 0
ev = sorted(ev, reverse=True)
od = sorted(od, reverse=True)
minl = min(eve, odd)
for i in range(minl):
	suml += ev[i] + od[i]
if odd > eve and odd != eve:
	suml += od[minl]
elif odd < eve and odd != eve:
	suml += ev[minl]
print(asum - suml)


x = int(input())
a = list(map(int, input().split()))
even = []
odd = []
new = []
s = 0
suc = True
c = 0
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(even) > len(odd):
	c = 0
else:
	c = 1
even.sort()
odd.sort()
while suc == True:
	if c == 0:
		even.remove(even[-1])
		c = 1
	else:
		odd.remove(odd[-1])
		c = 0
	if len(even) == 0 and c == 0:
		suc = False
	if len(odd) == 0 and c == 1:
		suc = False
new = even + odd
for i in new:
	s = s + i
print(s)


n = int(input())
a = sorted(map(int, input().split()))
b = [[], []]
for i in a:
	b[i % 2].append(i)
if abs(len(b[0]) - len(b[1])) < 2:
	print(0)
else:
	if len(b[1]) < len(b[0]):
		(b[0], b[1]) = (b[1], b[0])
	print(sum(b[1][:len(b[1]) - len(b[0]) - 1]))


R = lambda : map(int, input().split())
n = [*R()][0]
l = [*R()]
(odd, eve) = (sorted([i for i in l if i % 2 == 1]), sorted([i for i in l if i % 2 == 0]))
if len(odd) == len(eve):
	print(0)
elif len(odd) > len(eve):
	print(sum(odd[:len(odd) - len(eve) - 1]))
else:
	print(sum(eve[:len(eve) - len(odd) - 1]))


n = int(input())
l = input().split()
(odd, even) = ([], [])
for x in l:
	if int(x) % 2 == 0:
		even.append(int(x))
	else:
		odd.append(int(x))
even = sorted(even)
odd = sorted(odd)
len_odd = len(odd)
len_even = len(even)
if len_odd > len_even:
	print(sum(odd[:-(len_even + 1)]))
elif len(even) > len(odd):
	print(sum(even[:-(len_odd + 1)]))
else:
	print(0)


n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
a.reverse()
e = []
o = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
if n % 2 == 0:
	if len(e) == len(o):
		print(0)
	elif len(e) > len(o):
		k = 0
		del e[k]
		while len(o) != 0:
			del o[k]
			del e[k]
		print(sum(e) + sum(o))
	else:
		k = 0
		del o[k]
		while len(e) != 0:
			del e[k]
			del o[k]
		print(sum(e) + sum(o))
elif len(e) == len(o) + 1 or len(o) == len(e) + 1:
	print(0)
elif len(e) > len(o) + 1:
	k = 0
	del e[k]
	while len(o) != 0:
		del o[k]
		del e[k]
	print(sum(e) + sum(o))
else:
	k = 0
	del o[k]
	while len(e) != 0:
		del e[k]
		del o[k]
	print(sum(e) + sum(o))


def f(n, arr):
	even = list(filter(lambda x: x % 2 == 0, arr))
	even.sort(reverse=True)
	odd = list(filter(lambda x: x % 2 == 1, arr))
	odd.sort(reverse=True)
	if len(even) - len(odd) > 1:
		return sum(even[len(odd) + 1:])
	elif len(odd) - len(even) > 1:
		return sum(odd[len(even) + 1:])
	else:
		return 0
n = int(input())
arr = list(map(int, input().split()))
print(f(n, arr))


n = int(input())
num = [int(x) for x in input().split()]
even = [x for x in num if x % 2 == 0]
odd = [x for x in num if x % 2 == 1]
start = 1
if len(even) > len(odd):
	start = 0
odd.sort()
even.sort()
while len(even) and len(odd):
	if start:
		odd.pop()
		start = 0
	else:
		even.pop()
		start = 1
if start == 1 and len(odd):
	odd.pop()
if start == 0 and len(even):
	even.pop()
soma = sum(even) + sum(odd)
print(soma)


def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count
L1 = []
L2 = []
n = int(input())
L = [int(x) for x in input().split()]
for i in L:
	c = countSetBits(i)
	if i % 2 == 0:
		L2.append(i)
	else:
		L1.append(i)
L1 = sorted(L1)
L2 = sorted(L2)
status = 0
if len(L1) == len(L2):
	print(0)
	status = 1
elif max(len(L1), len(L2)) - min(len(L1), len(L2)) == 1:
	print(0)
	status = 1
elif len(L1) > len(L2):
	c1 = len(L1) - 1
	c2 = c1 - len(L2)
	Add = 0
	for x1 in range(0, c2):
		Add += L1[x1]
elif len(L2) > len(L1):
	c1 = len(L2) - 1
	c2 = c1 - len(L1)
	Add = 0
	for x2 in range(0, c2):
		Add += L2[x2]
if status == 0:
	print(Add)


n = int(input())
l = list(map(int, input().split()))
chet = 0
nechet = 0
sum_chet = 0
sum_nechet = 0
l_chet = []
l_nechet = []
for i in l:
	if i % 2 == 0:
		chet += 1
		sum_chet += i
		l_chet.append(i)
	else:
		nechet += 1
		sum_nechet += i
		l_nechet.append(i)
l_chet.sort()
l_nechet.sort()
if chet == nechet or chet - 1 == nechet or nechet - 1 == chet:
	print(0)
elif chet > nechet:
	print(sum(l_chet[:chet - nechet - 1]))
else:
	print(sum(l_nechet[:nechet - chet - 1]))


n = int(input())
nums = list(map(int, input().split(' ')))
even = []
odd = []
for i in nums:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort()
odd.sort()
even1 = even.copy()
odd1 = odd.copy()
min1 = 0
min2 = 0
(m, n) = (len(even), len(odd))
for i in range(min(m, n)):
	even.pop()
	odd.pop()
if len(even) != 0:
	even.pop()
min1 = sum(odd) + sum(even)
for i in range(min(m, n)):
	odd1.pop()
	even1.pop()
if len(odd) != 0:
	odd1.pop()
min2 = sum(odd1) + sum(even1)
print(min(min1, min2))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	odd = sorted([x for x in a if x % 2 == 1], reverse=True)
	even = sorted([x for x in a if x % 2 == 0], reverse=True)
	if abs(len(odd) - len(even)) < 2:
		print(0)
	elif len(odd) > len(even):
		print(sum(odd[len(even) + 1:]))
	else:
		print(sum(even[len(odd) + 1:]))
main()


import math
a = int(input())
q = list(input().split())
s = 0
chet = []
nechet = []
for i in range(a):
	if int(q[i]) % 2 == 0:
		chet.append(int(q[i]))
	else:
		nechet.append(int(q[i]))
if max(len(chet), len(nechet)) - min(len(chet), len(nechet)) == 0 or max(len(chet), len(nechet)) - min(len(chet), len(nechet)) == 1:
	print(0)
else:
	nechet.sort()
	chet.sort()
	if len(chet) > len(nechet):
		n = chet
	elif len(chet) < len(nechet):
		n = nechet
	for i in range(max(len(chet), len(nechet)) - min(len(chet), len(nechet)) - 1):
		s += int(n[i])
	print(s)


n = int(input())
a = list(map(int, input().split()))
o = []
e = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
if len(o) == len(e):
	print(0)
	exit()
o.sort()
e.sort()
m = min(len(o), len(e))
if len(o) == m:
	ans = 0
	for i in range(len(e) - (m + 1)):
		ans += e[i]
	print(ans)
	exit()
ans = 0
for i in range(len(o) - (m + 1)):
	ans += o[i]
print(ans)


n = int(input())
L = list(map(int, input().split()))
L = sorted(L)
(odd, even) = ([], [])
for i in range(n):
	if L[i] % 2 == 0:
		even.append(L[i])
	else:
		odd.append(L[i])
if abs(len(odd) - len(even) == 0) or len(odd) - len(even) == 0:
	print('0')
elif len(even) > len(odd):
	sum = 0
	for i in range(len(even) - len(odd) - 1):
		sum += even[i]
	print(sum)
else:
	sum = 0
	for j in range(len(odd) - len(even) - 1):
		sum += odd[j]
	print(sum)


n = int(input())
l = list(map(int, input().split()))
t = []
z = []
ans = 0
for i in l:
	if i % 2 == 0:
		t.append(i)
	else:
		z.append(i)
t.sort()
z.sort()
s = abs(len(t) - len(z))
if s == 0 or s == 1:
	print(0)
elif len(z) > len(t) + 1:
	print(sum(z[:s - 1]))
else:
	print(sum(t[:s - 1]))


n = int(input())
l = list(map(int, input().strip().split(' ')))
l1 = []
l2 = []
summing = 0
for i in l:
	if i % 2 == 0:
		l1.append(i)
	else:
		l2.append(i)
	summing += i
l1.sort(reverse=True)
l2.sort(reverse=True)
length1 = len(l1)
length2 = len(l2)
val = min(length1, length2)
new_sum = 0
for i in range(val):
	new_sum += l1[i] + l2[i]
if length1 == length2:
	print(summing - new_sum)
else:
	if val == length1:
		new_sum += l2[val]
	else:
		new_sum += l1[val]
	print(summing - new_sum)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
even = list(filter(lambda x: x % 2 == 0, A))
odd = list(filter(lambda x: x % 2 != 0, A))
even = sorted(even)
odd = sorted(odd)
evenN = len(even)
oddN = len(odd)
ans = -1
if abs(evenN - oddN) <= 1:
	ans = 0
elif evenN > oddN:
	ans = sum(even[:evenN - oddN - 1])
else:
	ans = sum(odd[:oddN - evenN - 1])
print(ans)


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD = pow(10, 9) + 7

def IN(f=0):
	if f == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = IN(1)
a = IN()
b0 = []
b1 = []
for i in range(n):
	if a[i] % 2 == 0:
		b0.append(a[i])
	else:
		b1.append(a[i])
b0.sort(reverse=True)
b1.sort(reverse=True)
m0 = len(b0)
m1 = len(b1)
if abs(m0 - m1) < 2:
	print(0)
elif m0 > m1:
	print(sum(b0[m1 + 1:]))
else:
	print(sum(b1[m0 + 1:]))


import sys
n = int(sys.stdin.readline())
arr = [int(i) for i in sys.stdin.readline().split()]
c = []
d = []
for i in arr:
	if i % 2 == 0:
		c.append(i)
	else:
		d.append(i)
c.sort()
d.sort()
if abs(len(d) - len(c)) < 2:
	print(0)
elif len(d) == 0 or len(c) == 0:
	if len(d) == 0:
		print(sum(c[:-1]))
	else:
		print(sum(d[:-1]))
elif len(d) > len(c):
	print(sum(d[:-len(c) - 1]))
else:
	print(sum(c[:-len(d) - 1]))


n = int(input())
(x, count, even, z) = (sorted(list(map(int, input().split(' ')))), 0, 0, 1)
for i in x:
	if i % 2 == 0:
		even += 1
odd = n - even
if abs(even - odd) == 1 or odd == even:
	print(0)
	exit()
else:
	if even > odd:
		z = 0
	(i, sum) = (0, 0)
	while count < n - (min(even, odd) * 2 + 1):
		if x[i] % 2 == z:
			sum += x[i]
			count += 1
		i += 1
	print(sum)


n = int(input().strip())
a = list((int(i) for i in input().strip().split(' ')))
e = []
o = []
for each in a:
	if each % 2 == 0:
		e.append(each)
	else:
		o.append(each)
e = sorted(e)
o = sorted(o)
e1 = [i for i in e]
o1 = [i for i in o]
s1 = 0
s2 = 0
if len(e) > 0 and len(o) > 0:
	if e[-1] > o[-1]:
		e.pop()
		p = 1
	else:
		o.pop()
		p = 0
	while True:
		if p == 1 and len(o) > 0:
			o.pop()
			p = 0
		elif p == 0 and len(e) > 0:
			e.pop()
			p = 1
		else:
			break
	for i in e + o:
		s1 += i
	if len(e1) > len(o1):
		e1.pop()
		p = 1
	else:
		o1.pop()
		p = 0
	while True:
		if p == 1 and len(o1) > 0:
			o1.pop()
			p = 0
		elif p == 0 and len(e1) > 0:
			e1.pop()
			p = 1
		else:
			break
	for i in e1 + o1:
		s2 += i
	print(min(s1, s2))
else:
	s = 0
	if len(o) == 0:
		for i in range(len(e) - 1):
			s += e[i]
	else:
		for i in range(len(o) - 1):
			s += o[i]
	print(s)


masodd = []
maseven = []
ans = 0
n = int(input())
e = input()
mas_str = e.split(' ')
for i in range(n):
	ch = int(mas_str[i])
	ans += ch
	if ch % 2 == 1:
		masodd.append(ch)
	else:
		maseven.append(ch)
k = min(len(masodd), len(maseven))
masodd.sort()
maseven.sort()
for i in range(k):
	ans -= masodd[-i - 1]
	ans -= maseven[-i - 1]
if ans != 0:
	if len(masodd) > len(maseven):
		ans -= masodd[-k - 1]
	else:
		ans -= maseven[-k - 1]
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
c = []
s = 0
r = 0
e = 0
d = 0
for i in range(len(a)):
	if a[i] % 2 == 0:
		e += 1
		b.append(a[i])
	else:
		d += 1
		c.append(a[i])
if e > d + 1 and d > 0:
	x = e - d
	for i in range(x - 1):
		s = s + b[i]
	print(s)
elif d > e + 1 and e > 0:
	x = d - e
	for i in range(x - 1):
		s = s + c[i]
	print(s)
elif d == 0:
	for i in range(len(b) - 1):
		s = s + b[i]
	print(s)
elif e == 0:
	for i in range(len(c) - 1):
		s = s + c[i]
	print(s)
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
s1 = [sorted([q for q in a if q % 2 == 0]), sorted([q for q in a if q % 2 == 1])]
s2 = [s1[0][:], s1[1][:]]
start = 0
while len(s1[start]) > 0:
	s1[start].pop()
	start = 1 - start
ans1 = sum(s1[0]) + sum(s1[1])
start = 1
while len(s2[start]) > 0:
	s2[start].pop()
	start = 1 - start
ans2 = sum(s2[0]) + sum(s2[1])
print(min(ans1, ans2))


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
odds = []
evens = []
for num in nums:
	if num % 2 == 0:
		odds.append(num)
	else:
		evens.append(num)
diff = len(odds) - len(evens)
sum = 0
if diff > 1:
	for i in range(diff - 1):
		sum += odds[i]
elif diff < -1:
	for i in range(abs(diff) - 1):
		sum += evens[i]
print(sum)


n = int(input())
eve = []
odd = []
ev = 0
od = 0
s = []
sum1 = 0
d = []
x = list(map(int, input().split()))
for r in x:
	if r % 2 == 0:
		ev = ev + 1
		eve.append(r)
	else:
		od = od + 1
		odd.append(r)
t = ev - od
f = abs(t)
eve.sort()
odd.sort()
if ev == od or abs(ev - od) == 1:
	print('0')
else:
	if t > 0:
		for i in range(f - 1):
			sum1 = 0
			s.append(eve[i])
			for i in range(len(s)):
				sum1 = sum1 + s[i]
	else:
		for i in range(f - 1):
			sum1 = 0
			d.append(odd[i])
			for i in range(len(d)):
				sum1 = sum1 + d[i]
	print(sum1)


def choosing(evens, odds, even):
	(e, o) = (0, 0)
	total = sum(evens) + sum(odds)
	while True:
		if even and e < len(evens):
			total -= evens[e]
			e += 1
			even = not even
		elif not even and o < len(odds):
			total -= odds[o]
			o += 1
			even = not even
		else:
			break
	return total

def solution(arr):
	evens = []
	odds = []
	for a in arr:
		if a % 2 == 0:
			evens.append(a)
		else:
			odds.append(a)
	evens.sort(reverse=True)
	odds.sort(reverse=True)
	return min(choosing(evens, odds, even=True), choosing(evens, odds, even=False))
n = int(input())
arr = [int(i) for i in input().split()]
print(solution(arr))


n = input()
seq = input().split(' ')
seq = [int(element) for element in seq]
seq.sort(reverse=True)
pair = []
impair = []
for element in seq:
	if element % 2 == 0:
		pair.append(element)
	else:
		impair.append(element)
if len(pair) > len(impair):
	pair = pair[len(impair) + 1:]
	print(sum(pair))
elif len(impair) > len(pair):
	impair = impair[len(pair) + 1:]
	print(sum(impair))
else:
	print('0')


n = int(input())
x = list(map(int, input().split()))
y = []
z = []
for i in range(n):
	if x[i] % 2 == 0:
		y.append(x[i])
	else:
		z.append(x[i])
y.sort(reverse=True)
z.sort(reverse=True)
if len(y) > len(z):
	y = y[len(z) + 1:]
	print(sum(y))
else:
	z = z[len(y) + 1:]
	print(sum(z))


num = int(input())
inputs = []
raw = input().split()
inputs = [int(item) for item in raw]
inputs.sort()
even = 0
odd = 0
for item in inputs:
	if item % 2 == 0:
		even += 1
	else:
		odd += 1
result = 0
if even - odd > 1:
	temp = even - odd - 1
	for item in inputs:
		if item % 2 == 0 and temp > 0:
			result += item
			temp -= 1
elif odd - even > 1:
	temp = odd - even - 1
	for item in inputs:
		if item % 2 != 0 and temp > 0:
			result += item
			temp -= 1
print(result)


n = int(input())
O = []
E = []
OO = []
EE = []
p = input().rstrip().split(' ')
for i in range(0, len(p)):
	if int(p[i]) % 2 == 0:
		E.append(int(p[i]))
		EE.append(int(p[i]))
	else:
		O.append(int(p[i]))
		OO.append(int(p[i]))
if len(E) + 1 == len(O) or len(O) + 1 == len(E) or len(O) == len(E):
	print(0)
else:
	O.sort(key=int, reverse=True)
	OO.sort(key=int, reverse=True)
	E.sort(key=int, reverse=True)
	EE.sort(key=int, reverse=True)
	i = 0
	while len(O) != 0 or len(E) != 0:
		if i % 2 == 0:
			if len(O) != 0:
				i += 1
				del O[0]
			else:
				break
		elif len(E) != 0:
			i += 1
			del E[0]
		else:
			break
	G = 0
	while len(OO) != 0 or len(EE) != 0:
		if G % 2 == 0:
			if len(EE) != 0:
				G += 1
				del EE[0]
			else:
				break
		elif len(OO) != 0:
			G += 1
			del OO[0]
		else:
			break
	S = 0
	D = 0
	for i in range(0, len(O)):
		S = S + int(O[i])
	for i in range(0, len(E)):
		S = S + int(E[i])
	for i in range(0, len(OO)):
		D = D + int(OO[i])
	for i in range(0, len(EE)):
		D = D + int(EE[i])
	print(min(S, D))


n = int(input())
a = list(map(int, input().split()))
total_sum = sum(a)
odd = [x for x in a if x % 2 == 1]
even = [x for x in a if x % 2 == 0]
odd.sort(reverse=True)
even.sort(reverse=True)
len1 = len(odd)
len2 = len(even)
m = min(len1, len2)
sum1 = sum(odd[:m])
sum1 += sum(even[:m])
if len1 > m:
	sum1 += odd[m]
if len2 > m:
	sum1 += even[m]
print(total_sum - sum1)


t = int(input(''))
l = [int(x) for x in input().split()]
odd_list = list(filter(lambda x: x % 2 != 0, l))
if len(odd_list) > 0:
	odd_list.sort()
even_list = list(filter(lambda x: x % 2 == 0, l))
if len(even_list) > 0:
	even_list.sort()
if len(odd_list) > len(even_list):
	for i in range(len(even_list)):
		odd_list.pop()
		even_list.pop()
	odd_list.pop()
	if len(odd_list) == 0:
		print(0)
	else:
		print(sum(odd_list))
elif len(odd_list) < len(even_list):
	for i in range(len(odd_list)):
		odd_list.pop()
		even_list.pop()
	even_list.pop()
	if len(even_list) == 0:
		print(0)
	else:
		print(sum(even_list))
else:
	print(0)


N = int(input())
a = list(map(int, input().split()))
odd = [i for i in a if i % 2 != 0]
even = [i for i in a if i % 2 == 0]
nOdd = len(odd)
nEven = len(even)
if abs(nOdd - nEven) < 2:
	print(0)
elif nOdd > nEven:
	num = nOdd - nEven - 1
	odd.sort()
	print(sum(odd[:num]))
else:
	num = nEven - nOdd - 1
	even.sort()
	print(sum(even[:num]))


import heapq
n = int(input())
arr = list(map(int, input().split()))
ch = []
nc = []
for i in arr:
	if i % 2 == 0:
		ch.append(i)
	else:
		nc.append(i)
if len(ch) > len(nc):
	ans = sum(sorted(ch)[:len(ch) - len(nc) - 1])
elif len(ch) < len(nc):
	ans = sum(sorted(nc)[:len(nc) - len(ch) - 1])
else:
	ans = 0
print(ans)


def chot(s, ch):
	while any(list(map(lambda x: x % 2 == 0, s))) and ch or (any(list(map(lambda x: x % 2 == 1, s))) and (not ch)):
		if ch:
			del s[s.index(max(filter(lambda x: x % 2 == 0, s)))]
		else:
			del s[s.index(max(filter(lambda x: x % 2 == 1, s)))]
		ch = not ch
	return sum(s)
n = input()
s = list(map(lambda x: int(x), input().split()))
print(min(chot(s, True), chot(s, False)))


n = int(input())
a = [int(x) for x in input().split()]
odd = []
even = []
for elem in a:
	if elem & 1:
		odd.append(elem)
	else:
		even.append(elem)
odd.sort()
even.sort()
req = min(len(odd), len(even))
len_odd = min(0, req - len(odd))
len_even = min(0, req - len(even))
while len(odd) and len(even):
	odd.pop()
	even.pop()
if len_odd != 0:
	odd.pop()
if len_even != 0:
	even.pop()
ans = 0
for i in odd:
	ans = ans + i
for j in even:
	ans = ans + j
print(ans)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	sm = sum(a)
	even = []
	odd = []
	for i in range(n):
		if a[i] % 2:
			odd.append(a[i])
		else:
			even.append(a[i])
	even = sorted(even)
	odd = sorted(odd)
	l_ev = len(even)
	l_od = len(odd)
	if abs(l_ev - l_od) < 2:
		ans = 0
	else:
		ans = 0
		if l_ev > l_od:
			for i in range(l_ev - l_od - 1):
				ans += even[i]
		else:
			for i in range(-l_ev + l_od - 1):
				ans += odd[i]
	print(ans)
while TN != 0:
	solution()
	TN -= 1


t = int(input())
a = [int(i) for i in input().split()]
a.sort()
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(even) == len(odd):
	print(0)
elif len(even) > len(odd):
	while len(odd) != 0:
		even.pop()
		odd.pop()
	even.pop()
	print(sum(even))
else:
	while len(even) != 0:
		odd.pop()
		even.pop()
	odd.pop()
	print(sum(odd))


from sys import *
input()
q = list(map(int, input().split()))
odd = sorted(filter(lambda x: x % 2 == 0, q))[::-1]
even = sorted(filter(lambda x: x % 2 == 1, q))[::-1]
if len(odd) - len(even) > 1:
	print(sum(odd[len(even) + 1:]))
elif len(odd) - len(even) < -1:
	print(sum(even[len(odd) + 1:]))
else:
	print(0)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = il()
(el, ol) = ([], [])
for i in range(n):
	if l[i] & 1:
		ol.append(l[i])
	else:
		el.append(l[i])
ol.sort(reverse=True)
el.sort(reverse=True)
(l1, l2) = (len(ol), len(el))
if l1 > l2 + 1:
	print(sum(ol[-(l1 - l2 - 1):]))
elif l2 > l1 + 1:
	print(sum(el[-(l2 - l1 - 1):]))
else:
	print(0)


n = int(input())
n1 = []
n2 = []
for n in map(int, input().split()):
	if n % 2 == 0:
		n1.append(n)
	else:
		n2.append(n)
if len(n1) > len(n2):
	print(sum(sorted(n1)[:-(len(n2) + 1)]))
else:
	print(sum(sorted(n2)[:-(len(n1) + 1)]))


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
if abs(len(odd) - len(even)) < 2:
	print(0)
else:
	if len(odd) > len(even):
		odd.sort()
		s = sum(odd[0:len(odd) - len(even) - 1])
	else:
		even.sort()
		s = sum(even[0:len(even) - len(odd) - 1])
	print(s)


n = int(input())
a = [int(x) for x in input().split()]
odd = []
even = []
for i in a:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
t = sum(odd) + sum(even)
k = min(len(odd), len(even))
t -= sum(odd[:k])
t -= sum(even[:k])
if len(odd) > k:
	t -= odd[k]
elif len(even) > k:
	t -= even[k]
print(t)


import sys
import math
import bisect
import itertools
import random

def main():
	n = int(input())
	A = []
	B = []
	for a in list(map(int, input().split())):
		if a % 2 == 0:
			A.append(a)
		else:
			B.append(a)
	A.sort(reverse=True)
	B.sort(reverse=True)
	n = len(A)
	m = len(B)
	if n == m:
		print(0)
	elif n > m:
		print(sum(A[m + 1:]))
	else:
		print(sum(B[n + 1:]))
main()


n = int(input())
l = [int(x) for x in input().split()]
even = []
odd = []
for i in range(n):
	if l[i] % 2 == 0:
		even.append(l[i])
	else:
		odd.append(l[i])
e = len(even)
o = len(odd)
even.sort()
odd.sort()
if e == 0:
	print(sum(odd[:-1]))
elif o == 0:
	print(sum(even[:-1]))
elif e - o == 0:
	print('0')
elif e - o == 1 or o - e == 1:
	print('0')
elif e > o:
	print(sum(even[:e - o - 1]))
else:
	print(sum(odd[:o - e - 1]))


n = int(input())
ar = list(map(int, input().split()))
total = sum(ar)
chet = sorted([x for x in ar if x % 2 == 0], reverse=True)
nechet = sorted([x for x in ar if x % 2 != 0], reverse=True)
idx1 = 0
idx2 = 0
op = 'chet'
while idx1 < len(chet) and idx2 < len(nechet):
	total -= chet[idx1]
	op = 'nechet'
	total -= nechet[idx2]
	op = 'chet'
	idx1 += 1
	idx2 += 1
if op == 'chet' and idx1 < len(chet):
	total -= chet[idx1]
if op == 'nechet' and idx2 < len(nechet):
	total -= nechet[idx2]
min_tot = total
total = sum(ar)
op = 'nechet'
idx1 = 0
idx2 = 0
while idx1 < len(chet) and idx2 < len(nechet):
	total -= nechet[idx2]
	op = 'chet'
	total -= chet[idx1]
	op = 'nechet'
	idx1 += 1
	idx2 += 1
if op == 'chet' and idx1 < len(chet):
	total -= chet[idx1]
if op == 'nechet' and idx2 < len(nechet):
	total -= nechet[idx2]
print(min(min_tot, total))


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
odd = sorted([i for i in arr if i % 2 == 1])
even = sorted([i for i in arr if i % 2 == 0])
for i in range(min(len(odd), len(even))):
	odd.pop()
	even.pop()
if len(odd) >= 1:
	odd.pop()
elif len(even) >= 1:
	even.pop()
print(sum(odd) + sum(even))


n = int(input())
odd = list(map(int, input().split()))
even = []
oddnew = []
oddlen = len(odd)
for i in range(oddlen):
	if odd[-1] % 2 == 0:
		even.append(odd.pop())
	else:
		oddnew.append(odd.pop())
odd = sorted(oddnew)
even = sorted(even)
oddlen = len(oddnew)
evenlen = len(even)
diff = abs(oddlen - evenlen)
if diff == 1 or diff == 0:
	print(0)
elif oddlen > evenlen:
	oddlen -= 1
	print(sum(odd[:oddlen - evenlen]))
else:
	evenlen -= 1
	print(sum(even[:evenlen - oddlen]))


N = input()
sequence = input().split()
oddSequence = []
evenSequence = []
total = 0
for number in sequence:
	placed = False
	number = int(number)
	if number % 2 == 0:
		for index in range(len(evenSequence)):
			if not placed:
				even = evenSequence[index]
				if number < even:
					evenSequence.insert(index, number)
					placed = True
		if not placed:
			evenSequence.append(number)
	else:
		for index in range(len(oddSequence)):
			if not placed:
				odd = oddSequence[index]
				if number < odd:
					oddSequence.insert(index, number)
					placed = True
		if not placed:
			oddSequence.append(number)
	total = total + number
oddLength = len(oddSequence)
evenLength = len(evenSequence)
deleteType = 0
deletion = oddLength
if evenLength < deletion:
	deletion = evenLength
	deleteType = 1
if oddLength - deletion - deleteType <= 0:
	oddSequenceSum = 0
else:
	oddSequenceSum = sum(oddSequence[:oddLength - deletion - deleteType])
if evenLength - deletion - (1 - deleteType) <= 0:
	evenSequenceSum = 0
else:
	evenSequenceSum = sum(evenSequence[:evenLength - deletion - (1 - deleteType)])
total = oddSequenceSum + evenSequenceSum
output = '%s' % total
print(output)


n = int(input())
a = sorted(list(map(int, input().split())))
even = sum((1 for i in a if i % 2 == 0))
odd = n - even
if even == odd or even + 1 == odd or even == odd + 1:
	print(0)
else:
	if even > odd:
		even = even - odd - 1
		ans = 0
		for i in a:
			if even == 0:
				break
			if i % 2 == 0:
				ans += i
				even -= 1
	else:
		odd = odd - even - 1
		ans = 0
		for i in a:
			if odd == 0:
				break
			if i % 2 != 0:
				ans += i
				odd -= 1
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
(evens, odds) = ([], [])
for i in arr:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens.sort(reverse=True)
odds.sort(reverse=True)
if len(evens) >= len(odds):
	while evens and odds:
		evens.pop(0)
		odds.pop(0)
	if len(odds) == 0:
		e = 0 if len(evens) == 0 else evens.pop(0)
		summ = sum(evens) if len(evens) > 0 else 0
		print(summ)
	else:
		summ = sum(evens) if len(evens) > 0 else 0
		summ += sum(odds) if len(odds) > 0 else 0
		print(summ)
else:
	while evens and odds:
		odds.pop(0)
		evens.pop(0)
	if len(evens) == 0:
		e = 0 if len(odds) == 0 else odds.pop(0)
		summ = sum(odds) if len(odds) > 0 else 0
		print(summ)
	else:
		summ = sum(evens) if len(evens) > 0 else 0
		summ += sum(odds) if len(odds) > 0 else 0
		print(summ)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
(odd, even) = ([], [])
for num in a:
	if num % 2 == 1:
		odd.append(num)
	else:
		even.append(num)
tmp = min(len(odd), len(even))
result = sum(a) - sum(odd[:tmp]) - sum(even[:tmp])
if len(odd) != len(even):
	result -= odd[tmp] if len(odd) > len(even) else even[tmp]
print(result)


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in a:
	if i % 2 == 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
index = abs(len(odd) - len(even))
sum = 0
if index == 0 or index == 1:
	pass
elif len(odd) > len(even):
	for i in range(index - 1):
		sum += odd[i]
else:
	for i in range(index - 1):
		sum += even[i]
print(sum)


def input_ints():
	return list(map(int, input().split()))

def main():
	n = int(input())
	a = input_ints()
	a.sort()
	odd = [x for x in a if x % 2 == 1]
	even = [x for x in a if x % 2 == 0]
	if len(odd) >= len(even):
		x = max(0, len(odd) - len(even) - 1)
		ans = sum(odd[:x])
	else:
		ans = sum(even[:len(even) - len(odd) - 1])
	print(ans)
main()


n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
l.sort()
for i in l:
	if i % 2 == 0:
		l1.append(i)
	else:
		l2.append(i)
mx = max(l)
d = 0
if len(l1) > len(l2):
	d = 0
else:
	d = 1
for i in range(n):
	if d % 2 == 0:
		if not l1:
			break
		del l1[-1]
	else:
		if not l2:
			break
		del l2[-1]
	d += 1
print(sum(l1) + sum(l2))


gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
l = gi()
ev = [e for e in l if e % 2 == 0]
od = [e for e in l if e % 2 == 1]
ev.sort(reverse=True)
od.sort(reverse=True)
if len(ev) > len(od):
	s = sum(ev[:len(od) + 1])
	s += sum(od)
	ans = sum(l) - s
elif len(od) > len(ev):
	s = sum(od[:len(ev) + 1])
	s += sum(ev)
	ans = sum(l) - s
else:
	ans = 0
print(ans)


n = int(input())
s = list(map(int, str(input()).split()))
s = sorted(s)
s = s[::-1]
sp = [x for x in s if x % 2 == 0]
si = [x for x in s if x % 2 == 1]
if abs(len(sp) - len(si)) < 2:
	print(0)
else:
	if len(sp) > len(si):
		print(sum(sp[len(si) + 1:]))
	if len(si) > len(sp):
		print(sum(si[len(sp) + 1:]))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	(odd_count, even_count) = (0, 0)
	odd = []
	even = []
	for x in a:
		if x % 2:
			odd.append(x)
			odd_count += 1
		else:
			even.append(x)
			even_count += 1
	res = 0
	if odd_count < even_count:
		if odd_count + 1 == even_count:
			res = 0
		else:
			temp = even_count - odd_count - 1
			even.sort()
			res = sum(even[:temp])
	elif odd_count > even_count:
		if even_count + 1 == odd_count:
			res = 0
		else:
			temp = odd_count - even_count - 1
			odd.sort()
			res = sum(odd[:temp])
	else:
		res = 0
	print(res)
main()


n = int(input())
s = [int(i) for i in input().split()]
a = []
b = []
for i in s:
	if i % 2 == 0:
		a.append(i)
	else:
		b.append(i)
a.sort()
b.sort()
c = 0
if len(a) < len(b):
	for i in range(0, len(b) - len(a) - 1):
		c = c + b[i]
elif len(a) > len(b):
	for i in range(0, len(a) - len(b) - 1):
		c = c + a[i]
else:
	c = 0
print(c)


n = int(input())
arr = list(map(int, input().split()))
(even, odd) = ([], [])
for i in arr:
	if i % 2 == 0:
		even += [i]
	else:
		odd += [i]
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd):
	print(0)
	return
elif len(even) < len(odd):
	(even, odd) = (odd, even)
even.pop()
while even and odd:
	even.pop()
	odd.pop()
print(sum(even))


n = int(input())
lis = list(map(int, input().split()))
e = []
o = []
for i in lis:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
diff = len(e) - len(o)
summ = 0
if diff == 0 or diff == -1 or diff == 1:
	print(0)
else:
	if diff > 0:
		e.sort()
		for i in range(0, diff - 1):
			summ = summ + e[i]
	else:
		diff = -1 * diff
		o.sort()
		for i in range(0, diff - 1):
			summ = summ + o[i]
	print(summ)


n = int(input())
mas = input().split(' ')
for i in range(n):
	mas[i] = int(mas[i])
mas.sort()
chet = []
nechet = []
for i in range(n):
	if mas[i] % 2 == 0:
		chet.append(mas[i])
	else:
		nechet.append(mas[i])
if len(chet) > len(nechet):
	print(sum(chet[:len(chet) - len(nechet) - 1]))
elif len(chet) < len(nechet):
	print(sum(nechet[:len(nechet) - len(chet) - 1]))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
(even, odd) = ([], [])
for s in a:
	if s % 2 == 0:
		even.append(s)
	else:
		odd.append(s)
even.sort(reverse=True)
odd.sort(reverse=True)
diff = len(even) - len(odd)
ans = 0
if diff > 1:
	print(sum(even[-diff + 1:]))
elif diff < -1:
	print(sum(odd[diff + 1:]))
else:
	print(0)


t = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = []
l2 = []
for i in l:
	if i % 2 == 0:
		l1.append(i)
	else:
		l2.append(i)
x = abs(len(l1) - len(l2)) - 1
if x == 0:
	print(x)
elif x > 0 and len(l1) > len(l2):
	print(sum(l1[:x]))
elif x > 0 and len(l1) < len(l2):
	print(sum(l2[:x]))
elif x < 0 and len(l1) == len(l2):
	print(0)


n = int(input())
a = list(map(int, input().split(' ')))
o = []
e = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
en = len(e)
on = len(o)
e.sort(reverse=True)
o.sort(reverse=True)
m = min(en, on)
s = 0
if en < on:
	s = sum(o[m + 1:])
elif en > on:
	s = sum(e[m + 1:])
print(s)


n = int(input())
a = [int(x) for x in input().split()]
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
lene = len(even)
leno = len(odd)
ans = 0
if abs(lene - leno) < 2:
	print(0)
elif lene > leno:
	n = 0
	while n != lene - leno - 1:
		k = min(even)
		ans += k
		even.remove(k)
		n += 1
	print(ans)
else:
	n = 0
	while n != leno - lene - 1:
		k = min(odd)
		ans += k
		odd.remove(k)
		n += 1
	print(ans)


import sys
n = int(input())
a = [int(c) for c in input().split()]
evens = [i for i in a if i % 2 == 0]
odds = [i for i in a if i % 2 != 0]
evens.sort()
odds.sort()
if abs(len(evens) - len(odds)) <= 1:
	print(0)
elif len(evens) > len(odds):
	print(sum(evens[:len(evens) - len(odds) - 1]))
else:
	print(sum(odds[:len(odds) - len(evens) - 1]))


n = int(input())
lis = list(map(int, input().split()))
e = []
o = []
for i in lis:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
le = len(e)
lo = len(o)
e = e + [0]
o = o + [0]
e.sort(reverse=True)
o.sort(reverse=True)
k = min(lo, le)
i = 0
while i < k:
	e[i] = 0
	o[i] = 0
	i += 1
m = max(e[i], o[i])
print(sum(e) + sum(o) - m)


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in arr:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
if len(even) == len(odd):
	print(0)
elif len(even) > len(odd):
	ans = 0
	if len(even) - (len(odd) + 1) == 0:
		print(ans)
	else:
		ind = len(even) - (len(odd) + 1)
		for i in range(1, ind + 1):
			ans = ans + even[-i]
		print(ans)
else:
	ans = 0
	if len(odd) - (len(even) + 1) == 0:
		print(ans)
	else:
		ind = len(odd) - (len(even) + 1)
		for i in range(1, ind + 1):
			ans = ans + odd[-i]
		print(ans)


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	even = []
	odd = []
	for i in range(n):
		if arr[i] % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	even.sort(reverse=True)
	odd.sort(reverse=True)
	if len(even) > len(odd):
		f = even
		s = odd
	else:
		f = odd
		s = even
	diff = len(f) - len(s) - 1
	if diff <= 0:
		print(0)
		return
	else:
		print(sum(f[-diff::1]))
t = 1
for _ in range(t):
	main()


input()
nums = [int(i) for i in input().split(' ')]
odds = []
evens = []
for i in nums:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
odds.sort()
evens.sort()
l = len(odds) - len(evens)
if l > 1:
	print(sum(odds[:l - 1]))
elif l < -1:
	print(sum(evens[:-l - 1]))
else:
	print(0)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = scan_int()
	a = read_list()
	even = []
	odd = []
	for x in a:
		if x % 2 == 0:
			even.append(x)
		else:
			odd.append(x)
	even.sort()
	odd.sort()
	if len(odd) == n // 2 or len(even) == n // 2:
		print(0)
		return
	elif len(even) > len(odd):
		while True:
			even.pop()
			if len(odd) == 0:
				break
			odd.pop()
		print(sum(even))
	else:
		while True:
			odd.pop()
			if len(even) == 0:
				break
			even.pop()
		print(sum(odd))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


n = int(input())
a = [int(s) for s in input().split()]
(os, es) = (0, 0)
for ai in a:
	if ai % 2 == 0:
		es += 1
	else:
		os += 1
ans = 0
if es > os:
	es -= 1
elif os > es:
	os -= 1
if es != os:
	rem = 0
	if os > es:
		rem = 1
	k = abs(es - os)
	nums = [ai for ai in a if ai % 2 == rem]
	nums.sort()
	ans = sum(nums[0:k])
print(ans)


n = int(input())
inp = input()
jor = []
bijor = []
cjor = 0
cbijor = 0
for i in range(0, n):
	allinp = inp.split(' ')
for j in range(0, n):
	if int(allinp[j]) % 2 == 0:
		jor.append(int(allinp[j]))
		cjor += 1
	else:
		bijor.append(int(allinp[j]))
		cbijor += 1
all = sum(jor) + sum(bijor)
chk = 0
if cjor == cbijor or cjor - 1 == cbijor or cjor == cbijor - 1:
	print('0')
else:
	if sum(jor) > sum(bijor):
		while len(jor) != 0 or len(bijor) != 0:
			if len(jor) != 0:
				all -= max(jor)
				jor.remove(max(jor))
			else:
				chk = 1
			if len(bijor) != 0:
				all -= max(bijor)
				bijor.remove(max(bijor))
			else:
				chk = 1
			if chk == 1:
				break
	else:
		while len(jor) != 0 or len(bijor) != 0:
			if len(bijor) != 0:
				all -= max(bijor)
				bijor.remove(max(bijor))
			else:
				chk = 1
			if len(jor) != 0:
				all -= max(jor)
				jor.remove(max(jor))
			else:
				chk = 1
			if chk == 1:
				break
	print(all)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(b, c) = (0, 0)
d = []
e = []
for i in range(len(a)):
	if a[i] & 1:
		b += 1
		d.append(a[i])
	else:
		c += 1
		e.append(a[i])
d.sort()
e.sort()
if b == c - 1 or c == b - 1 or b == c:
	print('0')
elif b == len(a) or c == len(a):
	print(sum(a[0:len(a) - 1]))
elif b > c:
	print(sum(d[0:b - c - 1]))
else:
	print(sum(e[0:c - b - 1]))


input()
arr = [*map(int, input().split())]
last = -1
if len(arr) == 1:
	print(0)
else:
	evens = [*sorted([i for i in arr if i % 2 == 0], reverse=True)]
	odds = [*sorted([i for i in arr if i % 2 != 0], reverse=True)]
	if len(odds) == len(evens):
		print(0)
	elif len(odds) == 0 or len(evens) == 0:
		if len(odds) == 0:
			print(sum(evens[1:]))
		else:
			print(sum(odds[1:]))
	elif len(odds) > len(evens):
		print(sum(odds[len(evens) + 1:]))
	else:
		print(sum(evens[len(odds) + 1:]))


n = int(input())
l = list(map(int, input().split()))
lo = []
le = []
no = 0
ne = 0
for j in range(n):
	if l[j] % 2 == 0:
		le.append(l[j])
		ne += 1
	else:
		lo.append(l[j])
		no += 1
lo.sort(reverse=True)
le.sort(reverse=True)
if no - ne == 1 or no - ne == -1 or no - ne == 0:
	print(0)
else:
	s = sum(l)
	if ne > no:
		s = s - sum(lo)
		for j in range(no + 1):
			s = s - le[j]
		print(s)
	else:
		s = s - sum(le)
		for j in range(ne + 1):
			s = s - lo[j]
		print(s)


import sys
input = sys.stdin.readline
n = input().rstrip()
poly = list(map(int, input().split()))
removed = ''
odds = list()
evens = list()
for i in poly:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
l_o = len(odds)
l_e = len(evens)
if abs(len(odds) - len(evens)) <= 1:
	print(0)
elif l_o == 0 or l_e == 0:
	if l_o == 0:
		print(sum(evens) - max(evens))
	elif l_e == 0:
		print(sum(odds) - max(odds))
else:
	if len(odds) < len(evens):
		evens.remove(max(evens))
		removed = 'e'
	if len(odds) > len(evens):
		odds.remove(max(odds))
		removed = 'o'
	if len(odds) == len(evens):
		if max(odds) > max(evens):
			odds.remove(max(odds))
			removed = 'o'
		else:
			evens.remove(max(evens))
			removed = 'e'
	while len(odds) != 0 and len(evens) != 0:
		if removed == 'o':
			evens.remove(max(evens))
			removed = 'e'
		else:
			odds.remove(max(odds))
			removed = 'o'
	if removed == 'o' and evens != []:
		evens.remove(max(evens))
	if removed == 'e' and odds != []:
		odds.remove(max(odds))
	print(sum(odds) + sum(evens))


n = int(input())
a = [int(item) for item in input().split()]
a.sort()
o = [x for x in a if x % 2][::-1]
e = [x for x in a if x % 2 == 0][::-1]
l = min(len(o), len(e))
if len(o) < len(e):
	d = sum(o) + sum(e[:l + 1])
else:
	d = sum(e) + sum(o[:l + 1])
print(sum(a) - d)


n = int(input())
l = list(map(int, input().split()))
(e, o) = ([], [])
l.sort()
l = l[::-1]
for i in l:
	if i & 1:
		o.append(i)
	else:
		e.append(i)
if len(e) == len(o):
	print(0)
else:
	m = min(len(e), len(o))
	if len(e) < len(o):
		e = []
		for i in range(m + 1):
			o.pop(0)
		print(sum(o))
	else:
		o = []
		for i in range(m + 1):
			e.pop(0)
		print(sum(e))


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
k = [x for x in a if x % 2 == 0]
z = [x for x in a if x % 2 == 1]
k.sort()
z.sort()
if len(z) == len(k):
	print(0)
elif len(z) > len(k):
	print(sum(z[:len(z) - len(k) - 1]))
else:
	print(sum(k[:len(k) - len(z) - 1]))


def minim_cf():
	n = int(input())
	m = list(map(int, input().split()))
	os = []
	es = []
	for i in range(len(m)):
		if m[i] % 2 == 0:
			es.append(m[i])
		else:
			os.append(m[i])
	os.sort()
	es.sort()
	oe = len(os) - len(es)
	eo = len(es) - len(os)
	if oe > 1:
		d = oe - 1
		return sum(os[:d])
	elif eo > 1:
		d = eo - 1
		return sum(es[:d])
	else:
		return 0
print(minim_cf())


x = int(input())
p = list(sorted(map(int, input().split())))
(sm, od, ev, lo, le) = (sum(p), [], [], 0, 0)
for i in p:
	if i % 2 == 0:
		ev.append(i)
		le += 1
	else:
		od.append(i)
		lo += 1
if lo == le:
	print(0)
elif lo > le:
	if le + 1 == lo:
		print(0)
	else:
		print(sum(od[:lo - (le + 1)]))
elif le > lo:
	if lo + 1 == le:
		print(0)
	else:
		print(sum(ev[:le - (lo + 1)]))


import heapq

def solve(numbers, parity):
	even_numbers = [-n for n in numbers if n % 2 == 0]
	heapq.heapify(even_numbers)
	odd_numbers = [-n for n in numbers if n % 2 == 1]
	heapq.heapify(odd_numbers)

	def remove_element(some_numbers):
		if len(some_numbers) == 0:
			return True
		heapq.heappop(some_numbers)
		return False
	stop = False
	while not stop:
		if parity == 0:
			stop = remove_element(even_numbers)
		elif parity == 1:
			stop = remove_element(odd_numbers)
		parity = 1 - parity
	return -sum(even_numbers) - sum(odd_numbers)

def main():
	n = int(input().strip())
	numbers = list(map(int, input().strip().split()))
	even_r = solve(numbers, 0)
	odd_r = solve(numbers, 1)
	print(min(even_r, odd_r))
main()


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_elements = RI()
elements = RMI()
odds = []
even = []
for i in elements:
	if i % 2:
		odds.append(i)
	else:
		even.append(i)
odds = sorted(odds, reverse=True)
even = sorted(even, reverse=True)
leno = len(odds)
lene = len(even)
if leno > lene:
	print(sum(odds[lene + 1:]))
else:
	print(sum(even[leno + 1:]))


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
for i in l:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
num = min(len(o), len(e))
r = 0
if len(o) > len(e):
	l1 = num + 1
	l2 = num
elif len(e) > len(o):
	l1 = num
	l2 = num + 1
else:
	r = 1
if r == 0:
	for i in range(l1):
		o.remove(max(o))
	for i in range(l2):
		e.remove(max(e))
	print(sum(o) + sum(e))
else:
	print('0')


n = int(input())
l = [int(x) for x in input().split()]
l1 = []
l2 = []
for i in l:
	if i % 2 == 1:
		l1.append(i)
	else:
		l2.append(i)
l1.sort()
l2.sort()
l1.reverse()
l2.reverse()
if len(l1) == len(l2):
	for i in range(len(l2)):
		del l1[0]
		del l2[0]
elif len(l1) > len(l2):
	for i in range(len(l2)):
		del l1[0]
		del l2[0]
	del l1[0]
else:
	for i in range(len(l1)):
		del l1[0]
		del l2[0]
	del l2[0]
print(sum(l1) + sum(l2))


n = int(input())
a = list(map(int, input().split()))
a.sort()
o = list(filter(lambda x: x % 2 == 1, a))
e = list(filter(lambda x: x % 2 == 0, a))
if len(o) == len(e):
	print('0')
	quit()
if len(o) > len(e):
	x = len(o) - len(e) - 1
	s = 0
	for i in range(x):
		s += o[i]
	print(s)
	quit()
else:
	x = len(e) - len(o) - 1
	s = 0
	for i in range(x):
		s += e[i]
	print(s)
	quit()


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in range(n):
	if a[i] % 2 == 0:
		b.append(a[i])
	else:
		c.append(a[i])
b = sorted(b)
c = sorted(c)
if len(b) == len(c):
	print(0)
elif len(b) - len(c) == 1 or len(b) - len(c) == -1:
	print(0)
elif len(b) > len(c):
	k = len(b) - len(c)
	print(sum(b[0:k - 1]))
else:
	k = len(c) - len(b)
	print(sum(c[0:k - 1]))


n = int(input())
A = list(map(int, input().split()))
E = []
O = []
for a in A:
	if a % 2 == 0:
		E.append(a)
	else:
		O.append(a)
if len(E) >= len(O):
	if len(E) - len(O) <= 1:
		print(0)
	else:
		E.sort()
		print(sum(E[0:len(E) - len(O) - 1]))
elif len(O) - len(E) <= 1:
	print(0)
else:
	O.sort()
	print(sum(O[0:len(O) - len(E) - 1]))


n = int(input())
l = list(map(int, input().split()))
l.sort()
odds = [o for o in l if o % 2 == 1]
evens = [e for e in l if e % 2 == 0]
odds2 = [o for o in l if o % 2 == 1]
evens2 = [e for e in l if e % 2 == 0]
flag = True
while len(odds) >= 0 and len(evens) >= 0:
	if flag:
		if len(odds) == 0:
			break
		odds.pop()
	else:
		if len(evens) == 0:
			break
		evens.pop()
	flag = not flag
flag = False
while len(odds2) >= 0 and len(evens2) >= 0:
	if flag:
		if len(odds2) == 0:
			break
		odds2.pop()
	else:
		if len(evens2) == 0:
			break
		evens2.pop()
	flag = not flag
print(min(sum(odds) + sum(evens), sum(odds2) + sum(evens2)))


z = input
z()
l = sorted(map(int, z().split()))
l = l[::-1]
e = []
o = []
for i in l:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
om = len(o)
em = len(e)
c = min(om, em)
if om > em:
	l1 = o[c + 1:] + e[c:]
elif em > om:
	l1 = e[c + 1:] + o[c:]
else:
	l1 = [0]
print(sum(l1))


num = int(input())
num_list = list(map(int, input().split()))
odd = []
even = []
for i in num_list:
	if i % 2 == 1:
		even.append(i)
	else:
		odd.append(i)
odd.sort(reverse=False)
even.sort(reverse=False)
num_diff = len(odd) - len(even)
if abs(num_diff) <= 1:
	print(0)
elif num_diff > 1:
	print(sum(odd[:abs(num_diff) - 1]))
else:
	print(sum(even[:abs(num_diff) - 1]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
ev = []
od = []
re = []
for i in a:
	if i % 2 == 0:
		ev.append(i)
	else:
		od.append(i)
if len(ev) > len(od):
	re = ev[:len(ev) - 1 - len(od)]
elif len(ev) < len(od):
	re = od[:len(od) - 1 - len(ev)]
else:
	re = [0]
print(sum(re))


n = int(input())
a = list(map(int, input().split()))
(e, el) = ([], 0)
(o, ol) = ([], 0)
for i in a:
	if i % 2 == 0:
		e.append(i)
		el = el + 1
	else:
		o.append(i)
		ol = ol + 1
e = sorted(e, reverse=True, key=int)
o = sorted(o, reverse=True, key=int)
if el < ol:
	print(sum(o[min(el, ol) + 1:]))
elif el > ol:
	print(sum(e[min(el, ol) + 1:]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split(' ')))
even = [x for x in l if x % 2 == 0]
odd = [x for x in l if x % 2 == 1]
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd) or abs(len(even) - len(odd)) == 1:
	print(0)
elif len(odd) == 0:
	print(sum(even[:-1]))
elif len(even) == 0:
	print(sum(odd[:-1]))
else:
	l1 = len(even)
	l2 = len(odd)
	if l2 > l1:
		print(sum(odd[:l2 - l1 - 1]))
	else:
		print(sum(even[:l1 - l2 - 1]))


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	n = int(input())
	arr = get_array()
	odd = []
	even = []
	arr.sort()
	for i in arr:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	i = len(odd)
	j = len(even)
	while i > 0 and j > 0:
		odd.pop()
		even.pop()
		i -= 1
		j -= 1
	if len(odd) != 0:
		odd.pop()
	elif len(even) != 0:
		even.pop()
	print(sum(odd) + sum(even))
main()


from sys import stdin, stdout
get = stdin.readline
put = stdout.write
(n, a) = (int(get()), list(map(int, get().split())))
e = []
o = []
for i in a:
	if i % 2:
		o.append(i)
	else:
		e.append(i)
m = min(len(o), len(e))
o = sum(sorted(o)[::-1][m + 1:])
e = sum(sorted(e)[::-1][m + 1:])
put(str(e + o if e + o else 0))


x = int(input())
y = [int(x) for x in input().split()]
a = []
b = []
for i in y:
	if i % 2 == 0:
		a.append(i)
	else:
		b.append(i)
aa = len(a)
a = sorted(a)
bb = len(b)
b = sorted(b)
if len(a) == len(b) or aa == bb + 1 or bb == aa + 1:
	print(0)
elif len(a) == 0:
	b.pop()
	print(sum(b))
elif len(b) == 0:
	a.pop()
	print(sum(a))
elif len(a) > len(b):
	for i in range(bb + 1):
		a.pop()
	print(sum(a))
elif len(b) > len(a):
	for i in range(aa + 1):
		b.pop()
	print(sum(b))


n = int(input())
a = sorted(list(map(int, input().split())))
(z, x, s, m) = (0, 0, 0, 0)
for i in a:
	if i % 2 == 0:
		z += 1
	else:
		x += 1
if z - x - 1 > 0:
	for i in a:
		if i % 2 == 0:
			s += i
			m += 1
		if m == z - x - 1:
			print(s)
			break
elif x - z - 1 > 0:
	for i in a:
		if i % 2 != 0:
			s += i
			m += 1
		if m == x - z - 1:
			print(s)
			break
else:
	print(0)


n = int(input())
a = sorted(list(map(int, input().split())))
(no, ne) = (0, 0)
for i in a:
	if i & 1:
		no += 1
	else:
		ne += 1
s = 0
if ne - no >= 2:
	x = ne - no - 1
	for i in a:
		if i & 1 == 0:
			s += i
			x -= 1
		if x == 0:
			break
elif no - ne >= 2:
	x = no - ne - 1
	for i in a:
		if i & 1:
			s += i
			x -= 1
		if x == 0:
			break
print(s)


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
l.sort()
for i in l:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
e.reverse()
o.reverse()
if len(e) >= len(o):
	c = 0
else:
	c = 1
while n:
	if c % 2 == 0 and len(e) > 0:
		e.pop(0)
		c = c + 1
	elif c % 2 != 0 and len(o) > 0:
		o.pop(0)
		c = c + 1
	else:
		break
	n = n - 1
s1 = 0
for i in e:
	s1 = s1 + i
s2 = 0
for j in o:
	s2 = s2 + j
print(s1 + s2)


n = int(input())
l = list(map(int, input().split()))
(odd, even) = ([], [])
for i in range(n):
	if l[i] % 2 == 0:
		even.append(l[i])
	else:
		odd.append(l[i])
even.sort()
odd.sort()
even.reverse()
odd.reverse()
if len(odd) == 0 and len(even) > 0:
	print(sum(even[1:]))
	exit()
if len(even) == 0 and len(odd) > 0:
	print(sum(odd[1:]))
	exit()
if abs(len(odd) - len(even)) == 1:
	print(0)
	exit()
if len(odd) > len(even):
	print(sum(odd[len(even) + 1:]))
	exit()
if len(even) > len(odd):
	print(sum(even[len(odd) + 1:]))
	exit()
print(0)


a = int(input())
elements = list(map(int, input().split()))
elements.sort(reverse=True)
evens = []
odds = []
for i in elements:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
k = 0
if len(odds) > len(evens) + 1:
	print(sum(odds[len(evens) + 1:]))
elif len(evens) > len(odds) + 1:
	print(sum(evens[len(odds) + 1:]))
else:
	print(0)


n = int(input())
array = list(map(int, input().split()))
array = sorted(array)
even = []
odd = []
sum = 0
for i in array:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(even) > len(odd):
	for i in range(len(even) - len(odd) - 1):
		sum += even[i]
	print(sum)
elif len(even) < len(odd):
	for i in range(len(odd) - len(even) - 1):
		sum += odd[i]
	print(sum)
else:
	print('0')


n = int(input())
a = [int(elem) for elem in input().split()]
ch = []
nec = []
ans = 0
for i in range(n):
	ans += a[i]
	if a[i] % 2 == 0:
		ch.append(a[i])
	else:
		nec.append(a[i])
ch.sort()
nec.sort()
k = min(len(ch), len(nec))
sum1 = 0
sum2 = 0
for i in range(len(ch) - 1, len(ch) - k - 1, -1):
	sum1 += ch[i]
for i in range(len(nec) - 1, len(nec) - k - 1, -1):
	sum2 += nec[i]
if len(ch) - k > 0:
	sum1 += ch[len(ch) - k - 1]
elif len(nec) - k > 0:
	sum2 += nec[len(nec) - k - 1]
print(ans - sum1 - sum2)


t = int(input())
kp = list(map(int, input().split()))
even = []
odd = []
for ab in range(t):
	if kp[ab] % 2 == 0:
		even.append(kp[ab])
	else:
		odd.append(kp[ab])
even = sorted(even)
odd = sorted(odd)
if abs(len(odd) - len(even)) <= 1:
	print(0)
elif len(odd) > len(even):
	q = len(odd) - len(even) - 1
	print(sum(odd[:q]))
else:
	q = len(even) - len(odd) - 1
	print(sum(even[:q]))


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if arr[i] & 1:
		odd.append(arr[i])
	else:
		even.append(arr[i])
odd.sort()
even.sort()
times = min(len(odd), len(even)) + 1
smo = 0
for i in range(len(odd) - times):
	smo += odd[i]
sme = 0
for i in range(len(even) - times):
	sme += even[i]
print(max(sme, smo))


n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
(even, odd) = ([], [])
for i in l:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
(o, e) = (len(odd), len(even))
m = min(o, e)
if o > m + 1:
	print(sum(odd[:o - m - 1]))
elif e > m + 1:
	print(sum(even[:e - m - 1]))
else:
	print(0)


num = input()
num = int(num)
a = input().split()
a = [int(n) for n in a]
even = [n for n in a if n % 2 == 0 or n == 0]
zeros = [n for n in a if n == 0]
odd = [n for n in a if n % 2 != 0]
if len(even) == len(odd):
	sum = 0
elif len(even) > len(odd):
	x = len(even) - len(odd) - 1 - len(zeros)
	even.sort()
	sum = sum(even[:x])
else:
	x = len(odd) - len(even) - 1
	odd.sort()
	sum = sum(odd[:x])
print(sum)


input()
n = list(map(int, input().split()))
e = []
o = []
for i in n:
	if i % 2 == 1:
		o.append(i)
	else:
		e.append(i)
o.sort(reverse=True)
e.sort(reverse=True)
if len(o) > len(e):
	print(sum(o[len(e) + 1:]))
else:
	print(sum(e[len(o) + 1:]))


n = int(input())
arr = list(map(int, input().split()))
even = 0
ev = []
od = []
odd = 0
for i in range(n):
	if arr[i] % 2 == 0:
		even += 1
		ev.append(arr[i])
	else:
		odd += 1
		od.append(arr[i])
ev.sort()
od.sort()
if abs(even - odd) == 0 or abs(even - odd) == 1:
	print(0)
else:
	arrsum = 0
	if even > odd:
		diff = even - odd - 1
		for i in range(diff):
			arrsum += ev[i]
	else:
		diff = odd - even - 1
		for i in range(diff):
			arrsum += od[i]
	print(arrsum)


from collections import deque
import sys
input = sys.stdin.readline
n: int = int(input())
a: [int] = sorted([int(x) for x in input().split()], reverse=True)
(even, odd) = (deque(), deque())
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
for _ in range(min(len(even), len(odd))):
	even.popleft()
	odd.popleft()
ans: int = 0
if len(even) > 0:
	even.popleft()
if len(odd) > 0:
	odd.popleft()
ans = sum(even) + sum(odd)
print(ans)


import math
n = int(input())
list1 = []
list2 = []
for t in map(int, input().split()):
	if t % 2 == 0:
		list1.append(t)
	else:
		list2.append(t)
list1.sort()
list2.sort()
len1 = len(list1)
len2 = len(list2)
if abs(len1 - len2) <= 1:
	print('0')
else:
	add = abs(len1 - len2) - 1
	ans = 0
	if len1 > len2:
		for i in range(0, add):
			ans += list1[i]
	else:
		for i in range(0, add):
			ans += list2[i]
	print(ans)


input()
data = input().split()
evens = []
odds = []
for p in data:
	q = int(p)
	if q % 2 == 0:
		evens.append(q)
	else:
		odds.append(q)
odds.sort()
evens.sort()
if abs(len(evens) - len(odds)) < 2:
	print('0')
else:
	if len(evens) < len(odds):
		sm = sum(odds[:len(odds) - len(evens) - 1])
	else:
		sm = sum(evens[:len(evens) - len(odds) - 1])
	print(sm)


a = int(input())
s = [int(i) for i in input().split()]
h = sorted(filter(lambda x: x % 2 == 0, s), reverse=1)
p = sorted(filter(lambda x: x % 2 == 1, s), reverse=1)
if len(h) < len(p):
	(h, p) = (p, h)
h = h[len(p) + 1:]
print(sum(h))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
chectcn = 0
for i in a:
	if i % 2 == 0:
		chectcn += 1
nechetcnt = n - chectcn
if chectcn > nechetcnt:
	m = 0
else:
	m = 1
cnt_to_sum = abs(chectcn - nechetcnt) - 1
if cnt_to_sum < 0:
	cnt_to_sum = 0
summ = 0
if cnt_to_sum:
	for i in a:
		if i % 2 == m:
			summ += i
			cnt_to_sum -= 1
			if cnt_to_sum == 0:
				break
print(summ)


n = int(input())
l1 = list(map(int, input().split()))
ev1 = []
od1 = []
for i in range(n):
	if l1[i] % 2 == 0:
		ev1.append(l1[i])
	else:
		od1.append(l1[i])
ev = len(ev1)
od = len(od1)
if ev == 0 or od == 0:
	print(sum(l1) - max(l1))
else:
	if ev < od:
		temp = ev
	else:
		temp = od
	for j in range(temp):
		l1.remove(max(ev1))
		l1.remove(max(od1))
		ev1.remove(max(ev1))
		od1.remove(max(od1))
	if len(l1) > 0:
		l1.remove(max(l1))
	print(sum(l1))


n = int(input())
a = list(map(int, input().split()))
(even, odd) = ([], [])
(ev, od) = (0, 0)
for val in a:
	if val % 2 == 0:
		even.append(val)
		ev += 1
	else:
		odd.append(val)
		od += 1
even.sort()
odd.sort()
if abs(ev - od) <= 1:
	print(0)
else:
	dif = abs(ev - od) - 1
	if ev > od:
		print(sum(even[:dif]))
	else:
		print(sum(odd[:dif]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
o = []
e = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
c = 1
lo = len(o)
le = len(e)
if len(o) >= len(e):
	o.pop()
	lo -= 1
	c = 1
else:
	e.pop()
	c = 0
	le -= 1
while 1:
	if c == 1:
		if le:
			e.pop()
			le -= 1
			c = 0
		else:
			break
	elif lo:
		o.pop()
		lo -= 1
		c = 1
	else:
		break
ans = 0
ans += sum(o)
ans += sum(e)
print(ans)


t = int(input())
a = sorted(list(map(int, input().split())))
l_even = []
l_odd = []
for i in a:
	if i % 2 == 0:
		l_even.append(i)
	else:
		l_odd.append(i)
l_even.reverse()
l_odd.reverse()
if len(l_even) > len(l_odd):
	b = l_even[0]
	l_even.remove(b)
else:
	b = l_odd[0]
	l_odd.remove(b)
if b % 2 == 0:
	for i in range(t):
		if i % 2 == 0:
			if len(l_odd) > 0:
				l_odd.remove(l_odd[0])
			else:
				break
		elif len(l_even) > 0:
			l_even.remove(l_even[0])
		else:
			break
else:
	for i in range(t):
		if i % 2 == 0:
			if len(l_even) > 0:
				l_even.remove(l_even[0])
			else:
				break
		elif len(l_odd) > 0:
			l_odd.remove(l_odd[0])
		else:
			break
lst = l_even + l_odd
print(sum(lst))


n = int(input())
numbers = list(map(int, input().split()))
odd = []
even = []
for i in numbers:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
if len(odd) == len(even):
	print(0)
	exit()
if len(odd) < len(even):
	res = sum(numbers) - sum(odd) - sum(even[:len(odd) + 1])
if len(odd) > len(even):
	res = sum(numbers) - sum(even) - sum(odd[:len(even) + 1])
print(res)


def polycarp(list):
	(odd, even) = ([], [])
	for i in range(len(list)):
		if list[i] % 2 == 0:
			even.append(list[i])
		else:
			odd.append(list[i])
	even.sort()
	odd.sort()
	sum = 0
	if len(odd) > len(even) + 1:
		for i in range(len(odd) - len(even) - 1):
			sum += odd[i]
	elif len(odd) < len(even) - 1:
		for i in range(len(even) - len(odd) - 1):
			sum += even[i]
	else:
		sum = 0
	return sum
n = int(input())
l = list(map(int, input().strip().split()))
print(polycarp(l))


n = int(input())
a = [int(x) for x in input().split()]
ev = []
od = []
for i in a:
	if i % 2 == 0:
		ev.append(i)
	else:
		od.append(i)
ev.sort(reverse=True)
od.sort(reverse=True)
m = len(ev)
n = len(od)
ans = 0
if m > n:
	i = 0
	del ev[0]
	for i in range(n):
		del ev[0]
		del od[0]
elif m < n:
	del od[0]
	for i in range(m):
		del od[0]
		del ev[0]
else:
	for i in range(n):
		del od[0]
		del ev[0]
print(sum(ev) + sum(od))


n = int(input())
list = [int(i) for i in input().split()]
(eve, odd) = (0, 0)
for i in range(n):
	if list[i] % 2:
		odd += 1
	else:
		eve += 1
if abs(eve - odd) <= 1:
	print('0')
	exit()
list.sort()
large = max(eve, odd)
(cnt, i, j) = (0, 0, 0)
if large == eve:
	while i < eve - odd - 1:
		if list[j] % 2 == 0:
			cnt += list[j]
			i += 1
		j += 1
else:
	while i < odd - eve - 1:
		if list[j] % 2:
			cnt += list[j]
			i += 1
		j += 1
print(cnt)


n = int(input())
l1 = [[], []]
for x in sorted(list(map(int, input().split()))):
	l1[x % 2] += (x,)
l1.sort(key=len)
print(sum(l1[1][:-len(l1[0]) - 1]))


n = int(input())
m = input().split()
for i in range(n):
	m[i] = int(m[i])
m.sort(reverse=True)
odd = []
even = []
for x in m:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
if len(odd) > len(even):
	p = len(even)
	ans = sum(odd[p + 1:])
else:
	p = len(odd)
	ans = sum(even[p + 1:])
print(ans)


n = int(input())
(odd, even) = ([], [])
(o, e) = (0, 0)
ans = list(map(int, input().split()))
ins = sorted(ans)
for i in range(n):
	if ins[i] % 2 == 0:
		even.append(ins[i])
		e += 1
	else:
		odd.append(ins[i])
		o += 1
ans = 0
if e >= o:
	c = e - o - 1
	for i in range(c):
		ans += even[i]
	print(ans)
else:
	c = o - e - 1
	for i in range(c):
		ans += odd[i]
	print(ans)


def solve(array):
	odd_array = []
	even_array = []
	for elem in array:
		if elem % 2 == 0:
			even_array.append(elem)
		else:
			odd_array.append(elem)
	even_len = len(even_array)
	odd_len = len(odd_array)
	if abs(even_len - odd_len) <= 1:
		return 0
	odd_array = sorted(odd_array)
	even_array = sorted(even_array)
	if even_len > odd_len:
		return sum(even_array[:even_len - odd_len - 1])
	if odd_len > even_len:
		return sum(odd_array[:odd_len - even_len - 1])
arr_len = int(input())
array = list(map(int, input().split()))
print(solve(array))


N = int(input())
s = [int(x) for x in input().split()]
e = []
o = []
tot = 0
tot1 = 0
tot2 = 0
for i in range(0, len(s)):
	if s[i] % 2 == 0:
		e.append(s[i])
		tot2 = tot2 + s[i]
	else:
		o.append(s[i])
		tot1 = tot1 + s[i]
	tot = tot + s[i]
o = sorted(o)
e = sorted(e)
o = o[::-1]
e = e[::-1]
if len(o) < len(e):
	sumu = tot1
	h = e[:len(o) + 1]
	for j in range(0, len(h)):
		sumu = sumu + h[j]
	print(tot - sumu)
elif len(e) < len(o):
	sumu = tot2
	h = o[:len(e) + 1]
	for j in range(0, len(h)):
		sumu = sumu + h[j]
	print(tot - sumu)
else:
	print(0)


n = int(input())
a = [int(x) for x in input().split()]
ch = ne = 0
ch1 = []
ne1 = []
summa = 0
for item in a:
	if item % 2 == 0:
		ch += 1
		ch1.append(item)
	else:
		ne += 1
		ne1.append(item)
ch1.sort(reverse=True)
ne1.sort(reverse=True)
if ch > ne:
	for i in range(ne):
		summa += ne1[i]
	for i in range(ne + 1):
		summa += ch1[i]
elif ch < ne:
	for i in range(ch):
		summa += ch1[i]
	for i in range(ch + 1):
		summa += ne1[i]
else:
	summa = sum(a)
print(sum(a) - summa)


n = int(input())
A = list(map(int, input().split()))
odd = []
eve = []
for i in A:
	if i % 2:
		odd.append(i)
	else:
		eve.append(i)
odd.sort()
eve.sort()
while len(odd) and len(eve):
	odd.pop()
	eve.pop()
if len(odd):
	odd.pop()
if len(eve):
	eve.pop()
print(sum(odd) + sum(eve))


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
l.reverse()
odd_list = []
even_list = []
for i in l:
	if i % 2 == 0:
		even_list.append(i)
	else:
		odd_list.append(i)
len_oddlist = len(odd_list)
len_evenlist = len(even_list)
sum = 0
if len_oddlist - len_evenlist >= 1:
	while len_oddlist - len_evenlist > 1:
		sum += odd_list[len_oddlist - 1]
		len_oddlist -= 1
if len_evenlist - len_oddlist >= 1:
	while len_evenlist - len_oddlist > 1:
		sum += even_list[len_evenlist - 1]
		len_evenlist -= 1
print(sum)


n = int(input())
arr = list(map(int, input().strip().split()))
evens = sorted([x for x in arr if x % 2 == 0])
odds = sorted([x for x in arr if x % 2 == 1])
diff = abs(len(evens) - len(odds))
if diff >= 1:
	diff -= 1
if len(evens) > len(odds):
	print(sum(evens[:diff]))
else:
	print(sum(odds[:diff]))


num = int(input())
arr = list(map(int, input().split()))
odds = [i for i in arr if i % 2 != 0]
evens = [i for i in arr if i % 2 == 0]
if abs(len(odds) - len(evens)) < 2:
	print(0)
else:
	if len(odds) > len(evens):
		i = len(odds) - len(evens) - 1
		odds.sort()
		ans = sum(odds[:i])
	else:
		i = -len(odds) + len(evens) - 1
		evens.sort()
		ans = sum(evens[:i])
	print(ans)


n = int(input())
li = list(map(int, input().split()))
eve = []
od = []
for i in li:
	if i % 2 == 0:
		eve.append(i)
	else:
		od.append(i)
eve = sorted(eve)
od = sorted(od)
eve = eve[::-1]
od = od[::-1]
if abs(len(eve) - len(od)) < 2:
	print('0')
elif len(eve) > len(od):
	k = len(eve) - len(od)
	print(sum(eve[len(eve) - k + 1:]))
else:
	k = len(od) - len(eve)
	print(sum(od[len(od) - k + 1:]))


n = int(input())
a = list(map(int, input().split()))
y = list(filter(lambda x: x % 2 == 0, a))
n = list(filter(lambda x: x % 2 != 0, a))
y.sort()
y.reverse()
n.sort()
n.reverse()
if len(y) > len(n):
	a = y
	b = n
else:
	a = n
	b = y
if y == n or len(y) + 1 == len(n) or len(n) + 1 == len(y):
	print(0)
	quit()
ans = 0
for i in range(len(b) + 1, len(a)):
	ans += a[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
chet = 0
nechet = 0
mchet = []
mnechet = []
for i in range(n):
	if a[i] % 2 == 0:
		chet = chet + 1
		mchet.append(a[i])
	else:
		nechet = nechet + 1
		mnechet.append(a[i])
mnechet.sort()
mchet.sort()
nech = nechet - chet
ch = chet - nechet
if nech >= 2:
	s = mnechet[:nech - 1]
elif ch >= 2:
	s = mchet[:ch - 1]
else:
	s = [0]
print(sum(s))


n = int(input())
li = [int(x) for x in input().split()]
li.sort()
ev_li = []
od_li = []
for i in range(n):
	if li[i] % 2 == 0:
		ev_li.append(li[i])
	else:
		od_li.append(li[i])
l1 = len(ev_li)
l2 = len(od_li)
diff = abs(l1 - l2)
sum = 0
if l1 > l2:
	if diff > 1:
		for k in range(diff - 1):
			sum = sum + ev_li[k]
elif diff > 1:
	for k in range(diff - 1):
		sum = sum + od_li[k]
print(sum)


n = int(input())
mas = list(map(int, input().split()))
mas.sort()
mas.reverse()
ch = []
nch = []
sum = 0
for i in mas:
	if i % 2 == 0:
		ch.append(i)
	else:
		nch.append(i)
lch = len(ch)
lnch = len(nch)
if lch == min(lch, lnch):
	for i in range(lch + 1, lnch):
		sum += nch[i]
else:
	for i in range(lnch + 1, lch):
		sum += ch[i]
print(sum)


n = int(input())
a = [int(i) for i in input().split()]
odd = []
even = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort()
odd.sort()
ans = 100000000000.0
for k in range(2):
	i = k
	o = odd.copy()
	e = even.copy()
	while True:
		if i % 2 == 0:
			if len(e) == 0:
				break
			e.pop()
		else:
			if len(o) == 0:
				break
			o.pop()
		i += 1
	ans = min(ans, sum(e) + sum(o))
print(ans)


n = int(input())
l = list(map(int, input().split()))
o = []
e = []
for x in l:
	if x % 2 == 0:
		e.append(x)
	else:
		o.append(x)
e.sort()
o.sort()
if len(e) == 0:
	del o[-1]
	k = o
elif len(o) == 0:
	del e[-1]
	k = e
elif len(o) == len(e):
	if sum(e) >= sum(o):
		for x in range(len(e)):
			del e[-1]
			del o[-1]
		k = e + o
	if sum(o) > sum(e):
		for x in range(len(e)):
			del e[-1]
			del o[-1]
		k = e + o
elif len(e) > len(o):
	for x in range(len(o) + 1):
		del e[-1]
	k = e
else:
	for x in range(len(e) + 1):
		del o[-1]
	k = o
print(sum(k))


n = int(input())
a = list(map(int, input().split()))
odd = 0
even = 0
for i in range(len(a)):
	if a[i] % 2 == 0:
		even += 1
	else:
		odd += 1
if even == odd:
	print(0)
elif abs(odd - even) == 1:
	print(0)
else:
	ans = 0
	a.sort()
	if len(a) == 2:
		print(a[0])
	else:
		if odd > even:
			diff = odd - even - 1
			i = 0
			while diff > 0:
				if a[i] % 2 != 0:
					ans += a[i]
					diff -= 1
				i += 1
		else:
			diff = even - odd - 1
			i = 0
			while diff > 0:
				if a[i] % 2 == 0:
					ans += a[i]
					diff -= 1
				i += 1
		print(ans)


n = int(input())
b = [int(n) for n in input().split()]
ev = []
od = []
a = sorted(b)
for i in range(n):
	if a[i] % 2 == 0:
		ev.append(a[i])
	else:
		od.append(a[i])
s = 0
if len(ev) == len(od) or abs(len(ev) - len(od)) == 1:
	print('0')
elif len(ev) > len(od):
	for j in range(len(ev) - len(od) - 1):
		s += ev[j]
	print(s)
elif len(ev) < len(od):
	for j in range(len(od) - len(ev) - 1):
		s += od[j]
	print(s)


n = int(input())
li = list(map(int, input().split()))
(li1, li2) = ([], [])
(c1, c2) = (0, 0)
for i in li:
	if i % 2 == 0:
		li1.append(i)
		c1 += 1
	else:
		li2.append(i)
		c2 += 1
if c1 > c2:
	li1.sort()
	print(sum(li1[:c1 - c2 - 1]))
elif c2 > c1:
	li2.sort()
	print(sum(li2[:c2 - c1 - 1]))
else:
	print('0')


import math
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def invr():
	return list(map(int, input().split()))
inp()
a = invr()
a.sort()
a.reverse()
cc = 0
s = 0
for e in a:
	s += e
	cc += 1 if e % 2 == 0 else -1
c = 1 if cc < 0 else 0
l = len(a)
for ii in range(l):
	for (i, e) in enumerate(a):
		if e % 2 == c:
			a.pop(i)
			s -= e
			c = not c
			break
print(s)


n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
count1 = 0
count2 = 0
for i in range(n):
	if arr[i] % 2 == 0:
		count1 += 1
	else:
		count2 += 1
ans = 0
count3 = 0
if count1 > count2:
	l = count1 - count2 - 1
	diff = 0
else:
	l = count2 - count1 - 1
	diff = 1
for i in range(n):
	if l <= count3:
		break
	if arr[i] % 2 == diff:
		ans += arr[i]
		count3 += 1
print(ans)


n = int(input())
ai = list(map(int, input().split()))
ai.sort()
num = 0
for i in range(n):
	if ai[i] % 2 == 0:
		num += 1
num2 = min(num, n - num) * 2 + 1
num4 = 0
if n - num > num:
	num4 = 1
num3 = max(0, n - num2)
ans = 0
for i in range(n):
	if num3 == 0:
		break
	if ai[i] % 2 == num4:
		num3 -= 1
		ans += ai[i]
print(ans)


n = int(input())
A = list(map(int, input().split()))
chet = []
nechet = []
for i in A:
	if i % 2 == 0:
		chet.append(i)
	else:
		nechet.append(i)
if len(chet) == len(nechet) or abs(len(chet) - len(nechet)) == 1:
	print(0)
elif len(chet) > len(nechet):
	print(sum(sorted(chet)[:len(chet) - len(nechet) - 1]))
else:
	print(sum(sorted(nechet)[:len(nechet) - len(chet) - 1]))


n = int(input())
a = [int(num) for num in input().split()]
(e, o, ans) = (list(filter(lambda n: n % 2 == 0, a)), list(filter(lambda n: n % 2 != 0, a)), 0)
(e.sort(reverse=True), o.sort(reverse=True))
temp = abs(len(e) - len(o))
if temp > 1:
	ans = sum(e[len(o) + 1:]) if len(e) > len(o) else sum(o[len(e) + 1:])
print(ans)


from math import fabs
a = int(input())
a = [int(i) for i in input().split()]
b = list(filter(lambda x: x % 2 == 0, a))
c = list(filter(lambda x: x % 2 == 1, a))
lb = len(b)
lc = len(c)
if lb == lc or fabs(lb - lc) == 1:
	print(0)
elif lb > lc:
	b = sorted(b)
	print(sum(b[0:lb - lc - 1]))
else:
	c = sorted(c)
	print(sum(c[0:lc - lb - 1]))


n = int(input())
l = list(map(int, input().split()))
p = []
k = []
l.sort()
for i in range(n):
	if l[i] % 2 == 0:
		p.append(l[i])
	else:
		k.append(l[i])
r = len(p)
t = len(k)
if r > t:
	s = 0
	for i in range(1, r - t):
		s += p[i - 1]
	print(s)
else:
	s = 0
	for i in range(1, t - r):
		s += k[i - 1]
	print(s)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
l.reverse()
odd_list = list(filter(lambda x: x % 2 != 0, l))
even_list = list(filter(lambda x: x % 2 == 0, l))
mini = min(len(odd_list), len(even_list))
print(sum(odd_list[mini + 1:]) + sum(even_list[mini + 1:]))


n = int(input())
a = list(map(int, input().split()))
ao = []
ae = []
for i in a:
	if i % 2:
		ao.append(i)
	else:
		ae.append(i)
co = len(ao)
ce = len(ae)
if abs(co - ce) < 2:
	ans = 0
elif co > ce:
	d = co - (ce + 1)
	ao.sort()
	ans = sum(ao[:d])
else:
	d = ce - (co + 1)
	ae.sort()
	ans = sum(ae[:d])
print(ans)


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in range(len(a)):
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
even.sort(reverse=True)
odd.sort(reverse=True)
if abs(len(even) - len(odd)) <= 1:
	print(0)
else:
	k = min(len(even), len(odd))
	print(sum(even[k + 1:]) + sum(odd[k + 1:]))


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in a:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
o = len(odd)
e = len(even)
if o == e:
	print(0)
elif o < e:
	try:
		print(sum(even[o + 1:]))
	except:
		print(0)
elif o > e:
	try:
		print(sum(odd[e + 1:]))
	except:
		print(0)


n = int(input())
c = list(map(int, input().split()))
c = sorted(c)[::-1]
(count_even, count_odd) = (0, 0)
for i in range(len(c)):
	if c[i] % 2 == 0:
		count_even += 1
	else:
		count_odd += 1
if abs(count_even - count_odd) <= 1:
	print(0)
elif count_even > count_odd:
	r = count_even - count_odd - 1
	c = sorted(c)
	index = 0
	tot = 0
	for i in range(len(c)):
		if c[i] % 2 == 0:
			tot += c[i]
			index += 1
		if index == r:
			break
	print(tot)
else:
	flag = 0
	c = sorted(c)
	r = count_odd - count_even - 1
	index = 0
	tot = 0
	for i in range(len(c)):
		if c[i] % 2 == 1:
			tot += c[i]
			index += 1
		if index == r:
			break
	print(tot)


a = int(input())
b = list(map(int, input().split()))
c = []
d = []
for i in range(a):
	if b[i] % 2 == 0:
		c.append(b[i])
	else:
		d.append(b[i])
m = len(c)
n = len(d)
if m == n or abs(m - n) == 1:
	print(0)
else:
	c.sort()
	d.sort()
	p = min(m, n)
	if p == n:
		t = m - p - 1
		print(sum(c[0:t]))
	else:
		t = n - p - 1
		print(sum(d[0:t]))


n = input()
numbers = list(map(int, input().split()))
even = [i for i in numbers if i % 2 == 0 and i != 0]
odd = [i for i in numbers if i % 2 != 0]
taken = min(len(even), len(odd))
even.sort(reverse=True)
odd.sort(reverse=True)
value = 0
if len(even) > len(odd):
	value += sum(even[taken + 1:])
	value += sum(odd[taken:])
elif len(odd) > len(even):
	value += sum(odd[taken + 1:])
	value += sum(even[taken:])
else:
	value += sum(sorted(numbers[2 * taken + 1:], reverse=True))
print(value)


import math
import bisect

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
n = f()
cl = sorted(f(2))
a = 0
b = 0
cla = []
clb = []
for i in range(n):
	if cl[i] % 2 == 0:
		b += 1
		clb.append(cl[i])
	else:
		a += 1
		cla.append(cl[i])
if a < b:
	nb = b - a
	nb = max(0, nb - 1)
	if nb != 0:
		x = sum(clb[:nb])
	else:
		x = 0
elif b < a:
	na = a - b
	na = max(0, na - 1)
	if na != 0:
		x = sum(cla[:na])
	else:
		x = 0
else:
	x = 0
print(x)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
even = []
odd = []
for i in x:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if abs(len(even) - len(odd)) <= 1:
	print(0)
elif len(even) > len(odd):
	print(sum(even[:len(even) - len(odd) - 1]))
else:
	print(sum(odd[:len(odd) - len(even) - 1]))


n = int(input())
numbers = [int(x) for x in input().split()]
(odd, even) = ([], [])
for i in numbers:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
diff = abs(len(odd) - len(even))
if diff < 2:
	print(0)
else:
	spare = 0
	if len(odd) > len(even):
		odd = [int(x) for x in sorted(odd)]
		for i in range(diff - 1):
			spare = spare + odd[i]
	else:
		even = [int(x) for x in sorted(even)]
		for i in range(diff - 1):
			spare = spare + even[i]
	print(spare)


n = int(input())
s = [int(x) for x in input().split()]
odds = [x for x in s if x % 2]
evens = [x for x in s if x % 2 == 0]
odds.sort()
evens.sort()
if len(odds) - len(evens) >= 2:
	print(sum(odds[:-len(evens) - 1]))
elif len(evens) - len(odds) >= 2:
	print(sum(evens[:-len(odds) - 1]))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
odd = sorted([i for i in a if i % 2 == 1], reverse=True)
even = sorted([i for i in a if i % 2 == 0], reverse=True)
state = None
if len(odd) > len(even):
	state = 1
else:
	state = 0
for i in a:
	if state == 1:
		if not odd:
			break
		odd.pop(0)
		state = 0
	else:
		if not even:
			break
		even.pop(0)
		state = 1
print(sum(odd) + sum(even))


n = int(input())
e = []
o = []
arr = input().split()
for ele in arr:
	k = int(ele)
	if k % 2 == 0:
		e.append(k)
	else:
		o.append(k)
e.sort()
o.sort()
if len(e) - len(o) <= 1 and len(e) - len(o) >= -1:
	print(0)
elif len(e) > len(o):
	k = len(e) - len(o) - 1
	t = 0
	for i in range(0, k):
		t = t + e[i]
	print(t)
else:
	k = len(o) - len(e) - 1
	t = 0
	for i in range(0, k):
		t = t + o[i]
	print(t)


n = int(input())
query = list((int(i) for i in input().split()))
even = []
odd = []
for i in query:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
deletenumber = min(len(even), len(odd)) + 1
even.sort()
odd.sort()
ans = 0
if deletenumber >= len(even):
	pass
else:
	for i in range(deletenumber):
		even.pop(-1)
	ans += sum(even)
if deletenumber >= len(odd):
	pass
else:
	for i in range(deletenumber):
		odd.pop(-1)
	ans += sum(odd)
print(ans)


from collections import Counter
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
turn = 0
z = len(even) > len(odd)
z1 = len(even) == len(odd)
if z:
	even.remove(even[0])
	turn = 1
else:
	odd.remove(odd[0])
if z1:
	if odd[0] > even[0]:
		odd.remove(odd[0])
	else:
		even.remove(even[0])
s = [even, odd]
while len(s[turn]) != 0:
	s[turn].remove(s[turn][0])
	turn = (turn + 1) % 2
print(sum(s[0]) + sum(s[1]))


n = int(input())
l = list(map(int, input().split()))
el = []
ol = []
ec = 0
oc = 0
for i in range(n):
	if l[i] & 1 == 0:
		el.append(l[i])
		ec += 1
	else:
		ol.append(l[i])
		oc += 1
el.sort()
ol.sort()
if ec == oc or ec == oc + 1 or oc == ec + 1:
	print(0)
else:
	res = 0
	if oc > ec:
		res = sum(ol[:oc - (ec + 1)])
	else:
		res = sum(el[:ec - (oc + 1)])
	print(res)


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
odd = []
even = []
for e in arr:
	if e % 2 == 1:
		odd.append(e)
	else:
		even.append(e)
answer = 0
if len(odd) > len(even):
	odd_num = len(odd) - len(even) - 1
	answer = sum(odd[:odd_num])
if len(even) > len(odd):
	even_num = len(even) - len(odd) - 1
	answer = sum(even[:even_num])
print(answer)


n = int(input())
A = map(int, input().split())
odd = []
even = []
for a in A:
	if a % 2 == 1:
		odd.append(a)
	else:
		even.append(a)
if abs(len(odd) - len(even)) <= 1:
	print(0)
elif len(odd) > len(even):
	odd.sort()
	print(sum(odd[:len(odd) - len(even) - 1]))
else:
	even.sort()
	print(sum(even[:len(even) - len(odd) - 1]))


import math

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	b = [int(x) for x in input().split()]
	return (n, m, b)

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
nch = []
ch = []
for i in a:
	if i % 2 == 0:
		ch.append(i)
	else:
		nch.append(i)
ch = sorted(ch)
nch = sorted(nch)
while len(ch) > 0 and len(nch) > 0:
	ch.pop()
	nch.pop()
if len(ch) > 0:
	ch.pop()
elif len(nch) > 0:
	nch.pop()
print(sum(ch) + sum(nch))


n = int(input())
s = list(map(int, input().split()))
ss = sorted(s)
(oddcnt, evencnt) = ([], [])
for i in range(n):
	if ss[i] % 2:
		oddcnt.append(ss[i])
	else:
		evencnt.append(ss[i])
sum = 0
(ol, el) = (len(oddcnt), len(evencnt))
if ol >= el:
	for i in range(ol - el - 1):
		sum += oddcnt[i]
	print(sum)
else:
	for i in range(el - ol - 1):
		sum += evencnt[i]
	print(sum)


n = int(input())
s = list(map(int, input().split()))
s.sort(reverse=True)
summ = sum(s)
a1 = 0
a2 = 0
for i in range(n):
	if s[i] % 2:
		a1 += 1
	else:
		a2 += 1
if a1 == a2:
	print(0)
else:
	if a1 > a2:
		a1 = a2 + 1
	else:
		a2 = a1 + 1
	x = 0
	for i in range(n):
		if s[i] % 2 and x < a1:
			x += 1
			summ -= s[i]
	x = 0
	for i in range(n):
		if not s[i] % 2 and x < a2:
			x += 1
			summ -= s[i]
	print(summ)


n = int(input())
a = list(map(int, input().split()))
even = 0
odd = 0
summa = 0
a.sort()
for i in range(n):
	if a[i] % 2 == 1:
		odd += 1
	else:
		even += 1
	summa += a[i]
if abs(even - odd) > 1:
	if odd > even:
		odd = even + 1
	else:
		even = odd + 1
for i in range(n - 1, -1, -1):
	if odd == 0 and even == 0:
		break
	if a[i] % 2 == 0 and even > 0:
		summa -= a[i]
		even -= 1
	if a[i] % 2 == 1 and odd > 0:
		summa -= a[i]
		odd -= 1
print(summa)


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
evens = []
evencount = 0
odds = []
oddcount = 0
for item in l:
	if item % 2 == 0:
		evencount += 1
		evens.append(item)
	else:
		oddcount += 1
		odds.append(item)
if max(evencount - oddcount, oddcount - evencount) <= 1:
	print(0)
elif evencount >= oddcount:
	r = evencount - oddcount - 1
	print(sum(evens[:r]))
else:
	r = oddcount - evencount - 1
	print(sum(odds[:r]))


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a.reverse()
o = 0
e = 0
ans = 0
b = []
c = []
for i in range(len(a)):
	if a[i] % 2 == 1:
		b.append(a[i])
		o += 1
	else:
		e += 1
		c.append(a[i])
if o > e:
	i = o - (e + 1)
	ans = sum(b[o - i:])
	ans += sum(c[e:])
elif e > o:
	i = e - (o + 1)
	ans = sum(b[o:])
	ans += sum(c[e - i:])
else:
	ans = sum(b[o:])
	ans += sum(c[e:])
print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
(odd, even) = ([], [])
(o, e) = (0, 0)
for i in range(n):
	if a[i] & 1:
		o += 1
		odd.append(a[i])
	else:
		e += 1
		even.append(a[i])
odd.sort()
even.sort()
if abs(o - e) == 1 or e == o:
	print(0)
elif e >= o:
	print(sum(even[:-(o + 1)]))
else:
	print(sum(odd[:-(e + 1)]))


from collections import deque
(n, q1, q0, s) = (input(), deque(), deque(), 0)
for num in sorted(map(int, input().split())):
	if num & 1:
		q1.append(num)
	else:
		q0.append(num)
if len(q1) > len(q0):
	for i in range(len(q0) + 1, len(q1)):
		s += q1.popleft()
else:
	for i in range(len(q1) + 1, len(q0)):
		s += q0.popleft()
print(s)


from sys import stdin, stdout

def main():
	chet = 0
	nechet = 0
	C = []
	N = []
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().replace('\n', '').split()]
	for i in a:
		if i % 2 == 0:
			chet += 1
			C.append(i)
		else:
			nechet += 1
			N.append(i)
	out = max(chet, nechet) - min(chet, nechet) - 1
	if out == 0:
		stdout.write('0\n')
	else:
		C.sort()
		N.sort()
		s = 0
		if max(chet, nechet) == chet:
			for i in range(out):
				s += C[i]
		else:
			for i in range(out):
				s += N[i]
		stdout.write(str(s) + '\n')
main()


amount = int(input())
all_numbers = map(int, input().split())
even = []
odd = []
for element in all_numbers:
	if element % 2:
		odd.append(element)
	else:
		even.append(element)
even.sort()
odd.sort()

def good(even, odd):
	even_cpy = even[:]
	odd_cpy = odd[:]
	alter = True
	flag = True
	while flag:
		if alter:
			if len(odd) > 0:
				odd.pop()
			else:
				flag = False
				if len(odd_cpy) > 0:
					odd_cpy.pop()
			if len(even_cpy) > 0:
				even_cpy.pop()
			else:
				flag = False
				if len(even) > 0:
					even.pop()
			alter = not alter
		else:
			if len(even) > 0:
				even.pop()
			else:
				flag = False
				if len(even_cpy) > 0:
					even_cpy.pop()
			if len(odd_cpy) > 0:
				odd_cpy.pop()
			else:
				flag = False
				if len(odd) > 0:
					odd.pop()
			alter = not alter
	return min(sum(even) + sum(odd), sum(even_cpy) + sum(odd_cpy))
if len(odd) == 0:
	print(sum(even) - max(even))
elif len(even) == 0:
	print(sum(odd) - max(odd))
else:
	print(good(even, odd))


n = int(input())
l = [int(e.strip()) for e in input().strip().split()]
odd = []
even = []
sum = 0
for pp in l:
	if pp % 2 == 0:
		even.append(pp)
	else:
		odd.append(pp)
	sum += pp
odd = sorted(odd, reverse=1)
even = sorted(even, reverse=1)
for i in range(min(len(odd), len(even))):
	sum -= even[i]
	sum -= odd[i]
if len(odd) > len(even):
	sum -= odd[len(even)]
if len(odd) < len(even):
	sum -= even[len(odd)]
print(sum)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
odd = [i for i in arr if i % 2]
even = [i for i in arr if not i % 2]
len_odd = len(odd)
len_even = len(even)
if len_odd > len_even:
	dif = len_odd - len_even
	print(sum(odd[0:dif - 1]))
elif len_odd < len_even:
	dif = len_even - len_odd
	print(sum(even[0:dif - 1]))
else:
	print(0)


import sys

def fmax(o, p, n):
	if not o:
		p.sort()
		return sum(p[:n])
	elif not p:
		o.sort()
		return sum(o[:n])
	o.sort()
	p.sort()
	if len(o) < len(p):
		return sum(p[:n])
	else:
		return sum(o[:n])

def solve(a):
	o = []
	p = []
	for n in a:
		if n % 2 == 0:
			p.append(n)
		else:
			o.append(n)
	if abs(len(p) - len(o)) == 0 or abs(len(p) - len(o)) == 1:
		return 0
	else:
		return fmax(o, p, abs(len(p) - len(o)) - 1)
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
res = solve(a)
sys.stdout.write(str(res) + '\n')


n = int(input())
a = list(map(int, input().split()))
o = []
e = []
for i in a:
	if i % 2 == 0:
		o.append(i)
	else:
		e.append(i)
o = sorted(o, reverse=True)
e = sorted(e, reverse=True)
if len(o) == len(e):
	print(0)
elif len(o) > len(e):
	o = o[len(e) + 1:]
	print(sum(o))
else:
	e = e[len(o) + 1:]
	print(sum(e))


n = int(input())
arr = list(map(int, input().strip().split()))
odd = list(filter(lambda x: x % 2, arr))
even = list(filter(lambda x: x % 2 == 0, arr))
odd.sort()
even.sort()
if len(even) == len(odd) or abs(len(even) - len(odd)) == 1:
	print(0)
elif len(even) > len(odd):
	t = len(even) - len(odd) - 1
	print(sum(even[:t]))
else:
	t = len(odd) - len(even) - 1
	print(sum(odd[:t]))


n = int(input())
nums = [int(x) for x in input().split(' ')]
nums.sort()
evens = []
odds = []
for i in nums:
	temp = str(i)
	if int(temp[-1]) % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evensLen = len(evens)
oddsLen = len(odds)
resp = 0
if evensLen != oddsLen:
	if evensLen > oddsLen:
		for i in range(evensLen - oddsLen - 1):
			resp += int(evens[i])
	else:
		for i in range(oddsLen - evensLen - 1):
			resp += int(odds[i])
print(resp)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	odds = []
	evens = []
	for i in range(n):
		if arr[i] % 2:
			odds.append(arr[i])
		else:
			evens.append(arr[i])
	odds = sorted(odds, reverse=True)
	evens = sorted(evens, reverse=True)
	if len(odds) < len(evens):
		print(sum(evens[len(odds) + 1:]))
	else:
		print(sum(odds[len(evens) + 1:]))
	return 0
main()


def get_even(n_list):
	return sorted([n for n in n_list if not n % 2], reverse=True)

def get_odd(n_list):
	return sorted([n for n in n_list if n % 2], reverse=True)

def solve(n_list):
	even = get_even(n_list)
	odd = get_odd(n_list)
	(le, lo) = (len(even), len(odd))
	if le > lo + 1:
		return sum(even[lo + 1:])
	elif lo > le + 1:
		return sum(odd[le + 1:])
	else:
		return 0
_ = input()
s_list = input()
n_list = list(map(int, s_list.split(' ')))
print(solve(n_list))


n = int(input())
a = list(map(int, input().split()))
odd = sorted(list(filter(lambda x: x % 2, a)), reverse=True)
even = sorted(list(filter(lambda x: x % 2 == 0, a)), reverse=True)
x = abs(len(odd) - len(even))
if x == 0 or x == 1:
	print(0)
elif len(odd) > len(even):
	odd = odd[len(even) + 1:]
	print(sum(odd))
else:
	even = even[len(odd) + 1:]
	print(sum(even))


n = int(input())
integers = list(map(int, input().split()))
tot = sum(integers)
even_int = []
odd_int = []
(e, o) = (0, 0)
for i in range(n):
	if integers[i] % 2 == 0:
		even_int.append(integers[i])
	else:
		odd_int.append(integers[i])
even_int.sort(reverse=True)
odd_int.sort(reverse=True)
e = len(even_int)
o = len(odd_int)
k = min(e, o)
tot = tot - (sum(even_int[:k]) + sum(odd_int[:k]))
if e > o:
	tot = tot - even_int[k]
elif o > e:
	tot = tot - odd_int[k]
print(tot)


n = int(input())
ar = [int(x) for x in input().split()]
e = []
o = []
for k in ar:
	if k % 2 == 0:
		e.append(k)
	else:
		o.append(k)
e.sort(reverse=True)
o.sort(reverse=True)
ee = len(e)
oo = len(o)
if ee == oo or ee - oo == -1 or ee - oo == 1:
	print(0)
elif ee > oo:
	print(sum(e[oo + 1:]))
else:
	print(sum(o[ee + 1:]))


n = int(input())
a = input().split()
b1 = []
c1 = []
b2 = []
c2 = []
sum1 = 0
sum2 = 0
for i in range(n):
	if int(a[i]) % 2 == 0:
		b1.append(int(a[i]))
		b2.append(int(a[i]))
	else:
		c1.append(int(a[i]))
		c2.append(int(a[i]))
	sum1 += int(a[i])
	sum2 += int(a[i])
b1.sort(reverse=True)
c1.sort(reverse=True)
d = 0
while len(b1) > 0 and len(c1) > 0:
	if d % 2 == 0:
		sum1 -= b1[0]
		b1.pop(0)
		d += 1
	else:
		sum1 -= c1[0]
		c1.pop(0)
		d += 1
if d % 2 == 0 and len(b1) > 0 and (len(c1) == 0):
	sum1 -= b1[0]
	b1.pop(0)
elif d % 2 != 0 and len(b1) == 0 and (len(c1) > 0):
	sum1 -= c1[0]
	c1.pop(0)
b2.sort(reverse=True)
c2.sort(reverse=True)
e = 0
while len(b2) > 0 and len(c2) > 0:
	if e % 2 == 0:
		sum2 -= c2[0]
		c2.pop(0)
		e += 1
	else:
		sum2 -= b2[0]
		b2.pop(0)
		e += 1
if e % 2 == 0 and len(b2) == 0 and (len(c2) > 0):
	sum2 -= c2[0]
	c2.pop(0)
elif e % 2 != 0 and len(b2) > 0 and (len(c2) == 0):
	sum2 -= b2[0]
	b2.pop(0)
print(min(sum1, sum2))


n = int(input())
a = [int(x) for x in input().split()]
odd = []
even = []
for j in range(len(a)):
	if a[j] & 1:
		odd.append(a[j])
	else:
		even.append(a[j])
diff = abs(len(odd) - len(even))
ans = 0
if diff > 1:
	if len(odd) > len(even):
		odd.sort()
		for i in range(diff - 1):
			ans += odd[i]
	else:
		even.sort()
		for i in range(diff - 1):
			ans += even[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for num in a:
	if num % 2 == 1:
		odd.append(num)
	else:
		even.append(num)
le = len(even)
lo = len(odd)
if abs(le - lo) <= 1:
	print('0')
else:
	size = abs(le - lo) - 1
	if le > lo:
		m = sorted(even)
	else:
		m = sorted(odd)
	print(sum(m[:size]))


from collections import Counter, defaultdict, deque
import itertools
import string
n = int(input())
m = list(map(int, input().split()))
a = []
b = []
for mi in m:
	if mi % 2 == 0:
		a.append(mi)
	else:
		b.append(mi)
a.sort(reverse=True)
b.sort(reverse=True)
min_len = min(len(a), len(b))
max_len = max(len(a), len(b))
ans = 0
for i in range(min_len + 1, max_len):
	if i < len(a):
		ans += a[i]
	if i < len(b):
		ans += b[i]
print(ans)


n = int(input())
odd = []
even = []
for num in input().split():
	num = int(num)
	if num % 2 == 0:
		even.append(num)
	else:
		odd.append(num)
on = len(odd)
en = len(even)
if abs(on - en) <= 1:
	print(0)
else:
	diff = abs(on - en) - 1
	if on > en:
		odd.sort()
		print(sum(odd[:diff]))
	else:
		even.sort()
		print(sum(even[:diff]))


n = int(input())
a = list(map(int, input().split()))
a1 = []
a2 = []
for i in range(n):
	if a[i] % 2 == 0:
		a1.append(a[i])
	else:
		a2.append(a[i])
a1.sort()
a2.sort()
x = len(a1)
y = len(a2)
su = 0
if x > y:
	for i in range(0, x - y - 1):
		su += a1[i]
elif x < y:
	for i in range(0, y - x - 1):
		su += a2[i]
print(su)


def del_ev(a):
	for i in range(len(a)):
		if a[i] % 2 == 0:
			a.pop(i)
			return 0
	return 1

def del_od(a):
	for i in range(len(a)):
		if a[i] % 2 == 1:
			a.pop(i)
			return 0
	return 1
import copy
n = int(input())
a = list(map(int, input().split()))
sum_ev = 0
sum_od = 0
a.sort(reverse=True)
b = a.copy()
while True:
	if del_ev(a):
		sum1 = sum(a)
		break
	if del_od(a):
		sum1 = sum(a)
		break
while True:
	if del_od(b):
		sum2 = sum(b)
		break
	if del_ev(b):
		sum2 = sum(b)
		break
print(min(sum1, sum2))


n = input()
a = [int(i) for i in input().split()]
b = []
c = []
for i in range(int(n)):
	if a[i] % 2 == 0:
		b.append(a[i])
	else:
		c.append(a[i])
if abs(len(b) - len(c)) <= 1:
	print(0)
else:
	if len(b) - len(c) > 1:
		z = sorted(b)
		if len(c) == 0:
			print(sum(z[:len(z) - 1]))
		else:
			print(sum(z[:len(b) - len(c) - 1]))
	if len(c) - len(b) > 1:
		z = sorted(c)
		if len(b) == 0:
			print(sum(z[:len(z) - 1]))
		else:
			print(sum(z[:len(c) - len(b) - 1]))


n = int(input())
a = list(map(int, input().split()))
b = 0
c = 0
b1 = []
c1 = []
for i in range(n):
	if a[i] % 2 == 0:
		b += 1
		b1.append(a[i])
	else:
		c += 1
		c1.append(a[i])
if abs(b - c) < 2:
	print(0)
else:
	b1.sort()
	c1.sort()
	ans = 0
	if b > c:
		for i in range(b - c - 1):
			ans += b1[i]
	else:
		for i in range(c - b - 1):
			ans += c1[i]
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
e = []
o = []
i = 0
sum = int(0)
while i < len(arr):
	if arr[i] % 2 == 0:
		e.append(arr[i])
	else:
		o.append(arr[i])
	sum = sum + arr[i]
	i += 1
o.sort()
e.sort()
ind = -1
mn = min(len(o), len(e))
mn *= -1
while ind >= mn:
	sum -= o[ind]
	sum -= e[ind]
	ind -= 1
if len(o) > len(e):
	sum -= o[ind]
elif len(e) > len(o):
	sum -= e[ind]
print(sum)


n = int(input())
arr = list(map(int, input().split(' ')))
odd = []
even = []
for i in range(n):
	if arr[i] % 2 == 0:
		even.append(arr[i])
	else:
		odd.append(arr[i])
odd = sorted(odd)
even = sorted(even)
if len(even) > len(odd):
	p = 'e'
	while len(odd) > 0 and len(even) > 0:
		if p == 'e':
			even.pop(len(even) - 1)
			p = 'o'
		else:
			odd.pop(len(odd) - 1)
			p = 'e'
	if p == 'o' and len(odd) != 0:
		odd.pop(len(odd) - 1)
	elif p == 'e' and len(even) != 0:
		even.pop(len(even) - 1)
else:
	p = 'o'
	while len(odd) > 0 and len(even) > 0:
		if p == 'e':
			even.pop(len(even) - 1)
			p = 'o'
		else:
			odd.pop(len(odd) - 1)
			p = 'e'
	if p == 'o' and len(odd) != 0:
		odd.pop(len(odd) - 1)
	elif p == 'e' and len(even) != 0:
		even.pop(len(even) - 1)
print(sum(odd) + sum(even))


n = int(input())
a = [int(i) for i in input().split()]
chet = sorted([i for i in a if i % 2 == 0])
nechet = sorted([i for i in a if i % 2 == 1])
razn = abs(len(chet) - len(nechet))
if len(chet) > len(nechet):
	mx = chet
else:
	mx = nechet
if razn > 1:
	print(sum([mx[i] for i in range(razn - 1)]))
else:
	print(0)


nothing = input()
r = input().split()
s = []
for i in r:
	s.append(int(i))
even = []
uneaven = []
for i in s:
	if i % 2 == 1:
		uneaven.append(i)
	else:
		even.append(i)
even.sort()
uneaven.sort()
if len(uneaven) == 0:
	if len(even) > 0:
		even.pop()
elif len(even) == 0:
	if len(uneaven) > 0:
		uneaven.pop()
elif len(even) > len(uneaven):
	even.pop()
	while len(uneaven) > 0:
		even.pop()
		uneaven.pop()
elif len(uneaven) > len(even):
	uneaven.pop()
	while len(even) > 0:
		even.pop()
		uneaven.pop()
else:
	while len(even) > 0:
		even.pop()
		uneaven.pop()
sum = 0
for i in even:
	sum += i
for i in uneaven:
	sum += i
print(sum)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
li = ai()
ans = sum(li)
even = []
odd = []
for i in range(n):
	if li[i] & 1:
		odd.append(li[i])
	else:
		even.append(li[i])
even.sort(reverse=True)
odd.sort(reverse=True)
k = min(len(even), len(odd))
for i in range(k):
	ans -= odd[i]
for i in range(k):
	ans -= even[i]
if len(even) > k:
	ans -= even[k]
if len(odd) > k:
	ans -= odd[k]
op(ans)


n = int(input())
a = list(map(int, input().strip().split(' ')))
c1 = 0
c2 = 0
b = []
c = []
sum = 0
for j in a:
	if j % 2 == 0:
		c1 += 1
		b.append(j)
	else:
		c2 += 1
		c.append(j)
if c1 == c2:
	sum = 0
elif c1 > c2:
	c1 -= 1
	b.sort()
	for k in range(c1 - c2):
		sum += b[k]
elif c2 > c1:
	c2 -= 1
	c.sort()
	for k in range(c2 - c1):
		sum += c[k]
print(sum)


n = int(input())
even = []
odd = []
inp = input()
inp = inp.split(' ')
for i in range(n):
	inp[i] = int(inp[i])
for ele in inp:
	if ele % 2 == 0:
		even.append(ele)
	else:
		odd.append(ele)
odd.sort(reverse=True)
even.sort(reverse=True)
if len(odd) > len(even):
	ans = 0
	num = len(even) + 1
	for j in range(num, len(odd)):
		ans += odd[j]
	print(ans)
elif len(even) > len(odd):
	ans = 0
	num = len(odd) + 1
	for j in range(num, len(even)):
		ans += even[j]
	print(ans)
else:
	ans = 0
	print(ans)


n = int(input())
a = list(map(int, input().split()))
d = {'e': [0, []], 'o': [0, []]}
for i in range(n):
	if a[i] % 2 == 0:
		d['e'][0] += 1
		d['e'][1].append(a[i])
	else:
		d['o'][0] += 1
		d['o'][1].append(a[i])
if d['e'][0] == d['o'][0] or abs(d['e'][0] - d['o'][0]) == 1:
	print('0')
else:
	x = min(d['e'][0], d['o'][0]) + 1
	d['e'][1].sort(reverse=True)
	d['o'][1].sort(reverse=True)
	summ = 0
	if x < len(d['e'][1]):
		summ += sum(d['e'][1][x:])
	if x < len(d['o'][1]):
		summ += sum(d['o'][1][x:])
	print(summ)


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in range(len(arr)):
	if arr[i] % 2 == 0:
		even.append(arr[i])
	else:
		odd.append(arr[i])
even.sort(reverse=True)
odd.sort(reverse=True)
sc = sum(even) + sum(odd)
s = 0
if len(even) < len(odd):
	s += sum(even) + sum(odd[:len(even) + 1])
else:
	s += sum(odd) + sum(even[:len(odd) + 1])
print(sc - s)


a = int(input())
nums = map(int, input().split(' '))

def calc(a, nums):
	odds = list()
	evens = list()
	for i in nums:
		if i % 2:
			odds.append(i)
		else:
			evens.append(i)
	if abs(len(odds) - len(evens)) <= 1:
		return 0
	if len(odds) > len(evens):
		return sum(sorted(odds)[:-len(evens) - 1])
	else:
		return sum(sorted(evens)[:-len(odds) - 1])
print(calc(a, nums))


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve():
	n = ii()
	a = li()
	o = []
	e = []
	for i in a:
		if i & 1:
			o.append(i)
		else:
			e.append(i)
	o.sort()
	e.sort()
	ans = 0
	if len(o) >= len(e):
		x = len(o) - len(e) - 1
		if x > 0:
			ans += sum(o[:x])
	else:
		x = len(e) - len(o) - 1
		if x > 0:
			ans += sum(e[:x])
	print(ans)
solve()


k = int(input())
A = sorted([int(x) for x in input().split()])
odd_c = 0
evn_c = 0
odd_a = []
even_a = []
big_even = 0
big_odd = 0
for s in range(k):
	if A[s] % 2 == 0:
		evn_c += 1
		if A[s] > big_even:
			big_even = A[s]
		even_a.append(A[s])
	else:
		odd_c += 1
		if A[s] > big_odd:
			big_odd = A[s]
		odd_a.append(A[s])
if odd_c == evn_c:
	print(0)
elif odd_c == evn_c + 1 or evn_c == odd_c + 1:
	if odd_c != 0 and evn_c != 0:
		print(0)
	elif odd_c == 0:
		print(sum(A) - big_even)
	else:
		print(sum(A) - big_odd)
else:
	W = min(odd_c, evn_c)
	Z = 0
	if W == odd_c:
		Z += sum(even_a[:evn_c - W - 1])
		print(Z)
	else:
		print(sum(odd_a[:odd_c - W - 1]))


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
even = sorted(list(filter(lambda x: x % 2 == 0, a)), key=lambda x: -x)
odd = sorted(list(filter(lambda x: x % 2 != 0, a)), key=lambda x: -x)
s = sum(a)
if len(even) == 0:
	print(s - odd[0])
	exit()
if len(odd) == 0:
	print(s - even[0])
	exit()
x = min(len(even), len(odd))
s1 = sum(even[0:x]) + sum(odd[0:x + 1])
s2 = sum(even[0:x + 1]) + sum(odd[0:x])
print(s - max(s1, s2))


n = int(input())
array = list()
Sum = 0
odd = list()
even = list()
array = [int(x) for x in input().split(' ')]
for number in array:
	Sum += number
	if number % 2:
		odd.append(number)
	else:
		even.append(number)
odd.sort(reverse=True)
even.sort(reverse=True)
k = min(len(odd), len(even))
Sum -= sum(odd[:k]) + sum(even[:k])
if len(odd) > k:
	Sum -= odd[k]
if len(even) > k:
	Sum -= even[k]
print(Sum)


n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
for i in l:
	if i % 2:
		l1.append(i)
	else:
		l2.append(i)
if abs(len(l1) - len(l2)) <= 1:
	print(0)
else:
	a = len(l1)
	b = len(l2)
	l1.sort()
	l2.sort()
	if a > b:
		print(sum(l1[:a - b - 1]))
	else:
		print(sum(l2[:b - a - 1]))


n = int(input())
a = [int(i) for i in input().split()]
e = []
o = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
e = sorted(e, reverse=True)
o = sorted(o, reverse=True)
l = abs(len(e) - len(o))
if l > 1:
	s = 0
	if len(e) > len(o):
		for i in range(len(o) + 1, len(e)):
			s = s + e[i]
	else:
		for i in range(len(e) + 1, len(o)):
			s = s + o[i]
	print(s)
else:
	print(0)


n = int(input())
L = list(map(int, input().split()))
O = []
E = []
for l in L:
	if l % 2 == 1:
		O.append(l)
	else:
		E.append(l)
if abs(len(O) - len(E)) <= 1:
	print(0)
elif len(O) > len(E):
	O.sort()
	print(sum(O[:len(O) - len(E) - 1]))
else:
	E.sort()
	print(sum(E[:len(E) - len(O) - 1]))


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
even.sort()
even = even[::-1]
odd.sort()
odd = odd[::-1]
if abs(len(odd) - len(even)) <= 1:
	print(0)
else:
	o = len(odd)
	e = len(even)
	if o > e:
		print(sum(odd[e + 1:]))
	else:
		print(sum(even[o + 1:]))


def solve(odd, even):
	if len(odd) > len(even):
		l = len(odd) - len(even)
		if l:
			l -= 1
		print(sum(odd[:l]))
	else:
		l = len(even) - len(odd)
		if l:
			l -= 1
		print(sum(even[:l]))
n = int(input())
v = [int(x) for x in input().split()]
odd = sorted([x for x in v if x & 1])
even = sorted([x for x in v if not x & 1])
solve(odd, even)


N = int(input())
sk = [int(x) for x in input().split()]
lyg = []
nel = []
for i in sk:
	if i & 1:
		nel.append(i)
	else:
		lyg.append(i)
did = min(len(nel), len(lyg))
if len(nel) > did:
	nel.sort()
	print(sum(nel[:len(nel) - did - 1]))
elif len(lyg) > did:
	lyg.sort()
	print(sum(lyg[:len(lyg) - did - 1]))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
even = [i for i in a if i % 2 == 0]
odd = [i for i in a if i % 2 != 0]
even.sort()
odd.sort()
elen = len(even)
olen = len(odd)
if elen == olen + 1 or elen + 1 == olen or elen == olen:
	print(0)
else:
	m = min(elen, olen)
	s = 0
	if m == elen:
		for i in range(olen - m - 1):
			s += odd[i]
	else:
		for i in range(elen - m - 1):
			s += even[i]
	print(s)


import sys
input = sys.stdin.readline
n = int(input())
evens = []
odds = []
for i in map(int, input().split()):
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens.sort(reverse=True)
odds.sort(reverse=True)
if len(evens) > len(odds):
	print(sum(evens[len(odds) + 1:]))
elif len(odds) > len(evens):
	print(sum(odds[len(evens) + 1:]))
else:
	print(0)


def minimum_remaining_sum(lst):

	def greedy(lst, op_idx):
		while True:
			try:
				lst = ops[op_idx](lst)
				op_idx = (op_idx + 1) % 2
			except NoMatchingElementException:
				return lst
	rem_odd_start = sum(greedy(lst.copy(), 0))
	rem_even_start = sum(greedy(lst.copy(), 1))
	return min(rem_odd_start, rem_even_start)

def delete_odd(lst):
	for i in range(len(lst)):
		if lst[i] % 2 == 1:
			lst.pop(i)
			return lst
	raise NoMatchingElementException

def delete_even(lst):
	for i in range(len(lst)):
		if lst[i] % 2 == 0:
			lst.pop(i)
			return lst
	raise NoMatchingElementException
ops = [delete_odd, delete_even]

class NoMatchingElementException(Exception):
	pass
_ = int(input())
lst = sorted(map(int, input().split()), reverse=True)
print(minimum_remaining_sum(lst))


a = int(input())
b = map(int, input().split())
odd = []
even = []
sm = 0
for i in b:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
a = len(even)
b = len(odd)
if a == b:
	print(0)
elif a < b:
	print(sum(odd[a + 1:]))
else:
	print(sum(even[b + 1:]))


n = int(input())
f = list(map(int, input().split()))
if n == 1:
	print(f[0], end='')
elif n == 2:
	print(min(f), end='')
else:
	(odd, even) = (list(), list())
	for i in f:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	even.sort()
	odd.sort()
	if len(even) == len(odd):
		print(0, end='')
		exit(0)
	minlen = min(len(even), len(odd)) + 1
	del even[-minlen:]
	del odd[-minlen:]
	print(sum(even) + sum(odd), end='')


t = int(input())
s = list(map(int, input().split()))
s.sort()
a = []
b = []
even = 0
odd = 0
for i in range(t):
	if s[i] % 2 == 0:
		even = even + 1
		a.append(s[i])
	else:
		odd = odd + 1
		b.append(s[i])
if even == odd + 1 or odd == even + 1 or odd == even:
	print('0')
else:
	a.sort()
	b.sort()
	if even > odd:
		z = even - odd
		print(sum(a[:z - 1]))
	else:
		z = odd - even
		print(sum(b[:z - 1]))


N = int(input())
odd = []
even = []
for i in map(int, input().split()):
	odd.append(i) if i % 2 else even.append(i)
if len(odd) == len(even):
	print(0)
	exit()
if len(odd) > len(even):
	(odd, even) = (even, odd)
even.sort(reverse=1)
print(sum(even[len(odd) + 1:]))


N = int(input())
ls = list(map(int, input().split()))
even = []
odd = []
for i in ls:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
least = max(0, abs(len(even) - len(odd)) - 1)
if least == 0:
	print(0)
elif len(odd) > len(even):
	odd.sort()
	odd = odd[:least]
	Sum = 0
	for i in odd:
		Sum += i
	print(Sum)
elif len(even) > len(odd):
	even.sort()
	even = even[:least]
	Sum = 0
	for i in even:
		Sum += i
	print(Sum)


def nonDeleted(L):
	e = []
	o = []
	for i in L:
		if i & 1:
			o.append(i)
		else:
			e.append(i)
	Le = len(e)
	Lo = len(o)
	d = abs(Le - Lo) - 1
	if Le == Lo or d == 0:
		return 0
	if Le > Lo:
		Le = sorted(e)
		return sum(Le[0:d])
	Lo = sorted(o)
	return sum(Lo[0:d])
n = int(input())
L = list(map(int, input().rstrip().split()))
print(nonDeleted(L))


def delete(array, f):
	for j in range(len(array)):
		if f == 0:
			for k in range(len(array)):
				if array[k] % 2 != 0:
					array.remove(array[k])
					f = 1
					break
		else:
			for k in range(len(array)):
				if array[k] % 2 == 0:
					array.remove(array[k])
					f = 0
					break
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
even = a.copy()
odd = a.copy()
if a[0] % 2 == 0:
	even.remove(a[0])
	flag = 0
else:
	odd.remove(a[0])
	flag = 1
delete(even, flag)
delete(odd, flag)
if sum(even) < sum(odd):
	print(sum(even))
else:
	print(sum(odd))


n = int(input())
impar = []
par = []
l = [int(x) for x in input().split()]
l.sort()
for j in l:
	if j % 2 == 0:
		par.append(j)
	else:
		impar.append(j)
l = min(len(par), len(impar))
par = par[:len(par) - l]
impar = impar[:len(impar) - l]
if len(par) == 0 and len(impar) == 0:
	print(0)
elif len(par) == 0:
	print(sum(impar[:-1]))
elif len(impar) == 0:
	print(sum(par[:-1]))
elif par[-1] >= impar[-1]:
	print(sum(par[:-1]) + sum(impar))
else:
	print(sum(par) + sum(impar[:-1]))


n = int(input())
a = []
even_list = []
odd_list = []
a_string = input()
a = a_string.strip().split(' ')
a = [int(i) for i in a]
for i in range(n):
	if a[i] % 2 == 0:
		even_list.append(a[i])
	else:
		odd_list.append(a[i])
even_len = len(even_list)
odd_len = len(odd_list)
if (even_len == odd_len) | (even_len + 1 == odd_len) | (odd_len + 1 == even_len):
	print('0')
elif even_len > odd_len:
	even_list.sort()
	index = -1 * (odd_len + 1)
	even_list = even_list[:index]
	print(sum(even_list))
elif odd_len > even_len:
	odd_list.sort()
	index = -1 * (even_len + 1)
	odd_list = odd_list[:index]
	print(sum(odd_list))


n = int(input())
A = list(map(int, input().split()))
A0 = [a for a in A if a % 2 == 0]
A1 = [a for a in A if a % 2 == 1]
A0.sort()
A1.sort()
L0 = len(A0)
L1 = len(A1)
if abs(L0 - L1) <= 1:
	print(0)
elif L0 > L1:
	x = L0 - L1 - 1
	print(sum(A0[:x]))
elif L0 < L1:
	x = L1 - L0 - 1
	print(sum(A1[:x]))


n = int(input())
arr = list(map(int, input().split()))
odd = 0
even = 0
oa = []
ea = []
for i in range(n):
	if arr[i] % 2 == 0:
		even += 1
		ea.append(arr[i])
	else:
		odd += 1
		oa.append(arr[i])
diff = abs(even - odd)
if diff == 1 or diff == 0:
	print(0)
else:
	ea.sort()
	oa.sort()
	mn = min(odd, even)
	if mn == odd:
		for i in range(2 * mn + 1):
			if i % 2 == 0:
				ea = ea[:-1]
			else:
				oa = oa[:-1]
	else:
		for i in range(2 * mn + 1):
			if i % 2 == 0:
				oa = oa[:-1]
			else:
				ea = ea[:-1]
	print(sum(ea) + sum(oa))


def parDel(arr):
	eA = []
	oA = []
	e = 0
	o = 0
	for i in arr:
		if i % 2 == 0:
			eA.append(i)
			e += 1
		else:
			oA.append(i)
			o += 1
	eA.sort()
	oA.sort()
	if e - o > 1:
		ans = sum(eA[:e - o - 1])
	elif o - e > 1:
		ans = sum(oA[:o - e - 1])
	else:
		return 0
	return ans
n = int(input())
arr = list(map(int, input().split()))
print(parDel(arr))


n = int(input())
num = [int(x) for x in input().split(' ')]
(odd, even, x, y) = ([], [], 0, 0)
for i in range(n):
	if num[i] % 2 == 1:
		odd.append(num[i])
		x += 1
	else:
		even.append(num[i])
		y += 1
odd.sort()
even.sort()
if abs(x - y) <= 1:
	ans = 0
elif x > y:
	d = x - y - 1
	ans = sum(odd[:d])
else:
	d = y - x - 1
	ans = sum(even[:d])
print(ans)


import sys
n = int(input())
l = list(map(int, input().split()))
even = []
odd = []
for i in l:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
if len(even) > len(odd):
	fet = even
else:
	fet = odd
diff = abs(len(even) - len(odd)) - 1
if diff < 1:
	print(0)
	sys.exit()
fet.sort()
tot = 0
for i in range(diff):
	tot += fet[i]
print(tot)


n = int(input())
list1 = list(map(int, input().split()))
list2 = []
list3 = []
for i in list1:
	if i % 2 == 0:
		list2.append(i)
	else:
		list3.append(i)
list2.sort(reverse=True)
list3.sort(reverse=True)
if abs(len(list2) - len(list3)) <= 1:
	print(0)
elif len(list2) > len(list3):
	print(sum(list2[len(list3) + 1:]))
else:
	print(sum(list3[len(list2) + 1:]))


int(input())
a = map(int, input().split())
(o, e) = ([], [])
for aa in a:
	if aa % 2 == 0:
		o.append(aa)
	else:
		e.append(aa)
if abs(len(o) - len(e)) < 2:
	print(0)
elif len(o) > len(e):
	o.sort(reverse=True)
	print(sum(o[len(e) + 1:]))
else:
	e.sort(reverse=True)
	print(sum(e[len(o) + 1:]))


n = int(input())
a = list(map(int, input().split()))
(odd, even) = ([], [])
for _ in range(n):
	if a[_] % 2 == 0:
		even.append(a[_])
	else:
		odd.append(a[_])
odd.sort(reverse=True)
even.sort(reverse=True)
x1 = len(even)
x2 = len(odd)
if x2 > x1:
	print(sum(odd[x1 + 1:]))
else:
	print(sum(even[x2 + 1:]))


import sys
input = sys.stdin.buffer.readline
from math import *
n = int(input())
arr = list(map(int, input().split()))
odd = list(filter(lambda x: x % 2 == 1, arr))
even = list(filter(lambda x: x % 2 == 0, arr))
odd.sort()
even.sort()
od = len(odd)
ev = len(even)
if od == ev or od - ev == 1 or ev - od == 1:
	print('0')
elif od > ev:
	od -= ev + 1
	print(sum(odd[0:od]))
else:
	ev -= od + 1
	print(sum(even[0:ev]))


input()
a = [[], []]
for x in map(int, input().split()):
	a[x % 2] += [x]
(m, n) = map(len, a)
k = min(m, n)
for i in [0, 1]:
	a[i].sort(reverse=True)
print(sum(a[0] + a[1]) - sum(a[0][:k]) - sum(a[1][:k]) - (a[[0, 1][n > k]] + [0])[k] * (m != n))


a = input()
b = input()
hi = sorted([int(i) for i in b.split()])
hi = hi[::-1]
even = []
odd = []
counter = 0
for i in hi:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(even) == len(odd) or abs(len(even) - len(odd)) == 1:
	print(0)
else:
	if len(even) > len(odd):
		counter = sum(odd) + sum(even[0:len(odd) + 1])
	else:
		counter = sum(even) + sum(odd[0:len(even) + 1])
	print(sum(hi) - counter)


cases = int(input())
case_str = list(map(int, input().split(' ')))
case_str.sort()
case_str.reverse()
en_lst = []
od_lst = []
for x in case_str:
	if x % 2 != 0:
		od_lst.append(x)
	else:
		en_lst.append(x)
ln = min(len(od_lst), len(en_lst)) + 1
print(sum(od_lst[ln:]) + sum(en_lst[ln:]))


n = int(str(input()).strip())
arr = [int(x) for x in str(input()).strip().split(' ')]
o = []
e = []
for a in arr:
	if a % 2 == 0:
		e.append(a)
	else:
		o.append(a)
o = list(sorted(o, reverse=True))
e = list(sorted(e, reverse=True))
minoe = min(len(o), len(e))
co = sum(o[minoe + 1:]) + sum(e[minoe:])
ce = sum(e[minoe + 1:]) + sum(o[minoe:])
print(min(co, ce))


n = int(input())
arr = [int(x) for x in input().split()]
odd = [j for j in arr if j & 1]
even = [k for k in arr if k & 1 == 0]
kk = min(len(odd), len(even))
odd = sorted(odd, reverse=True)
even = sorted(even, reverse=True)
odd = odd[kk:]
even = even[kk:]
if len(odd) == 0 and len(even) == 0:
	print(0)
elif len(even) == 0:
	print(sum(odd[1:]))
elif len(odd) == 0:
	print(sum(even[1:]))


n = int(input())
arr = [int(x) for x in input().split()]
e = []
o = []
for i in range(len(arr)):
	if arr[i] % 2:
		e.append(arr[i])
	else:
		o.append(arr[i])
m = 0
if len(e) > len(o):
	e.sort()
	for i in range(len(e) - len(o) - 1):
		m += e[i]
else:
	o.sort()
	for i in range(len(o) - len(e) - 1):
		m += o[i]
print(m)


a = int(input())
b = list(map(int, input().split()))
ch = [x for x in b if x % 2 == 0]
nech = [x for x in b if x % 2 == 1]
ch.sort()
nech.sort()
(e, r) = (len(ch), len(nech))
if max(e, r) - min(e, r) < 2:
	print('0')
else:
	if e > r:
		e = len(ch) - len(nech) - 1
		lk = ch
	else:
		e = len(nech) - len(ch) - 1
		lk = nech
	sym = 0
	for i in range(e):
		sym += lk[i]
	print(sym)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	(even, odd) = ([], [])
	for i in range(n):
		if arr[i] % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	turn = 1 if len(even) > len(odd) else -1
	can = True
	even.sort(reverse=True)
	odd.sort(reverse=True)
	while can:
		if turn == 1 and len(even) > 0:
			even.pop(0)
		elif turn == -1 and len(odd) > 0:
			odd.pop(0)
		else:
			can = False
		turn *= -1
	print(sum(even) + sum(odd))
main()


def calc(n, a):
	even = []
	odd = []
	for i in a:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	even.sort(reverse=True)
	odd.sort(reverse=True)
	if len(even) == 0:
		print(sum(odd[1:]))
	elif len(odd) == 0:
		print(sum(even[1:]))
	elif len(odd) < len(even):
		print(sum(even[len(odd) + 1:]))
	elif len(odd) > len(even):
		print(sum(odd[len(even) + 1:]))
	else:
		print(0)
n = int(input())
a = list(map(int, input().split()))
calc(n, a)


def solve():
	N = int(input())
	A = [int(k) for k in input().split()]
	A.sort()
	even = []
	odd = []
	for i in range(N):
		if A[i] % 2:
			odd.append(A[i])
		else:
			even.append(A[i])
	if len(odd) > len(even):
		while True:
			odd.pop()
			if even:
				even.pop()
			else:
				break
	else:
		while True:
			if even:
				even.pop()
			else:
				break
			if odd:
				odd.pop()
			else:
				break
	print(sum(odd) + sum(even))
solve()


par = []
impar = []
tam_par = 0
tam_impar = 0
res = 0
n = int(input())
s = input()
s = list(map(int, s.split()))
for i in range(0, n):
	if s[i] % 2:
		impar.append(s[i])
		tam_impar += 1
	else:
		par.append(s[i])
		tam_par += 1
if abs(tam_impar - tam_par) == 0 or abs(tam_impar - tam_par) == 1:
	res = 0
elif tam_impar - tam_par < 0:
	par.sort()
	for i in range(0, tam_par - tam_impar - 1):
		res += par[i]
else:
	impar.sort()
	for i in range(0, tam_impar - tam_par - 1):
		res += impar[i]
print(res)


n = int(input())
a = []
b = []
for k in input().split(' '):
	if int(k) % 2 == 0:
		a.append(int(k))
	else:
		b.append(int(k))
u = len(a)
v = len(b)
a.sort()
b.sort()
ans = []
if u > v:
	if u - v < 2:
		ans.append(0)
	elif u - v == 2:
		ans.append(a[0])
	else:
		q = 0
		for i in range(0, len(a) - 1 - len(b)):
			q = q + a[i]
		ans.append(q)
	if v != 0:
		if u - v < 1:
			ans.append(0)
		elif u - v == 1:
			ans.append(a[0])
		else:
			q = 0
			for i in range(0, len(a) - len(b)):
				q = q + a[i]
			ans.append(q)
elif u == v:
	ans.append(0)
else:
	if v - u < 2:
		ans.append(0)
	elif v - u == 2:
		ans.append(b[0])
	else:
		q = 0
		for i in range(0, len(b) - 1 - len(a)):
			q = q + b[i]
		ans.append(q)
	if u != 0:
		if v - u < 1:
			ans.append(0)
		elif v - u == 1:
			ans.append(b[0])
		else:
			q = 0
			for i in range(0, len(b) - len(a)):
				q = q + b[i]
			ans.append(q)
print(min(ans))


n = int(input())
a = list(map(int, input().split()))
odd = [x for x in a if x % 2 != 0]
even = [x for x in a if x % 2 == 0]
even.sort(reverse=True)
odd.sort(reverse=True)
ne = len(even)
no = len(odd)
if abs(ne - no) <= 1:
	print(0)
elif ne > no:
	print(sum(even[no + 1:]))
else:
	print(sum(odd[ne + 1:]))


n = int(input())
(a, b) = ([], [])
for el in map(int, input().split()):
	if el % 2:
		a.append(el)
	else:
		b.append(el)
if len(a) < len(b):
	(a, b) = (b, a)
if len(a) <= len(b) + 1:
	print(0)
else:
	a.sort(reverse=True)
	print(sum(a[len(b) + 1:]))


input()
X = list(map(int, input().split()))
(Odd, Even) = ([], [])
for i in X:
	if i % 2 == 0:
		Even.append(i)
	else:
		Odd.append(i)
if abs(len(Odd) - len(Even)) in [0, 1]:
	print(0)
	exit()
(Odd, Even) = (sorted(Odd), sorted(Even))
if len(Odd) > len(Even):
	print(sum(Odd[:len(Odd) - len(Even) - 1]))
	exit()
print(sum(Even[:len(Even) - len(Odd) - 1]))


n = int(input())
array = input()
A = [int(x) for x in array.split()]
odd_list = []
even_list = []
odd_counter = 0
even_counter = 0
for x in A:
	if x % 2 == 0:
		even_list.append(x)
		even_counter += 1
	else:
		odd_list.append(x)
		odd_counter += 1
if even_counter > odd_counter + 1:
	even_list.sort()
	dif = even_counter - odd_counter - 1
	ans = sum(even_list[:dif])
elif odd_counter > even_counter + 1:
	odd_list.sort()
	dif = odd_counter - even_counter - 1
	ans = sum(odd_list[:dif])
else:
	ans = 0
print(ans)


a = int(input())
o = []
e = []
n = 0
for i in map(int, input().split()):
	if i % 2:
		o += [i]
		n += 1
	else:
		e += [i]
z = a - n
if z > n:
	print(sum(sorted(e, reverse=True)[n + 1:]))
else:
	print(sum(sorted(o, reverse=True)[z + 1:]))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
mod = 10 ** 9 + 7
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	n = int(input())
	arr = list_input()
	(even, odd) = ([], [])
	for i in arr:
		if i % 2 != 0:
			odd.append(i)
		else:
			even.append(i)
	if abs(len(even) - len(odd)) <= 1:
		print(0)
		return
	odd.sort(reverse=True)
	even.sort(reverse=True)
	if odd == []:
		print(sum(even[1:]))
		return
	if even == []:
		print(sum(odd[1:]))
		return
	if len(even) < len(odd):
		print(sum(odd[len(even) + 1:]))
	else:
		print(sum(even[len(odd) + 1:]))
t = 1
for _ in range(t):
	solve()


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if arr[i] % 2 == 0:
		even.append(arr[i])
	else:
		odd.append(arr[i])
l = len(odd)
r = len(even)
mina = min(l, r)
even.sort(reverse=True)
odd.sort(reverse=True)
ans = sum(arr)
suma = 0
for i in range(mina):
	suma += odd[i] + even[i]
if l == mina and l != r:
	suma += even[mina]
elif r == mina and r != l:
	suma += odd[mina]
print(ans - suma)


def check(s):
	ss_even = [i for i in s if i % 2 == 0]
	ss_odd = [i for i in s if i % 2 == 1]
	ss_even.sort()
	ss_odd.sort()
	l_even = len(ss_even)
	l_odd = len(ss_odd)
	if len(s) == 0:
		return 0
	elif l_even == 0:
		rem = l_odd - 1
	elif l_odd == 0:
		rem = l_even - 1
	else:
		rem = abs(l_even - l_odd)
		rem = abs(max(rem - 1, 0))
	if l_even > l_odd:
		return sum(ss_even[:rem])
	else:
		return sum(ss_odd[:rem])
n = int(input())
s = [int(i) for i in input().split()]
print(check(s))


n = int(input())
b = list(map(int, input().split()))
b.sort(reverse=True)
x = 0
y = 0
for i in b:
	if i % 2 == 0:
		x += 1
	else:
		y += 1
if x == y or x == y + 1 or y == x + 1:
	print(0)
elif x == 0 or y == 0:
	print(sum(b) - b[0])
elif x > y:
	x = x - y - 1
	y = 0
	for i in range(len(b) - 1, -1, -1):
		if b[i] % 2 == 0:
			y += b[i]
			x -= 1
		if x == 0:
			break
	print(y)
elif x < y:
	y = y - x - 1
	x = 0
	for i in range(len(b) - 1, -1, -1):
		if b[i] % 2 == 1:
			x += b[i]
			y -= 1
		if y == 0:
			break
	print(x)


import math
n = int(input())
a = input().split(' ')
k1 = 0
k2 = 0
a1 = []
a2 = []
for i in range(n):
	if int(a[i]) % 2 == 0:
		k1 += 1
		a1.append(int(a[i]))
	else:
		k2 += 1
		a2.append(int(a[i]))
ab = abs(k2 - k1)
if ab > 1:
	t = [k2, k1]
	l = t.index(min(t))
	if l == 1:
		a2.sort()
		print(sum(a2[:ab - 1]))
	else:
		a1.sort()
		print(sum(a1[:ab - 1]))
else:
	print(0)


def fn(x):
	if str(x)[-1] in '02468':
		return 1
	return 0
n = int(input())
l = [*map(int, input().split())]
l.sort()
p = 0
f = []
g = []
for j in l:
	t = fn(j)
	p += t
	if t == 1:
		f.append(j)
	else:
		g.append(j)
m = n - p
if p - m == 0 or abs(p - m) == 1:
	print(0)
elif p > m:
	print(sum(f[:-m - 1]))
else:
	print(sum(g[:-p - 1]))


n = int(input())
A = sorted(list(map(int, input().rstrip().split())), reverse=True)
even = []
odd = []
s = 0
for a in A:
	if a % 2 == 0:
		even.append(a)
	else:
		odd.append(a)
if len(even) > len(odd):
	even = sorted(even, reverse=True)
	for i in range(len(odd) + 1, len(even)):
		s += even[i]
elif len(even) < len(odd):
	odd = sorted(odd, reverse=True)
	for i in range(len(even) + 1, len(odd)):
		s += odd[i]
print(s)


n = int(input())
l = list(map(int, input().split()))
l.sort()
odd = []
even = []
l.sort()
for i in l:
	if i % 2 != 0:
		odd.append(i)
	else:
		even.append(i)
if odd == []:
	print(sum(even[:len(even) - 1]))
elif even == []:
	print(sum(odd[:len(odd) - 1]))
else:
	if len(odd) > len(even):
		i = len(odd) - 1
		j = len(even) - 1
		count = 0
		while True:
			if count % 2 == 0:
				if odd != []:
					odd.pop(i)
					i -= 1
				else:
					break
			elif even != []:
				even.pop(j)
				j -= 1
			else:
				break
			count += 1
	else:
		i = len(odd) - 1
		j = len(even) - 1
		count = 0
		while True:
			if count % 2 != 0:
				if odd != []:
					odd.pop(i)
					i -= 1
				else:
					break
			elif even != []:
				even.pop(j)
				j -= 1
			else:
				break
			count += 1
	print(sum(even) + sum(odd))


n = int(input())
nn = list(map(int, input().rstrip().split()))
arrev = []
arrod = []
for i in nn:
	if i % 2 == 0:
		arrev.append(i)
	else:
		arrod.append(i)
arrev.sort(reverse=True)
arrod.sort(reverse=True)
lenev = len(arrev)
lenod = len(arrod)
if lenod == lenev:
	print(0)
elif abs(lenev - lenod) == 1:
	print(0)
elif lenev > lenod:
	arrrem = arrev[lenod + 1:]
	print(sum(arrrem))
elif lenod > lenev:
	arrrem = arrod[lenev + 1:]
	print(sum(arrrem))


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a.reverse()
x1 = []
y = []
for x in a:
	if x % 2 == 0:
		y.append(x)
	else:
		x1.append(x)
x = min(len(x1), len(y)) + 1
print(sum(x1[x:]) + sum(y[x:]))


n = int(input())
a = list(map(int, input().split()))
(even, odd) = ([], [])
for i in range(n):
	if a[i] % 2:
		odd.append(a[i])
	else:
		even.append(a[i])
(odd, even) = (sorted(odd), sorted(even))
if len(odd) > len(even):
	i = 0
	while len(odd):
		if i % 2 == 0:
			if len(odd) == 0:
				break
			s = len(odd) - 1
			odd.pop(s)
		else:
			if len(even) == 0:
				break
			s = len(even) - 1
			even.pop(s)
		i += 1
elif len(even) > len(odd):
	i = 1
	while len(even):
		if i % 2 == 0:
			if len(odd) == 0:
				break
			s = len(odd) - 1
			odd.pop(s)
		else:
			if len(even) == 0:
				break
			s = len(even) - 1
			even.pop(s)
		i += 1
else:
	i = 1
	while len(even) or len(odd):
		if i % 2 == 0:
			if len(odd) == 0:
				break
			s = len(odd) - 1
			odd.pop(s)
		else:
			if len(even) == 0:
				break
			s = len(even) - 1
			even.pop(s)
		i += 1
ans = 0
for i in range(len(odd)):
	ans += odd[i]
for i in range(len(even)):
	ans += even[i]
print(ans)


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

def m():
	evens = []
	odds = []
	for i in a:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	evens_cnt = len(evens)
	odds_cnt = len(odds)
	if abs(evens_cnt - odds_cnt) <= 1:
		return 0
	if evens_cnt > odds_cnt:
		evens.sort(reverse=True)
		return sum(evens[odds_cnt + 1:])
	else:
		odds.sort(reverse=True)
		return sum(odds[evens_cnt + 1:])
print(m())


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	b = sorted([c for c in a if c % 2 == 0])
	c = sorted([c for c in a if c % 2 == 1])
	bl = len(b)
	cl = len(c)
	r = 0
	if abs(bl - cl) < 2:
		return 0
	if bl > cl:
		return sum(b[:bl - cl - 1])
	return sum(c[:cl - bl - 1])
print(main())


n = int(input())
Ar = [int(x) for x in input().split()]
Even_Array = []
Odd_Array = []
for i in Ar:
	if i % 2 == 0:
		Even_Array.append(i)
	else:
		Odd_Array.append(i)
Len_Odd_Array = len(Odd_Array)
Len_Even_Array = len(Even_Array)
Odd_Array.sort()
Even_Array.sort()
if Len_Even_Array - Len_Odd_Array > 0:
	n = Len_Even_Array - Len_Odd_Array
	if n != 0:
		print(sum(Even_Array[:n - 1]))
	else:
		print(0)
else:
	n = Len_Odd_Array - Len_Even_Array
	if n != 0:
		print(sum(Odd_Array[:n - 1]))
	else:
		print(0)


n = int(input())
k = list(map(int, input().split()))
even = sorted([i for i in k if i % 2 == 0], reverse=True)
odd = sorted([i for i in k if i % 2 == 1], reverse=True)
sum1 = 0
if len(even) == len(odd) or len(even) - len(odd) == 1:
	sum1 = 0
elif len(even) > len(odd):
	sum1 = sum(even[len(odd) + 1:])
else:
	sum1 = sum(odd[len(even) + 1:])
print(sum1)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	cnte = 0
	cnto = 0
	a.sort()
	for i in range(len(a)):
		if a[i] % 2 == 0:
			cnte += 1
		else:
			cnto += 1
	if abs(cnte - cnto) <= 1:
		print(0)
		return
	flag = True
	if cnto - cnte >= 1:
		flag = False
	add = 0
	k = abs(cnte - cnto) - 1
	for i in range(len(a)):
		if flag and a[i] % 2 == 0:
			add += a[i]
			k -= 1
			if k == 0:
				print(add)
				return
		elif flag == False and a[i] % 2 != 0:
			add += a[i]
			k -= 1
			if k == 0:
				print(add)
				return
	return
main()


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
arr = []
brr = []
for i in a:
	if i % 2 == 0:
		arr.append(i)
	else:
		brr.append(i)
if abs(len(arr) - len(brr)) <= 1:
	print('0')
elif len(arr) > len(brr):
	print(sum(arr[min(len(arr), len(brr)) + 1:]))
elif len(arr) < len(brr):
	print(sum(brr[min(len(arr), len(brr)) + 1:]))


n = int(input())
a = [int(i) for i in input().split()]
e = []
o = []
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
e.sort(reverse=True)
o.sort(reverse=True)
if len(o) < len(e):
	s = sum(e[len(o) + 1:len(e)])
elif len(e) < len(o):
	s = sum(o[len(e) + 1:len(o)])
else:
	s = 0
print(s)


a = int(input())
s = list(map(int, input().split()))
d = []
f = []
for i in range(a):
	if s[i] % 2 == 0:
		d.append(s[i])
	else:
		f.append(s[i])
if len(f) >= len(d):
	f.sort()
	f.reverse()
	del f[:len(d) + 1]
	print(sum(f))
else:
	d.sort()
	d.reverse()
	del d[:len(f) + 1]
	print(sum(d))


num = int(input())
(even, odd) = (0, 0)
a = list(map(int, input().split()))
for i in range(0, num):
	if a[i] & 1 == 0:
		even += 1
	else:
		odd += 1
a.sort()
Sum = 0
Del = min(even, odd) * 2 + 1
Del = min(num, Del)
Del = num - Del
if Del > 0:
	if even > odd:
		for i in range(0, num):
			if a[i] & 1 == 0:
				Sum += a[i]
				Del -= 1
			if Del == 0:
				break
	else:
		for i in range(0, num):
			if a[i] & 1 == 1:
				Sum += a[i]
				Del -= 1
			if Del == 0:
				break
print(Sum)


n = int(input())
t = list(map(int, input().split(' ')))
even = sum([x % 2 == 0 for x in t])
odd = n - even
if even >= odd - 1 and even <= odd + 1:
	print(0)
elif even > odd:
	t_even = [x for x in t if x % 2 == 0]
	t_even = sorted(t_even)
	print(sum(t_even[:even - odd - 1]))
else:
	t_even = [x for x in t if x % 2 == 1]
	t_even = sorted(t_even)
	print(sum(t_even[:-even + odd - 1]))


n = int(input())
array = input().split(' ')
even = []
odd = []
for i in range(n):
	if int(array[i]) % 2 == 0:
		even.append(int(array[i]))
	else:
		odd.append(int(array[i]))
if abs(len(even) - len(odd)) > 1:
	if len(even) > len(odd):
		even.sort()
		for x in range(len(odd) + 1):
			del even[len(even) - 1]
		sam = 0
		for y in range(len(even)):
			sam += even[y]
		print(sam)
	else:
		odd.sort()
		for x in range(len(even) + 1):
			del odd[len(odd) - 1]
		sam = 0
		for y in range(len(odd)):
			sam += odd[y]
		print(sam)
else:
	print(0)


n = int(input())
s = input()
a = [int(x) for x in s.split() if int(x) % 2 == 0]
b = [int(x) for x in s.split() if int(x) % 2 != 0]
if abs(len(a) - len(b)) < 2:
	print(0)
elif len(b) == 0:
	a.sort()
	print(sum(a[:len(a) - 1]))
elif len(a) == 0:
	b.sort()
	print(sum(b[:len(b) - 1]))
elif len(a) > len(b):
	x = len(b) + 1
	a.sort()
	for i in range(x):
		m = a[-1]
		a.remove(m)
	print(sum(a))
else:
	x = len(a) + 1
	b.sort()
	for i in range(x):
		m = b[-1]
		b.remove(m)
	print(sum(b))


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in arr:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
if len(odd) > len(even):
	sum_ = sum(odd[len(even) + 1:])
	print(sum_)
elif len(odd) < len(even):
	sum_ = sum(even[len(odd) + 1:])
	print(sum_)
else:
	print(0)


input()
(even, odd) = ([], [])
for a in sorted(map(int, input().split())):
	if a % 2:
		odd.append(a)
	else:
		even.append(a)
x = min(len(even), len(odd)) + 1
print(sum(even[:-x]) + sum(odd[:-x]))


n = int(input())
l = list(map(int, input().split()))
odd = []
even = []
for x in l:
	if x % 2:
		odd.append(x)
	else:
		even.append(x)
odd.sort()
even.sort()
while len(odd) and len(even):
	odd.pop()
	even.pop()
if len(odd):
	odd.pop()
if len(even):
	even.pop()
print(sum(odd) + sum(even))


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	x = []
	y = []
	l.sort(reverse=True)
	a = sum(l)
	for i in l:
		if i & 1:
			x.append(i)
		else:
			y.append(i)
	z = min(len(x), len(y))
	a -= sum(x[:z])
	a -= sum(y[:z])
	if len(x) > z:
		a -= x[z]
	if len(y) > z:
		a -= y[z]
	print(a)
for _ in range(1):
	solve()


(n, a) = (int(input()), list(map(int, input().split())))
(o, e) = (sorted(list(filter(lambda _: _ & 1, a))), sorted(list(filter(lambda _: not _ & 1, a))))
idx = min(len(o), len(e))
print(sum(o[:-1 - idx]) + sum(e[:-1 - idx]))


k = int(input())
l = list(map(int, input().split()))
ev1 = 0
ev = []
ed = []
for i in range(k):
	if l[i] % 2 == 0:
		ev1 += 1
		ev.append(l[i])
	else:
		ed.append(l[i])
if abs(len(ev) - len(ed)) == 1 or abs(len(ev) - len(ed)) == 0:
	print(0)
	exit()
else:
	ev.sort()
	ed.sort()
	dif = len(ev) - len(ed)
	if dif > 0:
		print(sum(ev[:abs(dif) - 1]))
	elif dif < 0:
		print(sum(ed[:abs(dif) - 1]))


import math
input()
inlist = map(int, input().split())
chet = list()
nechet = list()
for i in inlist:
	if i % 2 == 0:
		chet.append(i)
	else:
		nechet.append(i)
if math.fabs(len(chet) - len(nechet)) <= 1:
	print('0')
elif len(chet) > len(nechet):
	d = len(chet) - len(nechet)
	chet.sort()
	print(str(sum(chet[0:d - 1])))
else:
	d = len(nechet) - len(chet)
	nechet.sort()
	print(str(sum(nechet[0:d - 1])))


amount = int(input())
arr = sorted([int(i) for i in input().split(' ')])
odd = 0
for i in arr:
	if i % 2 != 0:
		odd += 1
even = len(arr) - odd
diff = abs(even - odd)
if diff < 2:
	del arr
	print(0)
else:
	sum_val = 0
	i = 0
	diff -= 1
	while diff > 0:
		if even > odd:
			if arr[i] % 2 == 0:
				sum_val += arr[i]
				diff -= 1
		elif odd >= even:
			if arr[i] % 2 != 0:
				sum_val += arr[i]
				diff -= 1
		i += 1
	print(sum_val)


n = int(input())
a = list(map(int, input().split()))
a0 = []
a1 = []
for x in a:
	if x % 2 == 0:
		a0.append(x)
	else:
		a1.append(x)
a0.sort(reverse=True)
a1.sort(reverse=True)
len0 = len(a0)
len1 = len(a1)
min_l = min(len0, len1)
print(sum(a0[min_l + 1:]) + sum(a1[min_l + 1:]))


n = int(input())
l = [int(e.strip()) for e in input().strip().split()]
l.sort()
od = []
ev = []
for e in l:
	if e % 2 == 0:
		ev.append(e)
	else:
		od.append(e)
if -2 < len(ev) - len(od) < -1:
	print(0)
elif len(ev) < len(od):
	sum = 0
	for i in range(len(od) - len(ev) - 1):
		sum += od[i]
	print(sum)
else:
	sum = 0
	for i in range(len(ev) - len(od) - 1):
		sum += ev[i]
	print(sum)


n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l, reverse=True)
(even, odd) = ([], [])
for i in l:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
summ = 0
l1 = int(len(odd))
l2 = int(len(even))
if (l1 == 0) | (l2 == 0):
	ind = 1
	if l1 == 0:
		while 1:
			summ += even[ind]
			ind += 1
			if ind == l2:
				break
	else:
		while 1:
			summ += odd[ind]
			ind += 1
			if ind == l1:
				break
elif l2 > l1 + 1:
	ind = l1 + 1
	while 1:
		summ += even[ind]
		ind += 1
		if ind == l2:
			break
elif l1 > l2 + 1:
	ind = l2 + 1
	while 1:
		summ += odd[ind]
		ind += 1
		if ind == l1:
			break
else:
	summ = 0
print(summ)


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
(e, o) = (0, 0)
l = []
m = []
for i in arr:
	if i % 2 == 0:
		e += 1
		l.append(i)
	else:
		o += 1
		m.append(i)
if abs(e - o) < 2:
	print(0)
elif e > o:
	x = e - o - 1
	print(sum(l[:x]))
elif o > e:
	x = o - e - 1
	print(sum(m[:x]))


n = int(input())
data = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if data[i] % 2 == 0:
		even.append(data[i])
	else:
		odd.append(data[i])
le = len(even)
lo = len(odd)
even = sorted(even)
odd = sorted(odd)
if abs(le - lo) <= 1:
	print(0)
elif lo > le:
	x = lo - le - 1
	print(sum(odd[:x]))
else:
	x = le - lo - 1
	print(sum(even[:x]))


n = int(input())
l = list(map(int, input().split()))
ch = []
nch = []
for i in l:
	if i % 2 == 0:
		ch.append(i)
	else:
		nch.append(i)
if abs(len(ch) - len(nch)) <= 1:
	print(0)
elif len(ch) > len(nch):
	ch.sort()
	print(sum(ch[:len(ch) - len(nch) - 1]))
else:
	nch.sort()
	print(sum(nch[:len(nch) - len(ch) - 1]))


no_of_elements = int(input())
array = list(map(int, input().split()))
odd_array = sorted(list(filter(lambda x: x % 2 != 0, array)), reverse=True)
even_array = sorted(list(filter(lambda x: x % 2 == 0, array)), reverse=True)
a = min(len(even_array), len(odd_array))
print(sum(odd_array[a + 1:]) + sum(even_array[a + 1:]))


n = int(input())
a = list(map(int, input().split()))
ev = []
od = []
for i in range(n):
	if a[i] % 2 == 0:
		ev.append(a[i])
	else:
		od.append(a[i])
p = len(ev)
q = len(od)
if p == q or p - q == 1 or q - p == 1:
	print(0)
else:
	s = min(p, q)
	if p == s:
		print(sum(sorted(od)[0:q - p - 1]))
	else:
		print(sum(sorted(ev)[0:p - q - 1]))


import heapq

def Pad(n, arr):
	odd = []
	even = []
	for i in range(n):
		if arr[i] % 2 == 0:
			even.append(arr[i])
		else:
			odd.append(arr[i])
	size = abs(len(odd) - len(even))
	if size == 0:
		return 0
	if len(odd) > len(even):
		ans = heapq.nsmallest(size - 1, odd)
	else:
		ans = heapq.nsmallest(size - 1, even)
	return sum(ans)
n = int(input())
arr = list(map(int, input().split()))
print(Pad(n, arr))


n = int(input())
arr = list(map(int, input().split()))
odd = sorted(filter(lambda x: x % 2 != 0, arr))
even = sorted(filter(lambda x: x % 2 == 0, arr))
if len(odd) > len(even):
	while len(odd) > 0 and len(even) > 0:
		odd.pop()
		even.pop()
	if len(odd) > 0:
		odd.pop()
else:
	while len(odd) > 0 and len(even) > 0:
		even.pop()
		odd.pop()
	if len(even) > 0:
		even.pop()
print(sum(odd) + sum(even))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
a = listIn()
(e, o) = ([], [])
for i in range(n):
	if a[i] % 2 == 0:
		e.append(a[i])
	else:
		o.append(a[i])
if len(e) == n:
	e.sort()
	print(sum(e[:-1]))
	exit(0)
if len(o) == n:
	o.sort()
	print(sum(o[:-1]))
	exit(0)
(e1, o1) = (len(e), len(o))
e.sort()
o.sort()
if e1 == o1:
	print(0)
elif e1 > o1:
	d = e1 - o1
	print(sum(e[:d - 1]))
else:
	d = o1 - e1
	print(sum(o[:d - 1]))


num = int(input().strip())
array = list(map(int, input().strip().split()))
array1 = sorted(array, reverse=True)
array2 = [i for i in array1]
even = True
while True:
	stop = True
	for i in range(len(array1)):
		if array1[i] % 2 == 0:
			if even:
				array1.pop(i)
				stop = False
				break
		elif not even:
			array1.pop(i)
			stop = False
			break
	if even:
		even = False
	else:
		even = True
	if array1 == [] or stop:
		break
even = False
while True:
	stop = True
	for i in range(len(array2)):
		if array2[i] % 2 == 0:
			if even:
				array2.pop(i)
				stop = False
				break
		elif not even:
			array2.pop(i)
			stop = False
			break
	if even:
		even = False
	else:
		even = True
	if array2 == [] or stop:
		break
print(min(sum(array1), sum(array2)))


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
o = e = 0
l = []
m = []
for i in range(n):
	if a[i] % 2 == 0:
		e += 1
		l.append(a[i])
	else:
		o += 1
		m.append(a[i])
l.sort()
m.sort()
if abs(o - e) <= 1:
	ans = 0
elif e > o:
	f = e - o - 1
	ans = sum(l[0:f])
else:
	f = o - e - 1
	ans = sum(m[0:f])
print(ans)


n = int(input())
a = list(map(int, input().split()))
ec = 0
oc = 0
even = []
odd = []
a.sort()
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even2 = even.copy()
odd2 = odd.copy()
for i in range(n):
	if i % 2 == 0 and even:
		even.pop()
	elif i % 2 != 0 and odd:
		odd.pop()
	if i % 2 == 0 and (not odd) or (i % 2 != 0 and (not even)):
		break
sum1 = sum(even) + sum(odd)
for i in range(n):
	if i % 2 != 0 and even2:
		even2.pop()
	elif i % 2 == 0 and odd2:
		odd2.pop()
	if i % 2 == 0 and (not even2) or (i % 2 != 0 and (not odd2)):
		break
sum2 = sum(even2) + sum(odd2)
print(min(sum1, sum2))


import re, math, decimal, bisect, collections

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
n = iread()
arr = sorted(viread())[::-1]
tot = sum(arr)
divd = [[], []]
for i in arr:
	divd[i % 2].append(i)
i = 0
s = 0
while i < min(map(len, divd)):
	s += divd[0][i] + divd[1][i]
	i += 1
if i >= len(divd[0]) and i < len(divd[1]):
	s += divd[1][i]
elif i >= len(divd[1]) and i < len(divd[0]):
	s += divd[0][i]
print(tot - s)


n = int(input())
l = [int(num) for num in input().split()]
(e, o) = ([], [])
for i in range(n):
	if l[i] % 2 == 0:
		e.append(l[i])
	else:
		o.append(l[i])
(l1, l2) = (len(e), len(o))
e.sort(reverse=True)
o.sort(reverse=True)
sum = 0
if l1 - l2 == -1 or l1 == l2 or l1 - l2 == 1:
	pass
elif l1 > l2:
	sum += e[l2 + 1]
	for j in range(l2 + 2, l1):
		sum = sum + e[j]
else:
	sum += o[l1 + 1]
	for j in range(l1 + 2, l2):
		sum = sum + o[j]
print(sum)


n = int(input())
l = list(map(int, input().split()))
a = list()
b = list()
for i in l:
	if i % 2:
		a.append(i)
	else:
		b.append(i)
a.sort()
b.sort()
a.reverse()
b.reverse()
k = min(len(a), len(b))
if abs(len(a) - len(b)) < 2:
	print(0)
else:
	s = 0
	if len(a) < len(b):
		for i in range(k + 1, len(b)):
			s += b[i]
	else:
		for i in range(k + 1, len(a)):
			s += a[i]
	print(s)


def main():
	n = int(input())
	v = input().split()
	a = []
	b = []
	countc = 0
	countn = 0
	for i in range(n):
		if int(v[i]) % 2 == 0:
			countc += 1
			a.append(int(v[i]))
		else:
			countn += 1
			b.append(int(v[i]))
	a.sort()
	b.sort()
	if abs(countc - countn) <= 1:
		ans = 0
	else:
		ans = 0
		if len(a) > len(b):
			for i in range(len(a) - (len(b) + 1)):
				ans += a[i]
		else:
			for i in range(len(b) - (len(a) + 1)):
				ans += b[i]
	print(ans)
main()


def SI():
	return input()

def II():
	return int(SI())

def STI():
	return SI().split()

def ITI():
	return map(int, STI())

def SLI():
	return list(SI())

def ILI():
	return list(ITI())
n = II()
a = ILI()
(e, o) = ([], [])
la = len(a)
for i in range(la):
	e.append(a[i]) if a[i] % 2 == 0 else o.append(a[i])
result = 0
le = len(e)
lo = la - le
if le > lo + 1:
	oe = sorted(e)
	result = sum(oe[:le - lo - 1])
if le + 1 < lo:
	oo = sorted(o)
	result = sum(oo[:lo - le - 1])
print(result)


n = int(input())
l = list(map(int, input().split()))
even = []
odd = []
l.sort()
for s in l:
	if s & 1 == 1:
		odd.append(s)
	else:
		even.append(s)
if len(odd) == len(even):
	print(0)
elif len(odd) > len(even):
	print(sum(odd[:len(odd) - len(even) - 1]))
else:
	print(sum(even[:len(even) - len(odd) - 1]))


mas_y = []
mas_x = []
otv = 0
n = int(input())
vvod = input()
mas_str = vvod.split(' ')
for i in range(n):
	chislo = int(mas_str[i])
	otv += chislo
	if chislo % 2 == 1:
		mas_y.append(chislo)
	else:
		mas_x.append(chislo)
minim = min(len(mas_y), len(mas_x))
mas_y.sort()
mas_x.sort()
for i in range(minim):
	otv -= mas_y[-i - 1]
	otv -= mas_x[-i - 1]
if otv != 0:
	if len(mas_y) > len(mas_x):
		otv -= mas_y[-minim - 1]
	else:
		otv -= mas_x[-minim - 1]
print(otv)


n = int(input())
a = [int(x) for x in input().split()]
even = odd = 0
for i in a:
	if i % 2:
		odd += 1
	else:
		even += 1
d = even - odd
if abs(d) <= 1:
	print(0)
	exit()
balance = d > 0
count = abs(d) - 1
stay = []
for i in a:
	if balance and (not i % 2) or (not balance and i % 2):
		stay.append(i)
stay.sort()
print(sum(stay[:count]))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
odd = []
even = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
l1 = len(odd)
l2 = len(even)
k = -1
if l1 == l2:
	print(0)
elif l1 == l2 + 1 or l1 + 1 == l2:
	print(0)
elif l1 > l2:
	if l2 == 0:
		odd.remove(odd[0])
		print(sum(odd))
	else:
		k = 1
elif l1 == 0:
	even.remove(even[0])
	print(sum(even))
else:
	k = 0
if k == 0 or k == 1:
	while len(odd) != 0 and len(even) != 0:
		if k == 0:
			even.remove(even[0])
			k = 1
		else:
			odd.remove(odd[0])
			k = 0
	if len(even) == 0:
		print(sum(odd[1:]))
	else:
		print(sum(even[1:]))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
(b, c) = ([], [])
for i in a:
	if i % 2:
		b.append(i)
	else:
		c.append(i)
b.sort()
c.sort()
(bb, cc) = (len(b), len(c))
if abs(bb - cc) <= 1:
	ans = 0
elif bb > cc:
	ans = sum(b[:bb - cc - 1])
else:
	ans = sum(c[:cc - bb - 1])
print(ans)


n = int(input())
(odd, even) = ([], [])
for a in map(int, input().split()):
	if a % 2 == 0:
		even.append(a)
	else:
		odd.append(a)
odd = sorted(odd)
even = sorted(even)
if len(odd) > len(even):
	odd.pop()
	prev_odd = True
elif len(odd) < len(even):
	even.pop()
	prev_odd = False
elif odd[-1] > even[-1]:
	odd.pop()
	prev_odd = True
else:
	even.pop()
	prev_odd = False
while (len(odd) > 0 or prev_odd) and (len(even) > 0 or not prev_odd):
	if prev_odd:
		even.pop()
	else:
		odd.pop()
	prev_odd = not prev_odd
print(sum(even) + sum(odd))


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
a.reverse()
odd = 0
even = 0
b = []
c = []
for i in range(len(a)):
	if a[i] % 2 == 1:
		b.append(a[i])
		odd += 1
	else:
		even += 1
		c.append(a[i])
s = 0
t = 0
if odd > even:
	i = odd - (even + 1)
	s = sum(b[odd - i:])
	s += sum(c[even:])
elif even > odd:
	i = even - (odd + 1)
	s = sum(b[odd:])
	s += sum(c[even - i:])
else:
	s = sum(b[odd:])
	s += sum(c[even:])
print(s)


n = int(input())
l = list(map(int, input().split()))
even = []
odd = []
for i in l:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
if len(even) == len(odd):
	print(0)
elif len(even) + 1 == len(odd) or len(odd) + 1 == len(even):
	print(0)
elif len(even) > len(odd):
	x = len(even) - len(odd) - 1
	even.sort()
	s = 0
	for i in range(x):
		s += even[i]
	print(s)
else:
	x = len(odd) - len(even) - 1
	odd.sort()
	s = 0
	for i in range(x):
		s += odd[i]
	print(s)


import sys
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
n = I()
l = li()
l.sort()
odd = []
even = []
for i in l:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
o = len(odd)
e = len(even)
if o == e or o + 1 == e or o == e + 1:
	print(0)
elif o > e:
	odd = odd[:o - e - 1]
	print(sum(odd))
else:
	even = even[:e - o - 1]
	print(sum(even))


int(input())
a = list(map(int, input().split(' ')))
b = list(filter(lambda x: x % 2 == 0, a))
b.sort(reverse=True)
c = list(filter(lambda x: x % 2 != 0, a))
c.sort(reverse=True)
if abs(len(b) - len(c)) <= 1:
	print(0)
else:
	if len(b) < len(c):
		(b, c) = (c, b)
	b.sort()
	s = 0
	for i in range(0, len(b) - len(c) - 1):
		s += b[i]
	print(s)


n = int(input())
A = list(map(int, input().split()))
A1 = sorted((a for a in A if a % 2))
A2 = sorted((a for a in A if a % 2 == 0))
mlen = min(len(A1), len(A2))
(A1, A2) = (A1[:len(A1) - mlen], A2[:len(A2) - mlen])
print(sum((A1 + A2)[:-1]))


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even_len = len(even)
odd_len = len(odd)
sum = 0
if odd_len - even_len in range(-1, 2):
	print(0)
else:
	diff = odd_len - even_len
	if diff > 0:
		odd.sort()
		for j in range(diff - 1):
			sum += odd[j]
	else:
		diff = 0 - diff
		even.sort()
		for j in range(diff - 1):
			sum += even[j]
	print(sum)


n = int(input())
nums = [int(s) for s in input().split(' ')]
odd = [num for num in nums if num & 1 == 1]
even = [num for num in nums if num & 1 == 0]
ol = len(odd)
oe = len(even)
if ol < oe - 1:
	diff = oe - ol - 1
	even.sort()
	print(sum(even[:diff]))
elif oe < ol - 1:
	diff = ol - oe - 1
	odd.sort()
	print(sum(odd[:diff]))
else:
	print(0)


def MinimizeleftOverSum(a, n):
	(v1, v2) = ([], [])
	for i in range(n):
		if a[i] % 2:
			v1.append(a[i])
		else:
			v2.append(a[i])
	if len(v1) > len(v2):
		v1.sort()
		v2.sort()
		x = len(v1) - len(v2) - 1
		sum = 0
		i = 0
		while i < x:
			sum += v1[i]
			i += 1
		return sum
	elif len(v2) > len(v1):
		v1.sort()
		v2.sort()
		x = len(v2) - len(v1) - 1
		sum = 0
		i = 0
		while i < x:
			sum += v2[i]
			i += 1
		return sum
	else:
		return 0
n = int(input())
a = list(map(int, input().split()))
n = len(a)
print(MinimizeleftOverSum(a, n))


t = int(input())
l = list(map(int, input().split()))
pair = [x for x in l if x % 2 == 0]
unpair = [x for x in l if x % 2 == 1]
pair.sort()
unpair.sort()
pair.reverse()
unpair.reverse()
n = len(pair)
m = len(unpair)
if n == m or abs(n - m) == 1:
	print(0)
elif n > m:
	print(sum(pair[m + 1:]))
else:
	print(sum(unpair[n + 1:]))


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	GI()
	xs = GIS()
	ps = [[], []]
	for x in xs:
		ps[x % 2].append(x)
	ps.sort(key=len)
	lendiff = len(ps[1]) - len(ps[0])
	if lendiff > 1:
		large = ps[1]
		large.sort()
		print(sum(large[:lendiff - 1]))
	else:
		print(0)
main()


N = int(input())
ITEMS = [int(item) for item in input().split()]
ODDS = [item for item in ITEMS if item % 2 != 0]
EVENS = [item for item in ITEMS if item % 2 == 0]
if len(EVENS) > len(ODDS):
	for _ in range(len(ODDS) + 1):
		EVENS.remove(max(EVENS))
	print(sum(EVENS))
elif len(EVENS) < len(ODDS):
	for _ in range(len(EVENS) + 1):
		ODDS.remove(max(ODDS))
	print(sum(ODDS))
else:
	print('0')


import math
n = int(input())
a = [int(i) for i in input().split()]
even = sorted([i for i in a if i % 2 == 0])
odd = sorted([i for i in a if i % 2 == 1])
if abs(len(even) - len(odd)) <= 1:
	print(0)
elif len(even) > len(odd):
	one = even[:len(even) - len(odd) - 1]
	print(sum(one))
else:
	one = odd[:len(odd) - len(even) - 1]
	print(sum(one))


n = int(input())
A = list(map(int, input().split()))
A.sort()
nodds = 0
nevens = 0
for i in range(len(A)):
	p1 = A[i] % 2
	if p1 == 1:
		nodds = nodds + 1
	if p1 == 0:
		nevens = nevens + 1
if nodds > nevens:
	startparity = 1
	nextparity = 0
	nodds -= 1
else:
	startparity = 0
	nextparity = 1
	nevens -= 1
for i in range(len(A) - 1, -1, -1):
	if A[i] % 2 == startparity:
		A[i] = -1
		break
while nextparity == 1 and nodds > 0 or (nextparity == 0 and nevens > 0):
	for i in range(len(A) - 1, -1, -1):
		if A[i] != -1 and A[i] % 2 == nextparity:
			A[i] = -1
			if nextparity == 1:
				nodds -= 1
			else:
				nevens -= 1
			nextparity = 1 - nextparity
			break
s = 0
for a in A:
	if a != -1:
		s += a
print(s)


from sys import stdin, stdout
import sys
import math
sys.setrecursionlimit(15000)

def get_count(arr):
	even = []
	odd = []
	for i in arr:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	return (even, odd)
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
arr.sort()
(even, odd) = get_count(arr)
if len(even) < len(odd):
	while len(even) > 0:
		if len(even) > 0:
			even.pop()
		odd.pop()
	if len(odd) > 0:
		odd.pop()
	print(sum(even) + sum(odd))
else:
	while len(odd) > 0:
		if len(odd) > 0:
			odd.pop()
		even.pop()
	if len(even) > 0:
		even.pop()
	print(sum(even) + sum(odd))


n = int(input())
x = [int(i) for i in input().split()]
odd = []
even = []
for i in x:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
diff = len(even) - len(odd)
if diff <= 1 and diff >= -1:
	sum = 0
elif len(even) > len(odd):
	sum = sum(even[len(odd) + 1:])
else:
	sum = sum(odd[len(even) + 1:])
print(sum)


(n, a) = (int(input()), list(map(int, input().split())))
even = list(filter(lambda x: x % 2 == 0, a))
odd = list(filter(lambda x: x % 2 != 0, a))
a.sort()
odd.sort()
odd.reverse()
even.sort()
even.reverse()
min1 = min(len(even), len(odd))
print(sum(even[min1 + 1:]) + sum(odd[min1 + 1:]))


a = [[], []]
input()
for ai in map(int, input().split()):
	a[ai % 2].append(ai)
(a, b) = a
a.sort()
b.sort()
print(sum(a[:-len(b) - 1] + b[:-len(a) - 1]))


n = int(input())
a = map(int, input().split())
odds = []
evens = []
for number in a:
	if number % 2 == 0:
		evens.append(number)
	else:
		odds.append(number)
o = len(odds)
e = len(evens)
if o - e in [-1, 0, 1]:
	print(0)
else:
	if o > 0:
		odds.sort()
	if e > 0:
		evens.sort()
	if o > e:
		print(sum(odds[:o - e - 1]))
	elif e > o:
		print(sum(evens[:e - o - 1]))


def parity_brute_force(x):
	bit = 0
	num_bits = 0
	while x:
		bitmask = 1 << bit
		bit += 1
		if x & bitmask:
			num_bits += 1
		x &= ~bitmask
	return num_bits % 2
n = int(input())
s = list(map(int, input().split()))
s.sort()
o = []
e = []
par = []
for i in s:
	if i % 2:
		o.append(i)
	else:
		e.append(i)
x = len(o)
y = len(e)
if x > y + 1:
	print(sum(o[:x - y - 1]))
elif y > x + 1:
	print(sum(e[:y - x - 1]))
else:
	print(0)


def check(line):
	lst = sorted(line)
	last = -1
	for item in lst:
		if last != -1 and ord(item) != last + 1:
			return False
		last = ord(item)
	return True

def main():
	n_row = input()
	line = input()
	num = line.split(' ')
	(odd, even) = ([], [])
	for i in num:
		item = int(i)
		if item % 2:
			odd.append(item)
		else:
			even.append(item)
	odd = sorted(odd, reverse=True)
	even = sorted(even, reverse=True)
	if abs(len(odd) - len(even)) <= 1:
		print(0)
		return
	min_size = min(len(odd), len(even))
	sum = 0
	for i in range(min_size + 1, len(odd)):
		sum += odd[i]
	for i in range(min_size + 1, len(even)):
		sum += even[i]
	print(sum)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return (int(input()), [int(i) for i in input().split()])

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	(n, a) = get()
	odd = []
	even = []
	for i in range(n):
		if a[i] % 2 == 0:
			odd.append(a[i])
		else:
			even.append(a[i])
	(x, y) = (len(odd), len(even))
	if abs(x - y) <= 1:
		print(0)
	else:
		odd = sorted(odd, reverse=True)
		even = sorted(even, reverse=True)
		if x > y:
			print(sum(odd) - sum(odd[:y + 1]))
		else:
			print(sum(even) - sum(even[:x + 1]))
main()


n = int(input())
arr = input().split()
arr = [int(x) for x in arr]
chet_arr = []
nechet_arr = []
for x in arr:
	if x % 2 == 0:
		chet_arr.append(x)
	else:
		nechet_arr.append(x)
if abs(len(chet_arr) - len(nechet_arr)) < 2:
	print(0)
else:
	r = len(nechet_arr) - len(chet_arr)
	if r > 0:
		nechet_arr.sort()
		print(sum(nechet_arr[0:r - 1]))
	else:
		r = -1 * r
		chet_arr.sort()
		print(sum(chet_arr[0:r - 1]))


n = int(input())
a = list(map(int, input().split(' ')))
ach = []
anech = []
for i in range(n):
	if a[i] % 2 == 0:
		ach.append(a[i])
	else:
		anech.append(a[i])
if abs(len(ach) - len(anech)) < 2:
	print(0)
elif len(ach) - len(anech) > 1:
	ach.sort()
	print(sum(ach[:len(ach) - len(anech) - 1]))
else:
	anech.sort()
	print(sum(anech[:len(anech) - len(ach) - 1]))


input()
numbers = list(map(int, input().split()))
even = []
odd = []
for number in numbers:
	if number & 1:
		odd.append(number)
	else:
		even.append(number)
even_len = len(even)
odd_len = len(odd)
dif = abs(even_len - odd_len)
if dif <= 1:
	print(0)
else:
	dif -= 1
	result = 0
	is_even = True if min(even_len, odd_len) == odd_len else False
	if is_even:
		even.sort(reverse=True)
		for _ in range(dif):
			result += even.pop()
	else:
		odd.sort(reverse=True)
		for _ in range(dif):
			result += odd.pop()
	print(result)


n = int(input())
A = sorted(list(map(int, input().split())))
odd = 0
even = 0
sum = 0
for i in range(n):
	if A[i] % 2 == 0:
		even += 1
	else:
		odd += 1
if even > odd:
	e = even - odd - 1
	i = 0
	while e > 0:
		if A[i] % 2 == 0:
			sum += A[i]
			e = e - 1
		i += 1
elif even < odd:
	o = odd - even - 1
	i = 0
	while o > 0:
		if A[i] % 2 == 1:
			sum += A[i]
			o = o - 1
		i += 1
print(sum)


def process(A, n):
	odd = []
	even = []
	for i in A:
		if i % 2 == 1:
			odd.append(i)
		else:
			even.append(i)
	if abs(len(odd) - len(even)) == 1 or len(odd) == len(even):
		return 0
	elif len(odd) > len(even):
		a = len(odd) - 1 - len(even)
		odd.sort()
		return sum(odd[:a])
	elif len(odd) < len(even):
		b = len(even) - 1 - len(odd)
		even.sort()
		return sum(even[:b])
n = int(input())
A = []
for x in input().split():
	A.append(int(x))
print(process(A, n))


n = int(input())
evens = []
odds = []
for x in input().split():
	x = int(x)
	if x % 2 == 0:
		evens.append(x)
	else:
		odds.append(x)
evens.sort()
odds.sort()
common = min(len(evens), len(odds))
deletes = 0
if common > 0:
	for x in evens[-common:]:
		deletes += x
	for x in odds[-common:]:
		deletes += x
if len(evens) > common:
	y = evens[-common - 1]
else:
	y = 0
if len(odds) > common:
	z = odds[-common - 1]
else:
	z = 0
print(sum(evens) + sum(odds) - deletes - max(y, z))


n = int(input())
odd = odd_sum = even = even_sum = 0
even_list = []
odd_list = []
x = list(map(int, input().split()))
for i in range(n):
	if x[i] % 2 == 0:
		even += 1
		even_list.append(x[i])
		even_sum += x[i]
	else:
		odd += 1
		odd_list.append(x[i])
		odd_sum += x[i]
even_list.sort()
odd_list.sort()
if odd > even:
	print(sum(odd_list[0:odd - even - 1]))
elif even > odd:
	print(sum(even_list[0:even - odd - 1]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
odd = []
even = []
for j in l:
	if j % 2 == 0:
		even.append(j)
	else:
		odd.append(j)
odd.sort(reverse=True)
even.sort(reverse=True)
evenL = len(even)
oddL = len(odd)
mm = min(evenL, oddL)
neven = even[mm:evenL]
nodd = odd[mm:oddL]
if len(neven) > len(nodd):
	summ = sum(neven) - neven[0] + sum(nodd)
elif len(neven) < len(nodd):
	summ = sum(neven) - nodd[0] + sum(nodd)
else:
	summ = 0
print(summ)


n = int(input())
a = [int(x) for x in input().split()]
evens = []
odds = []
for i in a:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens = sorted(evens)
odds = sorted(odds)
if abs(len(evens) - len(odds)) <= 1:
	print(0)
elif len(evens) > len(odds):
	rem = len(evens) - len(odds) - 1
	print(sum(evens[:rem]))
else:
	rem = len(odds) - len(evens) - 1
	print(sum(odds[:rem]))


a = int(input())
ent = input().split()
pares = []
imp = []
for num in ent:
	if int(num) % 2 == 0:
		pares.append(int(num))
	else:
		imp.append(int(num))
pares.sort()
imp.sort()
dif = len(pares) - len(imp)
if dif < -1:
	for i in range(len(pares) + 1):
		imp.pop()
	print(sum(imp))
elif dif > 1:
	for i in range(len(imp) + 1):
		pares.pop()
	print(sum(pares))
else:
	print(0)


z = []
x = int(input())
s = [int(n) for n in input().split()]
s.sort()
s = s[::-1]
z += [n % 2 for n in s]
evv = z.count(0)
odd = z.count(1)
e = [n for n in s if n % 2 == 0]
o = [n for n in s if n % 2 == 1]
if evv > odd:
	print(sum(e[odd + 1:]))
elif odd > evv:
	print(sum(o[evv + 1:]))
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
while len(arr) > 0:
	ele = arr.pop(0)
	if ele % 2 == 0:
		even.append(ele)
	else:
		odd.append(ele)
if len(even) == len(odd):
	print(0)
elif len(even) > len(odd):
	diff = len(even) - len(odd)
	even.sort()
	ans = 0
	for i in range(diff - 1):
		ans += even[i]
	if diff == 1:
		ans = 0
	print(ans)
else:
	diff = -1 * (len(even) - len(odd))
	odd.sort()
	ans = 0
	for i in range(diff - 1):
		ans += odd[i]
	if diff == 1:
		ans = 0
	print(ans)


number = input()
values = list(map(int, input().split(' ')))
odd = []
even = []
for i in values:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if len(sorted(odd)) == len(sorted(even)):
	print(0)
elif len(sorted(odd)) - len(sorted(even)) == -1 or len(sorted(odd)) - len(sorted(even)) == 1:
	print(0)
elif len(sorted(odd)) > len(sorted(even)):
	sum = 0
	for i in range(len(sorted(odd)) - len(sorted(even)) - 1):
		sum = sum + sorted(odd)[i]
	print(sum)
elif len(sorted(even)) > len(sorted(odd)):
	sum = 0
	for i in range(len(sorted(even)) - len(sorted(odd)) - 1):
		sum = sum + sorted(even)[i]
	print(sum)


n = int(input())
a = list(map(int, input().split()))
vals = [[] for i in range(2)]
for x in a:
	vals[x % 2].append(x)
cnt = [len(vals[i]) for i in range(0, 2)]
for i in range(0, 2):
	vals[i].sort()
	vals[i].reverse()
best = 2 * 10 ** 9
for start in range(0, 2):
	if not vals[start]:
		continue
	can = min(len(vals[start]), len(vals[start ^ 1]))
	for i in range(0, 2):
		f = [can, can]
		f[start] += i
		if f[start] > len(vals[start]):
			continue
		cur_val = 0
		for k in range(0, 2):
			for j in range(0, len(vals[k])):
				if j >= f[k]:
					cur_val += vals[k][j]
		best = min(best, cur_val)
print(best)


n = int(input())
lista = str(input()).split()
impar = []
par = []
flag = False
flag2 = False
tamanho = 0
tamanho2 = 0
for num in lista:
	if int(num) % 2 == 1:
		impar.append(int(num))
	else:
		par.append(int(num))
tamanho = len(impar)
tamanho2 = len(par)
impar.sort()
par.sort()
if (tamanho > tamanho2 or tamanho == tamanho2) and (tamanho != 0 or tamanho2 != 0):
	while (tamanho != 0 or tamanho2 != 0) and flag == False and (flag2 == False):
		if tamanho != 0:
			del impar[-1]
			tamanho = tamanho - 1
		else:
			flag = True
		if tamanho2 != 0:
			del par[-1]
			tamanho2 = tamanho2 - 1
		else:
			flag2 = True
elif tamanho2 > tamanho and (tamanho != 0 or tamanho2 != 0):
	while (tamanho != 0 or tamanho2 != 0) and flag == False and (flag2 == False):
		if tamanho2 != 0:
			del par[-1]
			tamanho2 = tamanho2 - 1
		else:
			flag2 = True
		if tamanho != 0:
			del impar[-1]
			tamanho = tamanho - 1
		else:
			flag = True
if tamanho == 0 and tamanho2 == 0:
	print('0')
elif tamanho == 0 and tamanho2 != 0:
	print(sum(par))
elif tamanho != 0 and tamanho2 == 0:
	print(sum(impar))


n = int(input())
alist = list(map(int, input().split()))
blist = []
clist = []
for i in alist:
	if i % 2 == 1:
		blist.append(i)
	else:
		clist.append(i)
b = len(blist)
c = len(clist)
blist.sort(reverse=True)
clist.sort(reverse=True)
if abs(b - c) <= 1:
	print('0')
elif b > c:
	blist = blist[c + 1:]
	print(sum(blist))
elif c > b:
	clist = clist[b + 1:]
	print(sum(clist))


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
for i in range(len(l)):
	if l[i] % 2 == 0:
		e.append(l[i])
	else:
		o.append(l[i])
ek = len(e)
ok = len(o)
if ek == ok + 1 or ok + 1 == ek or ek == ok:
	print('0')
elif ek > ok:
	d = ek - ok - 1
	sum = 0
	for i in range(d):
		k = min(e)
		m = e.index(k)
		e.pop(m)
		sum += k
	print(sum)
else:
	d = ok - ek - 1
	sum = 0
	for i in range(d):
		k = min(o)
		m = o.index(k)
		o.pop(m)
		sum += k
	print(sum)


n = int(input())
h = input()
ch = 0
nch = 0
nch1 = 0
k = 0
s = 0
mas = list(map(int, h.split(' ')))
for i in range(n):
	if mas[i] % 2 == 0:
		ch = ch + 1
	else:
		nch = nch + 1
if abs(nch - ch) <= 1:
	print(0)
else:
	k = nch - ch
	if k > 0:
		nch1 = 1
	else:
		nch1 = 0
	mas.sort()
	i = 0
	k = abs(k) - 1
	while k != 0:
		if nch1 == 1:
			if mas[i] % 2 != 0:
				s = s + mas[i]
				k = k - 1
		elif mas[i] % 2 == 0:
			s = s + mas[i]
			k = k - 1
		i = i + 1
	print(s)


n = int(input())
a = [int(x) for x in input().split()]
odd = []
even = []
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
leven = len(even)
lodd = len(odd)
if leven > lodd:
	even.sort()
	print(sum(even[:leven - lodd - 1]))
elif leven < lodd:
	odd.sort()
	print(sum(odd[:-leven + lodd - 1]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split(' ')))
l.sort(reverse=True)
odd = []
even = []
for x in l:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
if len(odd) >= len(even):
	p = len(even)
	ans = sum(odd[p + 1:])
else:
	p = len(odd)
	ans = sum(even[p + 1:])
print(ans)


n = int(input())
arr = list(map(int, input().split()))
cnt_even = 0
cnt_odd = 0
even = []
odd = []
flag = False
for i in range(n):
	if arr[i] % 2 == 0:
		cnt_even += 1
		even.append(arr[i])
	else:
		cnt_odd += 1
		odd.append(arr[i])
even.sort()
odd.sort()
if cnt_even == 0:
	cnt_odd -= 1
	flag = True
elif cnt_odd == 0:
	cnt_even -= 1
	flag = True
if (cnt_even == cnt_odd or cnt_even + 1 == cnt_odd or cnt_even == cnt_odd + 1) and flag == False:
	print('0')
elif cnt_even > cnt_odd and flag == False:
	index = cnt_even - cnt_odd - 1
	print(sum(even[0:index]))
elif cnt_even < cnt_odd and flag == False:
	index = cnt_odd - cnt_even - 1
	print(sum(odd[0:index]))
elif cnt_even >= cnt_odd and flag == True:
	index = cnt_even
	print(sum(even[0:index]))
elif cnt_even <= cnt_odd and flag == True:
	index = cnt_odd
	print(sum(odd[0:index]))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=1)
ch = []
nch = []
for i in a:
	if i % 2 == 0:
		ch.append(i)
	else:
		nch.append(i)
if len(ch) == len(nch):
	print(0)
	exit(0)
if len(ch) > len(nch):
	print(sum(ch[len(nch) + 1:]))
else:
	print(sum(nch[len(ch) + 1:]))


n = int(input())
a = list(map(int, input().split(' ')))
odd = sorted(filter(lambda x: x % 2 == 1, a))
even = sorted(filter(lambda x: x % 2 == 0, a))
if len(odd) > len(even):
	odd.pop()
elif len(even) > len(odd):
	even.pop()
while len(odd) > 0 and len(even) > 0:
	odd.pop()
	even.pop()
print(sum(odd) + sum(even))


n = int(input())
s = map(int, input().split())
even = list()
odd = list()
for it in s:
	if it % 2 == 0:
		even.append(it)
	else:
		odd.append(it)
if abs(len(even) - len(odd)) <= 1:
	print(0)
else:
	even = sorted(even)
	odd = sorted(odd)
	if len(even) > len(odd):
		print(sum(even[:-len(odd) - 1]))
	else:
		print(sum(odd[:-len(even) - 1]))


def parity():
	n = int(input())
	I = list(map(int, input().split(' ')))
	even = []
	odd = []
	for i in I:
		if i % 2 == 0:
			even.append(i)
		if i % 2 == 1:
			odd.append(i)
	if len(even) == len(odd) + 1 or len(even) + 1 == len(odd) or len(even) == len(odd):
		return 0
	if len(even) < len(odd):
		odd = sorted(odd)
		diff = len(odd) - len(even)
		sum = 0
		for i in range(diff - 1):
			sum += odd[i]
		return sum
	if len(even) > len(odd):
		even = sorted(even)
		diff = len(even) - len(odd)
		sum = 0
		for i in range(diff - 1):
			sum += even[i]
		return sum
print(parity())


_ = input()
inp_list = list(map(int, input().split()))

def solve(list_):
	odds = []
	evens = []
	for num in list_:
		if num % 2 == 0:
			evens.append(num)
		else:
			odds.append(num)
	if abs(len(odds) - len(evens)) <= 1:
		return 0
	is_odd_deletion = len(odds) > len(evens)
	if is_odd_deletion:
		odds = sorted(odds, reverse=True)
		res = sum(odds[len(evens) + 1:])
	else:
		evens = sorted(evens, reverse=True)
		res = sum(evens[len(odds) + 1:])
	return res
res = solve(inp_list)
print(res)


n = int(input())
l = sorted(list(map(int, input().split())))
l = l[::-1]
(o, e) = ([], [])
for i in range(n):
	if l[i] % 2 == 0:
		e.append(l[i])
	else:
		o.append(l[i])
a = len(e)
b = len(o)
if a == 0:
	print(sum(o) - o[0])
elif b == 0:
	print(sum(e) - e[0])
elif a == b or a + 1 == b or b == a + 1:
	print('0')
else:
	m = min(a, b)
	if a > m:
		print(sum(e[m + 1:]))
	else:
		print(sum(o[m + 1:]))


n = int(input())
l = sorted(list(map(int, input().split())))
counte = []
counto = []
for i in range(n):
	if l[i] % 2 == 0:
		counte.append(l[i])
	else:
		counto.append(l[i])
if len(counte) == len(counto) or len(counte) + 1 == len(counto) or len(counte) == len(counto) + 1:
	print(0)
elif len(counte) > len(counto):
	print(sum(counte[:len(counte) - len(counto) - 1]))
elif len(counte) < len(counto):
	print(sum(counto[:len(counto) - len(counte) - 1]))


n = int(input())
odd = 0
even = 0
odd_min = []
even_min = []
s = list(map(int, input().split()))
for i in range(0, n):
	a = s[i]
	if a & 1 == 1:
		odd += 1
		odd_min.append(a)
	else:
		even += 1
		even_min.append(a)
summ = 0
if even - odd >= -1 and even - odd <= 1:
	print(0)
else:
	if even > odd:
		even_min.sort()
		for i in range(0, even - odd - 1):
			summ += even_min[i]
	else:
		odd_min.sort()
		for i in range(0, odd - even - 1):
			summ += odd_min[i]
	print(summ)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
n = ri(1)
a = ri()
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
ans = 0
i = 0
j = 0
f = 0
while 1:
	try:
		if f == 0:
			f = 1
			ans += even[i]
			i += 1
		else:
			f = 0
			ans += odd[j]
			j += 1
	except:
		break
ans1 = 0
i = 0
j = 0
f = 1
while 1:
	try:
		if f == 0:
			f = 1
			ans1 += even[i]
			i += 1
		else:
			f = 0
			ans1 += odd[j]
			j += 1
	except:
		break
print(sum(a) - max(ans, ans1))


n = int(input())
m = list(map(int, input().split()))
even = []
odd = []
lodd = 0
leven = 0
for i in m:
	if i % 2:
		even.append(i)
		leven += 1
	else:
		odd.append(i)
		lodd += 1
if abs(leven - lodd) < 2:
	print(0)
	exit()
else:
	even.sort()
	odd.sort()
	if lodd - min(lodd, leven) - 1 == -1:
		kk = 0
	else:
		kk = lodd - min(lodd, leven) - 1
	if leven - min(lodd, leven) - 1 == -1:
		kkk = 0
	else:
		kkk = leven - min(lodd, leven) - 1
	print(sum(odd[0:kk]) + sum(even[0:kkk]))


n = int(input().strip())
l = list(map(int, input().split()))
l_odd = [x for x in l if x % 2 != 0]
l_even = [x for x in l if x % 2 == 0]
prev = None
for i in range(n):
	if i == 0:
		if len(l_odd) != len(l_even) and len(l_odd) > len(l_even):
			del l_odd[l_odd.index(max(l_odd))]
			prev = False
		elif len(l_odd) != len(l_even) and len(l_odd) < len(l_even):
			del l_even[l_even.index(max(l_even))]
			prev = True
		else:
			temp = max(l)
			if temp % 2 == 0:
				del l_even[l_even.index(temp)]
				prev = True
			else:
				prev = False
				del l_odd[l_odd.index(temp)]
	if prev and len(l_odd) > 0:
		del l_odd[l_odd.index(max(l_odd))]
		prev = False
	elif not prev and len(l_even) > 0:
		del l_even[l_even.index(max(l_even))]
		prev = True
print(sum(l_odd + l_even))


n = int(input())
a = list(map(int, input().split()))
codd = 0
ceven = 0
odd = []
even = []
for i in a:
	if i % 2 == 0:
		ceven += 1
		even.append(i)
	else:
		codd += 1
		odd.append(i)
even.sort(reverse=True)
odd.sort(reverse=True)
if abs(codd - ceven) <= 1:
	print(0)
elif ceven > codd:
	temp = ceven - codd - 1
	print(sum(even[ceven - temp:]))
else:
	temp = codd - ceven - 1
	print(sum(odd[codd - temp:]))


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
N = lambda : int(input())
(even, odd) = (list(), list())
n = N()
a = Y()
a.sort()
even = list(filter(lambda x: x % 2 == 0, a))
odd = list(filter(lambda y: y % 2 == 1, a))
h = len(even) - len(odd)
if h == 0 or h == 1:
	print(0)
else:
	print(sum((i for i in even[:h - 1])) if h > 0 else sum((i for i in odd[:h * -1 - 1])))


N = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
even.sort()
odd.sort()
lenE = len(even)
lenO = len(odd)
if lenE == lenO or abs(lenE - lenO) == 1:
	print(0)
elif lenE > lenO:
	ind = lenE - lenO - 1
	ans = 0
	for i in range(0, ind):
		ans += even[i]
	print(ans)
else:
	ind = lenO - lenE - 1
	ans = 0
	for i in range(0, ind):
		ans += odd[i]
	print(ans)


n = int(input())
a = list(map(int, input().split()))
(l1, l2, x, y) = ([], [], 0, 0)
for i in a:
	if i % 2 == 0:
		x += 1
		l1.append(i)
	else:
		y += 1
		l2.append(i)
l1.sort(reverse=True)
l2.sort(reverse=True)
p = abs(x - y)
if p <= 1:
	print(0)
else:
	s = 0
	while p >= 2:
		if x > y:
			s += l1.pop()
			p -= 1
		elif y > x:
			s += l2.pop()
			p -= 1
	print(s)


n = int(input())
arr = list(map(int, input().split()))
evens = []
odds = []
for i in arr:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens.sort()
odds.sort()
if len(odds) < len(evens):
	count = len(odds)
	for i in range(count):
		odds.pop()
		evens.pop()
	evens.pop()
	print(sum(evens) + sum(odds))
elif len(odds) > len(evens):
	count = len(evens)
	for i in range(count):
		odds.pop()
		evens.pop()
	odds.pop()
	print(sum(evens) + sum(odds))
else:
	count = len(evens)
	for i in range(count):
		odds.pop()
		evens.pop()
	if odds and odds[-1] > evens[-1]:
		odds.pop()
	elif evens:
		evens.pop()
	print(sum(evens) + sum(odds))


n = input()
l = list(map(int, input().split()))
l.sort()
even = []
odd = []
for x in l[::-1]:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
diff = len(even) - len(odd)
if diff == 0:
	print(0)
elif diff > 0:
	print(sum(even[len(even) - diff + 1:]))
elif diff < 0:
	print(sum(odd[len(odd) + diff + 1:]))


size = int(input())
array = list(map(int, input().split()))
evens = sorted([i for i in array if i % 2 == 0])[::-1]
odds = sorted([i for i in array if i % 2 != 0])[::-1]
deletions = min(len(evens), len(odds))
evens = evens[deletions:]
odds = odds[deletions:]
if len(odds) > 0 or len(evens) > 0:
	if len(odds) > 0:
		odds = odds[1:]
	if len(evens) > 0:
		evens = evens[1:]
print(sum(evens) + sum(odds))


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
even = []
odd = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
o_e = 0
e_o = 0
even = sorted(even)[::-1]
odd = sorted(odd)[::-1]
e_index = 0
o_index = 0
while True:
	if len(even) - 1 < e_index:
		break
	e_o += even[e_index]
	if len(odd) - 1 < o_index:
		break
	e_o += odd[o_index]
	e_index += 1
	o_index += 1
e_index = 0
o_index = 0
while True:
	if len(odd) - 1 < o_index:
		break
	o_e += odd[o_index]
	if len(even) - 1 < e_index:
		break
	o_e += even[e_index]
	e_index += 1
	o_index += 1
print(min(s - e_o, s - o_e))


n = int(input())
ll = sorted([*map(int, input().split())])
evod = [[], []]
for i in ll:
	evod[i % 2].append(i)
evod.sort(key=len)
ans = sum(evod[1][:max(0, len(evod[1]) - len(evod[0]) - 1)])
print(ans)


n = int(input())
a = list(map(int, input().split()))
ev = []
od = []
(e, o) = (0, 0)
for i in range(len(a)):
	if a[i] % 2 == 0:
		ev.append(a[i])
		e += 1
	else:
		od.append(a[i])
		o += 1
x = min(e, o)
ev.sort(reverse=True)
od.sort(reverse=True)
if e > o:
	print(sum(ev[x + 1:len(ev)]))
elif o > e:
	print(sum(od[x + 1:len(od)]))
else:
	print(0)


n = int(input())
f = list(map(int, input().split()))
e = []
o = []
for i in range(n):
	if f[i] % 2 == 0:
		e.append(f[i])
	else:
		o.append(f[i])
e.sort(reverse=True)
o.sort(reverse=True)
if len(e) > len(o) + 1:
	print(sum(e[len(o) + 1:]))
elif len(o) > len(e) + 1:
	print(sum(o[len(e) + 1:]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split(' ')))
s = [list(), list()]
for i in l:
	s[i % 2].append(i)
if -1 <= len(s[0]) - len(s[1]) <= 1:
	print(0)
else:
	s[0].sort()
	s[1].sort()
	if len(s[0]) > len(s[1]):
		print(sum(s[0][:len(s[0]) - len(s[1]) - 1]))
	else:
		print(sum(s[1][:len(s[1]) - len(s[0]) - 1]))


n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
s = sum(A)
(B, C) = ([], [])
for i in A:
	if i % 2 == 0:
		B.append(i)
	else:
		C.append(i)
(b, c) = (0, 0)
for i in range(min(len(B), len(C))):
	b += B[i] + C[i]
	c += B[i] + C[i]
if len(B) > len(C):
	b += B[min(len(B), len(C))]
elif len(B) < len(C):
	c += C[min(len(B), len(C))]
print(min(s - b, s - c))


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def pp(A):
	for i in A:
		print(i)

def solve():
	n = int(input())
	A = ip()
	A.sort()
	(O, E) = ([], [])
	for i in A:
		if i % 2 == 0:
			E.append(i)
		else:
			O.append(i)
	ans = 0
	if len(O) > len(E):
		for i in range(len(O) - len(E) - 1):
			ans += O[i]
		return ans
	elif len(E) > len(O):
		for i in range(len(E) - len(O) - 1):
			ans += E[i]
		return ans
	else:
		return 0
print(solve())


N = int(input())
(odd, eve) = ([], [])
L = list(map(int, input().split()))
for i in L:
	if i % 2 == 0:
		eve += [i]
	else:
		odd += [i]
eve.sort()
odd.sort()
deL = min(len(eve), len(odd)) + 1
ans = 0
if len(eve) > deL:
	ans += sum(eve[:len(eve) - deL])
if len(odd) > deL:
	ans += sum(odd[:len(odd) - deL])
print(ans)


def main():
	jumlah_int = int(input())
	list_int = []
	numbers_unsplit = input()
	for i in numbers_unsplit.split(' '):
		list_int.append(int(i))
	parity_alternated_deletions(list_int)

def parity_alternated_deletions(list_int):
	list_even = []
	list_odd = []
	for i in list_int:
		if i % 2 == 0:
			list_even.append(i)
		else:
			list_odd.append(i)
	if len(list_even) == len(list_odd):
		print('0')
	elif len(list_even) > len(list_odd):
		count = 0
		diff = len(list_even) - len(list_odd)
		for i in range(diff - 1):
			min_val = list_even[0]
			index_val = 0
			for j in range(1, len(list_even)):
				if min_val > list_even[j]:
					min_val = list_even[j]
					index_val = j
			count += min_val
			list_even.pop(index_val)
		print(count)
	else:
		count = 0
		diff = len(list_odd) - len(list_even)
		for i in range(diff - 1):
			min_val = list_odd[0]
			index_val = 0
			for j in range(1, len(list_odd)):
				if min_val > list_odd[j]:
					min_val = list_odd[j]
					index_val = j
			count += min_val
			list_odd.pop(index_val)
		print(count)
main()


n = int(input())
a = list(map(int, input().split()))
n_2 = []
n_2_1 = []
for num in a:
	if num % 2 == 0:
		n_2.append(num)
	else:
		n_2_1.append(num)
n_2.sort()
n_2_1.sort()
a = len(n_2)
b = len(n_2_1)
if a >= b:
	print(sum(n_2[:-(b + 1)]))
else:
	print(sum(n_2_1[:-(a + 1)]))


n = int(input())
l = [int(x) for x in input().split()]
even = [x for x in l if x % 2 == 0]
odd = [x for x in l if x % 2 == 1]
even.sort(reverse=True)
odd.sort(reverse=True)
(ol, el) = (len(odd), len(even))
if ol == el:
	print(0)
elif ol < el:
	even = even[ol + 1:]
	print(sum(even))
else:
	odd = odd[el + 1:]
	print(sum(odd))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	ar = lis()
	even = []
	odd = []
	for i in ar:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	even.sort()
	odd.sort()
	k1 = len(even)
	k2 = len(odd)
	s = 0
	if k1 > k2:
		for i in range(k1 - k2 - 1):
			s += even[i]
	else:
		for i in range(k2 - k1 - 1):
			s += odd[i]
	print(s)
solve()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
even = []
odd = []
e = 0
o = 0
for i in arr:
	if i % 2 == 0:
		even = even + [i]
		e = e + 1
	else:
		odd = odd + [i]
		o = o + 1
if e > o and e - o > 1:
	print(sum(even[:e - o - 1]))
elif o > e and o - e > 1:
	print(sum(odd[:o - e - 1]))
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
odds = []
evens = []

def place(num):
	if num % 2 == 0:
		evens.append(num)
		return
	odds.append(num)
a = list(map(place, arr))
odds = sorted(odds, reverse=True)
evens = sorted(evens, reverse=True)
if len(odds) == len(evens):
	rem = 0
elif len(odds) > len(evens):
	rem = len(odds) - len(evens) - 1
	if rem != 0:
		res = sum(odds[-rem:])
else:
	rem = len(evens) - len(odds) - 1
	if rem != 0:
		res = sum(evens[-rem:])
if rem == 0:
	res = 0
print(res)


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
ce = 0
co = 0
for i in range(n):
	if l[i] % 2 == 0:
		ce += 1
		e.append(l[i])
	else:
		co += 1
		o.append(l[i])
if ce == co:
	print('0')
elif ce == 0:
	o.sort()
	o.remove(o[len(o) - 1])
	print(sum(o))
elif co == 0:
	e.sort()
	e.remove(e[len(e) - 1])
	print(sum(e))
elif ce > co:
	e.sort()
	o.sort()
	sumt = sum(e[0:len(e) - (co + 1)]) + sum(o[0:len(o) - co])
	print(sumt)
else:
	e.sort()
	o.sort()
	sumt = sum(e[0:len(e) - ce]) + sum(o[0:len(o) - (ce + 1)])
	print(sumt)


N = int(input())
A = list(map(int, input().split()))
even = sorted([a for a in A if a % 2 == 0])
odd = sorted([a for a in A if a % 2 == 1])
even_len = len(even)
odd_len = len(odd)
if even_len > odd_len + 1:
	print(sum(even[:even_len - odd_len - 1]))
elif odd_len > even_len + 1:
	print(sum(odd[:odd_len - even_len - 1]))
else:
	print(0)


n = int(input())
array = sorted(list(map(int, input().split())), reverse=True)
odds = []
evens = []

def check(number):
	if number % 2 == 0:
		return True
for x in array:
	if check(x):
		evens.append(x)
	else:
		odds.append(x)
lo = len(odds)
le = len(evens)
if lo > le:
	sums = 0
	sums += sum(evens)
	sums += sum(odds[0:le + 1])
	print(sum(array) - sums)
else:
	sums = 0
	sums += sum(odds)
	sums += sum(evens[0:lo + 1])
	print(sum(array) - sums)


n = int(input())
a = [int(i) for i in input().split()]
e = []
o = []
p = 0
s = sum(a)
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
d = len(e)
f = len(o)
mi = 0
if d < f:
	mi = d
else:
	mi = f
e.sort(reverse=True)
o.sort(reverse=True)
for i in range(mi):
	s = s - e[i]
	s = s - o[i]
if len(e) > mi:
	s = s - e[mi]
if len(o) > mi:
	s = s - o[mi]
print(s)


n = int(input())
arr = list(map(int, input().split()))
odd = []
even = []
for num in arr:
	if num & 1 == 0:
		even.append(num)
	else:
		odd.append(num)
odd.sort()
even.sort()
(m, n) = (len(odd), len(even))
if m < n:
	(m, n) = (n, m)
	(odd, even) = (even, odd)
if m - n <= 1:
	print(0)
else:
	print(sum(odd[:m - n - 1]))


from itertools import zip_longest

def next_even(numbers, idx=0):
	for i in range(idx, len(numbers)):
		if numbers[i] % 2 == 0:
			yield i

def next_odd(numbers, idx=0):
	for i in range(idx, len(numbers)):
		if numbers[i] % 2 == 1:
			yield i

def min_remain_sum(numbers):
	numbers = sorted(numbers, reverse=True)
	numlen = len(numbers)
	even_numbers = len([1 for number in numbers if number % 2 == 0])
	odd_numbers = numlen - even_numbers
	if even_numbers > odd_numbers:
		zipper = zip_longest(next_even(numbers), next_odd(numbers), fillvalue=None)
	else:
		zipper = zip_longest(next_odd(numbers), next_even(numbers), fillvalue=None)
	used = [False] * len(numbers)
	for (idx1, idx2) in zipper:
		if idx1 is not None:
			used[idx1] = True
		if idx2 is not None:
			used[idx2] = True
		if idx1 is None or idx2 is None:
			break
	return sum((numbers[idx] for (idx, is_used) in enumerate(used) if not is_used))
n = int(input())
numbers = [int(part) for part in input().split()]
print(min_remain_sum(numbers))


import math
n = int(input())
a = list(map(int, input().split()))
eve = []
odd = []
for i in range(n):
	if a[i] % 2 == 0:
		eve.append(a[i])
	else:
		odd.append(a[i])
o = min(len(odd), len(eve))
if len(eve) == len(odd) or abs(len(eve) - len(odd)) == 1:
	print(0)
else:
	eve.sort(reverse=True)
	odd.sort(reverse=True)
	if len(eve) > len(odd):
		print(sum(eve[o + 1:]))
	else:
		print(sum(odd[o + 1:]))


n = int(input())
num = list(map(int, input().split()))
e = o = 0
even = [0] * n
odd = [0] * n
num = sorted(num)
for i in range(n):
	if num[i] % 2 == 0:
		even[e] = num[i]
		e += 1
	else:
		odd[o] = num[i]
		o += 1
dif = abs(e - o)
if dif == 0 or dif == 1:
	print('0')
else:
	soma = 0
	if e > o:
		for i in range(dif - 1):
			soma += even[i]
	else:
		for i in range(dif - 1):
			soma += odd[i]
	print(soma)


from collections import *
n = int(input())
a = list(map(int, input().split()))
(o, e) = (0, 0)
for i in a:
	if i % 2 == 0:
		e += 1
	else:
		o += 1
a.sort(reverse=True)
i = 0
(ex, ox) = (min(o, e), min(o, e))
if o > ox:
	ox += 1
if e > ex:
	ex += 1
while i < n and (ox or ex):
	if ex and a[i] % 2 == 0:
		a[i] = 0
		ex -= 1
	if ox and a[i] % 2 == 1:
		a[i] = 0
		ox -= 1
	i += 1
print(sum(a))


n = int(input())
arr = map(int, input().split())
arr = sorted(arr)
even = 0
for i in arr:
	if i % 2 == 0:
		even = even + 1
odd = n - even
finalSum = 0
if odd > even:
	i = 0
	j = 0
	while i < odd - even - 1:
		if arr[j] % 2 != 0:
			finalSum += arr[j]
			i += 1
		j += 1
else:
	i = 0
	j = 0
	while i < even - odd - 1:
		if arr[j] % 2 == 0:
			finalSum += arr[j]
			i += 1
		j += 1
print(finalSum)


qtd = int(input())
elements = list(map(int, input().split()))
evenElements = sorted(list(filter(lambda x: not x % 2, elements)), reverse=True)
oddElements = sorted(list(filter(lambda x: x % 2, elements)), reverse=True)
if len(evenElements) > len(oddElements):
	evenElements.pop(0)
	getOdd = True
	getEven = False
else:
	oddElements.pop(0)
	getOdd = False
	getEven = True
while len(evenElements) and len(oddElements):
	if getEven and len(evenElements):
		evenElements.pop(0)
		getOdd = True
		getEven = False
	elif getOdd and len(oddElements):
		oddElements.pop(0)
		getOdd = False
		getEven = True
if getEven and len(evenElements):
	evenElements.pop(0)
elif getOdd and len(oddElements):
	oddElements.pop(0)
print(sum(evenElements) + sum(oddElements))


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
N = lambda : int(input())
(even, odd) = (list(), list())
n = N()
a = Y()
a.sort()
for _ in a:
	even.append(_) if _ % 2 == 0 else odd.append(_)
while len(even) and len(odd):
	even.pop()
	odd.pop()
if len(even):
	even.pop()
if len(odd):
	odd.pop()
print('{}'.format(sum(even) + sum(odd)))


import sys, math, queue
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
od = []
ev = []
for i in range(n):
	if a[i] % 2 == 0:
		ev.append(a[i])
	else:
		od.append(a[i])
od.sort()
ev.sort()
if abs(len(od) - len(ev)) <= 1:
	print(0)
	return
ans = 0
if len(od) > len(ev):
	for i in range(len(od) - len(ev) - 1):
		ans += od[i]
else:
	for i in range(len(ev) - len(od) - 1):
		ans += ev[i]
print(ans)


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def main():
	N = int(input())
	A = list(map(int, input().split()))
	(even, odd) = ([], [])
	for a in A:
		if a % 2 == 0:
			even.append(a)
		else:
			odd.append(a)
	even.sort()
	odd.sort()
	num_even = len(even)
	num_odd = len(odd)
	if abs(num_even - num_odd) <= 1:
		ans = 0
	elif num_even > num_odd:
		ans = 0
		for i in range(num_even - num_odd - 1):
			ans += even[i]
	else:
		ans = 0
		for i in range(num_odd - num_even - 1):
			ans += odd[i]
	print(ans)
main()


import sys

def main():
	n = int(input())
	a = list(map(int, input().split()))
	chet = []
	nechet = []
	for i in range(n):
		if a[i] % 2 == 0:
			chet.append(a[i])
		else:
			nechet.append(a[i])
	chet.sort()
	nechet.sort()
	if len(chet) == len(nechet):
		return 0
	if len(chet) > len(nechet):
		c = False
		while chet != [] and nechet != []:
			chet.pop()
			c = True
			nechet.pop()
			c = False
		if not c and chet != []:
			chet.pop()
			return sum(chet) if chet != [] else 0
	else:
		c = False
		while chet != [] and nechet != []:
			nechet.pop()
			c = True
			chet.pop()
			c = False
		if not c and nechet != []:
			nechet.pop()
			return sum(nechet) if nechet != [] else 0
print(main())


N = int(input())
k = sorted([int(i) for i in input().split()])
odd = list(filter(lambda x: x % 2 == 0, k))
even = list(filter(lambda x: x % 2 == 1, k))
sum = 0
if abs(len(odd) - len(even)) < 2:
	pass
elif len(even) > len(odd):
	for i in range(len(even) - len(odd) - 1):
		sum += even[i]
else:
	for i in range(len(odd) - len(even) - 1):
		sum += odd[i]
print(sum)


akdmslac = int(input())
a = []
b = 0
d = 0
e = 0
c = 0
a = [int(x) for x in input().split()]
for i in range(akdmslac):
	if a[i] % 2 == 0:
		b = b + 1
	else:
		c = c + 1
if b - c == 1 or b - c == -1 or b == c:
	print('0')
else:
	if b > c:
		for n in range(akdmslac):
			if min(a) % 2 == 0:
				d = d + min(a)
				e = e + 1
			if e == b - c - 1:
				break
			a.remove(min(a))
	elif c > b:
		for n in range(akdmslac):
			if min(a) % 2 == 1:
				d = d + min(a)
				e = e + 1
			if e == c - b - 1:
				break
			a.remove(min(a))
	print(d)


def solve(a):
	a.sort()
	odd = []
	even = []
	for i in a:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	if abs(len(even) - len(odd)) <= 1:
		return 0
	elif len(even) > len(odd):
		l = len(even) - len(odd) - 1
		return sum(even[:l])
	else:
		l = len(odd) - len(even) - 1
		return sum(odd[:l])
n = int(input())
x = input().split()
a = []
for i in x:
	a.append(int(i))
print(solve(a))


a = int(input())
z = list(map(int, input().split()))
iit = sum(z)
even = []
odd = []
for i in range(len(z)):
	if z[i] % 2 == 0:
		even.append(z[i])
	else:
		odd.append(z[i])
even = sorted(even)
even = even[::-1]
odd = sorted(odd)
odd = odd[::-1]
if abs(len(odd) - len(even)) == 1 or len(odd) == len(even):
	print(0)
else:
	if len(odd) > len(even):
		t = sum(odd[0:len(even) + 1]) + sum(even)
	else:
		t = sum(even[0:len(odd) + 1]) + sum(odd)
	print(iit - t)


n = int(input())
a = list(map(int, input().split()))
evens = []
odds = []
for i in a:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
evens.sort()
odds.sort()
le = len(evens)
lo = len(odds)
non_del = max(0, abs(le - lo) - 1)
if le > lo:
	print(sum(evens[:non_del]))
else:
	print(sum(odds[:non_del]))


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in a:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort(reverse=True)
even.sort(reverse=True)
lo = len(odd)
le = n - lo
if lo > le:
	print(sum(odd[le + 1:]))
else:
	print(sum(even[lo + 1:]))


a = int(input())
z = list(map(int, input().split()))
odd = []
eve = []
for i in range(len(z)):
	if z[i] % 2 == 1:
		odd.append(z[i])
	else:
		eve.append(z[i])
odd.sort(reverse=True)
eve.sort(reverse=True)
arr1 = []
arr2 = []
l1 = 0
l2 = 0
i = 0
while l1 < len(odd) and l2 < len(eve):
	if i % 2 == 1:
		arr1.append(odd[l1])
		l1 += 1
	else:
		arr1.append(eve[l2])
		l2 += 1
	i += 1
if l1 == len(odd) and l2 < len(eve):
	arr1.append(eve[l2])
if l1 < len(odd) and l2 == len(eve):
	arr1.append(odd[l1])
l1 = 0
l2 = 0
i = 0
while l1 < len(odd) and l2 < len(eve):
	if i % 2 == 1:
		arr2.append(eve[l2])
		l2 += 1
	else:
		arr2.append(odd[l2])
		l1 += 1
	i += 1
if l1 == len(odd) and l2 < len(eve):
	arr2.append(eve[l2])
if l1 < len(odd) and l2 == len(eve):
	arr2.append(odd[l1])
total = sum(z)
print(min(total - sum(arr1), total - sum(arr2)))


input()
a = [int(x) for x in input().split()]
o = [x for x in a if x % 2 == 1]
e = [x for x in a if x % 2 == 0]
o.sort()
e.sort()
k = min(len(o), len(e))
for _ in range(k):
	o.pop()
	e.pop()
if e and (not o or o[-1] < e[-1]):
	e.pop()
elif o:
	o.pop()
print(sum(e) + sum(o))


n = int(input())
c = input().split()
for i in range(n):
	c[i] = int(c[i])
if n == 1:
	print(0)
	exit(0)
a = []
b = []
for i in range(n):
	if c[i] % 2 == 0:
		a.append(c[i])
	else:
		b.append(c[i])
a = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = []
n = len(a)
m = len(b)
for i in range(min(n, m)):
	a.pop(0)
	b.pop(0)
a = a[1:]
b = b[1:]
print(sum(a) + sum(b))


def pc(a, n):
	e = []
	o = []
	ne = 0
	no = 0
	s = 0
	for x in a:
		s += x
		if x % 2 == 0:
			e.append(x)
			ne += 1
		else:
			o.append(x)
			no += 1
	e.sort()
	o.sort()
	e.reverse()
	o.reverse()
	if ne > no:
		return s - sum(e[:no + 1]) - sum(o)
	if no > ne:
		return s - sum(o[:ne + 1]) - sum(e)
	else:
		return 0
n = int(input().strip())
inp = input()
a = [int(x) for x in inp.strip().split(' ')]
print(pc(a, n))


n = int(input())
s = input().split()
a = []
i = 0
for i in s:
	a.append(int(i))
a.sort()
a.reverse()
nulls = 0
for i in range(n):
	nulls += (a[i] + 1) % 2
if nulls >= n - nulls:
	j = 1
else:
	j = 0
while 1:
	flag = 0
	for i in range(len(a)):
		if not a[i] % 2 == j:
			flag = 1
			j = a[i] % 2
			a.pop(i)
			break
	if flag == 0:
		break
sum = 0
if len(a) > 0:
	for i in a:
		sum += i
	print(sum)
else:
	print(0)


n = int(input())
l = sorted(map(int, input().split()))
le = []
lo = []
for i in l:
	if i % 2 == 0:
		le.append(i)
	else:
		lo.append(i)
sumd = len(le) - len(lo)
if sumd >= 2:
	print(sum(le[:sumd - 1]))
elif sumd <= -2:
	print(sum(lo[:-sumd - 1]))
else:
	print(0)


n = int(input())
l = list(map(int, input().split()))
odd = []
even = []
l.sort()
for i in range(n):
	if l[i] % 2 == 0:
		odd.append(l[i])
	else:
		even.append(l[i])
no = len(odd)
ne = len(even)
if no == ne:
	print(0)
elif no < ne:
	diff = ne - no
	print(sum(even[0:diff:1]) - max(even[0:diff:1]))
else:
	diff = no - ne
	print(sum(odd[0:diff:1]) - max(odd[0:diff:1]))


n = int(input())
a = list(map(int, input().split()))
a_ch = []
a_nch = []
s = 0
for i in range(n):
	if a[i] % 2 == 0:
		a_ch.append(a[i])
	else:
		a_nch.append(a[i])
a_ch = sorted(a_ch, reverse=True)
a_nch = sorted(a_nch, reverse=True)
if len(a_ch) < len(a_nch):
	for i in range(len(a_ch) + 1, len(a_nch)):
		s += a_nch[i]
else:
	for i in range(len(a_nch) + 1, len(a_ch)):
		s += a_ch[i]
print(s)


n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
x = []
y = []
ans = 0
for i in a:
	if i % 2 == 0:
		x.append(i)
	else:
		y.append(i)
xc = len(x)
yc = len(y)
if xc == min(xc, yc):
	for i in range(xc + 1, len(y)):
		ans += y[i]
else:
	for i in range(yc + 1, len(x)):
		ans += x[i]
print(ans)


n = int(input())
e = []
o = []
ans = 0
dc = dict()
for i in input().split():
	a = int(i)
	if a % 2 == 0:
		e.append(a)
	else:
		o.append(a)
if abs(len(e) - len(o)) <= 1:
	ans = 0
else:
	d = len(e) - len(o)
	if d > 0:
		b = sorted(e)
		for j in range(d - 1):
			ans += b[j]
	else:
		b = sorted(o)
		for j in range(-d - 1):
			ans += b[j]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
chet = []
nechet = []
for i in range(n):
	if arr[i] % 2 == 0:
		chet.append(arr[i])
	else:
		nechet.append(arr[i])
chet.sort()
nechet.sort()
if len(chet) == len(nechet) or len(chet) + 1 == len(nechet) or len(nechet) + 1 == len(chet):
	print(0)
elif len(chet) > len(nechet):
	print(sum(chet[0:len(chet) - len(nechet) - 1]))
else:
	print(sum(nechet[0:len(nechet) - len(chet) - 1]))


from __future__ import division, print_function
import io
import os
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from cStringIO import StringIO
	from future_builtins import ascii, filter, hex, map, oct, zip
else:
	from io import BytesIO as StringIO
(sys.stdout, stream) = (io.IOBase(), StringIO())
sys.stdout.flush = lambda : os.write(1, stream.getvalue()) and (not stream.truncate(0)) and stream.seek(0)
sys.stdout.write = stream.write if sys.version_info[0] < 3 else lambda s: stream.write(s.encode())
(input, flush) = (sys.stdin.readline, sys.stdout.flush)
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	p = [0, 0]
	e = []
	o = []
	for i in a:
		p[i & 1] += 1
		if i & 1:
			o.append(i)
		else:
			e.append(i)
	e.sort(reverse=True)
	o.sort(reverse=True)
	if abs(p[0] - p[1]) < 2:
		print(0)
	else:
		if p[0] < p[1]:
			d = sum(e) + sum(o[:p[0] + 1])
		else:
			d = sum(o) + sum(e[:p[1] + 1])
		print(sum(a) - d)
main()


import sys
from bisect import bisect_left, bisect_right
from collections import deque
inf = float('inf')
mod = 1000000007

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())
sys.setrecursionlimit(1000000)
n = int(input())
array = get_array()
array.sort()
ret = []
balance = 0
odds = []
evens = []
for i in array:
	if i % 2 == 0:
		evens.append(i)
	if i % 2 == 1:
		odds.append(i)
if len(odds) == len(evens):
	print(0)
else:
	if len(odds) < len(evens):
		smaller = odds
		larger = evens
	else:
		smaller = evens
		larger = odds
	for i in range(len(larger) - len(smaller)):
		ret.append(larger[i])
	ret.pop()
	print(sum(ret))


n = int(input())
a = list(map(int, input().split()))
o_1 = []
o_2 = []
for i in range(n):
	if a[i] % 2 == 0:
		o_2.append(a[i])
	else:
		o_1.append(a[i])
s = 0
o_1.sort()
o_2.sort()
if len(o_1) > len(o_2):
	for i in range(len(o_1) - len(o_2) - 1):
		s += o_1[i]
	print(s)
else:
	for i in range(len(o_2) - len(o_1) - 1):
		s += o_2[i]
	print(s)


n = int(input())
l = [int(x) for x in input().split()]
(p, q) = ([], [])
g = sum(l)
for i in l:
	if i % 2 == 0:
		p.append(i)
	else:
		q.append(i)
(p.sort(reverse=True), q.sort(reverse=True))
k = min(len(p), len(q))
g -= sum(p[:k]) + sum(q[:k])
if g != 0:
	if len(p) > len(q):
		print(g - p[k])
	else:
		print(g - q[k])
else:
	print(g)


n = int(input())
arr = list(map(int, input().split()))

def parity(arr):
	odd = []
	even = []
	for i in arr:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	if len(odd) >= len(even):
		while len(even) != 0:
			odd.remove(max(odd))
			even.remove(max(even))
		if len(odd) != 0:
			odd.remove(max(odd))
		return sum(odd) + sum(even)
	else:
		while len(odd) != 0:
			even.remove(max(even))
			odd.remove(max(odd))
		if len(even) != 0:
			even.remove(max(even))
		return sum(odd) + sum(even)
print(parity(arr))


t = int(input())
l1 = [int(x) for x in input().split()]
l1.sort(reverse=True)
odds = len([1 for x in l1 if x % 2])
evens = len(l1) - odds
if evens > odds:
	temp = odds
	odds = evens
	evens = temp
odds = min(odds, evens + 1)
odds1 = odds
evens1 = evens
l2 = l1.copy()
for x in l1:
	if x % 2 and odds:
		l1[l1.index(x)] = 0
		odds -= 1
	elif x % 2 == 0 and evens:
		l1[l1.index(x)] = 0
		evens -= 1
odds = odds1
evens = evens1
for x in l2:
	if x % 2 and evens:
		l2[l2.index(x)] = 0
		evens -= 1
	elif x % 2 == 0 and odds:
		l2[l2.index(x)] = 0
		odds -= 1
print(min(sum(l1), sum(l2)))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	odd = [x for x in a if x % 2 == 1]
	even = [x for x in a if x % 2 == 0]
	if abs(len(odd) - len(even)) <= 1:
		print(0)
	else:
		so = sorted(odd)
		se = sorted(even)
		if len(so) > len(se):
			print(sum(so[:len(so) - len(se) - 1]))
		else:
			print(sum(se[:len(se) - len(so) - 1]))
main()


n = int(input())
a = [int(i) for i in input().split()]
even = []
odd = []
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
even.sort()
odd.sort()
even = even[::-1]
odd = odd[::-1]
ch = 'e'
while not (len(even) == 0 and ch == 'e' or (len(odd) == 0 and ch == 'o')):
	if ch == 'e':
		even.pop(0)
		ch = 'o'
	else:
		odd.pop(0)
		ch = 'e'
if len(even) == 0:
	res1 = sum(odd)
else:
	res1 = sum(even)
ch = 'o'
while not (len(even) == 0 and ch == 'e' or (len(odd) == 0 and ch == 'o')):
	if ch == 'e':
		even.pop(0)
		ch = 'o'
	else:
		odd.pop(0)
		ch = 'e'
if len(even) == 0:
	res2 = sum(odd)
else:
	res2 = sum(even)
res = min(res1, res2)
print(res)


a = int(input())
b = list(map(int, input().split()))
odd = []
even = []
for i in b:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
x = len(odd)
y = len(even)
if x >= y:
	v = x - y
	if v == 0 or v == 1:
		print(0)
	else:
		v = v - 1
		print(sum(odd[:v]))
else:
	v = y - x - 1
	print(sum(even[:v]))


n = int(input())
a = [int(x) for x in input().split()]
t1 = []
t2 = []
for x in a:
	if x % 2 == 0:
		t1.append(x)
	else:
		t2.append(x)
t1.sort()
t2.sort()
i = len(t1) - 1
j = len(t2) - 1
while 1:
	if i >= 0 and j >= 0:
		i -= 1
		j -= 1
	elif i >= 0:
		i -= 1
		break
	else:
		break
s1 = 0
for r in range(i + 1):
	s1 += t1[r]
for r in range(j + 1):
	s1 += t2[r]
i = len(t1) - 1
j = len(t2) - 1
while 1:
	if i >= 0 and j >= 0:
		i -= 1
		j -= 1
	elif j >= 0:
		j -= 1
		break
	else:
		break
s2 = 0
for r in range(i + 1):
	s2 += t1[r]
for r in range(j + 1):
	s2 += t2[r]
print(min(s1, s2))


n = int(input())
ar = list(map(int, input().split()))
even = 0
odd = 0
for i in range(n):
	if ar[i] % 2 == 0:
		even += 1
	else:
		odd += 1
l = abs(even - odd)
j = 0
sum = 0
if l <= 1:
	print('0')
else:
	ar.sort()
	if even > odd:
		for i in range(n):
			if ar[i] % 2 == 0 and j < l - 1:
				j += 1
				sum += ar[i]
		print(sum)
	if even < odd:
		for i in range(n):
			if ar[i] % 2 != 0 and j < l - 1:
				j += 1
				sum += ar[i]
		print(sum)


n = int(input())
a = [int(x) for x in input().split()]
odd = sorted(filter(lambda x: x % 2 == 1, a))
even = sorted(filter(lambda x: x % 2 == 0, a))
if abs(len(odd) - len(even)) <= 1:
	print(0)
elif len(odd) > len(even):
	print(sum(odd[:len(odd) - len(even) - 1]))
else:
	print(sum(even[:len(even) - len(odd) - 1]))


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
li = ai()
even = []
odd = []
for i in range(n):
	if li[i] & 1:
		odd.append(li[i])
	else:
		even.append(li[i])
even.sort(reverse=True)
odd.sort(reverse=True)
while len(odd) > 0 and len(even) > 0:
	odd.pop(0)
	even.pop(0)
ans = 0
if len(odd) == len(even):
	ans = 0
elif len(odd) > len(even):
	ans = odd[0]
else:
	ans = even[0]
print(sum(even) + sum(odd) - ans)


n = int(input())
s = list(map(int, input().split()))
all = sum(s)
odd = sorted([i for i in s if i % 2 == 1])
odd = odd[::-1]
even = sorted([i for i in s if i % 2 == 0])
even = even[::-1]
k = min(len(odd) - 1, len(even) - 1)
all -= sum(odd[:k + 1])
all -= sum(even[:k + 1])
if len(odd) > len(even):
	all -= odd[k + 1]
elif len(even) > len(odd):
	all -= even[k + 1]
print(all)


n = int(input(''))
a = input('').split()
odd = []
even = []
for i in range(n):
	a[i] = int(a[i])
	(odd if a[i] % 2 == 1 else even).append(a[i])
if -1 <= len(odd) - len(even) <= 1:
	print(0)
else:
	n = len(odd) - len(even)
	if n < 0:
		n = -n
	n -= 1
	w = odd
	if len(odd) < len(even):
		w = even
	w.sort()
	total = sum(w[:n])
	print(total)


n = int(input())
lis = list(map(int, input().split()))
odd = []
even = []
for i in lis:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd = sorted(odd, reverse=1)
even = sorted(even, reverse=1)
res = 0
length = min(len(odd), len(even))
for _ in range(length):
	even.remove(even[0])
	odd.remove(odd[0])
if len(odd) > 0:
	odd.remove(odd[0])
elif len(even) > 0:
	even.remove(even[0])
print(sum(odd) + sum(even))


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
n = inp(1)
l = inp()
odd = []
even = []
for i in l:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
m = min(len(odd), len(even))
even.sort(reverse=True)
odd.sort(reverse=True)
for i in range(m):
	even[i] = 0
	odd[i] = 0
if len(even) == m and len(odd) > m:
	odd[m] = 0
elif len(odd) == m and len(even) > m:
	even[m] = 0
print(sum(even) + sum(odd))


n = int(input())
a = []
b = []
for j in map(int, input().split()):
	if j % 2 == 0:
		a.append(j)
	else:
		b.append(j)
a = sorted(a)
b = sorted(b)
if abs(len(a) - len(b)) <= 1:
	print(0)
elif len(a) > len(b):
	c = len(a) - len(b) - 1
	print(sum(a[:c]))
else:
	c = len(b) - len(a) - 1
	print(sum(b[:c]))


n = int(input())
l = list(map(int, input().split()))
e = []
o = []
for i in range(len(l)):
	if l[i] % 2 == 0:
		e.append(l[i])
	else:
		o.append(l[i])
e.sort()
o.sort()
e.reverse()
o.reverse()
s = 0
if len(e) > len(o):
	for i in range(len(o) + 1, len(e)):
		s += e[i]
	print(s)
elif len(e) < len(o):
	for i in range(len(e) + 1, len(o)):
		s += o[i]
	print(s)
else:
	print(0)


n = int(input())
li = list(map(int, input().split()))
if len(li) == 1:
	print(li[0])
else:
	odd = [i for i in li if i % 2 != 0]
	even = [i for i in li if i % 2 == 0]
	if len(li) == 2:
		if len(even) == 2 or len(odd) == 2:
			print(min(li[0], li[1]))
	elif len(even) == len(odd):
		print(0)
	elif len(even) + 1 == len(odd):
		print(0)
	elif len(even) - 1 == len(odd):
		print(0)
	else:
		odd.sort()
		even.sort()
		if len(odd) > len(even):
			x = len(odd) - len(even) - 1
			odd = odd[:x]
			print(sum(odd))
		else:
			x = len(even) - len(odd) - 1
			even = even[:x]
			print(sum(even))


n = int(input())
a = list(map(int, input().split()))
(odd, even) = (0, 0)
for el in a:
	if el % 2:
		odd += 1
	else:
		even += 1
if abs(odd - even) <= 1:
	print(0)
	exit()
a.sort()
ans = 0
if odd > even:
	d = odd - even - 1
	for el in a:
		if el % 2:
			ans += el
			d -= 1
		if d == 0:
			break
	print(ans)
else:
	d = even - odd - 1
	for el in a:
		if (el + 1) % 2:
			ans += el
			d -= 1
		if d == 0:
			break
	print(ans)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ev = []
od = []
for i in range(n):
	if a[i] % 2 == 0:
		ev.append(a[i])
	else:
		od.append(a[i])
lev = len(ev)
lod = len(od)
ev.sort()
od.sort()
ev.reverse()
od.reverse()
if abs(lev - lod) == 1 or abs(lev - lod) == 0:
	print('0')
elif min(lev, lod) == lev:
	t = lod - lev
	print(sum(od[lev + 1:lod]))
elif min(lev, lod) == lod:
	t = lev - lod
	print(sum(ev[lod + 1:lev]))


n = int(input())
a = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
even.sort()
odd.sort()
len_e = len(even)
len_o = len(odd)
diff = abs(len_e - len_o)
if diff == 1 or diff == 0:
	print(0)
elif len_e > len_o:
	print(sum(even[0:diff - 1]))
else:
	print(sum(odd[0:diff - 1]))


import math
n = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
for i in arr:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if math.fabs(len(even) - len(odd)) > 1:
	even = sorted(even)
	odd = sorted(odd)
	lacking = 0
	answer = 0
	if len(even) < len(odd):
		lacking += len(odd) - len(even) - 1
		for i in range(lacking):
			answer += odd[i]
	else:
		lacking += len(even) - len(odd) - 1
		for i in range(lacking):
			answer += even[i]
	print(answer)
else:
	print('0')


def oddsFirst(oddNums, evenNums):
	minimum = min(len(oddNums), len(evenNums))
	for i in range(minimum):
		oddNums.remove(oddNums[-1])
		evenNums.remove(evenNums[-1])
	if len(oddNums) > 0:
		oddNums.remove(oddNums[-1])
	return sum(evenNums) + sum(oddNums)

def evensFirst(oddies, evenies):
	minimum = min(len(oddies), len(evenies))
	for i in range(minimum):
		oddies.remove(oddies[-1])
		evenies.remove(evenies[-1])
	if len(evenies) > 0:
		evenies.remove(evenies[-1])
	return sum(evenies) + sum(oddies)
n = int(input())
a = [int(x) for x in input().split()]
odds = []
evens = []
for i in a:
	if i % 2 == 0:
		evens.append(i)
	else:
		odds.append(i)
odds.sort()
evens.sort()
oddsAns = oddsFirst(odds, evens)
evensAns = evensFirst(odds, evens)
print(min(oddsAns, evensAns))


x = int(input())
a = [int(x) for x in input().split()]
ods1 = []
ods2 = []
evens1 = []
evens2 = []
for e in a:
	if e % 2 == 0:
		evens1.append(e)
	else:
		ods1.append(e)
ods1.sort()
evens1.sort()
evens2 = evens1.copy()
ods2 = ods1.copy()
for i in range(min(len(ods1), len(evens1))):
	ods1.pop()
	evens1.pop()
if ods1 != evens1:
	if ods1 == []:
		evens1.pop()
	if evens1 == []:
		ods1.pop()
s = sum(ods1) + sum(evens1)
print(s)


n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
for x in l:
	if x % 2 == 0:
		l1.append(x)
	else:
		l2.append(x)
su = 0
l1 = sorted(l1, reverse=True)
l2 = sorted(l2, reverse=True)
for i in range(min(len(l1), len(l2))):
	su += l1[i] + l2[i]
if len(l1) > len(l2):
	su += l1[min(len(l1), len(l2))]
if len(l1) < len(l2):
	su += l2[min(len(l1), len(l2))]
print(sum(l) - su)


n = int(input())
a = sorted(list(map(int, input().split(' '))), reverse=True)
even = [x for x in a if x % 2 == 0]
odd = [y for y in a if y % 2 != 0]
if abs(len(even) - len(odd)) == 1:
	print(0)
elif len(even) == len(odd):
	print(0)
elif len(even) > len(odd):
	even = even[::-1]
	l = len(even) - len(odd)
	even = even[:l - 1]
	print(sum(even))
elif len(odd) > len(even):
	odd = odd[::-1]
	l = len(odd) - len(even)
	odd = odd[:l - 1]
	print(sum(odd))


N = int(input())
numbers = sorted([int(x) for x in input().split(' ')], reverse=True)
odd = []
even = []
for x in numbers:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
if len(even) == len(odd) + 1 or len(even) + 1 == len(odd) or len(even) == len(odd):
	print(0)
elif len(even) > len(odd):
	print(sum(even[len(odd) + 1:]))
else:
	print(sum(odd[len(even) + 1:]))


n = int(input())
arr = sorted(list(map(int, input().split())), reverse=True)
odd = []
even = []

def Parity(n, arr):
	for i in arr:
		if i % 2 != 0:
			odd.append(i)
		else:
			even.append(i)
	maxlen = max(len(odd), len(even))
	minlen = min(len(odd), len(even))
	if maxlen - minlen <= 1:
		return 0
	elif len(odd) == minlen:
		return sum(even[minlen + 1:])
	else:
		return sum(odd[minlen + 1:])
print(Parity(n, arr))


import sys
from bisect import bisect_left, bisect_right
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log
from itertools import permutations
inf = float('inf')
mod = 1000000007
mini = 1000000007

def fact(n):
	if n == 0:
		return 1
	p = 1
	d = 10 ** 9 + 7
	for i in range(1, n + 1):
		p = p * i
		p = p % d
	return p

def ncr(n, r):
	d = 10 ** 9 + 7
	num = fact(n)
	den = fact(r) * fact(n - r) % d
	den = pow(den, d - 2, d)
	return num * den % d

def sieve(n):
	prime = [True for i in range(n + 1)]
	lst = []
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p = p + 1
	for i in range(2, n + 1):
		if prime[i]:
			lst.append(i)
	return len(lst)

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def calculate_factors(n):
	hh = [1] * (n + 1)
	p = 2
	while p * p < n:
		if hh[p] == 1:
			for i in range(p * 2, n, p):
				hh[i] = 0
		p += 1
	total = 1
	for p in range(2, n + 1):
		if hh[p] == 1:
			count = 0
			if n % p == 0:
				while n % p == 0:
					n = int(n / p)
					count += 1
				total *= count + 1
	return total

def prime_factors(n):
	i = 2
	factors = set()
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.add(i)
	if n > 1:
		factors.add(n)
	if len(factors) == 2:
		return True
	else:
		return False

def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
even = []
odd = []
for i in Arr:
	if i & 1:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
len_odd = len(odd)
len_even = len(even)
if len_odd == len_even or abs(len_even - len_odd) == 1:
	print(0)
elif len_odd > len_even:
	total = 0
	for i in range(len_odd - len_even - 1):
		total = total + odd[i]
	print(total)
else:
	total = 0
	for i in range(len_even - len_odd - 1):
		total = total + even[i]
	print(total)


n = int(input())
lst = list(map(int, input().split()))
(a, b, len1, len2) = ([], [], 0, 0)
for (i, x) in enumerate(lst):
	if x % 2 == 0:
		a.append(x)
		len1 += 1
	else:
		b.append(x)
		len2 += 1
a.sort()
a.reverse()
b.sort()
b.reverse()
if len1 < len2:
	print(sum(b[len1 + 1:]))
else:
	print(sum(a[len2 + 1:]))


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
even = 0
odd = 0
count = 0
tmp = 0
for i in a:
	if i % 2 == 0:
		even += 1
	else:
		odd += 1
if even == odd or odd == even + 1:
	print(0)
	exit()
elif even > odd:
	for i in a:
		if tmp == even - odd - 1:
			break
		if i % 2 == 0:
			count += i
			tmp += 1
elif odd > even:
	for i in a:
		if tmp == odd - even - 1:
			break
		if i % 2 != 0:
			count += i
			tmp += 1
print(count)


n = int(input())
l = sorted(list(map(int, input().split())))
l = l[::-1]
o = []
e = []
for i in l:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
if len(o) < len(e):
	print(sum(e[len(o) + 1:]))
elif len(o) > len(e):
	print(sum(o[len(e) + 1:]))
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
(odds, evens) = ([], [])
for i in range(n):
	if arr[i] % 2 == 0:
		evens.append(arr[i])
	else:
		odds.append(arr[i])
evens.sort()
odds.sort()
even = len(evens) > len(odds)
while True:
	if even:
		if len(evens) > 0:
			evens.pop()
		else:
			break
		even = not even
	else:
		if len(odds) > 0:
			odds.pop()
		else:
			break
		even = not even
print(sum(evens) + sum(odds))


n = int(input())
arr = list(map(int, input().split()))
arr1 = []
arr2 = []
for i in range(n):
	if arr[i] % 2 == 0:
		arr1.append(arr[i])
	else:
		arr2.append(arr[i])
arr1.sort(reverse=True)
arr2.sort(reverse=True)
if len(arr1) == len(arr2):
	print(0)
elif len(arr1) > len(arr2):
	l = len(arr2)
	print(sum(arr1) - sum(arr1[:l + 1]))
else:
	l = len(arr1)
	print(sum(arr2) - sum(arr2[:l + 1]))


t = int(input())
l = list(map(int, input().split()))
even = []
odd = []
for w in l:
	if w % 2 == 0:
		even.append(w)
	else:
		odd.append(w)
even = sorted(even)
odd = sorted(odd)
(e, o) = (len(even), len(odd))
ans = 0
if e == o or e - o == 1 or e - o == -1:
	print(0)
elif e == 0:
	for w in range(o - 1):
		ans += odd[w]
	print(ans)
elif o == 0:
	for w in range(e - 1):
		ans += even[w]
	print(ans)
else:
	if e > o:
		for w in range(e - o - 1):
			ans += even[w]
	elif o > e:
		for w in range(o - e - 1):
			ans += odd[w]
	print(ans)


from bisect import insort
n = int(input())
e = []
o = []
for v in map(int, input().split()):
	if v & 1:
		insort(o, v)
	else:
		insort(e, v)
le = len(e)
lo = len(o)
de = max(le - lo - 1, 0)
do = max(lo - le - 1, 0)
print(sum(e[:de]) + sum(o[:do]))


n = int(input())
lst = [int(i) for i in input().split()]
even = []
odd = []
for i in lst:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd) or abs(len(even) - len(odd)) == 1:
	print(0)
elif len(even) > len(odd):
	print(sum(even[:len(even) - len(odd) - 1]))
else:
	print(sum(odd[:len(odd) - len(even) - 1]))


n = int(input())
a = []
b = []
for i in list(map(int, input().split())):
	if i % 2:
		a.append(i)
	else:
		b.append(i)
a.sort()
b.sort()
s = sum(a) + sum(b)
i = len(a) - 1
j = len(b) - 1
while True:
	if i >= 0:
		s -= a[i]
		i -= 1
	else:
		break
	if j >= 0:
		s -= b[j]
		j -= 1
	else:
		break
s1 = sum(a) + sum(b)
i = len(a) - 1
j = len(b) - 1
while True:
	if j >= 0:
		s1 -= b[j]
		j -= 1
	else:
		break
	if i >= 0:
		s1 -= a[i]
		i -= 1
	else:
		break
print(min(s, s1))


n = int(input())
l = [*map(int, input().split())]
odd = []
even = []
for i in l:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
odd.sort()
even.sort()
while odd and even:
	odd.pop()
	even.pop()
res = float('inf')
if not odd and (not even):
	res = 0
if odd:
	res = min(res, sum(odd) + sum(even) - odd[-1])
if even:
	res = min(res, sum(odd) + sum(even) - even[-1])
print(res)


from __future__ import absolute_import, division, print_function, unicode_literals
from typing import List
import sys
DEBUG = len(sys.argv) > 1 and sys.argv[1] == '-d'

def LOG(*argv):
	if DEBUG:
		print(*argv, file=sys.stderr)

def CHECK(cond, err_msg=''):
	if DEBUG:
		assert cond, err_msg

def CHECK_EQ(a, b, err_msg=''):
	CHECK(a == b, err_msg='{} v.s. {} {}'.format(a, b, err_msg))

def readval(typ=int):
	return typ(input())

def readvals(typ=int):
	return map(typ, input().split())

def solve(arr: List[int]) -> int:
	(pile1, pile2) = ([], [])
	for a in arr:
		if a % 2 == 0:
			pile1.append(a)
		else:
			pile2.append(a)
	if len(pile1) < len(pile2):
		(pile1, pile2) = (pile2, pile1)
	LOG(pile1)
	LOG(pile2)
	if len(pile1) - len(pile2) <= 1:
		return 0
	pile1.sort(reverse=True)
	return sum(pile1[len(pile2) + 1:])
CHECK_EQ(solve([1, 2, 3]), 0)
CHECK_EQ(solve([2, 3, 4, 4]), 2)
CHECK_EQ(solve([4, 4, 4]), 8)
CHECK_EQ(solve([4, 5]), 0)
CHECK_EQ(solve([1, 5, 8, 7, 2]), 0)
_ = readval()
arr = readvals()
print(solve(arr))


N = int(input())
A = [int(a) for a in input().split()]
E = []
O = []
for a in A:
	if a % 2:
		O.append(a)
	else:
		E.append(a)
E = sorted(E)
O = sorted(O)
e = len(E)
o = len(O)
if e == o:
	print(0)
elif e < o:
	print(sum(O[:o - e - 1]))
else:
	print(sum(E[:e - o - 1]))


n = int(input())
a = [int(i) for i in input().split()]
odd = []
even = []
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
if abs(len(odd) - len(even)) <= 0:
	print('0')
	exit(0)
m = min(len(odd), len(even)) + 1
odd.sort()
even.sort()
ans = []
for i in range(len(odd) - m):
	ans.append(odd[i])
for i in range(len(even) - m):
	ans.append(even[i])
print(sum(ans))


n = int(input())
a = [int(i) for i in input().split()]
cntev = 0
cntodd = 0
even = []
odd = []
for el in a:
	if el % 2 == 0:
		even.append(el)
	else:
		odd.append(el)
even.sort()
odd.sort()
s = 0
if abs(len(even) - len(odd)) < 2:
	print(0)
elif len(even) > len(odd):
	cnt = len(even) - len(odd)
	for i in range(cnt - 1):
		s += even[i]
	print(s)
elif len(even) < len(odd):
	cnt = len(odd) - len(even)
	for i in range(cnt - 1):
		s += odd[i]
	print(s)


def fun(array, n):
	(odd, even) = ([], [])
	(l_odd, l_even) = (0, 0)
	for v in array:
		if v % 2 == 0:
			even.append(v)
			l_even += 1
		else:
			odd.append(v)
			l_odd += 1
	if l_odd == 0:
		even.sort()
		return sum(even[:l_even - 1])
	if l_even == 0:
		odd.sort()
		return sum(odd[:l_odd - 1])
	odd.sort()
	even.sort()
	if l_odd == l_even or (l_odd == l_even + 1 or l_even == l_odd + 1):
		return 0
	elif l_odd > l_even:
		return sum(odd[:l_odd - l_even - 1])
	else:
		return sum(even[:l_even - l_odd - 1])
n = int(input())
array = list(map(int, input().split()))
print(fun(array, n))


def minisum(arr):
	evens = list(filter(lambda a: a % 2 == 0, arr))
	odds = list(filter(lambda a: a % 2 != 0, arr))
	if abs(len(evens) - len(odds)) <= 1:
		return 0
	if len(evens) > len(odds):
		diff = len(evens) - 1 - len(odds)
		return sum(evens[0:diff])
	else:
		diff = len(odds) - 1 - len(evens)
		return sum(odds[0:diff])
n = int(input())
arr = sorted(list(map(int, input().split())))
print(minisum(arr))


n = int(input())
arr = [int(item) for item in input().split(' ')]
sep = [[], []]
for item in arr:
	sep[item % 2].append(item)
e = len(sep[0])
o = len(sep[1])
d = abs(o - e)
su = 0
if d <= 1:
	pass
elif e > o:
	sep[0].sort()
	su = sum(sep[0][:d - 1])
else:
	sep[1].sort()
	su = sum(sep[1][:d - 1])
print(su)


n = int(input())
l = list(map(int, input().split()))
r = sorted(l)
k = 0

def oddCount(l):
	if l % 2 == 0:
		return False
	else:
		return True

def evenCount(l):
	if l % 2 == 0:
		return True
	else:
		return False
t1 = list(filter(oddCount, r))
t2 = list(filter(evenCount, r))
k = min(len(t1), len(t2))
if len(t1) == len(t2) + 1 or len(t1) + 1 == len(t2) or len(t1) == len(t2):
	print(0)
else:
	r = 0
	if k == len(t1):
		for i in range(len(t2) - k - 1):
			r = r + t2[i]
	else:
		for j in range(len(t1) - k - 1):
			r = r + t1[j]
	print(r)


n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
odd_total = 0
even_total = 0
odd = bool(False)
for i in range(len(a)):
	if a[i] % 2 == 0:
		even_total += 1
	else:
		odd_total += 1
if even_total < odd_total:
	odd = True
else:
	pass
for j in range(len(a)):
	if a[j] % 2 == odd:
		del a[j]
		odd = not odd
		break
	else:
		pass
c = 0
while a and c != len(a):
	if a[c] % 2 == odd:
		del a[c]
		odd = not odd
		c = 0
		continue
	elif c < len(a):
		c += 1
	else:
		break
print(sum(a))


even = []
odd = []
n = int(input())
Arr = list(map(int, input().split()))
for i in range(n):
	if Arr[i] % 2 == 0:
		even.append(Arr[i])
	else:
		odd.append(Arr[i])
even.sort()
count1 = len(even)
odd.sort()
count2 = len(odd)
if abs(count1 - count2) <= 1:
	print(0)
elif count1 > count2:
	print(sum(even[:count1 - count2 - 1]))
else:
	print(sum(odd[:count2 - count1 - 1]))


n = int(input())
arr = (int(i) for i in input().split(' '))
sum = 0
a = []
b = []
for i in arr:
	sum += i
	if i % 2 == 0:
		a.append(i)
	else:
		b.append(i)
if len(a) < len(b):
	(a, b) = (b, a)
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(len(a)):
	if i >= len(b):
		if i < len(a):
			sum -= a[i]
		print(sum)
		exit()
	sum -= a[i] + b[i]
print(sum)


n = int(input())
a = list(map(int, input().split()))
o = []
e = []
for i in range(n):
	if a[i] % 2 != 0:
		o.append(a[i])
	else:
		e.append(a[i])
o.sort()
e.sort()
c = 0
if sum(e) >= sum(o):
	c = 1
while len(e) > 0 and len(o) > 0:
	if c == 1:
		e.pop()
		o.pop()
	else:
		e.pop()
		o.pop()
if len(e) > 0:
	e.pop()
if len(o) > 0:
	o.pop()
print(sum(o) + sum(e))


n = int(input())
s = sorted(list(map(int, input().split())))
f = []
z = []
for i in s:
	if i % 2 == 1:
		f.append(i)
	else:
		z.append(i)
if abs(len(z) - len(f)) <= 1:
	print(0)
elif len(z) - len(f) > 1:
	s = 0
	for i in range(0, len(z) - len(f) - 1):
		s += z[i]
	print(s)
else:
	s = 0
	for i in range(0, len(f) - len(z) - 1):
		s += f[i]
	print(s)


n = int(input())
a = list(map(int, input().split()))
odd = []
even = []
a.sort()
a = a[::-1]
for i in a:
	if i % 2 == 0 and i != 1:
		even.append(i)
	else:
		odd.append(i)
if abs(len(odd) - len(even)) < 2:
	ans = 0
else:
	i = len(odd)
	j = len(even)
	while i > 0 and j > 0:
		odd.pop(0)
		even.pop(0)
		i -= 1
		j -= 1
	if len(odd) > 0:
		odd.pop(0)
		ans = sum(odd)
	else:
		even.pop(0)
		ans = sum(even)
print(ans)


n = int(input())
li = list(map(int, input().strip().split()))
even = 0
odd = 0
for num in li:
	if num % 2 == 0:
		even += 1
	else:
		odd += 1
even_first_deleted = False
diff = odd - even
left_nums = n - 2 * even - 1
if odd == 0:
	even_first_deleted = True
	left_nums = even - 1
elif even == 0:
	left_nums = odd - 1
elif even > odd:
	even_first_deleted = True
	diff = even - odd
	left_nums = n - 2 * odd - 1
li.sort()
sum = 0
i = 0
for num in li:
	if i >= left_nums:
		break
	elif even_first_deleted:
		if num % 2 == 0:
			sum += num
			i += 1
	elif num % 2 != 0:
		sum += num
		i += 1
print(sum)


def solve(values):
	odd = sorted((value for value in values if value % 2 == 1))
	even = sorted((value for value in values if value % 2 == 0))
	if abs(len(odd) - len(even)) <= 1:
		return 0
	if len(even) > len(odd):
		return sum(even[:len(even) - len(odd) - 1])
	return sum(odd[:len(odd) - len(even) - 1])

def main() -> None:
	n = int(input())
	values = list(map(int, input().split()))
	print(solve(values))
main()


n = int(input())
a = list(map(int, input().split()))
ch = []
nech = []
for i in a:
	if i % 2 == 0:
		ch.append(i)
	else:
		nech.append(i)
ch.sort()
nech.sort()
beg = len(ch) > len(nech)
while len(ch) > 0 and len(nech) > 0:
	if beg:
		ch.pop()
		nech.pop()
	else:
		nech.pop()
		ch.pop()
if beg:
	ch.pop()
elif len(nech) > 0:
	nech.pop()
print(sum(ch) + sum(nech))


n = int(input())
A = [int(i) for i in input().split()]
odds = [A[i] for i in range(n) if A[i] & 1]
evens = [A[i] for i in range(n) if A[i] & 1 == 0]
odds.sort()
evens.sort()
if len(odds) < len(evens):
	print(sum(evens[:max(0, len(evens) - len(odds) - 1)]))
else:
	print(sum(odds[:max(0, len(odds) - len(evens) - 1)]))


n = int(input())
a = list(map(int, input().rstrip().split()))
even = []
odd = []
if len(a) == 1:
	print(0)
	exit()
else:
	pass
for i in range(n):
	if a[i] % 2 == 0:
		even.append(a[i])
	else:
		odd.append(a[i])
even.sort()
odd.sort()
if len(even) == 0 and len(odd) >= 1:
	odd.pop()
	print(sum(odd))
elif len(odd) == 0 and len(even) >= 1:
	even.pop()
	print(sum(even))
elif len(even) == len(odd):
	print(0)
elif sum(a) == 0:
	print(0)
elif abs(len(odd) - len(even)) == 1:
	print(0)
elif len(even) > len(odd):
	print(sum(even[0:len(even) - len(odd) - 1]))
else:
	print(sum(odd[0:len(odd) - len(even) - 1]))


n = int(input())
a = sorted(list(map(int, input().split())))
o = []
e = []
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
o.sort()
e.sort()
if len(o) >= len(e):
	s = sum(o[0:max(len(o) - len(e) - 1, 0)])
else:
	s = sum(e[0:max(len(e) - len(o) - 1, 0)])
print(s)


n = int(input())
l = [int(i) for i in input().split()]
lp = []
li = []
for i in range(n):
	if l[i] % 2 == 0:
		lp.append(l[i])
	else:
		li.append(l[i])
li = sorted(li)
li = li[::-1]
lp = sorted(lp)
lp = lp[::-1]
if len(lp) == len(li) or abs(len(lp) - len(li)) == 1:
	print(0)
elif len(li) > len(lp):
	print(sum(li[len(lp) + 1:]))
else:
	print(sum(lp[len(li) + 1:]))


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
ev = [i for i in L if i % 2 == 0]
od = [i for i in L if i % 2]
ev = sorted(ev)
od = sorted(od)
ma = max(len(ev), len(od))
(le, lo) = (len(ev), len(od))
if ma == len(ev):
	if lo == le or le == lo + 1:
		print(0)
	else:
		print(sum(ev[:le - lo - 1]))
elif lo == le or lo == le + 1:
	print(0)
else:
	print(sum(od[:lo - le - 1]))


n = int(input())
(e, o) = ([], [])
for i in map(int, input().split()):
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
(se, so) = (len(e), len(o))
e.sort()
o.sort()
if se == so or abs(se - so) == 1:
	exit(print(0))
print(sum(e[:se - (so + 1)]) if min(se, so) == so else sum(o[:so - (se + 1)]))


n = input()
input_ = input().split()
nums = list(map(int, input_))
odd = 0
even = 0
nums.sort()
oddNum = []
evenNum = []
for i in nums:
	if i % 2:
		odd += 1
		oddNum.append(i)
	else:
		even += 1
		evenNum.append(i)
if odd == even or abs(odd - even) == 1:
	print(0)
else:
	ans = 0
	dif = abs(odd - even)
	dif -= 1
	if odd > even:
		print(sum(oddNum[0:dif]))
	else:
		print(sum(evenNum[0:dif]))


n = int(input())
r = list(map(int, input().split()))
ev = []
od = []
for i in r:
	if i % 2 == 0:
		ev.append(i)
	else:
		od.append(i)
if len(ev) > len(od):
	ev.sort()
	ev.remove(ev[len(ev) - 1])
	ev = ev[:len(ev) - len(od)]
	print(sum(ev))
elif len(ev) - len(od) == 0:
	print(0)
else:
	od.sort()
	od.remove(od[len(od) - 1])
	od = od[:len(od) - len(ev)]
	print(sum(od))


import heapq
n = int(input())
a = list(map(int, input().split()))
parity_map = {0: [], 1: []}
for ai in a:
	parity_map[ai % 2].append(ai)
odd_len = len(parity_map[1])
even_len = len(parity_map[0])
min_heap = list()
if abs(odd_len - even_len) <= 1:
	print(0)
else:
	if odd_len > even_len:
		rem_len = odd_len - even_len - 1
		rel_elems = parity_map[1]
	else:
		rem_len = even_len - odd_len - 1
		rel_elems = parity_map[0]
	heapq.heapify(rel_elems)
	ans = 0
	for _ in range(rem_len):
		curr = heapq.heappop(rel_elems)
		ans += curr
	print(ans)


def count_odd_and_even(lst):
	odd = []
	even = []
	for i in lst:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	odd_num = len(odd)
	even_num = len(even)
	if odd_num == even_num or odd_num + 1 == even_num or even_num + 1 == odd_num:
		return 0
	else:
		delta = abs(odd_num - even_num) - 1
		if odd_num > even_num:
			return sum(odd[:delta])
		elif odd_num < even_num:
			return sum(even[:delta])
n = int(input())
lst = sorted(list(map(int, input().split())))
print(count_odd_and_even(lst))


n = int(input())
l = list(map(int, input().split()))
(el, ol) = ([], [])
(e, o) = (0, 0)
for x in l:
	if x % 2 == 0:
		el.append(x)
		e += 1
	else:
		ol.append(x)
		o += 1
if abs(e - o) <= 1:
	print(0)
elif e > o:
	el.sort(reverse=True)
	print(sum(el[o + 1:]))
else:
	ol.sort(reverse=True)
	print(sum(ol[e + 1:]))


n = int(input())
A = sorted(list(map(int, input().split())))
anso = 0
anse = 0
for i in A:
	if i % 2 == 0:
		anse += 1
	else:
		anso += 1
k = 0
ans = 0
t = 0
if anse > anso:
	while k < n and t < anse - anso - 1:
		if A[k] % 2 == 0:
			ans += A[k]
			t += 1
		k += 1
else:
	while k < n and t < anso - anse - 1:
		if A[k] % 2 == 1:
			ans += A[k]
			t += 1
		k += 1
print(ans)


import math
import sys

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
n = ii()
d = li()
odd = []
even = []
for i in d:
	if i % 2:
		even.append(i)
	else:
		odd.append(i)
odd.sort()
even.sort()
a = len(odd)
b = len(even)
if a >= b:
	print(sum(odd[:-(b + 1)]))
else:
	print(sum(even[:-(a + 1)]))


import random

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	n = input()
	a = li()
	even = []
	odd = []
	for i in a:
		if i % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
	even = sorted(even)
	odd = sorted(odd)
	even2 = [i for i in even]
	odd2 = [i for i in odd]
	(sum1, sum2) = (0, 0)
	if len(even) == len(odd):
		print(0)
		exit()
	while len(even) > 0 and len(odd) > 0:
		even.pop()
		odd.pop()
	if len(odd) > 0:
		odd.pop()
		sum1 = sum(odd)
	else:
		even.pop()
		sum1 = sum(even)
	while len(even2) > 0 and len(odd2) > 0:
		even2.pop()
		odd2.pop()
	if len(odd2) > 0:
		odd2.pop()
		sum2 = sum(odd2)
	else:
		even2.pop()
		sum2 = sum(even2)
	print(max(sum1, sum2))
main()


n = int(input())
n1 = list(map(int, input().split()))
oddlist = []
evenlist = []
for i in n1:
	if i % 2 == 0:
		evenlist.append(i)
	else:
		oddlist.append(i)
evenlist.sort()
oddlist.sort()
a1 = len(evenlist)
b1 = len(oddlist)
if a1 > b1:
	index = a1 - b1 - 1
	sumo = 0
	for i in range(index):
		sumo += evenlist[i]
elif b1 > a1:
	index = b1 - a1 - 1
	sumo = 0
	for i in range(index):
		sumo += oddlist[i]
else:
	sumo = 0
print(sumo)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ch = [[], []]
for i in a:
	ch[i % 2].append(i)
ch[0].sort(reverse=True)
ch[1].sort(reverse=True)
if len(ch[0]) >= len(ch[1]):
	s -= sum(ch[1])
	s -= sum(ch[0][:len(ch[1])])
	if len(ch[0]) != len(ch[1]):
		s -= ch[0][len(ch[1])]
else:
	s -= sum(ch[0])
	s -= sum(ch[1][:len(ch[0]) + 1])
print(s)


ll = lambda : list(map(int, input().split()))
n = int(input())
l = ll()
(e, o) = ([], [])
total = sum(l)
for i in l:
	if i & 1:
		o.append(i)
	else:
		e.append(i)
o.sort(reverse=True)
e.sort(reverse=True)
if abs(len(o) - len(e)) <= 1:
	print(0)
else:
	if len(o) < len(e):
		ans = sum(e[:len(o) + 1]) + sum(o)
	else:
		ans = sum(o[:len(e) + 1]) + sum(e)
	print(total - ans)


n = input()
l = list(map(int, input().split()))
odd = list()
even = list()
for i in l:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd.sort()
even.sort()
r = 0
q = len(odd) - len(even)
w = len(even) - len(odd)
if q > 1:
	for i in range(q - 1):
		r = r + odd[i]
elif w > 1:
	for i in range(w - 1):
		r = r + even[i]
print(r)


from math import *

def sumx(z, t):
	count = 0
	for i in range(t):
		count = count + z[i]
	return count
n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in a:
	if i % 2 == 0:
		b.append(i)
	else:
		c.append(i)
d = sorted(b)
e = sorted(c)
f = abs(len(d) - len(e))
if f == 1 or 0:
	print(0)
elif len(d) > len(e):
	print(sumx(d, f - 1))
else:
	print(sumx(e, f - 1))


n = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
e = []
o = []
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
l_e = len(e)
l_o = len(o)
c = e
if l_o > l_e:
	c = o
t = max(l_e, l_o) - min(l_e, l_o) - 1
s = 0
if t > 0:
	s = sum(c[:t])
print(s)


n = int(input())
a = [int(i) for i in input().split()]
e = []
o = []
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
o.sort(reverse=True)
e.sort(reverse=True)
(poso, pose) = (0, 0)
player = 0
while True == True:
	if player == 0:
		if pose < len(e):
			pose += 1
		else:
			break
	elif poso < len(o):
		poso += 1
	else:
		break
	player ^= 1
sum1 = 0
if poso == len(o):
	for i in range(pose, len(e), 1):
		sum1 += e[i]
else:
	for i in range(poso, len(o), 1):
		sum1 += o[i]
(poso, pose) = (0, 0)
player = 1
while True == True:
	if player == 0:
		if pose < len(e):
			pose += 1
		else:
			break
	elif poso < len(o):
		poso += 1
	else:
		break
	player ^= 1
sum2 = 0
if poso == len(o):
	for i in range(pose, len(e), 1):
		sum2 += e[i]
else:
	for i in range(poso, len(o), 1):
		sum2 += o[i]
print(min(sum1, sum2))


n = int(input())
ch = input()
L = ch.split(' ')
odd = []
even = []
for i in L:
	if int(i) % 2 == 0:
		even.append(int(i))
	else:
		odd.append(int(i))
even.sort()
odd.sort()
d = len(even) - len(odd)
if d >= 1:
	print(sum(even[:abs(d) - 1]))
elif d <= -1:
	print(sum(odd[:abs(d) - 1]))
elif d == 0:
	print('0')


import math
n = int(input())
l = list(map(int, input().split()))
countOdd = 0
countEven = 0
for i in range(0, n):
	if l[i] % 2 == 0:
		countOdd += 1
	else:
		countEven += 1
l.sort()
if abs(countEven - countOdd) == 0 or abs(countEven - countOdd) == 1:
	print(0)
	exit(0)
sums = 0
if countEven > countOdd:
	k = countEven - countOdd - 1
	while True:
		for i in range(0, n):
			if l[i] % 2 != 0:
				sums += l[i]
				k -= 1
			if k == 0:
				print(sums)
				exit(0)
else:
	k = countOdd - countEven - 1
	while True:
		for i in range(0, n):
			if l[i] % 2 == 0:
				sums += l[i]
				k -= 1
			if k == 0:
				print(sums)
				exit(0)


n = int(input())
a = [int(j) for j in input().split()]
a.sort()
even = []
odd = []
for i in range(n):
	if a[i] % 2 == 0:
		even += [a[i]]
	else:
		odd += [a[i]]
if abs(len(even) - len(odd)) <= 1:
	print(0)
elif len(even) - len(odd) >= 1:
	print(sum(even[:len(even) - len(odd) - 1]))
elif len(odd) - len(even) >= 1:
	print(sum(odd[:len(odd) - len(even) - 1]))


n = int(input())
l = list(map(int, input().split()))
l1 = []
l2 = []
for i in range(len(l)):
	if l[i] % 2 == 0:
		l1.append(l[i])
	else:
		l2.append(l[i])
l1.sort()
l2.sort()
if abs(len(l1) - len(l2)) == 0 or abs(len(l1) - len(l2)) == 1:
	print('0')
else:
	sum1 = 0
	if len(l1) > len(l2):
		for j in range(len(l1) - len(l2) - 1):
			sum1 = sum1 + l1[j]
	else:
		for j in range(len(l2) - len(l1) - 1):
			sum1 = sum1 + l2[j]
	print(sum1)


input()
temp = [int(x) for x in input().split()]
even = list()
odd = list()
for i in temp:
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
if len(odd) + 1 == len(even) or len(odd) == len(even) or len(odd) - 1 == len(even):
	print(0)
elif len(odd) + 1 < len(even):
	even.sort()
	print(sum(even[0:len(even) - len(odd) - 1]))
elif len(even) + 1 < len(odd):
	odd.sort()
	print(sum(odd[0:len(odd) - len(even) - 1]))


n = int(input())
a = [int(s) for s in input().split()]
a.sort()
ch = []
nh = []
(c, h) = (0, 0)
for i in range(n):
	if a[i] % 2 == 0:
		ch.append(a[i])
	else:
		nh.append(a[i])
r = abs(len(ch) - len(nh)) - 1
s = 0
if r > 0:
	if len(ch) > len(nh):
		s = sum(ch[:r])
	else:
		s = sum(nh[:r])
print(s)


n = int(input())
ms = input().split()
(chet, nechet) = ([], [])
for i in range(n):
	ms[i] = int(ms[i])
	if ms[i] % 2 == 0:
		chet.append(ms[i])
	else:
		nechet.append(ms[i])
a = len(chet)
b = len(nechet)
c = max(a, b) - min(a, b) - 1
if c <= 0:
	print(0)
elif a > b:
	chet.sort()
	print(sum(chet[:c]))
else:
	nechet.sort()
	print(sum(nechet[:c]))


n = int(input())
l = list(map(int, input().strip().split()))
p = []
d = []
for i in range(n):
	if l[i] % 2 == 0:
		p += [l[i]]
	else:
		d += [l[i]]
p = sorted(p)[::-1]
d = sorted(d)[::-1]
if abs(len(p) - len(d)) <= 1:
	print(0)
elif len(p) > len(d):
	print(sum(p[len(d) + 1:]))
else:
	print(sum(d[len(p) + 1:]))


n = int(input())
a = [int(x) for x in input().split()]
b = [x for x in a if x % 2 == 0]
c = [x for x in a if x % 2 != 0]
b.sort(reverse=True)
c.sort(reverse=True)
if len(b) < len(c):
	(b, c) = (c, b)
s = 0
for i in range(len(c) + 1, len(b)):
	s += b[i]
print(s)


n = int(input())
lst = sorted(list(map(int, input().split())), reverse=True)
even = odd = 0
for i in range(n):
	if lst[i] & 1 == 1:
		odd += 1
	else:
		even += 1
if even > odd:
	even = odd + 1
elif odd > even:
	odd = even + 1
for i in range(n):
	if lst[i] & 1 == 1 and odd > 0:
		odd -= 1
		lst[i] = 0
	elif lst[i] & 1 == 0 and even > 0:
		even -= 1
		lst[i] = 0
	if even == 0 and odd == 0:
		break
print(sum(lst))


n = int(input())
lis = list(map(int, input().split()))[:n]
odd = sorted(list(filter(lambda x: x % 2 != 0, lis)))
even = sorted(list(filter(lambda x: x % 2 == 0, lis)))
odd = odd[::-1]
even = even[::-1]
le = min(len(odd), len(even))
print(sum(odd[le + 1:] + even[le + 1:]))


n = int(input())
inp = input()
a = list(map(int, inp.split()))
odd_a = list()
ndd_a = list()
for x in a:
	if x % 2 == 0:
		odd_a.append(x)
	else:
		ndd_a.append(x)
sum_1 = 0
sum_2 = 0
odd_a = sorted(odd_a)
ndd_a = sorted(ndd_a)
odd_a_r = odd_a.copy()
ndd_a_r = ndd_a.copy()
cur = True
while len(odd_a) > 0 and len(ndd_a) > 0:
	if cur:
		odd_a.pop()
	else:
		ndd_a.pop()
	cur = not cur
if cur and len(odd_a) > 0:
	odd_a.pop()
if not cur and len(ndd_a) > 0:
	ndd_a.pop()
sum_1 = sum(odd_a) + sum(ndd_a)
cur = False
while len(odd_a_r) > 0 and len(ndd_a_r) > 0:
	if cur:
		odd_a_r.pop()
	else:
		ndd_a_r.pop()
	cur = not cur
if cur and len(odd_a_r) > 0:
	odd_a_r.pop()
if not cur and len(ndd_a_r) > 0:
	ndd_a_r.pop()
sum_2 = sum(odd_a_r) + sum(ndd_a_r)
print(min(sum_1, sum_2))


n = int(input())
s = list(map(int, input().split()))
odd = []
even = []
for i in s:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
odd.sort()
even.sort()
if abs(len(odd) - len(even)) <= 1:
	print(0)
else:
	m = min(len(odd), len(even))
	if len(odd) > len(even):
		print(sum(odd[:-m - 1]))
	else:
		print(sum(even[:-m - 1]))


def run(n, a):
	even = sorted([i for i in a if i % 2 == 0], reverse=True)
	odd = sorted([i for i in a if i % 2 != 0], reverse=True)
	l1 = len(even)
	l2 = len(odd)
	if l1 < l2:
		print(sum(odd[l1 + 1:]))
	elif l2 < l1:
		print(sum(even[l2 + 1:]))
	else:
		print(0)
n = int(input())
a = list(map(int, input().split()))
run(n, a)


n = int(input())
a = list(map(int, input().split()))
b = [i for i in a if i % 2 == 0]
c = [i for i in a if i % 2 == 1]
(p, q) = (len(b), len(c))
b.sort()
c.sort()
if p > q:
	if p == q + 1:
		print(0)
	else:
		print(sum(b[:p - (q + 1)]))
elif p < q:
	if q == p + 1:
		print(0)
	else:
		print(sum(c[:q - (p + 1)]))
else:
	print(0)


n = int(input())
a = [[], []]
for i in map(int, input().split()):
	a[i % 2].append(i)
d = len(a[0]) - len(a[1])
if abs(d) < 2:
	print(0)
else:
	m = a[0] if d > 0 else a[1]
	m.sort()
	print(sum(m[:abs(d) - 1]))


a = int(input())
arr = list(map(int, input().split()))
even = []
odd = []
ans = 0
for x in arr:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
even = sorted(even)
odd = sorted(odd)
diff = int(abs(len(even) - len(odd)))
if diff > 1:
	if len(even) < len(odd):
		for i in range(diff - 1):
			ans += odd[i]
	else:
		for i in range(diff - 1):
			ans += even[i]
print(ans)


n = int(input())
l = [0] + list(map(int, input().split()))
ans = sum(l)
sum_ch = 0
sum_n = 0
while True:
	max_ch = 0
	max_n = 0
	for i in range(1, len(l)):
		if l[i] % 2 == 0 and l[i] > l[max_ch]:
			max_ch = i
		elif l[i] % 2 == 1 and l[i] > l[max_n]:
			max_n = i
	sum_ch += l[max_ch]
	sum_n += l[max_n]
	if l[max_ch] != 0:
		sum_ch += l[max_n]
	if l[max_n] != 0:
		sum_n += l[max_ch]
	if l[max_ch] == 0 or l[max_n] == 0:
		break
	l[max_ch] = 0
	l[max_n] = 0
print(ans - max(sum_ch, sum_n))


n = int(input())
a = [int(i) for i in input().split()]
odd = [i for i in a if i % 2 == 0]
even = [i for i in a if i % 2 != 0]
odd.sort()
even.sort()
if len(even) == len(odd) + 1 or len(even) + 1 == len(odd) or len(even) == len(odd):
	print('0')
else:
	nums = abs(len(even) - len(odd)) - 1
	summ = 0
	if len(odd) > len(even):
		summ = sum(odd[:nums])
	else:
		summ = sum(even[:nums])
	print(summ)


n = int(input())
a = list(map(int, input().split()))
a.sort()
odd = 0
even = 0
for i in a:
	if i % 2 == 0:
		even += 1
	else:
		odd += 1
summ = 0
if odd + 1 > even:
	ac = odd - even - 1
	add = 0
	for i in a:
		if add < ac:
			if i % 2 == 1:
				summ += i
				add += 1
		else:
			break
elif even + 1 > odd:
	ac = even - odd - 1
	add = 0
	for i in a:
		if add < ac:
			if i % 2 == 0:
				summ += i
				add += 1
		else:
			break
print(summ)


n = int(input())
l = list(map(int, input().split()))
par = []
npar = []
for i in l:
	if i % 2 == 0:
		par.append(i)
	else:
		npar.append(i)
if abs(len(par) - len(npar)) <= 1:
	print(0)
else:
	if len(par) - len(npar) > 1:
		par = sorted(par)
		npar = sorted(npar)
		wyn = 0
		for i in range(len(par) - len(npar) - 1):
			wyn = wyn + par[i]
		print(wyn)
	if len(npar) - len(par) > 1:
		par = sorted(par)
		npar = sorted(npar)
		wyn = 0
		for i in range(len(npar) - len(par) - 1):
			wyn = wyn + npar[i]
		print(wyn)


n = int(input())
a = list(map(int, input().split()))
e = []
o = []
for i in a:
	if i % 2 == 0:
		e.append(i)
	else:
		o.append(i)
if len(e) == len(o) or abs(len(e) - len(o)) == 1:
	print(0)
elif len(e) < len(o):
	e.sort(reverse=True)
	o.sort(reverse=True)
	s = len(e)
	ans = sum(o[s + 1:])
	print(ans)
else:
	e.sort(reverse=True)
	o.sort(reverse=True)
	s = len(o)
	ans = sum(e[s + 1:])
	print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
even = []
odd = []
od = 0
e = 0
for i in arr:
	if i & 1:
		odd.append(i)
		od += 1
	else:
		even.append(i)
		e += 1
l = abs(od - e) - 1
if l == 0 or l == -1:
	print(0)
elif od > e:
	print(sum(odd[:l]))
else:
	print(sum(even[:l]))


n = int(input())
a = [int(x) for x in input().split()]
odds = sorted([x for x in a if x % 2])
evens = sorted([x for x in a if x % 2 == 0])
diff = len(odds) - len(evens)
if diff == 0:
	print(0)
elif diff < 0:
	diff += 1
	print(sum(evens[:-diff]))
else:
	diff -= 1
	print(sum(odds[:diff]))


n = int(input())
inp = input()
(even, odd) = ([], [])
numbers = inp.split(' ')
for number in numbers:
	number = int(number)
	if number % 2 == 0:
		even.append(number)
	else:
		odd.append(number)
diff = abs(len(even) - len(odd))
if diff <= 1:
	print(0)
else:
	sum = 0
	even.sort()
	odd.sort()
	if len(even) > len(odd):
		for i in reversed(range(diff - 1)):
			sum += even[i]
	else:
		for i in reversed(range(diff - 1)):
			sum += odd[i]
	print(sum)


N = int(input())
A = list(map(int, input().split()))
odds = [i for i in A if i % 2 == 1]
evens = [i for i in A if i % 2 == 0]
nodds = len(odds)
nevens = len(evens)
if nodds == nevens or abs(nodds - nevens) == 1:
	res = 0
elif nodds < nevens:
	diff = nevens - nodds - 1
	sevens = sorted(evens, reverse=True)
	res = sum(sevens[-diff:])
elif nevens < nodds:
	diff = nodds - nevens - 1
	sodds = sorted(odds, reverse=True)
	res = res = sum(sodds[-diff:])
print(res)


n = int(input())
mas = list(map(int, input().split()))
ch = []
nch = []
for i in mas:
	if i % 2 == 1:
		nch.append(i)
	else:
		ch.append(i)
ch.sort(reverse=True)
nch.sort(reverse=True)
for i in range(min(len(ch), len(nch))):
	ch.pop(0)
	nch.pop(0)
if (len(ch) <= 1) & (len(nch) <= 1):
	print(0)
elif len(ch) > 1:
	print(sum(ch[1:]))
else:
	print(sum(nch[1:]))


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
arr = intInp()
even = []
odd = []
for i in arr:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
even.sort()
odd.sort()
if abs(len(even) - len(odd)) < 2:
	print(0)
elif len(odd) > len(even):
	print(sum(odd[0:len(odd) - len(even) - 1]))
else:
	print(sum(even[0:len(even) - len(odd) - 1]))


n = int(input())
numl = list(map(int, input().split()))
numl.sort()
(even, odd) = ([], [])
for i in numl:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
le = len(even)
lo = len(odd)
if abs(le - lo) < 2:
	print(0)
elif le > lo:
	print(sum(even[:le - lo - 1]))
else:
	print(sum(odd[:lo - le - 1]))


import sys
import random

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		x = [self.next_int() for _ in range(0, n)]
		odd = sorted(filter(lambda x: x % 2 == 1, x))
		even = sorted(filter(lambda x: x % 2 == 0, x))
		if len(odd) > len(even) + 1:
			print(sum(odd[:len(odd) - len(even) - 1]))
		elif len(even) > len(odd) + 1:
			print(sum(even[:len(even) - len(odd) - 1]))
		else:
			print(0)
Main().solve()


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	n = int(input())
	o = []
	e = []
	m = map(int, read().split())
	for a in m:
		if a & 1:
			o.append(a)
		else:
			e.append(a)
	sumall = sum(o) + sum(e)
	o.sort(reverse=True)
	e.sort(reverse=True)
	leno = len(o)
	lene = len(e)
	if leno == lene:
		print(0)
	elif leno < lene:
		r = sumall - sum(e[:leno + 1]) - sum(o)
		print(r)
	else:
		r = sumall - sum(o[:lene + 1]) - sum(e)
		print(r)
main()


n = int(input())
a = [int(s) for s in input().split()]
even = []
odd = []
a.sort()
for i in a:
	if i % 2 == 0:
		even.append(i)
	else:
		odd.append(i)
ev = len(even)
od = len(odd)
if abs(ev - od) <= 1:
	print(0)
elif ev > od:
	print(sum(even[:ev - od - 1]))
elif od > ev:
	print(sum(odd[:od - ev - 1]))