// 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=Math.max(arr[i]/req-1,0);
                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];
            for(int i=0;i<n;i++){
                arr[i]=scan.nextLong();
            }
            long[] divs=new long[n];
            Arrays.fill(divs,1);
            long more=k-n;
            PriorityQueue<trip> pq=new PriorityQueue<>(n,new mc());
            for(int i=0;i<n;i++){
                pq.add(new trip(i,arr[i],1));
            }
            while(more>0){
                trip cur=pq.remove();
                divs[cur.x]++;
                cur.z++;
                pq.add(cur);
                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 mc implements Comparator<trip>{
        @Override
        public int compare(trip o1, trip o2) {
            long v1=val(o1.y,o1.z)+val(o2.y,o2.z+1);
            long v2=val(o1.y,o1.z+1)+val(o2.y,o2.z);
            if(v1>=v2){
                return -1;
            }
            return 1;
        }
    }
    static class trip{
        int x;
        long y;
        long z;
        trip(int x,long y,long z) {
            this.x = x;
            this.y = y;
            this.z=z;
        }
    }
    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();
            int[] arr=new int[n];
            PriorityQueue<Long> pq=new PriorityQueue<>(Collections.reverseOrder());
            for(int i=0;i<n;i++){
                pq.add(scan.nextLong());
            }
            while(pq.size()<k){
                long top=pq.remove();
                pq.add(top/2);
                if(top%2!=0){
                    pq.add(top/2+1);
                }else{
                    pq.add(top/2);
                }
            }
            long ans=0;
            while(!pq.isEmpty()){
                long cur=pq.remove();
                ans+=cur*cur;
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    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;
            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;
        }
    }
}


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

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 2e18 + 20;
    static final int MOD = (int) 1e9 + 7;

    static class Pair {
        int l, p;

        Pair(int l, int p) {
            this.l = l;
            this.p = p;
        }
    }

    static long f(int l, int p) {
        if (l < p)
            return oo;
        int l1 = l / p;
        int l2 = l1 + 1;
        return (long) l1 * l1 * (p - l % p) + (long) l2 * l2 * (l % p);
    }

    static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        PriorityQueue<Pair> pq = new PriorityQueue<>((o1, o2) -> {
            long delta1 = f(o1.l, o1.p) - f(o1.l, o1.p + 1);
            long delta2 = f(o2.l, o2.p) - f(o2.l, o2.p + 1);
            return -Long.compare(delta1, delta2);
        });

        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += (long) a[i] * a[i];
            pq.add(new Pair(a[i], 1));
        }

        for (int i = n; i < k; i++) {
            Pair fi = pq.poll();
            ans -= f(fi.l, fi.p) - f(fi.l, fi.p + 1);
            pq.add(new Pair(fi.l, fi.p + 1));
        }

        out.println(ans);

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);
//        fileInputOutput();

        int T = 1;
//        T = in.nextInt();
        while (T-- > 0)
            solve();

        out.flush();
        out.close();
    }

    static void fileInputOutput() {
        try {
            in = new FastReader("input.txt");
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    static void runInThread() {
        Thread thread = new Thread(null, () -> {
            int T = 1;
//            T = in.nextInt();
            while (T-- > 0)
                solve();
        }, "thread1", 1 << 28);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


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

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 2e18 + 20;
    static final int MOD = (int) 1e9 + 7;

    static void shuffle(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int j = i + rand.nextInt(arr.length - i);
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }

    static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        int[] a = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum += a[i];
        }

        shuffle(a);
        Arrays.sort(a);

        int mid = (int) (sum / k);

        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] < mid) {
                ans += (long) a[i] * a[i];
                sum -= a[i];
                mid = (int) (sum / (n - i - 1));
            } else {
                int mid2 = mid + 1;
                int k2 = k - i;
                int cnt = (int) (sum % k2);
                for (int j = 0; j < k2 - cnt; j++) {
                    ans += (long) mid * mid;
                }
                for (int j = 0; j < cnt; j++) {
                    ans += (long) mid2 * mid2;
                }
                break;
            }
        }

        out.println(ans);

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);
//        fileInputOutput();

        int T = 1;
//        T = in.nextInt();
        while (T-- > 0)
            solve();

        out.flush();
        out.close();
    }

    static void fileInputOutput() {
        try {
            in = new FastReader("input.txt");
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    static void runInThread() {
        Thread thread = new Thread(null, () -> {
            int T = 1;
//            T = in.nextInt();
            while (T-- > 0)
                solve();
        }, "thread1", 1 << 28);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


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

/*
polyakoff
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int oo = (int) 1e9 + 10;
    static final long OO = (long) 2e18 + 20;
    static final int MOD = (int) 1e9 + 7;

    static void shuffle(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int j = i + rand.nextInt(arr.length - i);
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
    }

    static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        int[] a = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum += a[i];
        }

        shuffle(a);
        Arrays.sort(a);

        int mid = (int) (sum / k);

        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] < mid) {
                ans += (long) a[i] * a[i];
                sum -= a[i];
                mid = (int) (sum / (k - i - 1));
            } else {
                int mid2 = mid + 1;
                int k2 = k - i;
                int cnt = (int) (sum % k2);
                for (int j = 0; j < k2 - cnt; j++) {
                    ans += (long) mid * mid;
                }
                for (int j = 0; j < cnt; j++) {
                    ans += (long) mid2 * mid2;
                }
                break;
            }
        }

        out.println(ans);

    }

    public static void main(String[] args) {
        in = new FastReader();
        out = new PrintWriter(System.out);
//        fileInputOutput();

        int T = 1;
//        T = in.nextInt();
        while (T-- > 0)
            solve();

        out.flush();
        out.close();
    }

    static void fileInputOutput() {
        try {
            in = new FastReader("input.txt");
            out = new PrintWriter(new FileOutputStream("output.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    static void runInThread() {
        Thread thread = new Thread(null, () -> {
            int T = 1;
//            T = in.nextInt();
            while (T-- > 0)
                solve();
        }, "thread1", 1 << 28);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader() {
            this(System.in);
        }
        FastReader(String file) throws FileNotFoundException {
            this(new FileInputStream(file));
        }
        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }
        String nextLine() {
            String line;
            try {
                line = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      int n = sc.nextInt();
      int k = sc.nextInt();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         int a = sc.nextInt();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         p.b++;
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         int div = p.a/p.b;
         int num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      int a, b;
      public Pair(int x, int y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      long n = sc.nextLong();
      long k = sc.nextLong();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextLong();
         pq.add(new Pair(a, 1L)) ;
      }
      for(int i = 0; i < k-n; i++){
         Pair p = pq.poll();
         if(p.b < p.a){
            p.b++;
         }
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         ans += calc(p.a, p.b);
      }
      out.println(ans);
      out.close();
   }
   static long calc(long a, long b){
      long ans = 0;
      long div = a/b;
      long num = (a)%(b);
      ans += num*(div+1)*(div+1);
      ans += (b-num)*(div*div);
      return ans;
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         long val = calc(this.a, this.b) - calc(this.a, this.b+1);
         long oval = calc(o.a, o.b) - calc(o.a, o.b+1);
         if(val < oval){
            return 1;
         }
         else if(val == oval){
            return 0;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      int n = sc.nextInt();
      int k = sc.nextInt();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextInt();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         if(p.b == p.a) break;
         p.b++;
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         long div = p.a/p.b;
         long num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      int n = sc.nextInt();
      int k = sc.nextInt();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         int a = sc.nextInt();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         if(p.b == p.a) break;
         p.b++;
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         int div = p.a/p.b;
         int num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      int a, b;
      public Pair(int x, int y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      long n = sc.nextLong();
      long k = sc.nextLong();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextLong();
         pq.add(new Pair(a, 1L)) ;
      }
      for(int i = 0; i < k-n; i++){
         Pair p = pq.poll();
         if(p.b < p.a){
            p.b++;
         }
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         long div = p.a/p.b;
         long num = (p.a)%(p.b);
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = (double)(this.a)/(double)(this.b);
         double oval =(double)(o.a)/(double)(o.b);
         if(val < oval){
            return 1;
         }
         else if(val == oval){
            return 0;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      long n = sc.nextLong();
      long k = sc.nextLong();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextLong();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         if(p.b < p.a){
            p.b++;
         }
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         long div = p.a/p.b;
         long num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else if(val == oval){
            return 0;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      int n = sc.nextInt();
      int k = sc.nextInt();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextInt();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         if(p.b < p.a){
            p.b++;
         }
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         long div = p.a/p.b;
         long num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


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

public class E
{
   public static void main(String[] args) throws IOException
   {
      FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
      long n = sc.nextLong();
      long k = sc.nextLong();
      PriorityQueue<Pair> pq = new PriorityQueue<Pair>();
      for(int i = 0; i < n; i++){
         long a = sc.nextLong();
         pq.add(new Pair(a, 1)) ;
      }
      k -= n;
      for(int i = 0; i < k; i++){
         Pair p = pq.poll();
         if(p.b < p.a){
            p.b++;
         }
         pq.add(p);
      }
      long ans = 0;
      while(!pq.isEmpty()){
         Pair p = pq.poll();
         long div = p.a/p.b;
         long num = p.a%p.b;
         ans += num*(div+1)*(div+1);
         ans += (p.b-num)*(div*div);
      }
      out.println(ans);
      out.close();
   }
   static class Pair implements Comparable<Pair>{
      long a, b;
      public Pair(long x, long y){
         this.a = x;
         this.b = y;
      }
      public int compareTo(Pair o){
         double val = this.a/this.b;
         double oval = o.a/o.b;
         if(val < oval){
            return 1;
         }
         else{
            return -1;
         }
      }
   }
   static class FastScanner {
      private int BS = 1 << 16;
      private char NC = (char) 0;
      private byte[] buf = new byte[BS];
      private int bId = 0, size = 0;
      private char c = NC;
      private double cnt = 1;
      private BufferedInputStream in;

      public FastScanner() {
         in = new BufferedInputStream(System.in, BS);
      }

      public FastScanner(String s) {
         try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
         } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
         }
      }

      private char getChar() {
         while (bId == size) {
            try {
               size = in.read(buf);
            } catch (Exception e) {
               return NC;
            }
            if (size == -1)
               return NC;
            bId = 0;
         }
         return (char) buf[bId++];
      }

      public int nextInt() {
         return (int) nextLong();
      }

      public int[] nextInts(int N) {
         int[] res = new int[N];
         for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
         }
         return res;
      }

      public long[] nextLongs(int N) {
         long[] res = new long[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextLong();
         }
         return res;
      }

      public long nextLong() {
         cnt = 1;
         boolean neg = false;
         if (c == NC) c = getChar();
         for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
         }
         long res = 0;
         for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
         }
         return neg ? -res : res;
      }

      public double nextDouble() {
         double cur = nextLong();
         return c != '.' ? cur : cur + nextLong() / cnt;
      }

      public double[] nextDoubles(int N) {
         double[] res = new double[N];
         for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
         }
         return res;
      }

      public String next() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c > 32) {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public String nextLine() {
         StringBuilder res = new StringBuilder();
         while (c <= 32) c = getChar();
         while (c != '\n') {
            res.append(c);
            c = getChar();
         }
         return res.toString();
      }

      public boolean hasNext() {
         if (c > 32)
            return true;
         while (true) {
            c = getChar();
            if (c == NC)
               return false;
            else if (c > 32)
               return true;
         }
      }
   }

   static void ASSERT(boolean assertion, String message) {
      if (!assertion) throw new AssertionError(message);
   }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            ECarrotsForRabbits solver = new ECarrotsForRabbits();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECarrotsForRabbits {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            int[] a = new int[n];
            in.populate(a);
            long now = 0;
            PriorityQueue<Item> pq = new PriorityQueue<>(n, (x, y) -> -Long.compare(x.profit, y.profit));
            int cut = k - n;
            for (int i = 0; i < n; i++) {
                now += pow2(a[i]);
                pq.add(new Item(profit(a[i], 0) - profit(a[i], 1), 1, i));
            }
            while (cut > 0) {
                Item head = pq.remove();
                now -= head.profit;
                cut--;
                pq.add(new Item(profit(a[head.index], head.cut) - profit(a[head.index], head.cut + 1), head.cut + 1, head.index));
            }

            out.println(now);
        }

        public long profit(long a, long x) {
            x++;
            if (a <= x) {
                return a;
            }
            long avg = a / x;
            long more = a % x;
            return pow2(avg) * (x - more) + pow2(avg + 1) * more;
        }

        public long pow2(long a) {
            return a * a;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        public void populate(int[] data) {
            for (int i = 0; i < data.length; i++) {
                data[i] = readInt();
            }
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class Item {
        long profit;
        int cut;
        int index;

        public Item(long profit, int cut, int index) {
            this.profit = profit;
            this.cut = cut;
            this.index = index;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.AbstractQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt() - N;
            long[] cost = new long[N];
            long[] tot = new long[N];
            Arrays.fill(tot, 1);
            long[] a = new long[N];
            long[] chg = new long[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
                cost[i] = a[i] * a[i];
                chg[i] = getSplit(a[i], ++tot[i]) - cost[i];
            }
            PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {

                public int compare(Integer integer, Integer t1) {
                    return Long.compare(chg[integer], chg[t1]);
                }
            });
            for (int i = 0; i < N; i++) {
                queue.add(i);
            }
            while (K-- > 0) {
                int next = queue.remove();
                cost[next] += chg[next];
                chg[next] = getSplit(a[next], ++tot[next]) - cost[next];
                queue.add(next);
            }
            long ans = 0;
            for (int i = 0; i < N; i++) {
                ans += cost[i];
            }
            out.println(ans);
        }

        long getSplit(long S, long P) {
            long mid = S / P;
            return mid * mid * (P - (S - mid * P)) + (S - mid * P) * (mid + 1) * (mid + 1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		int n =fr.nextInt() ,k =fr.nextInt() ,left ,mid ,right ,ctr ,max ,i ;

 		long j ,sum =0 ;

 		ArrayList<Integer> a =new ArrayList<>() ,dummy =new ArrayList<>() ;

 		for (i = 0 ; i<n ; ++i)
 			a.add(fr.nextInt()) ;

 		while (!a.isEmpty()) {
 			left =right =1 ;

 			max =0 ;

 			n =a.size() ;

 			for (i =0 ; i<n ; ++i)
 				right =Math.max(right , a.get(i)) ;

 			while (left <= right) {
	 			mid =(left + right)/2 ;

	 			ctr =0 ;

	 			for (i =0 ; i<n ; ++i) {
	 				ctr += (a.get(i)/mid) ;

	 				ctr += (a.get(i)%mid == 0 ? 0 : 1) ;
	 			}

	 			if (ctr <= k)
	 				max =mid ;

	 			if (ctr == k)	break;

	 			if (ctr < k)	right =mid-1 ;
	 			else	left =mid+1 ;
	 		}

	 		for (i =0 ; i<n ; ++i) {
	 			ctr =a.get(i)/max ;

	 			while (ctr-- > 0) {
	 				j =max ;

	 				sum += (j*j) ;

	 				--k ;
	 			}

	 			ctr =a.get(i)%max ;

	 			if (ctr != 0)
	 				dummy.add(ctr) ;
	 		}

	 		a.clear() ;

	 		a.addAll(dummy) ;

	 		dummy.clear() ;
 		}

		op.println(sum) ;	op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements()))
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		int n =fr.nextInt() ,k =fr.nextInt() ,carrot[][] =new int[n][2] ,cut =k-n ,i ;

 		PriorityQueue<pair> pq =new PriorityQueue<>(n , new cmp()) ;

 		long j ,sum =0 ;

 		pair obj ;

 		for (i =0 ; i<n ; ++i) {
 			carrot[i][0] =fr.nextInt() ;

 			carrot[i][1] =1 ;

 			j =findTime(carrot[i][0] , carrot[i][1]) - findTime(carrot[i][0] , carrot[i][1]+1) ;

 			pq.add(new pair(j , i)) ;
 		}

 		while (cut-- > 0) {
 			obj =pq.poll() ;

 			i =obj.second ;

 			++carrot[i][1] ;

 			j =findTime(carrot[i][0] , carrot[i][1]) - findTime(carrot[i][0] , carrot[i][1]+1) ;

 			obj.first =j ;

 			pq.add(obj) ;
 		}

 		for (i =0 ; i<n ; ++i) {
 			j =findTime(carrot[i][0] , carrot[i][1]) ;

 			sum += j ;
 		}

		op.println(sum) ;	op.flush();	op.close();
	}
	static long findTime (long L , long P) {
		long w =L/P ,P2 =L%P ;

		long time =(w*w) * (P - P2) ;

		++w ;

		time += ((w*w) * P2) ;

		return time ;
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements()))
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}
class pair {
	long first ;

	int second ;

	pair (long f , int s) {
		first =f ;

		second =s ;
	}
}
class cmp implements Comparator<pair> {
	public int compare (pair A , pair B) {
		long diff =B.first - A.first ;

		if (diff == 0)	return 0 ;

		if (diff < 0)	return -1 ;

		return 1 ;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		int n =fr.nextInt() ,k =fr.nextInt() ,i ;

 		long sum =0 ,j ;

 		if (k==n) {
 			for (i =0 ; i<n ; ++i) {
 				j =fr.nextLong() ;

 				sum += (j*j) ;
 			}

 			op.println(sum) ;
 		}
 		else {
 			PriorityQueue<Long> q =new PriorityQueue<>(k , Collections.reverseOrder()) ;

 			for (i =0 ; i<n ; ++i)	q.add(fr.nextLong()) ;

 			k -= n ;

 			while (k-- > 0) {
 				j =q.poll() ;

 				q.add(j/2l) ;

 				q.add((j/2l + (j&1l))) ;
 			}

 			while (!q.isEmpty()) {
 				j =q.poll() ;

 				sum += (j*j) ;
 			}

 			op.println(sum) ;
 		}

		op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements()))
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.*;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);

 		int n =fr.nextInt() ,k =fr.nextInt() ,a[] =new int[n] ,left ,mid ,right =0 ,ctr ,min =0 ,i ;

 		long j ,sum =0 ;

 		for (i = 0 ; i<n ; ++i) {
 			a[i] =fr.nextInt() ;

 			right =Math.max(right , a[i]) ;
 		}

 		left =1 ;

 		while (left <= right) {
 			mid =(left + right)/2 ;

 			ctr =0 ;

 			for (i =0 ; i<n ; ++i) {
 				ctr += (a[i]/mid) ;

 				ctr += (a[i]%mid == 0 ? 0 : 1) ;
 			}

 			if (ctr <= k) {
 				min =mid ;

 				right =mid-1 ;
 			}
 			else
 				left =mid+1 ;
 		}

 		PriorityQueue<Integer> q =new PriorityQueue<>(k , Collections.reverseOrder()) ;

 		for (i =0 ; i<n ; ++i) {
 			ctr =a[i]/min ;

 			while (ctr-- > 0)
 				q.add(min) ;

 			ctr =a[i]%min ;

 			if (ctr != 0)
 				q.add(ctr) ;
 		}

 		while (q.size() < k) {
 			i =q.poll() ;

 			q.add(i/2) ;

			q.add((i/2 + (i&1))) ;
 		}

 		while (!q.isEmpty()) {
			j =q.poll() ;

			sum += (j*j) ;
		}

		op.println(sum) ;	op.flush();	op.close();
	}
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br =new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st==null || (!st.hasMoreElements()))
			{
				try
				{
					st =new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}

			}
			return st.nextToken();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


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

public class E {
	public static void main(String[] args) throws IOException {

		/**/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		/*/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/e.in"))));
		/**/

		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] shark = new long[n];
		for (int i = 0; i < n; ++i)
			shark[i] = sc.nextInt();
		long ans = 0;
		int[] div = new int[n];

		PriorityQueue<Long> pq = new PriorityQueue<>();
		for (int i = 0; i < n; ++i) {
			div[i] = 1;
			ans += calc(shark[i],1);
			long diff = calc(shark[i],1)-calc(shark[i],2);
			pq.add(-(diff*n+i));
		}
		int rab = n;
		while (rab < k) {
			long rem = -pq.remove();
			int ind = (int)(rem%n);
			long cd = rem/n;
			ans -= cd;
			++rab;
			++div[ind];
			long nd = calc(shark[ind],div[ind])-calc(shark[ind],div[ind]+1);
			pq.add(-(nd*n+ind));
		}
		System.out.println(ans);
	}

	public static long calc(long size, long count) {
		long base = size/count;
		long xtr = size%count;
		return count*base*base+xtr*(base*2+1);
	}
}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

 /*

 6666666666666			 6666666666666
 6						 6
 6						 6
 6						 6
 6						 6
 6                       6
 6666666666666           6666666666666
 6		     6           6		     6
 6			 6	         6			 6
 6			 6           6			 6
 6		     6	         6		     6
 6666666666666           6666666666666

 */

// Please name your class Main
public class Main {

	//static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    /*static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}*/

	static Scanner in = new Scanner(System.in);

	public static void main (String[] args) throws java.lang.Exception {

		//InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int T=1;

		for(int t=0;t<T;t++){
			int n=Int();
			int k=Int();
			int A[]=new int[n];
			for(int i=0;i<n;i++){
				A[i]=Int();
			}

			Solution sol=new Solution();
			sol.solution(A,k);
		}

		out.flush();
	}

	public static int Int(){
		return in.nextInt();
	}
	public static String Str(){
		return in.next();
	}
}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	public void solution(int A[],int k){
		long res=0;
		if(A.length==1){//cut evenly as possible
			int mod=A[0]%k;
			long avg=A[0]/k;
			for(int i=0;i<mod;i++){
				res+=((avg+1)*(avg+1));
			}
			for(int i=0;i<k-mod;i++){
				res+=(avg*avg);
			}
			msg(res+"");
			return;
		}

		PriorityQueue<Integer>pq=new PriorityQueue<>((a,b)->{
			return b-a;
		});
		for(int i:A)pq.add(i);

		while(pq.size()<k){
			int top=pq.poll();
			int pre=pq.peek();
			int need=k-pq.size();

			int cut=top/pre;
			if(cut==1){
				int half=top/2;
				pq.add(half);
				pq.add(top-half);
			}else{
				int go=-1;
				if(cut>=need){
					go=need;
				}else{
					go=cut;
				}

				int mod=top%go;
				int avg=A[0]/go;
				for(int i=0;i<mod;i++){
					pq.add((avg+1));
				}
				for(int i=0;i<k-mod;i++){
					pq.add((avg));
				}
			}
		}

		//60 60 ->30 30 30 30
		//60 60 -> 20 20 20 60

		while(pq.size()!=0){
			long top=pq.poll();
			res+=(top*top);
		}
		msg(res+"");
	}

	public void swap(int A[],int l,int r){
		int t=A[l];
		A[l]=A[r];
		A[r]=t;
	}

	public long C(long fact[],int i,int j){ // C(20,3)=20!/(17!*3!)
		// take   a/b     where a=20!  b=17!*3!
		if(j>i)return 0;
		if(j==0)return 1;
		long mod=1000000007;
		long a=fact[i];
		long b=((fact[i-j]%mod)*(fact[j]%mod))%mod;
		BigInteger B= BigInteger.valueOf(b);
		long binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();
		return ((a)*(binverse%mod))%mod;
	}

	//map operation
	public void put(Map<Integer,Integer>map,int i){
		if(!map.containsKey(i))map.put(i,0);
		map.put(i,map.get(i)+1);
	}

	public void delete(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void remove(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public void msg1(String s){
		System.out.print(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}

    class Node{//what the range would be for that particular node
		boolean state=false;
        int l=0,r=0;
		int ll=0,rr=0;
        public Node(boolean state){
            this.state=state;
        }
    }

	class Seg1{
			int A[];
			public Seg1(int A[]){
				this.A=A;
			}

			public void update(int left,int right,int val,int s,int e,int id){
				if(left<0||right<0||left>right)return;
				if(left==s&&right==e){

					A[id]+=val;
					return;
				}
				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(left>=mid+1){
					update(left,right,val,mid+1,e,id*2+2);
				}else if(right<=mid){
					update(left,right,val,s,mid,id*2+1);
				}else{
					update(left,mid,val,s,mid,id*2+1);
					update(mid+1,right,val,mid+1,e,id*2+2);
				}
			}

			public int query(int i,int add,int s,int e,int id){

				if(s==e&&i==s){
					return A[id]+add;
				}

				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(i>=mid+1){
					return query(i,A[id]+add,mid+1,e,id*2+2);
				}else{
					return query(i,A[id]+add,s,mid,id*2+1);
				}
			}
	}

	 class MaxFlow{

		  public static List<Edge>[] createGraph(int nodes) {
			List<Edge>[] graph = new List[nodes];
			for (int i = 0; i < nodes; i++)
			  graph[i] = new ArrayList<>();
			return graph;
		  }

		  public static void addEdge(List<Edge>[] graph, int s, int t, int cap) {
			graph[s].add(new Edge(t, graph[t].size(), cap));
			graph[t].add(new Edge(s, graph[s].size() - 1, 0));
		  }

		  static boolean dinicBfs(List<Edge>[] graph, int src, int dest, int[] dist) {
			Arrays.fill(dist, -1);
			dist[src] = 0;
			int[] Q = new int[graph.length];
			int sizeQ = 0;
			Q[sizeQ++] = src;
			for (int i = 0; i < sizeQ; i++) {
			  int u = Q[i];
			  for (Edge e : graph[u]) {
				if (dist[e.t] < 0 && e.f < e.cap) {
				  dist[e.t] = dist[u] + 1;
				  Q[sizeQ++] = e.t;
				}
			  }
			}
			return dist[dest] >= 0;
		  }

		  static int dinicDfs(List<Edge>[] graph, int[] ptr, int[] dist, int dest, int u, int f) {
			if (u == dest)
			  return f;
			for (; ptr[u] < graph[u].size(); ++ptr[u]) {
			  Edge e = graph[u].get(ptr[u]);
			  if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
				int df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));
				if (df > 0) {
				  e.f += df;
				  graph[e.t].get(e.rev).f -= df;
				  return df;
				}
			  }
			}
			return 0;
		  }

		  public static int maxFlow(List<Edge>[] graph, int src, int dest) {
			int flow = 0;
			int[] dist = new int[graph.length];
			while (dinicBfs(graph, src, dest, dist)) {
			  int[] ptr = new int[graph.length];
			  while (true) {
				int df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);
				if (df == 0)
				  break;
				flow += df;
			  }
			}
			return flow;
		  }

	 }

	 	 class Edge {
			int t, rev, cap, f;

			public Edge(int t, int rev, int cap) {
			  this.t = t;
			  this.rev = rev;
			  this.cap = cap;
			}
		  }

    class Seg{
        int l,r;
        int min=Integer.MAX_VALUE;
        Seg left=null,right=null;
		long sum=0;long cnt=0;
        public Seg(int l,int r){
            this.l=l;
            this.r=r;

        }
        public long[] query(int s,int e){
            if(l==s&&r==e){
                return new long[]{sum,cnt};
            }
            int mid=l+(r-l)/2; //left :  to mid-1,

			if(left==null)left=new Seg(l,mid);
			if(right==null)right=new Seg(mid+1,r);

			if(e<=mid){
                return left.query(s,e);
            }
            else if(s>=mid+1){
                return right.query(s,e);
            }else{
				long A[]=left.query(s,mid);
				long B[]=right.query(mid+1,e);
				return new long[]{A[0]+B[0],A[1]+B[1]};

            }
        }

        public void update(int index,int v){
			sum+=v;
			cnt++;
            if(l==r&&l==index){
                return;
            }
            int mid=l+(r-l)/2;
            if(index<=mid){
				if(left==null)left=new Seg(l,mid);
                left.update(index,v);
            }else{
				if(right==null)right=new Seg(mid+1,r);
                right.update(index,v);
            }

        }
    }


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

 /*

 6666666666666			 6666666666666
 6						 6
 6						 6
 6						 6
 6						 6
 6                       6
 6666666666666           6666666666666
 6		     6           6		     6
 6			 6	         6			 6
 6			 6           6			 6
 6		     6	         6		     6
 6666666666666           6666666666666

 */

// Please name your class Main
public class Main {

	//static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    /*static int read() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static String readString() throws IOException {
        in.nextToken();
        return in.sval;
	}*/

	static Scanner in = new Scanner(System.in);

	public static void main (String[] args) throws java.lang.Exception {

		//InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int T=1;

		for(int t=0;t<T;t++){
			int n=Int();
			int k=Int();
			int A[]=new int[n];
			for(int i=0;i<n;i++){
				A[i]=Int();
			}

			Solution sol=new Solution();
			sol.solution(A,k);
		}

		out.flush();
	}

	public static int Int(){
		return in.nextInt();
	}
	public static String Str(){
		return in.next();
	}
}

class Solution{
	//constant variable
	final int MAX=Integer.MAX_VALUE;
	final int MIN=Integer.MIN_VALUE;
	//Set<Integer>adjecent[];
	//////////////////////////////

	public void solution(int A[],int k){
		long res=0;
		if(A.length==1){//cut evenly as possible
			int mod=A[0]%k;
			long avg=A[0]/k;
			for(int i=0;i<mod;i++){
				res+=((avg+1)*(avg+1));
			}
			for(int i=0;i<k-mod;i++){
				res+=(avg*avg);
			}
			msg(res+"");
			return;
		}

		//k segment

		PriorityQueue<long[]>pq=new PriorityQueue<>((a,b)->{
			return Long.compare(b[2]-b[3],a[2]-a[3]);
		});

		int cnt=A.length;
		for(long i:A){
			long a=i*i;
			res+=a;
			long half1=i/2;
			long half2=i/2+1;

			long total=(half1)*(half1)+(half2)*(half2);
			pq.add(new long[]{i,2,a,total});
		}

		while(cnt!=k){
			long top[]=pq.poll();
			long num=top[0];
			long a=top[1];

			long precost=top[2];
			long curcost=top[3];

			res-=precost;
			res+=curcost;

			long newcost=0;
			long mod=num%(a+1);
			long avg=num/(a+1);

			newcost=newcost+(avg+1)*(avg+1)*mod+(a+1-mod)*(avg)*(avg);

			pq.add(new long[]{num,a+1,curcost,newcost});
			cnt++;
		}

		msg(res+"");
	}

	public void swap(int A[],int l,int r){
		int t=A[l];
		A[l]=A[r];
		A[r]=t;
	}

	public long C(long fact[],int i,int j){ // C(20,3)=20!/(17!*3!)
		// take   a/b     where a=20!  b=17!*3!
		if(j>i)return 0;
		if(j==0)return 1;
		long mod=1000000007;
		long a=fact[i];
		long b=((fact[i-j]%mod)*(fact[j]%mod))%mod;
		BigInteger B= BigInteger.valueOf(b);
		long binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();
		return ((a)*(binverse%mod))%mod;
	}

	//map operation
	public void put(Map<Integer,Integer>map,int i){
		if(!map.containsKey(i))map.put(i,0);
		map.put(i,map.get(i)+1);
	}

	public void delete(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	/*public void tarjan(int p,int r){
		if(cut)return;
		List<Integer>childs=adjecent[r];
		dis[r]=low[r]=time;
		time++;

		//core for tarjan
		int son=0;
		for(int c:childs){
			if(ban==c||c==p)continue;
			if(dis[c]==-1){
				son++;
				tarjan(r,c);
				low[r]=Math.min(low[r],low[c]);
				if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
					cut=true;
					return;
				}
			}else{
				if(c!=p){
					low[r]=Math.min(low[r],dis[c]);
				}
			}
		}

	}*/

	//helper function I would use
	public void remove(Map<Integer,Integer>map,int i){
		map.put(i,map.get(i)-1);
		if(map.get(i)==0)map.remove(i);
	}

	public void ascii(String s){
		for(char c:s.toCharArray()){
			System.out.print((c-'a')+" ");
		}
		msg("");
	}

	public int flip(int i){
		if(i==0)return 1;
		else return 0;
	}

	public boolean[] primes(int n){
		boolean A[]=new boolean[n+1];
		for(int i=2;i<=n;i++){
			if(A[i]==false){
				for(int j=i+i;j<=n;j+=i){
					A[j]=true;
				}
			}
		}
		return A;
	}

	public void msg(String s){
		System.out.println(s);
	}

	public void msg1(String s){
		System.out.print(s);
	}

	public int[] kmpPre(String p){
		int pre[]=new int[p.length()];
		int l=0,r=1;
		while(r<p.length()){
			if(p.charAt(l)==p.charAt(r)){
				pre[r]=l+1;
				l++;r++;
			}else{
				if(l==0)r++;
				else l=pre[l-1];
			}
		}
		return pre;
	}

	public boolean isP(String s){
		int l=0,r=s.length()-1;
		while(l<r){
			if(s.charAt(l)!=s.charAt(r))return false;
			l++;r--;
		}
		return true;
	}

	public int find(int nums[],int x){//union find => find method
		if(nums[x]==x)return x;
		int root=find(nums,nums[x]);
		nums[x]=root;
		return root;
	}

	public int get(int A[],int i){
		if(i<0||i>=A.length)return 0;
		return A[i];
	}
	public int[] copy1(int A[]){
		int a[]=new int[A.length];
		for(int i=0;i<a.length;i++)a[i]=A[i];
		return a;
	}

	public void print1(int A[]){
		for(long i:A)System.out.print(i+" ");
		System.out.println();
	}
	public void print2(int A[][]){
		for(int i=0;i<A.length;i++){
			for(int j=0;j<A[0].length;j++){
				System.out.print(A[i][j]+" ");
			}System.out.println();
		}
	}

	public int min(int a,int b){
		return Math.min(a,b);
	}

	public int[][] matrixdp(int[][] grid) {
        if(grid.length==0)return new int[][]{};
        int res[][]=new int[grid.length][grid[0].length];
        for(int i=0;i<grid.length;i++){
            for(int j=0;j<grid[0].length;j++){
                res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
            }
        }
        return res;
    }

    public int get(int grid[][],int i,int j){
        if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
        return grid[i][j];
    }

	public int[] suffixArray(String s){
		int n=s.length();
		Suffix A[]=new Suffix[n];

		for(int i=0;i<n;i++){
			A[i]=new Suffix(i,s.charAt(i)-'a',0);
		}

		for(int i=0;i<n;i++){
			if(i==n-1){
				A[i].next=-1;
			}else{
				A[i].next=A[i+1].rank;
			}
		}
		Arrays.sort(A);

		for(int len=4;len<A.length*2;len<<=1){
			int in[]=new int[A.length];
			int rank=0;
			int pre=A[0].rank;
			A[0].rank=rank;
			in[A[0].index]=0;
			for(int i=1;i<A.length;i++){//rank for the first two letter
				if(A[i].rank==pre&&A[i].next==A[i-1].next){
					pre=A[i].rank;
					A[i].rank=rank;
				}else{
					pre=A[i].rank;
					A[i].rank=++rank;
				}
				in[A[i].index]=i;
			}

			for(int i=0;i<A.length;i++){
				int next=A[i].index+len/2;
				if(next>=A.length){
					A[i].next=-1;
				}else{
					A[i].next=A[in[next]].rank;
				}
			}

			Arrays.sort(A);
		}

		int su[]=new int[A.length];
		for(int i=0;i<su.length;i++){
			su[i]=A[i].index;
		}
		return su;
	}

}

//suffix array Struct
class Suffix implements Comparable<Suffix>{
	int index;
	int rank;
	int next;
	public Suffix(int i,int rank,int next){
		this.index=i;
		this.rank=rank;
		this.next=next;
	}

	@Override
	public int compareTo(Suffix other) {
		if(this.rank==other.rank){
			return this.next-other.next;
		}
		return this.rank-other.rank;
	}

	public String toString(){
		return this.index+"   "+this.rank+"   "+this.next+"  ";
	}
}

class Wrapper implements Comparable<Wrapper>{
	int spf;int cnt;
	public Wrapper(int spf,int cnt){
		this.spf=spf;
		this.cnt=cnt;
	}

	@Override
	public int compareTo(Wrapper other) {
		return this.spf-other.spf;
	}
}

    class Node{//what the range would be for that particular node
		boolean state=false;
        int l=0,r=0;
		int ll=0,rr=0;
        public Node(boolean state){
            this.state=state;
        }
    }

	class Seg1{
			int A[];
			public Seg1(int A[]){
				this.A=A;
			}

			public void update(int left,int right,int val,int s,int e,int id){
				if(left<0||right<0||left>right)return;
				if(left==s&&right==e){

					A[id]+=val;
					return;
				}
				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(left>=mid+1){
					update(left,right,val,mid+1,e,id*2+2);
				}else if(right<=mid){
					update(left,right,val,s,mid,id*2+1);
				}else{
					update(left,mid,val,s,mid,id*2+1);
					update(mid+1,right,val,mid+1,e,id*2+2);
				}
			}

			public int query(int i,int add,int s,int e,int id){

				if(s==e&&i==s){
					return A[id]+add;
				}

				int mid=s+(e-s)/2; //[s,mid] [mid+1,e]

				if(i>=mid+1){
					return query(i,A[id]+add,mid+1,e,id*2+2);
				}else{
					return query(i,A[id]+add,s,mid,id*2+1);
				}
			}
	}

	 class MaxFlow{

		  public static List<Edge>[] createGraph(int nodes) {
			List<Edge>[] graph = new List[nodes];
			for (int i = 0; i < nodes; i++)
			  graph[i] = new ArrayList<>();
			return graph;
		  }

		  public static void addEdge(List<Edge>[] graph, int s, int t, int cap) {
			graph[s].add(new Edge(t, graph[t].size(), cap));
			graph[t].add(new Edge(s, graph[s].size() - 1, 0));
		  }

		  static boolean dinicBfs(List<Edge>[] graph, int src, int dest, int[] dist) {
			Arrays.fill(dist, -1);
			dist[src] = 0;
			int[] Q = new int[graph.length];
			int sizeQ = 0;
			Q[sizeQ++] = src;
			for (int i = 0; i < sizeQ; i++) {
			  int u = Q[i];
			  for (Edge e : graph[u]) {
				if (dist[e.t] < 0 && e.f < e.cap) {
				  dist[e.t] = dist[u] + 1;
				  Q[sizeQ++] = e.t;
				}
			  }
			}
			return dist[dest] >= 0;
		  }

		  static int dinicDfs(List<Edge>[] graph, int[] ptr, int[] dist, int dest, int u, int f) {
			if (u == dest)
			  return f;
			for (; ptr[u] < graph[u].size(); ++ptr[u]) {
			  Edge e = graph[u].get(ptr[u]);
			  if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
				int df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));
				if (df > 0) {
				  e.f += df;
				  graph[e.t].get(e.rev).f -= df;
				  return df;
				}
			  }
			}
			return 0;
		  }

		  public static int maxFlow(List<Edge>[] graph, int src, int dest) {
			int flow = 0;
			int[] dist = new int[graph.length];
			while (dinicBfs(graph, src, dest, dist)) {
			  int[] ptr = new int[graph.length];
			  while (true) {
				int df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);
				if (df == 0)
				  break;
				flow += df;
			  }
			}
			return flow;
		  }

	 }

	 	 class Edge {
			int t, rev, cap, f;

			public Edge(int t, int rev, int cap) {
			  this.t = t;
			  this.rev = rev;
			  this.cap = cap;
			}
		  }

    class Seg{
        int l,r;
        int min=Integer.MAX_VALUE;
        Seg left=null,right=null;
		long sum=0;long cnt=0;
        public Seg(int l,int r){
            this.l=l;
            this.r=r;

        }
        public long[] query(int s,int e){
            if(l==s&&r==e){
                return new long[]{sum,cnt};
            }
            int mid=l+(r-l)/2; //left :  to mid-1,

			if(left==null)left=new Seg(l,mid);
			if(right==null)right=new Seg(mid+1,r);

			if(e<=mid){
                return left.query(s,e);
            }
            else if(s>=mid+1){
                return right.query(s,e);
            }else{
				long A[]=left.query(s,mid);
				long B[]=right.query(mid+1,e);
				return new long[]{A[0]+B[0],A[1]+B[1]};

            }
        }

        public void update(int index,int v){
			sum+=v;
			cnt++;
            if(l==r&&l==index){
                return;
            }
            int mid=l+(r-l)/2;
            if(index<=mid){
				if(left==null)left=new Seg(l,mid);
                left.update(index,v);
            }else{
				if(right==null)right=new Seg(mid+1,r);
                right.update(index,v);
            }

        }
    }