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:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N, K = map(int, readline().split())
N = N + 1

lower = None
upper = None
answer = 0
for k in range(K, N+1):
    if lower is None:
        lower = sum(range(k))
        upper = sum(range(N-k, N))
    else:
        lower += k - 1
        upper += N - k
    answer += (upper - lower + 1) % MOD
print(answer)

Submission status: Wrong Answer

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

res = 0
for i in range(K, N+2):
    m = i*(i+1)//2 % 1000000007
    M = i*(2*N+3-i)//2 % 1000000007
    res += (M - m + 1) % 1000000007

print(res)

Submission status: Wrong Answer

Solution code:
inp_str = input()
N, K = list(map(int, inp_str.split(" ")))
MOD = 10e9 + 7

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

Solution code:
import sys
#import copy
#import math
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
mod = 1000000007

#read = sys.stdin.buffer.read

def main():
    # input
    N, K = map(int, readline().split())

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

    ans0 = 0
    ans1 = 0
    for k in range(K, N+1):
        maxsum0 = (k * (2 * N - k + 1)) // 2
        maxsum1 = ((k - 1) * (2 * N - k + 2)) // 2
        minsum0 = (k * (k + 1)) // 2
        minsum1 = ((k - 1) * k) // 2
        ans0 += maxsum0 - minsum0 + 1
        ans1 += maxsum1 - minsum1 + 1


    ans = (ans0 + ans1) % mod
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

num = 0
for x in range(k, n + 1):
    minnum = sum(i for i in range(k))
    maxnum = sum (i for i in range(n - k + 1,n + 1))
    num += maxnum - minnum + 1

print(num)

Submission status: Wrong Answer

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

num = 0
for x in range(k, n + 1):
    print(x)
    minnum = sum(i for i in range(k))
    maxnum = sum (i for i in range(n - k + 1,n + 1))
    num += maxnum - minnum + 1

print(num)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
MOD = 1e9+7

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

    s[i] = (s[i-1] + ( i * (n-i+1) + 1 )) % MOD
    if s[i] < 0:
        s[i] %= MOD

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

Submission status: Wrong Answer

Solution code:
def d():
    n, k = map(int, input().split())
    combination = [0] * (n+2)
    min = [0] * (n+2)
    min[1] = 0
    max = [0] * (n+2)
    max[1] = n
    # print(min, max)

    # i個選ぶ場合、その合計値のパターン: 最大値〜最小値が1つずつ生成できるからそれ
    # min: 0, 1, 2, ..., i-1
    # max: n, n-1, n-2, ..., n+1-i
    for i in range(k, n+2):
        max[i] = max[i-1] + n+1-i
        min[i] = min[i-1] + i-1
        combination[i] = max[i] - min[i] + 1
        # print('i, min_i, max_i, cmb_i', i, min[i], max[i], combination[i])
        # print(min, max)

    mod = 10**9 + 7
    print(sum(combination) % mod)


##########
if __name__ == "__main__":
    d()

Submission status: Wrong Answer

Solution code:
import numpy
N, K  = map(int, input().split(' '))
right = 0
s = 0
for i in range(K, N+2):
    mi = (i-1)*i/2
    ma = (2*N-i+1)*i/2
    s += (ma - mi) + 1
print(int(s%(1e7+7)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
#N = int(input())
#A = list(map(int,input().split()))
p=list(range(N+1))
c=0
s=sum(p[:K])
S=sum(p[:K])

l=sum(p[len(p)-K:])
L=sum(p[len(p)-K:])
for i in range(K,len(p)):
    s += p[i]
    S += s
    #print(s,S)
    #print(c)
    l += p[len(p)-i-1]
    L += l
#    print(i)
 #   print(l,L)
c = L - S + (N-K+2)
print(c)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

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

min_list = [sum([i for i in range(K)])]
for i in range(K, N):
    min_list.append((min_list[-1]+i) % MOD)

max_list = [sum([N-i for i in range(K)])]
for i in range(K, N):
    max_list.append((max_list[-1]+N-i) % MOD)

count = 0
for i in range(len(min_list)):
    count = (count+(max_list[i]-min_list[i]+1)) % MOD

print((count+1) % MOD)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
MOD = 1e9+7

a = [0] * (n+2)
s = [0] * (n+2)
a[1] = (n+1)
s[1] = a[1]
for i in range(2,n+2):
    add = ( a[i-1] + n - 2 * (i-1) ) % MOD
    if add < 0:
        add += MOD

    a[i] = add

    add = (s[i-1] + a[i]) % MOD
    if add < 0:
        add += MOD

    s[i] = add

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

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

def calc(i):
    minv = i * (i-1) // 2
    maxv = minv + i * (N - i + 1)
    print(minv, maxv)
    return maxv-minv+1

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
MOD = 1e9+7

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

    add = (s[i-1] + a[i]) % MOD
    if add < 0:
        add += MOD

    s[i] = add

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
ans=((2+n-k)*(6+n+n**2+2*k+k*n-k**2*2))//6
print(ans)

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 + 2):
    res_min = ModInt(0)
    res_max = ModInt(0)
    res_min += int(i * (i - 1) / 2)
    res_max += int(i * (N + (N - i + 1)) / 2)
    
    sub = res_max - res_min + 1
    ans += sub

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=list(map(int,input().split()))
s=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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
nk = list(map(int,input().split()))
n, k = nk[0], nk[1]
def wa(a,b):
    return (b*(b+1)//2)-(a*(a-1)//2)
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + n*(i+2) - 2*wa(0,i+1) + 1
if k == 1:
    ans = s[n] + 1
else:
    ans = s[n] - s[k-2]
while ans >= 10**9 + 7:
    ans -= (10**9 + 7)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import os
import math

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

def main():
    #file_input()

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

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

    print(int(sum))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

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

#def mpow(x, n):
#    result = 1
#    while n > 0:
#        if (n & 1):
#            result = (result * x) % MOD
#        x = (x * x) % MOD
#        n >>= 1
#    return result
#
#factorial = [0] * (n + 2)
#inverse = [0] * (n + 2)
#factorial[0] = 1
#inverse[0] = 1
#
#for i in range(1, n + 2):
#    factorial[i] = (factorial[i-1] * i) % MOD
#    inverse[i] = mpow(factorial[i], MOD - 2) % MOD

ans = 0

if k == 1:
    print((n+1) % MOD)
    sys.exit(0)

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

for i in range(k, n+1):
    #ans += (factorial[n+1] * inverse[n+1-i] * inverse[i]) % MOD
    ans += ((sum_cache[n] - sum_cache[n-i]) - sum_cache[i-1] + 1) % MOD
# n + 1
ans += 1

print(ans % MOD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(answer % mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 10 ** 9 + 7

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

#def mpow(x, n):
#    result = 1
#    while n > 0:
#        if (n & 1):
#            result = (result * x) % MOD
#        x = (x * x) % MOD
#        n >>= 1
#    return result
#
#factorial = [0] * (n + 2)
#inverse = [0] * (n + 2)
#factorial[0] = 1
#inverse[0] = 1
#
#for i in range(1, n + 2):
#    factorial[i] = (factorial[i-1] * i) % MOD
#    inverse[i] = mpow(factorial[i], MOD - 2) % MOD

ans = 0

if k == 1:
    print((n+1) % MOD)
    sys.exit(0)

# Last entry for -1 index
sum_cache = [0] + [0] * n + [0]
for i in range(1, n+1):
    sum_cache[i] = sum_cache[i-1] + i

for i in range(k, n+2):
    #ans += (factorial[n+1] * inverse[n+1-i] * inverse[i]) % MOD
    ans += ((sum_cache[n] - sum_cache[n-i]) - sum_cache[i-1] + 1) % MOD

print(ans % MOD)

Submission status: Wrong Answer

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

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

print(answer % mod)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7

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


cnt = 0
for k in range(K,N+2):

    t = (N-k+1)*k
    cnt += t
    cnt %= MOD
print(cnt)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(answer % mod)

Submission status: Wrong Answer

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

for i in range(K,N+2):
    max = (N+(N-(i-1)))*i*(0.5)
    min = (0+(i-1))*i*0.5
    sum += max-min+1

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

Submission status: Wrong Answer

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

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

print(answer % mod)

Submission status: Wrong Answer

Solution code:
import math
nk = list(map(int,input().split()))
n, k = nk[0], nk[1]
def wa(a,b):
    return (b*(b+1)//2)-(a*(a-1)//2)
s = [0] * (n+1)
s[0] = 0
for i in range(n):
    s[i+1] = s[i] + n*(i+2) - 2*wa(0,i+1) + 1
ans = s[n] - s[k-2]
while ans >= 10**9 + 7:
    ans -= (10**9 + 7)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
MOD = 1000000007
small = 0
large = 0
res = 0

for i in range(K-1):
  small += i
  large += N-i

for i in range(K, N+2):
  small += i-1
  large += N - i +1
  gap = large - small +1
  res += gap

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from scipy import special

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

for i in range(K, N + 1):
    y = special.comb(N + 1, i, True)
    count += y
print(count)

Submission status: Wrong Answer

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
        mii += i
        maa += nk[0]-i

    print(c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
nk = list(map(int,input().split()))
n, k = nk[0], nk[1]
def wa(a,b):
    return (b*(b+1)//2)-(a*(a-1)//2)
s = [0] * (n+1)
s[0] = 0
for i in range(n):
    s[i+1] = s[i] + n*(i+2) - 2*wa(0,i+1) + 1
ans = s[n] - s[k-2]
while ans >= 10**9 + 7:
    ans -= 10**9 + 7
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

# firstからlastまでの和を速く計算する
def sumRange(first, last):
    count = last - first + 1
    return int((first + last) * count / 2)

# 選んだ数値の個数がselectedのとき
# 第1項の係数はselectedになるので、選んだ個数が違えば和も必ず異なる
# よって、選んだ個数ごとに分けて考えてよい
for selected in range(K, (N + 1) + 1):
    # 最小値は数列のうち先頭selected個をとったもの
    minFraction = sumRange(0, selected - 1)

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

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

print(possible)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
mod = 10**9+7
answer = 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: Wrong Answer

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

ans = 0
for i in range(k,n+1) :
  # k個使う場合の最小値
  min_k = (k-1)*k//2
  # k個使う場合の最大値
  max_k = (n-k+1+n)*k//2
  ans += (max_k-min_k+1)
  
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

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

temp=1
ans=1

for i in range(N-K+1):#2回
    temp=temp*(K+i+1)*mod_inv(i+1,mod)%mod
    ans+=temp
    ans%=mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

# firstからlastまでの和を速く計算する
def sumRange(first, last):
    count = last - first + 1
    return (first + last) * count / 2

# 選んだ数値の個数がselectedのとき
# 第1項の係数はselectedになるので、選んだ個数が違えば和も必ず異なる
# よって、選んだ個数ごとに分けて考えてよい
for selected in range(K, (N + 1) + 1):
    # 最小値は数列のうち先頭selected個をとったもの
    minFraction = sumRange(0, selected - 1)

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

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

print(possible)

Submission status: Wrong Answer

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

print(((N*(N+1)*(N+2) - K*(K-1)*(3*N-2*K+4))/6 + N - K + 2)%1000000007)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 1e9+7

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

print(int(s[n+1] - s[k-1]))

Submission status: Wrong Answer

Solution code:

def answer(N:int,K:int) -> int:
    counter = 0
    for i in range(K,N+2):
        counter += i*(N - K + 1) + 1
    return counter % (10**9 + 7)



def main():
    N,K = map(int,input().split())
    # answer()
    print(answer(N,K))

if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
import numpy as np


mod = 10 ** 9 + 7

n, k = map(int, input().split())
k_np = np.arange(k, n + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = n * k_np - low
cnt = high - low + 1
print(cnt.sum() % mod)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
from collections import Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))


N, K= [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
go = 0

for i in range(K,N+2):
    ans_= (i*(N-i+1) + 1) % 1000000007
    ans += ans_
    go += 1
    

print(go,ans%1000000007)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Ans = (A - B + C + D) % x
 
print(Ans)

Submission status: Wrong Answer

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

max_value = sum(range(1,n+1))
lowest_value = sum(range(1,k+1))

answer = max_value - lowest_value + 1

print(answer % mod)

Submission status: Wrong Answer

Solution code:
import itertools
import math
from functools import reduce

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

#set obj
#cnt = 0

sum_list = set()

for i in range(k, n + 1):
    
    for pattern in list(itertools.combinations(range(n + 1), i)):
        #print(pattern)
        result = reduce(lambda a, b : a + b + math.pow(10, 100), pattern, 0)
        #result = reduce(lambda a, b : a + b + 100, pattern, 0)
        #result = reduce(lambda a, b : a + b, pattern, 0)
        #print(result)
        sum_list.add(result)
    #cnt += len(sum_list)
    #print(sum_list)
    #sum = set()

print(len(sum_list) + 1)
#print(sum_list)

# + 1

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 += k*(N-k+1)+1  
print(r%md)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
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: 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=i*(i-1)//2
        a=n*(n+1)//2
        b=(n-i)*(n-i+1)//2
        maxi=a-b
        total=maxi-mini+1
        count+=total
print(count%(10**9+7))

Submission status: Wrong Answer

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

c = 0

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

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

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans
mod = 10**9+7 #出力の制限
N = 10**5 * 2 + 1
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] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

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 )
# a = cmb(n,r)

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,k = m()

dp = [0 for i in range(n+1)]
dp[0] = n+1
co = 0
for i in range(1,n+1):
    dp[i] = dp[i-1] + (n - 2*i)
    dp[i] %= mod
    if i >= k-1:
        co += dp[i]
        co %= mod

print(co)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations
def calc(a,b,l):
    if b - a ==1:
        return 1
    c =  0
    ll = []
    for i in range(b, a + 1):
        p = list(combinations(l,i))
        for j in p:
            s = sum(list(j))
            if s not in ll:
                c +=1
    return c
l = []
a,b = map(int, input().split())
for k in range(a+1):
    l.append(k)
print(calc(a, b , l))

Submission status: Wrong Answer

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

c = 0

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n, k = [int(i) for i in input().split()]
    #smallのバリエーション
    mod = int(10e9 + 7)
    res = 0
    for i in range(k, n+2):
        min_s = int(i*(i-1)/2)
        max_s = int(n*(n+1)/2 - (n-i)*(n-i+1)/2 )
        res += (max_s - min_s + 1) % mod
    print(int(res))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# import time

def main(N, K):
    def sumN(x):
        return int(x * (x + 1) * 0.5)
    # ans = 0
    # for k in range(K, N + 2):
    #     M = sumN(N) - sumN(N - k)
    #     m = sumN(k-1)
    #     ans += M - m + 1
    ans = sum([sumN(N) - sumN(N - k) - sumN(k - 1) + 1 for k in range(K, N + 2)])

    print(ans)



if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    # t1 = time.time()
    # N, K = 3, 2
    # N, K = 200000, 200001
    # N, K = 141421, 35623
    main(N, K)
    # t2 = time.time()
    # print(t2-t1)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
num_list=[x for x in range(3+1)]
answer=0
count=N-K+2
for y in range(K,N+2):
    min=sum(num_list[:y])
    max=sum(num_list[-y:])
    answer+=max-min+1

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
ans=[]
small=range(k)
big=[n-i for i in range(k)]
s=sum(small)
b=sum(big)
while s!=b:
  ans.append((b-s+1)%((10**9)+7))
  s+=(small[-1]+1)
  b-=(big[-1]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def f(ns, k):
    for x in itertools.combinations(ns, k):
        print(x, sum(x))
    return (sum(ns[-k:]) - sum(ns[:k]) + 1)

def main():
    p = 10**9+7
    n, k = map(int, input().split())
    ns = list(range(n+1))

    r = 0
    bottom = sum(ns[:(k-1)])
    top = sum(ns[(-k+1):])
    for i, k2 in enumerate(range(k, n+1+1)):
        if k2 == n+1:
            r += 1
            break
        bottom += ns[i+k-1]
        top += ns[-i-k]

        r += (top - bottom + 1)
    print(r % p)

main()