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: Accepted

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

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

    ans = (ans + (maxValue - minValue + 1)) % (10 ** 9 + 7)

print(int(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    ans = 0
    for i in range(K, N + 2):
        a = (i * (i - 1)) // 2
        b = N * i - a
        ans += b - a + 1
        ans %= MOD
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main():
    n,k = na()
    ans = 0
    mod = pow(10,9)+7
    for i in range(k,n+2):
        sum_min = i*(i-1)//2
        sum_max = i*(2*n-i+1)//2
        #print(sum_min,sum_max)
        ans += (sum_max - sum_min + 1)
        ans %= mod
    print(ans%mod)
    return
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

MOD = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    N, K = [int(a) for a in input().split()]
    # A = [int(a) for a in input().split()]

    res = 0

    for k in range(K, N + 2):
        minv = k * (k + 1) // 2
        maxv = minv + (N + 1 - k) * k
        t = maxv - minv + 1
        res = (res + t) % MOD

    print(res)

    # @lru_cache(None)
    # def f(i, j):
    #     if i < 0 or j < 0:
    #         return -INF
    #     if i == 0:
    #         return -INF
    #     if abs(j - i // 2 - 1) >= 2:
    #         return -INF
    #     if j == 0:
    #         return 0
    #     if j == 1:
    #         return max(A[:i])
    #     return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))
    #
    # print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
x = sum(range(1,K))
y = sum(range(N+1,N+2-K,-1))
a = K-1
b = N+3-K
ans = 0
MOD = 10**9+7
for i in range(K,N+2):
  x += i
  y += N+2-i
  ans += y-x+1
  ans %= MOD
print(ans%MOD)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
mod = 10**9+7
li = [int(i) for i in range(N+1)]
suma = [0]*(N+1)
for i in range(1,N+1):
    suma[i] = suma[i-1]+li[i]
ans = 0
for i in range(K,N+1):
    m = suma[i-1]
    M = suma[-1] - suma[-(i+1)]
    ans += M-m+1
    ans %= mod
ans +=1
ans %= mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

fst = 0
lst = N
ans = 0
mod = 10**9+7

for i in range(1,K):
    fst += i
    lst += N-i
# print(i,fst,lst,ans)

for i in range(K,N+2):
    ans += lst-fst+1
    ans %= mod
    fst += i
    lst += N-i
    # print(i,fst,lst,ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools

N, K = map(int, input().split())
MOD = 10**9 + 7
a = [i for i in range(N+1)]

ma = list(itertools.accumulate(a))
Ma = list(itertools.accumulate(a[::-1]))

ans = 1
for k in range(K, N+1):
    m = ma[k-1]
    M = Ma[k-1]
    ans += (M - m + 1) % MOD
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
mod = 10**9 + 7
ans = 0
for i in range(K, N+2):
  mi = N-i+1
  ma = N
  s_max = ((mi+ma)*i)//2
  mi = 0
  ma = i-1
  s_min = ((mi+ma)*i)//2
  #print(s_min, s_max)
  ans += (s_max-s_min+1)
  ans %= mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

L = 0
R = 0
for i in range(K):
    L += i
    R += (N - i)

ans = 0
for x in range(K, N + 2):
    ans = (ans + (R - L + 1)) % mod
    L += x
    R += (N - x)

print(ans % mod)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
MOD = 10**9+7
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )

def sumarray(a,b):
    res=b*(b+1)//2
    res-=a*(a-1)//2
    return mint(res)

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


ans=mint(0)

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    ans=0
    S=[0]*(N+2)
    for i in range(N+1):
        S[i+1]=S[i]+(i)
    
    
    for i in range(K,N+2):#i個選ぶ
        m=S[i]
        M=S[-1]-S[-1-i]
        ans+=(M-m+1)%mod
        ans%=mod
    print(ans)
        

main()

Submission status: Accepted

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

res = 0

for k in range(K, N + 2):
    res += N * k - k * (k - 1) + 1
    res %= MOD

print(res)

Submission status: Accepted

Solution code:
[N,K] = list(map(int,input().split()))
out = 0
for i in range(K,N+2):
    L = (i-1)*i//2
    R = N*i-L
    P = (R-L+1)
    out += P
    out = out%(10**9+7)
print(out)

Submission status: Accepted

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

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


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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

mod = 10**9+7

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

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

ans = 0
for k in range(K, N+2):
    if k == N+1:
        ans = (ans + 1)%mod
    else:
        ans = (ans + (A[-1]-A[-k-1]) - A[k-1] + 1) % mod
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def f(st, en):
    n = en - st + 1
    return n * (st + en) // 2

def main():
    N, K = LI()
    cnt = 0
    for i in range(K, N+2):
        m = f(0, i-1)
        M = f(N - (i-1), N)
        cnt += (M - m + 1)
        cnt %= mod
    print(cnt % mod)



main()

Submission status: Accepted

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

ans = 0
for i in range(k, n + 1):

    sum_min =  (i - 1) * (i) // 2
    sum_max = i * (2*n - i - 1) // 2
    ans += sum_max - sum_min + 1
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
def main():
    MOD = 10**9+7
    N, K = [int(x) for x in input().split()]
    ans = 0
    for k in range(K, N+2):
        ans += k*N - k*(k-1)+1
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#MLE注意！ not は使わず !=

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

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

    res = 0

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 10**9+7
mod2 = 998244353
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,k = map(int,input().split())
ans = 0
for i in range(k,n+2):
  ans += n*(n+1)//2-(n-i)*(n-i+1)//2-i*(i-1)//2+1
  ans %= mod
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
up = [0]
down = [n]
for i in range(n):
    up.append(up[-1] + i+1)
    down.append(down[-1] +(n-i-1))
res = 0

for i in range(k-1,n+1):
    res += down[i] - up[i] + 1
    res %= mod
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
# tmp1=(k-1+0)*k//2
# tmp2=(n+0)*(n+1)//2
# print(tmp2,tmp1)
# print((tmp2-tmp1+1)%mod)
ans=0
for i in range(k,n+2):
    tmp1=(i-1+0)*i//2
    tmp2=(n+(n-(i-1)))*i//2
    # print(tmp1,tmp2)
    ans+=tmp2-tmp1+1
    ans%=mod
print(ans%mod)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

ANS=0
for t in range(K,N+2):
    MIN=(0+0+(t-1))*t//2
    MAX=(N+N-(t-1))*t//2

    ANS+=MAX-MIN+1
    ANS%=10**9+7

print(ANS)

Submission status: Accepted

Solution code:
Q = 10**9+7
def main():
    N, K = map( int, input().split())
    m = 0
    M = 0
    for i in range(K-1):
        m += i
        M += N-i
    ans = 0
    for i in range(K-1, N+1):
        m += i
        M += N-i

        ans += M-m+1
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(K,N+2):
    m = i*(i+1)//2
    m %= mod
    M = i*(N+2) - m
    M %= mod
    ans += M - m + 1
    ans %= mod
print(ans)

Submission status: Accepted

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 = 0
for k in range(K, N+2):  # k ことる
	mi = k*(k-1)//2
	x = N-k
	ma = N*(N+1)//2 - x*(x+1)//2
	ans += ma-mi+1
	ans %= mod

print(ans%mod)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, k = mi()
    ans = 0
    for i in range(k, n+2):
        low = i * (i + 1) // 2
        high = i * (2 * n + 3 - i) // 2
        ans += (high-low+1) % mod
        # print(ans)
    print(ans % mod)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

mod = 10**9+7

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10**9+7
a = [i for i in range(n+1)]
for i in range(n):
    a[i+1] += a[i]
b = [i for i in range(n, -1, -1)]
for i in range(n):
    b[i+1] += b[i]

ans = 0
for i in range(k-1, n+1):
    ans += b[i] - a[i] + 1
    ans %= mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

mod = 1000000007
INF = 110110110
_INFL = -INF * INF

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

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

Submission status: Accepted

Solution code:
def main():
    import sys
    N,K=list(map(int,sys.stdin.readline().split()))
    output=0
    for k in range(K,N+2):
        output+=(2*N-k+1)*k//2-k*(k-1)//2+1
        output%=10**9+7

    print(output)
main()

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,K = inputIL()

sum = 0

for s in range(K,N+2):
  sum = ( sum + ((2*N-s+1)*s-(s-1)*s)//2+1 )%MOD
  
print(sum)

Submission status: Accepted

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

for i in range(K,N+2):
    l = (i*(i-1))//2
    r = N*i - (i*(i-1))//2
    ans += r-l+1
    ans %= MOD
    
print(ans)

Submission status: Accepted

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

cnt = 0

for i in range(k, n + 2):
    hani_max = (n + n - i + 1) * (i) // 2
    hani_min = (i - 1) * i // 2
    cnt += hani_max - hani_min + 1
    cnt %= mod
print(cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate

n, k = map(int, input().split())
MOD = 10 ** 9 + 7
f_acc = [0] + list(accumulate(list(range(n + 1))))
b_acc = [0] + list(accumulate(reversed(list(range(n + 1)))))
ans = 0
for i in range(k, n + 2):
    min_ = f_acc[i]
    max_ = b_acc[i]
    ans = (ans + max_ - min_ + 1) % MOD
print(ans)

Submission status: Accepted

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

MOD = 10 ** 9 + 7

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *
from math import *

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

for i in range(K, N+2):
    c = ((2*N-i+1)*i)//2-i*(i-1)//2+1
    ans += c
    ans %= MOD

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
# n, k = 3, 2
# n, k = 141421, 35623
p = 10**9+7
s = 0
for l in range(k, n+1+1):
    s = (s+(n+1)*l-l**2+1) % p
print(s)

Submission status: Accepted

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

ans = 0
for i in range(k, n+2):
    max_i = ((n + (n - i + 1)) * i) // 2
    min_i = ((i - 1) *  i) // 2
    ans += max_i - min_i + 1
    ans %= 10**9 + 7

print(ans)

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n,k=map(int,input().split())
mod=10**9+7
ans=0
for i in range(k,n+2):
  l=(i-1)*i//2
  r=(2*n-i+1)*i//2
  ans+=r-l+1
  if ans>=mod:
    ans%=mod
print(ans)

Submission status: Accepted

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

ans = 0
mod = 10 ** 9 + 7

for k in range(K, N + 2):
    min_sum = k * (k - 1) // 2
    max_sum = k * (N + (N - k + 1)) // 2
    ans = (ans + (max_sum - min_sum + 1)) % mod

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mod = 10 ** 9 + 7
  
ret = 0
for i in range(K, N + 2) :
  ret += (2 * N - i + 1) * i // 2 - (i - 1) * i // 2 + 1
  ret %= mod
  
print(ret)

Submission status: Accepted

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

ans = 0

left = 0
right = 0

m = 10**9+7
for i in range(k-1):
    left += i

for i in range(k-1):
    right += n-i


for i in range(k,n+2):
    left += i-1
    right += n-(i-1)
    ans += max(0,(right-left)+1)
    ans %= m
    # print(left,right,ans)

print(ans)