codeparrot/codecomplex huggingface dataset:
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.*;
public class B {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		int k = in.nextInt();
		
		long numCandies = 1;
		int turns = 1, add = 2;
		while (numCandies < k) {
			++turns;
			numCandies += add++;
		}
		int res = 0;
		if (numCandies > k) {
			turns += (numCandies-k);
			res += (numCandies-k);
			numCandies = k;
		}
		
		if (turns == n) {
			System.out.println(res);
		}
		else {
			while (turns != n) {
				res += add;
				turns += add++ + 1;
			}
			System.out.println(res);
		}
		
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class B {

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

	public void run() throws Exception {
		FastIO file = new FastIO();
		long n = file.nextLong();
		long k = file.nextLong();
		long lo = 1;
		long hi = n;
		long ans = 0;
		while (lo <= hi) {
			long mi = lo + (hi - lo) / 2;
			long q = mi * (mi + 1) / 2 - (n - mi);
			if (q == k) {
				ans = (n - mi);
				break;
			}
			else if (q < k) {
				lo = mi + 1;
			}
			else {
				hi = mi - 1;
			}
		}
		System.out.println(ans);
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, p / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, p / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;

 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		long n = sc.nextLong(), k = sc.nextLong();
		long ans = 0, sum = 0;
		while(ans < n) {
			if(sum - (n-ans) == k) break;
			ans++;
			sum += ans;
		}
		sc.close();
		System.out.println(n-ans);
	}
    
   
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		FastReader fr =new FastReader();

		PrintWriter op =new PrintWriter(System.out);

		long n =fr.nextLong() ,k =fr.nextLong() ,d =(long)Math.sqrt(9l+8l*(n+k)) ;

		d -= 3l ;	d /=2l ;op.println(n-d) ;

		op.flush();	op.close();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

		String nextLine() {
			String str ="";

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

			return str;
		}

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

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.*;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n=sc.nextInt(),k=sc.nextInt();
		for(int x=0;;x++) {
			if(2*1L*x+x*1L*(x+1)==2L*(k+n)) {
				out.println(n-x);
				break;
			}
		}
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

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

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

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

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

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

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

	}

}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aman Kumar Singh
 */
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);
        BSportMafia solver = new BSportMafia();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSportMafia {
        int MAXN = 200005;
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long n = nl();
            long k = nl();
            long i = 0;
            k += n;
            for (i = 0; i < MAXN; i++) {
                long x = (i * (i + 3)) / 2;
                if (k == x) {
                    pn(n - i);
                    return;
                }
            }

        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

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

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

            return res.toString();
        }

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

    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.StringTokenizer;

public class TaskB {

    void run() {
        FastReader in = new FastReader(System.in);
//        FastReader in = new FastReader(new FileInputStream("input.txt"));
        PrintWriter out = new PrintWriter(System.out);
//        PrintWriter out = new PrintWriter(new FileOutputStream("output.txt"));


        long n = in.nextLong();
        long k = in.nextLong();

        long a = 1;
        long b = -(2 * n + 3);
        long c = n * n + n - 2 * k;

        long d = b * b - 4 * a * c;
        long ans1 = (-b + (long) Math.sqrt(d)) / 2;
        long ans2 = (-b - (long) Math.sqrt(d)) / 2;

        if (ans1 >= 0 && ans1 <= n) {
            out.println(ans1);
        } else {
            out.println(ans2);
        }


        out.close();
    }

    class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

        String next() {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(nextLine());

            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }


    public static void main(String[] args) {
        new TaskB().run();
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
 
 
public class q5 {
	
	
	
    
  
	
 
	public static void main(String[] args) throws IOException {
	
	Reader.init(System.in);
	PrintWriter out=new PrintWriter(System.out);
	long n=Reader.nextInt();
	long k=Reader.nextLong();
	long v=8*n+8*k+4;
	long v2=(long) Math.sqrt(v);
	long v3=2*n+2;
	//long v4=(v3+v2)/2;
	long v5=(v3-v2)/2;
	out.println(v5);
	
	
	
	
	
	out.flush();
	}
}




 
 
 
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */
    static void init() throws IOException {
    	 reader = new BufferedReader(
                 new FileReader("detect.in"));
    tokenizer = new StringTokenizer("");
    }
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.*;

public class F {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(reader.readLine());
        long n = Integer.parseInt(st.nextToken());
        long k = Integer.parseInt(st.nextToken());
        long l = 0;
        long r = n;
        while(l <= r){
            long min = (l + r) / 2;
            if((min * (min + 1) / 2 - (n - min) == k)){
                System.out.println(n - min);
                return;
            }
            else if((min * (min + 1) / 2 - (n - min) > k)){
                r = min - 1;
            }
            else{
                l = min + 1;
            }
        }
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.*;

public class  zz{
	static int mod=(int)1e9+7;
    public static void main(String[] args) throws Exception{
        //MScanner sc = new MScanner("chess.in");
        MScanner sc = new MScanner(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        //int[]in=new int[n];for(int i=0;i<n;i++)in[i]=sc.nextInt();
        int k=sc.nextInt();
        int x=(-3+(int)Math.sqrt(9+4*1.0*(2*k*1.0+2*n*1.0)))/2;
        pw.println(n-x);
        pw.flush();
    }
    static class pair implements Comparable<pair>{
    	String t;int d;int idx;
    	pair(String x,int y,int i){
    		t=x;d=y;idx=i;
    	}
    	@Override
    	public int compareTo(pair o) {
    		if(t.compareTo(o.t)!=0) {
    			return t.compareTo(o.t);
    		}
    		return o.d-d;
    	}
    	 
    	public boolean equals(pair o) {
    		if(this.compareTo(o)==0)return true;
    		return false;
    	}
    	public String toString() {
    		return "("+t+" "+d+")";
    	}
    }
    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 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);
		}
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;

public class Main {
	static StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(System.in));
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pr = new PrintWriter(new BufferedOutputStream(System.out));
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws NumberFormatException, IOException {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int i = 0;
		int cont = 0;
		while(cont<b) {
			i++;
			cont+=i;
		}
		
		if(i+cont-b==a) {
			System.out.println(cont-b);
		}else {
			while(i+cont-b!=a) {
				i++;
				cont+=i;
			}
			System.out.println(cont-b);
		}
	}

	private static int nextInt() {
		try {
			st.nextToken();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return (int) st.nval;
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
public class CFEdu66 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long k = in.nextLong();
		double tmp = Math.sqrt(9 + 8*(n+k));
		if(Math.ceil(tmp)-tmp<0.001)
			tmp = Math.ceil(tmp);
		
		long root = (long)tmp;
		long x = (-3+root)/2;
		System.out.println(n-x);
		
	}

}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
  public static void main(String[] args) {
    long  n,k;
    Scanner s= new Scanner(System.in);
	n=s.nextInt();
	k=s.nextInt();
	System.out.println((int)(n-((-3+Math.sqrt(9+8*(n+k)))/2)));  
  }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		double n=s.nextLong();
		double k=s.nextLong();
		
		double num=(-3+Math.sqrt(9+8*(n+k)))/2;
		
		System.out.println((long)(n-num));
		
	}
	
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;

public class B {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	public static void main(String[] args) throws Exception {
		String[] split = br.readLine().split(" ");
		
		long n = Long.parseLong(split[0]);
		long k = Long.parseLong(split[1]);
		
		long left = -1;
		long right = n + 1;
		
		while(right - left >= 2) {
			long mid = (left + right) / 2; // 10
			// if(mid > n) {
				// right = mid;
				// continue;
			// }
			
			long newN = n - mid; //-5
			long temp = newN * (newN + 1) / 2; //10
			
			long eh = temp - k - mid;
			
			if(eh == 0) {
				pw.println(mid);
				break;
			}
			else if(eh < 0)
				right = mid;
			else
				left = mid;
		}
		
		pw.close();
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;


public class Solution{
 
	public static Integer INT(String s){
		return Integer.parseInt(s);
	}
 
	public static Long LONG(String s){
		return Long.parseLong(s);
	}
 
	//====================================================================================================================
 
 
 	

	public static void main(String args[])throws IOException{
 
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));	Scanner in=new Scanner(System.in);	StringBuilder out=new StringBuilder();
 
		long n=in.nextLong(),
			 k=in.nextLong();

		long a=1,
			 b=3,
			 c=-2*(n+k);
		
		long r1=(-b+(long)Math.sqrt(b*b-4*a*c))/(2*a);
		long r2=(-b-(long)Math.sqrt(b*b-4*a*c))/(2*a);

		System.out.println(n-Math.max(r1, r2));
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

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

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BSportMafia solver = new BSportMafia();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSportMafia {
        public long findsqrt(long a) {
            long b = (long) Math.sqrt(a);
            for (long tt = Math.max(0, b - 10); tt <= b + 10; tt++) if (tt * tt == a) return tt;
            return -1;
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            long n = in.scanInt();
            long k = in.scanInt();
            out.println(n - (-3 + findsqrt(9 + 8 * (k + n))) / 2);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st = new StringTokenizer("");
    static PrintWriter pw = new PrintWriter(System.out);

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

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

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

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

    void run() throws IOException {
        long n = nextInt();
        long k = nextInt();
        long d = 9 + 8 * (n + k);
        pw.print(n - (-3 + (int)Math.sqrt(d)) / 2);
        pw.close();
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;

public class B {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextInt(), k = sc.nextInt();
		
		
		long start = 1, end = n;
		
		while(start <= end) {
			long mid = (start + end) >> 1;
			if(calc(mid) - (n - mid) == k) {
				System.out.println(n - mid);
				return;
			} else if (calc(mid) - (n - mid) > k) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
			
		}
		
	}
	
	public static long calc(long n) {
		return (n * n + n) / 2;
	}
}