// 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){
		int N=A.length;
		int res=0;

		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 half=top/2;
			pq.add(half);
			pq.add(top-half);
		}

		while(pq.size()!=0){
			int 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;
		}

		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();

			//System.out.println(pq);

			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=top/go;

				for(int i=0;i<mod;i++){
					pq.add((avg+1));
				}
				for(int i=0;i<go-mod;i++){
					pq.add((avg));
				}
			}
		}

		//System.out.println(pq);
		//60 60 ->30 30 30 30
		//60 60 -> 20 20 20 60

		while(pq.size()!=0){
			long top=pq.poll();
			//msg1(top+"  ");
			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-half1;

			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];

			//msg(num+"  "+a+"  "+precost+"  "+curcost);

			res-=precost;
			res+=curcost;

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

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

			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);
            }

        }
    }


/**
 * author: derrick20
 * created: 10/17/20 6:31 PM
 */

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

public class CarrotsRedo implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new CarrotsRedo(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        long K = sc.nextLong();
        PriorityQueue<Pair> pairs = new PriorityQueue<>(Comparator.comparingLong(p -> p.delta));
        for (int i = 0; i < N; i++) {
            pairs.add(new Pair(sc.nextInt(), 1));
        }
        K -= N;
        /*
        Key idea: Think about incremental benefits from adding a split.
        The key for us to employ a greedy approach is for there to be some
        sort of internal order to the values we're picking. In this case,
        we have that the DELTA as we increase the number of splits is
        a decreasing (we should observe it's essentially the derivative
        of 1 / k with some constants there)
         */
        while (K > 0) {
            Pair p = pairs.poll();
            pairs.add(new Pair(p.x, p.k + 1));
            K--;
        }
        long ans = 0;
        for (Pair p : pairs) {
            ans += cost(p.x, p.k);
        }
        out.println(ans);
        out.close();
    }

    static long cost(long x, long k) {
        return k * (x / k) * (x / k) + (2 * (x / k) + 1) * (x % k);
    }

    static class Pair {
        long x, k;
        long delta;
        public Pair(long val, long splits) {
            x = val; k = splits;
            delta = cost(x, k + 1) - cost(x, k);
        }
    }

    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);
    }

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


/**
 * author: derrick20
 * created: 10/17/20 11:11 AM
 */

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

public class CarrotsRabbits implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new CarrotsRabbits(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] a = sc.nextLongs(N);
        long curr = 0;
        for (long v : a) {
            curr += v * v;
        }
        long lo = 0;
        long hi = (long) 1e18;
        // find maximum min improvement amount
        // x^2 - (sum of small squares)
        // maximum is N * sum [ai^2] = 10^17
        long ans = curr;
        K -= N;
        while (lo < hi) {
            // find the smallest maxDelta so that everyone can cut enough
            // so they're next increment is <= maxDelta
            // 01
            long mid = (lo + hi) / 2;
            long val = doable(a, K, mid);
//            System.out.println("Found " + val + " at " + mid);
            if (val != -1) {
                ans = val;
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        out.println(ans);
        out.close();
    }

    static long doable(long[] a, int K, long maxDelta) {
        long ans = 0;
//        System.out.println("Forcing maxDelta <= " + maxDelta);
        for (int i = 0; i < a.length; i++) {
            // minimum cuts possible so that delta <= maxDelta
            int lo = 0;
            int hi = K;
            boolean found = false;
            while (lo <= hi) {
                // 01
                int mid = (lo + hi) / 2;
//                System.out.println("Delta = " + delta(a[i], mid + 1) + " for split = " + (mid + 1));
                if (delta(a[i], mid + 1) <= maxDelta) {
                    hi = mid;
                    found = true;
                    if (lo == hi) {
                        ans += calc(a[i], lo + 1);
                        break;
                    }
                } else {
                    lo = mid + 1;
                }
            }
            // potentially, our delta is always bigger than maxDelta
            // so, the validity is 0000
            if (!found) return -1;
//            System.out.println("Cuts for " + a[i] + " = " + lo);
            K -= lo;
        }
        return K >= 0 ? ans : -1;
    }

    static long delta(long x, long k) {
        return -calc(x, k + 1) + calc(x, k);
    }

    static long calc(long x, long k) {
        return k * (x / k) * (x / k) + (2 * (x / k) + 1) * (x % k);
    }

    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);
    }

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


/**
 * author: derrick20
 * created: 10/17/20 11:11 AM
 */

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

public class CarrotsRabbits implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new CarrotsRabbits(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

//        generate();
//        long start = System.currentTimeMillis();
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] a = sc.nextLongs(N);
//        int N = (int) 1e5;
//        int K = (int) 1e5;
//        System.out.println(N + " " + K);
//        long[] a = new long[N];
//        for (int i = 0; i < N; i++) {
//            int v = (int) (Math.random() * 1e6) + 1;
//            a[i] = v;
//            System.out.print(v + " ");
//        }
        long curr = 0;
        for (long v : a) {
            curr += v * v;
        }
        long lo = 0;
        long hi = (long) 1e18;
        // [ai^2] = 10^12
        long ans = curr;
        K -= N;
        while (lo < hi) {
            // find the smallest maxDelta so that everyone can cut enough
            // so they're next increment is <= maxDelta
            // 01
            long mid = (lo + hi) / 2;
            long val = doable(a, K, mid);
//            System.out.println("Found " + val + " at " + mid);
            if (val != -1) {
                ans = val;
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        out.println(ans);
//        out.println("Time = " + (System.currentTimeMillis() - start) / 1000.0);
        out.close();
    }

    static void generate() {
        int N = (int) 1e5;
        int K = (int) 1e5;
        System.out.println(N + " " + K);
        for (int i = 0; i < N; i++) {
            int v = (int) (Math.random() * 1e6) + 1;
            System.out.print(v + " ");
        }
    }
    static long doable(long[] a, int K, long maxDelta) {
        long ans = 0;
//        System.out.println("Forcing maxDelta <= " + maxDelta);
        for (int i = 0; i < a.length; i++) {
            // minimum cuts possible so that delta <= maxDelta
            int lo = 0;
            int hi = K;
            boolean found = false;
            while (lo <= hi) {
                // 01
                int mid = (lo + hi) / 2;
//                System.out.println("Delta = " + delta(a[i], mid + 1) + " for split = " + (mid + 1));
                if (delta(a[i], mid + 1) <= maxDelta) {
                    hi = mid;
                    found = true;
                    if (lo == hi) {
                        ans += calc(a[i], lo + 1);
                        break;
                    }
                } else {
                    lo = mid + 1;
                }
            }
            // potentially, our delta is always bigger than maxDelta
            // so, the validity is 0000
            if (!found) return -1;
//            System.out.println("Cuts for " + a[i] + " = " + lo);
            K -= lo;
            if (K < 0) return -1;
        }
        return ans;
    }

    static long delta(long x, long k) {
        return -calc(x, k + 1) + calc(x, k);
    }

    static long calc(long x, long k) {
        return k * (x / k) * (x / k) + (2 * (x / k) + 1) * (x % k);
    }

    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);
    }

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


/**
 * author: derrick20
 * created: 10/17/20 11:11 AM
 */

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

public class CarrotsRabbits implements Runnable {
    public static void main(String[] args) throws Exception {
        new Thread(null, new CarrotsRabbits(), ": )", 1 << 28).start();
    }

    public void run() {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

//        generate();
//        long start = System.currentTimeMillis();
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] a = sc.nextLongs(N);
//        int N = (int) 1e5;
//        int K = (int) 1e5;
//        System.out.println(N + " " + K);
//        long[] a = new long[N];
//        for (int i = 0; i < N; i++) {
//            int v = (int) (Math.random() * 1e6) + 1;
//            a[i] = v;
//            System.out.print(v + " ");
//        }
        long lo = 0;
        long hi = (long) 1e12;
        // [ai^2] = 10^12
        long ans = 0;
        K -= N;
        while (lo < hi) {
            // find the smallest maxDelta so that everyone can cut enough
            // so they're next increment is <= maxDelta
            // 01
            long mid = (lo + hi) / 2;
            long val = doable(a, K, mid);
//            System.out.println("Found " + val + " at " + mid);
            if (val != -1) {
                ans = val;
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        out.println(ans);
//        out.println("Time = " + (System.currentTimeMillis() - start) / 1000.0);
//        out.println(ops);
        out.close();
    }

//    static int ops = 0;

    static void generate() {
        int N = (int) 1e5;
        int K = (int) 1e5;
        System.out.println(N + " " + K);
        for (int i = 0; i < N; i++) {
            int v = (int) (Math.random() * 1e6) + 1;
            System.out.print(v + " ");
        }
    }
    static long doable(long[] a, int K, long maxDelta) {
        long ans = 0;
//        System.out.println("Forcing maxDelta <= " + maxDelta);
        for (int i = 0; i < a.length; i++) {
            // minimum cuts possible so that delta <= maxDelta
            int lo = 0;
            int hi = K;
            boolean found = false;
            while (lo <= hi) {
                // 01
                int mid = (lo + hi) / 2;
//                long next = calc(a[i], mid + 2);
                // no way?
                long x = a[i];
                long k = mid + 2;
                long div = x / k;
                long next = k * div * div + (2 * div + 1) * (x % k);
                k = mid + 1;
                div = x / k;
                long curr = k * div * div + (2 * div + 1) * (x % k); // calc(a[i], mid + 1);
                if (curr - next <= maxDelta) {
                    hi = mid;
                    found = true;
                    if (lo == hi) {
                        ans += curr;
                        break;
                    }
                } else {
                    lo = mid + 1;
                }
            }
            // potentially, our delta is always bigger than maxDelta
            // so, the validity is 0000
            if (!found) return -1;
//            System.out.println("Cuts for " + a[i] + " = " + lo);
            K -= lo;
            if (K < 0) return -1;
        }
        return ans;
    }

//    static long delta(long x, long k) {
//        return -calc(x, k + 1) + calc(x, k);
//    }

//    static long calc(long x, long k) {
//        ops++;
//        return k * (x / k) * (x / k) + (2 * (x / k) + 1) * (x % k);
//    }

    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);
    }

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


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

public class E2 {
	static PrintWriter out = new PrintWriter(System.out);

	static int N,K;
	static long[] ar;

	static final boolean debug = false;

	public static void main(String[] args) {
		FS in = new FS();

		N = in.nextInt();
		K = in.nextInt();
		ar = new long[N];
		for(int i = 0; i < N; i++) ar[i] = in.nextInt();

		// Initially take 1 of everything
		long res = 0;
		for(long ll : ar) res += ll*ll;

		int cur[] = new int[N];
		Arrays.fill(cur, 1);

		// Get deltas
		long delta[] = new long[N];
		for(int i = 0; i < N; i++) {
			delta[i] = delta(ar[i], 1);
		}

		int curHave = N;

		if(debug) System.out.println(cost(5,1)+" "+cost(5,2));

		PriorityQueue<Integer> pq = new PriorityQueue<>((a,b) -> Long.compare(delta[a], delta[b]));
		for(int i = 0; i < N; i++) pq.add(i);

		if(debug) System.out.println("CURRES = "+res+" HAVE + "+curHave);

		while(curHave < K) {
			int id = pq.poll();
			res += delta[id];

			if(debug) System.out.println(" id = "+id+" del = "+delta[id]);

			curHave++;
			cur[id]++;
			delta[id] = delta(ar[id], cur[id]);
			pq.add(id);
		}

		out.println(res);

		out.close();
	}

	static long delta(long val, int cur) {
		return cost(val, cur+1) - cost(val, cur);
	}

	static long cost(long val, int cur) {
		long each = val/cur;
		long extra = val%cur;

		long normal = cur - extra;

		return normal*each*each + extra*((each+1)*(each+1));
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}

}


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

public class E {
	static PrintWriter out = new PrintWriter(System.out);

	static int N,K;
	static long[] ar;

	static final boolean debug = true;

	public static void main(String[] args) {
		FS in = new FS();

		N = in.nextInt();
		K = in.nextInt();
		ar = new long[N];
		for(int i = 0; i < N; i++) ar[i] = in.nextInt();

		int lo = 1, hi = 1_000_005;
		int best = hi;
		while(lo <= hi) {
			int mid = (lo+hi)/2;
			if(go(mid) != -1) { // possible, try lower
				hi = mid-1;
				best = Math.min(best, mid);
			}
			else {
				lo = mid+1;
			}
		}

//		System.out.println(best);

		out.println(go(best));

		out.close();
	}

	// returns -1 if not possible, cost otherwise
	static long go(long x) {
		int curHave = 0;
		long cost = 0;

		ArrayDeque<Long> q = new ArrayDeque<Long>();
		for(int i = 0; i < N; i++) {
			if(ar[i] <= x) {
				curHave++;
				cost += ar[i]*ar[i];
			}
			else q.add(ar[i]);
		}

		while(!q.isEmpty()) {
			if(curHave > K) return -1; // Too many things

			long v = q.poll();

			v -= x;
			curHave++;
			cost += x*x;

			if(v < x) {
				curHave++;
				cost += v*v;
			}
			else {
				q.add(v);
			}
		}

		if(curHave > K) return -1;
		return cost;
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}

}


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

/**
 *
 * @author True
 */

public class Main {
    public static Long calc(int n, int k) {
        Long s = Long.valueOf(n/k);
        Long t = Long.valueOf(n%k);
        return t*(s+1)*(s+1) + (k-t)*s*s;
    }
    public static int[] a = new int[100010];
    public static int[] b = new int[100010];
    public static void main(String args[]) {
        Scanner in;
        PrintStream out;
        in = new Scanner (new BufferedInputStream(System.in));
        out = System.out;
        try{
            in = new Scanner(new FileInputStream("java.in"));
            out = new PrintStream("java.out");
        } catch (FileNotFoundException e) {}
        TreeSet<Long> st;
        st = new TreeSet<>();
        int n = in.nextInt(), k = in.nextInt();
        Long tmp = (long)1000000;
        Long ans = (long)0;
        for(int i=1; i<=n; i++) {
            b[i] = 1;
            a[i] = in.nextInt();
            Long f = calc(a[i], 2) - calc(a[i], 1);
            f *= tmp;
            f += i;
            st.add(f);
            ans += (long)a[i]*a[i];
        }
        for(int i=0; i<k-n; i++) {
            Long f = st.first();
            int g = (int)(f%tmp);
            if(g<0) g+=tmp;
            ans += (f-g)/tmp;
            b[g]++;
            st.remove(f);
            f = calc(a[g], b[g]+1) - calc(a[g], b[g]);
            f *= tmp;
            f += g;
            st.add(f);
        }
        out.println(ans);
    }
}


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

public class E {

  void solve() throws IOException {
    int n = nextInt();
    int k = nextInt();
    PriorityQueue<Group> queue = new PriorityQueue<>();
    for (int i = 0; i < n; i++) {
      queue.add(new Group(nextInt()));
    }
    while (n < k) {
      Group g = queue.poll();
      g.addCut();
      queue.add(g);
      n++;
    }
    long ans = queue.stream().mapToLong(Group::calcScore).sum();
    out.println(ans);
  }

  class Group implements Comparable<Group> {
    int len;
    int cut;
    long improve;

    public Group(int len) {
      this.len = len;
      this.cut = 1;
      if (len == 1) {
        improve = 0;
      } else {
        improve = calcScore(1) - calcScore(2);
      }
    }

    public void addCut() {
      cut++;
      if (len == cut) {
        improve = 0;
      } else {
        improve = calcScore(cut) - calcScore(cut + 1);
      }
    }

    public long calcScore() {
      return calcScore(cut);
    }

    public long calcScore(int cut) {
      int l1 = len / cut;
      if (len % cut == 0) {
        return l1 * 1L * l1 * cut;
      }
      int l2 = l1 + 1;
      int c2 = len % cut;
      int c1 = cut - c2;
      return l1 * 1L * l1 * c1 + l2 * 1L * l2 * c2;
    }

    @Override
    public int compareTo(Group o) {
      return Long.compare(o.improve, improve);
    }
  }

  public static void main(String[] args) throws IOException {
    new E().run();
  }

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  String nextToken() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }
}


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

public class Main{
	static long val(long len,long pieces) {
		long cur=len/pieces;
		long rem=len%pieces;
		long hasCur=pieces-rem;
		long ans=(cur*1l*cur*hasCur);
		ans+=((cur+1)*1l*(cur+1)*rem);
		return ans;
	}
	//the decrease if we cut (pieces+1) out of len instead of (pieces)
	static long decrease(long len,long pieces) {
		return val(len, pieces)-val(len, pieces+1);
	}
	static void main() throws Exception{
		int n=sc.nextInt();long k=sc.nextInt();
		long[]in=sc.longArr(n);
		long ans=0;
		PriorityQueue<long[]>pq=new PriorityQueue<long[]>((x,y)->Long.compare(y[0], x[0]));
		for(int i=0;i<n;i++) {
			ans+=(in[i]*in[i]);
			pq.add(new long[] {decrease(in[i], 1),in[i],1});
		}
		while(k-->n) {
			long[]biggestDecrease=pq.poll();
			ans-=biggestDecrease[0];
			long len=biggestDecrease[1],pieces=biggestDecrease[2]+1;
			pq.add(new long[] {decrease(len, pieces),len,pieces});
		}

		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		sc=new MScanner(System.in);
		pw = new PrintWriter(System.out);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


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

public class Main {
	static BufferedReader br;
	static PrintWriter pr;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int sum(long n)
	{
		int ans=0;
		while(n!=0)
		{
			ans=ans+(int)(n%10);
			n=n/10;
		}
		return ans;
	}
	static long gcd(long x,long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		if(x>y)
			return gcd(x%y,y);
		else
			return gcd(x,y%x);
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		pr=new PrintWriter(new OutputStreamWriter(System.out));
		int cases=1;
		while(cases!=0)
		{
			cases--;
			int[]ar=split();
			int n=ar[0];
			int k=ar[1];
			int[]arr=split();
			PriorityQueue<Pair> pq=new PriorityQueue<>();
		    for(int i=0;i<n;i++)
		    {
		        pq.add(new Pair(arr[i],1));
		    }
		    for(int i=0;i<k-n;i++)
		    {
		        Pair p=pq.poll();
		        pq.add(new Pair(p.len,p.parts+1));
		    }
		    long ans=0;
		    for(Pair p:pq)
		    {
		        //System.out.println(p.len+" "+p.parts);
		        ans=ans+p.val(p.len,p.parts);
		    }
		    System.out.println(ans);
		}
	}
}
class Pair implements Comparable<Pair>
{
    int len;
    int parts;
    public Pair(int len,int parts)
    {
        this.len=len;
        this.parts=parts;
    }
    public long val(int l,int p)
    {
        long x=l/p;
        long y=x+1;
        long cnt1=l%p;
        long cnt2=p-cnt1;
        return cnt2*x*x+cnt1*y*y;
    }
    public long imp()
    {
        return val(this.len,this.parts)-val(this.len,this.parts+1);
    }
    public int compareTo(Pair p)
    {
        if(this.imp()>p.imp())
        return -1;
        else if(this.imp()<p.imp())
        return 1;
        return 0;
    }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 0;
  int HAS_TESTCASES = 0;
  String INPUT = "3 6\n" + "5 3 1";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Integer> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    pri_queue.addAll(a);
    int cuts = k - n;
    while (cuts-- > 0) {
      int divide = pri_queue.poll();
      if (divide == 1)
        break;
      if (divide % 2 == 1) {
        pri_queue.add(divide / 2);
        pri_queue.add(divide / 2 + 1);
      } else {
        pri_queue.add(divide / 2);
        pri_queue.add(divide / 2);
      }
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      int v = pri_queue.poll();
      result = result + (long) v * v;
    }
    System.out.println(result);
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 1;
  int HAS_TESTCASES = 0;
  String INPUT = "1 3\n" + "1000000";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      for (Integer v : c.getPieces()) {
        result += (long) v * v;
      }
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int nr_pieces = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
    }
    public void cut_carrot() {
      nr_pieces++;
      int div = size / nr_pieces;
      if (size % nr_pieces > 0) {
        largest_piece = div + 1;
      } else {
        largest_piece = div;
      }
    }
    public List<Integer> getPieces() {
      List<Integer> pieces = new ArrayList<>();
      if (size % nr_pieces == 0) {
        for (int i = 0; i < nr_pieces; i++) {
          pieces.add(largest_piece);
        }
        return pieces;
      }
      int small_piece = size / nr_pieces;
      int large_piece = small_piece + 1;
      int sum = 0;
      int i = 1;
      for (; i <= nr_pieces; i++) {
        sum += small_piece;
        pieces.add(small_piece);
        if (sum + (nr_pieces - i) * large_piece == size)
          break;
      }
      i++;
      for (; i <= nr_pieces; i++) {
        pieces.add(large_piece);
      }
      return pieces;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return this.largest_piece - c2.largest_piece == 0 ? c2.size - this.size : largest_piece - c2.largest_piece;
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 0;
  int HAS_TESTCASES = 0;
  String INPUT = "3 6\n" + "5 3 1\n" + "";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      result += c.current_val;
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int nr_pieces = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
      List<Integer> one_piece = new ArrayList<>();
      one_piece.add(size);
      current_val = currentVal();
      next_val = nextVal();
      gain = current_val - next_val;
    }
    public void cut_carrot() {
      nr_pieces++;
      if (nr_pieces > size)
        nr_pieces = size;
      int div = size / nr_pieces;
      if (size % nr_pieces > 0) {
        largest_piece = div + 1;
      } else {
        largest_piece = div;
      }
      current_val = next_val;
      next_val = nextVal();
      gain = current_val - next_val;
    }
    long current_val;
    long next_val;
    long gain;
    long currentVal() {
      long w1 = size / nr_pieces;
      long w2 = w1 + 1;
      int p2 = size % nr_pieces;
      int p1 = nr_pieces - p2;
      long val = p1 * w1 * w1 + p2 * w2 * w2;
      return val;
    }
    long nextVal() {
      long w1 = size / (nr_pieces + 1);
      long w2 = w1 + 1;
      int p2 = size % (nr_pieces + 1);
      int p1 = (nr_pieces + 1) - p2;
      long val = p1 * w1 * w1 + p2 * w2 * w2;
      return val;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return Long.compare(this.gain, c2.gain);
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 1;
  int HAS_TESTCASES = 0;
  String INPUT = "1 3\n" + "1000000";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      for (Integer v : c.getPieces()) {
        result += (long) v * v;
      }
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int cuts = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
    }
    public void cut_carrot() {
      cuts++;
      int div = size / cuts;
      if (size % cuts > 0)
        largest_piece = div + 1;
    }
    public List<Integer> getPieces() {
      List<Integer> pieces = new ArrayList<>();
      if (size % cuts == 0) {
        for (int i = 0; i < cuts; i++) {
          pieces.add(largest_piece);
        }
        return pieces;
      }
      int small_piece = size / cuts;
      int large_piece = small_piece + 1;
      int sum = 0;
      int i = 1;
      for (; i <= cuts; i++) {
        sum += small_piece;
        pieces.add(small_piece);
        if (sum + (cuts - i) * large_piece == size)
          break;
      }
      i++;
      for (; i <= cuts; i++) {
        pieces.add(large_piece);
      }
      return pieces;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return this.largest_piece - c2.largest_piece == 0 ? this.size - c2.size : largest_piece - c2.largest_piece;
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 1;
  int HAS_TESTCASES = 0;
  String INPUT = "1 3\n" + "1000000";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      for (Integer v : c.getPieces()) {
        result += (long) v * v;
      }
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int cuts = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
    }
    public void cut_carrot() {
      cuts++;
      int div = size / cuts;
      if (size % cuts > 0)
        largest_piece = div + 1;
    }
    public List<Integer> getPieces() {
      List<Integer> pieces = new ArrayList<>();
      if (size % cuts == 0) {
        for (int i = 0; i < cuts; i++) {
          pieces.add(largest_piece);
        }
        return pieces;
      }
      int small_piece = size / cuts;
      int large_piece = small_piece + 1;
      int sum = 0;
      int i = 1;
      for (; i <= cuts; i++) {
        sum += small_piece;
        pieces.add(small_piece);
        if (sum + (cuts - i) * large_piece == size)
          break;
      }
      i++;
      for (; i <= cuts; i++) {
        pieces.add(large_piece);
      }
      return pieces;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return this.largest_piece - c2.largest_piece == 0 ? c2.size - this.size : largest_piece - c2.largest_piece;
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 0;
  int HAS_TESTCASES = 0;
  String INPUT = "3 6\n" + "5 3 1\n" + "";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      result += c.current_val;
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int nr_pieces = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
      List<Integer> one_piece = new ArrayList<>();
      one_piece.add(size);
      current_pieces = one_piece;
      next_pieces = getNextPieces();
      current_val = currentVal();
      next_val = nextVal();
      gain = current_val - next_val;
    }
    public void cut_carrot() {
      nr_pieces++;
      if (nr_pieces > size)
        nr_pieces = size;
      int div = size / nr_pieces;
      if (size % nr_pieces > 0) {
        largest_piece = div + 1;
      } else {
        largest_piece = div;
      }
      current_pieces = next_pieces;
      current_val = next_val;
      next_pieces = getNextPieces();
      next_val = nextVal();
      gain = current_val - next_val;
    }
    List<Integer> current_pieces = null;
    List<Integer> next_pieces = null;
    long current_val;
    long next_val;
    long gain;
    long currentVal() {
      long val = 0;
      for (Integer v : current_pieces) {
        val += (long) v * v;
      }
      return val;
    }
    long nextVal() {
      long val = 0;
      for (Integer v : next_pieces) {
        val += (long) v * v;
      }
      return val;
    }
    public List<Integer> getNextPieces() {
      List<Integer> pieces = new ArrayList<>();
      int next_nr_pieces = nr_pieces + 1;
      if (size % next_nr_pieces == 0) {
        for (int i = 0; i < next_nr_pieces; i++) {
          pieces.add(largest_piece);
        }
        return pieces;
      }
      int small_piece = size / next_nr_pieces;
      int large_piece = small_piece + 1;
      int sum = 0;
      int i = 1;
      for (; i <= next_nr_pieces; i++) {
        sum += small_piece;
        pieces.add(small_piece);
        if (sum + (next_nr_pieces - i) * large_piece == size)
          break;
      }
      i++;
      for (; i <= next_nr_pieces; i++) {
        pieces.add(large_piece);
      }
      return pieces;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return Long.compare(this.gain, c2.gain);
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class E {
  int USE_FILE = 1;
  int HAS_TESTCASES = 0;
  String INPUT = "1 3\n" + "1000000";
  void solve(int caseNr) {
    int n = in.nextInt();
    int k = in.nextInt();
    List<Integer> a = next_int_list(n);
    PriorityQueue<Carrot> pri_queue = new PriorityQueue<>(Collections.reverseOrder());
    for (Integer val : a) {
      Carrot carrot = new Carrot(val);
      pri_queue.add(carrot);
    }
    int perform_cuts = k - n;
    while (perform_cuts-- > 0) {
      Carrot c = pri_queue.poll();
      c.cut_carrot();
      pri_queue.add(c);
    }
    long result = 0;
    while (pri_queue.size() > 0) {
      Carrot c = pri_queue.poll();
      for (Integer v : c.getPieces()) {
        result += (long) v * v;
      }
    }
    System.out.println(result);
  }
  class Carrot implements Comparable<Carrot> {
    int size;
    int cuts = 1;
    int largest_piece;
    public Carrot(int size) {
      this.size = size;
      this.largest_piece = size;
    }
    public void cut_carrot() {
      cuts++;
      int div = size / cuts;
      if (size % cuts > 0)
        largest_piece = div + 1;
    }
    public List<Integer> getPieces() {
      List<Integer> pieces = new ArrayList<>();
      if (size % cuts == 0) {
        for (int i = 0; i < cuts; i++) {
          pieces.add(largest_piece);
        }
        return pieces;
      }
      int small_piece = size / cuts;
      int large_piece = small_piece + 1;
      int sum = 0;
      int i = 1;
      for (; i <= cuts; i++) {
        sum += small_piece;
        pieces.add(small_piece);
        if (sum + (cuts - i) * large_piece == size)
          break;
      }
      i++;
      for (; i <= cuts; i++) {
        pieces.add(large_piece);
      }
      return pieces;
    }
    @Override
    public String toString() {
      return String.format("size=%d piece=%d", size, largest_piece);
    }
    @Override
    public int compareTo(Carrot c2) {
      return this.largest_piece - c2.largest_piece;
    }
  }
  public static List<Integer> next_int_list(int n) {
    List<Integer> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(in.nextInt());
    }
    return a;
  }
  static boolean LOCAL = java.lang.System.getProperty("ONLINE_JUDGE") == null;
  static Scanner in;
  static PrintWriter output_writer = new PrintWriter(java.lang.System.out);
  static class System {
    static PrintWriter out = null;
  }
  void setup() throws Exception {
    System.out = output_writer;
    if (LOCAL && USE_FILE == 0) {
      java.lang.System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
      in = new Scanner(java.lang.System.in);
    }
    if (LOCAL && USE_FILE > 0) {
      String filename = String.format("in/cf%d.txt", USE_FILE);
      File inputFile = new File(filename);
      in = new Scanner(inputFile);
      System.out.printf("[%s]\n", filename);
    }
    if (!LOCAL) {
      in = new Scanner(java.lang.System.in);
    }
    long startTime = java.lang.System.currentTimeMillis();
    int t = HAS_TESTCASES > 0 ? in.nextInt() : 1;
    for (int i = 1; i <= t; i++) {
      solve(i);
    }
    in.close();
    if (LOCAL) {
      System.out.printf("[%dms]\n", java.lang.System.currentTimeMillis() - startTime);
    }
    output_writer.flush();
  }
  public static void main(String[] args) throws Exception {
    new E().setup();
  }
}