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:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, K = MI()
    ans = 0

    for i in range(K, N+2):
        mx = (N + (N - i + 1)) * i // 2
        mn = (i - 1) * i // 2
        # print(N, N - i + 1)
        # print(i, mn, mx)
        ans += mx - mn + 1
        ans %= MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split());mod=10**9+7;print((n*(n+1)*(n+2)//6-k*(k-1)*(3*n-2*k+4)//6+n-k+2)%mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7

mi = 0
ma = N
mii = 1
maa = N - 1
su = 0
for i in range(1,N+2):
    if i >= K:
        su += ma - mi + 1
        su %= mod
    mi += mii
    mii += 1
    ma += maa
    maa -= 1

print(su)

Submission status: Accepted

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

ans = 0

s = n*(n+1)//2 #0からnまでの総和

for i in range(k,n+2): #kからn+1まで
    mi = (i-1)*i//2
    ma = s - (n-i)*(n-i+1)//2
    ans += (ma-mi+1)%mod
print(ans%mod)

Submission status: Accepted

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

c = 0

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

print(int(c%(10**9 + 7)))

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
N,k=map(int,input().split())
n=N+1
a1=-(n**3-k**3)*2
a2=-(n**2+k**2)*3
a3=-(n-k)*1
A=(a1+a2+a3)//6
B=n*(n+k)*(n-k+1)//2
C=(n-k+1)
print ((A+B+C)%(10**9+7))

Submission status: Accepted

Solution code:

#!/usr/bin/env 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)


# region fastio

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")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def calc(x):
    smallest = x * (x - 1) // 2
    largest = smallest + (N - x + 1) * x
    return largest - smallest + 1


N, K = map(int, input().split())
M = 10 ** 9 + 7
res = 0
for x in range(K, N + 2):
    res = (res + calc(x)) % M

print(res)

Submission status: Accepted

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

def numK(n, k):
    return k * (n - k + 1) + 1


I = input().split()
N = int(I[0])
K = int(I[1])

sum = 0
for i in range(K,N+2):
    sum += numK(N,i)

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

Submission status: Accepted

Solution code:
def div_with_mod(x, y, mod):
    # Fermat's little theorem
    return x*pow(y, mod - 2, mod)


def solve():
    N, K = map(int, input().split())
    mod = 10**9+7

    s = 0
    s_1 = 0
    a = []
    b = 0
    ans = 0
    for i in range(N+1):
        b += i
        a.append(b)

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

mod = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
count=0
for i in range(n+2):
    if i<k:
        continue
    elif i>=k:
        mini=i*(i-1)//2
        a=n*(n+1)//2
        b=(n-i)*(n-i+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
ans=count%(10**9+7)
print(ans)

Submission status: Accepted

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

ans = Mint()
for i in range(K,N+2):
    mn = Mint(i*(i-1)//2)
    mx = Mint((N+N-i+1)*i//2)
    ans += mx - mn + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, k = [int(i) for i in input().split()]
    #smallのバリエーション
    mod = 1000000007
    res = 0
    for i in range(k, n+2):
        min_s = int(i*(i-1)/2)
        max_s = int(n*(n+1)/2 - (n-i)*(n-i+1)/2 )
        res += max_s - min_s + 1
        res = res % mod
    print(int(res))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
n = a[0]
k = a[1]

count = 0

#10**100の係数のリスト作成,bは係数の個数。
b=n+1-k+1
keisu=[0]*b
for i in range(b):
  keisu[i]=k+i

#係数毎に個数を求める,iは係数。
for i in keisu:
  mn = (i-1)*i/2
  mx = ((n-i+1)+n)*i/2
  count += (mx-mn+1)
  count %= (10**9+7)
  
print(int(count))

Submission status: Accepted

Solution code:
from itertools import accumulate
n, k = map(int,input().split())
MOD = 10**9+7

a = [i for i in range(n+1)]
ac = list(accumulate(a))
sa = sum(a)
cnt = 0
for i in range(k, n+2):
    if i == n+1:
        cnt += 1
        break
    cnt += sa - ac[-i-1] - ac[i-1] + 1
print(cnt%MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sum_C(n,k):
	nn=n
	max = 0
	min = 0
	sum=0
	for i in range(k):
		min += i
	for j in range(k):
		max += nn
		nn-=1
	sum += (max-min+1)%(pow(10,9)+7)

	#print(sum)
	
	for i in range(k,n+1,1):
		max+=n-i
		min+=i
		#print(max-min+1)
		sum+=(max-min+1)%(pow(10,9)+7)
	return sum
 
 
N,K = map(int, input().split())
 
p = sum_C(N,K)
p = p%(pow(10,9)+7)
print(p)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

N,K = map(int,input().split())
p = 10**9+7
Nlist = []
ReNlist =[]
Ans = 0
for i in range(N+1):
    Nlist.append(i)
    ReNlist.append(N-i)
Nlist = np.array(Nlist).cumsum()
ReNlist = np.array(ReNlist).cumsum()
for i in range(K,N+1):
    Ans += ReNlist[i-1]-Nlist[i-1] +1
    Ans = Ans % p
print(Ans+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    ans = 0
    m = (N * (N + 1)) // 2
    for k in range(K, N+2):
        mi = ((k-1) * k) // 2
        ma = m - ((N-k) * (N-k+1)) // 2
        ans += (ma - mi + 1) % MOD

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

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

Submission status: Accepted

Solution code:
def main_function():
    from sys import stdin
    from sys import stdout
    input = stdin.readline
    print = stdout.write

    modulo = pow(10, 9) + 7
    n, k = list(map(int, input().split()))
    ans = 0
    tmp = 1
    for i in range(1, k):
        tmp -= i * 2
    for i in range(k, n + 2):
        ans += i * n + tmp
        tmp -= i * 2
        ans %= modulo
    print(f'{ans % modulo}')


if __name__ == '__main__':
    main_function()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    B = [0]*(N+2-K)
    full = (((N+1)*(N)) // 2)
    for n in range(K, N+2):
        mi = (n*(n-1)) // 2
        ma = full - ((N-n)*(N-n+1)//2)
        B[n-K] = ma-mi+1

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


if __name__ == '__main__':
    main()

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 += i*N - i*(i-1) + 1
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
number = [ i for i in range(0, N + 1)]


left = number[K - 1]
right = number[-K]
s_min = sum(number[0:K])
s_max = sum(number[-K:])
count = s_max - s_min + 1
for i in range(K + 1, N + 2):
    left += 1
    right -= 1
    s_min += left
    s_max += right
    count += s_max - s_min + 1
print(count % 1000000007)

Submission status: Accepted

Solution code:
def main():
    import math
    import itertools
    N, K = map(int, input().split())

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

    B = [0]*(N+2-K)
    # import numpy as np
    # for n in range(K, N+2):
    #     # print('n:', n)
    #     num = math.factorial(N+1) // (math.factorial(n)
    #                                   * math.factorial(N+1-n))
    #     try:
    #         C = [0]*num
    #     except:
    #         print(n)
    #     for i, v in enumerate(itertools.combinations(A, n)):
    #         # print('v:', v)
    #         C[i] = sum(v)
    #     # print('C:', C)
    #     B[n-K] = len(set(C))
    #     # print('B:', B[n-K])

    full = (((N+1)*(N)) // 2)
    for n in range(K, N+2):
        mi = (n*(n-1)) // 2
        # print(mi)
        ma = full - ((N-n)*(N-n+1)//2)
        # print(ma, '\n')
        B[n-K] = ma-mi+1
        # print(B[n-K])
    print(sum(B) % (10**9 + 7))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

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+=cnt
            ans%=mod
    print(ans)

    return

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

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

Solution code:
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max_value = (n*(n+1)) //2
for a in range(k,n+1):
    high = (max_value-(n-a)*(n-a+1)//2)
    low = (a*(a-1)) //2
    total += high - low + 1
total += 1 # k = n+1
print(total%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):
  
  sigma1=(i-1)*i//2
  sigma2=(n-i)*(n-i+1)//2
  sigma3=n*(n+1)//2
  ans+=sigma3-sigma2-sigma1+1
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

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()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
MOD = 10**9 + 7

def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n + 2):
        ans += i * (n - i + 1) + 1
    print(ans%MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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+=(n-i+1)*i+1
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
import sys
N, K = [int(x) for x in input().split()]

p = 10 ** 9 + 7
a = 10 ** 100 % p

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inputLine=input()
N = int(inputLine.split(" ")[0])
K = int(inputLine.split(" ")[1])

result = 0
for i in range(K,N+2):
    min_number = (i - 1) * i / 2
    max_number = (N + ( N - i + 1)) * i / 2

    result += max_number - min_number + 1

result = result % (10**9 + 7)
result = int(result)
print(result)

Submission status: Accepted

Solution code:
import math

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

Z = 10**9 + 7
X = 0

# for i in range(K, N+1):
#     a = list(range(i))
#     b = list(range(N + 1 - i, N + 1))
#     X = X + (sum(b) - sum(a) + 1)

for i in range(K, N+1):
    a = (0 + (i - 1)) * i / 2
    b = (N + (N - i + 1)) * i / 2
    X = X + (b - a + 1)

print(math.floor((X + 1)%Z))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

ans = 0
for i in range(k,n+2):
    add = -i**2 + i*(n+1) + 1
    add %= MOD
    ans += add

ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

def sum(a,b):
    i=0
    i = (a + b)*(b - a + 1)/2
    return i

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(int(s % (10**9+7)))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    MOD = 10 ** 9 + 7
    
    acc = [0] * (N + 1)
    for i in range(1, N + 1):
        acc[i] = (acc[i - 1] + i) % MOD
    
    ans = 0
    for i in range(K, N + 1):
        ans = (ans + acc[N] - acc[N - i] - acc[i - 1] + 1) % MOD
    ans = (ans + 1) % MOD
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
MOD = 10 ** 9 + 7

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

sum_mat = [0]
for i in range(1, 2*(10**5)+3):
    sum_mat.append(sum_mat[i-1]+i)


ans = 0
for i in range(k, n + 1):
    top = sum_mat[i]
    bottom = sum_mat[i-1] - 1
    ans += (i * n - top - bottom) % MOD
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

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')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()

acc = list(range(N+2))
acc = list(accumulate(acc))

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

Submission status: Accepted

Solution code:
def rangesum(a, b=0):
    return (abs(a-b)+1) * (a+b) // 2

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

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

print(res)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    ans = 0
    cnt = 0
    mod = 10 ** 9 + 7
    for i in range(k,n+1):
        s = (i-1) * i // 2
        e = i * (2 * (n-i+1) + i - 1) // 2
        ans += e - s + 1
        ans %= mod
        cnt += 1
        # print(e-s+1)
    print((ans+1)%mod)
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+=(2*n-i+1)*i//2-i*(i-1)//2+1
    ans%=mod
print(ans)

Submission status: Accepted

Solution code:
a,b=(int(x)for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%(10**9+7);b+=1
print(z)

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
mod=10**9+7
a=s[0]
b=s[1]
e=0
if b==1:
  b+=1
  e+=(a+1)
c=sum(range(0,b))
d=sum(range(a+1-b,a+1))
for i in range(b,a+2):
  if i!=b:
    c+=(i-1)
    d+=(a-i+1)
  e+=(d-c+1)
  e%=mod
print(e)

Submission status: Accepted

Solution code:
a,b=(int(x)for x in input().split())
z=0
while b<=a+1:z=(z+(a-b+1)*b+1)%(10**9+7);b+=1
print(z)

Submission status: Accepted

Solution code:
def f(n, k):
    return ((2 * n - k + 1) * k) // 2 - (k * (k - 1)) // 2 + 1


def g(n, k):
    return sum([f(n, ki) for ki in range(k, n + 2)])


n, k = map(int, input().split())
print(g(n, k) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
MOD = 1000000007
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
            other
        )

    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 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
        n_terms = min(r, n-r)
        numerator = ModInt(1)
        denominator = ModInt(1)
        for j in range(1, n_terms + 1):
            numerator *= m - j
            denominator *= j
        return numerator * self.modinv(denominator.x)

if __name__ == "__main__":
    N, K = map(int, input().split())

    num = list()
    for i in range(N):
        num.append(i)
    
    ans = ModInt(0)
    for i in range(K, N+2):
        # i 本の矢印を立てる => i-1本を端においやって残り1本の自由度が(N+1) - (i-1)
        # i-1本の内j本が左だと(i-1) - j本が右
        # j == i-1 のとき、free = (N+1) - j
        # 上記以外のとき、free = (N+1) - (j +1) - (i-1 - j)
        
        #free = 0
        # for j in range(0, i):
        #     if j == i-1:
        #         free += (N+1) - j
        #     else:
        #         free += (N+1) - (j +1) - (i-1 - j)

        free = (N+1-i)*(i-1) + (N+1) -(i-1)
        # print(free)
        ans += free
    
    print(ans)

    
# a b c d e f g

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Mod = 1000000007

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

res  = 0

for i in range(k, n + 2):
    res += ((i * (n - i + 1)) % Mod);
    res += 1
    res %= Mod
print(res)

Submission status: Accepted

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

ret = 0
for a in range(k,n+1):
#	print(((n-a+1)*a+1))
	ret = (ret+(n-a+1)*a+1)%mod

ret=(ret+1)%mod
print(ret)