You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $E = \sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$. You have to perform exactly k_1 operations on array A and exactly k_2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.

Output the minimum possible value of error after k_1 operations on array A and k_2 operations on array B have been performed.


-----Input-----

The first line contains three space-separated integers n (1 ≤ n ≤ 10^3), k_1 and k_2 (0 ≤ k_1 + k_2 ≤ 10^3, k_1 and k_2 are non-negative) — size of arrays and number of operations to perform on A and B respectively.

Second line contains n space separated integers a_1, a_2, ..., a_{n} ( - 10^6 ≤ a_{i} ≤ 10^6) — array A.

Third line contains n space separated integers b_1, b_2, ..., b_{n} ( - 10^6 ≤ b_{i} ≤ 10^6)— array B.


-----Output-----

Output a single integer — the minimum possible value of $\sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$ after doing exactly k_1 operations on array A and exactly k_2 operations on array B.


-----Examples-----
Input
2 0 0
1 2
2 3

Output
2
Input
2 1 0
1 2
2 2

Output
0
Input
2 5 7
3 4
14 4

Output
1


-----Note-----

In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)^2 + (2 - 3)^2 = 2. 

In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)^2 + (2 - 2)^2 = 0. This is the minimum possible error obtainable.

In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)^2 + (4 - 4)^2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)^2 + (4 - 5)^2 = 1.

Source: codeforces | Difficulty: MEDIUM
Tags: Sorting

Data structures

Greedy algorithms


Solutions:
(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [abs(a[i] - b[i]) for i in range(n)]
k = k1 + k2
for _ in range(k):
	mx = max(d)
	id = d.index(mx)
	if mx == 0:
		d[id] += 1
	else:
		d[id] -= 1
print(sum([x ** 2 for x in d]))


from math import *
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = 0
c = []
s = k1 + k2
for i in range(n):
	c.append((a[i] - b[i]) * (a[i] - b[i]))
m = sum(c)
while s:
	s -= 1
	ma = c.index(max(c))
	c[ma] = (sqrt(c[ma]) - 1) * (sqrt(c[ma]) - 1)
print(int(sum(c)))


import os
import sys
from io import BytesIO, IOBase
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 inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

class MaxHeapTransform(int):

	def __lt__(self, other):
		return self >= other
from heapq import *

def main():
	(n, k1, k2) = mpint()
	aa = list(mpint())
	bb = list(mpint())
	hp = [(MaxHeapTransform(abs(aa[i] - bb[i])), i) for i in range(n)]
	heapify(hp)
	for _ in range(k1):
		mx = heappop(hp)
		(num, i) = mx
		num = MaxHeapTransform(abs(num - 1))
		if aa[i] < bb[i]:
			aa[i] += 1
		else:
			aa[i] -= 1
		heappush(hp, (num, i))
	hp = [(MaxHeapTransform(abs(aa[i] - bb[i])), i) for i in range(n)]
	heapify(hp)
	for _ in range(k2):
		mx = heappop(hp)
		(num, i) = mx
		num = MaxHeapTransform(abs(num - 1))
		if bb[i] < aa[i]:
			bb[i] += 1
		else:
			bb[i] -= 1
		heappush(hp, (num, i))
	print(sum(((a - b) ** 2 for (a, b) in zip(aa, bb))))
DEBUG = 0
URL = ''
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 3:
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG:
		_print = print

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


import heapq
[n, k1, k2] = [int(x) for x in input().split(' ')]
A = input().split(' ')
B = input().split(' ')
error = 0
diff = [0] * n
for i in range(n):
	a = int(A[i])
	b = int(B[i])
	diff[i] = -1 * abs(a - b)
heapq.heapify(diff)
k = k1 + k2
error = 0
for i in range(k):
	tmp = heapq.heappop(diff)
	if tmp == 0 and i != k - 1:
		error = 0 if (k - i) % 2 == 0 else 1
		break
	heapq.heappush(diff, tmp + 1)
for i in diff:
	error = error + i * i
print(error)


[n, k1, k2] = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0 for i in range(n)]
for i in range(n):
	c[i] = a[i] - b[i] if a[i] > b[i] else b[i] - a[i]
c.sort(reverse=True)
k = k1 + k2
while k > 0:
	i = 0
	while i != n - 1 and c[i] <= c[i + 1]:
		i += 1
	c[i] = abs(c[i] - 1)
	k -= 1
result = 0
for x in c:
	result += x * x
print(result)


import sys
input = sys.stdin.buffer.readline

def solution():
	(n, x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		z = abs(a[i] - b[i])
		c.append(z)
	i = 0
	z = x + y
	for i in range(z):
		c.sort(reverse=True)
		c[0] = abs(c[0] - 1)
	for i in range(n):
		c[i] *= c[i]
	print(sum(c))
solution()


import heapq
(n, k, k1) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [-1 * abs(a[i] - b[i]) for i in range(n)]
c.sort(reverse=True)
heapq.heapify(c)
k += k1
while k > 0:
	e = heapq.heappop(c)
	if e == 0:
		heapq.heappush(c, e)
		break
	heapq.heappush(c, e + 1)
	k -= 1
s = 0
for j in range(len(c)):
	s += c[j] * c[j]
	c[j] *= -1
ce = k % 2
ad = ce * 2 * min(c) + ce
print(s + ad)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = k1 + k2
c = list()
for i in range(n):
	c.append(abs(a[i] - b[i]))
c.sort()
for i in range(n - 1, 0, -1):
	if c[i] == c[i - 1]:
		continue
	if (n - i) * (c[i] - c[i - 1]) <= k:
		k = k - (n - i) * (c[i] - c[i - 1])
		for j in range(i, n):
			c[j] = c[i - 1]
	else:
		while k > 0:
			for j in range(n - 1, i - 1, -1):
				c[j] = c[j] - 1
				k = k - 1
				if k == 0:
					break
while k > 0 and c[0] > 0:
	for i in range(n):
		c[i] = c[i] - 1
		k = k - 1
		if k == 0:
			break
if k > 0:
	if k & 1:
		sum = 1
	else:
		sum = 0
else:
	sum = 0
	for i in range(n):
		sum = sum + c[i] * c[i]
print(sum)


(n, k1, k2) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [-abs(x - y) for (x, y) in zip(a, b)]
k = k1 + k2
import heapq as hq
hq.heapify(d)
chained = 1
ans = -1
while len(d) > 0:
	curr = -hq.heappop(d)
	next = -d[0] if len(d) > 0 else 0
	if k >= (curr - next) * chained:
		k -= (curr - next) * chained
		chained += 1
		continue
	(dd, m) = (k // chained, k % chained)
	ans = (curr - dd - 1) ** 2 * m + (curr - dd) ** 2 * (chained - m)
	for x in d:
		ans += x ** 2
	break
else:
	ans = k % 2
print(ans)


from math import *
import sys
import random
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
k = k2 + k1
for i in range(n):
	arr.append((a[i] - b[i]) * (a[i] - b[i]))
while k:
	maxi = arr.index(max(arr))
	arr[maxi] = (sqrt(arr[maxi]) - 1) * (sqrt(arr[maxi]) - 1)
	k -= 1
print(int(sum(arr)))


from math import *
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = []
for i in range(n):
	dif.append(abs(a[i] - b[i]))
tot = k1 + k2
dif.sort(reverse=True)
while tot > 0 and dif[0] > 0:
	dif[0] -= 1
	tot -= 1
	dif.sort(reverse=True)
ans = tot % 2
for i in range(n):
	ans += dif[i] ** 2
print(ans)


from sys import stdin, stdout
from itertools import *
inp = lambda : (int(i) for i in stdin.readline().split())
(n, k1, k2) = inp()
a = [abs(x - y) for (x, y) in zip(list(inp()), list(inp()))]
for i in range(k1 + k2):
	id = a.index(max(a))
	a[id] = abs(a[id] - 1)
stdout.write(str(sum((i ** 2 for i in a))))


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = {}
for i in range(n):
	r[i] = (a[i] - b[i]) ** 2
for i in range(k1):
	q = max(r, key=r.get)
	a[q] = a[q] - 1 if a[q] > b[q] else a[q] + 1
	r[q] = (a[q] - b[q]) ** 2
for i in range(k2):
	q = max(r, key=r.get)
	b[q] = b[q] - 1 if b[q] > a[q] else b[q] + 1
	r[q] = (a[q] - b[q]) ** 2
r = 0
for i in range(n):
	r += (a[i] - b[i]) ** 2
print(r)


(n, k, l) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
lst = [abs(x - y) for (x, y) in zip(a, b)]
for _ in range(k + l):
	lst.sort()
	lst[-1] = abs(lst[-1] - 1)
print(sum((elem * elem for elem in lst)))


R = lambda : map(int, input().split())
(n, k, l) = R()
a = [abs(x - y) for (x, y) in zip(R(), R())]
for _ in range(k + l):
	a.sort()
	a[-1] = abs(a[-1] - 1)
print(sum((i * i for i in a)))


(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [abs(a[i] - b[i]) for i in range(n)]
d = sorted(d)[::-1]
k = k1 + k2
while k > 0:
	if d[0] == 0:
		break
	if k > 0:
		d[0] -= 1
		k -= 1
		d = sorted(d)[::-1]
print(sum([i ** 2 for i in d]) + k % 2)


(N, K1, K2) = map(int, input().split())
(A, B) = ([*map(int, input().split())], [*map(int, input().split())])
for i in range(K1):
	(max_pos, max_diff) = (-1, 0)
	for j in range(N):
		if abs(A[j] - B[j]) >= max_diff:
			(max_pos, max_diff) = (j, abs(A[j] - B[j]))
	if A[max_pos] >= B[max_pos]:
		A[max_pos] -= 1
	else:
		A[max_pos] += 1
for i in range(K2):
	(max_pos, max_diff) = (-1, 0)
	for j in range(N):
		if abs(A[j] - B[j]) >= max_diff:
			(max_pos, max_diff) = (j, abs(A[j] - B[j]))
	if B[max_pos] >= A[max_pos]:
		B[max_pos] -= 1
	else:
		B[max_pos] += 1
ans = 0
for i in range(N):
	ans += (A[i] - B[i]) ** 2
print(ans)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(-abs(a[i] - b[i]))
from heapq import heapify, heappush as pu, heappop as po
heapify(c)
for i in range(k1 + k2):
	x = po(c)
	if x >= 0:
		pu(c, x - 1)
	else:
		pu(c, x + 1)
ans = 0
for i in c:
	ans += i * i
print(ans)


(n, k1, k2) = [int(x) for x in input().split()]
arrA = [int(x) for x in input().split()]
arrB = [int(x) for x in input().split()]
diffs = [abs(a - b) for (a, b) in zip(arrA, arrB)]
for i in range(k1 + k2):
	diffs = sorted(diffs)
	diffs[-1] = abs(diffs[-1] - 1)
print(sum([a * a for a in diffs]))


(n, k1, k2) = map(int, input().split())
line1 = [int(x) for x in input().split()]
line2 = [int(x) for x in input().split()]
k = k1 + k2
line = []
for i in range(n):
	line.append(abs(line1[i] - line2[i]))
s = sum(line)
if k > s:
	if (k - s) % 2 == 0:
		print(0)
	else:
		print(1)
else:
	line.sort(reverse=True)
	m = line[0]
	while k >= 1:
		for i in range(n):
			if line[i] == m:
				line[i] -= 1
				k -= 1
				if k == 0:
					break
			else:
				break
		m -= 1
	print(sum(map(lambda x: x * x, line)))


def solve(k1, k2, a, b):
	d = [abs(i - j) for (i, j) in zip(a, b)]
	e = sum(d)
	ops = k1 + k2
	diff = e - ops
	if diff <= 0:
		return abs(diff) % 2
	d.sort(reverse=True)
	while ops > 0:
		maxx = d[0]
		for i in range(len(d)):
			if d[i] == maxx:
				d[i] -= 1
				ops -= 1
			if ops == 0:
				break
	return sum((x ** 2 for x in d))
(_, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(k1, k2, a, b))


firstLine = input().strip().split(' ')
n = int(firstLine[0])
k1 = int(firstLine[1])
k2 = int(firstLine[2])
A = list(map(int, input().strip().split(' ')))
B = list(map(int, input().strip().split(' ')))

def findErrorInRankingTable():
	error = 0
	for item in rankingTable:
		error += item[3]
	return error
rankingTable = []
for i in range(n):
	difference = A[i] - B[i]
	rankingTable.append([i, A[i], B[i], difference ** 2])
rankingTable.sort(key=lambda item: item[3])
for i in range(k1):
	if rankingTable[n - 1][1] < rankingTable[n - 1][2]:
		rankingTable[n - 1][1] += 1
	else:
		rankingTable[n - 1][1] -= 1
	rankingTable[n - 1][3] = (rankingTable[n - 1][1] - rankingTable[n - 1][2]) ** 2
	rankingTable.sort(key=lambda item: item[3])
for i in range(k2):
	if rankingTable[n - 1][2] < rankingTable[n - 1][1]:
		rankingTable[n - 1][2] += 1
	else:
		rankingTable[n - 1][2] -= 1
	rankingTable[n - 1][3] = (rankingTable[n - 1][1] - rankingTable[n - 1][2]) ** 2
	rankingTable.sort(key=lambda item: item[3])
print(findErrorInRankingTable())


(n, k1, k2) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = sorted([abs(a[i] - b[i]) for i in range(n)])[::-1]
k = k1 + k2
cur = 0
for i in range(k):
	if c[0] == 0:
		break
	cur += 1
	c[0] -= 1
	j = 0
	while j + 1 < n and c[j] < c[j + 1]:
		(c[j], c[j + 1]) = (c[j + 1], c[j])
		j += 1
k -= cur
if k > 0:
	print(k % 2)
else:
	ans = 0
	for i in c:
		ans += i ** 2
	print(ans)


from collections import defaultdict as dd, deque
(n, k1, k2) = map(int, input().split())
k = k1 + k2
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
D = dd(int)
for i in range(n):
	D[abs(A[i] - B[i])] += 1
x = sorted([[k, v] for (k, v) in D.items()], reverse=True)
ops = 0
i = 0
while x[i][0] > 0:
	if i < len(x) - 1:
		if x[i][0] == x[i + 1][0]:
			x[i + 1][1] += x[i][1]
			x[i][1] = 0
			i += 1
	(diff, cnt) = x[i]
	if k - ops >= cnt:
		x[i][0] -= 1
		ops += cnt
	else:
		x.append((diff - 1, k - ops))
		x[i][1] -= k - ops
		ops += k - ops
		break
if ops != k:
	print(1 if (k - ops) % 2 else 0)
else:
	ans = 0
	for (diff, cnt) in x:
		ans += cnt * diff ** 2
	print(ans)


(n, k1, k2) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
a = []
k = 0
for i in range(n):
	a.append(abs(arr1[i] - arr2[i]))
	k += a[i]
if k <= k1 + k2:
	print((k - k1 - k2) % 2)
else:
	for j in range(k1 + k2):
		m = 0
		for x in range(n):
			if a[x] > m:
				i = x
				m = a[x]
		a[i] -= 1
	ans = 0
	for i in range(n):
		ans += a[i] * a[i]
	print(ans)


from math import fabs
from collections import deque
(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
raz = [fabs(i - j) for (i, j) in zip(A, B)]
raz.sort(reverse=True)
raz_raz = deque()
for i in range(n - 1):
	raz_raz.append(raz[i] - raz[i + 1])
raz_raz.append(0)
K = k1 + k2
S = sum(raz)
if S <= K:
	if (K - S) % 2 == 0:
		print(0)
	else:
		print(1)
else:
	R = 0
	for i in range(n):
		if raz_raz[i] != 0:
			if K >= raz_raz[i] * (i + 1):
				K -= raz_raz[i] * (i + 1)
				for j in range(i + 1):
					raz[j] -= raz_raz[i]
			else:
				krug = K // (i + 1)
				ost = K % (i + 1)
				for j in range(i + 1):
					if j + 1 <= ost:
						raz[j] -= krug + 1
					else:
						raz[j] -= krug
				break
		elif i == n - 1:
			krug = K // (i + 1)
			ost = K % (i + 1)
			for j in range(i + 1):
				if j + 1 <= ost:
					raz[j] -= krug + 1
				else:
					raz[j] -= krug
	print(int(sum((n ** 2 for n in raz))))


import sys
import heapq
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(1):
	(n, k1, k2) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [-abs(a[i] - b[i]) for i in range(n)]
	heapq.heapify(c)
	k = k1 + k2
	while k != 0:
		pp = heapq.heappop(c)
		if pp < 0:
			heapq.heappush(c, pp + 1)
		else:
			heapq.heappush(c, pp - 1)
		k -= 1
	ans = 0
	for i in c:
		ans += i ** 2
	print(ans)


from collections import *
from functools import reduce
import sys
input = sys.stdin.readline

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

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input())
(n, k1, k2) = li()
a = li()
b = li()
l = []
for i in range(n):
	l.append(abs(a[i] - b[i]))
l.sort(reverse=1)
l += [0]
k = k1 + k2
i = 0
cou = 1
while k:
	if i == n:
		break
	if (l[i] - l[i + 1]) * cou <= k:
		k -= (l[i] - l[i + 1]) * cou
		l[i] = l[i + 1]
		for j in range(i):
			l[j] = l[i + 1]
	else:
		temp = k // cou
		l[i] -= temp
		k -= temp * cou
		for j in range(i):
			l[j] = l[i]
		for j in range(k):
			l[j] = l[i] - 1
		l = sorted(l[:-1])
		k = 0
		break
	cou += 1
	i += 1
if k & 1:
	l[0] = 1
print(sum((i ** 2 for i in l)))


def minimo_error(n, movimientosA, movimientosB, A, B):
	distancias = []
	for pos in range(n):
		distancias.append(abs(A[pos] - B[pos]))
	while movimientosA > 0 or movimientosB > 0:
		pos_max_dist = distancias.index(max(distancias))
		A_max = A[pos_max_dist]
		B_max = B[pos_max_dist]
		if abs(A_max) >= abs(B_max):
			if movimientosA > 0:
				if A_max > 0:
					A_max -= 1
				else:
					A_max += 1
				A[pos_max_dist] = A_max
				movimientosA -= 1
			else:
				if A_max > 0:
					B_max += 1
				else:
					B_max -= 1
				B[pos_max_dist] = B_max
				movimientosB -= 1
			distancias[pos_max_dist] = abs(A_max - B_max)
			continue
		elif abs(B_max) >= abs(A_max):
			if movimientosB > 0:
				if B_max > 0:
					B_max -= 1
				else:
					B_max += 1
				B[pos_max_dist] = B_max
				movimientosB -= 1
			else:
				if B_max > 0:
					A_max += 1
				else:
					A_max -= 1
				A[pos_max_dist] = A_max
				movimientosA -= 1
			distancias[pos_max_dist] = abs(A_max - B_max)
	error = 0
	for pos in range(n):
		error += (A[pos] - B[pos]) ** 2
	return error
datos_matrices = list(map(lambda x: int(x), input().split(' ')))
A = list(map(lambda x: int(x), input().split(' ')))
B = list(map(lambda x: int(x), input().split(' ')))
print(minimo_error(*datos_matrices, A, B))


(n, k1, k2) = input().split()
a1 = input().split()
a2 = input().split()
res = []
for i in range(len(a1)):
	res.append(int(a1[i]) - int(a2[i]))
res = [abs(i) for i in res]
k = int(k1) + int(k2)
k = int(k)
n = int(n)
if sum(res) < int(k):
	if (k - sum(res)) % 2:
		print('1')
	else:
		print('0')
elif sum(res) == k:
	print('0')
else:
	while k:
		res.sort()
		res[-1] = res[-1] - 1
		k -= 1
	result = 0
	for i in res:
		result += i ** 2
	print(result)


(n, ak, bk) = map(int, input().split())
k = ak + bk
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = abs(a[i] - b[i])
c.sort()
x = 0
coo = 0
for i in range(k):
	c.sort()
	if c[n - 1] == 0:
		coo += 1
	c[n - 1] = max(0, c[n - 1] - 1)
count = 0
for i in range(n):
	count += c[i] ** 2
print(count + coo % 2)


import heapq
(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(-1 * abs(a[i] - b[i]))
heapq.heapify(c)
e = 1
for i in range(k1 + k2):
	if c[0] < 0:
		heapq.heapreplace(c, c[0] + 1)
		e = 1
	elif c[0] == 0:
		print((k1 + k2 - i) % 2)
		e = 0
		break
if e == 1:
	s = 0
	for i in range(n):
		s = s + c[i] ** 2
	print(s)


(n, k1, k2) = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
cola_prioridad = []
i = 0
while i < n:
	cola_prioridad.append(((A[i] - B[i]) * (A[i] - B[i]), i))
	i += 1
cola_prioridad.sort()
for x in range(0, k1):
	(maxE, i) = cola_prioridad[n - 1]
	if A[i] > B[i]:
		A[i] -= 1
	else:
		A[i] += 1
	cola_prioridad[n - 1] = ((A[i] - B[i]) * (A[i] - B[i]), i)
	cola_prioridad.sort()
for x in range(0, k2):
	(maxE, i) = cola_prioridad[n - 1]
	if B[i] > A[i]:
		B[i] -= 1
	else:
		B[i] += 1
	cola_prioridad[n - 1] = ((A[i] - B[i]) * (A[i] - B[i]), i)
	cola_prioridad.sort()
sumaFinal = 0
for x in cola_prioridad:
	sumaFinal += x[0]
print(sumaFinal)


def heapify(a, i):
	left = 2 * i + 1
	right = 2 * i + 2
	largest = i
	if left < len(a) and a[left] > a[largest]:
		largest = left
	if right < len(a) and a[right] > a[largest]:
		largest = right
	if largest != i:
		(a[largest], a[i]) = (a[i], a[largest])
		heapify(a, largest)

def build_heap(a):
	heap = a[:]
	for i in range(len(a) // 2)[::-1]:
		heapify(heap, i)
	return heap

def decrease_root(a, value):
	a[0] = abs(abs(a[0]) - value)
	heapify(a, 0)
(n, k1, k2) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
delta_heap = build_heap([abs(a[i] - b[i]) for i in range(len(a))])
k = k1 + k2
while k > 0:
	decrease_root(delta_heap, 1)
	k -= 1
print(sum([delta_heap[i] ** 2 for i in range(len(delta_heap))]))


from heapq import heappush, heappop
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pq = []
for i in range(n):
	heappush(pq, -abs(a[i] - b[i]))
k = k1 + k2
while k:
	old_error = heappop(pq)
	if old_error == 0:
		pq.append(k % 2)
		break
	heappush(pq, old_error + 1)
	k -= 1
error = sum([e ** 2 for e in pq])
print(error)


(n, k1, k2) = map(int, input().split())
s = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	s.append(abs(a[i] - b[i]))
for i in range(k1 + k2):
	ma = s[0]
	ind = 0
	for j in range(n):
		if s[j] > ma:
			ma = s[j]
			ind = j
	if ma == 0:
		s[ind] = 1
	else:
		s[ind] -= 1
t = 0
for i in s:
	t += i ** 2
print(t)


(n, k1, k2) = map(int, input().split())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
gap = [abs(a1[i] - a2[i]) for i in range(n)]
for k in range(k1 + k2):
	gap[gap.index(max(gap))] = abs(max(gap) - 1)
print(sum((i * i for i in gap)))


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
	c[i] = abs(a[i] - b[i])
c = sorted(c, reverse=True)
k = k1 + k2
while k > 0:
	c[0] -= 1
	if c[0] < 0:
		c[0] = 1
	if n != 1 and c[0] < c[1]:
		c = sorted(c, reverse=True)
	k -= 1
d = [i * i for i in c]
print(sum(d))


[n, k1, k2] = [int(x) for x in input().split()]
k = k1 + k2
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
error = [abs(x[0] - x[1]) for x in zip(a, b)]
error = sorted(error, reverse=True)
if k >= sum(error):
	print((k - sum(error)) % 2)
	exit()
index = 0
while k != 0:
	error[index] -= 1
	if index + 1 == n:
		index = 0
	elif error[index] + 1 == error[index + 1]:
		index += 1
	else:
		index = 0
	k -= 1
print(sum([x * x for x in error]))


(n, k1, k2) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
l = []
k = k1 + k2
s = 0
c = 0
ans = 0
for i in range(0, n):
	s += abs(a[i] - b[i])
	l.append(abs(a[i] - b[i]))
if s <= k:
	if (k - s) % 2 == 0:
		ans = 0
	else:
		ans = 1
else:
	l.sort()
	l.reverse()
	l += [0]
	i = 0
	while c < k:
		if l[i] == l[i + 1]:
			i += 1
		for j in range(0, i + 1):
			if c < k and l[j] != l[i + 1]:
				l[j] -= 1
				c += 1
	for i in range(0, n):
		ans += l[i] * l[i]
print(ans)


import operator
(n, k1, k2) = map(int, input().split(' '))
arrayA = list(map(int, input().split(' ')))
arrayB = list(map(int, input().split(' ')))
arraydiff = list(map(operator.sub, arrayA, arrayB))
arraydiff = list(map(abs, arraydiff))
for i in range(k1 + k2):
	index = arraydiff.index(max(arraydiff))
	if arraydiff[index] == 0:
		arraydiff[index] += 1
	else:
		arraydiff[index] -= 1
print(sum(map(lambda x: x * x, arraydiff)))


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = []
for i in range(n):
	arr.append(abs(a[i] - b[i]))
arr = sorted(arr, reverse=True)
for i in range(k1 + k2):
	arr[0] = abs(arr[0] - 1)
	j = 0
	while j < n - 1 and arr[j] < arr[j + 1]:
		(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
		j += 1
ans = 0
for i in range(n):
	ans = ans + arr[i] * arr[i]
print(ans)


R = lambda : map(int, input().split())
(n, k, l) = R()
a = list(R())
b = list(R())
k += l
e = [abs(a[i] - b[i]) for i in range(n)]
for i in range(k):
	e.sort()
	e[-1] = abs(e[-1] - 1)
print(sum([x * x for x in e]))


p = lambda : map(int, input().split())
(n, k, l) = p()
a = [abs(x - y) for (x, y) in zip(list(p()), list(p()))]
for _ in range(k + l):
	d = a.index(max(a))
	a[d] = abs(a[d] - 1)
print(sum((i * i for i in a)))


(lenght, a, b) = map(int, input().split())
masa = list(map(int, input().split()))
masb = list(map(int, input().split()))
masc = list((abs(masa[i] - masb[i]) for i in range(lenght) if abs(masa[i] - masb[i]) != 0))
moves = a + b
while moves > 0:
	if not masc:
		break
	masc.sort()
	masc[~0] -= 1
	if masc[~0] == 0:
		masc.remove(0)
	moves -= 1
print(sum((i ** 2 for i in masc)) if masc else moves % 2)


(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
r = sorted([abs(a[i] - b[i]) for i in range(n)], reverse=True)
for it in range(k1 + k2):
	if r[0] == 0:
		r[0] = 1
	else:
		r[0] -= 1
		for i in range(n - 1):
			if r[i] < r[i + 1]:
				(r[i], r[i + 1]) = (r[i + 1], r[i])
print(sum((x ** 2 for x in r)))


(n, k1, k2) = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
C = [x - y for (x, y) in zip(B, A)]
k = k1 + k2
for i in range(k):
	if min(C) >= 0:
		C[C.index(max(C))] -= 1
	elif abs(max(C)) <= abs(min(C)):
		C[C.index(min(C))] += 1
	else:
		C[C.index(max(C))] -= 1
ans = 0
for i in C:
	ans += i ** 2
print(ans)


import sys
[n, k1, k2] = map(int, sys.stdin.readline().strip().split())
ais = list(map(int, sys.stdin.readline().strip().split()))
bis = list(map(int, sys.stdin.readline().strip().split()))
k = k1 + k2
cis = [abs(ai - bi) for (ai, bi) in zip(ais, bis)]
cis.sort(reverse=True)
cis.append(0)
s = 0
i = 1
done = False
while i < n + 1:
	s += i * (cis[i - 1] - cis[i])
	if s >= k:
		done = True
		break
	i += 1
if not done:
	if (k - s) % 2 == 0:
		print(0)
	else:
		print(1)
else:
	d = s - k
	h = d // i
	n1 = d % i
	n0 = i - n1
	print(sum((ci ** 2 for ci in cis[i:])) + n0 * (cis[i] + h) ** 2 + n1 * (cis[i] + h + 1) ** 2)


import heapq
(n, k1, k2) = map(int, input().split())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
dis = []
for i in range(n):
	dis.append(0 - abs(list1[i] - list2[i]))
heapq.heapify(dis)
num = k1 + k2
while num > 0:
	tmp = heapq.heappop(dis)
	if tmp == 0:
		break
	tmp += 1
	heapq.heappush(dis, tmp)
	num -= 1
if num > 0:
	if num % 2 == 1:
		print(1)
	else:
		print(0)
else:
	num = 0
	for i in dis:
		num += i ** 2
	print(num)


(z, zz, dgraphs, mod) = (input, lambda : list(map(int, z().split())), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, a, b) = zz()
l1 = zz()
l2 = zz()
ans = []
for (i, j) in zip(l1, l2):
	ans.append(abs(i - j))
t = 0
for _ in range(a + b):
	ind = ans.index(max(ans))
	ans[ind] = abs(ans[ind] - 1)
print(sum((i * i for i in ans)))


from bisect import *
(n, k, k1) = map(int, input().split())
l = list(map(int, input().split()))
arr = [abs(int(i) - k) for (i, k) in zip(input().split(), l)]
arr.sort()
k = k + k1
while k > 0:
	x = arr[-1]
	del arr[-1]
	insort(arr, abs(x - 1))
	k -= 1
ans = 0
for i in arr:
	ans += i * i
print(ans)


(n, a, b) = map(int, input().split())
w = a + b
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
L = []
for i in range(n):
	L.append([abs(l[i] - l1[i]), i])
for i in range(w):
	q = max(L, key=lambda x: x[0])
	if q[0] == 0:
		if (w - i) % 2 == 0:
			print(0)
		else:
			print(1)
		exit()
	L[q[1]] = [q[0] - 1, q[1]]
ans = 0
for i in range(n):
	ans += L[i][0] * L[i][0]
print(ans)


def error(lista):
	error = 0
	for element in lista:
		error += element ** 2
	return error

def ordenar(tupla):
	return abs(tupla[1] - tupla[0])

def obtener(lista):
	maximo = 0
	for elem in lista:
		if elem > maximo:
			maximo = elem
	return elem
(n, k1, k2) = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
C = list()
for i in range(n):
	C.append(abs(A[i] - B[i]))
op = k1 + k2
result = list()
C.sort()
mm = True
while op > 0:
	if error(C) == 0:
		if op % 2 == 0:
			print(0)
			mm = False
			break
		else:
			print(1)
			mm = False
			break
	else:
		valor = C.pop()
		valor -= 1
		C.append(valor)
		op -= 1
		C.sort()
if mm:
	print(error(C))


from math import *
(n, k, k1) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
m = 0
d = []
s = k1 + k
for i in range(n):
	d.append((A[i] - B[i]) ** 2)
m = sum(d)
while s:
	s -= 1
	ind = d.index(max(d))
	d[ind] = (sqrt(d[ind]) - 1) ** 2
print(int(sum(d)))


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:n]
c = [abs(a[i] - b[i]) for i in range(n)]
ans = 0
for i in range(k1 + k2):
	c.sort(reverse=True)
	c[0] -= 1
	c[0] = abs(c[0])
for i in c:
	ans += i * i
print(ans)


import os
import sys
import math
import heapq
from io import BytesIO, IOBase
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')
(n, k1, k2) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
k = k1 + k2
E = []
i = 0
while i < n:
	E.append(-1 * abs(a[i] - b[i]))
	i += 1
heapq.heapify(E)
while k > 0:
	if E[0] == 0:
		break
	elif E[0] < 0:
		heapq.heapreplace(E, E[0] + 1)
		k -= 1
sum = 0
i = 0
while i < n:
	sum = sum + E[i] ** 2
	i += 1
sum = sum + max(k, 0) % 2
print(sum)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(abs(a[i] - b[i]))
for i in range(k1 + k2):
	k = -1
	max1 = 0
	for j in range(n):
		if c[j] > max1:
			max1 = c[j]
			k = j
	c[k] = abs(c[k] - 1)
sumx = 0
for i in range(n):
	sumx += c[i] ** 2
print(sumx)


(n, k1, k2) = map(int, input().split())
l = []
k = k1 + k2
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	l.append(abs(a[i] - b[i]))
ans = 0
for i in range(k):
	l.sort()
	if l[-1] > 0:
		l[-1] -= 1
	else:
		l[-1] += 1
for i in l:
	ans += i ** 2
print(ans)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
e = []
for (ai, bi) in zip(a, b):
	e.append(pow(ai - bi, 2))
for i in range(k1):
	pos = e.index(max(e))
	if a[pos] <= b[pos]:
		a[pos] += 1
	else:
		a[pos] -= 1
	e[pos] = pow(a[pos] - b[pos], 2)
for i in range(k2):
	pos = e.index(max(e))
	if b[pos] <= a[pos]:
		b[pos] += 1
	else:
		b[pos] -= 1
	e[pos] = pow(a[pos] - b[pos], 2)
print(sum(e))


from sys import stdin, stdout
from itertools import *
inp = lambda : (int(i) for i in stdin.readline().split())
(n, k1, k2) = inp()
a = list(inp())
b = list(inp())
for i in range(n):
	a[i] = abs(a[i] - b[i])
for i in range(k1 + k2):
	c = a.index(max(a))
	a[c] = abs(a[c] - 1)
su = 0
for i in a:
	su += i * i
print(su)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [abs(a[i] - b[i]) for i in range(n)]
k = k1 + k2
while k > 0:
	c.sort()
	c[-1] = abs(c[-1] - 1)
	k -= 1
print(sum((i ** 2 for i in c)))


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [abs(x - y) for (x, y) in zip(a, b)]
ans.sort()
for i in range(k1 + k2):
	ans[-1] = abs(ans[-1] - 1)
	j = -1
	while j > -n and ans[j] < ans[j - 1]:
		(ans[j], ans[j - 1]) = (ans[j - 1], ans[j])
		j -= 1
ans = sum(map(lambda x: x * x, ans))
print(ans)


(n, k1, k2) = list(map(int, input().split()))
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
ci = [0] * n
k = k1 + k2
for i in range(n):
	ci[i] = abs(ai[i] - bi[i])
ci.sort()
ci2 = [0] * n
ci3 = [0] * n
ci2[0] = ci[0]
ci3[0] = 1
j = 0
for i in range(1, n):
	if ci[i] == ci[i - 1]:
		ci3[j] += 1
	else:
		j += 1
		ci2[j] = ci[i]
		ci3[j] = 1
temp2 = -1
temp3 = 0
for i in range(j, 0, -1):
	if k >= ci3[i] * (ci2[i] - ci2[i - 1]):
		k -= ci3[i] * (ci2[i] - ci2[i - 1])
		ci3[i - 1] += ci3[i]
		ci3[i] = 0
	else:
		temp = k // ci3[i]
		temp2 = k % ci3[i]
		temp3 = i
		ci2[i] -= temp
		break
if temp2 != -1:
	ans = 0
	for i in range(temp3):
		ans += ci3[i] * ci2[i] ** 2
	print(ans + (ci3[temp3] - temp2) * ci2[temp3] ** 2 + temp2 * (ci2[temp3] - 1) ** 2)
elif k >= ci3[0] * ci2[0]:
	k -= ci3[0] * ci2[0]
	print(k % 2)
else:
	temp = k // ci3[0]
	temp2 = k % ci3[0]
	print((ci3[0] - temp2) * (ci2[0] - temp) ** 2 + temp2 * (ci2[0] - temp - 1) ** 2)


from sys import stdin, exit
from typing import List, Tuple

def flaten(arr: List[int], by: int):
	pass
(_, k1, k2) = [int(v) for v in stdin.readline().rstrip().split()]
A = [int(v) for v in stdin.readline().rstrip().split()]
B = [int(v) for v in stdin.readline().rstrip().split()]
for i in range(len(A)):
	A[i] -= B[i]
A.sort(key=lambda x: abs(x), reverse=True)
last_value_index = []
last = abs(A[0])
for i in range(len(A)):
	A[i] = abs(A[i])
	if A[i] != last:
		last_value_index.append((i - 1, A[i]))
		last = A[i]
moves = k1 + k2
changes = [0] * len(A)
levels_reduced = 0
if len(last_value_index) > 0:
	while moves > 0 and A[0] != 0:
		left_edge = max(last_value_index[levels_reduced][0] - moves, -1)
		for i in range(last_value_index[levels_reduced][0], left_edge, -1):
			A[i] -= 1
			moves -= 1
			if moves == 0:
				break
		if last_value_index[levels_reduced][1] == A[0]:
			levels_reduced += 1
			if levels_reduced >= len(last_value_index):
				break
if levels_reduced >= len(last_value_index):
	i = 0
	while moves > 0 and A[-1] != 0:
		A[i] -= 1
		moves -= 1
		i = (i + 1) % len(A)
if moves > 0 and A[0] == 0:
	print(moves % 2)
	exit(0)
E = 0
for i in A:
	E += i ** 2
print(E)


from sys import setcheckinterval, stdin
setcheckinterval(1000)

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

def lin():
	return list(map(int, stdin.readline().split()))
import heapq as hq
(n, k1, k2) = lin()
a = lin()
b = lin()
ha = []
for i in range(n):
	ha.append([-(a[i] - b[i]) ** 2, i])
hq.heapify(ha)
while k1 or k2:
	(x, y) = hq.heappop(ha)
	if k1:
		if (a[y] + 1 - b[y]) ** 2 < -x:
			a[y] += 1
		else:
			a[y] -= 1
		k1 -= 1
	else:
		if (a[y] + 1 - b[y]) ** 2 < -x:
			b[y] -= 1
		else:
			b[y] += 1
		k2 -= 1
	hq.heappush(ha, [-(a[y] - b[y]) ** 2, y])
ans = 0
for (i, j) in ha:
	ans += -i
print(ans)


(a, b, c) = map(int, input().split())
k = b + c
x = list(map(int, input().split()))
y = list(map(int, input().split()))
i = 0
z = []
while i < len(x):
	z = z + [max(x[i], y[i]) - min(x[i], y[i])]
	i = i + 1
z.sort()
i = 0
while i < k:
	if z[len(z) - 1] != 0:
		z[len(z) - 1] = z[len(z) - 1] - 1
	else:
		if (k - i) % 2 == 1:
			z = [1]
		break
	z.sort()
	i = i + 1
s = 0
for elem in z:
	s = s + elem ** 2
print(s)


import heapq
(n, k1, k2) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
err = [abs(x - y) for (x, y) in zip(a, b)]
if k1 + k2 >= sum(err):
	print((k1 + k2 - sum(err)) % 2)
else:
	moves = k1 + k2
	err = [-a for a in err]
	heapq.heapify(err)
	while moves:
		x = heapq.heappop(err)
		x += 1
		heapq.heappush(err, x)
		moves -= 1
	print(sum([x ** 2 for x in err]))


(n, k1, k2) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = [abs(a[i] - b[i]) for i in range(n)]
for i in range(k1 + k2):
	x.sort(reverse=True)
	x[0] = abs(x[0] - 1)
z = 0
for i in x:
	z += i * i
print(z)


(n, k1, k2) = [int(elem) for elem in input().split(' ')]
list1 = [int(elem) for elem in input().split(' ')]
list2 = [int(elem) for elem in input().split(' ')]
lst = list1.copy()
for i in range(len(lst)):
	lst[i] = abs(list1[i] - list2[i])
k = k1 + k2
while k > 0:
	lst.sort(reverse=True)
	lst[0] = abs(lst[0] - 1)
	k -= 1
result = 0
for num in lst:
	result += num ** 2
print(result)


(n, k1, k2) = input().split()
a = input().split()
b = input().split()
c = [abs(int(a[i]) - int(b[i])) for i in range(int(n))]
for i in range(int(k1) + int(k2)):
	c.sort()
	c[int(n) - 1] = abs(c[int(n) - 1] - 1)
e = 0
for i in range(int(n)):
	e += c[i] ** 2
print(e)


(n, a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
S = [abs(A[i] - B[i]) for i in range(n)]
for i in range(a + b):
	S.sort()
	S[-1] = abs(S[-1] - 1)
x = [i * i for i in S]
print(sum(x))


from heapq import heappop, heapify, heappush
(n, c1, c2) = [int(n) for n in input().split()]
arr = [int(item) for item in input().split()]
brr = [int(item) for item in input().split()]
c = c1 + c2
crr = []
for i in range(n):
	crr.append(abs(arr[i] - brr[i]))
count = 0
for i in range(c):
	r = crr.index(max(crr))
	crr[r] = abs(crr[r] - 1)
for j in crr:
	count = count + j * j
print(count)


(n, k1, k2) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [abs(a[i] - b[i]) for i in range(n)]
for i in range(k1):
	ind = d.index(max(d))
	d[ind] = abs(d[ind] - 1)
for i in range(k2):
	ind = d.index(max(d))
	d[ind] = abs(d[ind] - 1)
s = 0
for i in range(n):
	s += d[i] ** 2
print(s)


import heapq
(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
h = []
heapq.heapify(h)
for i in range(n):
	heapq.heappush(h, -1 * (A[i] - B[i]) ** 2)
for _ in range(k1 + k2):
	t = (-1 * heapq.heappop(h)) ** (1 / 2)
	heapq.heappush(h, -1 * int((t - 1) ** 2))
ans = 0
while len(h) > 0:
	ans += -1 * int(heapq.heappop(h))
print(ans)


from operator import itemgetter

class CodeforcesTask960BSolution:

	def __init__(self):
		self.result = ''
		self.n_k_k = 0
		self.A = 0
		self.B = 0

	def read_input(self):
		self.n_k_k = [int(x) for x in input().split(' ')]
		self.A = [int(x) for x in input().split(' ')]
		self.B = [int(x) for x in input().split(' ')]

	def process_task(self):
		c = [abs(self.A[x] - self.B[x]) for x in range(self.n_k_k[0])]
		x = self.n_k_k[1] + self.n_k_k[2]
		c.sort(reverse=True)
		while x:
			if c[0] > 0:
				c[0] -= 1
			else:
				c[0] += 1
			c.sort(reverse=True)
			x -= 1
		self.result = str(sum([x ** 2 for x in c]))

	def get_result(self):
		return self.result
Solution = CodeforcesTask960BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import math
import random
mod = 1000000007
r1 = lambda : int(input())
rm = lambda : map(int, input().split())
rls = lambda : list(rm())

def maxi(ls):
	ans = 0
	ind = 0
	for i in range(len(ls)):
		if ls[i] > ans:
			ind = i
			ans = ls[i]
	return ind
(n, k1, k2) = rm()
ls1 = rls()
ls2 = rls()
ans = []
for i in range(n):
	ans.append(abs(ls1[i] - ls2[i]))
for i in range(k1 + k2):
	x = maxi(ans)
	ans[x] = abs(ans[x] - 1)
ret = 0
for i in ans:
	ret += i ** 2
print(ret)


import sys
input = sys.stdin.readline

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

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

def LI():
	return [*map(int, input().strip().split())]
import copy
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby, count, filterfalse
from operator import itemgetter
for _ in range(1):
	(n, k1, k2) = LI()
	l1 = LI()
	l2 = LI()
	lst = [abs(l1[i] - l2[i]) for i in range(n)]
	x = k1 + k2
	while x > 0:
		lst.sort()
		lst[-1] = abs(lst[-1] - 1)
		x = x - 1
	s = 0
	for i in range(n):
		s = s + lst[i] ** 2
	print(s)


str1 = input()
str2 = input()
str3 = input()
a1 = str1.split()
a2 = str2.split()
a3 = str3.split()
fr = [int(a3[i]) - int(a2[i]) for i in range(int(a1[0]))]
fr1 = [i * i for i in fr]

def dd(n1):
	pp = n1 ** (1 / 2)
	pp = pp - 1
	return pp ** 2
for i in range(int(a1[1]) + int(a1[2])):
	ap = fr1.index(max(fr1))
	fr1[ap] = dd(fr1[ap])
print(int(sum(fr1)))


import heapq
(n, k, l) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
diff = []
edit = k + l
for i in range(n):
	heapq.heappush(diff, -abs(a[i] - b[i]))
while edit > 0:
	m = heapq.heappop(diff)
	if m < 0:
		m += 1
	else:
		m -= 1
	edit -= 1
	heapq.heappush(diff, m)
result = 0
for i in diff:
	result += i * i
print(result)


import math
(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [int(math.fabs(A[i] - B[i])) for i in range(n)]
for _ in range(k1):
	i = C.index(max(C))
	if A[i] > B[i]:
		A[i] -= 1
		C[i] -= 1
	elif A[i] < B[i]:
		A[i] += 1
		C[i] -= 1
	else:
		A[i] += 1
		C[i] += 1
for _ in range(k2):
	i = C.index(max(C))
	if A[i] > B[i]:
		B[i] += 1
		C[i] -= 1
	elif A[i] < B[i]:
		B[i] -= 1
		C[i] -= 1
	else:
		B[i] += 1
		C[i] += 1
soma = 0
for i in range(n):
	soma += (A[i] - B[i]) ** 2
print(soma)


s = input().split()
(n, k1, k2) = (int(s[0]), int(s[1]), int(s[2]))
k = k1 + k2
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cl = []
for i in range(n):
	cl.append(abs(a[i] - b[i]))
for i in range(k):
	cl[cl.index(max(cl))] = abs(max(cl) - 1)
res = 0
for x in range(n):
	res += cl[x] ** 2
print(res)


(n, oa, ob) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = []
for (i, j) in zip(a, b):
	diff.append(abs(i - j))
k = oa + ob
while k > 0:
	diff.sort()
	if diff[len(diff) - 1] == 0:
		break
	diff[len(diff) - 1] = diff[len(diff) - 1] - 1
	k = k - 1
if k & 1 == 1:
	print(1)
else:
	ans = [i ** 2 for i in diff]
	print(sum(ans))


(n, k1, k2) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
left = 0
for it in range(k1 + k2):
	if a == b:
		left = k1 + k2 - it
		break
	(j, vl) = (-1, -1)
	for i in range(n):
		if abs(a[i] - b[i]) > vl:
			vl = abs(a[i] - b[i])
			j = i
	if a[j] > b[j]:
		a[j] -= 1
	elif a[j] < b[j]:
		a[j] += 1
sm = 0
for i in range(n):
	sm += (a[i] - b[i]) ** 2
sm += left % 2
print(sm)


def main():
	(n, k1, k2) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [abs(a[i] - b[i]) for i in range(n)]
	s = sum(c)
	if s >= k1 + k2:
		op = k1 + k2
		while op > 0:
			c = sorted(c)
			c[-1] -= 1
			op -= 1
		ans = sum([x ** 2 for x in c])
	else:
		after = k1 + k2 - s
		if after % 2 == 0:
			ans = 0
		else:
			ans = 1
	print(ans)

def __starting_point():
	main()
__starting_point()


import bisect
from itertools import accumulate, count
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
from sys import maxsize
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))

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

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return sorted(fac)

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
import heapq
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(0, len(a)):
	ans.append(abs(a[i] - b[i]))
op = k1 + k2
while op > 0:
	c = ans.index(max(ans))
	ans[c] = abs(ans[c] - 1)
	op -= 1
fans = 0
for i in range(0, len(ans)):
	fans += ans[i] ** 2
print(fans)


(n, k1, k2) = [int(x) for x in input().split()]
a = input().split()
b = input().split()
d = [abs(int(x) - int(y)) for (x, y) in zip(a, b)]
for i in range(k1 + k2):
	m = 0
	max_ind = 0
	for j in range(n):
		if d[j] >= m:
			m = d[j]
			max_ind = j
	d[max_ind] = abs(d[max_ind] - 1)
print(sum((x * x for x in d)))


(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def just_relax():
	global gruz
	mam = 0
	ind = -1
	for i in range(n):
		if abs(A[i] - B[i]) > mam:
			mam = abs(A[i] - B[i])
			ind = i
	if ind != -1:
		if A[ind] < B[ind]:
			A[ind] += 1
		else:
			A[ind] -= 1
	else:
		gruz = 1
gruz = 0
ans = 0
for iq in range(k1 + k2):
	just_relax()
	if gruz:
		if (k1 + k2 - iq) % 2 == 0:
			print(0)
		else:
			print(1)
		exit(0)
for i in range(n):
	ans += abs(A[i] - B[i]) ** 2
print(ans)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for i in range(n):
	c.append(abs(a[i] - b[i]))
k = k1 + k2
c.sort(reverse=True)
while k != 0:
	if c[0] == 0:
		break
	c[0] -= 1
	k -= 1
	c.sort(reverse=True)
if k != 0:
	if k % 2:
		ans = 1
	else:
		ans = 0
else:
	ans = 0
	for i in c:
		ans += i ** 2
print(ans)


inp = lambda : map(int, input().split())
(n, k1, k2) = inp()
a = [abs(x - y) for (x, y) in zip(list(inp()), list(inp()))]
for i in range(k1 + k2):
	id = a.index(max(a))
	a[id] = abs(a[id] - 1)
print(sum((i ** 2 for i in a)))


from heapq import *
R = lambda : list(map(int, input().split()))
(n, k1, k2) = R()
(a, b) = (R(), R())
h = []
for i in range(n):
	a[i] = abs(a[i] - b[i])
	heappush(h, -a[i])
k1 += k2
while k1 > 0:
	val = -heappop(h)
	heappush(h, -abs(val - 1))
	k1 -= 1
ans = 0
while h:
	val = heappop(h)
	ans += val * val
print(ans)


R = lambda : map(int, input().split())
(n, k1, k2) = R()
k = k1 + k2
A = list(R())
B = tuple(R())
for i in range(n):
	A[i] = abs(A[i] - B[i])
for _ in range(k):
	idx = A.index(max(A))
	A[idx] = abs(A[idx] - 1)
s = 0
for a in A:
	s += a * a
print(s)


import sys
(n, k1, k2) = map(int, input().split())
a = [int(i) for i in sys.stdin.readline().split()]
b = [int(i) for i in sys.stdin.readline().split()]
for i in range(n):
	a[i] = abs(a[i] - b[i])
for i in range(k1 + k2):
	c = a.index(max(a))
	a[c] = abs(a[c] - 1)
su = 0
for i in a:
	su += i * i
print(su)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = k1 + k2
d = [abs(a[i] - b[i]) for i in range(n)]
if sum(d) > k:
	for i in range(k):
		m = max(d)
		d.remove(m)
		d.append(m - 1)
	ans = sum((x ** 2 for x in d))
	print(ans)
else:
	print((k - sum(d)) % 2)


def decrease_max(C, D):
	mx = (-1, -1)
	for (i, e) in enumerate((abs(c - d) for (c, d) in zip(C, D))):
		if e > mx[1]:
			mx = (i, e)
	i = mx[0]
	if C[i] > D[i]:
		C[i] -= 1
	else:
		C[i] += 1

def solution(k1, k2, A, B):
	for _ in range(k1):
		decrease_max(A, B)
	for _ in range(k2):
		decrease_max(B, A)
	return sum(((a - b) ** 2 for (a, b) in zip(A, B)))
(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(solution(k1, k2, A, B), end='')


import operator
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = list(map(operator.sub, a, b))
diff = list(map(abs, diff))
n = len(diff) - 1
diff.sort()
op = k1 + k2
while op > 0:
	if diff[n] > 0:
		diff[n] -= 1
	else:
		diff[n] += 1
	if diff[n] < diff[n - 1]:
		diff.sort()
	op -= 1
error_sum = 0
for i in range(len(diff)):
	error_sum += diff[i] * diff[i]
print(error_sum)


(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Z = []
a = k1 + k2
for i in range(n):
	Z.append(abs(A[i] - B[i]))
Z.sort()
for i in range(a):
	Z[-1] = abs(Z[-1] - 1)
	Z.sort()
ans = 0
for i in range(n):
	ans += Z[i] * Z[i]
print(ans)


(n, k_1, k_2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
differences = sorted([abs(a_i - b_i) for (a_i, b_i) in zip(a, b) if a_i != b_i], reverse=True)
k = k_1 + k_2
while k > 0 and differences:
	differences[0] -= 1
	k -= 1
	if differences[0] == 0:
		del differences[0]
	for i in range(len(differences) - 1):
		if differences[i] <= differences[i + 1]:
			(differences[i], differences[i + 1]) = (differences[i + 1], differences[i])
if k == 0:
	print(sum([s ** 2 for s in differences]))
else:
	print(k % 2)


R = lambda : map(int, input().split())
(n, k1, k2) = R()
diff = [abs(x1 - x2) for (x1, x2) in zip(R(), R())]
for _ in range(k1 + k2):
	diff.sort()
	diff[-1] = abs(diff[-1] - 1)
print(sum((i ** 2 for i in diff)))


from queue import PriorityQueue
[n, k1, k2] = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = PriorityQueue()
for i in range(n):
	diff.put(-1 * abs(a[i] - b[i]))
while k1:
	x = diff.get()
	if x == 0:
		diff.put(0)
		break
	diff.put(x + 1)
	k1 -= 1
while k2:
	x = diff.get()
	if x == 0:
		diff.put(0)
		break
	diff.put(1 + x)
	k2 -= 1
ans = 0
flag = 0
if (k1 + k2) % 2:
	flag = 1
for i in range(n):
	x = diff.get()
	if i == n - 1 and flag:
		x += 1
	ans += x * x
print(ans)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
difference = []
k = k1 + k2
for i in range(n):
	difference.append(abs(a[i] - b[i]))
while k != 0:
	if max(difference) > 0:
		difference[difference.index(max(difference))] -= 1
		k -= 1
	else:
		difference[difference.index(max(difference))] += 1
		k -= 1
for i in range(n):
	difference[i] **= 2
print(sum(difference))


(n, k1, k2) = [int(x) for x in input().split()[:3]]
ks1 = [int(x) for x in input().split()[:n]]
ks2 = [int(x) for x in input().split()[:n]]
err = [abs(ks1[i] - ks2[i]) for i in range(n)]
num = k1 + k2
rest1 = False
if num % 2 != sum(err) % 2:
	rest1 = True

def kill():
	global num
	maxx = max(err)
	if maxx == 0 or num == 0:
		return False
	for i in range(len(err)):
		if err[i] == maxx:
			err[i] -= 1
			num -= 1
			if num == 0:
				return False
	return True
while kill():
	pass
summ = sum([x ** 2 for x in err])
if summ == 0 and rest1:
	print(1)
else:
	print(summ)


(n, k1, k2) = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
da = []
for i in range(len(A)):
	da.append(abs(A[i] - B[i]))
da.sort(reverse=1)
op = k1 + k2
while op:
	if all((x == 0 for x in da)):
		if op % 2 == 0:
			print(0)
			exit()
		else:
			print(1)
			exit()
	da[da.index(max(da))] -= 1
	op -= 1
print(sum((x ** 2 for x in da)))


(n, k, l) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [abs(x - y) for (x, y) in zip(a, b)]
moves = k + l
d.sort()
d.reverse()
while moves > 0:
	if d[0] == 0:
		print(moves % 2)
		break
	d[0] -= 1
	c = 0
	while c < n - 1 and d[c] < d[c + 1]:
		(d[c], d[c + 1]) = (d[c + 1], d[c])
		c += 1
	moves -= 1
else:
	print(sum([x ** 2 for x in d]))


import sys
import math
texto = sys.stdin.read().split('\n')
texto.pop(-1)
n = int(texto[0].split(' ')[0])
k1 = int(texto[0].split(' ')[1])
k2 = int(texto[0].split(' ')[2])
A = [int(x) for x in texto[1].split(' ')]
B = [int(x) for x in texto[2].split(' ')]
espera = []
for index in range(0, n):
	espera.append(((A[index] - B[index]) ** 2, index))
espera.sort()
for operations in range(0, k1):
	(error, index) = espera[n - 1]
	if A[index] > B[index]:
		A[index] -= 1
		espera[n - 1] = ((A[index] - B[index]) ** 2, index)
		espera.sort()
	else:
		A[index] += 1
		espera[n - 1] = ((A[index] - B[index]) ** 2, index)
		espera.sort()
for operations in range(0, k2):
	(error, index) = espera[n - 1]
	if B[index] > A[index]:
		B[index] -= 1
		espera[n - 1] = ((A[index] - B[index]) ** 2, index)
		espera.sort()
	else:
		B[index] += 1
		espera[n - 1] = ((A[index] - B[index]) ** 2, index)
		espera.sort()
sum = 0
for (a, b) in espera:
	sum = sum + a
print(sum)


s = [int(x) for x in str.split(input())]
(n, k1, k2) = s
a = [int(x) for x in str.split(input())]
b = [int(x) for x in str.split(input())]
dbst = [abs(a[0] - b[0])]
for i in range(1, n):
	dbst.append(abs(a[i] - b[i]))
dbst.sort()
su = 0
for i in range(k1 + k2, 0, -1):
	if dbst[-1] == 0:
		su += i % 2
		break
	dbst[-1] -= 1
	dbst.sort()
for i in range(n):
	su += dbst[i] * dbst[i]
print(su)


import heapq
(n, m, k) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
tot = m + k
li = []
for i in range(n):
	li.append(-1 * abs(arr1[i] - arr2[i]))
heapq.heapify(li)
while tot:
	t = heapq.heappop(li)
	t += 1
	if t > 0:
		t = -1 * t
	heapq.heappush(li, t)
	tot -= 1
ans = 0
for i in li:
	ans += i * i
print(ans)


import math
(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
for i in range(len(a)):
	d.append(int(math.fabs(a[i] - b[i])))
k = k1 + k2
for i in range(k):
	m = max(d)
	num = d.index(m)
	if m != 0:
		d[num] -= 1
	else:
		d[num] += 1
s = 0
for i in d:
	s += i ** 2
print(s)


import math
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
for i in range(n):
	x.append(int(math.fabs(a[i] - b[i])))
k = k1 + k2
while k > 0:
	max_num = 0
	idx = -1
	for i in range(n):
		if x[i] > max_num:
			max_num = x[i]
			idx = i
	if idx == -1:
		break
	x[idx] -= 1
	k -= 1
ret = 0
for i in range(n):
	ret += x[i] * x[i]
if k % 2 == 1:
	ret += 1
print(ret)


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [abs(a[i] - b[i]) for i in range(n)]
moves = k1 + k2
diff.sort()
while moves > 0 and diff != [0] * n:
	diff[-1] -= 1
	moves -= 1
	diff.sort()
if moves:
	if moves % 2 == 0:
		print(0)
	else:
		print(1)
else:
	ans = 0
	for i in range(n):
		ans += diff[i] ** 2
	print(ans)
	print()


(nrazmer, k1operationsA, k2operationsB) = map(int, input().split())
myListA = list(map(int, input().split()))
myListB = list(map(int, input().split()))
diffList = []
for i in range(0, nrazmer):
	a = myListA[i]
	b = myListB[i]
	diff = abs(a - b)
	diffList.append(diff)
totalOps = k1operationsA + k2operationsB
diffList.sort()
diffList.reverse()
while totalOps > 0 and diffList[0] > 0:
	diffList[0] -= 1
	diffList.sort()
	diffList.reverse()
	totalOps -= 1
if diffList[0] == 0 and totalOps > 0:
	if totalOps % 2 == 1:
		diffList[0] = 1
	else:
		diffList[0] = 0
errorSum = 0
for j in range(0, len(diffList)):
	errorSum += diffList[j] * diffList[j]
print(errorSum)


from math import fabs
import heapq

def getError(l, size):
	r = 0
	for i in range(size):
		r += l[i] ** 2
	return r
pq = []
(n, k1, k2) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
disp = k1 + k2
for i in range(n):
	pq.extend([int(-1 * fabs(a[i] - b[i]))])
heapq.heapify(pq)
while disp > 0:
	x = heapq.heappop(pq)
	if x == 0:
		heapq.heappush(pq, -1)
	else:
		heapq.heappush(pq, x + 1)
	disp -= 1
print(getError(pq, len(pq)))


import heapq

def read():
	return [int(v) for v in input().split()]

def main():
	(n, k1, k2) = read()
	k = k1 + k2
	a = read()
	b = read()
	c = [-abs(a - b) for (a, b) in zip(a, b)]
	heapq.heapify(c)
	while k:
		top = heapq.heappop(c)
		if top < 0:
			top += 1
			heapq.heappush(c, top)
		else:
			break
		k -= 1
	if k > 0:
		print(k % 2)
		return
	print(sum((a * a for a in c)))
main()


(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
while k1 + k2 > 0:
	max_dif = -10000000000000
	ind = -1
	for i in range(n):
		if (a[i] - b[i]) ** 2 > max_dif:
			max_dif = (a[i] - b[i]) ** 2
			ind = i
	if k1 != 0:
		k1 -= 1
		if a[ind] > b[ind]:
			a[ind] -= 1
		else:
			a[ind] += 1
	elif k2 != 0:
		k2 -= 1
		if b[ind] > a[ind]:
			b[ind] -= 1
		else:
			b[ind] += 1
ans = 0
for i in range(n):
	ans += (a[i] - b[i]) ** 2
print(ans)


import sys
input = sys.stdin.readline
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [abs(a[i] - b[i]) for i in range(n)]
k = k1 + k2
while k != 0:
	maxx = 0
	for i in c:
		maxx = max(i, maxx)
	if maxx == 0:
		break
	for i in range(n):
		if c[i] == maxx:
			c[i] -= 1
			k -= 1
		if k == 0:
			break
ans = 0
for i in c:
	ans += i ** 2
print(ans + k % 2)


(n, m, k) = map(int, input().split())
total = m + k
z = list(map(int, input().split()))
m = list(map(int, input().split()))
ans = []
for i in range(len(z)):
	ans.append(abs(z[i] - m[i]))
ans.sort(reverse=True)
if total == sum(ans):
	print(0)
elif total > sum(ans):
	r = total - sum(ans)
	if r % 2 == 1:
		print(1)
	else:
		print(0)
else:
	flag = 0
	count = total
	quant = 0
	for i in range(1, len(ans)):
		if flag == 1:
			break
		if ans[i - 1] > ans[i]:
			quant = ans[i - 1] - ans[i]
			for j in range(i):
				if quant < count:
					ans[j] -= quant
					count -= quant
				else:
					for t in range(j):
						count += quant
						ans[t] = ans[j]
					flag = 1
					break
	ans.sort(reverse=True)
	if flag == 1:
		x = ans.count(ans[0])
		gam = count // x
		tam = count % x
		for i in range(x):
			ans[i] -= gam
		for i in range(tam):
			ans[i] -= 1
	else:
		gam = count // len(ans)
		tam = count % len(ans)
		for i in range(len(ans)):
			ans[i] -= gam
		for i in range(tam):
			ans[i] -= 1
	fin = 0
	for i in range(len(ans)):
		fin += pow(ans[i], 2)
	print(fin)


(n, m, k) = [int(i) for i in input().split()]
k = k + m
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [abs(a[i] - b[i]) for i in range(n)]
while k != 0:
	c.sort()
	c[-1] = abs(c[-1] - 1)
	k -= 1
t = 0
for i in range(n):
	t += c[i] * c[i]
print(t)


from queue import PriorityQueue
(n, k1, k2) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = PriorityQueue()
for i in range(n):
	dif = a[i] - b[i]
	c.put((abs(dif) * -1, i))
for e in range(k1 + k2):
	(val, pos) = c.get()
	if val >= 0:
		c.put((val - 1, pos))
	else:
		c.put((val + 1, pos))
suma = 0
for i in range(n):
	a = c.get()
	suma += a[0] ** 2
print(suma)


f = lambda : map(int, input().split())
(n, k1, k2) = f()
(a, b) = (list(f()), list(f()))
c = []
k = k1 + k2
for i in range(n):
	c.append(abs(a[i] - b[i]))
for i in range(k):
	c.sort()
	c[-1] = abs(c[-1] - 1)
print(sum((x * x for x in c)))


from heapq import heappush, heappop
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pq = []
for i in range(n):
	if abs(a[i] - b[i]) > 0:
		heappush(pq, -abs(a[i] - b[i]))
tot = k1 + k2
while pq and tot > 0:
	ce = -heappop(pq)
	tot -= 1
	if ce == 1:
		continue
	heappush(pq, -(ce - 1))
ans = 0
if tot > 0:
	ans = tot % 2
elif pq:
	for elm in pq:
		ans += elm ** 2
print(ans)


import bisect
(n, k1, k2) = map(int, input().split())
k = k1 + k2
a = list(map(int, input().split()))
(c, s) = (0, 0)
e = []
for i in input().split():
	e0 = abs(int(i) - a[c])
	bisect.insort(e, e0)
	s += (int(i) - a[c]) ** 2
	c += 1
while k:
	if e[-1] == 0:
		break
	l = bisect.bisect_left(e, e[-1])
	a = len(e) - l
	if k > a:
		k -= a
	else:
		(k, a) = (0, k)
	s -= a * (2 * e[-1] - 1)
	e[l:] = list((e[-1] - 1 for i in range(a)))
print(s + k % 2)


import heapq
(n, k1, k2) = map(int, input().split())
a = list(map(int, input().split()))[:n]
b = list(map(int, input().split()))[:n]
total = k1 + k2
arr = []
for i in range(n):
	arr.append(-1 * abs(a[i] - b[i]))
heapq.heapify(arr)
while total > 0:
	item = -1 * heapq.heappop(arr)
	heapq.heappush(arr, -1 * abs(item - 1))
	total -= 1
ans = 0
for i in range(len(arr)):
	ans += arr[i] ** 2
print(ans)


R = lambda : map(int, input().split())
(n, k1, k2) = R()
a = [abs(x - y) for (x, y) in zip(R(), R())]
for _ in range(k1 + k2):
	idx = a.index(max(a))
	a[idx] = abs(a[idx] - 1)
print(sum((x * x for x in a)))


(n, k1, k2) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))

def process(s, t, k):
	while k > 0:
		dmax = 0
		maxi = -1
		for i in range(n):
			if abs(s[i] - t[i]) >= dmax:
				dmax = abs(s[i] - t[i])
				maxi = i
		if s[maxi] >= t[maxi]:
			s[maxi] -= 1
		else:
			s[maxi] += 1
		k -= 1
process(a, b, k1)
process(b, a, k2)
res = 0
for i in range(n):
	res += (a[i] - b[i]) ** 2
print(res)


(n, k1, k2) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = k1 + k2
C = [abs(x - y) for (x, y) in zip(A, B)]
E = sum([x ** 2 for x in C])
if k == 0:
	print(E)
else:
	while E > 0 and k > 0:
		C.sort(reverse=True)
		C[0] -= 1
		k -= 1
		E = sum([x ** 2 for x in C])
	if k % 2 == 0:
		print(E)
	else:
		print(E + 1)


from queue import PriorityQueue as PQ
(N, kA, kB) = [int(c) for c in input().split(' ')]
A = [int(c) for c in input().split(' ')]
B = [int(c) for c in input().split(' ')]
pq = PQ()
for i in range(N):
	pq.put(-abs(A[i] - B[i]))
for i in range(kA + kB):
	max_value = pq.get()
	if max_value == 0:
		pq.put(-1)
	else:
		pq.put(max_value + 1)
error = 0
while not pq.empty():
	error += pq.get() ** 2
print(error)