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: Time Limit Exceeded

Solution code:
import math,itertools
a,b = [int(i) for i in input().split(" ")]
lim = 10**9 + 7
res = range(0,a+1)
count = 0

for i in range(b,a+2):
    fact_list = set([sum(j) for j in list(itertools.combinations(res,i))])
    #print(D)
    count += (len(fact_list) % lim)

print(count % lim)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

sm = 0
l = list(range(N+1))
ans = list()
for a in range(K, N+2):
    sm_list = list(combinations(l, a))
    for b in range(0, len(sm_list)):
        sm_list[b] = sum(sm_list[b])
    ans += list(set(sm_list))


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

Submission status: Time Limit Exceeded

Solution code:
mod = 10 ** 9 + 7
def main():
    n, k = map(int,input().split())
    lis = [i for i in range(n + 1)]
    res = 0
    for i in range(k, n + 2):
        res += (sum(lis[-i:]) - sum(lis[:i]) + 1)
        res %= mod
    print(res)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int, input().split()))
totalmin = [] # N+1個 totalmin[0 ~ N]
totalmax = [] # N+1個 totalmax[0 ~ N]
num = [] # N+1個 num[0 ~ N]
ans = 0
for i in range(N+1):
  num.append(i)
for i in range(N+1):
  tempmin = 0
  tempmax = 0
  for j in range(i):
    tempmin += num[j]
    tempmax += num[N-j]
  totalmin.append(tempmin)
  totalmax.append(tempmax)
for i in range(K, N+1):
  ans += totalmax[i] - totalmin[i] + 1
print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
s=1
lis=list(range(N+1))
for i in range(K,N+1):
    # print(lis[i:])
    # print(lis[:i])
    s+=(sum(lis[-i:])-sum(lis[:i])+1)
# print(s)
print(s%(pow(10,9)+7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

mod=1e9+7

l=list()
for i in range(n+1):
    l.append(i)

ans=0
tmpl=list()
for i in range(k,len(l)+1):
    for j in list(itertools.combinations(l,i)):
        tmpl.append(sum(j))
    ans+=len(set(tmpl))%mod
    tmpl.clear()

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
list = input().split()
N = int(list[0])
K = int(list[1])
i = K
s = 0

def sum(a,b):
    i=0
    for p in range (b-a+1):
        i += a + p
    return i

while i <= N + 1:
    #print(sum(N-i+1,N) + sum(0,i-1))
    s = s + sum(N-i+1,N) - sum(0,i-1) + 1
    i += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
import math,itertools
a,b = [int(i) for i in input().split(" ")]
lim = 10**9 + 7
res = range(0,a+1)
count = 0

for i in range(b,a+2):
    fact_list = set([sum(j) for j in list(itertools.combinations(res,i))])
    #print(D)
    count += len(fact_list)

print(count % lim)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = list()
B = list()
x = 0
A = [2**100+i for i in range(N+1)]
for i in range(K, N+2):
    a = itertools.combinations(A,i)
    for s in a:
        B.append(sum(s))
print(len(list(set(B)))%(10**9+7))

Submission status: Time Limit Exceeded

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

ans = 0
while n+1 - k >= 0:
    low = 0
    high = 0
    for i in range(k):
        low += i
        high += (n-i)
    cnt = high - low + 1
    ans += cnt
    ans %= 10**9 + 7
    k += 1

print(str(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
l = [_ for _ in range(n + 1)]

from itertools import combinations

x = []
y = []
z = 0
for i in range(k, n+2):
    x = list(combinations(l, i))
    for j in range(len(x)):
        y.append(sum(x[j]))
    z += len(set(y)) % (10**9+7)
    x,y = [],[]

print(z)

Submission status: Time Limit Exceeded

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

Ns = list(range(N+1))

sum_ = 0

for k in range(K, N+2):
    min_idx = sum(Ns[:k])
    max_idx = sum(Ns[-k:])
    sum_ += max_idx - min_idx + 1

print(sum_)

Submission status: Time Limit Exceeded

Solution code:
import math,itertools
a,b = [int(i) for i in input().split(" ")]
lim = 10**9 + 7
res = range(0,a+1)
count = 0

for i in range(b,a+2):
    D  = set([])
    fact_list = itertools.combinations(res,i)
    #print(list(fact_list))
    for j in fact_list:
        result = sum(list(j))
        D.add(result)
    #print(D)
    count += len(D)

print(count % lim)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k, n+2):
  ans += sum(s[:i]) - sum(l[:i]) +1
  
print(ans%(int(1e9)+7))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
mod=(10**9+7)
n+=1
N=[_ for _ in range(0,n)]
C=set([])
ans=0
for i in range(2**n):
   B=[0]*n
   for j in range(n):
      if i>>j&1:
         B[j]=1
   score=[x * y for (x, y) in zip(N, B)]
   num=sum(score)
   jou=sum(B)
   if jou>=k:
       if (num,jou) not in C:
           C.add((num,jou))
           ans+=1       

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

N, K = map(int, input().split())
mod = 10**9 + 7
A = list(range(N+1))
out = 0
for i in range(N+1, K-1, -1):
  B = list(itertools.combinations(A, i))
  C = [sum(b) for b in B]
  out += len(collections.Counter(C))
print(out)

Submission status: Time Limit Exceeded

Solution code:
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


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


# main
n, k = mis()

if n+1 == k:
    print('1')
    exit(0)

comb = 0

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

print(comb)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
#xは求める場合の数
x=0
for i in range(k,n+2):
  #ｙはi-1までの和
  y=0
  for j in range(i):
    y+=j
  x+=((i*n-2*y+1)%(10**9+7))
print(x)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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


a = [combinations(range(0, N + 1), i) for i in range(K, N + 2)]

print(sum([len(set([sum(c) for c in b])) for b in a]))

Submission status: Time Limit Exceeded

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

from sys import stdin
import itertools


def main():
    N, K = map(int, stdin.readline().split())
    a = list(range(0, N + 1))
    pattern = []
    for i in range(K, N + 2):
        pattern.extend(list(itertools.combinations(a, i)) )

    b = []
    for p in pattern:
        val = (10 ^ 100) * len(p) + sum(p)
        b.append(val % (10 ^ 9 + 7))
    print(len(set(b)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def nCr(n,r):
    if r*2>n:
        return nCr(n,n-r)
    mod = 10 ** 9 + 7
    a = b = 1
    for i in range(r):
        a = (a * (n - i)) % mod
        b = (b * (r - i)) % mod
    return (a * pow(b,mod-2,mod))%mod

N,K = map(int,input().split())
cnt = 0
tmp = [i for i in range(N+1)]
for i in range(K,N+2):
    cnt += sum(tmp[-i:])-sum(tmp[:i])+1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


n, k = map(int, input().split())
nums = list(range(1, n+1)) + [0.5]


def loop(nums):
    combi = set()
    for i in range(k, n+2):
        combi |= set(map(sum, combinations(nums, r=i)))
    return len(combi)


print(loop(nums))

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
n,k = map(int, input().split())
n += 1
count = 0
def combination(n,r):
    ls = []
    tmp_list = []
    ls =  list(itertools.combinations(range(n),r))
    for l in ls:
        tmp_list.append(str(len(l))+str(sum(l)))
    return len(set(tmp_list))
for i in range(k,n+1):
    count += combination(n,i)
print(count % 1000000007)

Submission status: Time Limit Exceeded

Solution code:
class Mint:
    
    MOD = 10**9+7
    
    def __init__(self, x=0):
        self.x = (x%self.MOD + self.MOD) % self.MOD
    
    def __iadd__(self, other):
        self.x += other.x
        if self.x >= self.MOD:
            self.x -= self.MOD
        return self
    
    def __isub__(self, other):
        self.x += self.MOD - other.x
        if (self.x >= self.MOD):
            self.x -= self.MOD
        return self
    
    def __imul__(self, other):
        self.x *= other.x
        self.x %= self.MOD;
        return self;
    
    def __add__(self, other):
        ans = Mint(self.x)
        ans += other
        return ans
        
    def __sub__(self, other):
        ans = Mint(self.x)
        ans -= other
        return ans
    
    def __mul__(self, other):
        ans = Mint(self.x)
        ans *= other
        return ans
    
    def __pow__(self, n):
        if n == 0:
            return Mint(1)
        a = self.__pow__(n >> 1)
        a *= a
        if n&1:
            a *= self
        return a
    
    def inv(self):
        return self**(self.MOD-2)
    
    def __ifloordiv__(self, other):
        self *= other.inv()
        return self
    
    def __floordiv__(self, other):
        ans = Mint(self.x)
        ans //= other
        return ans
        

    
def Main(N, K):
    ans = Mint(0)
    for i in range(K, N+2):
        low = ((Mint(0)+Mint(i-1))*Mint(i))//Mint(2)
        high =((Mint(N)+Mint(N-i+1))*Mint(i))//Mint(2)
        ans += high - low + Mint(1)
    return ans.x

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

CalcList = tuple(range(int(K), int(N)+2))

#print(CalcList)

ans = 0

for i in CalcList:
    tmp = 0
    min = sum(range(0,i))
#    print(min)
    max = i * int(N) -min
#    print(max)

    tmp = max - min +1
    ans += tmp

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

Submission status: Time Limit Exceeded

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

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


mod = 10**100 + 7  # 出力の制限
N = 10**7
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)


s = 0
for i in range(k, n + 2):
    s += cmb(n + 1,i,mod)
    
print(s%(10**9+7)-1)

Submission status: Time Limit Exceeded

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

import itertools

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

    n_li = list(range(n+1))

    ans = 0

    for i in range(k, n+2):
        ans += len(set(map(sum, itertools.combinations(n_li,i))))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l=list()
for i in range(n+1):
    l.append(i)

ans=0
tmpl=list()
for i in range(k,len(l)+1):
    for j in list(itertools.combinations(l,i)):
        tmpl.append(sum(j))
    ans+=len(set(tmpl))
    tmpl.clear()

print(ans)

Submission status: Time Limit Exceeded

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

#intの場合
L, K = map(int,input().split())

List = [0] * (L+1)
ans = set()

for a in range(L+1):
  List[a] = 1j + a

for x in range(K,L+1):
   for y in itertools.combinations(List, x):
      ans.add(sum (y))

print (len(ans)+1)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import sys
n, k = map(int, sys.stdin.readline().split())

lst = {i for i in range(0, n+1)}
re = 0
for i in range(k, n+1):
    temp = set(combinations(lst, i))
    tt = {sum(j) for j in temp}
    re += len(tt)

print(re+1)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def solution():
    n, k = map(int, input().split())
    candidates = [10 ** 8 + i for i in range(n+1)]
    ans = 0
    for i in range(k, n+2):
        a = set([sum(b) for b in list(itertools.combinations(candidates, i))])
        ans += len(a)
    ans %= 10**9 + 7
    print(ans)

solution()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n, k = map(int, open(0).read().split())

length = n + 1

total = 0
seq = range(1, length+1)
for i in range(k, length+1):
    pat = list(combinations(seq, i))
    #print(pat)
    
    sums = set()
    for x in pat:
        sums.add(sum(x))
    
    #print(sums)
    total += len(sums)    

print(total)

Submission status: Time Limit Exceeded

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

CalcList = list(range(int(K), int(N)+2))

#print(CalcList)

ans = 0

for i in CalcList:
    tmp = 0
    min = sum(range(0,i))
#    print(min)
    max = i * int(N) -min
#    print(max)

    tmp = max - min +1
    ans += tmp

print(ans % 1000000007)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(k, n+2):
  ans += sum(s[:i]) - sum(l[:i]) +1
  
print(ans%(int(1e9)+7))

Submission status: Time Limit Exceeded

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

import itertools

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

    n_li = list(range(n+1))

    ans = 0

    for i in range(k, n+2):
        ans += len(set(map(sum, list(itertools.combinations(n_li,i)))))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
  n, k = map(int,input().split())
  result = 0
  for i in range(k, n+2):
    max = 0
    min = 0
    for j in range(i):
      max += (n-j)
      min += j
    
    result += (max-min+1)
    
  return result

if __name__ == '__main__':
  print(main())

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
lst = list(range(0,N+1))
cnt = 0
for i in range(K,N+1):
    start = sum(lst[:i])
    end = sum(lst[-i:])
    cnt += end - start + 1
cnt += 1    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

lst = {i for i in range(0, n+1)}
re = 0
for i in range(k, n+1):
    temp = set(combinations(lst, i))
    tt = {sum(j) for j in temp}
    re += len(tt)

print(re+1)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

n_li = list(range(n+1))

ans = 0

for i in range(k, n+2):
  ans += len(set(list(map(sum, list(itertools.combinations(n_li,i))))))

print(ans)

Submission status: Time Limit Exceeded

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

result = 0
mod = 10 ** 9 + 7

for i in range(K, N + 2):
    first = 0
    second = 0
    for j in range(i):
        first += j
        second += N - j
    result = (result + second - first + 1) % mod

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()

# dp = list(set(sum(n) for n in combinations(range(0, N + 1), K))) # K個選んだときの和の組み合わせ
# for k in range(K+1, N+2):
#     dp = dp + list(set(sum(n) for n in combinations(range(0, N + 1), k)))

# return
# nums = []
count = 0
for num_nums in range(K, N + 2):
    tmp_nums = []
    for n in combinations(range(0, N + 1), num_nums):
        s = sum(n)
        if s not in tmp_nums:
            tmp_nums.append(s)
    count += len(tmp_nums)
    # for i in tmp_nums:
    #     nums.append((num_nums, i))
# print(len(nums))
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
total = 0
for i in range(k, n + 2):
    total += sum(range(n - i + 1, -~n)) - sum(range(i)) + 1
print(int(total % (1e9 + 7)))

Submission status: Time Limit Exceeded

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

import itertools

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

    n_li = list(range(n+1))

    ans = 0

    for i in range(k, n+2):
        ans += len(set(list(map(sum, list(itertools.combinations(n_li,i))))))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    import itertools
    import numpy as np
    ln=range(N+1)
    ans=0
    for i in range(K,N+2):
        l=np.array(list(itertools.combinations(ln, i)))
        ans+=len(set(l.sum(axis=1)))
    
    print(int(ans%(10**9+7)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = [int(n) for n in input().split()]
div = 10**9+7
ans = []
for k in range(K, N+2):
    ans += [(k*10**100+sum(c))%div for c in combinations(range(N+1), k)]
print(len(set(ans)))

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(n - k + 2):
    buf_max = sum(list(range(n, -1, -1)[:i + k:]))
    buf_min = sum(list(range(n + 1)[:i + k:]))
    cnt += buf_max - buf_min + 1

cnt  = cnt % (10**9 + 7)

print(cnt)

Submission status: Time Limit Exceeded

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

l = list(range(n+1))
cnt = 0
for i in range(k,n+1):
    s = []
    for v in itertools.combinations(l,i):
        a = sum(v)
        if not a in s:
            s.append(a)
            cnt+=1
print((cnt+1)%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,K = map(int, input().split())
nums = range(0,N+1)
sums = []
ans = 0

for i in range(K,N+2):
  cbs = list(itertools.combinations(nums,i))
  for l in cbs:
    sm = sum(l)
    if not sm in sums:
      sums.append(sm)
      #print(sm)
  ans += len(sums)
  sums = []
#
print(ans)

Submission status: Time Limit Exceeded

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

@author: arute
"""


from sys import stdin

import time
import numpy as np
import math



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

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

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

# すべての場合の数を計算。
probs = 0

for m in range(M,N+2):
    # 作れる最小は？
    small = sum(range(m))
    #
    large = sum(range(N+1-m,N+1))
    
    probs += large - small + 1
# 重複を計算し除去

print(probs)

Submission status: Time Limit Exceeded

Solution code:
N,K = list(map(int , input().split()))
S = []
M = 0
for i in range(N+1):
    S.append(i)
for j in range (N-K+2):
    Min_sum = sum(S[:(j+K)])
    Max_sum = sum(S[-(j+K):])
    M += (Max_sum - Min_sum +1)
print(M)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = map(int, input().split())
l = [x+200001 for x in range(N+1)]

result_list = [sum(number_pair) for k in range(K, N+2) for number_pair in combinations(l, k)]

print(len(set(result_list)))

Submission status: Time Limit Exceeded

Solution code:

n,k = map(int, input().split())
b = []
for i in range(0,n+1):
    b.append(i)
ans =  0
count = 0
for i in range(k,n+2):
    c = sum(b[0:i])
    d = sum(b[-i:])
    count +=1
    ans += d-c
ans += count
print(ans % (10 ** 9 +7))

Submission status: Time Limit Exceeded

Solution code:
#D
a = input().split()
n = int(a[0]) +1
m = int(a[1])

N_list =[i for i in range(n) ]
N_list_rev = [i for i in range(n) ]
N_list_rev.reverse()
s = 0
for i in range(n-m+1):
    s += sum(N_list[i:]) -sum(N_list_rev[i:]) +1

print(s)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()

# 和があればTrue
# dp = [False] * ((N + 1) * N // 2 + 1)
dp = defaultdict(int)

# for k in range(N + 1, K - 1, -1):
q = [[10 ** 10 + i for i in range(0, N + 1)]]
# print(q)
while q:
    a = q.pop()
    # print(a)
    s = sum(a)
    # print(a)
    # print(s)
    dp[s] = True
    if len(a) > K:
        # K より大きければ続ける
        for i in range(len(a)):
            b = deepcopy(a)
            b.pop(i)
            q.append(b)
# print(sum(dp) % mod)
print(len(dp) % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def sumall(a,b):
  s=0
  while a<=b:
    s=s+a
    a+=1
  return s
ans=0
while k <= n+1:
  ans += sumall(n-k+1, n)-int((k-1)*k/2)+1
  k+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    inf = 10**9 + 7
    N, K = map(int, input().split())

    L = []
    # N+1個からK個以上の数を選ぶ
    for i in range(N+1):
        L.append(i)

    # for team in itertools.combinations(L, 2):
    #     print(team)

    # def combinations_count(n, r):
    #     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
    ans = []
    r_append = ans.append
    for i in range(K, N+2):
        for team in itertools.combinations(L, i):
            r_append(sum(team)+(10*i))

    print(len(list(set(ans)))%inf)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
mod = 10 ** 9 + 7
premin = 0
premax = 0
ans = 0
list = [i for i in range(n + 1)]
for x in range(n + 2):
    if x < k: continue
    premin = sum(list[0 : x])
    premax = sum(list[n + 1 - x : n + 1])
    ans += (premax - premin + 1)
    if ans >= mod: ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def comb(lis, k):
    l_sum = [sum(pair) for pair in itertools.combinations(lis, k)]
    return len(set(l_sum))
    
n, k = map(int, input().split())
ans = 0
l = [i for i in range(n+1)]
for i in range(k, n+2):
    ans += comb(l, i)
    
mod = 10 ** 9 + 7
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import Counter
n, k = map(int, input().split())
As = list(range(n+1))
s = 0
for i in range(k, n+2):
	l = Counter(list(map(sum, combinations(As, i))))
	s+=len(l)%(10**9+7)
print(s%(10**9+7))

Submission status: Time Limit Exceeded

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


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

mod = 10**9+7 #出力の制限
N = 10**100
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

lst = {i for i in range(0, n+1)}
re = 0
for i in range(k, n+2):
    temp = set(combinations(lst, i))
    tt = {sum(j) for j in temp}
    re += len(tt)

print(re)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def readInt():
    return list(map(int,input().split()))
n, k = readInt()
ans = 0
l = [int(x) for x in range(n+1)]
for i in range(k,n+2):
    # print(i, ".")
    c_l = list(itertools.combinations(l,i))
    a = []
    for j in range(len(c_l)):
        # print(sum(c_l[j]))
        a.append(sum(c_l[j]))
        # print(a)
    # print(a)
    # print(set(a))
    # print(c_l)
    ans += len(set(a))
print(ans)

Submission status: Time Limit Exceeded

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


tmp = []
mod = 1000000007

for i in range(0, N+1):
    tmp.append(((10 ** 100) +i) % mod)
ans = []

def comb(l, n):
    for v in itertools.combinations(l, n):
        ans.append(sum(v))
    
for x in range(K, N+1):
    comb(tmp, x)

ans_num = len(set(ans))+ 1

print(ans_num)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(M,N+2): #M~N+1までやる
    min=sum(list(range(0,i)))
    max=sum(list(range(N+1-i,N+1)))

    ans+=max-min+1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

list = []

for i in range(n+1):
    list.append(i)

sum = 0

for j in range(m,n+2):
    mini = 0
    big = 0
    for k in range(j):
        mini += list[k]
        big += list[len(list)-k-1]
    sum += (big-mini+1)

print(sum)

Submission status: Time Limit Exceeded

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

Ns = []
for n in range(N+1):
    Ns.append(n)

# print(Ns)

ans = set()
for k in range(K, N+2):
    nums = itertools.combinations(Ns, k)
    # print(list(nums))
    for num in nums:
        tmp = f'{str(sum(list(num)))} + {str(k)}'
        ans.add(tmp)
print((len(ans)))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
p = 10 ** 9 + 7
N = 10 ** 7  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

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

# ②事前計算した項を掛け合わせ
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
print(cmb(n,k,p))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = range(n + 1)

a = 0

for i in range(k, n + 2):
    p = itertools.permutations(l, i)
    a += len(set(list(map(sum, p))))

print(a)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N, K = tuple(map(int, input().split()))
count = 0
list_N = [i for i in range(N+1)]
for l in range(K, N+2):
    x = list(combinations(list_N, l))
    #print(x)
    #print(len(x))
    #print(x[0])
    #print(sum(x[0]))
    sum_ = []
    for i in range(len(x)):
        t = sum(x[i])
        sum_.append(t)
    sum_set = set(sum_)
    count += len(sum_set)
print(count)

Submission status: Time Limit Exceeded

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

if n + 1 == k:
    print(1)
    exit()

n_list = [i for i in range(n+1)]
ans = 0
for i in range(k, n+2): 
    min_num = sum(n_list[:i])
    max_num = sum(n_list[-i:])
    ans += (max_num - min_num + 1)
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter
N, K = map(int, input().split())
MOD = 10**9 + 7
pluse = 10**10
n = []
comb_list = []
for i in range(N+1):
    n.append(pluse+i)
for i in range(K,N+2):
    tmp = list(itertools.combinations(n,i))
    for j in range(len(tmp)):
        comb_list.append(sum(tmp[j]))
# print(comb_list)
counter = Counter(comb_list)
print(len(counter.values())%MOD)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7

def start(a):
    num = 0
    for i in range(1, a):
        num += i
    return num

def end(m, b):
    num = 0
    for i in range(n, n-b, -1):
        num += i
    return num

n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    s = start(i)
    e = end(n, i)
    cnt = e-s+1
    ans = ans + cnt
    ans %= MOD
print(ans)