import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  }
} Main public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  } main {
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  } Scanner s = new Scanner(System.in); s new Scanner(System.in) int K = s.nextInt(); K s.nextInt() s.nextInt s int S = s.nextInt(); S s.nextInt() s.nextInt s int Ans = 0; Ans 0 if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2; S <= K S K Ans = (S+1) * (S+2) / 2 Ans (S+1) * (S+2) / 2 (S+1) * (S+2) (S+1) S 1 (S+2) S 2 2 if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2; K < S && S <= 2*K K < S K S S <= 2*K S 2*K 2 K Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2 Ans (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2 (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2 (K+1)*(K+1) (K+1) K 1 (K+1) K 1 (2*K - S +1)*(2*K - S)/2 (2*K - S +1)*(2*K - S) (2*K - S +1) 2*K - S 2*K 2 K S 1 (2*K - S) 2*K 2 K S 2 (S -K +1)*(S-K)/2 (S -K +1)*(S-K) (S -K +1) S -K S K 1 (S-K) S K 2 if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2; 2*K <= S 2*K 2 K S Ans = (3*K -S +1)*(3*K - S +2)/2 Ans (3*K -S +1)*(3*K - S +2)/2 (3*K -S +1)*(3*K - S +2) (3*K -S +1) 3*K -S 3*K 3 K S 1 (3*K - S +2) 3*K - S 3*K 3 K S 2 2 System.out.println(Ans) System.out.println System.out System System.out Ans String args[] args public class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  }
} public class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
    int K = s.nextInt();
    int S = s.nextInt();
    int Ans = 0;
    if (S <= K)
      Ans = (S+1) * (S+2) / 2;
    else if (K < S && S <= 2*K)
      Ans = (K+1)*(K+1) - (2*K - S +1)*(2*K - S)/2 - (S -K +1)*(S-K)/2;
    else if (2*K <= S)
      Ans = (3*K -S +1)*(3*K - S +2)/2;
    System.out.println(Ans);
  }
}
