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: Runtime Error

Solution code:
; タイプ別設定 Ver1
; Monokai for Sakura Editor (C/C++)
; cpp_monokai.ini
;
;  Created on: 2015/06/13
;      Author: KeitetsuWorks

[Types]
C[BRC]=1,1,f2f8f8,a6e22e,0
C[CAR]=1,0,a5a5a5,222827,0
C[CBK]=0,0,f2f8f8,222827,0
C[CMT]=1,0,5e7175,222827,0
C[CTL]=1,0,a5a5a5,222827,0
C[CVL]=0,0,a5a5a5,222827,0
C[DFA]=1,0,222827,ffd0a2,0
C[DFC]=1,0,222827,c0fdbd,0
C[DFD]=1,0,222827,f2f8f8,0
C[EBK]=0,0,222827,222827,0
C[EOF]=1,0,a5a5a5,222827,0
C[EOL]=1,0,a5a5a5,222827,0
C[FN2]=1,0,222827,ffffa0,0
C[FN3]=1,0,222827,99ff99,0
C[FN4]=1,0,222827,9999ff,0
C[FN5]=1,0,222827,ff66ff,0
C[FND]=1,0,222827,00ffff,0
C[HDC]=0,0,74dbe6,222827,0
C[IME]=1,0,a5a5a5,222827,0
C[KW1]=1,0,efd966,222827,0
C[KW2]=1,0,7226f9,222827,0
C[KW3]=1,0,2ee2a6,222827,0
C[KW4]=1,0,1f97ff,222827,0
C[KW5]=1,0,ff81ae,222827,0
C[KW6]=1,0,ffffff,222827,0
C[KW7]=1,0,ffffff,222827,0
C[KW8]=1,0,ffffff,222827,0
C[KW9]=1,0,ffffff,222827,0
C[KWA]=1,0,ffffff,222827,0
C[LNO]=1,0,5e7175,222827,0
C[MOD]=1,1,5e7175,222827,0
C[MRK]=1,0,222827,c08000,0
C[NOT]=0,0,ffc0c0,f0fbff,0
C[NUM]=1,0,ff81ae,222827,0
C[PGV]=1,0,f0fbff,ffe6be,0
C[RAP]=1,0,463a96,222827,0
C[RK1]=0,0,ff0000,222827,0
C[RK2]=0,0,ff0000,222827,0
C[RK3]=0,0,ff0000,222827,0
C[RK4]=0,0,ff0000,222827,0
C[RK5]=0,0,ff0000,222827,0
C[RK6]=0,0,ff0000,222827,0
C[RK7]=0,0,ff0000,222827,0
C[RK8]=0,0,ff0000,222827,0
C[RK9]=0,0,ff0000,222827,0
C[RKA]=0,0,ff0000,222827,0
C[RUL]=1,0,5e7175,222827,0
C[SEL]=1,0,3e4849,3e4849,0
C[SPC]=0,0,c0c0c0,222827,0
C[SQT]=1,0,74dbe6,222827,0
C[TAB]=1,0,a5a5a5,222827,0
C[TXT]=1,0,f2f8f8,222827,0
C[UND]=1,0,a5a5a5,222827,0
C[URL]=1,0,7226f9,222827,1
C[VER]=0,0,463a96,222827,0
C[WQT]=1,0,74dbe6,222827,0
C[ZEN]=1,0,a5a5a5,222827,0
FileTree(0).bIgnoreHidden=1
FileTree(0).bIgnoreReadOny=0
FileTree(0).bIgnoreSystem=0
FileTree(0).eItemType=0
FileTree(0).nDepth=0
FileTree(0).szTargetFile=*.*
FileTree(0).szTargetPath=.
bAutoIndent=1
bAutoIndent_ZENSPACE=1
bChkEnterAtEnd=1
bDefaultBom=0
bFileTreeProject=1
bHokanLoHiCase=0
bInsSpace=1
bKinsokuHead=0
bKinsokuHide=0
bKinsokuKuto=0
bKinsokuRet=0
bKinsokuTail=0
bOutlineDockDisp=0
bOutlineSortDesc=0
bPriorCesu8=0
bRTrimPrevLine=0
bStringEndLine=0
bStringLineOnly=1
bTabArrow=0
bTypeHtmlHelpIsSingle=1
bUseDocumentIcon=0
bUseHokanByFile=1
bUseHokanByKeyword=0
bUseKeyHelpAllSearch=0
bUseKeyHelpKeyDisp=0
bUseKeyHelpPrefix=0
bUseKeyWordHelp=0
bUseRegexKeyword=0
bUseTypeFont=0
bgImgPath=
bgImgPos=0
bgImgPosOffsetX=0
bgImgPosOffsetY=0
bgImgRepeartX=1
bgImgRepeartY=1
bgImgScrollX=1
bgImgScrollY=1
cLineTermChar=:
eDefaultCodetype=0
eDefaultEoltype=1
eOutlineDockSide=0
id=1450618
lf=0,0,0,0,0,0,0,0,0,0,0,0,0
lfFaceName=
nDefaultOutline=1
nDockOutline=0
nFileTreeItemCount=1
nHokanType=0
nImeState=256
nIndentLayout=0
nInts=2,10240,0,4,16,17,0,1,1,0,0
nKeywordSelect10=-1
nKeywordSelect3=18
nKeywordSelect4=-1
nKeywordSelect5=-1
nKeywordSelect6=-1
nKeywordSelect7=-1
nKeywordSelect8=-1
nKeywordSelect9=-1
nLineCommentColumn=-1
nLineCommentColumn2=-1
nLineCommentColumn3=-1
nLineNumWidth=2
nLineSpace=1
nNoteLineOffset=0
nOutlineSortCol=0
nOutlineSortType=0
nPointSize=0
nSmartIndent=1
nTextWrapMethod=1
nVertLineIdx1=0
szBlockCommentFrom=/*
szBlockCommentFrom2=#if 0
szBlockCommentTo=*/
szBlockCommentTo2=#endif
szExtHelp=
szExtHtmlHelp=
szFileTreeProjectIni=
szHokanFile=
szIndentChars=
szKinsokuHead=
szKinsokuKuto=、。，．､｡,.
szKinsokuTail=
szLineComment=//
szLineComment2=
szLineComment3=
szOutlineRuleFilename=
szTabViewString=^       
szTypeExts=c,cpp,cxx,cc,cp,c++,h,hpp,hxx,hh,hp,h++,rc,hm
szTypeName=C/C++
xyOutlineDock=0,0,0,0

[TypeEx]
szKeywordCase[1]=1
szKeywordCase[2]=1
szKeywordCase[3]=1
szKeywordFile[1]=cpp_kw1_datatypes.kwd
szKeywordFile[2]=cpp_kw2_keywords.kwd
szKeywordFile[3]=cpp_kw3_functions.kwd
szKeyword[1]=cpp_kw1_datatypes
szKeyword[2]=cpp_kw2_keywords
szKeyword[3]=cpp_kw3_functions

[Info]
szVersion=2.2.0.1
vStructureVersion=166

Submission status: Runtime Error

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

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

print(result)

Submission status: Runtime Error

Solution code:
# 初期入力
import numpy as np 
N,Q = (int(x) for x in input().split())
aa=0  
bb=0
a=[0] 
b=[0]
a_set =set()
ki_kouzou =np.zeros((N+1,1),dtype=np.int32)
ki_kouzou_dic ={i:set() for i in range(1,N+1)}

#木の構造を入力
for i in range(1,N): #直接つながっているところ。
    aa,bb = (int(x) for x in input().split())
    if bb in a_set: #親子判定 頂点3⇒頂点2もありうる
        #np.append(ki_kouzou[bb,:],aa,axis=1)
        a_set.add(aa)
        ki_kouzou_dic[bb].add(aa)
    else:
        #np.append(ki_kouzou[aa,:],bb,axis=1)
        #ki_kouzou[aa].append(bb)
        ki_kouzou_dic[aa].add(bb)
        a_set.add(bb)
    a.append(aa)     
    b.append(bb)


#間接的に繋がっているところ
kansetu ={i:set() for i in range(1,N+1)}
for ki_key in range(1,N+1) :
    for v_v in ki_kouzou_dic[ki_key]:
        if v_v in ki_kouzou_dic.keys():
            kansetu[ki_key] = kansetu[ki_key] | ki_kouzou_dic[v_v] 

for i in range(1,N+1):
    ki_kouzou_dic[i] =ki_kouzou_dic[i] | kansetu[i] #直接 ＋ 間接
    ki_kouzou_dic[i].add(i) #各頂点自身はは必ずポイント加算あり


# ポイント入力-計算
point={i:0 for i in range(1,N+1)}
pp=0 ; xx=0
for _ in range(Q):
    pp,xx = (int(x) for x in input().split())
    for i in ki_kouzou_dic[pp]:
        point[i] += xx 

print(*point.values())

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
 
s = 0
 
for i in range(K,N+2):
  s += i*N +1 - i*(i -1)

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

Submission status: Runtime Error

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

s = 0

for i in range(K,N+2):
  s += i*N +1 - i*(i -1)

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

Submission status: Runtime Error

Solution code:
    n, k = map(int, input().split())
    if n < k:
        print(1)
        exit(0)

    MOD = pow(10, 9) + 7
    count = 0
    while n+1 >= k:
        minv = k * (k-1) // 2
        maxv = ((n+1) * n // 2) - ((n-k) * (n-k+1) // 2)

        count += (maxv - minv + 1)
        count %= MOD
        k += 1

    print(count)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i] = i*N - i*(i-1) + 1

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i] = (i+1)*N - i^2

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i] = (i+1)*(N-i)

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)

Submission status: Runtime Error

Solution code:
M = int(input())
K = int(input()) 

sum = 0

for j in range(K,M+2):
    temp = j*(M-j+1) + 1
    if temp > (10^9 + 7):
        temp = temp%(10^9 + 7)
    sum += temp

print(sum)

Submission status: Runtime Error

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

ans = 0

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
if n<=k:
    print(1)
else:
    for i in range(k,n+1):
        g += (cmb(n+1,i))
    print(g)

Submission status: Runtime Error

Solution code:
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n, aii):
    dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

    for x in range(1, n+1):
        ai, i = aii[x-1]
        dp[x][0] = dp[x-1][0] + ai * (i-x+1)
        dp[0][x] = dp[0][x-1] + ai * (n-x-i)

    for s in range(1, n+1):
        for x in range(1, s):
            y = s - x
            ai, i = aii[s-1]
            dp[x][y] = max(dp[x-1][y] + ai * (i-x+1),
                           dp[x][y-1] + ai * (n-y-i))

    res = 0
    for x in range(n+1):
        if dp[x][n-x] > res:
            res = dp[x][n-x]
    return res


if __name__ == "__main__":
    n = i1num()
    a = inums()
    aii = sorted([(a[i], i)for i in range(n)], reverse=True)
    print(solve(n, aii))

Submission status: Runtime Error

Solution code:
s_1 = 0
s_2 = 0
s_3 = 0
mod = 1000000007
ans = 0
for i in range(k, n + 2):
    s_1 = (n + n + 1 - i) * i / 2
    s_2 = (0 + i - 1) * i / 2
    s_3 += s_1 + 1 - s_2
ans = s_3 % 1000000007
print('{:g}'.format(ans))

Submission status: Runtime Error

Solution code:
N,K=input().split()
a=[i for i in range(int(N))]
print(i)

Submission status: Runtime Error

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

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

ans = 0
for a in range(k, n+2):
  ans += calc(a)
  ans %= MOD
  
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())  # 0~NのN+1個の数字, K個以上選んで出来上がる数
ans = 0
MOD = 10**9+7
# 出来上がる数字の幅を考える
for k in range(K, N+2):  # K~N+1までループを回す
  upper = k*(2N-(k-1))//2
  lower = k*(k-1)//2
  ans += upper - lower + 1
  ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
N,K = input().split()
import math
#print(math.factorial(int(N)+1) - math.factorial(int(K)-1) -1)
print(math.factorial(int(N)+1) / math.factorial(int(K)) - math.factorial(int(K)))

Submission status: Runtime Error

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

ans = 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))

Submission status: Runtime Error

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

for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
int main() {
    long long N, K;
    cin >> N >> K;
    long long M = N+1, L = K-1;
    long long res = M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6;
    cout << res%MOD << endl;
}

Submission status: Runtime Error

Solution code:
N, K = list(map(int, inp_str.split(" ")))
def choise(n, m):
    if n == 0:
        return 0
    min_sum = (0 + m - 1) * m // 2 % MOD
    max_sum = (2*n - m + 1) * m // 2 % MOD
    return max_sum - min_sum + 1
ans_list = [choise(N, m) for m in range(1, N+2)]
sum_ans = 0
for ans in ans_list[K-1:]:
    sum_ans += ans
    sum_ans = sum_ans % MOD
print(int(sum_ans))

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

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

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

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(k,n+1):
  max_value = sum(range(n-i+1,n+1))
  lowest_value = sum(range(1,i+1))
  answer = answer + max_value - lowest_value + 1
 
print(answer % mod)

Submission status: Runtime Error

Solution code:


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

    c = 0
    mii = sum(range(nk[1]))
    maa = sum(range(nk[0]-nk[1]+1, nk[0]+1))
    for i in range(nk[1], nk[0]+2):
        c += maa-mii+1
        //print(c, mii, maa)
        mii += i
        maa += nk[0]-i

    print(c)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for i in range(k,n+1)

max_value = sum(range(n-i+1,n+1))
lowest_value = sum(range(1,i+1))
 
answer = answer + max_value - lowest_value + 1
 
print(answer % mod)

Submission status: Runtime Error

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

def combinationListRecursive(data, r):
  if r == 0 or r > len(data):
    return []

  result = []
  _combinationListRecursive(data, r, 0, [], result)
  return result


def _combinationListRecursive(data, r, start, progress, result):
  if r == 0:
    result.append(progress)
    return

  for i in range(start, len(data)):
    #別解 _combinationListRecursive(listExcludedIndices(data, [i]), r - 1, i, progress + [data[i]], result)
    _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)

# スペース区切りの整数の入力
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)

ans=0

i=K
while(i<=N+1):
    comb=combinationListRecursive(list, 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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    # print(i, ".")
    c_l = list(itertools.combinations(np.mod(l,10**9+7),i))
    a = []
    for j in range(len(c_l)):
        # print(sum(c_l[j]))
        a.append(sum(c_l[j]))
        # print(a)
    # print(a)
    # print(set(a))
    # print(c_l)
    ans += np.mod(len(set(a)),10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
 
import os
import sys
from io import BytesIO, IOBase
 
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
 
 
def main():
    n, k = map(int, input().split())
 
    MOD = 10**9 + 7
 
    s = 0
    for i in range(k, n + 2):
        a = ((i - 1) * i) // 2
        s = (s + (n * i) - (2 * a) + 1) % MOD
 
    print(s)
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
 
 
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
 
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    main()
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    MOD = 10**9 + 7

    s = 0
    for i in range(k, n + 2):
        a = ((i - 1) * i) // 2
        s = (s + (n * i) - (2 * a) + 1) % MOD

    print(s)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def fact(n):
  if n <= 1:
    return 1
  return n * fact(n-1)
def c(n,k):
  no = 1
  for i in range(k):
    no *= (n-i)
  de = fact(k)
  return no//de
n,k = map(int,input().split())
ans = 0
for i in range(k,n+1):
    ans += c(n+1,i)
print(ans%(pow(10,9)+7))

Submission status: Runtime Error

Solution code:
mport 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(map(sum,l2))
        ad += len(se)
print(ad)

Submission status: Runtime Error

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

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


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

# from operator import mul

sys.setrecursionlimit(100001)


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

# ===FUNCTION===

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

    return outputDataList


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

    return outputDataList


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

    return outputDataList


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

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

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


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

print(ans)

Submission status: Runtime Error

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

from scipy.special import comb
print(comb(n, r, exact=True, repetition=True)%(pow(10,9)+7)

Submission status: Runtime Error

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

def nCr(n, r): 
  
    return (fact(n) / (fact(r)  
                * fact(n - r))) 
  
def fact(n): 
  
    res = 1
      
    for i in range(2, n+1): 
        res = res * i 
          
    return res

ans = 0
for K in range(K, N+1+1):
	ans += nCr(N+1, K)

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
N,K=list(map(int,(stdin.readline().strip().split())))
limit=10**9
a = cmb(N,K,limit)
print(a)

Submission status: Runtime Error

Solution code:
import np

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

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
print(math.factorial(n) // math.factorial(n-k))

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
nk = input('').split(' ')
n = int(nk[0])+1
k = int(nk[1])

x=1
mod = 10 ** 9 + 7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range(k,n+1):
    p=1
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    p = cmb(n,i,mod)
    x+=p

print(int(x))

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:

import itertools
n,k = map(int, input().split())
x = [i for i in range(n+1)]
a = [i for i in range(k,n+1)]

b = [0] * ((n+1) * (n+2))
ans = []
for i in a:
    for team in itertools.combinations(x, i):
        b[sum(team)] = 1

    ans.append(len([i for i in b if i != 0]))
    b.clear()
    b = [0] * ((n+1) * (n+2))

print(sum(ans)+1)

Submission status: Runtime Error

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

def combination_mod(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

mod = 10**9+7
fact = [1, 1]
factinv = [0, 1]
inv = [0, 1]
total = 0

for i in range(2, N+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

for i in range(K, N+1):
    total += combination_mod(N, i, mod) % mod

print(total)

Submission status: Runtime Error

Solution code:
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

a,b=int(input())
c=combinations_count(a,b)

if c==1:
  print(1)
else:
  print(c)

Submission status: Runtime Error

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


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

    if K == N+1:
        print(1)
        exit()

    nc = N+1
    n = N+1
    r = K

    for rc in range(1, r):
        nc -= 1
        n = n*nc % mod
        r = r*rc % mod

    ans = div_with_mod(n, r, mod) % mod
    rc += 1

    for k in range(rc, N+1):
        rc += 1
        nc -= 1
        n = n*nc % mod
        r = r*rc % mod
        a = div_with_mod(n, r, mod) % mod
        ans += a

    print(ans % mod)


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

def nCr(n, r): 
  
    return (fact(n) / (fact(r)  
                * fact(n - r))) 
  
def fact(n): 
  
    res = 1
      
    for i in range(2, n+1): 
        res = res * i 
          
    return res

ans = 0
for K in range(K, N+1+1):
	ans += (N+1)CK

print(ans)

Submission status: Runtime Error

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

MOD = 1000000007  # type: int




# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = map(int,input())
    l = []
    for i in range(N+K):
        l.append(i * K + K*(K+1)/2)
    s = set(l)
    print(len(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
k = int(input())
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)

Submission status: Runtime Error

Solution code:
import math

#N = int(input())
#Ai = list(map(int,input().split()))
N,K = map(int,input().split())

#10**100

def comb(pre,aft):
  if(pre==aft):
    return 1
  elif(pre-aft==1):
    return pre
  else:
    num = [0 for i in range(aft*pre)]
    for i in range(0, pre):
      for j in range(i+1, pre):
        num[i+j]=1
    ans=0
    #print(num)
    ans = sum(num)
    #print(str(pre)+'C'+str(aft)+'='+str(ans))
    return ans
  

def calc(n,k):
  if(n-k==-1):
    return 1
  else:
    tot=0
    for i in range(k,n+2):
      tot+=comb(n+1,i)
    
    return tot
  
    

sum = calc(N,K)

print(sum)

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())

print(2**(a+1) - 2**(n-b+1))

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7

def gauss(n):
    ans = int (n * (n + 1) / 2)
    return(ans) 

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


if k - n == 1:
    print(1)
else:
    a = [0] * (gauss(n)+2)
    t = k
    for i in range(n):
        l = gauss(t-1)
        r = gauss(n) - gauss(n-t)
        a[l] += 1
        a[r+1] -= 1
        t += 1

    for i in range(1, len(a)):
        a[i] += a[i-1]

    print(sum(a) % MOD)