# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from heapq import *

class Node:
    def __init__(self,ori,piece):
        self.ori = ori
        self.piece = piece
        xx,yy = divmod(self.ori,self.piece)
        xx1,yy1 = divmod(self.ori,self.piece+1)
        aa = self.piece*(xx**2)+yy*(2*xx+1)
        bb = (self.piece+1)*(xx1**2)+yy1*(2*xx1+1)
        self.inc = aa-bb
    def __lt__(self, other):
        return self.inc > other.inc

def main():
    n,k = map(int,input().split())
    x = list(map(lambda y:Node(int(y),1),input().split()))
    heapify(x)
    for _ in range(k-n):
        r = heappop(x)
        xx,yy = divmod(r.ori,r.piece)
        aa = r.piece*(xx**2)+yy*(2*xx+1)
        r.piece += 1
        xx1,yy1 = divmod(r.ori,r.piece)
        bb = r.piece*(xx1**2)+yy1*(2*xx1+1)
        r.inc = aa-bb
        heappush(x,r)
    ti = 0
    for j in x:
        rr = j.ori//j.piece
        ti += j.piece*rr*rr
        ti += (2*rr+1)*(j.ori%j.piece)
    print(ti)

#Fast IO Region
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")

if __name__ == '__main__':
    main()


# by the authority of GOD     author: manhar singh sachdev #

import os, sys
from io import BytesIO, IOBase
from heapq import *

class Node:
    def __init__(self, ori, val, piece):
        self.ori = ori
        self.val = val
        self.piece = piece
        xx, yy = divmod(self.ori, self.piece)
        xx1, yy1 = divmod(self.ori, self.piece+1)
        aa = self.piece*(xx**2) + yy*(2*xx+1)
        bb = (self.piece+1)*(xx1**2) + yy1*(2*xx1+1)
        self.inc = aa-bb
    def __lt__(self, other):
        return self.inc > other.inc
    def __str__(self):
        return '{} {} {} {}'.format(self.ori,self.val,self.piece,self.inc)

def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    tar = sum(arr)//k+1
    ti = 0
    x = []
    for i in arr:
        if i > tar:
            x.append(Node(i,i,1))
        else:
            ti += i*i
    heapify(x)
    for _ in range(k - len(arr)):
        r = heappop(x)
        xx,yy = divmod(r.ori, r.piece)
        aa = r.piece * (xx ** 2) + yy * (2 * xx + 1)
        r.piece += 1
        xx1,yy1 = divmod(r.ori, r.piece)
        bb = r.piece * (xx1 ** 2) + yy1 * (2 * xx1 + 1)
        r.inc = aa-bb
        r.val = r.ori//r.piece+(r.ori%r.piece!=0)
        heappush(x,r)
    for j in x:
        ti += j.piece*(j.val-1)**2
        rr = j.ori%j.piece
        if not rr:
            rr = j.piece
        ti += (2*j.val-1)*rr
    print(ti)

# Fast IO Region
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")

if __name__ == '__main__':
    main()


# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from heapq import *

class Node:
    def __init__(self,ori,piece):
        self.ori = ori
        self.piece = piece
        self.inc = 0
    def __lt__(self, other):
        return self.inc > other.inc

def main():
    n,k = map(int,input().split())
    x = list(map(lambda y:Node(int(y),1),input().split()))
    for i in x:
        xx,yy = divmod(i.ori,i.piece)
        xx1,yy1 = divmod(i.ori,i.piece+1)
        aa = i.piece*(xx**2)+yy*(2*xx+1)
        bb = (i.piece+1)*(xx1**2)+yy1*(2*xx1+1)
        i.inc = aa-bb
    heapify(x)
    for _ in range(k-n):
        r = heappop(x)
        xx,yy = divmod(r.ori,r.piece)
        aa = r.piece*(xx**2)+yy*(2*xx+1)
        r.piece += 1
        xx1,yy1 = divmod(r.ori,r.piece)
        bb = r.piece*(xx1**2)+yy1*(2*xx1+1)
        r.inc = aa-bb
        heappush(x,r)
    ti = 0
    for j in x:
        rr,rr1 = divmod(j.ori,j.piece)
        ti += j.piece*rr*rr+(2*rr+1)*rr1
    print(ti)

#Fast IO Region
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")

if __name__ == '__main__':
    main()


# by the authority of GOD     author: manhar singh sachdev #

import os, sys
from io import BytesIO, IOBase
from heapq import *

class Node:
    def __init__(self, ori, piece):
        self.ori = ori
        self.piece = piece
        xx, yy = divmod(self.ori, self.piece)
        xx1, yy1 = divmod(self.ori, self.piece+1)
        aa = self.piece*(xx**2) + yy*(2*xx+1)
        bb = (self.piece+1)*(xx1**2) + yy1*(2*xx1+1)
        self.inc = aa-bb
    def __lt__(self, other):
        return self.inc > other.inc

def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    tar = sum(arr)//k+1
    ti = 0
    x = []
    for i in arr:
        if i > tar:
            x.append(Node(i,1))
        else:
            ti += i*i
    heapify(x)
    for _ in range(k - len(arr)):
        r = heappop(x)
        xx,yy = divmod(r.ori, r.piece)
        aa = r.piece * (xx ** 2) + yy * (2 * xx + 1)
        r.piece += 1
        xx1,yy1 = divmod(r.ori, r.piece)
        bb = r.piece * (xx1 ** 2) + yy1 * (2 * xx1 + 1)
        r.inc = aa-bb
        r.val = r.ori//r.piece+(r.ori%r.piece!=0)
        heappush(x,r)
    for j in x:
        rr = j.ori//j.piece
        ti += j.piece*rr**2
        ti += (2*rr+1)*(j.ori%j.piece)
    print(ti)

# Fast IO Region
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")

if __name__ == '__main__':
    main()


# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from heapq import *

class Node:
    def __init__(self,ori,piece):
        self.ori = ori
        self.piece = piece
        self.inc = 0
    def __lt__(self, other):
        return self.inc > other.inc

def main():
    n,k = map(int,input().split())
    x = list(map(lambda y:Node(int(y),1),input().split()))
    for i in x:
        xx,yy = divmod(i.ori,i.piece)
        xx1,yy1 = divmod(i.ori,i.piece+1)
        aa = i.piece*(xx**2)+yy*(2*xx+1)
        bb = (i.piece+1)*(xx1**2)+yy1*(2*xx1+1)
        i.inc = aa-bb
    heapify(x)
    for _ in range(k-n):
        r = heappop(x)
        r.piece += 1
        xx,yy = divmod(r.ori,r.piece)
        aa = r.piece*(xx**2)+yy*(2*xx+1)
        xx1,yy1 = divmod(r.ori,r.piece+1)
        bb = (r.piece+1)*(xx1**2)+yy1*(2*xx1+1)
        r.inc = aa-bb
        heappush(x,r)
    ti = 0
    for j in x:
        rr,rr1 = divmod(j.ori,j.piece)
        ti += j.piece*rr*rr+(2*rr+1)*rr1
    print(ti)

#Fast IO Region
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")

if __name__ == '__main__':
    main()


import heapq

def cost(L, m):
    """Min cost (time) of cutting L into m pieces.
    L = p1^2+...+pm^2, L is minimized when cutting as evenly as possible.
    """
    min_len = L//m
    rem = L-min_len*m
    # "Spread" rem across rem pieces, each receives +1 in len, so we have rem pieces of len `min_len+1` and m-rem pieces of len `min_len`.
    return (m-rem) * min_len * min_len + rem * (min_len+1) * (min_len+1)

def solve(a, n, k):
    pq = []
    total = 0
    for c in a:
        total += c*c
        # decrease in cost by cutting c in 2 pieces (compared to no cut)
        decrease_in_cost = cost(c, 1)-cost(c, 2)
        # Max heap by negating value
        pq.append((-decrease_in_cost, c, 2))

    heapq.heapify(pq)  # heapify modifies pq in-place, returns None!

    # Since we start with n pieces and end with k pieces, so the number of cut is k-n
    for _ in range(k-n):
        top = heapq.heappop(pq)
        total += top[0]
        c, m = top[1], top[2]
        decrease_in_cost = cost(c, m) - cost(c, m+1)
        heapq.heappush(pq, (-decrease_in_cost, c, m+1))
        # Why does this work?
        # Note at some point if we find that it's better to cut c in m2 pieces than the current cutting in m1 pieces, cost(c, 1) - cost(c, m1) + cost(c, m1) - cost(c, m2) = cost(c,1) - cost(c,m2).

    return total

n, k = (int(x) for x in input().split())
a = list(int(x) for x in input().split())

print(solve(a, n, k))


from heapq import *

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

def find_add(a, k):
    extra = a%k
    return (k-extra)*((a//k)**2) + extra*(((a+k-1)//k)**2)

for i in range(n):
    a[i] = ((find_add(a[i], 2)-find_add(a[i], 1)), a[i], 1)

total = n

while total != mx:
    curr_cont, el, k = heappop(a)
    new = (find_add(el, k+1)-find_add(el, k), el, k+1)
    heappush(a, new)
    total += 1

sc = 0
while a:
    curr_cont, el, k = heappop(a)
    sc += find_add(el, k)

print(sc)


from heapq import *

def find_add(a, k):
    extra = a%k
    return (k-extra)*((a//k)**2) + extra*((1+(a//k))**2)

n, mx = map(int, input().split())
lst = list(map(int, input().split()))
a = []
heapify(a)

for i in lst:
    heappush(a, (find_add(i, 2)-find_add(i, 1), i, 1))

total = n

while total != mx:
    curr_cont, el, k = heappop(a)
    new = (find_add(el, k+1)-find_add(el, k), el, k+1)
    heappush(a, new)
    total += 1

sc = 0
while a:
    curr_cont, el, k = heappop(a)
    sc += find_add(el, k)

print(sc)


from heapq import *

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

def find_contribution(a, k):
    return (a//k)**2 + (a%k)*((a+k-1)//k)**2

for i in range(n):
    a[i] = (-find_contribution(a[i], 2), a[i], 2)

total = n

while total != mx:
    curr_cont, el, k = heappop(a)
    new = (-find_contribution(el, k+1), el, k+1)
    heappush(a, new)
    total += 1

sc = 0
while a:
    curr_cont, el, k = heappop(a)
    sc += find_contribution(el, k-1)

print(sc)


from heapq import *

def find_add(a, k):
    extra = a%k
    return (k-extra)*((a//k)**2) + extra*((1+(a//k))**2)

n, mx = map(int, input().split())
lst = list(map(int, input().split()))
a = []
heapify(a)

for i in lst:
    heappush(a, (find_add(i, 2)-find_add(i, 1), i, 1))

total = n

while total != mx:
    curr_cont, el, k = heappop(a)
    new = (find_add(el, k+2)-find_add(el, k+1), el, k+1)
    heappush(a, new)
    total += 1

sc = 0
while a:
    curr_cont, el, k = heappop(a)
    sc += find_add(el, k)

print(sc)


from heapq import *

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

def find_add(a, k):
    extra = a%k
    return (k-extra)*(a//k)**2 + extra*((a+k-1)//k)**2

for i in range(n):
    a[i] = ((find_add(a[i], 2)-find_add(a[i], 1)), a[i], 2)

total = n

while total != mx:
    curr_cont, el, k = heappop(a)
    new = ((find_add(el, k+1)-find_add(el, k)), el, k+1)
    heappush(a, new)
    total += 1

sc = 0
while a:
    curr_cont, el, k = heappop(a)
    sc += find_add(el, k-1)

print(sc)


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import heapq

MOD = 10 ** 5 + 1

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    target = min((sum(a) + (k - 1)) // k - 100,1)
    cost = []
    currentSplit = []
    currentCost = []
    for elem in a:
        currentSplit.append((elem + target - 1) // target)
        currentCost.append((elem // currentSplit[-1]) ** 2 * currentSplit[-1])
        currentCost[-1] += (elem % currentSplit[-1]) * (1 + 2 * (elem // currentSplit[-1]))
        if currentSplit[-1] != 1:
            newSplit = currentSplit[-1] - 1
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[-1]) * MOD + len(currentCost) - 1)
    curAns = sum(currentSplit)
    curCost = sum(currentCost)
    while curAns > k:
        curAns -= 1
        curElem = heapq.heappop(cost)
        addedCost = curElem // MOD
        loc = curElem % MOD
        currentCost[loc] += addedCost
        curCost += addedCost
        currentSplit[loc] -= 1
        if currentSplit[loc] != 1:
            newSplit = currentSplit[loc] - 1
            elem = a[loc]
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[loc]) * MOD + loc)
    print(curCost)

# region fastio

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")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import heapq

MOD = 10 ** 5 + 1

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    target = (sum(a) + (k - 1)) // k
    cost = []
    currentSplit = []
    currentCost = []
    for elem in a:
        currentSplit.append((elem + target - 1) // target)
        currentCost.append((elem // currentSplit[-1]) ** 2 * currentSplit[-1])
        currentCost[-1] += (elem % currentSplit[-1]) * (1 + 2 * (elem // currentSplit[-1]))
        if currentSplit[-1] != 1:
            newSplit = currentSplit[-1] - 1
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[-1]) * MOD + len(currentCost) - 1)
    curAns = sum(currentSplit)
    curCost = sum(currentCost)
    while curAns > k:
        curAns -= 1
        curElem = heapq.heappop(cost)
        addedCost = curElem // MOD
        loc = curElem % MOD
        currentCost[loc] += addedCost
        curCost += addedCost
        currentSplit[loc] -= 1
        if currentSplit[loc] != 1:
            newSplit = currentSplit[loc] - 1
            elem = a[loc]
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[loc]) * MOD + loc)
    print(curCost)

# region fastio

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")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import heapq

MOD = 10 ** 5 + 1

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    target = max((sum(a) + (k - 1)) // k - 100,1)
    cost = []
    currentSplit = []
    currentCost = []
    for elem in a:
        currentSplit.append((elem + target - 1) // target)
        currentCost.append((elem // currentSplit[-1]) ** 2 * currentSplit[-1])
        currentCost[-1] += (elem % currentSplit[-1]) * (1 + 2 * (elem // currentSplit[-1]))
        if currentSplit[-1] != 1:
            newSplit = currentSplit[-1] - 1
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[-1]) * MOD + len(currentCost) - 1)
    curAns = sum(currentSplit)
    curCost = sum(currentCost)
    while curAns > k:
        curAns -= 1
        curElem = heapq.heappop(cost)
        addedCost = curElem // MOD
        loc = curElem % MOD
        currentCost[loc] += addedCost
        curCost += addedCost
        currentSplit[loc] -= 1
        if currentSplit[loc] != 1:
            newSplit = currentSplit[loc] - 1
            elem = a[loc]
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[loc]) * MOD + loc)
    print(curCost)

# region fastio

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")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import heapq

MOD = 10 ** 5 + 1

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    target = (sum(a) + (k - 1)) // k + 100
    cost = []
    currentSplit = []
    currentCost = []
    for elem in a:
        currentSplit.append((elem + target - 1) // target)
        currentCost.append((elem // currentSplit[-1]) ** 2 * currentSplit[-1])
        currentCost[-1] += (elem % currentSplit[-1]) * (1 + 2 * (elem // currentSplit[-1]))
        if currentSplit[-1] != 1:
            newSplit = currentSplit[-1] - 1
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[-1]) * MOD + len(currentCost) - 1)
    curAns = sum(currentSplit)
    curCost = sum(currentCost)
    while curAns > k:
        curAns -= 1
        curElem = heapq.heappop(cost)
        addedCost = curElem // MOD
        loc = curElem % MOD
        currentCost[loc] += addedCost
        curCost += addedCost
        currentSplit[loc] -= 1
        if currentSplit[loc] != 1:
            newSplit = currentSplit[loc] - 1
            elem = a[loc]
            curDecCost = (elem // newSplit) ** 2 * newSplit
            curDecCost += (elem % newSplit) * (1 + 2 * (elem // newSplit))
            heapq.heappush(cost,(curDecCost - currentCost[loc]) * MOD + loc)
    print(curCost)

# region fastio

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")

# endregion

if __name__ == "__main__":
    main()


from sys import stdin, gettrace
from heapq import heappush, heappop

if gettrace():
    inputi = input
else:
    def input():
        return next(stdin)[:-1]

    def inputi():
        return stdin.buffer.readline()

def cost(ln, pieces):
    extras = ln%pieces
    return ((ln//pieces) * (ln//pieces)) * pieces + 2*(ln//pieces)*extras + extras

def cost_decrease(ln, pieces):
    return cost(ln, pieces) - cost(ln, pieces+1)

def main():
    n,k = map(int, inputi().split())
    aa = [int(a) for a in inputi().split()]
    hp = []
    for a in aa:
        heappush(hp, (-cost_decrease(a, 1), a, 1))
    for _ in range(n,k):
        _, a, c = heappop(hp)
        heappush(hp, (-cost_decrease(a, c+1), a, c+1))
    print(sum(cost(a, c) for _,a,c in hp))

if __name__ == "__main__":
    main()


import heapq

def sum_sqaure(a, k):
    q, r = divmod(a, k)
    return q**2 * (k-r) + (q+1)**2 * r

def diff(a, k):
    return sum_sqaure(a, k+1) - sum_sqaure(a, k)

n, k = map(int, input().split())
nums = list(map(int, input().split()))

curr = sum(sum_sqaure(a, 1) for a in nums)
Q = [(diff(a, 1), a, 1) for a in nums]
heapq.heapify(Q)
for __ in range(k - n):
    d, a, i = heapq.heappop(Q)
    curr += d
    heapq.heappush(Q, (diff(a, i+1), a, i+1))
print(curr)


import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.PriorityQueue
import java.util.StringTokenizer

fun main() {
  E_CarrotsForRabbits()
}

class E_CarrotsForRabbits {
  val reader = InputReader()
  val writer = PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))

  init {
    solve()
    writer.close()
  }

  private fun solve() {
    val n = reader.readInt()
    val k = reader.readInt()
    var cutsLeft = k - n

    val pq = PriorityQueue<Carrot>()

    for (i in 0 until n) {
      pq.add(Carrot(reader.readLong(), 1))
    }

    for (i in 0 until cutsLeft) {
      val carrot = pq.poll()
      carrot.pieces++
      pq.add(carrot)
    }

    var ans = 0L
    while (pq.isNotEmpty()) {
      ans += pq.poll().cost()
    }

    writer.println(ans)
  }

  data class Carrot(val length: Long, var pieces: Int) : Comparable<Carrot> {
    override fun compareTo(other: Carrot): Int =
        other.costDiff().compareTo(this.costDiff())

    fun costDiff(): Long {
      return cost(pieces) - cost(newPieces = pieces + 1)
    }

    fun cost(newPieces: Int = pieces): Long {
      val over = length % newPieces
      return over * ((length / newPieces) + 1) * ((length / newPieces) + 1) + (newPieces - over) * (
          length / newPieces) * (length / newPieces)
    }
  }

  class InputReader {
    val stdin = BufferedReader(InputStreamReader(System.`in`))
    var st = StringTokenizer("")

    fun readString(): String {
      while (!st.hasMoreTokens()) {
        st = StringTokenizer(stdin.readLine())
      }
      return st.nextToken()
    }

    fun readLong(): Long {
      return readString().toLong()
    }

    fun readInt(): Int {
      return readString().toInt()
    }
  }
}


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")
@file:OptIn(ExperimentalStdlibApi::class)

import java.io.PrintWriter
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
//    val startTime = System.nanoTime()

    val numCases = 1//readInt()
    case@ for(case in 1..numCases) {
//        print("Case #$case: ")

        val n = readInt()
        val k = readInt()

        val A = readIntArray(n)
        val D = IntArray(n) { 1 }

        var ans = A.sumOf { it.sq }
        val S = LongArray(n) { i ->
            cost(A[i], 1) - cost(A[i], 2)
        }

        val h = IntArray(n+1) { it-1 }

        fun sink(i0: Int) {
            var i = i0
            while(true) {
                val l = i shl 1
                if(l > n) break
                val r = l or 1

                var best = l
                var p = S[h[l]]
                if(r <= n) {
                    val pr = S[h[r]]
                    if(pr > p) {
                        best = r
                        p = pr
                    }
                }

                if(S[h[i]] >= p) break

                h.swap(i, best)
                i = best
            }
        }

        for(i in n/2 downTo 1) sink(i)

        repeat(k - n) {
            val i = h[1]
            val s = S[i]
            ans -= s
            val a = A[i]
            val d = ++D[i]
            S[i] = cost(a, d) - cost(a, d+1)
            sink(1)
        }

        println(ans)
    }

//    iprintln("Time: ${(System.nanoTime() - startTime) / 1000000} ms")
}

fun IntArray.swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }

val Int.sq get() = toLong() * this

fun cost(a: Int, d: Int): Long {
    val q = a/d
    val r = a - q*d
    return q.sq * (d-r) + (q+1).sq * r
}

infix fun Int.divCeil(other: Int) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }

inline infix fun Int.divFloor(other: Int) = Math.floorDiv(this, other)

infix fun Long.divCeil(other: Long) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }
inline infix fun Long.divCeil(other: Int) = divCeil(other.toLong())

inline infix fun Long.divFloor(other: Long) = Math.floorDiv(this, other)

/** IO */
//@JvmField val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null
//const val PATH = "src/main/resources/"
//@JvmField val INPUT = File(PATH + "input.txt").inputStream()
//@JvmField val OUTPUT = File(PATH + "output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar() else c
    }
}

/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */
fun readCharArray(n: Int, skipNext: Boolean = true): CharArray {
    val res = CharArray(n) { readChar() }
    if(skipNext) readChar()
    return res
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(c != '\n' && c != Char.MIN_VALUE) {
            append(c)
            c = readChar()
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

inline fun <A, T> _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {
    var a = a0
    var tmp = tmp0
    var len = 1
    while(len < n) {
        var l = 0
        while(true) {
            val m = l + len
            if(m >= n) break
            val r = min(n, m + len)
            var i = l
            var j = m
            for(k in l until r) {
                if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {
                    tmp.set(k, a.get(i++))
                } else tmp.set(k, a.get(j++))
            }
            l = r
        }
        for(i in l until n) tmp.set(i, a.get(i))
        val t = a; a = tmp; tmp = t
        len += len
    }
    if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))
}

inline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }
inline fun <T: Comparable<T>> IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun IntArray.sort() { sortBy { it } }
fun IntArray.sortDescending() { sortByDescending { it } }

inline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }
inline fun <T: Comparable<T>> LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun LongArray.sort() { sortBy { it } }
fun LongArray.sortDescending() { sortByDescending { it } }

inline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }
inline fun <T: Comparable<T>> DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun DoubleArray.sort() { sortBy { it } }
fun DoubleArray.sortDescending() { sortByDescending { it } }

inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T : Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T : Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T : Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T : Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

// import preserving junk function
@Suppress("NonAsciiCharacters") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }

fun IntArray.sumLong() = sumOf { it.toLong() }

fun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> List<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> List<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }

// max/min Kotlin 1.6 -> 1.4 shim
fun IntArray.max() = maxOf { it }
fun IntArray.min() = minOf { it }
fun LongArray.max() = maxOf { it }
fun LongArray.min() = minOf { it }
fun CharArray.max() = maxOf { it }
fun CharArray.min() = minOf { it }
fun <T : Comparable<T>> Iterable<T>.max() = maxOf { it }
fun <T : Comparable<T>> Iterable<T>.min() = minOf { it }
fun <T : Comparable<T>> Sequence<T>.max() = maxOf { it }
fun <T : Comparable<T>> Sequence<T>.min() = minOf { it }


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")
@file:OptIn(ExperimentalStdlibApi::class)

import java.io.PrintWriter
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
//    val startTime = System.nanoTime()

    val numCases = 1//readInt()
    case@ for(case in 1..numCases) {
//        print("Case #$case: ")

        val n = readInt()
        val k = readInt()

        val A = readIntArray(n)
        val D = IntArray(n) { 1 }

        var ans = A.sumOf { it.sq }
        val S = LongArray(n) { i ->
            A[i].sq - cost(A[i], 2)
        }

        val h = IntArray(n+1) { it-1 }

        fun sink(i0: Int) {
            var i = i0
            while(true) {
                val l = i shl 1
                if(l > n) break
                val r = l or 1

                var best = l
                var p = S[h[l]]
                if(r <= n) {
                    val pr = S[h[r]]
                    if(pr > p) {
                        best = r
                        p = pr
                    }
                }

                if(S[h[i]] >= p) break

                h.swap(i, best)
                i = best
            }
        }

        for(i in n/2 downTo 1) sink(i)

        repeat(k - n) {
            val i = h[1]
            val s = S[i]
            ans -= s
            val a = A[i]
            val d = ++D[i]
            S[i] = cost(a, d) - cost(a, d+1)
            sink(1)
        }

        println(ans)
    }

//    iprintln("Time: ${(System.nanoTime() - startTime) / 1000000} ms")
}

fun IntArray.swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }

val Int.sq get() = toLong() * this

fun cost(a: Int, d: Int): Long {
    val q = a/d
    val r = a - q*d
    return q.sq * (d-r) + (q+1).sq * r
}

infix fun Int.divCeil(other: Int) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }

inline infix fun Int.divFloor(other: Int) = Math.floorDiv(this, other)

infix fun Long.divCeil(other: Long) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }
inline infix fun Long.divCeil(other: Int) = divCeil(other.toLong())

inline infix fun Long.divFloor(other: Long) = Math.floorDiv(this, other)

/** IO */
//@JvmField val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null
//const val PATH = "src/main/resources/"
//@JvmField val INPUT = File(PATH + "input.txt").inputStream()
//@JvmField val OUTPUT = File(PATH + "output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar() else c
    }
}

/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */
fun readCharArray(n: Int, skipNext: Boolean = true): CharArray {
    val res = CharArray(n) { readChar() }
    if(skipNext) readChar()
    return res
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(c != '\n' && c != Char.MIN_VALUE) {
            append(c)
            c = readChar()
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

inline fun <A, T> _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {
    var a = a0
    var tmp = tmp0
    var len = 1
    while(len < n) {
        var l = 0
        while(true) {
            val m = l + len
            if(m >= n) break
            val r = min(n, m + len)
            var i = l
            var j = m
            for(k in l until r) {
                if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {
                    tmp.set(k, a.get(i++))
                } else tmp.set(k, a.get(j++))
            }
            l = r
        }
        for(i in l until n) tmp.set(i, a.get(i))
        val t = a; a = tmp; tmp = t
        len += len
    }
    if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))
}

inline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }
inline fun <T: Comparable<T>> IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun IntArray.sort() { sortBy { it } }
fun IntArray.sortDescending() { sortByDescending { it } }

inline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }
inline fun <T: Comparable<T>> LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun LongArray.sort() { sortBy { it } }
fun LongArray.sortDescending() { sortByDescending { it } }

inline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }
inline fun <T: Comparable<T>> DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun DoubleArray.sort() { sortBy { it } }
fun DoubleArray.sortDescending() { sortByDescending { it } }

inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T : Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T : Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T : Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T : Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

// import preserving junk function
@Suppress("NonAsciiCharacters") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }

fun IntArray.sumLong() = sumOf { it.toLong() }

fun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> List<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> List<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }

// max/min Kotlin 1.6 -> 1.4 shim
fun IntArray.max() = maxOf { it }
fun IntArray.min() = minOf { it }
fun LongArray.max() = maxOf { it }
fun LongArray.min() = minOf { it }
fun CharArray.max() = maxOf { it }
fun CharArray.min() = minOf { it }
fun <T : Comparable<T>> Iterable<T>.max() = maxOf { it }
fun <T : Comparable<T>> Iterable<T>.min() = minOf { it }
fun <T : Comparable<T>> Sequence<T>.max() = maxOf { it }
fun <T : Comparable<T>> Sequence<T>.min() = minOf { it }


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")
@file:OptIn(ExperimentalStdlibApi::class)

import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.PriorityQueue
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
//    val startTime = System.nanoTime()

    val numCases = 1//readInt()
    case@ for(case in 1..numCases) {
//        print("Case #$case: ")

        val n = readInt()
        val k = readInt()

        val A = readIntArray(n)
        val D = IntArray(n) { 1 }

        var ans = A.sumOf { it.sq }
        val Q = PriorityQueue<QE>(compareByDescending { it.s })
        for(i in 0 until n) Q.add(QE(i, cost(A[i], 1) - cost(A[i], 2)))

        repeat(k - n) {
            val (i, s) = Q.remove()
            ans -= s
            val a = A[i]
            val d = ++D[i]

            Q.add(QE(i, cost(a, d) - cost(a, d+1)))
        }

        println(ans)
    }

//    iprintln("Time: ${(System.nanoTime() - startTime) / 1000000} ms")
}

data class QE(val i: Int, val s: Long)

val Int.sq get() = toLong() * this

fun cost(a: Int, d: Int): Long {
    val q = a/d
    val r = a - q*d
    return q.sq * (d-r) + (q+1).sq * r
}

infix fun Int.divCeil(other: Int) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }

inline infix fun Int.divFloor(other: Int) = Math.floorDiv(this, other)

infix fun Long.divCeil(other: Long) =
    (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }
inline infix fun Long.divCeil(other: Int) = divCeil(other.toLong())

inline infix fun Long.divFloor(other: Long) = Math.floorDiv(this, other)

/** IO */
//const val PATH = "src/main/resources/"
//@JvmField val INPUT = File(PATH + "input.txt").inputStream()
//@JvmField val OUTPUT = File(PATH + "output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */
fun readCharArray(n: Int, skipNext: Boolean = true): CharArray {
    val res = CharArray(n) { readChar() }
    if(skipNext) readChar()
    return res
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(c != '\n' && c != Char.MIN_VALUE) {
            append(c)
            c = readChar()
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

fun IntArray.sort() { shuffle(random); _sort() }
fun IntArray.sortDescending() { shuffle(random); _sortDescending() }

fun LongArray.sort() { shuffle(random); _sort() }
fun LongArray.sortDescending() { shuffle(random); _sortDescending() }

fun DoubleArray.sort() { shuffle(random); _sort() }
fun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }

inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T : Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T : Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T : Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T : Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

// import preserving junk function
@Suppress("NonAsciiCharacters") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }

fun IntArray.sumLong() = sumOf { it.toLong() }

// max/min Kotlin 1.6 -> 1.4 shim
fun IntArray.max() = maxOf { it }
fun IntArray.min() = minOf { it }
fun LongArray.max() = maxOf { it }
fun LongArray.min() = minOf { it }
fun CharArray.max() = maxOf { it }
fun CharArray.min() = minOf { it }
fun <T : Comparable<T>> Iterable<T>.max() = maxOf { it }
fun <T : Comparable<T>> Iterable<T>.min() = minOf { it }
fun <T : Comparable<T>> Sequence<T>.max() = maxOf { it }
fun <T : Comparable<T>> Sequence<T>.min() = minOf { it }


import java.util.*

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */

private fun calLength(l :Long, p :Long) :Long {
    var q = l / p
    var r = l % p
    return r * (q+1) * (q+1) + (p-r) * q * q
}

class Carrot(l: Long, p: Long, d: Long) {
    val length: Long = l
    val pieces: Long = p
    val delta: Long = d
}

fun main() {
    // Write your solution here

    var (n,k) = readLine()!!.split(" ").map { it.toInt() }

    var pq = PriorityQueue<Carrot>(compareBy{it.delta})
    var ans: Long = 0
    val tokenizer = StringTokenizer(readLine()!!)
    for (i in 1..n) {
        var a = tokenizer.nextToken().toLong()
        ans += a * a
        if (a>1) {
            pq.add(Carrot(a, 1, calLength(a, 2) - calLength(a, 1))) // decreasing priority
        }
    }

    for (t in k-n downTo 1) {
        var top = pq.remove()
        ans += top.delta  // add negative
        val newPiece = top.pieces + 1
        if (top.length > newPiece) {
            pq.add(Carrot(top.length, newPiece, calLength(top.length, newPiece+1) - calLength(top.length, newPiece)))
        }
    }

    println(ans)
}


import java.util.*

fun main() {
    fun split(n: Long, k: Long): Long {
        val r = n % k
        val x = n / k
        return ((k - r) * x * x) + (r * (x + 1L) * (x + 1L))
    }
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val pq = PriorityQueue<Split>(compareBy { it.delta })
    var answer = 0L
    val tokenizer = StringTokenizer(readLine()!!)
    for (j in 1..n) {
        val x = tokenizer.nextToken().toLong()
        answer += x * x
        if (x > 1L) {
            pq.add(Split(x, 2L, split(x, 2L) - split(x, 1L)))
        }
    }
    for (j in 1..k - n) {
        val s = pq.remove()
        answer += s.delta
        if (s.length > s.amt) {
            pq.add(Split(s.length, s.amt + 1L, split(s.length, s.amt + 1L) - split(s.length, s.amt)))
        }
    }
    println(answer)
}

data class Split(val length: Long, val amt: Long, val delta: Long)


import java.io.*
import java.util.*

fun main(args: Array<String>) {
    val sc = MyScanner()
    val out = PrintWriter(BufferedOutputStream(System.out))
    val n = sc.nextInt()
    val k = sc.nextInt()
    val pq = PriorityQueue(Comparator.comparingLong { x: Pairr ->
        change(
            x.l,
            x.p
        )
    })
    for (i in 0 until n) pq.add(Pairr(sc.nextInt().toLong(), 1))
    for (i in 0 until k - n) {
        val best = pq.poll()
        if (best.p < best.l) pq.add(Pairr(best.l, best.p + 1))
    }
    var res: Long = 0
    while (!pq.isEmpty()) {
        val x = pq.poll()
        res += split(x.l, x.p)
    }
    out.println(res)
    out.close()
}

internal class Pairr(var l: Long, var p: Long)

fun split(l: Long, p: Long): Long {
    val q = l / p
    return q * q * (p - l % p) + (q + 1) * (q + 1) * (l % p)
}

fun change(curL: Long, curP: Long): Long {
    return split(curL, curP + 1) - split(curL, curP)
}

//-----------MyScanner class for faster input----------
class MyScanner {
    var br: BufferedReader
    var st: StringTokenizer? = null
    operator fun next(): String {
        while (st == null || !st!!.hasMoreElements()) {
            try {
                st = StringTokenizer(br.readLine())
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
        return st!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }

    fun nextLong(): Long {
        return next().toLong()
    }

    fun nextDouble(): Double {
        return next().toDouble()
    }

    fun nextLine(): String {
        var str = ""
        try {
            str = br.readLine()
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return str
    }

    init {
        br = BufferedReader(InputStreamReader(System.`in`))
    }
}


import java.io.*
import java.util.*

    fun main(args: Array<String>) {
        val sc = MyScanner()
        val out = PrintWriter(BufferedOutputStream(System.out))
        val n = sc.nextInt()
        val k = sc.nextInt()
        val pq = PriorityQueue<P>()
        for (i in 0 until n) pq.add(P(sc.nextInt().toLong(), 1))
        for (i in 0 until k - n) {
            val best = pq.poll()
            if (best.p < best.l) pq.add(P(best.l, best.p + 1))
        }
        var res: Long = 0
        while (!pq.isEmpty()) {
            val x = pq.poll()
            res += split(x.l, x.p)
        }
        out.println(res)
        out.close()
    }

    fun split(l: Long, p: Long): Long {
        val q = l / p
        return q * q * (p - l % p) + (q + 1) * (q + 1) * (l % p)
    }

    fun change(curL: Long, curP: Long): Long {
        return split(curL, curP + 1) - split(curL, curP)
    }

    internal class P(var l: Long, var p: Long) : Comparable<P?> {
        override operator fun compareTo(other: P?): Int {
            if (other != null) {
                return java.lang.Long.compare(change(l, p), change(other.l, other.p))
            } else {
                return 1;
            }
        }
    }

    //-----------MyScanner class for faster input----------
    class MyScanner {
        var br: BufferedReader
        var st: StringTokenizer? = null
        operator fun next(): String {
            while (st == null || !st!!.hasMoreElements()) {
                try {
                    st = StringTokenizer(br.readLine())
                } catch (e: IOException) {
                    e.printStackTrace()
                }
            }
            return st!!.nextToken()
        }

        fun nextInt(): Int {
            return next().toInt()
        }

        fun nextLong(): Long {
            return next().toLong()
        }

        fun nextDouble(): Double {
            return next().toDouble()
        }

        fun nextLine(): String {
            var str = ""
            try {
                str = br.readLine()
            } catch (e: IOException) {
                e.printStackTrace()
            }
            return str
        }

        init {
            br = BufferedReader(InputStreamReader(System.`in`))
        }
    }


import java.io.BufferedOutputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintStream
import java.util.*
import kotlin.random.Random.Default.nextInt
import kotlin.time.ExperimentalTime

@ExperimentalStdlibApi
@ExperimentalTime
@ExperimentalUnsignedTypes
class Task {

    @Suppress("unused", "MemberVisibilityCanBePrivate")
    private class FastReader {
        private val br = BufferedReader(InputStreamReader(System.`in`))
        private var st = StringTokenizer("")

        fun readString(): String {
            while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
            return st.nextToken()
        }

        fun readInt() = readString().toInt()
        fun readLong() = readString().toLong()
        fun readDouble() = readString().toDouble()

        fun readStringArray(n: Int) = Array(n) { readString() }
        fun readIntArray(n: Int) = IntArray(n) { readInt() }
        fun readLongArray(n: Int) = LongArray(n) { readLong() }
        fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
    }

    private val fin: FastReader = FastReader()

    companion object {
        fun <T> Array<T>.swap(i: Int, j: Int) {
            val x = this[i]
            this[i] = this[j]
            this[j] = x
        }

        fun <T> MutableList<T>.swap(i: Int, j: Int) {
            val x = this[i]
            this[i] = this[j]
            this[j] = x
        }

        fun IntArray.swap(i: Int, j: Int) {
            val x = this[i]
            this[i] = this[j]
            this[j] = x
        }

        fun LongArray.swap(i: Int, j: Int) {
            val x = this[i]
            this[i] = this[j]
            this[j] = x
        }

        fun DoubleArray.swap(i: Int, j: Int) {
            val x = this[i]
            this[i] = this[j]
            this[j] = x
            sort()
        }

        fun IntArray.shuffleSort() {
            for (i in 1 until size) swap(i, nextInt(i + 1))
            sort()
        }

        fun LongArray.shuffleSort() {
            for (i in 1 until size) swap(i, nextInt(i + 1))
            sort()
        }

        fun DoubleArray.shuffleSort() {
            for (i in 1 until size) swap(i, nextInt(i + 1))
            sort()
        }

        fun println(a: IntArray) {
            if (a.isNotEmpty()) {
                print(a[0])
                for (i in 1 until a.size) {
                    print(' ')
                    print(a[i])
                }
            }
            println()
        }

        fun println(a: LongArray) {
            if (a.isNotEmpty()) {
                print(a[0])
                for (i in 1 until a.size) {
                    print(' ')
                    print(a[i])
                }
            }
            println()
        }

        fun println(a: Array<*>) {
            if (a.isNotEmpty()) {
                print(a[0])
                for (i in 1 until a.size) {
                    print(' ')
                    print(a[i])
                }
            }
            println()
        }

        fun println(a: List<*>) {
            if (a.isNotEmpty()) {
                print(a[0])
                for (i in 1 until a.size) {
                    print(' ')
                    print(a[i])
                }
            }
            println()
        }

        fun println(a: Iterable<*>) {
            val it = a.iterator()
            if (it.hasNext()) {
                print(it.next())
                while (it.hasNext()) {
                    print(' ')
                    print(it.next())
                }
            }
            println()
        }

        inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {
            var l = from
            var r = to + 1
            while (r - l > 1) {
                val m = (l + r) / 2
                if (f(m)) l = m
                else r = m
            }
            return l
        }

        inline fun binarySearch(f: (Int) -> Boolean): Int {
            var r = 1
            while (f(r)) r *= 2
            return binarySearch(r / 2, r, f)
        }

        fun <T : Comparable<T>> MutableList<T>.makeDistinct() {
            if (size <= 1) return
            sort()
            var sz = 1
            for (i in 1 until size) {
                if (this[i] != this[i - 1]) {
                    this[sz++] = this[i]
                }
            }
            while (size > sz) removeAt(size - 1)
        }

        inline fun ternary(from: Int, to: Int, lim: Int, f: (Int) -> Long): Long {
            var l = from
            var r = to
            while (r - l > lim) {
                val m1 = l + (r - l) / 3
                val m2 = r - (r - l) / 3
                if (f(m1) < f(m2)) r = m2
                else l = m1
            }
            return minOf(
                (from..minOf(to, from + lim)).minOf(f),
                (maxOf(from, to - lim)..to).minOf(f),
                (l..r).minOf(f)
            )
        }
    }

    fun solve() {
        data class Stick(val len: Int) {
            var curCount = 1

            fun cost(count: Int): Long {
                val countMore = len % count
                val countLess = count - countMore
                val defaultLen = (len / count).toLong()
                val costLess = defaultLen * defaultLen
                val costMore = (defaultLen + 1) * (defaultLen + 1)
                return costLess * countLess + costMore * countMore
            }

            fun profit() = cost(curCount) - cost(curCount + 1)
            fun isPossibleToSplit() = curCount < len
        }

        val n = fin.readInt()
        val k = fin.readInt()
        val a = Array(n) { Stick(fin.readInt()) }
        var cost = a.sumOf { it.cost(1) }
        val q = a.filter { it.isPossibleToSplit() }.toCollection(PriorityQueue(compareBy { -it.profit() }))
        repeat(k - n) {
            val s = q.poll()!!
            cost -= s.profit()
            if (++s.curCount < s.len) q += s
        }
        println(cost)
    }
}

@ExperimentalStdlibApi
@ExperimentalTime
@ExperimentalUnsignedTypes
fun main() {
    if (System.getProperty("ONLINE_JUDGE") != null)
        System.setOut(PrintStream(BufferedOutputStream(System.out)))
    Task().solve()
    System.out.flush()
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

private fun Int.sqr(): Long = this.toLong()*this

data class Carrot(val size: Int, val pieces: Int) {
    fun gain() : Long = cost() - cut().cost()

    fun cost() : Long {
        val sp = size / pieces
        val numLonger = size % pieces

        return sp.sqr()*(pieces - numLonger) + (sp+1).sqr()*numLonger
    }

    fun cut(): Carrot = Carrot(size, pieces+1)
}

fun main() {
    val (n, k) = readInts()

    val s = PriorityQueue(Comparator.comparing<Carrot, Long> { it.gain() }.reversed())
    s.addAll(readInts().map { Carrot(it, 1) })

    repeat(k - n) {
        val c = s.poll()
        s.add(c.cut())
    }

    println(s.map { it.cost() }.sum())
}


import java.util.*
import java.util.Comparator.comparing

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

private fun Int.sqr(): Long = this.toLong()*this

data class Carrot(val size: Int, val pieces: Int) {
    fun gain() : Long = cost() - cut().cost()

    fun cost() : Long {
        val sp = size / pieces
        val numLonger = size % pieces

        return sp.sqr()*(pieces - numLonger) + (sp+1).sqr()*numLonger
    }

    fun cut(): Carrot = Carrot(size, pieces+1)
}

fun main() {
    val (n, k) = readInts()

    val s = PriorityQueue(comparing<Carrot, Long> { it.gain() }.reversed())
    s.addAll(readInts().map { Carrot(it, 1) })

    repeat(k - n) {
        val c = s.poll()
        s.add(c.cut())
    }

    println(s.map { it.cost() }.sum())
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

fun main() {
    val (n, k) = readInts()
    val s = Splay<Int>()
    readInts().forEach { s.insert(it) }
    while (s.size < k) {
        val carrot = s.max()
        s.remove(carrot)
        s.insert(carrot/2)
        s.insert(carrot - carrot/2)
    }

    println(s.map { it.toLong()*it }.sum())
}

// https://en.wikipedia.org/wiki/Splay_tree

data class SplayNode<T : Comparable<T>>(
        val key: T,
        var left: SplayNode<T>? = null,
        var right: SplayNode<T>? = null,
        var parent: SplayNode<T>? = null,
        var size: Int = 1) {

    fun subtree_min(): SplayNode<T> {
        var node = this
        while (true) node = node.left ?: break
        return node
    }

    fun subtree_max(): SplayNode<T> {
        var node = this
        while (true) node = node.right ?: break
        return node
    }

    fun update() {
        size = 1 + left.size() + right.size()
    }
}

fun <T : Comparable<T>> SplayNode<T>?.size() = this?.size ?: 0

class Splay<T : Comparable<T>> : Collection<T> {
    private var root: SplayNode<T>? = null

    override val size: Int
        get() = root.size()

    override fun isEmpty(): Boolean = size == 0

    fun find(value: T): SplayNode<T>? {
        var n = root
        while (n != null) {
            n = when {
                value == n.key -> return n
                value > n.key -> n.right
                else -> n.left
            }
        }
        return null
    }

    override fun contains(element: T) = find(element) != null

    override fun containsAll(elements: Collection<T>): Boolean = elements.all { contains(it) }

    fun remove(v: T) {
        val z = find(v) ?: return
        splay(z)

        val zl = z.left
        val zr = z.right
        when {
            zl == null -> replace(z, zr)
            zr == null -> replace(z, zl)
            else -> {
                val y = zr.subtree_min()
                if (y.parent !== z) {
                    replace(y, y.right)
                    y.right = zr
                    y.right?.parent = y

                    var n = y.parent
                    while (n !== zr) {
                        n!!.update()
                        n = n.parent
                    }
                }
                replace(z, y)
                y.left = zl
                y.left?.parent = y

                zr.update()
                y.update()
            }
        }
    }

    fun insert(v: T) {
        var z = root
        var p: SplayNode<T>? = null

        while (z != null) {
            p = z
            p.size++
            z = if (v > z.key) z.right else z.left
        }

        z = SplayNode(v)
        z.parent = p
        when {
            p == null -> root = z
            p.key < z.key -> p.right = z
            else -> p.left = z
        }

        splay(z)
    }

    /**
     * @return number of elements between [start] (inclusive) and [end] (exclusive)
     */
    fun numEltsBetween(start: T, end: T): Int = rank(end) - rank(start)

    /**
     * @return position of [limit] within the structure, if it was sorted.
     * If [limit] is not present in the structure then position at which it would be inserted.
     * In either case that corresponds to the number of elements strictly smaller than [limit].
     */
    fun rank(limit: T): Int {
        var r = 0
        var node = root
        while (node != null) {
            node = if (limit <= node.key) {
                node.left
            } else {
                r += 1 + node.left.size()
                node.right
            }
        }
        return r
    }

    fun select(k: Int): T {
        var n = root ?: throw Error("select($k) in an empty Treap")
        var findK = k
        while (true) {
            val lSize = n.left.size()
            n = when {
                findK == lSize -> return n.key
                findK < lSize -> n.left!!
                else /* findK > lSize */ -> {
                    findK -= 1 + lSize
                    n.right!!
                }
            }
        }
    }

    fun max(): T = select(size-1)

    private fun replace(u: SplayNode<T>, v: SplayNode<T>?) {
        val parent = u.parent
        when {
            parent == null -> root = v
            u === parent.left -> parent.left = v
            else -> parent.right = v
        }
        v?.parent = u.parent
    }

    private fun left_rotate(x: SplayNode<T>) {
        val y = x.right
        if (y != null) {
            x.right = y.left
            y.left?.parent = x
            y.parent = x.parent
        }

        when {
            x.parent == null -> root = y
            x === x.parent?.left -> x.parent!!.left = y
            else -> x.parent!!.right = y
        }

        y?.left = x
        x.parent = y
        x.update()
        y?.update()
    }

    private fun right_rotate(x: SplayNode<T>) {
        val y = x.left
        if (y != null) {
            x.left = y.right
            y.right?.parent = x
            y.parent = x.parent
        }

        when {
            x.parent == null -> root = y
            x === x.parent?.left -> x.parent!!.left = y
            else -> x.parent!!.right = y
        }

        y?.right = x
        x.parent = y
        x.update()
        y?.update()
    }

    private fun splay(x: SplayNode<T>) {
        while (true) {
            val p = x.parent ?: break
            when {
                p.parent == null -> {
                    if (p.left === x) {
                        right_rotate(p)
                    } else {
                        left_rotate(p)
                    }
                }
                p.left === x && p.parent?.left === p -> {
                    right_rotate(p.parent!!)
                    right_rotate(x.parent!!)
                }
                p.right === x && p.parent?.right === p -> {
                    left_rotate(p.parent!!)
                    left_rotate(x.parent!!)
                }
                p.left === x && p.parent?.right === p -> {
                    right_rotate(p)
                    left_rotate(x.parent!!)
                }
                else -> {
                    left_rotate(p)
                    right_rotate(x.parent!!)
                }
            }
        }
    }

    override fun iterator(): Iterator<T> = iterator {
        val s: Stack<SplayNode<T>> = Stack()
        var node = root

        while (s.isNotEmpty() || node != null) {
            if (node != null) {
                s.push(node)
                node = node.left
            } else {
                node = s.pop()
                yield(node!!.key)
                node = node.right
            }
        }
    }
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

private fun Int.sqr(): Long = this.toLong()*this

data class Carrot(val size: Int, val pieces: Int) : Comparable<Carrot> {
    fun gain() : Long = cost() - cut().cost()

    fun cost() : Long {
        val sp = size / pieces
        val numLonger = size % pieces

        return sp.sqr()*(pieces - numLonger) + (sp+1).sqr()*numLonger
    }

    fun cut(): Carrot = Carrot(size, pieces+1)

    override fun compareTo(other: Carrot): Int = other.gain().compareTo(gain())
}

fun main() {
    val (n, k) = readInts()
    val s = PriorityQueue(readInts().map { Carrot(it, 1) })

    repeat(k - n) {
        val c = s.poll()
        s.add(c.cut())
    }

    println(s.map { it.cost() }.sum())
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

fun main() {
    val (n, k) = readInts()
    val s = Heap<Long>()
    readInts().forEachIndexed { idx, v -> s.add(idx.toLong(), v.toLong()) }

    var id = n.toLong()
    repeat(k - n) {
        val carrotId = s.max()
        val carrotLen = s.eltCounter[carrotId]!!

        s.remove(carrotId)
        s.add(id++,carrotLen/2)
        s.add(id++, carrotLen - carrotLen/2)
    }

    println(s.eltCounter.values.map { it.toBigInteger()*it.toBigInteger() }.reduce { l, r -> l + r })
}

class Heap<T> {
    // element -> counter
    val eltCounter : MutableMap<T, Long> = mutableMapOf()
    // counter -> elements with that counter
    val countersAt : SortedMap<Long, MutableSet<T>> = sortedMapOf()

    fun add(elt: T, count: Long) {
        assert(!eltCounter.containsKey(elt))
        eltCounter[elt] = count
        val current = countersAt[count]
        if (current == null) {
            countersAt[count] = mutableSetOf(elt)
        } else {
            current.add(elt)
        }
    }

    fun remove(elt: T) {
        val counter = eltCounter[elt]
        eltCounter.remove(elt)
        val s = countersAt[counter]!!
        s.remove(elt)
        if (s.isEmpty()) {
            countersAt.remove(counter);
        }
    }

    fun getAtCounter(c: Long) = countersAt[c]!!.first()
    fun max() = getAtCounter(countersAt.lastKey())
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

fun main() {
    val (n, k) = readInts()
    val s = Heap<Int>(mapOf())
    readInts().forEachIndexed { idx, v -> s.add(idx, v.toLong()) }

    var id = n
    while (s.size() < k) {
        val carrotId = s.max()
        val carrotLen = s.eltCounter[carrotId]!!

        s.remove(carrotId)
        s.add(id++,carrotLen/2)
        s.add(id++, carrotLen - carrotLen/2)
    }

    println(s.eltCounter.values.map { it*it }.sum())
}

class Heap<T>(elements: Map<T, Long>) {
    // element -> counter
    val eltCounter : MutableMap<T, Long> = mutableMapOf()
    // counter -> elements with that counter
    val countersAt : SortedMap<Long, MutableSet<T>> = sortedMapOf()

    fun size() = eltCounter.size

    init {
        elements.forEach { add(it.key, it.value) }
    }

    fun add(elt: T, count: Long) {
        assert(!eltCounter.containsKey(elt))
        eltCounter[elt] = count
        countersAt.merge(count, mutableSetOf(elt)) { s1, s2 -> s1.addAll(s2); s1 }
    }

    fun remove(elt: T) {
        val counter = eltCounter[elt]
        eltCounter.remove(elt)
        val s = countersAt[counter]!!
        s.remove(elt)
        if (s.isEmpty()) {
            countersAt.remove(counter);
        }
    }

    fun getAtCounter(c: Long) = countersAt[c]!!.first()
    fun max() = getAtCounter(countersAt.lastKey())
}


import java.util.*

fun readInts() = readLine()!!.split(' ').map { it.toInt() }

fun main() {
    val (n, k) = readInts()
    val s = Heap<Long>()
    readInts().forEachIndexed { idx, v -> s.add(idx.toLong(), v.toLong()) }

    var id = n.toLong()
    repeat(k - n) {
        val carrotId = s.max()
        val carrotLen = s.eltCounter[carrotId]!!

        s.remove(carrotId)
        s.add(id++,carrotLen/2)
        s.add(id++, carrotLen - carrotLen/2)
    }

    println(s.eltCounter.values.map { it*it }.sum())
}

class Heap<T> {
    // element -> counter
    val eltCounter : MutableMap<T, Long> = mutableMapOf()
    // counter -> elements with that counter
    val countersAt : SortedMap<Long, MutableSet<T>> = sortedMapOf()

    fun add(elt: T, count: Long) {
        assert(!eltCounter.containsKey(elt))
        eltCounter[elt] = count
        val current = countersAt[count]
        if (current == null) {
            countersAt[count] = mutableSetOf(elt)
        } else {
            current.add(elt)
        }
    }

    fun remove(elt: T) {
        val counter = eltCounter[elt]
        eltCounter.remove(elt)
        val s = countersAt[counter]!!
        s.remove(elt)
        if (s.isEmpty()) {
            countersAt.remove(counter);
        }
    }

    fun getAtCounter(c: Long) = countersAt[c]!!.first()
    fun max() = getAtCounter(countersAt.lastKey())
}


import java.io.*;
import java.util.*;

public class e {
    public static PrintWriter out;
    public static void main(String[] Args) throws Exception{
        FS sc = new FS(System.in);
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = sc.nextInt();
        int k = sc.nextInt()-n;
        PriorityQueue<Thing> pq = new PriorityQueue<Thing>();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            Thing nT = new Thing(sc.nextInt());
            ans += nT.w;
            pq.add(nT);
        }
        while (k-->0) {
            Thing cur = pq.poll();
            ans -= cur.w;
            cur.split();
            ans += cur.w;
            pq.add(cur);
        }
        out.println(ans);
        out.close();
    }
    public static class Thing implements Comparable<Thing> {
        long w;
        long sortVal;
        int cuts;
        long total;
        Thing(int val) {
            total = val;
            cuts = 1;
            w = val;
            w = w * w;
            sortVal = getNextW() - w;
        }
        long getNextW() {
            int newCuts = cuts + 1;
            long small = total / newCuts;
            long big = small + 1;
            long bigC = total % newCuts;
            long smallC = newCuts - bigC;
            return (smallC * small * small + bigC * big * big);
        }
        void split() {
            w = getNextW();
            cuts++;
            sortVal = getNextW() - w;
        }
        public int compareTo(Thing o) {
            return Long.compare(sortVal, o.sortVal);
        }
    }
    public static class FS {
        BufferedReader br;
        StringTokenizer st;
        FS(InputStream in) throws Exception {
            br = new BufferedReader(new InputStreamReader(in));
            st = new StringTokenizer(br.readLine());
        }
        String next() throws Exception {
            if (st.hasMoreTokens())
                return st.nextToken();
            st = new StringTokenizer(br.readLine());
            return next();
        }
        int nextInt() throws Exception {
            return Integer.parseInt(next());
        }
        long nextLong() throws Exception {
            return Long.parseLong(next());
        }
    }
}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FQ5 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int k=scan.nextInt();
            long[] arr=new long[n];
            long[] divs=new long[n];
            long sum=0;
            for(int i=0;i<n;i++){
                arr[i]=scan.nextInt();
                sum+=arr[i];
            }
            long req=sum/k;
            if(sum%k!=0){
                req++;
            }
            long more=k;
            for(int i=0;i<n;i++){
                divs[i]=arr[i]/req;
                more-=divs[i];
            }
            trip[] mods=new trip[n];
            for(int i=0;i<n;i++){
                mods[i]=new trip(i,arr[i],divs[i]);
            }
            Arrays.sort(mods);
            for(int i=0;i<n&&more>0;i++){
                divs[mods[i].x]++;
                more--;
            }
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=val(arr[i],divs[i]);
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class trip implements Comparable<trip>{
        int x;
        long y;
        long z;
        trip(int x,long y,long z) {
            this.x = x;
            this.y = y;
            this.z=z;
        }

        @Override
        public int compareTo(trip o) {
            if(this.z==0){
                return -1;
            }
            if(o.z==0){
                return 1;
            }
            long v1=val(this.y,this.z)+val(o.y,o.z+1);
            long v2=val(this.y,this.z+1)+val(o.y,o.z);
            if(v1>=v2){
                return -1;
            }
            return 1;
        }
    }
    static long val(long len,long grp){
        long sq=len/grp;
        long gr=len%grp;
        long val=0;
        val+=sq*sq*(grp-gr);
        sq++;
        val+=sq*sq*gr;
        return val;
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FQ5 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int k=scan.nextInt();
            long[] arr=new long[n];
            long[] divs=new long[n];
            Arrays.fill(divs,1);
            long sum=0;
            for(int i=0;i<n;i++){
                arr[i]=scan.nextInt();
                sum+=arr[i];
            }
            long req=sum/k;
            if(sum%k!=0){
                req++;
            }
            long more=k-n;
            for(int i=0;i<n&&more>0;i++){
                long xtra=arr[i]/req-1;
                divs[i]+=Math.min(xtra,more);
                more-=Math.min(xtra,more);
            }
            trip[] mods=new trip[n];
            for(int i=0;i<n;i++){
                mods[i]=new trip(i,arr[i],divs[i]);
            }
            Arrays.sort(mods);
            for(int i=0;i<n&&more>0;i++){
                divs[mods[i].x]++;
                more--;
            }
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=val(arr[i],divs[i]);
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class trip implements Comparable<trip>{
        int x;
        long y;
        long z;
        trip(int x,long y,long z) {
            this.x = x;
            this.y = y;
            this.z=z;
        }

        @Override
        public int compareTo(trip o) {
            if(this.z==0){
                return -1;
            }
            if(o.z==0){
                return 1;
            }
            long v1=val(this.y,this.z)+val(o.y,o.z+1);
            long v2=val(this.y,this.z+1)+val(o.y,o.z);
            if(v1>=v2){
                return -1;
            }
            return 1;
        }
    }
    static long val(long len,long grp){
        long sq=len/grp;
        long gr=len%grp;
        long val=0;
        val+=sq*sq*(grp-gr);
        sq++;
        val+=sq*sq*gr;
        return val;
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class FQ5 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int k=scan.nextInt();
            long[] arr=new long[n];
            long[] divs=new long[n];
            long sum=0;
            for(int i=0;i<n;i++){
                arr[i]=scan.nextInt();
                sum+=arr[i];
            }
            long req=sum/k;
            if(sum%k!=0){
                req++;
            }
            long more=k;
            for(int i=0;i<n;i++){
                divs[i]=arr[i]/req;
                more-=divs[i];
            }
            Pair[] mods=new Pair[n];
            for(int i=0;i<n;i++){
                mods[i]=new Pair(i,arr[i]%req);
            }
            Arrays.sort(mods);
            for(int i=0;i<n&&more>0;i++){
                divs[mods[i].x]++;
                more--;
            }
            long ans=0;
            for(int i=0;i<n;i++){
                long sq=arr[i]/divs[i];
                long gr=arr[i]%divs[i];
                ans+=sq*sq*(divs[i]-gr);
                sq++;
                ans+=sq*sq*(gr);
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    static class Pair implements Comparable<Pair>{
        int x;
        long y;
        Pair(int x,long y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if(this.y>=o.y){
                return -1;
            }
            return 1;
        }
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}