{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

modulus :: Int
modulus = 1000000007

main :: IO ()
main = do
    (n,k) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let f :: [Int] -> Int
        f []     = 0
        f (x:xs) = (-x^2+(n+1)*x+1 + f xs) `mod` modulus
    print $ f [0..n+1-k]