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:
def examA():
    R = I()
    ans = R*2*3.141592
    print(ans)
    return

def examB():
    N, M = LI()
    A = LI()
    S = sum(A)
    if N>=S:
        ans = N-S
    else:
        ans = -1
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    ans = [0]*N
    for i in range(N-2,-1,-1):
        ans[A[i]-1] +=1
    for v in ans:
        print(v)
    return

def examD():
    N, K = LI()
    S = [0]*(N+2)
    for i in range(1,N+1):
        S[i+1] = S[i] + i
    #print(S)
    ans = 0
    for i in range(K,N+2):
        cur = (S[N+1] - S[N-i+1]) - (S[i] - S[0]) +1
        ans += cur
        ans %= mod
        #print(cur)

    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
from collections import *
import sys
try: inp = raw_input
except: inp = input
def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N, K = nl()

MOD = 10**9 + 7
s1 = sum(range(0, K))
s2 = sum(range(N - K + 1, N+1))
no = s2 - s1 + 1
for k in range(K, N+1):
    s1 += k
    s2 += N - k
    no += (s2 - s1 + 1)
print(no%MOD)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    ans=1
    md=10**9+7
    n,k=MI()
    for a in range(k,n+1):
        ans+=(n-a+1)*a+1
        ans%=md
    print(ans)

main()

Submission status: Accepted

Solution code:
n,k = (int(num) for num in 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 % MOD)

Submission status: Accepted

Solution code:
mod = int(1e9) + 7

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

    small = 0
    large = 0
    ans = 0
    for i in range(0, n+1):
        small += i
        large += n-i
        if i+1 >= k:
            ans = (ans + (large - small + 1)) % mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))

# 選ぶ数・和
ans = 0
for i in range(K, N + 2):
    # i こ選ぶときの和
    l = (i - 1) * i // 2
    r = (N - i + 1 + N) * i // 2
    ans += r - l + 1
print(ans % MOD)

Submission status: Accepted

Solution code:

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

ans = 0
mi = 0
ma = 0
mod = 10**9+7
for i in range(N+2):

    if i >= K:
        ans += ma - mi + 1
        ans %= mod

    mi += i
    ma += N-i
    mi %= mod
    ma %= 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 += i*(2*n - i + 1)//2 + 1
    ans %= mod
    ans -= i*(i-1)//2
    ans %= mod

print(ans)

Submission status: Accepted

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

ans = 0
mn = mx = 0
for i in range(N+1):
    j = N-i
    mn += i
    mx += j
    if i+1 >= K:
        ans += mx - mn + 1
print(ans%MOD)

Submission status: Accepted

Solution code:
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,K = Ints()

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

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True

ans=0

n,k=LI()

for i in range(k,n+1+1):
    #r=(n+n-k+1)*k//2-(k-1)*k//2+1
    r=(n+n-i+1)*i//2-(i-1)*i//2+1
    r%=mo
    ans+=r
    #show(i,r)


print(ans%mo)

Submission status: Accepted

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

ans = 0
for i in range(k, n+2):
    bot = n+1-i
    ans += bot*i+1
    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=(ans+i*n-i*(i-1)+1)%mod
print(ans%mod)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

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

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7

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

for i in range(k, n + 2):
    MIN = (i * (i - 1))//2
    MAX = (n * i) - MIN
    out += MAX - MIN + 1
    out %= MOD
print(out)

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-i+1)*i+1
    ans%=mod
print(ans)

Submission status: Runtime Error

Solution code:


def main():
    mod = 10 ** 9 + 7
    cnt = 0
    for i in range(k, n+2):
        l = (i-1)*i//2
        h = (n+n-i+1)*i//2
        cnt += h - l + 1
    print(cnt % mod)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,k = map(int, input().split())
    n += 1
    l = [i for i in range(n)]
    L = [0]
    for i in range(1,n):
        L.append(L[i-1] + l[i])
    ans = 0
    for i in range(k, n):
        mi = L[i-1]
        ma = L[-1] - L[len(L)-i-1]
        ans += (ma-mi+1)
    ans += 1
    print(ans)

if __name__=="__main__":
    main()
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,k = map(int, input().split())
    n += 1
    l = [i for i in range(n)]
    L = [0]
    for i in range(1,n):
        L.append(L[i-1] + l[i])
    ans = 0
    for i in range(k, n):
        mi = L[i-1]
        ma = L[-1] - L[len(L)-i-1]
        ans += (ma-mi+1)
    ans += 1
    print(ans)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
mod=10**9+7
x=[0]+[0]
for i in range(1,2*10**5):
  x.append((x[-1]+i)%mod)

ans=0


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


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

Submission status: Runtime Error

Solution code:
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {

    private static final int MOD = (int)1e9 + 7; //998244353;
    private static final long INF = (long)1e18;

    public Main(FastScanner in, PrintWriter out) {
        long N = in.nextLong();
        long K = in.nextLong();

        long res = 0;
        long first = (K - 1) * K / 2;
        long last = (2 * N - K + 1) * K / 2;
        for (long i = K - 1, j = N - K + 1; i <= N; i++, j--) {
            res += last - first + 1;
            res %= MOD;
            first += i + 1;
            last += j - 1;
        }
        out.println(res);
    }

    private long gcd(long a, long b) {
        while (true) {
            if (b == 0) return a;
            long tmp = a;
            a = b;
            b = tmp % b;
        }
    }

    private long pow(long x, long p) {
        long res = 1;
        while (p > 0) {
            if (p % 2 == 1)
                res = res * x % MOD;
            x = x * x % MOD;
            p /= 2;
        }
        return res;
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        Main sol = new Main(in, out);

        out.close();
    }
}

// Pair
class Pair<T extends Comparable<? super T>, U extends Comparable<? super U>> implements Comparable<Pair<T, U>> {
    T a;
    U b;
    Pair() { }
    Pair(T a, U b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public String toString() { return "("+a.toString()+", "+b.toString()+")"; }

    @Override
    public int hashCode() { return Objects.hash(a, b); }

    @Override
    public boolean equals(Object obj) {
        if(this == obj) return true;
        if(obj == null) return false;
        if(this.getClass() != obj.getClass()) return false;
        Pair that = (Pair) obj;
        if(this.a.getClass() != that.a.getClass()) return false;
        if(this.b.getClass() != that.b.getClass()) return false;
        if(!this.a.equals(that.a)) return false;
        if(!this.b.equals(that.b)) return false;
        return true;
    }

    @Override
    public int compareTo(Pair<T, U> that) {
        int c = (this.a).compareTo(that.a);
        if(c == 0) c = (this.b).compareTo(that.b);
        return c;
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}

Submission status: Runtime Error

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, a, b = map(int, readline().rstrip().split())
    mod = 10 ** 9 + 7

    ans = pow(2, n, mod) - 1

    nca, ncb = 1, 1

    for i in range(b):
        ncb = ncb * (n - i) % mod
        ncb *= pow(i + 1, mod - 2, mod)
        if i + 1 == a:
            nca = ncb

    print((ans - (nca + ncb)) % mod)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Submission status: Runtime Error

Solution code:
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)
    print(len(S))

Submission status: Runtime Error

Solution code:
# 初期入力
NN,K = (int(x) for x in input().split())

#K個の和、初項と修項
p =10**9 + 7
seq =[i for i in range(NN+1)] #0-Nまでの数列
ans =[0] *NN
st =[0]*NN
fi =[0]*NN
st[0] =sum(seq[  :K])
fi[0] =sum(seq[-K: ])
ans[0] =fi[0] -st[0] +1
if NN==1:
    print(ans[0])
else:
    for i in range(NN -K+1):
        st[i+1] =st[i] +seq[K+i]
        fi[i+1] =fi[i] +seq[-K-i-1]
        ans.append(fi[i+1] -st[i+1] +1)
    print(sum(ans) %p)

Submission status: Runtime Error

Solution code:
# 初期入力
NN,K = (int(x) for x in input().split())

#K個の和、初項と修項
p =10**9 + 7
seq =[i for i in range(NN+1)] #0-Nまでの数列
ans =[0] *NN
st =[0]*NN
fi =[0]*NN
st[0] =sum(seq[  :K])
fi[0] =sum(seq[-K: ])
ans[0] =fi[0] -st[0] +1
for i in range(NN -K+1):
    st[i+1] =st[i] +seq[K+i]
    fi[i+1] =fi[i] +seq[-K-i-1]
    ans.append(fi[i+1] -st[i+1] +1)
print(sum(ans) %p)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=[]
for i in range(n+1):
  a=(10**100+i)%(10**9+7)
  l.append(a)

r=[0]*(n+1)
for j in range(n):
r[j+1]=r[j]+l[j]

s={}
for a in range(1,n-k+1):
  ss=r[a+k-1]-r[a-1]
  a.add(ss)
print(len(s))

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
s = 10**100 + sum(1,n)

print(divmod(10**9+7)

Submission status: Runtime Error

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

for i in range(k, n+2):
  a = 0.5* i* (i-1)
  b = 0.5* n* (n+1) - 0.5* (n-i)* (n-i+1)
  ans += int(b-a+1)
  
print(ans%(10**9+7)

Submission status: Runtime Error

Solution code:
def sum_part(N, k):
  return k*(2*N-k+1)/2-k*(k-1)/2+1
  
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2)
  ans += sum_part(N, k)
  
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

ans = 0

for k in range(K, N):
  ans += len(set(map(sum, itertools.combinations(range(N), k))))

print(ans%(10000000000+7)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools
from collections import defaultdict
mod = (10**9)+7

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

total=0
for k in range(K,N+2):
  d = defaultdict(int)
  for v in itertools.combinations(a,k):
    print(v)
    if d[sum(list(v))]==0:
      d[sum(list(v))] = 1
  total+=sum(d.values())

result=total % mod 
print(result)

Submission status: Runtime Error

Solution code:
import itertools
from collections import defaultdict
mod = (10**9)+7

N,K=map(int,input().split())
a=[i for i in range(N)]
d = defaultdict(int)

for k in range(K,N+2):
  for v in itertools.permutations(a,k):
    if d[sum(list(v))]>0:
      d[sum(v)] = 1
      
result=sum(d.values) % mod 
print(result)

Submission status: Runtime Error

Solution code:
import itertools
from collections import defaultdict

N,K=map(int,input().split())
a=[i for i in range(N)]
d = defaultdict(int)

for k in range(K,N+2):
  for v in itertools.permutations(a,k):
    if d[sum(list(v))]>0:
      d[sum(v)] = 1
print(sum(d.values))

Submission status: Runtime Error

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

ans = 0
for i in range(n-k+1):
    ans += math.factorial(n+1)/math.factorial(k+i)/math.factorial(n+1-k-i)

print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    small = 0
    large = 0
    ans = 0
    for i in range(0, n+1):
        small += i
        large += n-i
        if i+1 >= k:
            ans = (ans + (large - small + 1)) % mod
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools

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

    num = 10*100
    nums = [num + i for i in range(0, n+1)]

    sums = []
    for i in range(k, n+2):
        for v in itertools.combinations(nums, i):
            sums.append(v)

    totals = []
    for s in sums:
        totals.append(sum(s))

    totals = set(totals)
    print(len(totals))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import itertools
N, K = map(int, input().split())
n = np.array([])
n_list = [10**100 + i for i in range(N + 1)]
lists = []
for i in range(K, N + 2):
  for j in itertools.combinations(n_list, i):
    if sum(j) not in lists:
      lists.append(sum(j))
print(len(lists) % (10**9 + 7))

Submission status: Runtime Error

Solution code:
import numpy as np

x = int(input())
l = [0] * x
A = list(map(int, input().split()))

for num in range(x-1):
    l[A[0]-1] += 1

for i in range(x):
    print(l[i])

Submission status: Runtime Error

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

count = 0
for i in range(K,N+1):
  min = sum(0:i)
  max = sum(N:N-i+1:-1)
  count += max - min + 1
print(count)

Submission status: Runtime Error

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

ans=[0]*n

for i in l:
    ans[i-1]+=1

for j in ans:
    print(j)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
q

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
rom math import factorial
m = 10**9 + 7
  
def comb(n,k,p):
  if n<0 or k<0 or n<k: return 0
  if n is 0 or k is 0: return 1
  a=factorial(n) % p
  b=factorial(k) % p
  c=factorial(n - k) % p
  return (a * power(b, p - 2, p)*power(c, p-2, p)) % p
def power(a, b, p):
  if b == 0: return 1
  if b % 2 == 0:
    d = power(a, b // 2, p)
    return d * d % p
  if b % 2 == 1:
    return (a * power(a,b-1,p)) % p

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

if n <= k:
  pattern = 1
else:
  pattern = 0
  for num in range(k,n+1,1):
      pattern += comb(n+1, num, m)

print(pattern)

Submission status: Runtime Error

Solution code:
import itertools
 
n, m = list(map(int, input().split(" ")))
l = [ i for i in range(n + 1) ]
 
print(l[n:m] -  [0:n] )

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
l = len(S)

a = 0
count = 0

for i in range(l):
    a = int(S[l-i-1])
    for j in range(i+1,l):
        if int(S[l-j-1]) != 0:
            a += int(S[l-j-1])*10**(j-i)
            if j-i > 2:
                if a % 2019 == 0:
                    count += 1
            
print(count)

Submission status: Runtime Error

Solution code:
N = str(input())

#N = str(14282668646)

count = 0
lenN = len(N)+1
for i in range(0, lenN):
#    t = i
    for j in range(i+5, i+8):
#        print (i, j)
        number = int(str(N[i:j]))
        if number%2019 == 0:
            count +=1
            break


print (count)

Submission status: Runtime Error

Solution code:
N = str(input())

#N = str(14282668646)

count = 0
lenN = len(N)+1
for i in range(0, lenN):
#    t = i
    for j in range(i+5, i+8):
#        print (i, j)
        number = int(str(N[i:j]))
#        if number%2019 == 0:
#            count +=1
#            break
#            print (i, j)
#T = int(N)//2019
#
#for t in range (T):
#    den = 2019*t
#    length = len(str(den))
#    sum_length = len(N)
#    for i in range(sum_length-length):
#        if den == int(N[i:i+length]):
#            count +=1

print (count

Submission status: Runtime Error

Solution code:
def check(s,i,c):
    if i >= len(s):
        return c
    if int(s[i:i+4]) % 2019 == 0:
        c += 1
        return check(s,i+4,c)
    elif len(str(int(s[i:i+5]))) == 5 and int(s[i:i+5]) % 2019 == 0 and int(s[i:i+5])!= int(s[i:i+4]):
        c += 1
        return check(s,i+5,c)
    else:
        return c

s = input()
cnt = 0
li = []
for i in range(0,len(s)-3):
    a = int(s[i:i+4])
    b = int(s[i:i+5])
    if a % 2019 == 0:
        cnt += 1
        cnt += check(s,i+4,0)
    if b % 2019 == 0 and len(str(b)) ==5:
        cnt += 1
        cnt += check(s,i+5,0)
print(cnt)

Submission status: Runtime Error

Solution code:
S = input()
ans = 0
for j in range(3,len(S)):
    for i in range(j-2):
        if int(S[i:j+1])%2019 == 0:
            ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
# 今回は、等差数列の和の差をとって、


def calc(x):
    a = x * (x - 1) // 2
    b = (2 N - x + 1) * x // 2
    return a - b + 1


for i in range(K, N + 2):
    ans = calc(i)
    tot = +=ans

tot /= 10 ** 9 + 7

print(tot)

Submission status: Runtime Error

Solution code:
import math

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
total=0
while N+1 <= K:
  base = comb(N+1,K)
  total += base
  K+=1

print(total)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7

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

k = np.arange(K, N + 2, dtype=np.int64)
low = (k - 1) * k // 2
high = N * k - low
cnt = high - low + 1
print(cnt.sum() % MOD)

Submission status: Runtime Error

Solution code:
import math

def fac(x):
    if x<=1:
        return 1
    s=1
    for i in range(1,x+1):
        s=s*i
    return s
def com(m,n):
    return fac(m)/(fac(n)*fac(m-n))

temps=input().split()
n=int(temps[0])
m=int(temps[1])
sum=0
for i in range(m,n+1):
    sum=sum+com(n+1,i)
print(int(sum%(math.pow(10,9)+7)))

Submission status: Runtime Error

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

    wa=max-min+wa
    
print(wa)

Submission status: Runtime Error

Solution code:
import math

N, K = map(int, input().split())
ans = 0
for i in range(K, N+1):
    ans += (math.factorial(N+1) // (math.factorial(i) * math.factorial(N+1-i)))%(1e9+7)


print(int(ans))

Submission status: Runtime Error

Solution code:
#タプルを深くしたまま進め、速度アップ？
#初期入力
import sys
input = sys.stdin.readline
S = input().split()
S=S[0]
Q = int(input())
FQ_dic =tuple()
rev =0
for i in range(Q):
    FQ_dic =tuple(input().split())

    if      FQ_dic[0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし  
        if      FQ_dic[1]=="1":     #後ろにつける
            if rev %2 ==0:
                    S = FQ_dic[2] , S
            else:
                    S = S ,FQ_dic[2] 
        else: #                      #前につける
            if rev %2 ==0:
                    S = S , FQ_dic[2]
            else:        
                    S = FQ_dic[2] , S

#深いパックをアンパック
def flatten_list_tuple_range(l):
    for el in l:
        if isinstance(el, (list, tuple, range)):
            yield from flatten_list_tuple_range(el)
        else:
            yield el
S =flatten_list_tuple_range(S)
S=[i for i in S]

#逆転の回数で場合分け
if rev %2 ==0:
    print(*S,sep="")
else:
    print(*S[::-1],sep="")

Submission status: Runtime Error

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