codeparrot/codecomplex huggingface dataset:
// Problem: 1092_D1. Great Vova Wall (Version 1)
// Time complexity: linear
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.util.Stack;
public class D527A2 {

	public static void main(String[] args) {
		FastScanner in = new FastScanner(System.in);
		int N = in.nextInt();
		Stack<Integer> stack = new Stack<>();
		for(int i = 0; i < N; i++) {
			int num = in.nextInt() % 2;
			if(stack.size() >= 1 && stack.lastElement() == num)
				stack.pop();
			else
				stack.add(num);
		}
		
		System.out.println(stack.size() <= 1 ? "YES" : "NO");
	}
	
	/**
	 * Source: Matt Fontaine
	 */
	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int chars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (chars == -1)
				throw new InputMismatchException();
			if (curChar >= chars) {
				curChar = 0;
				try {
					chars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (chars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

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

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

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}

}
/*
5
2 1 1 2 5
outputCopy
YES
inputCopy
3
4 5 3
outputCopy
YES
inputCopy
2
10 10
outputCopy
YES
inputCopy
3
1 2 3
outputCopy
NO

5
2 3 2 2 3

YES
*/
// Problem: 1061_B. Views Matter
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

public class stacks {

	public static void main(String[] args) throws Exception {
		FastIO sc = new FastIO(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		long remove = 0;
		
		int[] heights = new int[n+1];
		
		for(int i = 0; i < n; i++) {
			heights[i] = sc.nextInt();
			remove += heights[i];
		}
		
		Arrays.sort(heights);
		//System.out.println(Arrays.toString(heights));
		long keep = 0;
		for(int i = n; i> 0; i--) {
			if(heights[i-1] >= heights[i]) {
				heights[i-1] = heights[i]-1;
			}
			keep += heights[i] - heights[i-1];
		}
		//System.out.println(Arrays.toString(heights));
		
		pw.println(remove - keep);
		pw.close();
	}

	static class FastIO {

		//Is your Fast I/O being bad?

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastIO(String fileName) throws Exception {
			dis = new FileInputStream(fileName);
		}

		public FastIO(InputStream is) throws Exception {
			dis = is;
		}

		int nextInt() throws Exception {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		long nextLong() throws Exception {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		byte nextByte() throws Exception {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String next() throws Exception {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}
// Problem: 1015_C. Songs Compression
// Time complexity: nlogn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            TaskC.pair[] songs = new TaskC.pair[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                songs[i] = new TaskC.pair(in.nextInt(), in.nextInt());
                sum += songs[i].a;
            }
            Arrays.sort(songs);

            int res = 0;
            int idx = n - 1;
            while (sum > m) {
                if (idx < 0) {
                    break;
                }
                sum -= (songs[idx].a - songs[idx].b);

                res++;
                idx--;
            }

            if (sum > m) {
                out.println(-1);
            } else {
                out.println(res);
            }
        }

        static class pair implements Comparable<TaskC.pair> {
            int a;
            int b;

            pair(int a, int b) {
                this.a = a;
                this.b = b;
            }

            public int compareTo(TaskC.pair p) {
                return (this.a - this.b) - (p.a - p.b);
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

    }
}
// Problem: 996_B. World Cup
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int best = 1;
        int bestTime = Integer.MAX_VALUE;
        for(int i=0;i<n;i++) {
            int time;
            int a = sc.nextInt();
            time = (a%n==0 || a%n<=i) ? a/n : (a+n)/n;
            if(time < bestTime) {
                best = i + 1;
                bestTime = time;
            }
        }

        pw.println(best);
        pw.close();
    }
}
// Problem: 1191_B. Tokitsukaze and Mahjong
// Time complexity: constant
//package codeforces;
import java.util.Scanner;
public class ex5 {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String S [] = new String[3];
	
	int m=0,s=0,p=0;
	int temp=0;
	
	for (int i = 0; i < S.length; i++) {
		S[i]=scan.next();
		if(S[i].indexOf('m')!=-1) m++;
		if(S[i].indexOf('s')!=-1) s++;
		if(S[i].indexOf('p')!=-1) p++;
	}
	
	
	int n1 = Integer.parseInt(S[0].substring(0,1));
	int n2 = Integer.parseInt(S[1].substring(0,1));
	int n3 = Integer.parseInt(S[2].substring(0,1));
	
	
	
	    int d3 = Math.abs(n1-n2);
		int d4 = Math.abs(n1-n3);
		int d5 = Math.abs(n2-n3);
		
	
	if(m==3||s==3||p==3) {
		
		    if(d3==1&d5==1&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2)
			System.out.println(0);
		else 
		    if(d3==0&d4==0) System.out.println(0);
		else 
			if(d3<d5&d3<d4) {
			    if(d3==1||d3==2||d3==0) System.out.println(1);
		        else                 System.out.println(2);
			    }
			else if (d5<d4&d5<d3){
				 if(d5==1||d5==2||d5==0) System.out.println(1);
					else                 System.out.println(2);
			}
			else if(d4<d5&d4<d3) {
				if(d4==1||d4==2||d4==0) System.out.println(1);
				else                 System.out.println(2);
			}
			else if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1)
				System.out.println(1);
			else System.out.println(2);
			
			
		
		 
		    
		    
	}
	
	if(m==2||s==2||p==2) {
		
		
		
		char c1 = S[0].charAt(1);
		char c2 = S[1].charAt(1);
		char c3 = S[2].charAt(1);
		
		
		if(c1==c2) {
			if(n1==n2) System.out.println(1);
			else if(d3==1||d3==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c1==c3) {
			if(n1==n3) System.out.println(1);
			else if(d4==1||d4==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c2==c3) {
			if(n2==n3) System.out.println(1);
			else if(d5==1||d5==2) System.out.println(1);
			else System.out.println(2);
		}
	}
	
	if(m==1&s==1&p==1) System.out.println(2);
		
	
	
}
}
// Problem: 1088_D. Ehab and another another xor problem
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DEhabIEsheOdnaOcherednayaZadachaNaXor {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int c = 0;
            int d = 0;

            int prevSign = 0;
            int nextSign;
            boolean zeroOut = true;
            for (int i = 29; i >= 0; i--) {
                if (zeroOut) {
                    print(c, d, out);
                    prevSign = read(in);
                }

                print((1 << i) | c, (1 << i) | d, out);
                nextSign = read(in);

                if (prevSign == nextSign) {
                    zeroOut = false;

                    print((1 << i) | c, d, out);
                    nextSign = read(in);

                    if (nextSign < 0) {
                        c = (1 << i) | c;
                        d = (1 << i) | d;
                    }
                } else {
                    zeroOut = true;

                    if (nextSign < 0) c = (1 << i) | c;
                    else d = (1 << i) | d;
                }
            }

            out.printf("! %d %d", c, d);
            out.flush();
        }

        private void print(int c, int d, PrintWriter out) {
            out.printf("? %d %d\n", c, d);
            out.flush();
        }

        private int read(InputReader in) {
            return in.nextInt();
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(readLine());
            }
            return tokenizer.nextToken();
        }

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}
// Problem: 991_A. If at first you don't succeed...
// Time complexity: constant
import java.util.*;
import java.io.*;

public class aaaaaaaaaaaaaaaa {
	public void run() throws Exception {
		Scanner file = new Scanner(System.in);
		int a = file.nextInt(), b= file.nextInt(), c = file.nextInt(), n = file.nextInt();
		a -= c;
		b -= c;
		if (a < 0 || b < 0) System.out.println(-1);
		else {
			int x = a + b + c;
			if (x >= n) System.out.println(-1);
			else System.out.println(n - x);
		}
	}

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

}
// Problem: 915_E. Physical Education Lessons
// Time complexity: nlogn
// discussed with rainboy
import java.io.*;
import java.util.*;

public class CF915E {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		int q = Integer.parseInt(br.readLine());
		TreeMap<Integer, Integer> mp = new TreeMap<>();
		int ans = 0;
		while (q-- > 0) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()) - 1;
			int r = Integer.parseInt(st.nextToken());
			int t = Integer.parseInt(st.nextToken());
			Map.Entry<Integer, Integer> e;
			int l_, r_;
			if (t == 1) {
				if ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) >= l) {
					l_ = e.getKey();
					ans -= r_ - l_;
					l = l_;
					r = Math.max(r, r_);
				}
				while ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) <= r) {
					r_ = e.getValue();
					ans -= r_ - l_;
					r = Math.max(r, r_);
					mp.remove(l_);
				}
				ans += r - l;
				mp.put(l, r);
			} else {
				r_ = l;
				if ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) > l) {
					l_ = e.getKey();
					if (l_ < l)
						mp.put(l_, l);
					else
						mp.remove(l_);
					ans -= r_ - l;
				}
				while ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) < r) {
					r_ = e.getValue();
					mp.remove(l_);
					ans -= r_ - l_;
				}
				if (r_ > r) {
					mp.put(r, r_);
					ans += r_ - r;
				}
			}
			pw.println(n - ans);
		}
		pw.close();
	}
}
// Problem: 975_B. Mancala
// Time complexity: constant
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	public static String conv(String str) {
		boolean[] Arr = new boolean[26];
		for (int i = 0; i < str.length(); i++) {
			Arr[str.charAt(i) - 'a'] = true;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 26; i++) {
			if (Arr[i])
				sb.append((char) (i + 'a'));
		}
		return "" + sb;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		HashSet<String> hs = new HashSet<String>();
		int[] Arr = new int[14];
		long max = 0;
		for (int i = 0; i < 14; i++) {
			Arr[i] = sc.nextInt();
		}

		for (int i = 0; i < 14; i++) {
			int[] arr = Arr.clone();

			long sum = 0;
			int r = arr[i];
			arr[i] = 0;
			for (int j = i + 1; j < arr.length && r > 0; j++) {
				arr[j]++;
				r--;
			}
			for (int j = 0; j < arr.length; j++) {
				arr[j] +=( r / 14);
				if (j + 1 <= (r % 14)) {
					arr[j]++;
				}
				if (arr[j] % 2 == 0) {
					sum += arr[j];
				}
			}
			max = Math.max(max, sum);

		}
		System.out.println(max);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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

	}
}
// Problem: 1075_B. Taxi drivers and Lyft
// Time complexity: linear


import java.util.Scanner;

public class TaxiDriversAndLyft2 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		long m = scanner.nextLong();
		long[] people = new long[(int) (n+m)];
		int[] taxiDrivers = new int[(int) (n+m)];
		
		for(int i = 0;i< (n+m); i++) {
			people[i] = scanner.nextLong();
		}
		
		for(int i = 0;i< (n+m); i++) {
			taxiDrivers[i] = scanner.nextInt();
		}
		
		int lastTaxiDriverIndex = -1;
		long[] riderCountArray = new long[(int) (m)];
		long[] a1 = new long[(int)n];
		long[] b1 = new long[(int)m];
		
		int j=0, k=0;
		for(int i = 0;i< (n+m); i++) {	
			if(taxiDrivers[i] == 0) {
				a1[j] = people[i];
				j++;
			}
			else  {
				b1[k] = people[i];
				k++;
			}
		}
		
		int l = 0, q=0;
		for(int i=0;i<j;i++) {
			while ((l<m-1 && m>1) && Math.abs(a1[i] - b1[l]) > Math.abs(a1[i] - b1[l+1])) {
				l++; 
			}
			
			riderCountArray[l]++;	
		}
		
		for(int i = 0;i< (m); i++) {
			System.out.print(riderCountArray[i]+" ");
		}
	} 
}
// Problem: 964_A. Splits
// Time complexity: constant
import java.io.*;
import java.util.*;

public class cf {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        pw.println(n/2+1);
        pw.close();
    }
}
// Problem: 1159_A. A pile of stones
// Time complexity: linear
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			int n=sc.nextInt();
			String s=sc.next();
			int sum=0;
			for(int i=0;i<s.length();i++) {
				if(s.charAt(i)=='+') {
					sum++;
				}
				if(s.charAt(i)=='-'&&sum!=0) {
					sum--;
				}
			}
			System.out.println(sum);
		}
	}
}