Jeff got 2n real numbers a_1, a_2, ..., a_2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:  choose indexes i and j (i ≠ j) that haven't been chosen yet;  round element a_{i} to the nearest integer that isn't more than a_{i} (assign to a_{i}: ⌊ a_{i} ⌋);  round element a_{j} to the nearest integer that isn't less than a_{j} (assign to a_{j}: ⌈ a_{j} ⌉). 

Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a_1, a_2, ..., a_2n (0 ≤ a_{i} ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.


-----Output-----

In a single line print a single real number — the required difference with exactly three digits after the decimal point.


-----Examples-----
Input
3
0.000 0.500 0.750 1.000 2.000 3.000

Output
0.250

Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896

Output
0.279



-----Note-----

In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.

Difficulty: MEDIUM_HARD
Tags: Mathematics

Dynamic programming

Implementation

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
n = int(input())
As = list(map(float, input().split()))
B = list((x - int(x) for x in As if x - int(x) > 0.0))
l = len(B)
if l == 0:
	print('{:.3f}'.format(0))
	exit(0)
S = sum((x for x in B))
ll = l if l % 2 == 0 else l + 1
ans = 10000000000.0
for i in range(max(0, l - n), (n if l > n else l) + 1):
	ans = min(ans, abs(i - S))
print('{:.3f}'.format(ans))


k = 0
ans = 0
n = int(input())
a = input().split()
for i in range(2 * n):
	s = float(a[i])
	if s != int(s):
		k += 1
		ans += int(s) + 1 - s
if ans - int(ans) > 0.5:
	p = int(ans) + 1
else:
	p = int(ans)
if p > n:
	p = n
if p + n >= k:
	print('%.3f' % abs(ans - p))
else:
	print('%.3f' % abs(ans - k + n))


n = int(input())
arr = list(map(float, input().split()))
arr = sorted([x - int(x) for x in arr if x - int(x) != 0])
o = 2 * n - len(arr)
arr_sum = sum(arr)
res = int(2000000000.0)
for i in range(n + 1):
	if i + o >= n:
		res = min(res, abs(i - arr_sum))
print('%.3f' % res)


N = int(input())
n = N
A = list(map(float, input().strip().split(' ')))
z = 0
for i in range(len(A)):
	A[i] = round(A[i], 3) - int(A[i])
	if A[i] == 0:
		z += 1
ANS = sum(A)
ans = 10 ** 10
for j in range(n - z, n + 1):
	ans = min(ans, abs(ANS - j))
print('%.3f' % ans)


n = int(input())
l = list(map(float, input().split()))
l = sorted([x - int(x) for x in l if x - int(x) != 0])
o = 2 * n - len(l)
su = sum(l)
ans = 1152921504606846975
for i in range(n + 1):
	if i + o >= n:
		ans = min(ans, abs(i - su))
print('%.3f' % ans)


(n, t) = (int(input()), [int(i[-3:]) for i in input().split()])
(k, s) = (t.count(0), sum(t))
c = s // 1000 + int(s % 1000 > 500)
(a, b) = (max(0, n - k), min(2 * n - k, n))
if a <= c <= b:
	s = abs(c * 1000 - s)
else:
	s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))


(n, k, s) = (int(input()), 0, 0)
for i in input().split():
	j = int(i[-3:])
	if j == 0:
		k += 1
	else:
		s += j
c = s // 1000 + int(s % 1000 > 500)
(a, b) = (max(0, n - k), min(2 * n - k, n))
if a <= c <= b:
	s = abs(c * 1000 - s)
else:
	s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))


from sys import *
s1 = stdin.readline().strip()
n = int(s1)
s1 = stdin.readline().strip()
a = list(map(float, s1.split()))
b = []
for i in range(2 * n):
	if int(a[i]) != a[i]:
		b.append(round(1000 * (a[i] - int(a[i]))))
m = len(b)
r = 0
for i in range(m):
	r = r + b[i]
if m <= n:
	if r >= 1000 * m:
		r = r - 1000 * m
	else:
		r = min(r - 1000 * (r // 1000), 1000 - r + 1000 * (r // 1000))
elif r >= n * 1000:
	r = r - 1000 * n
elif r <= 1000 * (m - n):
	r = 1000 * (m - n) - r
else:
	r = min(r - 1000 * (r // 1000), 1000 - r + 1000 * (r // 1000))
r = r / 1000
print('%.3f' % r)


from sys import *
import math

def numline(f=int):
	return map(f, input().split())
n = int(input())
a = list(filter(lambda x: x != 0, numline(lambda s: int(s.split('.')[1]))))
c0 = min(2 * n - len(a), len(a))
s = sum(a) - 1000 * min(n, len(a))
ans = abs(s)
for i in range(c0):
	s += 1000
	ans = min(ans, abs(s))
print('{}.{:0>3}'.format(ans // 1000, ans % 1000))