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:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

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

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

Submission status: Wrong Answer

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


print(N)
print(K)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def solve():
    N, K = map(int, input().split())
    #a = 226732710
    tot = 0
    for k in range(K, N+1+1):
        mi = k*(k-1)/2
        ma = N*(N+1)/2-(N-k-1)*(N-k)/2
        tot += int(ma-mi+1)
            
    print(tot)
solve()

Submission status: Wrong Answer

Solution code:
date=input().rstrip().split(" ")
N=int(date[0])
K=int(date[1])
result=0
for i in range(K-1,N+1):
  num0=0
  num1=0
  for j in range(i):
    num0+=N-j
    num1+=j
  result+=num0-num1
print(result)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
count=0
for i in range(n+1):
    if i<k:
        continue
    elif i>=k:
        mini=k*(k-1)//2
        a=n*(n+1)//2
        b=(n-k)*(n-k+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
print(count)

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

for num in range(1, input_n + 2):
    sum_min = sum_min + num - 1
    sum_max = sum_max + input_n + 1 - num
    if num >= input_k :
        sum_num = sum_num + sum_max - sum_min + 1
    # print(num)
    
    # print(sum_min)
    # print(sum_max)
    # print(sum_num)

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

Submission status: Wrong Answer

Solution code:
from itertools import permutations, combinations

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

ans = 0
_list = list(range(N+1))
_list.sort(reverse = True)
h = _list[0]
l = 0
cnt = 0

for i in range(1, N+1):
    h += _list[i]
    cnt += 1
    l += cnt
    if i >= K-1:
        ans += h - l + 1

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

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import math
sys.setrecursionlimit(4100000)

n, k = map(int, input().split())
n += 1
if (n //2) >= k:
    k = k // 2
#n += 1
mod = 10**9 + 7
flag = 1
sum = 0

def Comborution(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

while n > k:
    sum += Comborution(n, k)
    k += 1
    flg = 0

if flag ==1:
    print(1)
else:
    print(sum % mod)

Submission status: Wrong Answer

Solution code:
n, k = [int(i) for i in input().split(' ')]
ls = range(n+1)


ma = sum(ls[-k:])+1
mi = sum(ls[:k])
s = ma-mi

for i in range(k+1, n+2):
    ma += ls[-i]
    mi += ls[i-1]
    s += (ma-mi)
    
print(s)

Submission status: Wrong Answer

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

x=1
mod = 10 ** 9 + 7

for i in range(k,n+1):
    p=1
    for j in range(k,i+1):
        p*=j
        p%=mod
    p/=i
    x+=p

print(x)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, K = MAP()
ans = 1

def count(i, N):
	if i == 1:
		return N+1
	else:
		return (N*(N+1)/2 - (N-i)*(N-i+1)/2) - (i-1)*i/2 + 1


for i in range(K, N+1):
	ans += count(i, N)

print(int(ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
x = 100000007
 
A = (N - 1) * N * (N + 1) // 2
B = N * (N + 1) * (2 * N + 1) // 6
C = N * K * (K + 1) // 2
D = (K - 1) * K * (K + 1) // 3
E = N - K + 1 
Ans = (A - B - C + D + E) % x
 
print(Ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
ko = (N-K+1)*K+1
print('{:.0f}'.format(ko*(ko+1)/2))

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    ret = 1
    for i in range(k, n+2):
        ret += k*(k+1)//2

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
def touSum(a,l):
    return int(((l-a+1)*(a+l))/2)

N,K = map(int,input().split())
maxSum = touSum(1,N)
print(maxSum)
con = 0
for i in range(K,N+1+1):
    #print(str(i)+":"+str(touSum(1,i-1))+":"+str(touSum((1+N)-i,N)))
    if touSum(1,i-1)>maxSum:
        print(con)
        break
    else:
        con += touSum((1+N)-i,N) -touSum(1,i-1)+1
print(con%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


import numpy as np
from itertools import accumulate


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

n = range(N+1) #  + 10**100
# print((n + 10**100)%(10**9+7))

if K >= N:
    print(1)
    exit(0)

combi = np.array(range(N+1-(K-1)))+K
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    # S += len(set(np.sum(np.array(list(itertools.combinations(n, c))),axis=1)))
    # itertools.combinations(n, c)
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    # print(min_num, max_num)
    S += (max_num-min_num)
    S %= 1000000007
print(S)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
summ=0
l=[]
for i in range(n+1):
	summ+=(i)
	
	l.append(i)
#print(2)
dp=[]
for i in range(n+1):
	dp1=[]
	for j in range(summ+1):
		if(j==0):
			dp1.append(1)
		else:
			dp1.append(0)
	dp.append(dp1)

for i in range(1,n+1):
	dp[i][l[i-1]]=1
	for j in range(1,summ+1):
		if(dp[i-1][j]==1):
			dp[i][j]=1
			dp[i][j+l[i-1]]=1
print(dp)
count=0
for i in range(1,summ+1):

	if(dp[n][i]==1 and i>=k):
		count+=1
print(count+8)

Submission status: Wrong Answer

Solution code:
def cmb(n, k, mod, fac, ifac):
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod

def make_tables(mod, n):
    fac = [1, 1]
    ifac = [1, 1]
    inverse = [0, 1]

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


n, k = map(int, input().split())
MOD = 10**9 + 7
fac, ifac = make_tables(MOD, n+1)
ans = 0
if(n+1 == k):
    print(1)
else:
    for i in range(k,n+1):
        ans += cmb(n+1, i, MOD, fac, ifac)
    print(ans%MOD);

Submission status: Wrong Answer

Solution code:
import math

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

w = list(range(n + 1))
a = [0 for _ in range(n)]

mx = sum(w[(n // 2) + 1:]) - sum(w[:(n // 2) + 1]) + 1
a[(n // 2)] = mx

cnt = 1
prev = mx
for i in range((n // 2) - 1, -1, -1):
    a[i] = prev - cnt
    a[n - i - 1] = prev - cnt
    cnt += 2
    prev = a[i]

print((sum(a[k - 1:]) + 1) % 1000000007)

# w = list(range(n + 1))
# a = []

# sm = 0
# for i in range(k - 1, n):
#     i = i + 1
#     sm += sum(w[n - i + 1:]) - sum(w[0:i]) + 1

# print(sm + 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-


import numpy as np
from itertools import accumulate


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

n = range(N+1) #  + 10**100
# print((n + 10**100)%(10**9+7))

if K >= N:
    print(1)
    exit(0)

print(n)

combi = np.array(range(N+1-(K-1)))+K
print(combi)
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    # S += len(set(np.sum(np.array(list(itertools.combinations(n, c))),axis=1)))
    # itertools.combinations(n, c)
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    # print(min_num, max_num)
    S += (max_num-min_num)
    S %= 1000000007
print(S)

Submission status: Wrong Answer

Solution code:
n, r = 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 = 2 * 10**5
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)

if n > r:
    print(cmb(n, r, mod))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]

    res = 0
    if K <= N:
        for i in range(K, N+1):
            a = (i-1)*i//2
            c = N-i
            b = N*(N+1)//2 - c*(c+1)//2
            print(a, b)
            res += b - a +1
    res += 1
    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n,k=map(int,input().split())
ans=(n+1)*( (n+k+1)*(n-k+2)/2 - (n+2)*(2*n+3)/6 )+k*(k-1)*(2*k-1)/6+(n-k+2)
ans=int(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 += i*(N-i+1)+1
#
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

mod=pow(10,9)+7

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom %mod

a,b=map(int,input().split())

a+=1
ans=0

for i in range(a-b+1):
    ans=(ans+combinations_count(a,b+i))%mod

a-=2

for i in range(a-b+1):
    ans=(ans-combinations_count(a,b+i))%mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
x = 100000007
 
A = (N - 1) * N * (N + 1) // 2
B = N * (N + 1) * (2 * N + 1) // 6
C = N * K * (K + 1) // 2
D = (K - 1) * K * (K + 1) // 3
 
Ans = (A - B - C + D) % x
 
print(Ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
def po(a,t,p):
    bi=str(format(t,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
          res=(res*a) %p
    return res
print(po(2,n+1,1000000007)-po(2,k-1,1000000007))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

w = list(range(n + 1))
a = [0 for _ in range(n)]

mx = sum(w[(n // 2) + 1:]) - sum(w[:(n // 2) + 1]) + 1
a[(n // 2)] = mx

cnt = 1
prev = mx
for i in range((n // 2) - 1, -1, -1):
    a[i] = prev - cnt
    a[n - i - 1] = prev - cnt
    cnt += 2
    prev = a[i]

print(sum(a[k - 1:]) + 1)

Submission status: Wrong Answer

Solution code:
def factorial( n) : 
    M = 1000000007
    f = 1
  
    for i in range(1, n + 1):  
        f = f * i  # WRONG APPROACH as  
                  # f may exceed (2^64 - 1)  
  
    return f % M

Submission status: Wrong Answer

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

l = []
ans = 0

for i in range(N+1):
  l.append(i)

mx = l[N]
mn = 0
for i in range(K, N+2):
  s = 0
  mx += l[N-i+1]
  mn += l[i-1]
  ans += (mx - mn + 1) % INF

print(ans % INF)

Submission status: Wrong Answer

Solution code:
n, r = 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 = 2 * 10**5
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)

if n < r:
  print(cmb(n, r, mod))
else:
  print(1)

Submission status: Wrong Answer

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

l = []
ans = 0

for i in range(N+1):
  l.append(i)

mx = l[N]
mn = 0
print(l)
for i in range(K, N+2):
  s = 0
  mx += l[N-i+1]
  mn += l[i-1]
  ans += (mx - mn + 1) % INF

print(ans % INF)

Submission status: Wrong Answer

Solution code:
def mod(N, K):
	return (N%K + K) % K

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
A=(N+1/2)*(N*(N+1)/2-(K-1)*K/2)
B=N*(N+1)*(2*N+1)-(K-1)*K*(2*K-1)
B=B/12
print('{:.0f}'.format(A+B))

Submission status: Wrong Answer

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

goukei = 0

for j in range(k,n+2):
    goukei += ((2*n-j)*(j+1)/2) - ((j-1)*j/2) + 1
    
print(goukei)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb

N, K = map(int, input().split())
result = 0
if (N + 1) % 2 != 0:
    for i in range(K, N + 2):
        sycle = comb(N + 1, i, exact=True) - comb((N + 1) // 2, i // 2, exact=True) + 1
        result += sycle % (10 ** 9 + 7)
else:
    for i in range(K, N + 2):
        if i % 2 == 0:
            sycle = (
                comb(N + 1, i, exact=True) - comb((N + 1) // 2, i // 2, exact=True) + 1
            )
        else:
            sycle = comb(N + 1, i, exact=True)
        result += sycle % (10 ** 9 + 7)
print(result % (10 ** 9 + 7))

Submission status: Wrong Answer

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

minn = sum(lst[:k])
maxn = sum(lst[-k:])

print(maxn - minn)

Submission status: Wrong Answer

Solution code:

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

input_n = ls[0]

input_k = ls[1]


sum_num = 0

sum_min = 0

sum_max = 0

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

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

Submission status: Wrong Answer

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

MOD = 10**9 + 7

# for k = n
result = 1 % MOD

cand = [i for i in range(0, n+1)]
for ki in range(k, n+1):
   if ki == 1:
      result += (n+1) % MOD
   elif ki == 2:
      result += (2*n-1) % MOD
   else:
      minans = (ki-1) * ((ki-1)//2)
      maxans = (2*n-ki+1) * (ki//2)
      if ki % 2 == 1:
         minans += int((ki-1)/2)
         maxans += int((2*n-ki+1)/2)
      result += (maxans - minans + 1) % MOD

print(result % MOD)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
x = n+1
ans = 0
from itertools import combinations
for i in range(m,n+2):
    ans = ans + len(list(combinations(range(x),i)))
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
n, k = map(int, input().split())
cnt = 0
for i in range(k,n + 4 -k):
  ca = 0
  cb = 0
  for j in range(i):
    ca += n - j
    cb += j
  cnt += ca - cb + 1
print(cnt % mod)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb

N, K = map(int, input().split())
result = 0
if (N + 1) % 2 != 0:
    for i in range(K, N + 2):
        sycle = comb(N + 1, i, exact=True) - comb((N + 1) // 2, i // 2, exact=True) + 1
        print(sycle)
        result += sycle % (10 ** 9 + 7)
else:
    for i in range(K, N + 2):
        if i % 2 == 0:
            sycle = (
                comb(N + 1, i, exact=True) - comb((N + 1) // 2, i // 2, exact=True) + 1
            )
        else:
            sycle = comb(N + 1, i, exact=True)
        result += sycle % (10 ** 9 + 7)
        print(sycle)
print(result % (10 ** 9 + 7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:27:49 2020

@author: arute
"""


from sys import stdin

import time
import numpy as np
import math


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

############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])
M = int(temp[1])

# すべての場合の数を計算。
probs = np.zeros(1).astype("int64")

for i,m in enumerate(range(M,N+2)):
    # 作れる最小は？
    if i == 0:
        small = np.sum(np.arange(m))
        #
        large = np.sum(np.arange(N+1-m,N+2))
    else:
        small = (small+m-1).astype("int64")
        large = (large + (N+1-m)).astype("int64")
    
    probs = probs + (large - small + 1)

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7

class ModInt:
    def __init__(self, x):
        if isinstance(x, ModInt):
            self.value = x.value
        else:
            self.value = x % MOD
            if self.value < 0:
                self.value += MOD
    
    def get_mod(self):
        return MOD
    
    # str関数を使用したとき
    def __str__(self):
        return str(self.value)
    
    def __int__(self):
        return self.value
    
    __index__ = __int__
    
    # print関数を使用したとき
    __repr__ = __str__

    ## 四則演算
    def __add__(self, other):
        return ModInt(self.value + ModInt(other).value)
    
    def __sub__(self, other):
        return ModInt(self.value - ModInt(other).value)

    def __mul__(self, other):
        return ModInt(self.value * ModInt(other).value)
    
    def __truediv__(self, other):
        # a * a^(p - 2) ≡ 1 (mod p) 逆元から求める
        return ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))

    # 累乗
    def __pow__(self, other):
        return ModInt(pow(self.value, ModInt(other).value, MOD))

    ## 四則演算の順序
    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other - self.value)
    
    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.value, MOD - 2, MOD))

    def __rfloordiv__(self, other):
        return ModInt(other // self.value)
    
    # 累乗の順序
    def __rpow__(self, other):
        return ModInt(pow(other, self.value, MOD))
    
    ## 不等号
    def __lt__(self, other):
        return self.value < ModInt(other).value
    
    def __gt__(self, other):
        return self.value > ModInt(other).value

    def __le__(self, other):
        return self.value <= ModInt(other).value
    
    def __ge__(self, other):
        return self.value >= ModInt(other).value
    
    def __eq__(self, other):
        return self.value == ModInt(other).value
    
    def __ne__(self, other):
        return self.value != ModInt(other).value
    
    ## in-place 演算子(+=, -=, *=, /=)
    def __iadd__(self, other):
        self.value += ModInt(other).value
        if self.value >= MOD:
            self.value -= MOD
        return self.value
    
    def __isub__(self, other):
        self.value -= ModInt(other).value
        if self.value < 0:
            self.value += MOD
        return self.value
    
    def __imul__(self, other):
        self.value = ModInt(self.value * ModInt(other).value)
        return self.value

    def __itruediv__(self, other):
        self.value = ModInt(self.value * pow(ModInt(other).value, MOD - 2, MOD))
        return self.value
    
    # 逆元
    def modinv(self):
        return ModInt(pow(self.value, MOD - 2, MOD))
    
N, K = map(ModInt, map(int, input().split()))

ans = ModInt(0)
for i in range(K, N):
    res_min = ModInt(0)
    res_max = ModInt(0)
    for j in range(i):
        res_min += j
        res_max += N + 1 - j + 1
    
    sub = res_max - res_min + 1
    ans += sub

ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
ans=0
x=list(range(n+1))
for i in range(k,n+1):
  if n%2==1:
    if (n//2)+1 >= i:
      A=sum(x[n-i:n+1])
      B=sum(x[0:i])
    else:
      A=sum(x[i:n+1])
      B=sum(x[0:n-i])
  else:
    if n//2>=i:
      A=sum(x[n-i+1:n+1])
      B=sum(x[0:i])
    else:
      A=sum(x[i:n+1])
      B=sum(x[0:n-i+1])
  ans+=A-B+1
print(ans)

Submission status: Wrong Answer

Solution code:

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


for i in range(K,N+1):
    mini=i*(i-1)//2
    maxi=i*(N-1)
    ans=(ans+(mini-maxi+1))//(10^9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
l=list(range(K,N+2))
sum =0
for i in l:
    m=(i-1)*i/2
    p=i*N-2*m+1
    sum+=p
print(int(sum))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

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

@lru_cache(maxsize=None)
def get_factorial(num):
    return(math.factorial(num) % (10**9 + 7))
  
cnt = 0
c = get_factorial(n+1)
for i in range(k, n+2):
    cnt += c / (get_factorial(i) *  get_factorial(n+1-i))
print(int(cnt))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
sumX = (n+0)*(n+1)/2

if n+1 == k:
    print(1)
else:
    i = k
    sumA = 0
    while i <= n+1:
        sumA+=(((n+i)//2)*(n+1-i)+1)%(10**9+7)
        sumA %= (10**9+7)
        i+=1
    print(sumA)

Submission status: Wrong Answer

Solution code:
a,b=(int(x) for x in input().split())
z=0
for i in range(b,a+2):
  z=(z+(a-i+1)*i+1)%(1e9+7)
print(z)

Submission status: Wrong Answer

Solution code:
import itertools
N, K = map(int, input().split())
count = 0
a = list(range(N+1))
for i in range(K,len(a)+1):
        count += len(list(itertools.combinations(a,i)))
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations as C
n, k = map(int, input().split())
mod = 10**9 + 7
a = [i for i in range(n+1)]
tmp = []

for i in range(k, n+2): #iは選ぶ個数
    for cmb in C(a, i):
        #print(f"{cmb=},  {sum(cmb)=}")
        tmp.append(sum(cmb)//mod)
        
print(len(set(tmp)))

Submission status: Wrong Answer

Solution code:
import itertools

n, k = map(int, input().split())
inicial = (10**100) % (10**9 + 7)
listN = list(range(n+1))
count = 0

for i in range(k, n+2):
    count += len(list(itertools.combinations(listN, i)))
    
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import permutations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
MOD = pow(10, 9) + 7

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

l = range(0, N + 1)
sum_ = sum(l)
if K > N:
    print(1)
    sys.exit()

ans = 0
for i, k in enumerate(range(K, N + 2), 0):
    if k == K:

        small = sum(l[:K])
        large = sum(l[-K:])
    else:
        small += i + 1
        small = min(small, sum_)
        large += i
        large = min(large, sum_)
    acc = large - small + 1
    acc %= MOD
    ans += acc
    #break
print(ans % MOD)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

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

@lru_cache(maxsize=None)
def get_factorial(num):
    return(math.factorial(num) % (10**9 + 7))
  
cnt = 0
c = get_factorial(n+1)
for i in range(k, n+2):
    cnt += c / (get_factorial(i) *  get_factorial(n+1-i))
    print(cnt)
print(int(cnt))

Submission status: Wrong Answer

Solution code:
import itertools

n, k = map(int, input().split())
inicial = (10**100) % (10**9 + 7)
listN = list(range(n+1))
count = 0

for i in range(k, n+1):
    count += len(list(itertools.combinations(listN, i)))
    
print(count)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import math

n, k = map(int, input().split())
# n += 1
if (n //2) >= k:
    k = k // 2
n += 1
mod = 10**9 + 7
flg = 1
sum = 0

def Comborution(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

while n > k:
    sum += Comborution(n, k)
    k += 1
    flg = 0

if flg ==1:
    print(1)
else:
    print(sum % mod)

Submission status: Wrong Answer

Solution code:
import itertools
x =(input()).split(" ")
N = int(x[0])+1
K = int(x[1])
l = []
p =0
for i in range(N):
	l.append(p)
	p+=1
p = 0
while K<=N:
	c_list = list(itertools.combinations(l, K))
	print(c_list)
	K+=1
	p+=len(c_list)
print(p)

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

Submission status: Wrong Answer

Solution code:
NK = input()
NKs = NK.split(" ")
N = int(NKs[0])
K = int(NKs[1])
Ns = []
x = 1
for i in range(N+1):
    Ns.append(x)
    x = x + 1
    
dif = -1
output = 0
while dif != 0:
    za = 1
    zu = N + 1
    minimum = 0
    maximum = 0
    for i in range(0,K-1):
        minimum = minimum + za
        za = za + 1
        maximum = maximum + zu
        zu = zu - 1
    K = K + 1
    dif = maximum - minimum
    output = output + dif

print(output)

Submission status: Wrong Answer

Solution code:
import itertools

n,i = map(int,input().split())
a = [i + 10**100 for i in range(n+1)]
#a = [i + 10**1 for i in range(n+1)]
ans = {}
s = 0
m = i
print(i,n)
while i <= n+1:
  wrk = list(itertools.combinations(a,i))
  for l in wrk:
    s = sum(l)
    if s not in ans:
      ans[s] = int(1)
    else:
      ans[s] += int(1)
  i += 1
print(len(ans))

Submission status: Wrong Answer

Solution code:
import itertools
n, k = map(int, input().split())
ans = 0
if n <= k :
    ans +=1
else:
    for i in range(k, n+1):
        j = list(itertools.combinations(range(n+1), i))
        ans += len(j)

print(ans)

Submission status: Wrong Answer

Solution code:
import math


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


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

nCr = 1
for j in range(k,n+1):
    nCr_1 = nCr * (n+1-j)//(j+1)
    nCr = nCr_1
    s += nCr_1 %(pow(10,9)+7)
    s %= (pow(10,9)+7)

if s == 0:
    print(1)
else:
    print(s)

Submission status: Wrong Answer

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

x = 7+10**9

def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

List=[]
for i in range(K,N+2):
    List.append(comb(N+1,i,x))

print(sum(List)%x)

Submission status: Wrong Answer

Solution code:
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

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