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:
def sum1(a):
  t = list(range(a))
  return sum(t)
def sum2(b,n):
  s = list(range(n-b+1,n+1))
  return sum(s)

N,K = map(int,input().split())
x = [0]*(N+2)
for k in range(K,N+2):
  x[k] = sum2(k,N) - sum1(k) + 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int, input().split()))
ans = 0
for i in range(K,N+2):
  min = list(range(0,i))
  max = list(range(N-i+1,N+1))
  ans = ans + sum(max) - sum(min) + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

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

all_combination = 0
less_than_K_combination = 0
for num in range(K, N + 2): # 選ぶ個数を1 から N + 1個までずらす
    targetList = []
    for each_num in range(num):
        targetList.append(each_num)
    min = sum(targetList)
    targetList = []
    for each_num in range(N + 1 - num, N + 1):
        targetList.append(each_num)
    max = sum(targetList)
    all_combination += max - min + 1

#for num in range(1, K): # 選ぶ個数を1 から K - 1個までずらす
#    targetList = []
#    for each_num in range(num):
#        targetList.append(each_num)
#    min = sum(targetList)
#    targetList = []
#    for each_num in range(N + 1 - num, N + 1):
#        targetList.append(each_num)
#    max = sum(targetList)
#    less_than_K_combination += max - min + 1

print(all_combination)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n, k = map(int, input().split(' '))
  A = list(range(n+1))
  ans = 0
  for i in range(k, n+2):
    tmp_min = sum(A[:i])
    tmp_max = sum(A[n+1-i:])
    ans += tmp_max - tmp_min + 1
  print(ans)
    

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = [i for i in range(N+1)]
count = 0
for i in range(K,len(A)+1):
  sum_lst = []
  lst = list(itertools.combinations(A,i))
  for j in lst:
    sum_lst.append(sum(j))
  sum_lst = set(sum_lst)
  count += len(sum_lst) 
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
mod = 10**9+7
sum_min = 0
sum_max = 0
diff = 0
while K != N+2:
    for i in range(K):
        sum_min += i
    for k in range(N+1-K,N+1):
        sum_max += k
    diff += (sum_max-sum_min+1)
    sum_max = 0
    sum_min = 0
    K+= 1
diff = diff % mod
print(diff)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

N, K = map(int, input().strip().split())
L = math.pow(10, 10)

values = [0] * (N + 1)
for i in range(N + 1):
    values[i] = i

amount = 0
each_combination = []
for comb_no in range(K, N + 2):
    possible_values = set()
    for combination in itertools.combinations(values, comb_no):
        possible_values.add(sum(combination))
    each_combination.append(len(possible_values))
print(sum(each_combination))

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools

N, K = map(int, input().strip().split())
L = math.pow(10, 10)

values = [0] * (N + 1)
for i in range(N + 1):
    values[i] = L + i

amount = 0
possible_values = set()
for comb_no in range(K, N + 2):
    for combination in itertools.combinations(values, comb_no):
        possible_values.add(sum(combination))
print(len(possible_values))

Submission status: Time Limit Exceeded

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

data = []
for i in range(n+1):
  data.append(i)

l = n+1

ans = 0

# [4, 2] -> (0 + 1 + 2), (2 + 3 + 4) 

for i in range(k, (n+1) + 1):
  # i: 2, data[:2] = [0, 1], min: 1
  min = sum(data[:i])

  # i: 2,                    max: 5
  max = sum(data[l-i:])

  diff = max - min + 1
  # print(diff)
  ans += diff

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
l = [_ for _ in range(n + 1)]

x = 0
for i in range(k, n+2):
    x += sum(l[-1:-i-1:-1]) - sum(l[0:i]) + 1

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
#from mod10**9 import *

purasu_num, num_ijou = list(map(int, input().split(" ")))

sum_ways = 0 #和の個数
rupe_num = purasu_num - num_ijou + 2

atai_list = [i for i in range(purasu_num + 1)]
for i in range(rupe_num):
    kosu = i + num_ijou
    mi = sum(atai_list[:kosu])
    ma = sum(atai_list[-kosu:])
    sum_ways += ma - mi + 1
    #print(kosu, sum_ways)

print(sum_ways)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, m = list(map(int, input().split(" ")))
l = [ 10**100 + i for i in range(n + 1) ]
div = 10**9 + 7

ans = set()
for i in range(m, n + 2):
    for v in itertools.combinations(l, i):
        ans.add(sum(v) % div)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
s=1
lis=list(range(N+1))
 
def tousa(l,r):
    return((l+r)*(r-l+1)//2)
 
 
for i in range(K,N+1):
    s+=(tousa(lis[-i:][0], lis[-i:][-1])-tousa(lis[:i][0], lis[:i][-1])+1)
# print(s)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
s=1
lis=list(range(N+1))

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


for i in range(K,N+1):
    s+=(tousa(lis[-i:][0], lis[-i:][-1])-tousa(lis[:i][0], lis[:i][-1])+1)
# print(s)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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

l = range(n+1)

c = 0

for i in range(k, n+2):
    mn = sum(l[:i])
    mx = sum(l[-i:])
    c = c + mx - mn + 1

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,k = map(int, input().split())
n = n + 1
mod = 10**9+7
bag = []
ans = 0
for i in range(n):
	bag.append(i)
reverse =  bag[::-1]
for j in range(k, n+1):
	max = np.sum(reverse[:j])
	min = np.sum(bag[:j])
	ans = max-min+1 + ans
ans = ans % mod
print(ans)

Submission status: Time Limit Exceeded

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

import numpy as np

n, k = map(int, input().split())
MOD = int(1e9+7)
rem = (10*100)%MOD 
ans = 0 

# i個取るとき
for i in range(k, n+2):
    #print('i =', i)
    minimum = np.arange(i).sum()
    maximum = np.arange(n, n-i, -1).sum()
    #print('minimum =', minimum)
    #print('maximum =', maximum)
    #print(maximum-minimum+1)
    ans += (maximum-minimum+1)%MOD

print(ans%MOD)

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

result = 0
for i in range(k,n+2):
  numbers = range(0,n+1)
  mins = sum(numbers[0:i])
  maxs = sum(numbers[-i:])
  result += maxs - mins +1


print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = 0
tmp1 = range(K, N + 2)
tmp2 = range(10, 10 + N + 1)

for num in tmp1:
  max_num = sum(tmp2[-num:])
  min_num = sum(tmp2[:num])
  ans += (max_num - min_num + 1)
  
print(ans)

Submission status: Time Limit Exceeded

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

K = [int(i) for i in range(k, n + 2)]
#print(K)
N = [int(i) for i in range(n + 1)]
#print(N)
c = 0
for i in K:
  #print(N[: i])
  mi = sum(N[: i])
  ma = sum(N[::-1][: i])
  c += (ma - mi + 1)
  c %= (10 ** 9 + 7)
print(c)

Submission status: Time Limit Exceeded

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

K = [int(i) for i in range(k, n + 2)]
#print(K)
N = [int(i) for i in range(n + 1)]
#print(N)
c = 0
for i in K:
  #print(N[: i])
  mi = sum(N[: i])
  ma = sum(N[::-1][: i])
  c += (ma - mi + 1)
print(c)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=0
while k<=n+1:
    mi=0
    ma=0
    for t in range(k):
        mi+=t
        ma+=(n-t)
    a+=(ma-mi+1)
    k+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K=list(map(int, input().split()))
l = np.array([i for i in range(N+1)])
count=0
for i in range(K, N+2):
  count += (sum(l[-i:])-sum(l[:i])+1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# TLEになる愚直コードなはず

import itertools
 
n, k = map(int, input().split())
arr = [i for i in range(n+1)]
 
a = 0
for i in range((n+1)-(k-1)):
    tmp = set()
    for group in itertools.combinations(arr, i+k):
        tmp.add(sum(group))
    #print(tmp)
    a += len(tmp)
 
print(a)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
a = [i for i in range(N+1)]
# print(a)
ans = 0
for i in range(K, N+2):
    # print(a[N-i+1:])
    # print(a[:i])
    ans += sum(a[N-i+1:]) - sum(a[:i])+1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K, N + 2):
    a = sum(l[-i:])
    b = sum(l[0:i])
    ans += (a - b + 1)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(K, N + 2):
    a = sum(l[-i:])
    b = sum(l[0:i])
    ans += (a - b + 1)
print(ans % mod)

Submission status: Time Limit Exceeded

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

B=[]
for i in range(N + 1):
    B.append(i)

D = []
import itertools
for i in range(K,len(B)+1):
    for j in itertools.combinations(B, i):
        D.append(j)

E = []
F = []
G = 0
for i in range(K, len(D[-1])+1):
    for j in range(G,len(D)):
        if len(D[j]) == i:
            E.append(sum(D[j]))
        if len(D[j]) > i:
            G = j
            break
    F.append(set(E))
    E = []
        
H = 0
for i in range(len(F)):
    for j in range(len(F[i])):
        H += 1
print(H)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
ans=0
for i in range(K,N+2):
    d=0
    c=0
    for j in range(i):
        c+=j
    for k in range(N,N-i,-1):
        d+=k
    ans+=d-c+1
print(ans)

Submission status: Time Limit Exceeded

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

A = [i for i in range(N+1)]
A_rev = sorted(A, reverse=True)
ans = 0
for i in range(K, N+2):
    maximum = sum(A_rev[0:i])
    minimum = sum(A[0:i])
    ans += maximum - minimum + 1
print(ans%d)

Submission status: Time Limit Exceeded

Solution code:
from typing import NoReturn


def main() -> NoReturn:
    n, k = map(int, input().split())  # type: int, int

    p: int = 10 ** 9 + 7

    answer = 0

    for i in range(k, n + 2):
        min_val: int = sum(range(i))
        max_val: int = sum(range(n - i + 1, n + 1))
        answer += max_val - min_val + 1

    print(answer % p)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    mod = 1000000007
    n, k = (int(x) for x in input().split())
    l = tuple(i for i in range(n + 1))  # おまけの小さい部分，でも大事
    ans = 0
    # 選ぶ数の数で分ける。でかい部分は無視して，
    # 最小値と最大値が分かれば取りうる値も分かる。
    for j in range(k, n + 2):
        _min = sum(l[:j])
        _max = sum(l[-j:])
        ans += _max - _min + 1
        ans %= mod
    return ans


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

Submission status: Time Limit Exceeded

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

_mod = 10 ** 9 + 7

ans = 0

for i in range(k, n + 2):
    min0 = sum(range(0,i))
    max0 = sum(range(n + 1 - i, n + 1))
        
    tota0 = max0 - min0 + 1
    ans += tota0 % _mod

print(ans % _mod)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

ans = 0
for i in range(K, N+2):
    X = list(combinations(A, i))
    B = set()
    for j in X:
        B.add(sum(j))
    ans += len(B)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()

l = list(range(N+1))
mn_list = []
for i in range(K, N+2):
    mn_list.append(sum(l[:i]))

r = l[::-1]
mx_list = []
for i in range(K, N+2):
    mx_list.append(sum(r[:i]))

ans = 0
for j in range(len(mn_list)):
    ans += mx_list[j]-mn_list[j]+1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

N, K = mapint_inp()

l = list(range(N+1))
mn_list = []
for i in range(K, N+2):
    mn_list.append(sum(l[:i]))

r = l[::-1]
mx_list = []
for i in range(K, N+2):
    mx_list.append(sum(r[:i]))

ans = 0
for mn, mx in zip(mn_list, mx_list):
    ans += mx-mn+1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l = [i for i in range(n+1)]
r = list(reversed(l))

cnt = 0

for i in range(k, n+2):
  min = sum(l[:i])
  max = sum(r[:i])

  if min == max:
    cnt += 1
  else:
    cnt += max - min + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

import itertools
from pprint import pprint

N, K = mapint_inp()
l = list(range(N+1))
r = l[::-1]
ans = 0
while(K < N+2):
    mn = sum(l[:K])
    mx = sum(r[:K])
    ans += mx-mn+1
    K+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

import itertools
from pprint import pprint

N, K = mapint_inp()
l = list(range(N+1))
ans = 0
while(K < N+2):
    mn = sum(l[:K])
    mx = sum(l[::-1][:K])
    ans += mx-mn+1
    K+=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):
  minsum = sum(range(0, i))
  maxsum = sum(range(n+1-i ,n+1))
  ans += maxsum - minsum + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans_list = []
for k in range(K, N + 2):
    for i in itertools.combinations(num_list, k):
        if not (len(i), sum(i)) in ans_list:
            ans_list.append((len(i), sum(i)))

print(len(ans_list))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def get_result(data):
    N, K = data
    mod = 10**9+7
    value = [i for i in range(N+1)]
    ans = 0
    for r in range(K, N+2):
        min_val = sum(value[:r])
        max_val = sum(value[-r:])
        ans += (max_val - min_val + 1) % mod
    return ans % mod


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Time Limit Exceeded

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

for i in range(k, n+2):
  minsum = sum(n_list[:i])
  maxsum = sum(n_list[-i:])
  ans += maxsum - minsum + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
num=0
for i in range(k,n+2):
    minsum=maxsum=0
    for j in range(i):
        minsum+=j
        maxsum+=n-j
    num+=maxsum-minsum+1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = list(range(n+1))
x = 0
for i in range(m,n+2):
    b = sum(a[:i])
    c = sum(a[-i:])
    d = c - b + 1
    x += d
print(x)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
dic = {}
count = 0
for a in range(K, N+2):
    for i in itertools.combinations(range(1, N+2), a):
        length = len(i)
        sum_ = sum(i)
        if sum_ in dic.keys():
            if length == dic[sum_]:
                continue
            else:
                count += 1
                count %= 10000000007
        else:
            dic[sum_] = length
            count += 1
            count %= 10000000007

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
s=0
for i in range(k, n+2):
	# print("sum(range(n+2-i, n+2))")
	# print(sum(range(n+2-i, n+2)))
	# print("sum(range(i+1))")
	# print(sum(range(i+1)))
	s += sum(range(n+2-i, n+2)) - sum(range(i+1)) +1 
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
from functools import reduce

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

cnt = 0
for i in range(k, n + 1):
    sum_list = set()
    for pattern in list(itertools.combinations(range(n + 1), i)):
        result = reduce(lambda sum, val : sum + val, pattern, 0)
        sum_list.add(result)
    cnt += len(sum_list)

print(cnt + 1)

Submission status: Time Limit Exceeded

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

dp=[[[0]*2 for i in range(n+1)] for ii in range(n+1)]

dp[0][0][0]=0
dp[0][0][1]=0
dp[1][0][0]=0
dp[1][0][1]=1
dp[1][1][0]=1
dp[1][1][1]=1

mod=10**9+7
for nn in range(2,n+1):
    dp[nn][0][0]=0
    dp[nn][0][1]=nn
    for kk in range(1,nn):
        dp[nn][kk][0]=dp[nn-1][kk][0]
        dp[nn][kk][1]=(dp[nn-1][kk-1][1]+nn)%mod
    dp[nn][nn][0]=(dp[nn-1][nn-1][0]+nn)%mod
    dp[nn][nn][1]=(dp[nn-1][nn-1][1]+nn)%mod
ksum=0
for kk in range(k-1,n+1):
    ksum=ksum+(dp[n][kk][1]-dp[n][kk][0]+1)%mod
print(ksum)

Submission status: Time Limit Exceeded

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


s = 0
for i in range(k, n + 2):
    a = 0
    b = 0

    if i == 1:
        s += n+1
    else:
        for j in range(0, i):
            a += j
            b += n - j
        s += b - a + 1
    
    if s >= 10 ** 9 + 7:
        s -= 10 ** 9 +7
    
print(s)

Submission status: Time Limit Exceeded

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

import itertools

# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列の入力
#s = input()
#print(s[0:K-1]+s[K-1].lower()+s[K:N])

#list = []
#for i in range(N+1):
#    list.append(i)

#print(list)

#print(range(N+1))

ans=0

i=K
while(i<=N+1):
    #comb=combinationListRecursive(list, i)
    comb = list(itertools.combinations(range(N+1), i))
    #print(comb)
    tmp=[]
    for com in comb:
        sum=0
        for co in com:
            sum = sum+co
        if sum in tmp:
            continue
        else:
            tmp.append(sum)
            ans = ans+1
    i=i+1


print(ans)

Submission status: Time Limit Exceeded

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

for i in range(k,n+2):
  max_value = sum(range(n-i+1,n+1))
  lowest_value = sum(range(0,i))
  answer = answer + max_value - lowest_value + 1

print(answer % mod)

Submission status: Time Limit Exceeded

Solution code:
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
for howManyWeChoose in range(K, N+2):
    lastMembers = []
    firstmembers = []
    for i in range(howManyWeChoose):
        lastMembers.append(N-i)
        firstmembers.append(i)
    until = sum(lastMembers)
    start = sum(firstmembers)
#     sumOfAll += howManyWeChoose * (until - start + 1) * (10 ** 100) + sum(range(start, until + 1))
# print(sumOfAll%(7+10**9))
    sumOfAll += len(range(start, until + 1))
print(sumOfAll%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

answer = 0
count = 0
for i in range(N-K+2):
  l_max = N
  l_min = 0
  for j in range(i):
    count += l_max - l_min
    l_max -= 1
    l_min += 1
  count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import math

def file_input():
    f = open('input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()

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

    sum=0
    min=0
    max=0
    for i in range(K,N+2):
        # print(i)
        max=0
        min=0
        for j in range(i):
            min += j
            max += N-j
        sum+=max-min+1
        # print("i="+str(i)+"min="+str(min)+"max="+str(max))

    print(sum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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+=sum(bb[n-i+1:])-sum(bb[:i])+1
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
def partsum(n,k):
  ret = sum(list(range(n-k+1,n+1)))
  return ret

N, K = map(int,input().split())
ret  = 0
for k in range(K, N+2):
  ret += partsum(N,k) - partsum(k-1,k) + 1
print(ret)

Submission status: Time Limit Exceeded

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


s = 0
for i in range(k, n + 2):
    a = 0
    b = 0

    if i == 1:
        s += n+1
    else:
        for j in range(0, i):
            a += j
            b += n - j
        s += b - a +1
    
print(s)

Submission status: Time Limit Exceeded

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

t=[]
for i in range(n+1):
  tmp=0
  for j in range(i+1):
    tmp+=n-j
  t.append(tmp)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = (int(x) for x in input().split())
    num = N+1
    
    count = 0
    for A in range(K, num+1):
        sita = 0
        for i in range(A):
            sita = sita + i
        ue = A*N
        for i in range(A):
            ue = ue - i
        count = count + ue - sita + 1

    print(count % (1000000000+7))
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int,input().split())
ans = 0
li = list(range(n+1))

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]

xs = list(range(N+1))

ans = 0

for i in range(K, (N+2)):
    test =[]
    for x in itertools.combinations(xs, i):
        test.append(sum(x))
    ans +=len(set(test))
    
print(ans)

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:
import numpy as np
import itertools
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]

xs = np.arange(N+1)

ans = 0

for i in range(K, (N+2)):
    test =[]
    for x in itertools.combinations(xs, i):
        test.append(sum(x))
    ans +=len(set(test))
    
print(ans)

Submission status: Time Limit Exceeded

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

mod = 1000000000+7

z=0
for x in range(K, N+2):
  zz = 1
  for y in range(0,x):
    zz += (N-y) - y
    zz %= mod
  z += zz
  z %= mod
#
print(z)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

MOD = 1000000009

sum_map = {}
for choose in range(k, n+2):
    for pattern in itertools.permutations(range(n+1), choose):
        sum_ = sum(pattern)
        if 0 in pattern:
            sum_ += MOD
        if sum_ in sum_map:
            sum_map[sum_]+=1
        else:
            sum_map[sum_] = 0

print(len(sum_map))

Submission status: Time Limit Exceeded

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

s = 0

for a in range(K,N+2) :
  
  SUM1 = sum([x for x in range(0,a)])
  SUM2 = sum([x for x in range(N-a+1, N+1)])
  
  s = s + SUM2 - SUM1 + 1
  
print(s%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=0
while k<=n+1:
    mi=0
    ma=0
    for t in range(k):
        mi+=t
        ma+=(n-t)
    a+=(ma-mi+1)
    k+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
# mod = 1000000007
Ns = []
for n in range(N+1):
    Ns.append(n)

# print(Ns)

count = 0
# Kこ以上とる組み合わせを作る
for k in range(K, N+2):
    ans = set()
    nums = itertools.combinations(Ns, k)
    # 重複を避けてカウント
    for num in nums:
        ans.add(sum(list(num)))
    count += len(ans)

print(count)

Submission status: Time Limit Exceeded

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

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

ans_list = []
for k in range(K,N+2):
    for i in itertools.permutations(num_list, k):
        if not (len(i),sum(i)) in ans_list:
            ans_list.append((len(i),sum(i)))
            
print(len(ans_list))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

sm = 0
l = list(range(N+1))
ans = 0
for a in range(K, N+2):
    sm_list = list(combinations(l, a))
    for b in range(0, len(sm_list)):
        sm_list[b] = sum(sm_list[b])
    ans += len(list(set(sm_list))) % (10**9+7)


print(ans)

Submission status: Time Limit Exceeded

Solution code:





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

# 10^100はでかすぎるので和の第1項(10^100の整数倍、巨大)と第2項(端数)が干渉することはない

# ありうる和が何通りか
possible = 0

# 選んだ数値の個数がselectedのとき
for selected in range(K, (N + 1) + 1):
    # 第2項の最小値は数列のうち先頭selected個をとったもの
    minFraction = sum(range(selected))

    # 第2項の最大値は数列のうち末尾selected個をとったもの
    maxFraction = sum(range(N + 1 - selected, N + 1))

    # 最小値と最大値の間の数は全てありえるので個数は
    possible += maxFraction - minFraction + 1

print(possible)

Submission status: Time Limit Exceeded

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

ans = 0
a = []
b = []
for i in range(k, n+2):
  a.append(s[:i])
  b.append(l[:i])
  ans += 1
  
def flatten(nested_list):
  return [e for inner_list in nested_list for e in inner_list]

ans += sum(flatten(a)) - sum(flatten(b))

print(ans%(int(1e9)+7))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import permutations

N, K = map(int, sys.stdin.readline().split())

a = [n for n in range(1, N+2)]
ans = 0

for k in range(K, N+2):
    permute = permutations(a, k)
    ans_ = set()
    for s in permute:
        ans_.add(sum(s))
        
    ans += len(ans_)

print(ans)

Submission status: Time Limit Exceeded

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

B=[]
for i in range(N + 1):
    B.append(i)

D = []

import itertools
for i in range(K,len(B)+1):
    for j in itertools.combinations(B, i):
        D.append(j)

#print(D)
E = []
F = []
G = 0
for i in range(K, len(D[-1])):
    if G == 1:
        G = 0
    for j in range(len(D)):
        if len(D[j]) == i:
            E.append(sum(D[j]))
#            print(E)
        if len(D[j]) > i:
            G = 1
            break
    F.append(set(E))
    E = []
        
#print(F)
H = 0
for i in range(len(F)):
    for j in range(len(F[i])):
        H += 1
print(H+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
  
def main():
  N, K = map(int, input().split(" "))
  ans = 0
  for k in range(K, N+2):
   	ans += len(set([sum(xs) for xs in combinations(range(N+1), k)]))      
  print(ans)

  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, K = (int(x) for x in input().split())
    num = N+1
    num_list = list(range(num))

    
    count = 0
    for A in range(K, num+1):
        sita = sum([i for i in range(A)])
        l = num_list[::-1]
        l = l[:A]
        ue = sum(l)
        count = count + ue - sita + 1

    print(count % (1000000000+7))
    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Ns = list(range(N+1))
m = pow(10, 9) + 7

sum_ = 0

for k in range(K, N+2):
    min_idx = sum(Ns[:k])
    max_idx = sum(Ns[-k:])
    sum_ += (max_idx - min_idx + 1)
    sum_ %= m

print(sum_)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n, k= map(int,input().split())
a = [i for i in range(0,n+1)]
count=0
for i in range(k,n+2):
    b = []
    list_x = list(combinations(a, i))
    for j in range(0,len(list_x)):
        c = 0
        for g in range(0,i):
            c += list_x[j][g]
        b.append(c)
    nums_unique = list(set(b))
    count+=len(nums_unique)  
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
l = list(range(n+1))
ad = 0
for i in list(range(k,n+2)):
        l2 = list(itertools.combinations(l,r=i))
        se = set([sum(j) for j in l2])
        ad += len(se)
print(ad)