Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(n):
    d[input()] -= 1
print(max(0, max(d.values())))

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(m):
    d[input()] -= 1
print(max(0, max(d.values())))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(n):
    d[input()] -= 1
print(max(d.values()))

Fixed submission:
from collections import defaultdict
d = defaultdict(int)

n = int(input())
for _ in range(n):
    d[input()] += 1
m = int(input())
for _ in range(m):
    d[input()] -= 1
print(max(0, max(d.values())))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    ds = [nm // d + 1 for d in range(s, 0, -1)]
    ds = [sb] + ds + [n + 1]
    # print(m, nm, sb, s, ds)
    dd = np.diff(ds)
    pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # print(dd, pd, dd * pd, sum(dd * pd))
    ans += sum(dd * pd)
print(ans)


Fixed submission:
import numpy as np

n, k = map(int, input().split())
ans = 0
for m in range(k, n):
    nm = n - m
    sb = m + 1
    s = nm // sb
    p = s + 1 if m else s
    ps = sb
    for d in range(s, 0, -1):
        ds = nm // d + 1
        co = ds - ps
        ans += co * p
        ps = ds
        p -= 1
    ans += n + 1 - ps

    # ds = [nm // d + 1 for d in range(s, 0, -1)]
    # ds = [sb] + ds + [n + 1]
    # # print(m, nm, sb, s, ds)
    # dd = np.diff(ds)
    # pd = np.arange(s + 1, 0, -1) if m else np.arange(s, -1, -1)
    # # print(dd, pd, dd * pd, sum(dd * pd))
    # ans += sum(dd * pd)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

h, w, d = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(h)]

c_map = [0] * (h * w)
for i in range(h):
    for j in range(w):
        c_map[f[i][j] - 1] = (i, j)

buf = []
q = int(input())
for line in sys.stdin.readlines():
    l, r = map(int, line.split())
    ans = 0
    l -= 1
    r -= 1
    i, j = c_map[l]
    while l != r:
        i2, j2 = c_map[l + d]
        ans += abs(i - i2) + abs(j - j2)
        l += d
        i, j = i2, j2
    buf.append(ans)

print('\n'.join(map(str, buf)))


Fixed submission:
import sys

h, w, d = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(h)]

c_map = [0] * (h * w)
for i in range(h):
    for j in range(w):
        c_map[f[i][j] - 1] = (i, j)

d_map = [0] * (h * w)
for l in range(h * w - d - 1, -1, -1):
    i, j = c_map[l]
    i2, j2 = c_map[l + d]
    d_map[l] = d_map[l + d] + abs(i - i2) + abs(j - j2)

buf = []
q = int(input())
for line in sys.stdin.readlines():
    l, r = map(int, line.split())
    buf.append(d_map[l - 1] - d_map[r - 1])

print('\n'.join(map(str, buf)))

Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
queries = [list(map(int, input().split())) for _ in range(q)]

c_map = [0] * (h * w)
for i in range(h):
    for j in range(w):
        c_map[f[i][j] - 1] = (i, j)

buf = []
for l, r in queries:
    ans = 0
    l -= 1
    r -= 1
    i, j = c_map[l]
    while l != r:
        i2, j2 = c_map[l + d]
        ans += abs(i - i2) + abs(j - j2)
        l += d
        i, j = i2, j2
    buf.append(ans)

print('\n'.join(map(str, buf)))


Fixed submission:
import sys

h, w, d = map(int, input().split())
f = [list(map(int, input().split())) for _ in range(h)]

c_map = [0] * (h * w)
for i in range(h):
    for j in range(w):
        c_map[f[i][j] - 1] = (i, j)

d_map = [0] * (h * w)
for l in range(h * w - d - 1, -1, -1):
    i, j = c_map[l]
    i2, j2 = c_map[l + d]
    d_map[l] = d_map[l + d] + abs(i - i2) + abs(j - j2)

buf = []
q = int(input())
for line in sys.stdin.readlines():
    l, r = map(int, line.split())
    buf.append(d_map[l - 1] - d_map[r - 1])

print('\n'.join(map(str, buf)))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(s, k):
    n = len(s)
    pdp = [[0] * (k + 1) for _ in range(n + 1)]
    for l in range(n - 1, -1, -1):
        dp = [[0] * (k + 1) for _ in range(n + 1)]
        for r in range(l, n):
            dpr, dpr1 = dp[r], pdp[r - 1]
            inc = 1 if l == r else 2
            is_same = s[l] == s[r]
            for p in range(k + 1):
                if is_same:
                    dpr[p] = dpr1[p] + inc
                else:
                    if p:
                        dpr[p] = max(pdp[r][p], dp[r - 1][p], dpr1[p - 1] + inc)
                    else:
                        dpr[p] = max(pdp[r][p], dp[r - 1][p])
        pdp = dp

    return pdp[-2][k]


print(solve(input(), int(input())))


Fixed submission:
def solve(s, k):
    n = len(s)
    pdp = [[0] * (k + 1) for _ in range(n + 1)]
    for l in range(n - 1, -1, -1):
        dp = [[0] * (k + 1) for _ in range(n + 1)]
        for r in range(l, n):
            dpr, dpr1 = dp[r], pdp[r - 1]
            inc = 1 if l == r else 2
            is_same = s[l] == s[r]
            for p in range(k + 1):
                if is_same:
                    dpr[p] = dpr1[p] + inc
                else:
                    if p:
                        dpr[p] = max(pdp[r][p], dp[r - 1][p], dpr1[p - 1] + inc)
                    else:
                        dpr[p] = max(pdp[r][p], dp[r - 1][p])
        pdp = dp

    return pdp[-2][k]


print(solve(input(), int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, k):
    MOD = 998244353

    if n > k:
        return 0

    invs = [1] * (k + 1)
    pf, kf = 1, 1
    for m in range(2, k + 1):
        pf = kf
        kf *= m
        kf %= MOD
        invs[m] = pow(kf, MOD - 2, MOD)

    ans = 0
    if k & 1 == 0:
        if n == 1:
            ans = 1
        else:
            r = k >> 1
            t = r - n + 1
            ans = pf * (invs[r] * invs[r - 1] - invs[r + t] * invs[k - r - t - 1]) % MOD

    for r in range(k // 2 + 1, k + 1):
        if r * 2 >= n + k:
            ans += kf * invs[r] * invs[k - r]
        else:
            t = r - n + 1
            ans += kf * (invs[r] * invs[k - r] - invs[r + t] * invs[k - r - t])
        ans %= MOD
    return ans


print(solve(*map(int, input().split())))


Fixed submission:
def solve(n, k):
    MOD = 998244353

    if n > k:
        return 0
    if n == 1:
        return pow(2, k - 1, MOD)

    invs = [1] * (k + 1)
    pf, kf = 1, 1
    for m in range(2, k + 1):
        pf = kf
        kf *= m
        kf %= MOD
        invs[m] = pow(kf, MOD - 2, MOD)

    ans = 0
    if k & 1 == 0:
        r = k >> 1
        s = k - n + 1
        ans = pf * (invs[r] * invs[r - 1] - invs[s] * invs[k - s - 1]) % MOD

    for r in range(k // 2 + 1, k + 1):
        if r * 2 >= n + k:
            ans += kf * invs[r] * invs[k - r]
        else:
            s = r * 2 - n + 1
            ans += kf * (invs[r] * invs[k - r] - invs[s] * invs[k - s])
        ans %= MOD
    return ans


print(solve(*map(int, input().split())))
Buggy python submission (verdict: Runtime Error):
def dps(v, p, links):
    lv = links[v]
    if not lv:
        return 0
    cnt0 = 0
    ret = 0
    for l in lv:
        if l == p:
            continue
        res = dps(l, v, links)
        ret += res
        if res == 0:
            cnt0 += 1
    if cnt0:
        ret += cnt0 - 1
    return ret


def solve(n, links):
    if n == 2:
        return 1
    for i, l in enumerate(links):
        if len(l) > 1:
            return dps(i, None, links)


n = int(input())
links = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)
print(solve(n, links))


Fixed submission:
import sys

sys.setrecursionlimit(100000)


def dfs(v, p, links):
    lv = links[v]
    if len(lv) == 1:
        return 0
    cnt0 = 0
    ret = 0
    for l in lv:
        if l == p:
            continue
        res = dfs(l, v, links)
        ret += res
        if res == 0:
            cnt0 += 1
    if cnt0:
        ret += cnt0 - 1
    return ret


def solve(n, links):
    if n == 2:
        return 1
    for i, l in enumerate(links):
        if len(l) > 2:
            return dfs(i, None, links)
    else:
        return 1


n = int(input())
links = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)
print(solve(n, links))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())
print(['Even', 'Odd'][a * b % 2])

Fixed submission:
a, b = map(int, input().split())
print(['Even', 'Odd'][a * b % 2])
Buggy python submission (verdict: Runtime Error):
n = input().replace(' ', '')
m = int(n ** 0.5 + 1e-6)
print('Yes' if n == m * m else 'No')

Fixed submission:
n = int(input().replace(' ', ''))
m = int(n ** 0.5 + 1e-6)
print('Yes' if n == m * m else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from collections import defaultdict
from itertools import accumulate

n = int(input())
arr = list(map(int, input().split()))
arr.sort()
sa = sum(arr)
lim = sa // 2
dp = defaultdict(int)
dp[0] = 1

for a in arr:
    # print(a, dp)
    ndp = dp.copy()
    for i, v in dp.items():
        if i + a <= lim:
            ndp[i + a] += v
    dp = ndp
    # print(a, dp)

dpk = list(dp.keys())
dpk.sort()
dpv = [dp[k] for k in dpk]
adp = list(accumulate(dpv))
k = 2 ** (n - 1)
j = bisect_left(adp, k)

# print(adp)
# print(k)

print(sa - dpk[j])


Fixed submission:
n, arr, dp = int(input()), list(map(int, input().split())), 1
for a in arr:
    dp |= dp << a
ofs = (sum(arr) + 1) // 2
dp >>= ofs
print((dp & -dp).bit_length() + ofs - 1)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from itertools import accumulate

n = int(input())
arr = list(map(int, input().split()))
sa = sum(arr)
lim = sa // 2
dp = [0] * (lim + 1)
dp[0] = 1
mx = 0

for a in arr:
    # print(a, dp)
    for i in range(min(mx, lim - a), -1, -1):
        if dp[i]:
            dp[i + a] += dp[i]
    # print(a, dp)
    mx = max(mx + a, lim)

adp = list(accumulate(dp))
k = 2 ** (n - 1)

# print(adp)
# print(k)

print(sa - bisect_left(adp, k))


Fixed submission:
n, arr, dp = int(input()), list(map(int, input().split())), 1
for a in arr:
    dp |= dp << a
ofs = (sum(arr) + 1) // 2
dp >>= ofs
print((dp & -dp).bit_length() + ofs - 1)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect, bisect_left
from itertools import accumulate
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    bf = list(filter(lambda x: x > max_a, bb))
    bf.sort(reverse=True)
    bba = list(accumulate(bf))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    for i, dmg in enumerate(bba):
        if dmg >= throw_dmg:
            break
    return slash_cnt + i + 1


n, h = map(int, input().split())
aa, bb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

print(solve(h, aa, bb))


Fixed submission:
from bisect import bisect, bisect_left
from itertools import accumulate
from math import ceil


def solve(h, aa, bb):
    max_a = max(aa)
    bf = list(filter(lambda x: x > max_a, bb))
    if not bf:
        return ceil(h / max_a)
    bf.sort(reverse=True)
    bba = list(accumulate(bf))
    remain = h - bba[-1]
    slash_cnt = max(0, ceil(remain / max_a))
    slash_dmg = slash_cnt * max_a
    throw_dmg = h - slash_dmg
    for i, dmg in enumerate(bba):
        if dmg >= throw_dmg:
            break
    return slash_cnt + i + 1


n, h = map(int, input().split())
aa, bb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

print(solve(h, aa, bb))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(l, r):
    if l > r:
        return l
    m = (l + r) // 2
    t = sum(max(0, (m - w) // d + 1) for w, d in flowers)
    if t < k:
        l = m + 1
    else:
        r = m - 1
    return solve(l, r)


n, k = map(int, input().split())
flowers = [tuple(map(int, input().split())) for _ in range(n)]
print(solve(1, flowers[0][0] + flowers[0][1] * k))


Fixed submission:
from bisect import bisect


def solve(l, r):
    if l > r:
        return l
    m = (l + r) // 2
    j = bisect(flowers, (m, float('inf')))
    t = sum((m - w) // d + 1 for w, d in flowers[:j])
    if t < k:
        l = m + 1
    else:
        r = m - 1
    return solve(l, r)


n, k = map(int, input().split())
flowers = [tuple(map(int, input().split())) for _ in range(n)]
flowers.sort()
print(solve(1, flowers[0][0] + flowers[0][1] * k))
Buggy python submission (verdict: Runtime Error):
2import re

print('Yes' if re.match('A?KIHA?BA?RA?', input()) else 'No')


Fixed submission:
import re

print('YES' if re.match('A?KIHA?BA?RA?$', input()) else 'NO')
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from itertools import product, combinations


def solve(n, ds):
    if n >= 24:
        return 0
    freq = Counter(ds)
    if 0 in freq or freq[12] >= 2 or max(freq.values()) >= 3:
        return 0
    cmp = set()
    alt = []
    for d, l in freq.items():
        if l == 2 or d == 12:
            cmp.add(d)
            cmp.add(24 - d)
        else:
            alt.append((d, 24 - d))
    ans = min((abs(x - y) for x, y in combinations(cmp, 2)), default=0)
    for prd in product((0, 1), repeat=len(alt)):
        tmp_cmp = cmp.copy().union(x[i] for x, i in zip(alt, prd))
        tmp = min(abs(x - y) for x, y in combinations(tmp_cmp, 2))
        tmp = min(tmp, min(freq.keys()))
        ans = max(ans, tmp)
    return ans


print(solve(int(input()), list(map(int, input().split()))))


Fixed submission:
from collections import Counter


def solve(n, ds):
    if n >= 24:
        return 0
    freq = Counter(ds)
    if (0 in freq) or (freq[12] >= 2) or max(freq.values()) >= 3:
        return 0
    up_low = [0, 0]
    switch = 0
    ans = 25
    for d, s in sorted(freq.items()):
        if s == 2:
            ans = min(ans, d - up_low[0], d - up_low[1])
            up_low[0] = up_low[1] = d
        else:
            ans = min(ans, d - up_low[switch])
            up_low[switch] = d
            switch ^= 1
    ans = min(ans, 24 - sum(up_low))
    return ans


print(solve(int(input()), list(map(int, input().split()))))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cs = sorted((tuple(map(int, input().split())) for _ in range(n)), key=sum)
dp = [0]
for m, (h, p) in enumerate(cs):
    if dp[-1] <= h:
        dp.append(dp[-1] + p)
        bak = 3
    else:
        bak = 2
    for i in range(len(dp) - bak, -1, -1):
        if dp[i] <= h:
            dp[i + 1] = min(dp[i + 1], dp[i] + p)

print(len(dp) - 1)


Fixed submission:
n = int(input())
cs = sorted((tuple(map(int, input().split())) for _ in range(n)), key=sum)
dp = [0]
for m, (h, p) in enumerate(cs):
    if dp[-1] <= h:
        dp.append(dp[-1] + p)
        bak = 3
    else:
        bak = 2
    for i in range(len(dp) - bak, -1, -1):
        if dp[i] <= h:
            dp[i + 1] = min(dp[i + 1], dp[i] + p)

print(len(dp) - 1)
Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input().split())
aa=input().split()
an=int(aa[-1])
if len(aa) > 1:
    am=int(aa[-2])
    print(max(abs(an-w),abs(an-am)))
else:
    print(abs(an-w))

Fixed submission:
n,m=map(int,input().split())
q=(n-m)*100+m*1900
print(q*(1<<m))
Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input().split())
aa=input().split()
an,am=int(aa[-1]),int(aa[-2])
print(max(abs(an-w),abs(an-am)))

Fixed submission:
n,z,w=map(int,input().split())
aa=input().split()
an=int(aa[-1])
if len(aa) > 1:
    am=int(aa[-2])
    print(max(abs(an-w),abs(an-am)))
else:
    print(abs(an-w))
Buggy python submission (verdict: Runtime Error):
def check(iter, broken):
    iter_ans=0
    for j in iter:
        tmp_sum=0
        tmp_broken=set()
        for t in range(j, n, j+1):
            if t not in broken:
                tmp_sum+=aa[t]
                tmp_broken.add(t)
        # print(ans, j, tmp_broken, broken)
        if tmp_sum < 0:
            iter_ans -= tmp_sum
            broken.update(tmp_broken)
    return iter_ans


n=int(input())
aa=list(map(int,input().split()))
ans=sum(aa)
i=n//2
broken=set()
for j in range(i,n):
    if aa[j] < 0:
        ans -= aa[j]
        broken.add(j)
ccc=0
import random
for _ in range(100):
    c=check(random.shuffle(aa[i]), broken.copy())
    ccc=max(ccc,c)
print(ans+ccc)

Fixed submission:
from collections import deque


class Dinic:
    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None

    def add_link(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])

    def bfs(self, s):
        depth = [-1] * self.n
        depth[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth

    def dfs(self, v, t, flow):
        if v == t:
            return flow
        for i, link in enumerate(self.links[v]):
            if i < self.progress[v]:
                continue
            self.progress[v] = i
            cap, to, rev = link
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, float('inf'))
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, float('inf'))


n = int(input())
an = list(map(int, input().split()))
mf = Dinic(n + 2)
max_value = 0
for i, a in enumerate(an):
    i += 1
    if a > 0:
        max_value += a
        mf.add_link(i, n + 1, a)
    else:
        mf.add_link(0, i, -a)
    for j in range(2 * i, n + 1, i):
        mf.add_link(i, j, float('inf'))
print(max_value - mf.max_flow(0, n + 1))
Buggy python submission (verdict: Runtime Error):
def solve(k, n):
    if k & 1 == 0:
        return [k // 2] + [k] * (n - 1)
    xs = [((k ** i - 1) // (k - 1)) for i in range(1, -1)]
    xs = [((k ** i - 1) // (k - 1)) for i in range(n + 1, 1, -1)]
    tgt = xs[0] // 2 - 1
    mk1 = k // 2
    mk2 = mk1 + 1
    l = xs[1] * mk1
    ans = []
    for i in range(1, n - 1):
        if l == tgt:
            return ans
        nxt = l + xs[i + 1] * mk1 + 1
        if nxt > tgt:
            ans.append(mk1)
            l = nxt - xs[i + 1]
        else:
            ans.append(mk2)
            l = nxt
    if l == tgt:
        return ans
    return ans + [tgt - l]


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

print(*solve(k, n))


Fixed submission:
def solve(k, n):
    if k & 1 == 0:
        return [k // 2] + [k] * (n - 1)
    ans = [k // 2 + 1] * n
    l = n
    for i in range((n - 2) // 2 + 1):
        if ans[-1] == 1:
            ans.pop()
            l -= 1
        else:
            ans[-1] -= 1
            if l < n:
                ans += [k] * (n - l)
                l = n
    return ans


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

print(*solve(k, n))

Buggy python submission (verdict: Runtime Error):
def solve(k, n):
    if k & 1 == 0:
        return [k // 2] + [k] * (n - 1)
    xs = [((k ** i - 1) // (k - 1)) for i in range(n + 1, 1, -1)]
    tgt = xs[0] // 2 - 1
    mk = k // 2 + 1
    l = xs[1] * (k // 2)
    for i in range(1, n - 1):
        if l == tgt:
            return [mk] * i
        if l > tgt:
            return [mk] * i + [mk - 1] * (n - i)
        l += xs[i + 1] * (k // 2) + 1
    if l == tgt:
        return [mk] * (n - 1)
    return [mk] * (n - 1) + [tgt - l]


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

print(*solve(k, n))


Fixed submission:
def solve(k, n):
    if k & 1 == 0:
        return [k // 2] + [k] * (n - 1)
    ans = [k // 2 + 1] * n
    l = n
    for i in range((n - 2) // 2 + 1):
        if ans[-1] == 1:
            ans.pop()
            l -= 1
        else:
            ans[-1] -= 1
            if l < n:
                ans += [k] * (n - l)
                l = n
    return ans


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

print(*solve(k, n))
Buggy python submission (verdict: Time Limit Exceeded):
from string import ascii_lowercase

cd = {c: 1 << i for i, c in enumerate(ascii_lowercase)}
bt = set(cd.values())
bt.add(0)


def solve(s):
    q = {s}
    n = 0
    while True:
        nq = set()
        for s in q:
            if not s:
                return n
            b = 0
            for i, c in enumerate(s):
                b ^= cd[c]
                if b in bt:
                    nq.add(s[i + 1:])
        q = nq
        n += 1


print(solve(input()))


Fixed submission:
from string import ascii_lowercase

cd = {c: 1 << i for i, c in enumerate(ascii_lowercase)}
bt = set(cd.values())
bt.add(0)


def solve(s):
    a, b = [], 0
    for c in s:
        b ^= cd[c]
        a.append(b)
    if a[-1] == 0:
        return 1

    dp = {0: 0}
    for b1 in a:
        for b2 in bt:
            b3 = b1 ^ b2
            if b3 not in dp:
                continue
            if b1 in dp:
                dp[b1] = min(dp[b1], dp[b3] + 1)
            else:
                dp[b1] = dp[b3] + 1
    return dp[a[-1]]


print(solve(input()))

Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
import heapq

cd = {c: 1 << i for i, c in enumerate(ascii_lowercase)}


def solve(s):
    queue = [(0, s)]
    while queue:
        n, s = heapq.heappop(queue)
        if not s:
            return n
        b = 0
        for i, c in enumerate(s):
            b ^= cd[c]
            if bin(b).count('1') <= 1:
                heapq.heappush(queue, (n + 1, s[i + 1:]))


print(solve(input()))


Fixed submission:
from string import ascii_lowercase

cd = {c: 1 << i for i, c in enumerate(ascii_lowercase)}
bt = set(cd.values())
bt.add(0)


def solve(s):
    a, b = [], 0
    for c in s:
        b ^= cd[c]
        a.append(b)
    if a[-1] == 0:
        return 1

    dp = {0: 0}
    for b1 in a:
        for b2 in bt:
            b3 = b1 ^ b2
            if b3 not in dp:
                continue
            if b1 in dp:
                dp[b1] = min(dp[b1], dp[b3] + 1)
            else:
                dp[b1] = dp[b3] + 1
    return dp[a[-1]]


print(solve(input()))
Buggy python submission (verdict: Runtime Error):
from operator import add
n=int(input())
print(min(map(add, map(int, input().split())) for _ in range(n)))

Fixed submission:
from operator import add

n = int(input())
print(min(add(*map(int, input().split())) for _ in range(n)))