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:
N, K = map(int, input().split())
min_val = 0
max_val = 0
for i in range(K):
    max_val += N - i
    min_val += i
# print(min_val)
# print(max_val)

ans = 0
mod = 10 ** 9 + 7
for i in range(K, N + 2):
    ans += max_val - min_val + 1
    ans %= mod
    min_val += i
    max_val += N - i
print(ans)

Submission status: Accepted

Solution code:
def main():
  N, K = map(int, input().split())
  N = N + 1
  A=[n for n in range(N)]
  S=[0]*(N+1)
  for a in A:
    S[a+1]+=S[a]+a
  ans=0
  for k in range(K, N+1):
    maxS, minS=S[-1], S[k]
    offset=S[-k-1]
    ans+=(maxS - offset) - minS + 1
  print(ans%(1000000007))
  
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):
  a0=(i*(i-1))//2
  an=i*n-a0
  ans+=an-a0+1

print(ans%mod)

Submission status: Accepted

Solution code:
mod=10**9+7
x=[0]+[0]
for i in range(1,2*10**5+10):
  x.append((x[-1]+i)%mod)

ans=0


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


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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
L=list(range(n+1))

cnt=0
ans=0

def calc(i):
    smallest=(i-1)*i//2
    largest=(2*n-i+1)*i//2
    return largest-smallest+1


for i in range(k,n+2):
    cnt+=calc(i)
    cnt%=(10**9+7)
    

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nn, kk = list(map(int,input().split()))

sum = 0
for i in range(kk, nn+2):
    min = (0+i-1)*i/2
    max = (nn+nn-i+1)*i/2
    sum += (max-min)+1

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

Submission status: Accepted

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

Submission status: Accepted

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

mod =10**9+7
sum = 0
min = 0
max = 0

for k in range(1,n+2):
    min += k-1
    max += n-(k-1)

    if k >= m:
        sum = (sum + max-min+1) % mod
print(sum)

Submission status: Accepted

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

ans = 0

for p in range(k, n+2):
    minimum = p * (p-1) // 2  # 0〜(p-1)の和
    maximum = p * (2*n - p + 1) // 2  # (n-p+1)〜nの和
    ans += maximum - minimum + 1
    ans %= mod

print(ans)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
s = [0]
for i in range(1,n+1):
    s.append(s[i-1] + i)

ans = 0
for i in range(k,n+1):
    ans += ((s[n]-s[n-i]) - s[i-1])+ 1
print((ans+1) % (10**9 + 7))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
M = 10**9 + 7
A = [0 for _ in range(N+1)]
RA = [0 for _ in range(N+1)]
for i in range(1, N+1):
    A[i] = A[i-1] + i

RA[0] = N
for j in range(1, N+1):
    RA[j] = N-j + RA[j-1]

ans = 0
# print(A)
# print(RA)
for k in range(K, N+2):
    minv = A[k-1]
    maxv = RA[k-1]
    ans += ((maxv - minv) + 1)%M
    ans %= M
    # print(k, (maxv-minv)+1)

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N,K = [int(i) for i in input().split()]
    ans = 0
    mod = 10**9 + 7
    for M in range(K, N+2):
        min_sum = (M-1) * M // 2
        max_sum = (2*N-(M-1)) * M // 2
        cnt = max_sum - min_sum + 1
        ans += cnt
        ans %= mod
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n,k = MI()
ans = 0
for i in range(k,n+2):
    ans += i*(n-i+1)%mod + 1
print(ans%mod)

Submission status: Accepted

Solution code:
from scipy.special import comb
n, k = map(int, input().split())
num, ans = 0, 0

for i in range(n+1):
    num += n-2*i
    if i >= k-1:
        ans += num+1
ans = ans%(10**9+7)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    mod = 7 + 10 ** 9

    res = 0
    for k in range(K, N + 2):
        res += ((k * (2 * N - k + 1) / 2) - (k * (k - 1) / 2) + 1)
        res %= mod
    print(int(res))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = []

for i in range(k,n+2):
    cnt.append(i*n -(i-1)*i +1)
    
print(sum(cnt)%(10**9+7))

Submission status: Accepted

Solution code:
def rui_sum(n,k):
    k_lsum = (k-1)*k//2
    k_usum = k*n - (k-1)*k//2    
    return k_usum - k_lsum + 1

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

cnt = []

for i in range(k,n+2):
    cnt.append(rui_sum(n,i))
    
print(sum(cnt)%(10**9+7))

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
mod = 10**9+7
result = 0 
for i in range(K, N+2):
    min_sum = ((i-1) * i) // 2
    max_sum = ((N) * (N+1)) // 2 - ((N-i) * (N-i+1)) // 2
    result += (max_sum - min_sum + 1) % mod
print(result%mod)

Submission status: Accepted

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

mod = 10 ** 9 + 7
inv = pow(2, mod - 2) % mod

def calc(b, e, c):
    global mod
    global inv
    res = (e + b) % mod
    res = ((res * c) % mod ) * inv
    return res % mod

ans = 0
for i in range(k, n + 2):
    min_val = calc(0, i - 1, i)
    max_val = calc(n - i + 1, n, i)
    ans += (max_val - min_val + 1) % mod
    ans %= mod

print(ans)

Submission status: Accepted

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

mod = 10 ** 9 + 7
inv = pow(2, mod - 2, mod=mod)

def calc(b, e, c):
    global mod
    global inv
    res = (e + b) % mod
    res = ((res * c) % mod ) * inv
    return res % mod

ans = 0
for i in range(k, n + 2):
    min_val = calc(0, i - 1, i)
    max_val = calc(n - i + 1, n, i)
    ans += (max_val - min_val + 1) % mod
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,k=MI()
	m=10**9+7
	
	ans=0
	
	for i in range(n-k+2):
		ans+=n*(n+1)//2-i*(i-1)//2-(n-i)*(n-i+1)//2+1
		#print(n*(n+1)//2-i*(i-1)//2,(n-i)*(n-i+1)//2)
		ans%=m
		#print(ans)
	print(ans)
	
	
	
	

if __name__=="__main__":
	main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

mod = 10 ** 9 + 7
N, K = MI()
def num(self):
    return (-2 * pow(self, 3) + 3 * N * pow(self, 2) + (3 * N + 8) * self) // 6
ans = num(N + 1) - num(K - 1)
print(ans % mod)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, k = MI()
    ans = 0
    ttl = n * (n + 1) / 2

    for i in range(k, n + 2):
        min_i = i * (i - 1) / 2
        max_i = ttl - (n - i) * (n - i + 1) / 2
        ans += (max_i - min_i + 1) % (10 ** 9 + 7)
        ans %= 10 ** 9 + 7

    print(int(ans))


main()

Submission status: Accepted

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    n, k = getList()
    rui = [0]
    for i in range(n+1):
        rui.append(rui[-1] + i)
    ans = 0
    # print(rui)
    for i in range(k, n+2):
        ans += rui[n+1] - rui[n+1-i] - rui[i] + 1
        # print(ans)
        ans %= MOD
    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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


def main():
    from itertools import accumulate
    import sys
    input = sys.stdin.readline

    n, k = map(int, input().split())
    mod = 10 ** 9 + 7
    a = list(accumulate([0] + [i for i in range(n + 1)]))
    ans = 0

    for j in range(k, n + 2):
        max_value = a[-1] - a[n + 1 - j]
        min_value = a[j]
        ans += (max_value - min_value) + 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
ans = 1
for i in range(K, N + 1):
    ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:

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

MOD = 10 ** 9 + 7
count = [0] * (N + 1)
for i in range(1, N + 1):
    count[i] += count[i - 1] + i
    count[i] %= MOD

ans = 1
for k in range(K, N + 1):
    ans += count[-1] - count[-k - 1] - count[k - 1] + 1
    ans %= MOD
print(ans)

Submission status: Accepted

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

MOD = 10**9+7
n += 1
ans = 0
for i in range(k, n+1):
    p = i*(2*n - (i-1)) // 2
    m = i*(2 + i-1) // 2
    ans += p - m + 1
print(ans % MOD)

Submission status: Accepted

Solution code:
# https://drken1215.hatenablog.com/entry/2020/04/20/003900
# k  個足してできる最小の整数を求める (a とする)
# k 個足してできる最大の整数を求める (b とする)
# 出来上がる整数は b−a+1 個である

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

ans = 0
for k in range(K, N+2):
    mx = k * (2 * N - k + 1) / 2
    mi = k * (k - 1) / 2
    add = mx - mi + 1
    ans += add
    ans %= mod
print(int(ans))

Submission status: Accepted

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

M=[n]*(n+1)
m=[0]*(n+1)
for i in range(1,n+1):
    M[i]=M[i-1]+n-i
    m[i]=m[i-1]+i

mod=10**9+7
ans=0
for i in range(k-1,n+1):
    tmp=M[i]-m[i]+1
    ans=(ans+tmp)%mod
ans=ans%mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(K, N+2):
    # count += sum(range(N+1-i,N+1))-sum(range(i))+1
    # i*(2*N+1-i)/2-i*(i-1)/2 +1
    count += (N+1-i)*i+1

# print(count)
print(count % (10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans%MOD)

Submission status: Accepted

Solution code:
def f(m):
    return (((N+1)*((m*(m+1))//2))%p-((m*(m+1)*(2*m+1))//6)%p+m%p)%p
p = 10**9+7
N,K = map(int,input().split())
cnt = (f(N+1)-f(K-1))%p
print(cnt)

Submission status: Accepted

Solution code:
N,K= map(int,input().split())
p=10**9+7
q=0
 
def calc(n,k):
  if k==1:
    return n+1
  else:
    maxi = k*n- k*(k-1)//2
    mini=  k*(k-1)//2
    #print(k,maxi,mini,maxi-mini+1)
    return maxi-mini+1
  
ans=0
for i in range(K,N+2):
  ans = ( ans+calc(N,i) )%p
  
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
def calc(a):
    sml = (0 + a-1) * a //2
    lar = sml + a * (n-a+1)
    return lar - sml + 1
ans = 0
for i in range(k,n+2):
    ans += calc(i) % mod
print(ans % mod)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(k, n + 2):
  if i == k:
    tot_min = 0
    tot_max = 0
    for j in range(i):
      tot_min += j
      tot_max += n - j
  else:
    tot_min += i - 1
    tot_max += n - i + 1
  count += tot_max - tot_min + 1
count %= 10 ** 9 + 7
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

n_list=list(range(n+1))

saisyou=sum(n_list[0:k])
saidai=sum(n_list[n-k+1:n+1])

ans=saidai-saisyou+1

for i in range(k+1,n+2):
    saisyou+=n_list[i-1]
    saidai+=n_list[-(i)]
    ans+=saidai-saisyou+1
    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 += max(0, n*(n+1)//2 - (n-i)*(n+1-i)//2 - i*(i-1)//2 + 1)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
ans = 0
n_list = [i for i in range(n+1)]
l = sum(n_list[:k])
r = sum(n_list[len(n_list)-k:])
ans += r-l+1

for i in range(k,n+1):
    l += n_list[i]
    r += n_list[len(n_list)-i-1]
    ans += r-l+1
    ans = ans%1000000007

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc163/tasks/abc163_d

def main():
    MOD = 10**9 + 7
    n, k = [int(i) for i in input().strip().split()]
    table = [0] * (n + 2)
    table[1] = 1

    for i in range(2, n + 1):
        table[i] = table[i - 1] + i

    ans = 0
    for i in range(k, n + 1):
        _min = table[i - 1]
        _max = table[n] - table[n - i]
        ans += _max - _min + 1
        ans %= MOD
    print((ans + 1) % MOD)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ans = 0
num = n+1
for i in range(1,n+2):
  #i個選ぶとき
  if i>=k:
    ans += num
  num += n-(2*i)
print(ans%(10**9+7))

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

Submission status: Accepted

Solution code:
import sys


def resolve(in_):
    mod = 1000000007  # 10 ** 9 + 7
    n, k = map(int, in_.readline().split())
    n += 1

    # ans = 0
    ans = 1
    # while n >= k:
    while n > k:
        ans += (
            ((n + (n - k)) * k // 2) % mod - 
            ((1 + k - 1) * k // 2) % mod +
            1
            ) % mod
        ans %= mod
        k += 1
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a = n*(n+k+1)*(n-k+2)//2
b = n-k+2
c = -((n+2)*(n+1)*n - k*(k-1)*(k-2))//3

print((a+b+c) % (10**9+7))

Submission status: Accepted

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


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

  sum_ = 0
  for k in range(K, N+2):
    sum_ += (k*(N-k+1)+1)

  print(sum_ % 1_000_000_007)


if(__name__ == '__main__'):
  main()

Submission status: Accepted

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

def cul(N,K):
  Ans = 0
  for i in range(N+1-K+1):
    t = (K+i-1)*(K+i)/2
    Ans += (K+i)*N - 2*t +1
  return(int(Ans%mod))

print(cul(N,K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
preans = []
for n in range(K, N+2):
    MIN = (0+n-1) * n / 2
    MAX = (N + (N-n+1)) * n / 2
    preans.append(MAX - MIN+1)
    
print(int(sum(preans)%(10**9 + 7)))

Submission status: Accepted

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

def get_ans(i):
    ans = i*(N+1) - i**2 +1
    ans = max(0,ans)
    return ans

ans=0
for i in range(K,N+2):
    ans_= get_ans(i)
    ans+=ans_
#     print(ans_,ans)
    
print(ans%(10**9+7))

Submission status: Accepted

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

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 = (ans + (N + 1 - i)*i + 1) % mod
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):
    mn = (i - 1) * i // 2
    mx = (n + n - i + 1) * i // 2
    ans += mx - mn + 1
    ans %= mod
print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7
ans = 0
# 選ぶ個数で場合分け
# 選べる個数はK,K+1,K+2,...,N+1

# 等差数列の和S
# 項数n, 初項a,末項l,公差d
# S=(n/2)*(a+l)
# S=(n/2)*{2a+(n-1)d}

for i in range(K, N + 2):
    min_sum = i * (i - 1) // 2  # 0+1+...(項数=i)
    max_sum = (2 * N - i + 1) * i // 2  # N+(N-1)+...(項数=i)
    ans += max_sum - min_sum + 1  # minとmaxの間の数を全て取れる
    ans %= MOD

print(ans)

Submission status: Accepted

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

MOD = 10**9 + 7

ans = 0

# 選ぶ個数で場合分け
# 選べる個数はK,K+1,K+2,...,N+1

# 等差数列の和S
# 項数n, 初項a,末項l,公差d
# S=(n/2)*(a+l)
# S=(n/2)*{2a+(n-1)d}
# 0+1+2+...（項数=i）

for i in range(K, N + 2):
    min_sum = i * (i - 1) // 2  # 0+1+...(項数=i)
    max_sum = (2 * N - i + 1) * i // 2  # N+(N-1)+...(項数=i)
    ans += max_sum - min_sum + 1  # minとmaxの間の数を全て取れる
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N, K = mis()
    v = [0]
    for i in range(N+1):
        v.append(v[-1]+i)
    ans = 0
    for k in range(K, N+2):
        mi = v[k] - v[0]
        ma = v[-1] - v[-1-k]
        ans += ma - mi + 1
        ans %= N1097
    print(ans)



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

Submission status: Accepted

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

# all selected
upper = sum(range(N+1))
lower = sum(range(N+1))
answer = 1

for k in range(N, K - 1, -1):
    upper -= N - k
    lower -= max(0, k)
    answer += upper - lower + 1
    # print(k, upper, lower, answer)
print(answer % (10 ** 9 + 7))

Submission status: Accepted

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

Submission status: Accepted

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

mod=10**9+7
ans=0
for x in range(k,n+2):
  min_a=(0+x-1)*x//2
  max_a=(n-x+1+n)*x//2
  aa=max_a-min_a+1
  ans+=aa
  
print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]    
m=n+2-k
a=-m*(m+1)*(2*m+1)//6
b=(n-2*k+3)*m*(m+1)//2
c=m*(-k**2+3*k+n*k-n-1)
mod=10**9+7

a=a%mod
b=b%mod
c=c%mod

ans=a+b+c

print(ans%mod)

Submission status: Accepted

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

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