Problem:
 Score : 400 points    Problem Statement We have N+1 integers: 10^{100} , 10^{100}+1 , ..., 10^{100}+N .  We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7) .      Constraints  1 \leq N \leq 2\times 10^5  1 \leq K \leq N+1  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  K       Output Print the number of possible values of the sum, modulo (10^9+7) .        Sample Input 1 3 2      Sample Output 1 10  The sum can take 10 values, as follows:   (10^{100})+(10^{100}+1)=2\times 10^{100}+1  (10^{100})+(10^{100}+2)=2\times 10^{100}+2  (10^{100})+(10^{100}+3)=(10^{100}+1)+(10^{100}+2)=2\times 10^{100}+3  (10^{100}+1)+(10^{100}+3)=2\times 10^{100}+4  (10^{100}+2)+(10^{100}+3)=2\times 10^{100}+5  (10^{100})+(10^{100}+1)+(10^{100}+2)=3\times 10^{100}+3  (10^{100})+(10^{100}+1)+(10^{100}+3)=3\times 10^{100}+4  (10^{100})+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+5  (10^{100}+1)+(10^{100}+2)+(10^{100}+3)=3\times 10^{100}+6  (10^{100})+(10^{100}+1)+(10^{100}+2)+(10^{100}+3)=4\times 10^{100}+6        Sample Input 2 200000 200001      Sample Output 2 1  We must choose all of the integers, so the sum can take just 1 value.       Sample Input 3 141421 35623      Sample Output 3 220280457

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, k = map(int, input().split())

    MOD = 10**9 + 7

    s = 0
    for i in range(k, n + 2):
        a = ((i - 1) * i) // 2
        s = (s + (n * i) - (2 * a) + 1) % MOD

    print(s)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
N,K=map(int,input().split())
MAX=2*(10**5)+1
P=10**9+7
"""A=[i for i in range(MAX)]
B=[0 for i in range(MAX)]
P=10**9+7
A[1]=1
print(len(A))
for i in range(1,MAX-1):
    A[i+1]=(A[i]*(i+1))%P
B[-1]=A[-1]
for i in range(0,MAX-1):
    B[MAX-i-2]=(B[MAX-i-1]*pow(MAX-i-1,P-2,P))%P"""

ans=0
for i in range(K,N+2):
    ans+=(2*N-i+1)*i//2 - (i-1)*i//2 + 1
    ans%=P
    
print(ans)

Solution (Python):
N,K=map(int,input().split())


count=0
for i in range(K,N+1+1):
    count+=1
    yoyu=N-i
    count += (N+1-i)*i % (10**9+7)
    count %= (10**9+7)
print(count)

Solution (Python):
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    kos=((N+(N-i+1))*i)//2-((i-1)*i)//2+1
    ans=(ans+kos)%(10**9+7)
print(ans)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N,K=MI()
    N+=1
    ans = ModInt(0)
    for k in range(K,N+1):
        ans += k*(N-k)+1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import pi



Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7










  
n,k=  Ri()
n+=1
pre = [0]*(n)
for i in range(n):
    if i==0:
        pre[i] = i
    else:
        pre[i] = pre[i-1]+i
suf = [0]*(n)
for i in range(n-1,-1,-1):
    if i ==n-1:
        suf[i] = n-1
    else:
        suf[i] = suf[i+1]+i
summ = 0
for i in range(k,n+1):
    dif =suf[n-i]-pre[i-1]+1
    
    summ+=dif
    summ = summ%MOD
print(summ)

Solution (Python):
mod = 10 ** 9 + 7
N, K = map(int, input().split())
ans, R, L = 1, N * (N + 1) // 2, N * (N + 1) // 2
for i in range(N + 1 - K):
    R, L = R - i, L - (N - i)
    ans = (ans + R - L + 1) % mod
print(ans)

Solution (Python):
n,k = map(int, input().split())
mod = 10**9 + 7

starts=list(range(n+1))
ends=list(reversed(list(range(n+1))))

init_starts=sum(starts[0:k-1])
init_ends=sum(ends[0:k-1])

sums=0
for i in range(k-1,n+1):
    init_starts+=starts[i]
    init_ends+=ends[i]
    sums+=init_ends-init_starts+1
    sums%=mod
print(sums)

Solution (Python):
n, k = map(int, input().split())

counter = 0
mod = 10**9 + 7
for x in range(k, n+1):
    num = (x * n) - (x * (x - 1)) + 1
    counter += num
    counter %= mod
else:
    counter += 1
    counter %= mod
print(counter)

Solution (Python):
import numpy as np
if __name__ == "__main__":
    
    
    
    N, K = map(int, input().split())
    nums = np.array(range(N+1))
    a = np.cumsum(nums)
    b = np.cumsum(nums[::-1])
    
    
    ans = 0
    for k in range(K, N+1+1):
        
        
        ans += b[k-1] - a[k-1] + 1
    print(ans % (10**9+7))

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n, k = map(int, input().split())
    ans = 0
    div = 10 ** 9 + 7
    for i in range(k, n + 2):
        tmp = 0
        
        
        if i == n + 1:
            ans += 1
        else:
            ans += (2 * n - i + 1) * i / 2 - (i - 1) * i / 2 + 1

    print(int(ans % div))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 2"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """200000 200001"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """141421 35623"""
        output = """220280457"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
n, k = map(int, input().split())
total = 0
for l in range(k,n+2):
    total += l*n-l*(l-1)+1
print(total%1000000007)

Solution (Python):
n, k = list(map(int, input().split()))
mod = 1000000007
nums = [i for i in range(n + 1)]
ans = 0

for i in range(k, n + 2):
	mx = n * (n + 1) // 2 - (n - i) * (n - i + 1) // 2
	mn = i * (i - 1) // 2
	ans += (mx - mn + 1) % mod
	ans %= mod
print(ans)

Solution (Python):
n, k = map(int, input().split())
ans = 0

for c in range(k, n+2):
	ans = (ans + (c * (n-c+1) + 1)) % (10**9+7)

print(ans % (10**9+7))

Solution (Python):
mod = 1000000007

def sum_(a, b):
    return int((a+b)*(b-a+1)/2)

def main():
    args = input().rstrip().split(' ')
    N, K = int(args[0]), int(args[1])
    
    Ans = 0
    for i in range(K, N+2):
        sum_b = sum_(0, i-1)
        sum_u = sum_(N-i+1, N)
        Ans += (sum_u-sum_b)+1
        Ans = Ans % mod
    print(Ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()

rui = [0]
for i in range(1,N+1):
  rui.append(rui[-1] + i)

ans = 0
for i in range(K,N+1):
  ans += (rui[-1] - rui[-i-1]) - rui[i-1] +1
print((ans +1) %mod)

Solution (Python):



M = pow(10, 9) + 7


def main():
    n, k = map(int, input().split())

    ans = 0
    for i in range(n - k + 1 + 1):
        ans += range_sum(i, n) % M - range_sum(0, n - i) % M + 1
        ans %= M
    print(ans)


def range_sum(a, b):
    if a < 1:
        return b * (b + 1) // 2
    else:
        return b * (b + 1) // 2 - a * (a - 1) // 2


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque

from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

    
n,k=MI()
def standard(a,b):
    return b*(a-b+1)+1
def ansum(a,b):
    ansum=0
    for i in range(b,a):
        ansum+=standard(a,i)
    return ansum

anslarge=n+2
if k==1:
    if n==1:
        ans=3
    else:
        ans=ansum(n,2)+n+1+anslarge
elif k==n+1:
    ans=1
elif k==n:
    ans=n+2
else:
    ans=ansum(n,k)+anslarge
print(ans%mod)

Solution (Python):
from itertools import accumulate

def main():
    N, K = map(int, input().split())
    MOD = 10 ** 9 + 7
    A = list(range(0,N+1))
    B = list(accumulate(A))
    A.reverse()
    C = list(accumulate(A))
    ans = 0
    for r in range(K, N+2):
        r -= 1
        t_max = C[r]
        t_min = B[r]
        ans += t_max - t_min + 1 
        ans %= MOD
    print(ans)





if __name__ == "__main__":
    main()

Solution (Python):
N,K = list(map(int,input().split()))
ans = 0
for i in range(K,N+2):
    if i == 1:
        ans += N + 1
    elif i == 2:
        ans += 2*N - 1
    else:
        ans += N*i - i*(i-1) + 1
print(ans % (10**9 + 7))

Solution (Python):
A=list(map(int, input().split()))

N=A[0]
K=A[1]
sum_N = 0
for i in range(K,N+2):
    sum_N+=i*N-i*(i-1)+1

print(sum_N%(10**9+7))

Solution (Python):
n,k = map(int,input().split())
mod = 1000000007

memo = []
for i in range(0,n+1):
    memo.append(i)

shou = sum(memo[:k-1])
dai = sum(memo[n-k+2:])

ans = 1
for i in range(k-1,n):
    dai += memo[-i-1]
    shou += memo[i]
    ans += dai-shou+1
    ans = ans%mod
    
print(ans)

Solution (Python):
N, K = map(int, input().split())
MOD = 10**9 + 7

min_sum = sum(range(K))
max_sum = sum(range(N + 1 - K, N + 1))
ans = 0
for i in range(K, N + 2):
    ans += max_sum - min_sum + 1
    ans %= MOD
    min_sum += i
    max_sum += (N - i)
print(ans)

Solution (Python):

import sys
import numpy as np
import itertools

sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


N, K = map(int,input().split())


m = np.arange(1,N+2)
m1 = np.arange(N+1,0,-1)

for i in range(1,len(m)):
    m[i] = (m[i] + m[i-1])%mod
    m1[i] = (m1[i] + m1[i-1])%mod






ans = 0
for i in range(K-1,N+1):
    ans += m1[i] - m[i] + 1
    ans %= mod

print(ans)

Solution (Python):
MOD = 10 ** 9 + 7

n, k = map(int, input().split())
l = [0] * ((n + 1) // 2)
l[0] = n + 1
ans = 0

for i in range(1, (n + 1) // 2):
    l[i] = (l[i - 1] + (n - i * 2)) % MOD

for i in range(k, n + 1):
    if i <= (n + 1) // 2:
        ans += l[i - 1]
    else:
        ans += l[n - i]
    ans %= MOD

print((ans + 1) % MOD)

Solution (Python):
n,k=map(int,input().split())
print(sum([(n*(n+1))//2-((n+1-i)*(n-i))//2-(i*(i-1))//2+1 for i in range(k,n+2)])%(10**9+7))

Solution (Python):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0

for i in range(K, N + 2):
    p = 0 + i - 1
    q = N - i + 1
    P = p * (p + 1) // 2
    Q = P + (i * q)
    ans += Q - P + 1
    ans %= MOD
print(ans)

Solution (Python):
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(K, N+2):
    min = 0
    max = 0
    min = (i*(i-1))//2
    max = i*N-min
    ans += max-min+1
print(ans % (10**9+7))

Solution (Python):
from sys import stdin
n,k = [int(x) for x in stdin.readline().rstrip().split()]
answer = 0
while k <= n+1:
    min = k*(k-1)//2
    max = n*(n+1)//2
    t = n+1-k
    max -= t*(t-1)//2
    answer += max-min+1
    answer %= 1000000007
    k += 1
print(answer)

Solution (Python):
import math


def comb(n, r):
    mf = math.factorial
    return mf(n) // (mf(n - r) * mf(r))


n, k = map(int, input().split())

ans = 0
for i in range(k, n + 2):
    l = (n + (n - 1 * (i - 1))) * i // 2
    a = (0 + (0 + 1 * (i - 1))) * i // 2 - 1
    ans += l - a

print(ans % (10**9 + 7))

Solution (Python):
N,K = list(map(int, input().split()))

ans = 0

for i in range(K,N+2):
    ans += (N-(i-1))*i + 1
    if ans > 10**9 + 7:
        ans = ans % (10**9 + 7)

print(ans)

Solution (Python):
def solve():
    MOD = 10 ** 9 + 7
    N, K = map(int,input().split())
    mn = sum(list(range(K)))
    mx = sum(list(range(N,N-K,-1)))

    cnt = 0
    for i in range(K,N+2):
        if i != K:
            mn += i-1 % MOD
            mx += N-(i-1) % MOD
        cnt += mx % MOD - mn % MOD + 1 % MOD

    print(cnt % MOD)

if __name__ == '__main__':
    solve()

Solution (Python):
N, K = map(int, input().split())
sum = 0
for i in range(K, N+1+1):
    sum += (N*i-i*(i-1)+1)%(10**9+7)
    sum = sum%(10**9+7)
print(sum)

Solution (Python):
import math

n, k = map(int, input().split(" "))              

ans = ((k-1)/6)*(2*k**2 + (-3*n-4)*k -6 ) + ( n**3 + 3*n**2 + 8*n)/6
print((math.ceil(ans)+1) % (10**9 + 7))

Solution (Python):
MOD = 10**9+7
N, K = map(int, input().split())


ans = 0
for i in range(K, N+2): 
    minSum = (i-1)*i//2
    maxSum = (2*N+1-i)*i//2
    cnt = maxSum - minSum + 1
    
    
    ans += cnt
    ans %= MOD

print(ans)

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,k=map(int, readline().rstrip().split())

    mod = 10**9+7
    a=0
    z=0
    ans=0
    n+=1
    for i in range(1,n+1):
        a+=i
        z+=(n-i+1)
        cnt=z-a+1
        if i>=k:
            ans=(ans+cnt)%mod
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  

N, K = read_ints()





ans = 0
for k in ra(K, N + 2):
    tmp = ((N + N - (k - 1)) * k // 2) - ((0 + k - 1) * k // 2) + 1
    
    ans += tmp
    ans %= MOD
print(ans)

Solution (Python):
N, K = map(int,input().split())

ans = 0
s = sum(range(K-1))
for i in range(K, N+2):
    s += i - 1
    max_add = N * i - s
    min_add = s
    ans += max_add - min_add + 1

print(ans % (1000000007))

Solution (Python):
n,k = map(int,input().split())

sum_list = [i*(n-i+1)+1 for i in range(1,n+2)]

print(sum(sum_list[k-1::])%(10**9+7))

Solution (Python):
n, m = map(int, input().split(' '))

b = (n + 1)*(n**2 + 2*n + 6)
a = m*(2*m**2 - 3*m*(n + 2) + 3*n - 2)

ans = (a + b)//6+1
ans = ans % 1000000007
print(ans)

Solution (Python):
MOD = 10**9 + 7
N, K = map(int, input().split())

ans = 0
for k in range(K, N+2):
    ans += N*k - (k*(k-1)) + 1
print(ans % MOD)

Solution (Python):
N, K = map(int,input().split())
su = 0

for i in range(K, N+2):
    su += (1 + (N+1)*i -i**2)

ans = su % (7 + 10**9)
print(ans)

Solution (Python):
N, K = (int(x) for x in input().split())
sum = 0
for i in range(K, N+2):
    j = i*N - (i-1)*i + 1
    if j > 0:
        sum = sum + j
print(sum % 1000000007)

Solution (Python):
N, K = map(int, input().split())
mod = 10**9 + 7
ans = 1

prev = 1
for k in range(1, N+1):
    prev = prev - (k-1) + N - (k-1)
    if k >= K:
        ans += prev
        ans %= mod


print(ans % mod)

Solution (Python):
n, m = map(int, input().split(' '))

b = (n + 1)*(n**2 + 2*n + 6)
a = m*(2*m**2 - 3*m*(n + 2) + 3*n - 2)

ans = (a + b)//6+1
ans = ans % 1000000007
print(ans)

Solution (Python):
n, k = (int(i) for i in input().split())
c = 0
for x in range(k, n+2):
    h = x * (x - 1) / 2
    t = x * (n + n - x + 1) / 2
    c = c + (t - h) + 1
print(int(c%(10**9+7)))

Solution (Python):
n,k = map(int,input().split())
mod = 10**9+7
l = [i for i in range(n+1)]
rl = [i for i in range(n,-1,-1)]
suml = [0]*(n+1)
suml[0] = l[0]
for i in range(n):
    suml[i+1] = suml[i] + l[i+1]
sumrl = [0]*(n+1)
sumrl[0] = rl[0]
for i in range(n):
    sumrl[i+1] = sumrl[i] + rl[i+1]
cnt = 0
for m in range(k,n+2):
    max_m = sumrl[m-1]
    min_m = suml[m-1]
    cnt += max_m-min_m+1
print(cnt%mod)

Solution (Python):
N, K = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 0
for i in range(K, N+1):
    ans += (i*(N-i+1 + N))//2 - i*(0+ 0+i-1)//2 + 1
    ans %= MOD
ans = (ans + 1) % MOD
print(ans)

Solution (Python):

"""
Created on Sun Apr 19 21:12:01 2020

@author: black
"""


N, K = map(int, input().split())
List = [n for n in range(N)]

total = 1
for k in range(K, N+1):
    total += N*k-(k-1)*k+1
    total = total%(10**9+7)
print(total)

Solution (Python):
N,K=map(int,input().split())
ans=0
MOD=10**9+7
for i in range(K,N+1):
    Min=(1+i)*i//2
    Max=(2*N+3-i)*i//2
    ans=ans+Max-Min+1
print((ans+1)%MOD)

Solution (Python):
if __name__ == "__main__":
    n, k = map(int, input().split())
    n += 1
    sum_ = 0
    sums = [0]

    for i in range(1, n):
        sums.append(sums[-1] + i)

    for i in range(k, n + 1):
        if i == n:
            sum_ += 1
            continue
        up = (sums[-1] - sums[-i - 1])
        low = sums[i - 1]
        tmp = up - low + 1
        sum_ += tmp

    print(sum_ % (10 ** 9 + 7))

Solution (Python):
MOD = 10**9 + 7
def mySum(a, b):
    return (a + b) * (b - a + 1) // 2 % MOD

N, K = list(map(int, input().split()))
l = mySum(N-K+1, N) - mySum(0, K-1) + 1
res = l
for i in range(K, N+1):
    l = l - i + (N-i)
    res += l
    res %= MOD
print(res)

Solution (Python):
N,K=map(int,input().split())
a=[]
ans=0
for i in range(K,N+2):
  ans+=(N+1+N+2-i)*i/2-(1+i)*i/2+1
print(int(ans%1000000007))

Solution (Python):
n,k=map(int,input().split())
mod=10**9+7
ans=0
for i in range(k,n+2):
  mx=i*n-i*(i-1)//2
  mn=(i-1)*i//2-1
  ans+=(mx-mn)%mod
print(ans%mod)

Solution (Python):
def LI():return list(map(int,input().split()))
n,k=LI()
mod=10**9+7
ans=0
for kk in range(k,n+1+1):
    tmp=n*kk-(kk-1)*kk+1
    ans+=(tmp%mod)
print(ans%mod)

Solution (Python):
from sys import stdin

[N, K] = [int(x) for x in stdin.readline().rstrip().split()]










num_sum = 0
waru = 10**9+7
for i in range(K, N+2):
    num_sum += (2*N - i + 1)*i/2 - (i-1)*i/2 + 1
    
    num_sum = num_sum%waru

print(int(num_sum))

Solution (Python):
from sys import stdin
import sys


N, K = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

for i in range(K, N+2):
    
    min = 0
    max = 0
    min = (i*(i-1))//2
    max = i*N-min
    
    
    
    
    
    
    
    ans += max-min+1
print(ans%(10**9+7))

Solution (Python):
"""
NTC here
"""
 


import os
import sys
from io import BytesIO, IOBase

def iin(): return int(input())
 
 
def lin(): return list(map(int, input().split()))

def main():
    T = 1
    while T:
        md = 10**9+7
        T-=1
        n, k = lin()
        ans = [0]*(n+1)

        l, h = 0, n
        s1, s2 = 0, n
        for i in range(n+1):
            ans[i]+=s2-s1+1
            l+=1
            h-=1
            s1+=l
            s2+=h
        print(sum(ans[k-1:])%md) 
        
        










BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
  maxs=i*(2*n-i+1)//2
  mins=i*(i-1)//2
  ans+=maxs-mins+1
  ans%=10**9+7
  
  
  
print(ans%(10**9+7))

Solution (Python):
n, k = map(int, input().split())

def calc_k(k):
  return k*n - k*(k-1) + 1


m = 10**9+7
ans = 0

for i in range(k, n+2):
  ans += calc_k(i)%m
  
print(ans%m)

Solution (Python):
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()



x = readInts()
n = x[0]
k = x[1]

def ts(l):
	return int((l*(l-1))/2)

def ts2(l):
	return int(l*(n+n-(l-1))/2)









s = 0

for i in range(k,n+2):
	
	
	
	s += ts2(i)+1-ts(i)

print(s%(1000000007))

Solution (Python):

import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def lcm(a,b):return (a*b) // gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,K = imn()

c = [0 for _ in range(N+1)]
c[0] = N
tmp = N
for i in range(1, N+1):
    c[i] = c[i-1] + tmp-i

ans = 0
for i in range(K, N+2):
    if i == 1:
        min_v = 0
        max_v = N
    else:
        min_v = i*(i-1)//2
        max_v = c[i-1]
    ans += max_v-min_v+1
print(ans%MOD)

Solution (Python):
def main():
    n,k=map(int,input().split())
    mod=10**9+7
    if n-k==-1:
        print(1)
    else:
        ans=(n+2*k)*(n-k+1)*(n-k+2)//6+n-k+2
        print(ans%mod)
if __name__=="__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
ans = 0
for i in range(K, N+2):
    ans += i * (N - i + 1) + 1
    ans %= 1000000007
print(ans)

Solution (Python):
n, k = map(int, input().split())

MOD = 10**9 + 7

s = [0 for _ in range(n+2)]
v = 0
for i in range(n+2):
    v += i
    s[i] = v

ans = 0
for i in range(k, n+2):
    t = (s[n+1] - s[n+1-i]) - s[i] + 1
    ans += t
    ans %= MOD
print(ans)

Solution (Python):
n, k = map(int, input().split())
ans = 0
mod = 1000000007

maxNum = 0
minNum = 0

for i in range(k):
    maxNum += n - i
    minNum += i

for i in range(k, n+2):
    ans += maxNum - minNum + 1
    ans %= mod
    maxNum += n-i
    minNum += i

print(ans)

Solution (Python):
n, k = [int(x) for x in input().split()]

res = 0
for i in range(1, n+2):
    if i < k:
        continue
    max_sum = -(i**2)/2 + n*i + i/2
    min_sum = (i**2)/2 - i/2
    res += max_sum - min_sum + 1
    res = res % (10**9+7)
print(int(res))

Solution (Python):
n,k=map(int,input().split())
a=[i for i in range(n+1)]

b=[0]
c=[a[-1]]
for i in range(1,n+1):
    b.append(i+b[i-1])
    c.append(c[i-1]+(n-i))


if n+1==k:
    print(1)
else:
    s=0
    for i in range(k-1,n+1):
        s+=abs(b[i]-c[i])+1
    print(s%1000000007)

Solution (Python):
import sys
import numpy as np


n,k=map(int,sys.stdin.readline().split())



ans=0
mod=10**9+7
for i in range(k,n+2):
   ans+=(i*(n-i+1)+1)%(mod)

print(ans%(mod))

Solution (Python):
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
ints = lambda: list(map(int, input().split()))
mod = 10**9+7
n,k = ints()
def f(x,N):
    a = 2*x**2
    c = 3*N
    b = c*x
    return int(x*(-a+b+c+8)/6)

print((f(n+1,n)-f(k-1,n))%mod)

Solution (Python):
N,K=map(int,input().split())
N+=1
s=0
for i in range(K,N+1):
  s+=(N-i)*i+1
print(s%1000000007)

Solution (Python):
N, K = map(int, input().split())

MOD = 10**9 + 7
sum = 0
for j in range(K, N+1):
    MIN = j * (j-1) // 2
    MAX = (N+1)*N//2 - (N+1-j)*(N-j)//2
    
    sum += MAX - MIN + 1
    
print(sum % MOD + 1)

Solution (Python):
n,k= map(int, input().split())
ans=0
mod=10**9+7
for i in range(k,n+2):
    ans+=(n+(n-i+1))*i//2-(i-1)*i//2+1
    ans%=mod
print(ans)