tr_dot::Int-> Int
tr_dot n = div (n*(n+1)) 2

ans::Int -> Int -> Int
ans s k = if (k <= s) && ((2*k) >= s) then (tr_dot (s+1)) - (3*(tr_dot (s-k)))
                                      else if (k > s) then   (tr_dot (s+1))
                                                      else  tr_dot (((3*k)-s)+1)
main::IO()
main = do
  ksc<-getLine
  let k:s:[] = map read (words ksc)::[Int]
  print (ans s k)