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: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = map(int, input().split())
l = []
for i in range(N+1):
    l.append(i + 200001)

result_list = []

for k in range(K, N+2):
    for num in combinations(l, k):
        result_list.append(sum(num))

print(len(set(result_list)))

Submission status: Time Limit Exceeded

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

if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    
    zentori=[]
    for i in range(2**(K-1),2**(N+1)):
        baai=[]
        for j in range(N+1):
            if (i>>j) & 1:
                baai.append(j)
        if len(baai)>=K:
            zentori.append((sum(baai),len(baai)))
    
    setzentori=set(zentori)
    print(int(len(setzentori)%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
import sys
# sys.stdin = open('input.txt')

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

a = [i for i in range(n+1)]
a_rev = sorted(a, reverse=True)

ans = 0
for i in range(k, n+2):
    first = 0
    last = 0
    for j in range(i):
        first += a[j]
        last += a_rev[j]
    ans += last - first + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k  = map(int, input().split())
x = 0
for k in range(k, n+2):
  a = sum(list(range(0,k)))
  b = sum(list(range(n+1-k , n+1)))

  x += b- a +1
  
  
  
print(x)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    front = 0
    end = 0
    for j in range(i):
        front += j
    for j in range(n,n-i,-1):
        end += j
    if end-front+1 > 0:
        cnt += end-front+1
print(cnt)

Submission status: Time Limit Exceeded

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

import sys
from io import StringIO
import unittest

mod = 10**9+7

def modinv(a, mod):
    return pow_mod(a, mod-2, mod)

def pow_mod(a, b, mod):
    x = 1
    while b > 0:
        if b & 1:
            x = (x*a)%mod
        a = (a**2)%mod
        b //= 2
 
    return x

def comb(n,r,mod):
    combsum=1
    for i in range(n-r+1,n+1):
        combsum = (combsum * i)%mod
    for i in range(1,r+1):
        combsum = (combsum * inv[i])%mod
    return combsum

inv=[modinv(i,mod) for i in range(0,2*10**5)]

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

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

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

    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)
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

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

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
li = [i for i in range(0,n+1)]
#print(li)
#[0,1, 2, 3]
tmp = 0
def exc(n):
    return (1+n)*n//2

for i in range(k,n+2):
    #print(i,li[n-i+1:],li[:i],sum(li[n-i+1:]) - sum(li[:i]))
    tmp += sum(li[n-i+1:]) - sum(li[:i]) + 1
print(tmp)

Submission status: Time Limit Exceeded

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

ans = 0
Ns = range(N+1)
MOD = 10**9 + 7

for i in range(K, N+2): #k-->N+1
    tmp = sum(Ns[-i:]) - sum(Ns[:i]) + 1
    ans += tmp
    ans %= MOD

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    
    zentori=[]
    for i in range(1,2**(N+1)):
        baai=[]
        for j in range(N+1):
            if (i>>j) & 1:
                baai.append(j)
        if len(baai)>=K:
            zentori.append((sum(baai),len(baai)))
    
    setzentori=set(zentori)
    print(int(len(setzentori)%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

res=0
for i in range(K,N+2):
    x=list(itertools.combinations(range(N+1),i))
    s=[]
    for m in x:
        s.append(sum(m))
    res+=len(list(set(s)))

print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

lst = [i for i in range(0, n+1)]
re = 0
for i in range(k, n+2):
    temp = list(combinations(lst, i))
    tt = set()
    for j in temp:
        tt.add(sum(j))
    re += len(tt)

print(re)

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split()))
ans=0
for k in range(a[1],a[0]+2):
    min=0
    max=0
    for i in range(k):
        min +=i
    for i in range(k):
        max +=a[0]-i
    if min<=max:
        ans = ans+ max-min+1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n,k = map(int, input().split())
b = []
for i in range(0,n+1):
    b.append(i)
ans = 0

for i in range(k,n+2):
    c = []
    p_list = list(itertools.combinations(b,i))
    for j in range(len(p_list)):
        c.append(sum(p_list[j]))
    ans += len(set(c))

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

Submission status: Accepted

Solution code:
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

N=10**9 + 7
n,K=sep()
s=0
for k in range(K,n+2):
    s= (s + (k*(n-k+1))%N + 1)%N
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

def sigma(N, k):
  a = (k*(k+1)*(2*k+1)//6)%(10**9+7)
  b = (k*(k+1)//2)%(10**9+7)
  c = k
  return -a + (N+1)*b + c

print((sigma(N,N+1)-sigma(N, K-1))%(10**9+7))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------

mod = 10**9 +7
N, K = inpl()

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

print(ans)

Submission status: Accepted

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


A = [i for i in range(n+1)]
left = [A[0]]
right = [0 for i in range(n+1)]
right[-1] = A[-1]
for i in range(1, n+1):
    left.append(left[i-1] + A[i])
for i in range(n-1, -1, -1):
    right[i] = right[i+1]+A[i]
#print (left, right)
ans = 0
M = 10**9+7
for i in range(k, n+2):
    #print (ans, A[:i], A[n+1-i:])
    ans = (ans + right[-i]) % (10**9+7)
    #print (ans, right[-i], left[i-1]-1)
    #print (left[i-1])
    #print (ans - left[i-1]+1)
    ans = (ans - left[i-1]+1) % (10**9+7)
print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

result = 1
for i in range(K, N+1):
    tmp_min = (i - 1) * i // 2
    tmp_max = (N * (N + 1) - (N - i) * (N - i + 1)) // 2
    result += tmp_max - tmp_min + 1
    result %= 10 ** 9 + 7

print(result)

Submission status: Accepted

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

ans = 0
A = sum(list(range(N, N-K, -1)))
B = sum(list(range(K)))
for i in range(K, N+2):
    # print(A,B)
    ans += A-B+1
    A += N-i
    B += i
    ans %= C
print(ans)

Submission status: Accepted

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

mod = 10**9 + 7
# k個選ぶときからn-1個選ぶとき
ans = 0
for i in range(k, n+1):
  min = 1/2 * (i-1) * i
  max = 1/2 * (n-i+1+n) * (n-(n-i+1)+1)
  ans += (max - min + 1) % mod
print(int(ans + 1)% mod)

Submission status: Accepted

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

s = [0]*(n+1)
s[0] = n + 1
for i in range(1, n+1):
    s[i] = (s[i-1] + n - 2 * i) % mod

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

kMod = 10**9+7

ans = 0

for k in range(K, N+2):
    lb = (k-1) * k // 2
    ub = (N+1-k + N) * k // 2
    ans += (ub-lb+1)
    ans %= kMod
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
P = int(1e9+7)

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

Submission status: Accepted

Solution code:
def main():
	N, K = [int(x) for x in input().split(" ")]
	p = 1000000007
	cnt = 0
	for i in range(K, N + 2):
		cnt = (cnt + (i * N) - i * i + i + 1) % p

	print(cnt)

main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
def f(n):
  return n*(n+1)/2

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = [i for i in range(N+1)]
mod = 10**9+7
ans = 0
head = sum(A[:K-1]) if K > 1 else 0
tail = sum(A[-K+1:]) if K > 1 else 0
for i in range(K, N+2):
    head += A[i-1]
    tail += A[-i] 
    ans += tail-head+1
    ans = ans % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

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

h = 0
l = 0
for j in range(0,K-1):
    h += j
for j in range(N+2-K,N+1):
    l += j

for i in range(K,N+2):
    h += i-1
    l += N+1-i
    a += l - h + 1

a %= 10 ** 9 + 7
print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 19:24:24 2020

@author: liang
"""

key = 10**9 + 7
T, K = map(int, input().split())
N = list(range(T+1))
lower = sum(N[:K])
higher = sum(N[-K::1])
ans = 0
ans = (higher - lower + 1)%key
for i in range(K+1,T+2):
    lower += N[i-1]
    higher += N[-i]
    ans += higher - lower + 1
    ans %= key
print(ans)
#print(lower)
#print(higher)

Submission status: Accepted

Solution code:
# @uthor : Kaleab Asfaw
from sys import stdin, stdout
# Fast IO
# from math import gcd

def input():
	a = stdin.readline()
	if a[-1] == "\n": a = a[:-1]
	return a
def print(*argv, end="\n", sep=" "):
	n = len(argv)
	for i in range(n):
		if i == n-1: stdout.write(str(argv[i]))
		else: stdout.write(str(argv[i]) + sep)
	stdout.write(end)
# Others
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
	ans = 1
	for i in range(1, x+1): ans = (ans * i) % mod
	return ans
def arr2D(n, m, default=0):
	lst = []
	for i in range(n): temp = [default] * m; lst.append(temp)
	return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}

def solve(n, k):
	cnt = 0
	for i in range(k, n+2):
		# print(((i/2)*(n+n-i+1)), ((i*(i-1))/2), i)
		cnt += ((i/2)*(n+n-i+1)) - ((i*(i-1))/2) + 1
		cnt = cnt % mod
	return int(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)


# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

A = [i for i in range(N + 1)]
A = np.array(A)
cum_A = np.cumsum(A)

cnt = 0
for i in range(K, N + 1):
    cnt += (cum_A[N] - cum_A[N - i]) - cum_A[i - 1] + 1
print((cnt + 1) % (10**9 + 7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
x = 10
y = 10 + N

ans = 0
a = x
b = y
for i in range(1, N + 2):
    if i >= K:
        ans += b - a + 1
    a += (x + i)
    b += (y - i)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# bikkuri_n1 = math.factorial(n+1) % (10**9+7)

# bikkuri_k = math.factorial(k) % (10**9+7)

for i in range(k,n+2):
  
    small = i*(i-1)//2
    big = i*(2*n-i+1)//2
    
    ans += big-small+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 += n*i - i*(i-1) + 1
  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):
  num = ((2*N-i+1)*i)//2 - ((i-1)*i)//2 +1
  ans+=num%MOD
ans%=MOD
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import chain

# import numpy as np
# from itertools import combinations as comb
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter

MOD = 1000000007  # type: int
OFFSET = 10 ** 100


def k_in_n(k, n):
    """0〜n までの数からちょうど k 個の数を選ぶ時の最大最小"""
    minimum = (k * (k - 1)) // 2
    maximum = (k * (2 * n - k + 1)) // 2
    return (minimum, maximum)


def solve(N: int, K: int):
    keep = None  # まだ加算されていない範囲
    answer = 0
    for k in range(K, N + 2):
        if keep is None:
            keep = k_in_n(k, N)
        else:
            minmax = k_in_n(k, N)
            if minmax[0] + OFFSET <= keep[1]:
                keep[0] -= OFFSET
                keep[1] = minimum[1]
            else:
                answer = (answer + keep[1] - keep[0] + 1) % MOD
                keep = minmax

    if keep is not None:
        answer = (answer + keep[1] - keep[0] + 1) % MOD
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K = map(int, input().split())
    # N, K = input().strip()
    # N, K = int(input())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    answer = solve(N, K)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

MOD = 10**9 + 7
n_sum = [0]

for i in range(N):
    n_sum.append(n_sum[i] + i+1)
#print(n_sum)

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

print((ans+1)%MOD)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
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())
def main():
    n, k = LI()
    N = 10**9+7
    ans = 0
    start = sum([i for i in range(0,k-1)])
    goal = sum([i for i in range(n,n-k+1,-1)])

    for i, j in zip(range(k-1,n+1), range(n-k+1,-1,-1)):
        start += i
        goal  += j
        cnt = (goal-start+1)%N
        ans += cnt
        ans %= N

    print(ans)
main()

Submission status: Accepted

Solution code:
n,k = [int(x) for x in input().split()]
a = [0] * (n + 1)
for i in range(1,n+1):
  a[i] = a[i-1] + i
#print(a)
res = 0
for i in range(k,n+1):
  ma = a[n] - a[n-i]
  mi = a[i-1]
  res += ma - mi + 1
  #print(i,res,ma,mi)
res += 1
res %= 10 ** 9 + 7
print(res)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d,u=0,10**1000
ans=0
while d<u:
    d=(k*(k-1))//2
    u=(2*k*n-k**2+k)//2
    ans+=u-d+1
    k+=1
print(ans%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

MOD = (10 ** 9) + 7
ans = 0

min_val = 0
max_val = n
p = 1

for i in range(n + 1):
    # print(min_val, max_val)
    if i + 1 >= k:
        ans += max_val - min_val + 1
        ans = ans % MOD
    min_val += p
    max_val += n - p
    p += 1

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
b=0
c=0
ans=0

for i in range(0,K):
    b+=i
    c+=(N-i)
ans=c-b+1


for i in range(K,N+1):
    b+=i
    c+=N-i
    ans+=c-b+1

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

Submission status: Accepted

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

tmp = [0 for _ in range(10 ** 5 * 3 + 1)]
for i in range(10 ** 5 * 3):
    tmp[i + 1] = tmp[i] + (i + 1)

ans = 1
for i in range(K, N + 1):
    tmp_max = tmp[N] - tmp[N - i]
    ans += tmp_max - tmp[i-1] + 1

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

Submission status: Accepted

Solution code:
from itertools import accumulate
N,K = map(int,input().split())
acc = list(accumulate(range(N+1), lambda x,y:x+y))
ans = 0
mod = 10**9+7
for i in range(K, N+1):
    r = acc[N] - acc[N-i]
    l = acc[i-1]
    ans = (ans+r-l+1) % mod
ans += 1
print(ans % mod)

Submission status: Accepted

Solution code:
MODINT = 1000000007
n,k = map(int,input().split())
prod = [0]*(n+1)

for i in range(1,n+1):
    prod[i] = prod[i-1]+i
# print(prod)
ans = 0
for s in range(k-1,n+1):
    L = prod[s]
    R = prod[n] - prod[n-s] + (n-s)
    # print(L,R)
    ans += R-L+1
    ans %= MODINT
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Ans = 0

for m in range(K,N+2): # m個選ぶ m = K ~ N+1
    # 1刻みで全ての数を作ることができる
    # よって答えは、作れる数の　(最大値) - (最小値) 通りとなる

    # 最大値 = 大きい方からm個選ぶ = N-m+1 ~ N までの和
    maxi = m*(N-m+1 + N)/2

    # 最小値 = 小さい方からm個選ぶ = 0~m-1を選ぶ
    mini = m*(0 + m-1)/2

    Ans += int(maxi - mini + 1)
    Ans %= mod
    
print(Ans)

Submission status: Accepted

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

def ksum(n):
    return n*(n+1)//2

ans = 0
msum = ksum(N)
for i in range(K, N+2):
    ans += msum - ksum(N - i) - ksum(i-1) + 1
    #print(i, ans)
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
start = sum(range(K))
end = sum(range(N-K+1, N+1))
count = 0
#print(start, end)
for k in range(K, N + 2):
    count += end - start + 1
    count %= 1000000007
    start += k
    end += (N-k)
    
print(count)

Submission status: Accepted

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

Submission status: Accepted

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


def sub_sum(l, r):
    return (l + r) * (r - l + 1) / 2


ans = 0

for i in range(K, N+2):
    l = sub_sum(0, i-1)
    r = sub_sum(N-i+1, N)
    ans += r - l + 1

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

print(int(ans))

Submission status: Accepted

Solution code:
# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない
# なのでもはや無視していい
# 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ
# 3つ選ぶのは最小値3~最大値6の4つ
# 4つ選ぶのは1つ
# 毎回最大値と最小値を計算して差+1を加えてやるとできあがり
# 計算には数列の和を使う

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

ans = 1
for i in range(k, n + 1):
    # 初項0,公差1,末項i-1までの和
    min_s = i * (i - 1) // 2
    # 初項n+1-i, 公差1, 末項i-1までの和
    max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2
    ans += max_s - min_s + 1
    ans %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
mod=10**9+7
def part_sum(start,k):
    return k*(k+1)//2+(k*(start-1))

def count_sum(k):
    return part_sum(n-k+1,k)-part_sum(0,k)+1
ans=0
for i in range(k,n+2):
    ans+=count_sum(i)
    ans=ans%mod
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
S = N * (N+1) // 2

A = [0 for _ in range(N+1)]
for i in range(1, N+1):
    A[i] = i * (i+1) // 2

ans = 0
for j in range(K, N+2):
    minSum = j * (j-1) // 2
    maxSum = S - (N-j)*(N-j+1)//2
    possibleSums = maxSum - minSum + 1
    ans += possibleSums % (10**9 + 7)
ans %= (10**9 + 7)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(k, n + 2):
    minimum = (i - 1) * i // 2
    maximum = (2 * n - i + 1) * i // 2
    cnt += maximum - minimum + 1
    cnt %= 10 ** 9 + 7

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

Submission status: Accepted

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


if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

ans = 0
all_sum = N*(N+1)/2

mod = 10**9+7

for i in range(K,N+2):
    min_val = i*(i-1)/2
    max_val = N*(N+1)/2 - (N-i+1)*(N-i)/2
    ans += (int(max_val) - int(min_val) + 1) % mod

#    print(i, min_val, max_val)                                                                        


print(ans%mod)

Submission status: Accepted

Solution code:
from itertools import accumulate

# k個選んだ時の最小値と最大値が分かれば、個数が分かる？？
n,k = list(map(int, input().split()))
cumsum   = list(accumulate(range(n+1)))
cumsum_r = list(accumulate(range(n+1)[::-1]))

MOD = 10**9 + 7
ans = 0
for i in range(k, n+2):
    _min, _max = cumsum[i-1], cumsum_r[i-1]
    ans = (ans + _max - _min + 1) % MOD

print(ans)

Submission status: Accepted

Solution code:
from math import factorial
n, k = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def s(n, m=0): # m~nの総和
    global mod
    return (n * (n+1) // 2 - (n-m) * (n-m+1) // 2) % mod

sm = 0
for i in range(k, n+1):
    sm = (sm + s(n, i) - s(i-1, i-1) + 1) % mod

print((sm+1) % mod)

Submission status: Accepted

Solution code:
#import math
#import collections
n,k = map(int, input().split( ))
#A = list(map(int, input().split( )))
mod = 10**9+7
ans = 0
l,h = 0,0
for x in range(1,n+2):
  l += x -1
  h += n -x +1
  if x >= k:
    ans += (h-l+1)
    ans = ans%mod
print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,k = map(int, input().split())
    ans = 0
    mn = mx = 0
    for i in range(n+1):
        j = n-i
        mn += i
        mx += j
        if i+1 >= k:
            ans += mx-mn+1
    print(ans%(10**9+7))

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
#amari = (10**100)%(10**9+7)
def sm(i):
    tmpp = 0
    for j in range(i):
        tmpp += j
    return tmpp,j

def bi(i,N):
    tmpp = 0
    for j in range(i):
        tmpp += N-j

    return tmpp,N-j

def main():
    N,K = map(int,input().split())
    ans = 0
    #loopnum = (N+1) - K + 1
    for i in range(K,N+2,1):
        if i == K:
            small,numsmall = sm(i)
            big,numbig = bi(i,N)
            #print(numsmall,numbig)
        else:
            small += numsmall+1
            numsmall += 1
            big += numbig - 1
            numbig -= 1
        ans += big - small + 1

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

print(main())

Submission status: Accepted

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

s = 0
e = 0
ans = 0

MOD = 10 ** 9 + 7

for i in range(N+1):
    s += i 
    e += N - i 
    if i + 1 >= K:
        ans += e - s + 1
        ans %= MOD
print(ans)

Submission status: Accepted

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

input = sys.stdin.readline
mod = 1000000007


def ST():
    return input().rstrip()


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


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


def LI():
    return list(MI())


N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))

ans = 0

for k in range(K, N + 2):
    MAX += N - k + 1
    MIN += k - 1
    ans += (MAX - MIN + 1) % mod

print(ans % mod)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
#ans[i]=上からi個の和-下からiこの和+1 i個選んだ和の種類
ans = 0
mod = 10**9+7
for i in range(K,N+2):
    if i*2 > N+1:
      #print(i,(N+1-i)*N+1 % mod)
      ans += (N+1-i)*i+1 % mod
    else:
      #print(i,(N-i+1)*i+1 % mod)
      ans += (N-i+1)*i+1 % mod
print(ans%mod)

Submission status: Accepted

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

mod = pow(10, 9) + 7

a = list(range(n+1))

def cumulative_sum(array):
    ret = []
    for index, a in enumerate(array):
        if index != 0:
            ret.append(ret[-1] + a)
        else:
            ret.append(a)
    return ret

a_cumulative_sum = cumulative_sum(a)
a_rev_cumulative_sum = cumulative_sum(a[::-1])

ans = 0
for i in range(k, n + 2):
    ans += (a_rev_cumulative_sum[i - 1] - a_cumulative_sum[i - 1] + 1) % mod

ans %= mod
print(ans)

Submission status: Accepted

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

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

ans = 0
for n in range(K, N + 2):
    mn = s[n-1] - s[0]
    mx = s[N] - s[max(N-n, 0)]
    count = mx - mn + 1
    ans += count
    ans %= MOD
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
MOD=10**9+7

N,K=map(int,input().split())
ans=0
ans+=N-K+2
ans+=(N+1)*(N+1+K)*(N-K+2)//2
ans%=MOD
ans-=(N+1)*(N+2)*(2*N+3)//6
ans%=MOD
ans+=K*(K-1)*(2*K-1)//6
ans%=MOD
print(ans)

Submission status: Accepted

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