codeparrot/codecomplex huggingface dataset:
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class P1195B {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int l = 0;
        int r = n;
        int ans = 0;
        while (l <= r) {
            int eat = (l + r) >> 1;
            int lastPut = n - eat;
            long totalPut = (long) (lastPut + 1) * lastPut / 2;
            long remain = totalPut - eat;
            if (remain == k) {
                ans = eat;
                break;
            } else if (remain > k)
                l = eat + 1;
            else
                r = eat - 1;
        }
        writer.println(ans);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn

import java.util.Scanner;


public class CodeForces {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
        int ans = 0;
        long x = n;
        x = x*(x+1)/2;
        while (x!=k) {
            x-=n;
            n--;
            ans++;
            k++;
        }
        System.out.println(ans);
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
/*
Roses are red
Memes are neat
All my test cases time out
Lmao yeet
*/
import java.util.*;
import java.io.*;

   public class B
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         //bin search
         //ugh I'm shafting
         long x = (long)N;
         long low = 0L;
         long high = N;
         while(low != high)
         {
            x = (low+high+1)/2;
            long add = (x*(x+1))/2;
            long y = N-x;
            if(add-y > K)
               high = x;
            else if(add-y == K)
            {
               System.out.println(y);
               break;
            }
            else
               low = x;
         }
         //run time?
      }
      public static void sort(int[] arr)
      {
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.math.*;
    public class D {
        public static void main(String[] args) throws Exception {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
            // int n = Integer.parseInt(bf.readLine());
            StringTokenizer st = new StringTokenizer(bf.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());
            
            for(int i=0; i<100000; i++) {
              long mult = 1L*i*(i+1)/2;
              long b = 1L*mult - k;
              if(i+b == n*1L) {
                out.println(b);
                out.close(); System.exit(0);
              }
            }
            //out.println(count);
            out.close(); System.exit(0);
        }
    }

    // a(a+1)/2 - b = k;   a+b = n
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Cf2 {

    static boolean ok(long n, long k, long eatten) {
        long moves = n-eatten;
        long ans = moves*(moves+1)/2;
        ans -= eatten;
        return ans <= k;
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        long n = in.nextInt();
        long k = in.nextInt();
        long left = 0, right = n;
        while (left <= right) {
            long middle = (left+right)/2;
            if (ok(n, k, middle)) right = middle-1;
            else left=middle+1;
        }
        System.out.println(left);
    }

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

        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;
        }
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.Scanner;

public class SportMafia {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int next = 1;
		int current = 0;
		int result = 0;
		
		for(int i = 0; i < n; i++) {
			if(current < k) {
				current += next++;
			} else {
				current--;
				result++;
			}
		}
		
		System.out.println(result);
		
		sc.close();
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
public class algo_1802
{
    public static void main(String args[])
    {
        Scanner ex=new Scanner(System.in);
        int n=ex.nextInt();
        int k=ex.nextInt();
        int x=(int)((Math.sqrt(9.0+8.0*((double)n+(double)k))-3.0)/2.0);
        System.out.println(n-x);
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(System.out);

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

		long s=0;
		long e=n;

		long ans = -1;
		while (s<=e) {
			long m = (s+e)/2;
			long temp = ((n-m)*(n-m+1))/2 - m;

			if (temp < k) 
				e = m-1;
			else if (temp > k)
				s = m+1;
			else {
				ans = m;
				break;
			} 
		}

		writer.println(ans);
		writer.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();
		}

		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;
		}
	}
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn

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

public class B {

    public void solve() throws IOException {
        long n = nextInt(), k = nextInt();
        long c = 2 * (n + k);
        long l = -1, r = 200000;
        while (r - l > 1) {
            long m = l + (r - l) / 2;
            if (m * m + 3 * m >= c) {
                r = m;
            } else {
                l = m;
            }
        }
        out.print(n - r);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

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

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

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

    public int[] nextArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new B().run();
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
// Created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        long N,K,tmp,ans=0;

        String s[]=br.readLine().trim().split(" ");
        N=Long.parseLong(s[0]);
        K=Long.parseLong(s[1]);

        long l=1,r=N,mid;

        while(l<=r)
        {
            mid=(l+r)/2;

            tmp=mid*(mid+1)/2;
            tmp-=N;
            tmp+=mid;

            if(tmp==K)
            {
                ans=N-mid;
                break;
            }
            else if(tmp>K)
                r=mid-1;
            else
                l=mid+1;
        }
        System.out.println(ans);
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();
        long disc = (long)(Math.sqrt(9 - 4 * (-2 * n - 2 * k)));
        long x = (-3 + disc) / 2;
        System.out.println(n - x);
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());
        System.out.println((int)(n-(-3.0+Math.sqrt(9.0+8.0*(n+k)))/2.0));
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Codeforces {
    
    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(); 
        } 
  
        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 void main(String[] args) {
        FastReader input = new FastReader();
        long n = input.nextLong();
        long K = input.nextLong();
        long root = (long) Math.sqrt(8 * (K+n) + 9);
        if (root * root != 8 * (K+n) + 9){
            root++;
            if (root * root != 8 * (K+n) + 9) root -= 2;
        }
        System.out.println(n - (root - 3) / 2);
        
        
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Comparator.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    private void solve() throws IOException {
        solveB();
    }

    private void solveA() throws IOException {
        int n = in.nextInt(), k = in.nextInt();
        int[] cnt = new int[k];
        for (int i = 0; i < n; i++)
            cnt[in.nextInt() - 1] ^= 1;
        int ans = 0;
        for (int i = 0; i < k; i++)
            ans += cnt[i];
        out.println(n - ans + (ans + 1) / 2);
    }

    private void solveB() throws IOException {
        long n = in.nextLong();
        long c = (n + in.nextLong()) * 2;
        long l = 0, r = (long) 1e9;
        while (l + 1 < r) {
            long m = (l + r) / 2;
            if (m * m + 3 * m >= c)
                r = m;
            else
                l = m;
        }
        out.println(n-r);
    }

    private void solveC() throws IOException {
    }

    private void solveD() throws IOException {
    }

    private void solveE() throws IOException {
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

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

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

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

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

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

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

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

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

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        for (int t = 1; t-- > 0; )
            solve();

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

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;


public class Main {




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

        InputStreamReader r = new InputStreamReader(System.in);
        BufferedReader f = new BufferedReader(r);

        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();
        long m=sc.nextLong();
        long sum=0;
        if(n==1){

        }else {
            for (long i = 1; i <= n; i++) {
                sum += i;
                if (sum - (n - i) == m) {
                    sum = n - i;
                    break;
                }
            }
        }
        System.out.println(sum);


    }
}
// 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.util.Scanner;

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

    static class TaskBR574D2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            long r = (long) (Math.sqrt(9 + 8 * (n + k)) - 3) / 2;
            out.println(n - r);
        }

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

public class B_574 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int N = Integer.valueOf(input[0]);
        int K = Integer.valueOf(input[1]);
        long sum = 0;
        for(int i = 0; i < N; i++){
            if(sum - (N - i) == K){
                System.out.println(Integer.valueOf(N-i));
                return;
            }
            sum += (i+1);
        }
        System.out.println("0");
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.util.*;
import java.io.*;
public class template {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
		int n = sc.nextInt();
		int k = sc.nextInt();
		long left = 0;
		long right = n;
		long mid = left+right/2;
		while(left<=right) {
			mid = (left+(right))/2;
			if(((mid+1)*mid)/2-(n-mid)==k) {
				pw.println(n-mid);
				pw.close();
				break;
			}
			else if(((mid+1)*mid)/2-(n-mid)>k) {
				right = mid-1;
			}
			else left = mid+1;
		}
	}
}
@SuppressWarnings("all")
class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

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

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}
// Problem: 1195_B. Sport Mafia
// Time complexity: logn
import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class B {
    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    static MyScanner sc;

    static {
        try {
            sc = new MyScanner();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        doTask();
        out.flush();
    }

    public static void doTask(){
        long n = sc.nextInt();
        long k = sc.nextInt();
        long c = -2*(n+k);
        long d =  9 - 4*c;
        double result = n - (-3 + Math.sqrt(1.0*d))/2;
        out.println(Math.round(result));
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() throws FileNotFoundException {
            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;
        }

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

public class B
{
	static long sumN(long n)
	{
		return n * (n + 1) / 2;
	}

	static int binSearchPuts(int n, int k)
	{
		int L = 1;
		int U = n;
		int M = (L + U) / 2;

		while(L <= U)
		{
			long left = sumN(M) - (n - M);
			
			if(left < k)
			{
				L = M + 1;
			}
			else if(left > k)
			{
				U = M;
			}
			else
			{
				break;
			}

			M = (L + U) / 2;
		}

		return M;
	}

	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);

		int n = input.nextInt();
		int k = input.nextInt();

		long ate = n - binSearchPuts(n, k);
		System.out.println(ate);
	}
}