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



Sample input:
3 2


Sample output:
10

Submission status: Accepted

Solution code:
def main():
    mod=1000000007
    n,k=map(int,input().split())
    ans=0
    for i in range(k,n+2):
        l=i*(i+1)//2
        r=i*(2*n-i+3)//2
        ans+=r-l+1
        ans%=mod
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
n,k = map(int,input().split())
n += 1
mod = 10 ** 9 + 7
ans = 0
lis = [i for i in range(n)]
left = [0]
right = [lis[-1]]
for i in range(1,n):
    left.append(left[-1]+i)
for i in range(n-2,-1,-1):
    right.append(right[-1]+i)
for i in range(k-1,n):
  #    print(right[i],left[i])
    ans += max(0,right[i]-left[i]+1)%mod
    ans %= mod
  #print(left,right)
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
mod=(10**9)+7

ans=0

L=[i+1 for i in range(N+1)]
#print(L)

l=L[::-1]
#print(l)
RUI=[L[0]]
for i in range(1,len(L)):
    RUI.append(RUI[-1]+L[i])
#print(RUI)
rui=[l[0]]
for i in range(1,len(l)):
    rui.append(rui[-1]+l[i])
#print(rui)

ans=0
for i in range(N+1):
    I=N+1-i
    if I<M:
        break
    ans+=(rui[I-1]-RUI[I-1]+1)
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
P=10**9+7
#print(pow(10,100,P))
#X=226732710
#S=P-(X-1)

def culc():
    global N
    global K
    global P

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

print(culc())

Submission status: Accepted

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

Submission status: Accepted

Solution code:

MOD = 10 ** 9 + 7

def main():
    for _ in inputt(1):
        n, k  = inputi()
        t = 0
        for z in range(k, n + 2):
            t = (t + z * (n + 1 - z) + 1) % MOD
        print(t)

# region M


# region import
# 所有import部分

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)

# endregion

# region fastio
# 快速io，能提升大量时间

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.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(io.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):
    sys.stdout.write(kwargs.pop("split", " ").join(map(str, args)))
    sys.stdout.write(kwargs.pop("end", "\n"))
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda: map(int, inputs())
inputl = lambda t = 0, k = inputi: map(list, (k() for _ in range(t))) if t else list(k())

# endregion

# region bisect
# 二分搜索，标准库没有函数参数

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# 稀疏矩阵 图论部分
class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory
# number theory 数论部分
class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        pass


sieve = Sieve()
def isprime(n):
    pass
def prime(n):
    pass
def factorint(n):
    factordict = defaultdict(int)
    for i in sieve:
        if n <= i * i:
            break
        while not n % i:
            factordict[i] += 1
            n //= i
    if n != 1:
        factordict[n] += 1
    return factordict
# endregion

# region main
# main 函数部分

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7


def solve(n, k):
    cum_left = [0] * (n + 2)
    cum_right = [0] * (n + 2)
    for i in range(n + 1):
        cum_left[i + 1] = cum_left[i] + i
        cum_right[i + 1] = cum_right[i] + n - i
    # print(cum_left, cum_right)
    res = 0
    for i in range(k, n + 2):
        res += cum_right[i] - cum_left[i] + 1
        res %= MOD
    return res


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


def test():
    assert solve(3, 2) == 10
    assert solve(200000, 200001) == 1
    assert solve(141421, 35623) == 220280457


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())

mod = 1000000007

count = 0

for i in range(k, n+2):
    sum_i = i * (i-1) /2
    count_i = i*n - 2*sum_i + 1
    count+=count_i
    count%=mod
print(int(count))

Submission status: Accepted

Solution code:
def Count(N,i):
    return i*N+1-(i*(i-1))
N, K = map(int,input().split())
sumpat=0
bignum = pow(10,9)+7
for i in range(K,N+2):
    # print(Count(N,i))
    sumpat+= Count(N,i)%bignum
print(sumpat%bignum)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
ans = 0
tmp = n*(n-1)//2
l = k*(k-1)//2
r = ((n-k+1)+n)*k//2
tmp = n-k
tmp2 = k
for i in range(k,n+2):
    ans += r-l+1
    ans %= mod
    l += tmp2
    r += tmp
    tmp2 += 1
    tmp -= 1
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
m = n+1
s = 0
mod = 10**9 + 7
while m >= k:
    s += m * (n-m+1) + 1
    s = s % mod
    m -= 1
print(s)

Submission status: Accepted

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

res = 0
P = 10 ** 9 + 7
for i in range(K, N + 2):
    head = i * (i - 1) // 2#先頭i個の和
    tail = i * (2*N - i + 1) // 2#先頭i個の和
    res += tail - head + 1
    res %= P
print(res)

Submission status: Accepted

Solution code:
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    NN = np.array([n for n in range(N+1)], dtype=int)
    Ncumsum = NN.cumsum()
    Nrev_cumsum = NN[::-1].cumsum()
    ans = 0
    MOD = 10 ** 9 + 7
    for k in range(K-1, N+1):
        ans += Nrev_cumsum[k] - Ncumsum[k] + 1
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

mod=10**9+7
A=[0]*(N+1)

for i in range(N+1):
    if i==0:
        A[0]=N+1
    else:
        A[i]=A[i-1]+(N-2*i)
        A[i]%=mod

s=0
for i in range(K-1,N+1):
    s+=A[i]
    s%=mod

print(s)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate
MOD = 10 ** 9 + 7


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

def main():
    a = range(n + 1)
    sl = list(accumulate(a))
    sr = list(accumulate(a[::-1]))

    res = 0
    for i in range(k, n + 2):
        res += sr[i-1] - sl[i-1] + 1
        res %= MOD
    print(res)



    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

dum = list(range(N+1))

cnt = 0
minv = sum(dum[:K])
maxv = sum(dum[-K:])
for i in range(K, N+2):
    cnt += maxv-minv+1
    if cnt > MOD:
        cnt %= MOD
    minv += i
    maxv += N-i
print(cnt)

Submission status: Accepted

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

mod = 10**9 + 7


def f(k):
    min_r = k * (k-1) // 2
    max_r = (n + n+1-k) * k // 2
    return max_r - min_r + 1

ans = 0
for i in range(k, n+2):
    ans += f(i)
    ans %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
def f(a,N):
  minf=(a-1)*a//2
  maxf=(2*N-a+1)*a//2
  return maxf-minf+1
mod=10**9+7
ans=0
for i in range(K,N+2):
  ans+=f(i,N)%mod
print(ans%mod)

Submission status: Accepted

Solution code:
MOD = 1000000007
lim = 10 ** 4+1
fac = [0] * lim
finv = [0] * lim
inv = [0] * lim

class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)
    def __int__(self):
        return self.x

    __repr__ = __str__

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

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
    
    def __iadd__(self,other):
        self.x += other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self

    def __isub__(self,other):
        self.x += ModInt(MOD - other.x) if isinstance(other, ModInt) else ModInt(MOD - other)
        return self

    def __imul__(self, other):
        self.x *= other.x if isinstance(other, ModInt) else other
        self.x %= MOD
        return self
    
    def __ifloordiv__(self, other):
        self.x *= pow(int(other), MOD - 2, MOD)
        return self
    
    def factorical(self,n):
        tmp = ModInt(1)
        for i in range(n):
            tmp *= (i+1)
        return tmp
    
    #m:int MOD
    def modinv(self,a,m=MOD):
        b = m
        u = 1
        v = 0
        while(b):
            t = a//b
            a -= t * b
            a,b = b,a
            u -= t * v
            u,v = v,u
        return ModInt(u)

    def comb(self,n,r):
        n = int(n)
        r = int(r)
        if r > n or n < 0 or r < 0:
            return 0
        m = n+1
        nterms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, nterms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)

def COMinit():
    fac[0] = ModInt(1)
    fac[1] = ModInt(1)
    finv[0] = ModInt(1)
    finv[1] = ModInt(1)
    inv[1] = ModInt(1)
    for i in range(2,lim):
        fac[i] = ModInt(fac[i - 1] * i)
        inv[i] = ModInt(MOD - inv[MOD%i] * (MOD // i))
        finv[i] = ModInt(finv[i - 1] * inv[i])

def cmb(n,k) -> ModInt:
    if int(n) < int(k):
        return ModInt(0)
    if int(n) < 0 or int(k) < 0:
        return ModInt(0)
    if fac[0] == 0:
        COMinit()
    tmp = ModInt(finv[int(k)] * finv[int(n - k)])
    tmp *= fac[int(n)]
    return tmp


        
if __name__ == "__main__":
    n,k = map(int,input().split())
    ans = ModInt(0)
    for i in range(k,n+2):
        mini = i*(i-1)//2
        maxi = (n+n-i+1)*i//2
        ans += maxi-mini+1
    print(ans)

Submission status: Accepted

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

MOD=10**9+7

def sum_l(a,b):
    return (b-a+1)*(a+b)//2 %MOD

count=0
for i in range(k,n+1):
    min_i=sum_l(0,i-1)
    max_i=sum_l(n-i+1,n)
    count+=(max_i-min_i+1)%MOD

print((count+1)%MOD)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()

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

Submission status: Accepted

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

cnt = 0
mod = 10 ** 9 + 7

for i in range(k, n + 2):
    cnt += i * n - (1 + i - 1) * (i - 1) + 1
    cnt %= mod
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, input().split())
lst = list(range(N + 1))

MOD = 10 ** 9 + 7

small = 0
for i in range(K-1):
    small += lst[i]

big = 0
for i in range(1, K):
    big += lst[-i]

ans = 0
for i in range(K, N + 2):
    small += lst[i - 1]
    big += lst[-i]

    ans += big - small + 1
    ans %= MOD


print(ans % MOD)

Submission status: Accepted

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

ans = 0
for i in range(k, n+2):
    x = (i - 1) * i // 2
    y = (2 * n - i + 1) * i // 2
    ans = (ans + y - x + 1) % mod

print(ans)

Submission status: Accepted

Solution code:
import math
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""


            
       

t=1
for term in range(1,t+1):
    n,k=map(int,input().split())
    A=[i for i in range(n+1)]
    B=[0]
    for i in range(1,n+2):
        B.append(B[i-1]+A[i-1])
    ans=0
    while(k!=n+2):
        minsum=B[k]
        maxsum=B[-1]-B[-k-1]
        # print(k,minsum,maxsum)
        ans=(ans+maxsum-minsum+1)%(int(1e9+7))
        k+=1
    print(ans)

Submission status: Accepted

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

count = 0
for i in range(K, N+2):
    # print(i, (i-1)*i/2, (N+1-i+N)*i/2)
    count += (N+1-i+N)*i/2 - (i-1)*i/2 +1
    # if i == 10:
    #     break
print(int(count)%(10**9+7))

Submission status: Accepted

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

MOD = 1000000007
res = 0
for i in range(k, n+2):
  res += i*(n-i+1) + 1
  res = res%MOD
  
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
sum = 0

for i in range(k, n+2):
	minunchi = (i*(i-1))//2
	maxunchi = (n*(n+1))//2 - ((n+1-i)*(n-i))//2
	sum += maxunchi - minunchi + 1

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#n = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

x = 0
y = 0
for i in range(1, k):
    x += i-1
    y += n-i+1

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,math,copy,queue,itertools,bisect
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))
N,K = LI()
ans = 0
for i in range(K,N+2):
    ans = (ans + (N*i - (i-1) * i // 2) - i*(i-1) // 2 +1) % MOD
print (ans)

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

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

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

MAX = 510000

fac  = [0]*MAX
finv = [0]*MAX
inv  = [0]*MAX

def cominit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;

def mod_com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;

#cominit()

n,k= l_in()
res = 0

m=0
l=0
for i in range(1, k):
    m += n-i+1
    l += i-1
#    print(i,m,l)

for i in range(k,n+2):
    m += n-i+1
    l += i-1
#    print(i,m,l)
    res = mod_add(res, m-l+1)

print(res)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = [0] * (n + 1)
for i in range(1, n + 1):
    a[i] = i
c1 = [0] * (n + 1)
c1[1] = 1
for i in range(2, n + 1):
    c1[i] = c1[i - 1] + a[i]
# print(c1)
c2 = [0] * (n + 1)
c2[n] = a[n]
for i in range(n - 1, -1, -1):
    c2[i] = c2[i + 1] + a[i]
c2.reverse()
# print(c2)
ans = 0
for i in range(k - 1, n + 1):
    ans += c2[i] - c1[i] + 1
print(ans % 1000000007)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

ans = 0
for t in range(k, n+2):
    mini = t * (t-1) // 2 % mod
    residue = n - t + 1
    maxim = mini + t * residue
    maxim %= mod
    count = maxim - mini + 1
    count %= mod
    ans += count
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
box = [n for n in range(N+1)]
MOD = int(1e9) + 7
ans = 0

# 部分和
bubu = []
bubu.append(box[0])
for el in range(N+1):
    if el == 0:
        continue
    else:
        bubu.append(bubu[el - 1] + box[el])

rbubu = []
rbubu.append(box[-1])
for el in reversed(range(N+1)):
    if el == N:
        continue
    else:
        rbubu.append(rbubu[-1] + box[el])

for i in range(K, N+2):
    temp = (rbubu[i-1] - bubu[i-1] + 1) % MOD
    ans += temp
    ans = ans % MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
MOD = 10**9+7
n, k = map(int, sys.stdin.readline().split())
res = 0
for kk in range(k, n+2):
    mm = (kk-1)*kk // 2
    MM = (n-kk + n + 1) * kk // 2
    #print (mm,MM)
    res = (res + (MM-mm+1)) % (MOD)
print(res)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
M = 10**9 + 7
T = pow(10,100,M)
ans = 0
for k in range(K, N+2):
    ans += (2*N-k+1)*k//2 - k*(k-1)//2 + 1
    ans %= M
print(ans)

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
s=0
for i in range(k,n+2):
  s=(s+int((i*(2*n+1-i)-i*(i-1))/2+0.01)+1)%1000000007
print(s)

Submission status: Accepted

Solution code:
M = 10**9 + 7
n, k = [int(c) for c in input().split()]
out = 0
for kk in range(k, n+2):
    mm = kk * (kk-1) / 2
    MM = kk * (2*n - kk +1) / 2
    out += (MM - mm + 1)
    out %= M
print(int(out % M))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split(" "))
total = 0
for k in range(N+1,K-1,-1):
  total+=k*(N)-k*(k-1)+1
print(total%(10**9+7))

Submission status: Accepted

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

m,M=0,N
ans=0

if K==1:
    ans+=N+1

#print(1,m,M)
for i in range(2,N+2):
    m+=(i-1)
    M+=N-(i-1)
    #print(i,m,M)
    if i<K:
        continue
    else:
        ans+=M-m+1
        ans%=MOD

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

n, k = map(int, input().split())
cnt = 0
mod = 10 ** 9 + 7

for x in range(k, n + 2):
    cnt += x * n - x * (x - 1) + 1
    cnt %= mod

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(K, N+2):
    small = (i - 1) * i // 2
    large = (N - i + 1 + N) * i // 2
    temp = (large - small) % MOD
    ans = (ans + temp + 1) % MOD
    # print(temp + 1)
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,(input().split()))
MOD = 10**9+7
l = list(range(N+1))
s = [0]*(N+1)
s[0] = l[0]
for i in range(1,N+1):
    s[i] = s[i-1] + l[i]

sr = [0]*(N+1)
sr[0] = l[N]
for i in range(1,N+1):
    sr[i] = sr[i-1] + l[N-i]

c = 0
for i in range(K,N+2):
    c += sr[i-1]-s[i-1] +1
    c %= MOD
print(c)

Submission status: Accepted

Solution code:
mod = 10**9+7
N,K = map(int,input().split())
ans= 0
for i in range(N+2):
    if i < K:
        continue
    else:
        a = (0+i-1)*i//2
        b = (N-i+1+N)*i//2
        ans += (b-a+1)%mod
        ans %= mod
print(ans)

Submission status: Accepted

Solution code:
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k,n+2):
        ans += number(i,n) 
    print(ans%(10**9+7))

def number(i,n):
    minn = int((0 + i - 1)*i/2)
    maxn = int(((n-i+1)+n)*i/2)
    return maxn - minn + 1
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    solve()


def solve():
    N, K = map(int, input().split())

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

    total += 1

    print(total)
    return


if __name__ == '__main__':
    main()