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: Wrong Answer

Solution code:

N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[1] = 1
ninv[0],ninv[1] = 1,1
N = N + 1
for i in range(2, N + 1):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = ninv[i - 1] * inv[i] % MOD

ret = 0
for i in range(K,N+1):
    ret += (nac[N] *( ninv[i] * ninv[N - i] % MOD) % MOD) % MOD
print(int(ret))

Submission status: Wrong Answer

Solution code:

ls = list(map(int,input().split()))

input_n = ls[0]

input_k = ls[1]


sum_num = 0

for num in range(input_k, input_n + 2):
    sum_min = sum(range(0, num))
    sum_max = sum(range(input_n+1 - num, input_n+1))
    sum_num = sum_num + sum_max - sum_min + 1

print(sum_num % (10^9 + 7))

Submission status: Wrong Answer

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

count = 0
m = 10**9+7

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(N+1)
def SumCombi(n, r):
    k = max(0, n-r*2+1)
    return comb(n, r) - k*(k+1)//2

for i in range(K,N+2):
    count = (count + SumCombi(N+1, i)) % m
    # print(count)

print(count)

Submission status: Wrong Answer

Solution code:
data = input().split()
N = int(data[0])
K = int(data[1])
e = [n for n in range(N+1)]
print(e)
count = 0
for k in range(K,N+2):
    count += 2 * N - k * (k-1)
print(count//(10**9+7))

Submission status: Wrong Answer

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

total = 1
for k in range(N+2-K):
   for j  in range(k):
      total += N - j

K_list = range(-1, K-1)
K_sum = sum(K_list)

print(total - K_sum)

Submission status: Wrong Answer

Solution code:
from math import factorial, ceil
def comb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))
base = comb(5,3)
N, K = map(int, input().split())
n = N+1
nCr = comb(n, K)
S = nCr
for r in range(K,n):
    nCr_1 = nCr * (n - r) // (r + 1)
    nCr = nCr_1
    S+=nCr_1

k = 0
for i in range(K, N):
    k += ceil(N/i)-1
print(S-k)

Submission status: Wrong Answer

Solution code:
import math
n,k = map(int,input().split())
if(k>n):
	print("1")
else:
	ans=(pow(n+1,2,1000000007))
	ans2=-(pow(k,2,1000000007))-1
	print(ans2)
	for i in range(k+1,n+1):
		ans -= math.floor((i-1)/2)
	print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


total = 0


if K > N/2:
    for i in range(K,N+2):
        for j in range(i):
            total = (total + N - j - j) % (10**9 + 7)
        total += 1
    
    print(total)

else:
    for i in range(N//2+1):
        for j in range(i):
            total = (total + N - j - j) % (10**9 + 7)
        total += 1
        if i == K:
            tmp = total
    
    print(2*total-tmp)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7


def power(x, a):
    if a == 0:
        return 1
    elif a == 1:
        return x
    elif a % 2 == 0:
        return power(x, a//2) **2 % mod
    else:
        return power(x, a//2) **2 * x % mod


def modinv(x):
    return power(x, mod-2)

def binomial_coefficients(n, k):
    numera = 1  
    denomi = 1  

    for i in range(k):
        numera *= n-i
        numera %= mod
        denomi *= i+1
        denomi %= mod
    return numera * modinv(denomi) % mod



N,K=map(int,input().split())
ans=0
for i in range(K,N+1):
  ans+=binomial_coefficients(N+1, i)
print(ans)

Submission status: Wrong Answer

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

c = 0

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

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

Submission status: Wrong Answer

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

  x += b- a +1
  
  
y = 10^9+7
print(x%y)

Submission status: Wrong Answer

Solution code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
N,M = Line[0],Line[1]

# print(N,M)

kosuu = N+1
ans = 1

if M == 1 :
    M += 1
    ans += N

kaitensuu = kosuu - M

for i in range(kaitensuu):
    ans += kosuu + i
    ans = ans % 1000000007

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max = (n*(n+1)) //2  # 6 in ex.1
for a in range(k,n+1): # from 3 to 4 in ex.1
    high = (max-(n-a)) # 6-1 = 5, 6-0 = 6
    high %= mod
    low = (a*(a-1)) //2  # 1, 3
    low %= mod
    if high-low+1 < 0:
        high += mod
    total += high - low + 1 # 5, 4
    total %= mod
total += 1 # k = n+1

total %= mod
print(total)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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 #出力の制限
M = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, M + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
N, K = map(int, input().split())

a=0
for i in range(K,N+1):
  a += cmb(N+1, i, mod)
print(a % mod)

Submission status: Wrong Answer

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

total_num = 0

for k in range(K, N + 2):
    Min = sum(range(k - 1))
    Max = sum(range(N - (k - 1), N + 1))
    num = Max - Min + 1
    total_num += num

print(total_num)

Submission status: Wrong Answer

Solution code:
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, k = map(int, sys.stdin.readline().split())
    if k >= n:
        print(1)
    else:
        ans = 0
        for i in range(k, n+2):
            i = i - 1
            l = ((i * (i + 1)) // 2) % mod
            r = ((n*(n+1))//2 - ((n-i)*(n-i-1))//2) % mod
            ans += ((r-l)+1) % mod
        print(ans % mod)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a=0
for i in range(K,N+2):
  minn=0
  maxx=0
  minn=int((1/2)*(i-1)*i)
  maxx=int(((1/2)*N*(N+1))-((1/2)*(N-i)*(N-i+1)))
  
  a+=maxx-minn+1
  
print(a)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
a = N*(N+1)//2
b = K*(K+1)//2
c = K*(K-1)//2
if N<K:
    print(1)
else:
    print((2*a-b-c+2)%(10**9+7))

Submission status: Wrong Answer

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

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

def check(n,k):
    sum_min = (k-1)*k/2
    sum_max = n*(n+1)/2 - (n-k)*(n-k+1)/2
    
    sum_pattern = sum_max - sum_min + 1
    return sum_pattern


cnt = 0
for i in range(K,N+1):
    c = check(N,i)
    cnt = (cnt + c) % (10**9+7)
    
print(cnt+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,K = inputMap()
	N += 1

	if N == K or K == 0:
		print(1)
		sys.exit()

	ans = 0
	comb = Combination(N)
	for i in range(K,N):
		tmp = comb(N, i)
		#print(tmp)
		ans += tmp
		ans = ans % (10**9+7)

	print(ans)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[1] = 1
ninv[0],ninv[1] = 1,1
N = N + 1
for i in range(2, N + 1):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = int(ninv[i - 1] * inv[i] % MOD)

ret = 0
for i in range(K,N+1):
    ret += int(nac[N] / nac[i] / nac[N - i])
print(int(ret))

Submission status: Wrong Answer

Solution code:
import sys
N,K=map(int, sys.stdin.readline().split())
mod=10**9+7
ans=0
for k in range(K,N+2):
    max_n=(N+(N-k+1))*k/2
    min_n=(k-1)*k/2
    t=max_n-min_n+1
    if 4<=t:
        ans+=t+(t-4)/2
    else:
        ans+=t
print ans%mod

Submission status: Wrong Answer

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

cnt = 0
for i in range(K, N+2):
  start_idx = 0
  end_idx = 0
  #for j in range(i):
  #  start_idx += j
  start_idx = (i-1) * (i)//2
  
  #for j in range(i):
  #  end_idx += (N-j)
  end_idx = (i)*N - start_idx 
    
  #print( end_idx - start_idx+1)
  cnt += (end_idx - start_idx+1)
  cnt %= (10^9+7)
  
  
print(cnt%(10^9+7))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
ans=0
while k <= n+1:
  ans += k*(n-k+1)+1
  k+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import scipy as sp
n, k = list(map(int, (input().split())))

k_list = sp.arange(k, n+2)

k_list = n*k_list - k_list**2 + k_list + 1 &  (10**9 + 7)

print(sum(k_list))

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    P = []
    for i in range(n+1):
        P.append(-10**100 + i)
    #print(P)

    def comb(n,r,p = mod):
        r = min(r,n-r) # nCr
        res = 1
        div = 1 # nCr := n*n-1*...n-r+1 // 1*2*3...r
        for i in range(n-r+1,n+1):
            res *= i
            res %= p
        for i in range(1,r+1):
            div *= i
            div %= p
        res *= pow(div,p-2,p) # 掛け算に
        res %= p
        return res
    ans = 0
    for i in range(k,n+2):
        #print(comb(n+1,i),n+1-i-1)
        a = n-i
        if a < 0:
            a = 0
        ans += comb(n+1,i) - a
    print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
N,K = map(int,input().split())
ans=0
Nplus1= N+1
for i in range(K,Nplus1+1):
  ans += cmb(Nplus1,i)
  
print(ans%(7+10**9))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[1] = 1
ninv[0],ninv[1] = 1,1
N = N + 1
for i in range(2, N + 1):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = int(ninv[i - 1] * inv[i] % MOD)

ret = 0
for i in range(K,N+1):
    ret += int(nac[N] * (ninv[i] * ninv[N - i] % MOD) % MOD)
print(int(ret))

Submission status: Wrong Answer

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

print(int(ans))

'''
1ko 0 -- n nko
2ko 1 -- 2n-1 2n-1ko
3ko 3 -- 3n-3 3n-5 ko
4ko 6 -- 4n-6 4n-11 ko
k-ko sigma 1 - (k-1) -- k*n - sigma(1 - (k-1))
(sigma 1 - (k-1)) = k * (k-1) / 2
k-ko ippannsiki -> k*n - 2 * (k * (k-1) / 2) + 1
'''

Submission status: Wrong Answer

Solution code:
def ncr(n, r):
    if r == 0:
        return 1
    if r == 1:
        return n

    # 4c1と4c3は同じなので小さいrを使う
    r = min(r, n - r)

    # 桁が小さいときは繰り返し二乗法
    if n + r < 4000:
        x, y = 1, 1
        for i in range(r):
            x *= n-i
            y *= i+1
        return x // y

    x = list(range(n - r + 1, n + 1))
    y = list(range(1, r+1))
    for p in range(2, r + 1):
        pivot = y[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                x[k - offset] //= pivot
                y[k] //= pivot
    result = 1
    for k in range(r):
        result *= x[k]
    return result


n, k = map(int, input().split())
n += 1
MOD = 10**9+7
ans = 0

for i in range(k, n+1):
    ans += ncr(n, i) % MOD
    if i != n and i % 2 == 0:
        ans -= i // 2
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod
    
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

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

NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
N, K = map(int, input().split())

r = 0
for i in range(K, N+2):
    s = ((i-1) * i) //2
    s %= mod
    e = N*(N+1)//2
    print(e)
    e -= ((N-i)*(N-i+1)) //2
    e %= mod
    print(i, s, e)
    r = (r + e-s+1) % mod
print(r)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,k = (int(x) for x in input().split())
M = 10**9+7
s = 0

for i in range(n+2-k):
    ad = 1 + (n+1-k-i)*(k+i)
    s += ad
    if s >= M:
        s -= M
        
print(s)

Submission status: Wrong Answer

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

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

kosuu = N+1
result = 0
while K < kosuu:
    #N+1_C_Kを計算
    result += cmb(N+1, K)
    K += 1
print(result%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a = 0
count = 0
while k+count<n+1:    
    a += comb(n+1,k+count)
    count += 1
print(a)

Submission status: Wrong Answer

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


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**6
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 )

result = 0
for num in range(n-k,n):
    result += cmb(n+1,num,mod)

print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

def conbination(n, r):
    bunsi = math.factorial(n) // math.factorial(n - r)
    bunbo = math.factorial(r)
    return bunsi // bunbo

N, K = (int(x) for x in input().split())
sum = 0

for i in range(K,N+2):
    sum = sum + conbination(N+1, i)
    print(N+1, i ,conbination(N+1, i))

print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

Submission status: Wrong Answer

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

count = 0

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

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

Submission status: Wrong Answer

Solution code:
import math
import itertools

mod = 10**9 + 7

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

if n < k:
    print(1)
else:
    l = [i for i in range(n + 1)]

    s = set()

    for i in range(k, n + 1):
        for v in itertools.combinations(l, i):
            s.add(v)

    print(len(s) % mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
    if a == 0:
        return 1
    elif a == 1:
        return x
    elif a % 2 == 0:
        return power(x, a//2) **2 % mod
    else:
        return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
    return power(x, mod-2)

modinv_table = [-1] * (k+1)
for i in range(1, k+1):
    modinv_table[i] = modinv(i)

def binomial_coefficients(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i + 1]
        ans %= mod
    return ans

print(binomial_coefficients(n, k))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
N,K = map(int,input().split())
ans=0
Nplus1= N+1
for i in range(K,Nplus1):
  ans += cmb(Nplus1,i)
  
print(ans%(7+10**9))

Submission status: Wrong Answer

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

nums = set()

for k in range(K,N+1+1):
    s_min = k*(k-1)//2
    s_max =  k*(2*N-k+1)//2
    tmp = [k*1000+i for i in range(s_min,s_max+1)]
    nums = nums|set(tmp)


ans = len(nums)%(10**9+7)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from scipy.special import comb
a, b = map(int, input().split())
 
def coun(x, y):
  a = comb(x, y, exact=True)
  return a
 
if(a+1== b):
  print(1)
else:
  count = 0
  for i in range(a-b+2):
    count += coun(a+1,i+b)
  print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

for i in range(K,N+1):
  a = a+ cmb(N+1, i)
print(a % MOD)

Submission status: Wrong Answer

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

def C(N, p):
  min_p = p * (p - 1) // 2
  max_p = p * (2 * N - p + 1) // 2
  return max_p - min_p + 1

ans = 0
for i in range(K, N + 1):
  ans += C(N, i)
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
MOD = 10**9 + 7
nac = [0] * (N + 2)
ninv = [0] * (N + 2)
inv = [0] * (N + 2)
nac[0],nac[1] = 1,1
inv[0] = 1
ninv[0],ninv[1] = 1,1

for i in range(2, N + 2):
    nac[i] = (nac[i-1] * i % MOD)
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
    ninv[i] = int(ninv[i - 1] * inv[i] % MOD)

ret = 0
for i in range(K,N+2):
    ret += (nac[N + 1] / nac[i]/ nac[N+1 - i])
print(int(ret))

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int,input().split())
total = 0
max = (n*(n+1)) //2  # 6 in ex.1
for a in range(k,n+1): # from 3 to 4 in ex.1
    high = (max-(n-a)) # 6-1 = 5, 6-0 = 6
    low = (a*(a-1)) //2  # 1, 3
    total += high - low + 1 # 5, 4
    total = total%(10**9 + 7)
total += 1 # choice all

total = total%(1000000007)
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
import time
n, k = list(map(int, input().split()))

result = 0
for _k in range(k, n + 2):
    # print('選ぶ数', _k)
    min_value = ((_k-1)+1)*(_k-1)/2
    max_value = (n + n - (_k-1)) * (_k)/2
    # print(min_value, max_value)
    result += max_value - min_value + 1
print(int(result))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
if N<K:
    print(1)
else:
    a = int(N*(N+1)/2)
    b = int(K*(K+1)/2)
    print((2*a-b+1)%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#from scipy.special import comb

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

if K>=N:
  print(1)
else:

  ans = 0
  bunsi = 1
  l_bunsi = []
  bunbo = 1
  l_bunbo = []
  for i in reversed(range(N+2-K, N+2)):
    bunsi *= i
  l_bunsi = i
  for i in range(1,K+1):
    bunbo *= i
  l_bunbo = i

  ans = bunsi//bunbo

  for i in range(K+1, N+1):
    bunsi *= l_bunsi-1
    bunbo *= l_bunbo+1
    ans += bunsi//bunbo%(10**9+7)
  print(ans%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

LOW, HIGH = 0, N
ans = 0

if K >= 1:
    ans += (HIGH - LOW + 1)

for i in range(2, N + 2):
    LOW += i - 1
    HIGH += N - i + 1
    LOW %= MOD
    HIGH %= MOD
    if i >= K:
        ans += (HIGH - LOW + 1)
        ans %= MOD

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

LOW, HIGH = 0, N
ans = 0

for i in range(2, N + 2):
    LOW += i - 1
    HIGH += N - i + 1
    LOW %= MOD
    HIGH %= MOD
    if i >= K:
        ans += (HIGH - LOW + 1)
        ans %= MOD

print(ans)

Submission status: Wrong Answer

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

ans = 0

def comb(n,r):
    if n-r < r:
        r = n-r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n-r+k+1 for k in range(r)]
    deciminator = [k+1 for k in range(r)]

    for p in range(2,r+1):
        pivot = deciminator[p-1]
        if pivot > 1:
            offset = (n-r)%p
            for k in range(p-1,r,p):
                numerator[k-offset]/=pivot
                deciminator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result += int(numerator[k])

    return result


if K == N+1:
    ans = 1
else:
    for i in range(K,N+1):
        
        n = comb(N+1,i)
        ans += n%(10**9+7)

print(ans)