Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02982 (python)

Fixed submission:
from scipy.spatial import distance


def solve(string):
    n, d, *x = map(int, string.split())
    x = [tuple(c) for c in zip(*[iter(x)] * d)]
    dist = distance.cdist(x, x)
    return str(((dist == dist.astype("int32")).sum() - n) // 2)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m)+'\n'.join([input() for _ in range(n)])))

Buggy submission (verdict: Runtime Error):
import math
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i, x0 in enumerate(X): 
    for x1 in X[i+1:]:
        if math.sqrt(sum([(a-b)**2 for a, b in zip(X0,X1)])).is_integer():
            counter+=1
print(counter)
Problem p02988 (python)

Fixed submission:
def solve(string):
    n, *p = map(int, string.split())
    ans = 0
    for i, j, k in zip(p, p[1:], p[2:]):
        ans += 1 if i <= j <= k or i >= j >= k else 0
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
import numpy

def solve(string):
    n, *p = map(int, string.split())
    p = numpy.asarray(p)
    asc=(p[:-2] < p[1:-1]) & (p[1:-1] < p[2:])
    desc=(p[:-2] > p[1:-1]) & (p[1:-1] > p[2:])
    return str(sum(asc | desc))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
Problem p02996 (python)

Fixed submission:
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: (x[1], x[0]))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Buggy submission (verdict: Runtime Error):
    n = int(input())
Problem p03014 (python)

Fixed submission:
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)
        ans = 0
        for i in range(h):
            ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]]) for j in range(w)])
        return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))
Problem p03032 (python)

Fixed submission:
def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, k, *v = map(int, string.split())
    lefts = [0] * (k + 1)
    rights = [0] * (k + 1)
    """
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    """
    for i in range(1, k + 1):
        _v = sorted(v[:i], reverse=True)
        lefts[i] = max(lefts[i], sum(_v))
        j = 0def solve(string):
    n, k, *v = map(int, string.split())
    """
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    """

    def s(w):
        l = [0] * (k + 1)
        for i in range(1, k + 1):
            _w = sorted(w[:i], reverse=True)
            tmp = sum(_w)
            l[i] = max(l[i], tmp)
            j = 0
            while i + j < k and len(_w) and _w[-1] < 0:
                j += 1
                tmp -= _w.pop()
                l[i + j] = max(l[i + j], tmp)
        return l

    lefts = s(v)
    rights = s(v[::-1])
    ans = max([lefts[i] + rights[k - i] for i in range(k + 1)])
    ans = min(ans, sum([_v for _v in v if _v > 0]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

        while i + j < k and len(_v) and _v[-1] < 0:
            j += 1
            _v.pop()
            lefts[i + j] = max(lefts[i + j], sum(_v))
    for i in range(1, k + 1):
        _v = sorted(v[-i:], reverse=True)
        rights[i] = max(rights[i], sum(_v))
        j = 0
        while i + j < k and len(_v) and _v[-1] < 0:
            j += 1
            _v.pop()
            rights[i+j] = max(rights[i+j], sum(_v))
    ans = max([lefts[i] + rights[k - i] for i in range(k + 1)])
    ans = min(ans, sum([_v for _v in v if _v > 0]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, k, *v = map(int, string.split())

    def dfs(deq, get, count, minus):
        if count == k:
            return sum(get)
        op1 = dfs(deq[1:], get + [deq[0]], count + 1, minus + (deq[0] < 0))
        op2 = dfs(deq[:-1], get + [deq[-1]], count + 1, minus + (deq[-1] < 0))
        m = min(get) if len(get) > 0 else 0
        op3 = 0 if m >= 0 else dfs(deq[:], sorted(get)[1:], count + 1, minus - 1)
        return max(op1, op2, op3)

    return str(dfs(v[:], [], 0, 0))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
Problem p03074 (python)

Fixed submission:
def solve(string):
    n, k, s = string.split()
    n, k = map(int, [n, k])
    flip = [0]
    for i, (s0, s1) in enumerate(zip(s, s[1:]), start=1):
        if s0 != s1:
            flip.append(i)
    flip += [n]
    return str(
        max([
            flip[min(len(flip) - 1, i + 2 * k + (i % 2 ^ int(s[0])))] - flip[i]
            for i in range(len(flip))
        ]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, k, s = string.split()
    n, k = map(int, [n, k])
    s = "1" + s + "0"
    starts = [1]
    ends = []
    for i, (s0, s1) in enumerate(zip(s, s[1:])):
        if s0 == "0" and s1 == "1":
            starts.append(i + 1)
        elif s0 == "1" and s1 == "0":
            ends.append(i + 1)
    return str(max([e - s for s, e in zip(starts, ends[k:])])) if len(starts) > k else str(n)


if __name__ == '__main__':
    print(solve(input()))
Problem p03079 (python)

Fixed submission:
a,b,c = map(int, input().split())
ans = "Yes" if a==b==c else "No"
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
return "Yes" if a==b==c else "No"
Problem p03080 (python)

Fixed submission:
n=int(input())
s=input()
ans= "Yes" if s.count("R") > n//2 else "No" 
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
ans "Yes" if s.count("R") > n//2 eise "No" 
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
return "Yes" if s.count("R") > n//2 eise "No"
Problem p03102 (python)

Fixed submission:
import numpy as np


def solve(string):
    n, m, c, *ba = map(int, string.split())
    b = np.asarray(ba[:m])
    a = np.asarray(ba[m:])
    a.resize((n, m))
    return str(sum(np.dot(b, a.T) > -c))


if __name__ == '__main__':
    n, m, o = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, o) + '\n'.join([input() for _ in range(n + 1)])))

Buggy submission (verdict: Runtime Error):
import numpy as np


def solve(string):
    n, m, c, *ba = map(int, string.split())
    """
    b = np.asarray(ba[:m])
    a = np.asarray(ba[m:])
    a.resize((n, m))
    return str(np.sum(np.dot(a, b.T) > -c))
    """
    b = ba[:m]
    ans = 0
    for i in range(n):
        tmp = c
        for j in range(m):
            tmp += b[j] * ba[(i + 1) * n + j]
        if tmp > c:
            ans += 1
    return str(ans)


if __name__ == '__main__':
    n, m, o = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, o) + '\n'.join([input() for _ in range(n + 1)])))
Problem p03126 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans &= set(map(int, loves.split()[1:]))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base.split())
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = set([i + 1 for i in range(m)])
    for loves in string[1:]:
        ans &= set(map(int, loves.split()[1:]))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base)
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans = ans & (set(map(int, loves.split()[1:])))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base)
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans.intersection_update(set(map(int, loves.split()[1:])))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base)
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans &= set(map(int, loves.split()[1:]))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base)
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans &= set(map(int, loves.split()[1:]))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base)
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))
Problem p03136 (python)

Fixed submission:
def solve(string):
    l = map(int, string.split())
    l= sorted(l)
    return "Yes" if sum(l[:len(l)-1]) > l[-1] else "No"


if __name__ == '__main__':
    input()
    print(solve(input()))

Buggy submission (verdict: Runtime Error):
def solve(string):
    nl = map(int, string.split())
    l = sorted(list(nl)[1:])
    return "Yes" if sum(l[:-1]) > l[-1] else "No"


if __name__ == '__main__':
    print(solve(input()))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, *l = map(int, string.split())
    l= sorted(l)
    return "Yes" if sum(l[:-1]) > l[-1] else "No"


if __name__ == '__main__':
    print(solve(input()))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, *l = map(int, string.split())
    l = sorted(l)
    return "Yes" if sum(l[:-1]) > l[-1] else "No"


if __name__ == '__main__':
    print(solve("\n".join[input(), input()]))
Problem p03138 (python)

Fixed submission:
def solve(string):
    n, k, *a = map(int, string.split())
    if k == 0:
        x = 0
    else:
        l = len("{:b}".format(k))
        base = [2**(l - i - 1) for i in range(l)]
        count = [0] * l
        for _a in a:
            tmp = "{:b}".format(_a)
            for i, _f in enumerate(tmp[::-1]):
                if i >= l:
                    break
                if _f == "1":
                    count[l - i - 1] += 1
        x = 0
        for _c, _b in zip(count, base):
            if _c < n / 2 and x + _b <= k:
                x += _b
    return str(sum([x ^ _a for _a in a]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, k, *a = map(int, string.split())
    if k == 0:
        x = 0
    else:
        l = len("{:b}".format(k))
        count = [0] * l
        for _a in a:
            if _a == 0:
                continue
            tmp = "{:b}".format(_a)
            for i, _f in enumerate(tmp[::-1]):
                if _f == "1":
                    count[l - i - 1] += 1
        x = int("".join(["1" if _c < n / 2 else "0" for _c in count]), 2)
    return str(sum([x ^ _a for _a in a]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, k, *a = map(int, string.split())
    if k == 0:
        x = 0
    else:
        l = len("{:b}".format(k))
        count = [0] * l
        for _a in a:
            tmp = "{:b}".format(_a)
            for i, _f in enumerate(tmp[::-1]):
                if _f == "1":
                    count[l - i - 1] += 1
        x = int("".join(["1" if _c < n / 2 else "0" for _c in count]), 2)
    return str(sum([x ^ _a for _a in a]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
Problem p03238 (python)

Fixed submission:
def solve(string):
    flag, *ab = map(int, string.split())
    return str(sum(ab)) if flag - 1 else "Hello World"


if __name__ == '__main__':
    flag = int(input())
    if flag - 1:
        flag = "{}\n".format(flag) + "\n".join([input(), input()])
    print(solve(str(flag)))

Buggy submission (verdict: Runtime Error):
def solve(string):
    flag, *ab = map(int, string.split())
    return str(sum(ab)) if flag - 1 else "Hello World"


if __name__ == '__main__':
    flag = int(input())
    if flag - 1:
        flag = "{}\n".format(flag) + "\n".join([input(), input()])
    print(solve(flag))
Problem p03239 (python)

Fixed submission:
n, t = map(int, input().split(" "))
ct = [list(map(int, input().split(" "))) for _ in range(n)]
valid = [_ct for _ct in ct if _ct[-1] <= t]
if len(valid) > 0:
    print(sorted(valid, key=lambda x: x[0])[0][0])
else:
    print("TLE")

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, t, *ct = map(int, string.split())
    c = [_c for _c, _t in zip(ct[::2], ct[1::2]) if _t <= t]
    return str(min(c)) if len(c) else "TLE"


if __name__ == '__main__':
    n, t = map(int, input().split())
    print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in n])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, t, *ct = map(int, string.split())
    c = [_c for _c, _t in zip(ct[::2], ct[1::2]) if _t <= t]
    return str(min(c)) if len(c) else "TLE"


if __name__ == '__main__':
    n, t = map(int, input())
    print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in n])))
Problem p03244 (python)

Fixed submission:
import collections
n = int(input())
v = input().split(" ")
"""
n = 10000
# v = [_i % 10 for _i in range(n)]
v = [_i for _i in range(n)]
n = 10
v = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
"""
if len(set(v)) == 1:
    print(n // 2)
else:
    odds = v[1::2]
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    evens = v[::2]
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    ans1 = 0
    tmp = max(_o.values())
    ans1 += len(odds) - tmp
    key = r_o[str(tmp)]
    if key in _e.keys():
        _e[key] = 0
    ans1 += len(evens) - max(_e.values())

    ans2 = 0
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    tmp = max(_e.values())
    ans2 += len(evens) - tmp
    key = r_e[str(tmp)]
    if key in _o.keys():
        _o[key] = 0
    ans2 += len(evens) - max(_o.values())

    print(min(ans1, ans2))

Buggy submission (verdict: Runtime Error):
import collections


def solve(string):
    n, *v = map(int, string.split())
    if len(set(v)) == 1:
        return str(n // 2)
    else:
        odds = v[1::2]
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        evens = v[::2]
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        ans1 = 0
        tmp = max(_o.values())
        ans1 += len(odds) - tmp
        key = r_o[str(tmp)]
        if key in _e.keys():
            _e[key] = 0
        ans1 += len(evens) - max(_e.values())

        ans2 = 0
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        tmp = max(_e.values())
        ans2 += len(evens) - tmp
        key = r_e[str(tmp)]
        if key in _o.keys():
            _o[key] = 0
        ans2 += len(evens) - max(_o.values())

        return str(min(ans1, ans2))


if __name__ == '__main__':
    print(solve(input()))

Buggy submission (verdict: Runtime Error):
import collections


def solve(string):
    n, v = map(int, string.split())
    if len(set(v)) == 1:
        return str(n // 2)
    else:
        odds = v[1::2]
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        evens = v[::2]
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        ans1 = 0
        tmp = max(_o.values())
        ans1 += len(odds) - tmp
        key = r_o[str(tmp)]
        if key in _e.keys():
            _e[key] = 0
        ans1 += len(evens) - max(_e.values())

        ans2 = 0
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        tmp = max(_e.values())
        ans2 += len(evens) - tmp
        key = r_e[str(tmp)]
        if key in _o.keys():
            _o[key] = 0
        ans2 += len(evens) - max(_o.values())

        return str(min(ans1, ans2))


if __name__ == '__main__':
    print(solve(input()))
Problem p03282 (python)

Fixed submission:
def solve(string):
    s, k = string.split()
    if len(s) == 1:
        return s
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return "1" if len(k) < 4 and int(k) <= counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    s, k = string.split()
    if len(s) == 1:
        return s
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return "1" if len(k) < 4 and int(k) < counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    s, k = string.split()
    if len(s) == 1:
        return s
    k = int(k)
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return "1" if k < counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    s, k = map(int, string.split())
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return str(s) if len(str(s)) == 1 else "1" if k < counter else str(s)[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    s, k = map(int, string.split())
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return str(s) if len(str(s)) == 1 else "1" if k < counter else str(s)[counter]


if __name__ == '__main__':
    print(solve('n'.join([input(), input()])))
Problem p03287 (python)

Fixed submission:
from collections import defaultdict


def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]

    d = defaultdict(int)
    for i in range(n):
        d[a[i] % m] += 1
    ans = d[0]
    for v in d.values():
        ans += v * (v - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    l = [0] * m
    for i in range(n):
        l[a[i] % m] += 1
    ans = l[0]
    for i in range(m):
        ans += l[i] * (l[i] - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Buggy submission (verdict: Runtime Error):
def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    l = [0] * m
    print(a)
    for i in range(n):
        l[a[i] % m] += 1
    ans = l[0]
    for i in range(m):
        ans += l[i] * (l[i] - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))