Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N, M = makeMultiInteger(input_string[0])
    S = makeIntMatrix(input_string[1:])
    c = 0
    ra = range(1, N+1)
        
    min_range = ra
    for s in S:
        l = s[0]
        r = s[1]
        if l >= min_range[0]:
            min_l = l
        if r <= min_range[-1]:
            min_r = r
        min_range = range(min_l, min_r+1)
    #print(min_range)
    if ra[-1] > min_range[-1]:
        return len(min_range)
    else:
        return len(ra)



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N, M = makeMultiInteger(input_string[0])
    S = makeIntMatrix(input_string[1:])
    c = 0
    ra = range(1, N+1)
        
    min_range = ra
    min_l = ra[0]
    min_r = ra[-1]
    for s in S:
        l = s[0]
        r = s[1]
        if l > min_range[0]:
            min_l = l
        if r < min_range[-1]:
            min_r = r
        min_range = range(min_l, min_r+1)
        if len(min_range) == 0:
            return 0
    #if ra[-1] >= min_range[-1]:
    return len(min_range)
    #else:
    #    return len(ra)



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                if cost < min_cost:
                    min_cost = cost
    return min_cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                return cost
    return cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from sys import stdin


def b(input_string):
    a, b, k = [int(x) for x in input_string.split()]
    mod_0_numbers = []
    if a >= b:
        for i in range(1, a):
            if a % i == 0:
                if b % i == 0:
                    mod_0_numbers.append(i)
    else:
        for i in range(1, b):
            if b % i == 0:
                if a % i == 0:
                    mod_0_numbers.append(i)
    return mod_0_numbers[-k]


def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def b(input_string):
    a, b, k = [int(x) for x in input_string.split()]
    mod_0_numbers = []
    if a >= b:
        for i in range(1, a+1):
            if a % i == 0:
                if b % i == 0:
                    mod_0_numbers.append(i)
    else:
        for i in range(1, b+1):
            if b % i == 0:
                if a % i == 0:
                    mod_0_numbers.append(i)
    return mod_0_numbers[-k]


def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def b(input_string):
    _s = input_string
    s_length = len(_s)
    s = []
    for i in range(s_length):
        s.append(_s[i])
    #print(_s)
    #print(s)
    count = 0
    flag = True
    while flag and len(s) >= 2:
        flag = False
        for i in range(s_length):
            if i < len(s)-1:
                if s[i] != s[i+1]:
                    s.pop(i)
                    #print(s)
                    s.pop(i)
                    #print(s)
                    count += 2
                    flag = True
                    break
    return count



def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()


Fixed submission:
from sys import stdin


def b(input_string):
    _s = input_string
    s_length = len(_s)
    s = []
    for i in range(s_length):
        s.append(_s[i])
    count = 0
    i = 0
    while(i < len(s)-1):
        #print(s)
        #print(i)
        if s[i] != s[i+1]:
            s.pop(i)
            s.pop(i)
            count += 2
            if i != 0:
                i -= 1
        else:
            i += 1
    return count



def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = input()
string_list = input().rstrip().split()
l = [int(x) for x in string_list]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
return _max - _min

Fixed submission:
N = input()
string_list = input().rstrip().split()
l = [int(x) for x in string_list]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
print(_max - _min)

Buggy python submission (verdict: Runtime Error):
N = input()
l = [int(x) for x in input().rstrip().split()]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
return _max - _min

Fixed submission:
N = input()
string_list = input().rstrip().split()
l = [int(x) for x in string_list]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
print(_max - _min)

Buggy python submission (verdict: Runtime Error):
N = input()
l = [int(input()) for i in range(N)]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
return _max - _min

Fixed submission:
N = input()
string_list = input().rstrip().split()
l = [int(x) for x in string_list]
_max = 0
_min = l[0]
for t in l:
  if _max < t:
    _max = t
  if _min > t:
    _min = t  
print(_max - _min)
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = map(int, input().split())
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(0, N, 2):
        A += l[i]
print(A - sumB)

Fixed submission:
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = list(map(int, input().split()))
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(N):
    if i % 2 ==0:
        A += l[i]
print(A - sumB)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
res = 0
for i in range(N):
    if i + 1 == A[A[A[i]-1]]:
        res += 1 
print(res)

Fixed submission:
N = int(input())
A = [0] + list(map(int, input().split()))
res = 0
for i in range(1, N):
    if i == A[A[i]]:
        res += 1
        A[A[i]] = 0
print(res)
Buggy python submission (verdict: Runtime Error):
nk = input()

n = nk.split(' ')[0]
k = nk.split(' ')[1]

answer = n - k + 1
print(answer)

Fixed submission:
nk = input()

n = int(nk.split(' ')[0])
k = int(nk.split(' ')[1])

answer = n - k + 1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0 for _ in range(n)]
for i in range(1, n):
    dp[i] = min([dp[j] + abs(h[j] - h[i]) for j in range(max(0, i-k), i)])

print(dp[n-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0 for _ in range(n)]
for i in range(1, n):
    dp[i] = min([dp[j] + abs(h[j] - h[i]) for j in range(max(0, i-k), i)])

print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = max(ht - abs(xi - x) - abs(yi - y), 0)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

print(anss[0][0], anss[0][1], anss[0][2])

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = ht - abs(xi - x) - abs(yi - y)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

print(anss[0][0], anss[0][1], anss[0][2])

Fixed submission:
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = max(ht - abs(xi - x) - abs(yi - y), 0)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

print(anss[0][0], anss[0][1], anss[0][2])

Buggy python submission (verdict: Runtime Error):
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht0 = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            hti = hi + abs(xi - x) + abs(yi - y)
            if hti != ht0:
                flag = False
                break

        if flag:
            anss.append((x, y, ht0))

print(anss[0][0], anss[0][1], anss[0][2])

Fixed submission:
n = int(input())
xyhs = []
for _ in range(n):
    xyhs.append(tuple(map(int, input().split())))

xyhs = sorted(xyhs, key=lambda v: v[2], reverse=True)

anss = []
for y in range(101):
    for x in range(101):
        x0, y0, h0 = xyhs[0]
        ht = h0 + abs(x0 - x) + abs(y0 - y)

        flag = True
        for xyh in xyhs[1:]:
            xi, yi, hi = xyh
            his = max(ht - abs(xi - x) - abs(yi - y), 0)
            if his != hi:
                flag = False
                break

        if flag:
            anss.append((x, y, ht))

print(anss[0][0], anss[0][1], anss[0][2])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
vs = list(map(int, input().split()))

vs1 = [vs[i] for i in range(n) if i % 2 == 0]
vs2 = [vs[i] for i in range(n) if i % 2 != 0]

vsc1 = []
for v in set(vs1):
    vsc1.append((v, vs1.count(v)))

vsc2 = []
for v in set(vs2):
    vsc2.append((v, vs2.count(v)))

vsc1 = sorted(vsc1, key=lambda x: x[1], reverse=True)
vsc2 = sorted(vsc2, key=lambda x: x[1], reverse=True)
vsc1.append((-1, 0))
vsc2.append((-1, 0))

if vsc1[0][0] != vsc2[0][0]:
    print(n - (vsc1[0][1] + vsc2[0][1]))
else:
    print(n - max(vsc1[0][1] + vsc2[1][1], vsc1[1][1] + vsc2[0][1]))

Fixed submission:
from collections import defaultdict

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

vsd1 = defaultdict(int)
for i in range(0, n, 2):
    vsd1[vs[i]] += 1

vsd2 = defaultdict(int)
for i in range(1, n, 2):
    vsd2[vs[i]] += 1

vsc1 = []
for k, v in vsd1.items():
    vsc1.append((k, v))

vsc2 = []
for k, v in vsd2.items():
    vsc2.append((k, v))

vsc1.append((-1, 0))
vsc2.append((-1, 0))
vsc1 = sorted(vsc1, key=lambda x: x[1], reverse=True)
vsc2 = sorted(vsc2, key=lambda x: x[1], reverse=True)

if vsc1[0][0] != vsc2[0][0]:
    print(n - (vsc1[0][1] + vsc2[0][1]))
else:
    print(n - max(vsc1[0][1] + vsc2[1][1], vsc1[1][1] + vsc2[0][1]))
Buggy python submission (verdict: Runtime Error):
def gcd(l):
    if len(l) == 1:
        return l[0]

    return gcd([gcd2(l[0], l[1])] + l[2:])


def gcd2(a, b):
    if b == 0:
        return a

    return gcd2(b, a % b)


n, s = map(int, input().split())
x = list(map(int, input().split()))

x = [abs(xi - s) for xi in x]
print(gcd(x))


Fixed submission:
def gcd(l):
    if len(l) == 1:
        return l[0]

    v = gcd2(l[0], l[1])
    for i in range(2, n):
        v = gcd2(v, l[i])

    return v


def gcd2(a, b):
    if b == 0:
        return a

    return gcd2(b, a % b)


n, s = map(int, input().split())
x = list(map(int, input().split()))

x = [abs(xi - s) for xi in x]
print(gcd(x))
Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(lambda x: int(x) - 1, input().split())
    lr[l][r] += 1

c = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if j == 0:
            c[i][j] = lr[i][j]
        else:
            c[i][j] = c[i][j-1] + lr[i][j]

for _ in range(q):
    p, q = map(lambda x: int(x) - 1, input().split())
    count = 0
    for i in range(p, q+1):
        if p == 0:
            count += c[i][q]
        else:
            count += (c[i][q] - c[i][p-1])

    print(count)

Fixed submission:
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(lambda x: int(x) - 1, input().split())
    lr[l][r] += 1

for i in range(n):
    for j in range(1, n):
        lr[i][j] += lr[i][j-1]

for i in range(1, n):
    for j in range(n):
        lr[i][j] += lr[i-1][j]

for _ in range(q):
    p, q = map(lambda x: int(x) - 1, input().split())
    if p == 0:
        print(lr[q][q])
    else:
        print(lr[q][q]-lr[p-1][q]-lr[q][p-1]+lr[p-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(lambda x: int(x) - 1, input().split())
    lr[l][r] += 1

dp = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        added = 0
        for k in range(i, j+1):
            added += lr[k][j]
        dp[i][j] = dp[i][j-1] + added

for _ in range(q):
    p, q = map(lambda x: int(x) - 1, input().split())
    print(dp[p][q])


Fixed submission:
n, m, q = map(int, input().split())

lr = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l, r = map(lambda x: int(x) - 1, input().split())
    lr[l][r] += 1

for i in range(n):
    for j in range(1, n):
        lr[i][j] += lr[i][j-1]

for i in range(1, n):
    for j in range(n):
        lr[i][j] += lr[i-1][j]

for _ in range(q):
    p, q = map(lambda x: int(x) - 1, input().split())
    if p == 0:
        print(lr[q][q])
    else:
        print(lr[q][q]-lr[p-1][q]-lr[q][p-1]+lr[p-1][p-1])
Buggy python submission (verdict: Time Limit Exceeded):
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

print(sorted(list(ss))[k-1])

Fixed submission:
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

print(sorted(list(ss))[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input().strip()
k = int(input())

ss = set()
for i in range(len(s)):
    for j in range(i, len(s)):
        ss.add(s[i:j+1])

print(sorted(list(ss))[k-1])

Fixed submission:
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

print(sorted(list(ss))[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for x in range(a, b+1):
    if (x - a) < k or (b - x) < k:
        print(x)

Fixed submission:
a, b, k = map(int, input().split())
nums = set()
for i in range(k):
    if i > (b - a):
        break

    nums.add(a + i)
    nums.add(b - i)

for x in sorted(list(nums)):
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
q = int(input())
for _ in range(q):
    a, b = sorted(map(int, input().split()))
    if a == b:
        print(2 * a - 2)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        c = a
        while True:
            if (c + 1) * (c + 1) >= a * b:
                break
            c += 1

        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

Fixed submission:
import math

q = int(input())
for _ in range(q):
    a, b = sorted(map(int, input().split()))
    if a == b:
        print(2 * a - 2)
    elif a + 1 == b:
        print(2 * a - 2)
    else:
        c = math.ceil(math.sqrt(a * b)) - 1

        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
N = 20
f = [['#'] * N if i < (N/2) else ['.'] * N for i in range(N)]

for i in range(a-1):
    h = 2 * ((2 * i) // N)
    w = (2 * i) % N
    f[h][w] = '.'

for i in range(b-1):
    h = (N//2 + 1) + 2 * (2 * i // N)
    w = 2 * i % N
    f[h][w] = '#'


print(N, N)
for line in f:
    print(''.join(line))

Fixed submission:
a, b = map(int, input().split())
f = [['#' for _ in range(100)] for _ in range(50)] + \
    [['.' for _ in range(100)] for _ in range(50)]

for i in range(a-1):
    h = (i // 50) * 2
    w = (i % 50) * 2
    f[h][w] = '.'

for i in range(b-1):
    h = -((i // 50) * 2 + 1)
    w = (i % 50) * 2
    f[h][w] = '#'

print(100, 100)
for line in f:
    print(''.join(line))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    tt, aa = ti, ai
    while tt < t or aa < a:
        tt += ti
        aa += ai

    t = tt
    a = aa

print(t + a)

Fixed submission:
n = int(input())
t, a = list(map(int, input().split()))
for _ in range(n-1):
    ti, ai = list(map(int, input().split()))
    mt = t // ti if t % ti == 0 else t // ti + 1
    ma = a // ai if a % ai == 0 else a // ai + 1
    m = max(mt, ma)

    t = m * ti
    a = m * ai

print(t + a)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, a = list(map(int, input().split()))
xs = list(map(int, input().split()))

dp = [[[0 for _ in range(a * n + 1)] for _ in range(n + 1)]
      for _ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        for k in range(a * n + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j > 0 and k - xs[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k-xs[i-1]]


c = 0
for j in range(1, n+1):
    c += dp[n][j][j * a]

print(c)

Fixed submission:
import itertools

n, a = list(map(int, input().split()))
xs = list(map(int, input().split()))

dp = [[[0 for _ in range(a * n + 1)] for _ in range(n + 1)]
      for _ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        for k in range(a * n + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j > 0 and k - xs[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k-xs[i-1]]


c = 0
for j in range(1, n+1):
    c += dp[n][j][j * a]

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, a = list(map(int, input().split()))
xs = list(map(int, input().split()))

count = 0
for i in range(1, n+1):
    for c in itertools.combinations(xs, i):
        if sum(c) == a * i:
            count += 1

print(count)

Fixed submission:
import itertools

n, a = list(map(int, input().split()))
xs = list(map(int, input().split()))

dp = [[[0 for _ in range(a * n + 1)] for _ in range(n + 1)]
      for _ in range(n + 1)]
dp[0][0][0] = 1
for i in range(1, n+1):
    for j in range(n+1):
        for k in range(a * n + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j > 0 and k - xs[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k-xs[i-1]]


c = 0
for j in range(1, n+1):
    c += dp[n][j][j * a]

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


def main(N, scores):
    M = N - 1
    def max_score(d):
        even_steps = [scores[i] for i in range(0, M - d, d)]
        odd_steps = [scores[i] for i in range(M, d, -d)]
        scores_at_even_steps = np.cumsum(even_steps)
        scores_at_odd_steps = np.cumsum(odd_steps)
        cum_scores = scores_at_even_steps + scores_at_odd_steps

        if M % d > 0:
            return max(cum_scores)
        else:
            k = M // d + 1
            return max(cum_scores[: k // 2])

    corner_case = scores[0] + scores[M]
    otherwise = max(max_score(d) for d in range(1, M))
    return max(corner_case, otherwise)


N = int(input())
scores = [int(a) for a in input().split()]
result = main(N, scores)

print(result)

Fixed submission:
def cumsum(itr):
    arr = []
    val = 0
    for x in itr:
        val += x
        arr.append(val)
    return arr


def main(N, scores):
    M = N - 1

    def max_score(d):
        steps = (scores[i] + scores[-i - 1] for i in range(0, M - d, d))
        cum_scores = cumsum(steps)

        if M % d > 0:
            return max(cum_scores)
        else:
            k = M // d + 1
            return max(cum_scores[: k // 2])

    corner_case = scores[0] + scores[M]
    otherwise = max(max_score(d) for d in range(1, M))
    return max(corner_case, otherwise)


N = int(input())
scores = [int(a) for a in input().split()]
result = main(N, scores)

print(result)