codeparrot/codecomplex huggingface dataset:
// Problem: 5_D. Follow Traffic Rules
// Time complexity: constant

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

/**
 * CodeForces Round 5D. Follow Traffic Rules
 * Created by Darren on 14-9-14.
 */
public class Main {
    Reader in = new Reader(System.in);
    PrintWriter out = new PrintWriter(System.out);

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

    int a, v;
    int l, d, w;

    void run() throws IOException {
        a = in.nextInt();
        v = in.nextInt();
        l = in.nextInt();
        d = in.nextInt();
        w = in.nextInt();

        double totalTime = 0.0;
        if (v >= w) {
            if (w*w >= 2*a*d) {
                double x = Math.sqrt(2*a*d);
                totalTime = x / a;
                if ((v*v-x*x) >= 2*a*(l-d))
                    totalTime += (-2*x+Math.sqrt(4*x*x+8*a*(l-d))) / (2*a);
                else
                    totalTime += (v-x)/(1.0*a) + (l-d-(v*v-x*x)/(2.0*a))/v;
            } else {
//                totalTime = (-2*w+Math.sqrt(4*w*w+8*a*(l-d))) / (2*a);
                if (2*v*v-w*w <= 2*a*d) {
                    totalTime = v / (1.0*a) + (v-w) / (1.0*a) + (d-(2*v*v-w*w)/(2.0*a)) / v;
                } else {
                    double x = Math.sqrt((2*a*d+w*w)/2.0);
                    totalTime = x / a + (x-w) / a;
                }
                if ((v*v-w*w) >= 2*a*(l-d))
                    totalTime += (-2*w+Math.sqrt(4*w*w+8*a*(l-d))) / (2*a);
                else
                    totalTime += (v-w)/(1.0*a) + (l-d-(v*v-w*w)/(2.0*a))/v;
            }
        } else {
            if (v*v >= 2*a*l)
                totalTime = Math.sqrt(l*2.0/a);
            else
                totalTime = v / (1.0*a) + (l-v*v/(2.0*a)) / v;
        }

        out.printf("%.10f", totalTime);
        out.flush();
    }

    void solve() throws IOException {

    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public Reader(InputStream input) {
            reader = new BufferedReader(new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /** get next word */
        String nextToken() throws IOException {
            while ( ! tokenizer.hasMoreTokens() ) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer( reader.readLine() );
            }
            return tokenizer.nextToken();
        }

        String readLine() throws IOException {
            return reader.readLine();
        }

        char nextChar() throws IOException {
            return (char)reader.read();
        }

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

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

        double nextDouble() throws IOException {
            return Double.parseDouble( nextToken() );
        }
    }
}
// Problem: 958_C1. Encryption (easy)
// Time complexity: linear
/*
 * Created on 17.05.2019
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Wolfgang Weck
 */
public class C01Easy {
	public static void main(String[] args) {
		try (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {
			final String[] line = r.readLine().split(" ");
			final int N = Integer.parseInt(line[0]), P = Integer.parseInt(line[1]);
			final String[] numS = r.readLine().split(" ");
			if (numS.length != N) throw new IllegalArgumentException();
			final int[] n = new int[N];
			int sum1 = 0, sum2 = 0;
			for (int i = 0; i < N; i++) {
				n[i] = Integer.parseInt(numS[i]) % P;
				sum2 += n[i];
				if (sum2 >= P) sum2 -= P;
			}
			int max = sum2;
			for (int i = 0; i < N; i++) {
				sum1 += n[i];
				if (sum1 >= P) sum1 -= P;
				sum2 -= n[i];
				if (sum2 < 0) sum2 += P;
				final int s = sum1 + sum2;
				if (s > max) max = s;
			}
			System.out.println(max);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
}
// Problem: 979_A. Pizza, Pizza, Pizza!!!
// Time complexity: constant
import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        if(n==0)
        System.out.println(0);
        else if(n%2==1)
        System.out.println((n+1)/2);
        else
        System.out.println(n+1);
    }
}
// Problem: 528_B. Clique Problem
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] point = new int[n][];
        for(int i=0;i<n;i++) point[i] = new int[]{sc.nextInt(),sc.nextInt()};
        Arrays.sort(point,(a,b)->((a[0]-a[1])-(b[0]-b[1])));
        TreeMap<Integer,Integer> tm = new TreeMap<>();
        int ans = 0;
        for(int i=n-1;i>=0;i--){
            int x = point[i][0], w = point[i][1];
            Map.Entry<Integer,Integer> cur =  tm.ceilingEntry(x+w);
            int curRes;
            if(cur==null) curRes = 1;
            else curRes = cur.getValue()+1;
            ans = Math.max(ans,curRes);
            Map.Entry<Integer,Integer> upper = tm.ceilingEntry(x-w);
            if(upper==null||upper.getValue()<curRes) tm.put(x-w,curRes);
            //Integer key = tm.
        }
        System.out.println(ans);
    }
}
// Problem: 981_B. Businessmen Problems
// Time complexity: nlogn
import java.util.*;

public class Solution {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Comp c1 = getComp(scanner);
		Comp c2 = getComp(scanner);
		c1.sortByPrice();
		c2.sortByPrice();	
		int i = 0;
		int j = 0;
		while(i < c1.num || j < c2.num) {
			Elem xi = (i < c1.num) ? c1.elems.get(i) : null;
			Elem yj = (j < c2.num) ? c2.elems.get(j) : null;
			if(xi != null && yj != null) {
				if(xi.price >= yj.price) {
					if(!c2.resultSet.contains(xi)) {
						c1.resultSet.add(xi);
					}
					i++;
				} else {
					if(!c1.resultSet.contains(yj)) {
						c2.resultSet.add(yj);
					}
					j++;
				}
			} else
			if(xi != null) {
				if(!c2.resultSet.contains(xi)) {
					c1.resultSet.add(xi);
				}
				i++;
			} else {
				if(!c1.resultSet.contains(yj)) {
					c2.resultSet.add(yj);
				}
				j++;
			}				
		}
		
		long result = c1.getResultPrice() + c2.getResultPrice();
		System.out.println(result);
   }
   
   private static Comp getComp(Scanner scanner) {
	   Comp c = new Comp();
	   c.num = scanner.nextInt();
	   for(int i = 0; i < c.num; i++) {
		   c.addElem(scanner.nextLong(), scanner.nextLong());
	   }
	   return c;
   }
}

class Comp {
	int num;
	List<Elem> elems = new ArrayList<>();
	Set<Elem> resultSet = new HashSet<>();
	
	void addElem(long el, long pr) {
		Elem elem = new Elem(el, pr);
		elems.add(elem);
	}
	
	void sortByPrice() {
		Collections.sort(elems);
	}
	
	long getResultPrice() {
		long sumPrice = 0;
		for(Elem elem : resultSet) {
			sumPrice += elem.price;
		}
		
		return sumPrice;
	}
}

class Elem implements Comparable<Elem> {
	long elem;
	long price;
	
	public Elem(long el, long pr) {
		this.elem = el;
		this.price = pr;
	}
	
	public int compareTo(Elem other) {
		return (int) (other.price - price);
	}
	
	public boolean equals(Object o) {
		if(!(o instanceof Elem)) {
			return false;
		}
		
		Elem other = (Elem) o;
		return (other.elem == elem);
	}
	
	public int hashCode() {
		return (int) elem;
	}
	
	public String toString() {
		return "(" + elem + ", " + price + ")";
	}
}
// Problem: 1159_C. The Party and Sweets
// Time complexity: nlogn
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        long[] arrB = new long[n];
        long[] arrG = new long[m];
        st=new StringTokenizer(f.readLine());
        for(int i=0;i<n;i++){
            arrB[i]=Long.parseLong(st.nextToken());
        }
        st=new StringTokenizer(f.readLine());
        for(int j=0;j<m;j++){
            arrG[j]=Long.parseLong(st.nextToken());
        }
        Arrays.sort(arrB);
        Arrays.sort(arrG);
        long ans = 0;
//        for (int i = 0; i < n; i++) ans += arrB[i] * m;
//        for (int i = 0; i < m - 1; i++) ans += arrG[i] - arrB[0];
//        if (arrB[m - 1] != arrB[0]) {
//            if (arrB.length == 1) {
//                ans=-1;
//            }
//            else ans += arrG[m - 1] - arrB[1];
//        }
//        if (arrG[m-1] < arrB[0]) {
//            ans=-1;
//        }
        for(int i=0;i<n;i++){
            ans+=arrB[i]*(long)m;
        }
        for(int i=1;i<m;i++){
            ans+=arrG[i]-arrB[n-1];
        }
        if(arrB[n-1]!=arrG[0]){
            if(n==1){
                ans=-1;
            }
            else{
                //smallest g goes to second to last
                ans+=arrG[0]-arrB[n-2];
            }
        }
        if(arrB[n-1]>arrG[0]){
            ans=-1;
        }
        System.out.println(ans);
        f.close();
        out.close();
    }
}
// Problem: 1088_D. Ehab and another another xor problem
// Time complexity: logn
import java.util.*;
public class mad{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int cura = 0,curb = 0;
        int ver;
        System.out.println("? 0 0");
        System.out.flush();
        ver = sc.nextInt();
        for(int i=29;i>=0;i--){
            System.out.println("? "+(cura+(1<<i))+" "+curb);
            System.out.flush();
            int temp1 = sc.nextInt();
            System.out.println("? "+cura+" "+(curb+(1<<i)));
            System.out.flush();
            int temp2 = sc.nextInt();
            if(temp1!=temp2){
                if(temp2==1){
                    cura += (1<<i);
                    curb += (1<<i);
                }
            }
            else{
                if(ver==1) cura += (1<<i);
                if(ver==-1) curb += (1<<i);
                
                ver = temp1;
            }
        }
        System.out.println("! "+cura+" "+curb);
    }
    
}
// Problem: 1023_B. Pair of Toys
// Time complexity: constant
/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
			long n,s,p;
			Scanner in=new Scanner(System.in);
			n=in.nextLong();
			s=in.nextLong();
			if(n==1 && s<=1)
			{
			    System.out.print(n-1);
			}
	        else if(s<n)
	        {
	            if(s%2!=0)
		        {System.out.print(s/2);}
		        else
		        {System.out.print(s/2-1);}
	        }
	        else if(s==n)
	{
	    if(s%2==0)
		{System.out.println((n/2)-1);}
		else
		{System.out.println(n/2);}
	}
	else if(s<=(2*n-1))	
	{
		System.out.print((2*n+1-s)/2);
	}
	else
	{
		System.out.print(0);
	}
	}
}
// Problem: 958_A1. Death Stars (easy)
// Time complexity: quadratic
/*
 * Created on 17.05.2019
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Wolfgang Weck
 */
public class A01Easy {
	private static interface Matrix {
		boolean get(int i, int j);

		int size();
	}

	private static class MData implements Matrix {
		private final boolean[][] m;

		MData(boolean[][] m) {
			this.m = m;
		}

		@Override
		public boolean get(int i, int j) {
			return m[i][j];
		}

		@Override
		public int size() {
			return m.length;
		}
	}

	private static abstract class MDecorator implements Matrix {
		protected final Matrix inner;

		MDecorator(Matrix inner) {
			this.inner = inner;
		}

		@Override
		public int size() {
			return inner.size();
		}
	}

	private static class MHFlip extends MDecorator {
		MHFlip(Matrix inner) {
			super(inner);
		}

		@Override
		public boolean get(int i, int j) {
			return inner.get(size() - 1 - i, j);
		}
	}

	private static class MVFlip extends MDecorator {
		MVFlip(Matrix inner) {
			super(inner);
		}

		@Override
		public boolean get(int i, int j) {
			return inner.get(i, size() - 1 - j);
		}
	}

	private static class MRot extends MDecorator {
		MRot(Matrix inner) {
			super(inner);
		}

		@Override
		public boolean get(int i, int j) {
			return inner.get(j, size() - 1 - i);
		}
	}

	public static void main(String[] args) {
		try (BufferedReader r = new BufferedReader(new InputStreamReader(System.in))) {
			final int N = Integer.parseInt(r.readLine());
			Matrix m1 = readMatrix(r, N), m2 = readMatrix(r, N);
			boolean matched = matchesFlipped(m1, m2);
			int i = 0;
			while (i < 3 && !matched) {
				m1 = new MRot(m1);
				matched = matchesFlipped(m1, m2);
				i++;
			}
			System.out.println(matched ? "Yes" : "No");
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static Matrix readMatrix(BufferedReader r, int n) throws IOException {
		boolean[][] m = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			String line = r.readLine();
			for (int j = 0; j < n; j++) {
				m[i][j] = line.charAt(j) == 'X';
			}
		}
		return new MData(m);
	}

	private static boolean matches(Matrix m1, Matrix m2) {
		int i = 0, j = 0, n = m1.size();
		while (i < n && m1.get(i, j) == m2.get(i, j)) {
			j++;
			if (j == n) {
				j = 0;
				i++;
			}
		}
		return i == n;
	}

	private static boolean matchesFlipped(Matrix m1, Matrix m2) {
		return matches(m1, m2) || matches(new MHFlip(m1), m2) || matches(new MVFlip(m1), m2);
	}
}
// Problem: 1075_C. The Tower is Going Home
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class A4 {

    public BufferedReader input;
    public PrintWriter output;
    public StringTokenizer stoken = new StringTokenizer("");

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

    A4() throws IOException {
        input = new BufferedReader(new InputStreamReader(System.in));
        output = new PrintWriter(System.out);
        run();
        input.close();
        output.close();
    }

    private void run() throws IOException {
        int n = Math.toIntExact(nextLong());
        int m = Math.toIntExact(nextLong());
        int[] coor = new int[n + 1];
        int[] ss = new int[n + 1];
        for (int i = 0; i < n; i++) {
            coor[i] = Math.toIntExact(nextLong());
        }
        coor[n] = 1000000000;
        Arrays.sort(coor);
        for (int i = 0; i < m; i++) {
            long x1 = nextLong();
            long x2 = nextLong();
            nextLong();
            if (x1 == 1 && x2 >= coor[0]) {
                int l = 0;
                int r = n + 1;
                while (r - l > 1) {
                    int mi = (r + l) / 2;
                    if (coor[mi] > x2) {
                        r = mi;
                    } else {
                        l = mi;
                    }
                }
                ss[l]++;
            }
        }
        long[] ans = new long[n + 1];
        ans[n] = ss[n] + n;
        long min = ans[n];
        for (int i = n - 1; i > -1; i--) {
            ans[i] = ans[i + 1] - 1 + ss[i];
            if (ans[i] < min) {
                min = ans[i];
            }
        }
        System.out.println(min);
    }

    private Long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextString());
    }

    private String nextString() throws IOException {
        while (!stoken.hasMoreTokens()) {
            String st = input.readLine();
            stoken = new StringTokenizer(st);
        }
        return stoken.nextToken();
    }
}
// Problem: 975_B. Mancala
// Time complexity: constant
import java.io.*;
import java.util.*;
public class Codechef{
	static int max=Integer.MIN_VALUE;
	static int res=0;
	static int[] checkMax(int arr[],int j){
             int sum=0;
             int x=arr[j];
        		while(x!=0){
        		        if(j+1==15){
        		        	j=0;
        		        }else{
        		        	arr[j+1]=arr[j+1]+1;
        		        }
        		        // if(arr[j+1]%2==0){
        		        // 	sum=sum+arr[j+1];
        		        // 	if(sum>=max){
        		        // 	max=sum;
        		        // }
        		        // }

        		        
        		        x--;
        		        j++;
        		}
        		     return arr;

	}
      

    public static void main(String []args){
       Scanner sc = new Scanner (System.in);
    long a [] = new long [14];
    long b [] = new long [14];
    long p,q,r,s,max = 0;
    for(int i = 0; i < 14; i++) a[i] = sc.nextInt();
    for(int i = 0; i < 14; i++){
      p = a[i]%14;
      q = a[i]/14;
      r = 0;
      s = 0;
      for(int j = 0; j < 14; j++) b[j] = a[j];
      b[i] = 0;
      int j = (i+1)%14;
      for(; r < p; r++) {
        b[j]++;
        j=(j+1)%14;
      }
      for( j = 0; j < 14; j++) {
        b[j] += q;
        if(b[j] % 2 == 0) s+= b[j];
      }
      max = Math.max(max,s);
    }
    System.out.println(max);



    }

}
// Problem: 608_C. Chain Reaction
// Time complexity: nlogn
import javafx.util.Pair;

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

public class Beacon8 {
    public static void main(String[] args) throws IOException {
//        int[] arr = {1, 3, 7, 18};
//        int bIndex = Arrays.binarySearch(arr, 4);
//        System.out.println(bIndex);


        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Map<Integer, Integer> beacons = new TreeMap<>();

        for (int i = 0; i < n; i++) {
            int index = scan.nextInt();
            int power = scan.nextInt();
            beacons.put(index, power);
        }
        int[] indicesArr = new int[n];
        int arrInd = 0;
        for (int index : beacons.keySet()) {
            indicesArr[arrInd] = index;
            arrInd++;
        }
       // Integer[] indicesArr = ((Integer[])beacons.keySet().toArray());
        int[] nDestroys = new int[n];
        for (int i = 0; i < n; i++) {
            int bIndex = Arrays.binarySearch(indicesArr, indicesArr[i] - beacons.get(indicesArr[i]));
            if (bIndex < 0)
                bIndex = -(bIndex + 1);
            nDestroys[i] = i - bIndex;
        }
        int[] totalBeacons = new int[n];
        int maxBeacons = 1;
        totalBeacons[0] = 1;
        for (int i = 1; i < n; i++) {
            if (nDestroys[i] == 0)
                totalBeacons[i] = totalBeacons[i - 1] + 1;
            else {
                if ((i - nDestroys[i] - 1) >= 0)
                    totalBeacons[i] = totalBeacons[i - nDestroys[i] - 1] + 1;
                else
                    totalBeacons[i] = 1;
            }
               // totalBeacons[i] = totalBeacons[i - nDestroys[i]] + 1;
            //totalBeacons[i] = i - nDestroys[i] + totalBeacons[i - nDestroys[i]] + 1;
            if(totalBeacons[i] > maxBeacons)
                maxBeacons = totalBeacons[i];
        }
//        System.out.println("\ntotalBeacons array");
//        for (int i = 0; i < n; i++) {
//            System.out.print(totalBeacons[i] + " ");
//        }
//        if (maxBeacons == -1)
//            System.out.println(n);
        System.out.println(n - maxBeacons);
    }

}
// Problem: 1082_D. Maximum Diameter Graph
// Time complexity: linear
import java.io.*;
import java.util.*;

public class CF1082D {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] aa = new int[n];
		int[] i1 = new int[n];
		int[] i2 = new int[n];
		int n1 = 0, n2 = 0, m2 = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(st.nextToken());
			aa[i] = a;
			if (a == 1)
				i1[n1++] = i;
			else {
				i2[n2++] = i;
				m2 += a;
			}
		}
		if (m2 < (n2 - 1) * 2 + n1) {
			System.out.println("NO");
			return;
		}
		int m = n2 - 1 + n1;
		int d = n2 - 1 + Math.min(n1, 2);
		PrintWriter pw = new PrintWriter(System.out);
		pw.println("YES " + d);
		pw.println(m);
		for (int i = 0; i + 1 < n2; i++) {
			pw.println((i2[i] + 1) + " " + (i2[i + 1] + 1));
			aa[i2[i]]--; aa[i2[i + 1]]--;
		}
		if (n1 > 0) {
			while (n2 > 0 && aa[i2[n2 - 1]] == 0)
				n2--;
			pw.println((i2[n2 - 1] + 1) + " " + (i1[n1 - 1] + 1));
			aa[i2[n2 - 1]]--;
			n1--;
		}
		for (int i = 0, j = 0; j < n1; j++) {
			while (aa[i2[i]] == 0)
				i++;
			pw.println((i2[i] + 1) + " " + (i1[j] + 1));
			aa[i2[i]]--;
		}
		pw.close();
	}
}
// Problem: 913_A. Modular Exponentiation
// Time complexity: constant
/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/* 
package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{     
  static String reverse(String s){
    String reverse="";
    for(int i=s.length()-1;i>=0;i--){
        reverse=reverse + s.charAt(i);
    }
    return reverse;
  }

      
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         int m=sc.nextInt();
         int x=m%(int)Math.pow(2,n);
         System.out.println(x);



}
}
// Problem: 1159_C. The Party and Sweets
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Main {
  static Scanner in = new Scanner(System.in);
  static PrintWriter out = new PrintWriter(System.out);
  
  public static void main(String[] args) {
    int n = in.nextInt();
    int m = in.nextInt();
    long boyMax = 0;
    int NBoyMax = 0;

    long sweets = 0;
    TreeSet<Long> boyMember = new TreeSet<>();
    for (int i = 0; i < n; i++) {
      long input = in.nextLong();
      boyMember.add(input);
      if (boyMax < input) {
        boyMax = input;
        NBoyMax = 1;
      } else if (boyMax == input) NBoyMax++;
      sweets += (input * m);
    }

    long smallestGirl = (long) 1e8 + 1;
    long sum = 0;
    for (int i = 0; i < m; i++) {
      long input = in.nextLong();
      sum += input;
      if (smallestGirl > input) smallestGirl = input;
    }

    if (smallestGirl < boyMember.last()) {
      out.println(-1);
    } else if (smallestGirl == boyMember.last()) {
      sweets += sum - boyMember.last() * m;
      out.println(sweets);
    } else {

      if (NBoyMax > 1) {
        sweets += sum - boyMember.last() * m;
        out.println(sweets);
      } else {
        Object[] boyList = boyMember.toArray();
        if (boyList.length > 1) {
          long boy = 0;
          boy = (long)boyList[boyList.length - 2];
          sweets += (sum - smallestGirl - boyMember.last() * (m - 1));
          sweets += (smallestGirl - boy);
          out.println(sweets);
        } else {
          out.println(-1);
        }
      }
    }

    in.close();
    out.close();
  }
}
// Problem: 1197_C. Array Splitting
// Time complexity: nlogn
import java.util.*;
import java.math.*;
public class Split {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int k= sc.nextInt();
		int a[] = new int[n];
		int d[] = new int[n-1];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			if(i>0)
				d[i-1] = a[i-1] - a[i];
		}
		Arrays.sort(d);
		int t = 0;
		for(int i=0;i<k-1;i++)
			t += d[i];
		System.out.println(a[n-1]-a[0]+t);
	}

}