{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  print $ solve n k

solve :: Integer -> Integer -> Integer
solve n k = ((12 + 2 * k ^ 3 + 8 * n + 3 * n ^ 2 + n ^ 3 - 3 * k ^ 2 * (2 + n) + k * (-2 + 3 * n)) `div` 6) `mod` m

m :: Num a => a
m = 10 ^ (9 :: Int) + 7
