alexjercan/bugnet huggingface dataset:
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    d_e[0] = 0
    d_o[0] = 0
    de = sorted(d_e.items(), key=lambda x: -x[1])
    do = sorted(d_o.items(), key=lambda x: -x[1])
    if de[0][0] != do[0][0]:
        print(n - de[0][1] - do[0][1])
    else:
        p01 = de[0][1] + do[1][1]
        p10 = de[1][1] + do[0][1]
        print(n - max(p01, p10))


if __name__ == "__main__":
    resolve()


Error: 0

Fixed submission:

from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    de = sorted(d_e.items(), key=lambda x: x[1])
    do = sorted(d_o.items(), key=lambda x: x[1])
    if de == do:
        p = max(de[0][1], do[0][1])
        print(n - p)
    if de[0] != do[0]:
        print(n - de[0][1] - do[0][1])
    else:
        p = max(de[0][1] + do[1][1], de[1][1] + do[0][1])
        print(n - p)


if __name__ == "__main__":
    resolve()
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(i) for i in stdin.readline().rstrip().split()]

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

even_conter = Counter(even)
odd_conter = Counter(odd)

even_sorted = even_conter.most_common()
odd_sorted = odd_conter.most_common()

even_key1 = even_sorted[0][0]
even_val1 = even_sorted[0][1]
odd_key1 = odd_sorted[0][0]
odd_val1 = odd_sorted[0][1]

ans = n
if even_key1 == odd_key1:
    if len(even_sorted) >= 2:
        even_val2 = even_sorted[1][1]
        odd_val2 = odd_sorted[1][1]
        ans -= max((even_val1 + odd_val2), (odd_val1 + even_val2))
    else:
        ans -= max(even_val1, odd_val1)
else:
    ans -= even_val1 + odd_val1

print(ans)


Error: TypeError: can only concatenate list (not "int") to list
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03244/Python/s259366931.py", line 6, in <module>
    left = [0] * 10**5 + 1
TypeError: can only concatenate list (not "int") to list


Fixed submission:

from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5 + 1
right = [0] * 10**5 + 1

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

import collections

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

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common(2)
me = collections.Counter(even).most_common(2)

if mo[0][0] != me[0][0]:
    print(n - mo[0][1] - me[0][1])
elif len(mo) == 1:
    print(n - mo[0][1] - me[1][1])
elif len(me) == 1:
    print(n - mo[1][1] - me[0][1])
else:
    print(n - max(mo[0][1] + me[1][1], mo[1][1] + me[0][1]))


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03244/Python/s099535148.py", line 14, in <module>
    mo2 = collections.Counter(odd).most_common()[1]
IndexError: list index out of range


Fixed submission:

import collections

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

s = len(set(v))
if s == 1:
    print(n // 2)
    exit()

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0]
mo2 = collections.Counter(odd).most_common()[1]
me = collections.Counter(even).most_common()[0]
me2 = collections.Counter(even).most_common()[1]

if mo[0] == me[0]:
    if me2[1] < mo2[1]:
        mo = mo2
    else:
        me = me2
print(abs((n // 2) - mo[1]) + abs((n // 2) - me[1]))
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common()
vb_ = Counter(vb).most_common()

if va_[0][0] == vb_[0][0]:
    if len(va_) == 1 or len(vb_) == 1:
        if len(va_) == 1 and len(vb_) == 1:
            print(len(v) // 2)
        elif len(va_) == 1:
            if va_[0][0] == vb_[0][0]:
                print(len(vb) - vb_[1][1])
            else:
                print(len(vb) - vb_[0][1])
        else:
            if va_[0][0] == vb_[0][0]:
                print(len(va) - va_[1][1])
            else:
                print(len(va) - va_[0][1])
        exit()
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])


Error: 0

Fixed submission:

from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common(2)
vb_ = Counter(vb).most_common(2)

if va_[0][0] == vb_[0][0]:
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
ans = 0
c_odd = Counter(v_odd)
c_even = Counter(v_even)
v_o, c_o = zip(*c_odd.most_common())
v_e, c_e = zip(*c_even.most_common())
if len(c_o) == 1:
    odd1 = 0
else:
    odd1 = c_o[1]
if len(c_e) == 1:
    even1 = 0
else:
    even1 = c_e[1]
if not v_o[0] == v_e[0]:
    print(sum(c_o) - c_o[0] + sum(c_e) - c_e[0])
else:
    ans = min(sum(c_o) - c_o[0] + sum(c_e) - even1, sum(c_o) - odd1 + sum(c_e) - c_e[0])
    print(ans)


Error: AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03244/Python/s850974654.py", line 4, in <module>
    v = list(map(int, input.split()))
AttributeError: 'builtin_function_or_method' object has no attribute 'split'


Fixed submission:

from statistics import mode

n = int(input())
v = list(map(int, input.split()))
a = v[::1]
b = v[1::1]
slash = mode(a)
back_slash = mode(b)
a = [i for i in a if i != slash]
b = [j for j in b if j != back_slash]
print(len(a) + len(b))
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

# coding:utf-8
import collections


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

    va = []
    vb = []
    for i in range(0, n, 2):
        va.append(v[i])
        vb.append(v[i + 1])

    if va == vb and len(set(va)) == 1:
        print(len(va))
        return

    c1mc = collections.Counter(va).most_common()
    c2mc = collections.Counter(vb).most_common()

    if c1mc[0][0] != c2mc[0][0]:
        print(n - c1mc[0][1] - c2mc[0][1])
        return

    else:
        a = n - c1mc[1][1] - c2mc[0][1]
        b = n - c1mc[0][1] - c2mc[1][1]

        if a < b:
            print(a)
        else:
            print(b)


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

# coding:utf-8
import collections


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

    va = []
    vb = []
    for i in range(0, n, 2):
        va.append(v[i])
        vb.append(v[i + 1])

    c1mc = collections.Counter(va).most_common()
    c2mc = collections.Counter(vb).most_common()

    if c1mc[0][0] != c2mc[0][0]:
        print(n - c1mc[0][1] - c2mc[0][1])
        return

    else:
        a = n - c1mc[1][1] - c2mc[0][1]
        b = n - c1mc[0][1] - c2mc[1][1]

        if a < b:
            print(a)
        else:
            print(b)


if __name__ == "__main__":
    main()
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]
# ndChar1, ndCount1 = c1.most_common()[1]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]
# ndChar2, ndCount2 = c2.most_common()[1]

if mostChar1 == mostChar2:
    if len(c1.most_common()) == 1 and len(c1.most_common()) == 1:
        ans = n // 2
    elif len(c1.most_common()) == 1:
        ndChar2, ndCount2 = c2.most_common()[1]
        ans = n - mostCount1 - ndCount2
    elif len(c2.most_common()) == 1:
        ndChar1, ndCount1 = c1.most_common()[1]
        ans = n - mostCount2 - ndCount1
    else:
        ndChar1, ndCount1 = c1.most_common()[1]
        ndChar2, ndCount2 = c2.most_common()[1]
        temp1 = n - mostCount1 - ndCount2
        temp2 = n - mostCount2 - ndCount1
        ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03244/Python/s429102895.py", line 17, in <module>
    ndChar1, ndCount1 = c1.most_common()[1]
IndexError: list index out of range


Fixed submission:

import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]
ndChar1, ndCount1 = c1.most_common()[1]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]
ndChar2, ndCount2 = c2.most_common()[1]

if mostChar1 == mostChar2:
    temp1 = n - mostCount1 - ndCount2
    temp2 = n - mostCount2 - ndCount1
    ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)
Problem p03244 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if len(set(v)) == 1:
    print(len(v) // 2)
elif c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))


Error: 0

Fixed submission:

from collections import Counter

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))
Problem p03244 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

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

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""要素出現数を集計"""
odd_count = Counter(v[1::2])
even_count = Counter(v[::2])

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common(5):
    # if max_hit > odd_hit:
    #     break  # もう最大値は更新されないので打ち止め
    for even_val, even_hit in even_count.most_common(5):
        # if max_hit > even_hit:
        #     break  # もう最大値は更新されないので打ち止め
        if odd_val == even_val:
            continue  # 数字は2種類ないとダメ
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)


Error: TLE

Fixed submission:

from collections import Counter
import itertools


n = int(input())
v = [int(i) for i in input().split()]

if len(set(v)) == 1:
    print(int(len(v) / 2))
    exit()

max_hit = 0
a_nums = [v[i] for i in range(0, len(v), 2)]
a_count = Counter(a_nums)
b_nums = [v[i] for i in range(1, len(v), 2)]
b_count = Counter(b_nums)
vals = [None, None]

for i, j in itertools.product(set(a_nums), set(b_nums)):
    if i == j:
        continue

    if a_count[i] + b_count[j] > max_hit:
        max_hit = a_count[i] + b_count[j]
        vals[0] = i
        vals[1] = j

fix = 0
for i, x in enumerate(v):
    if x != vals[i % 2]:
        fix += 1
print(fix)
Problem p03245 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s = set([(x + y) % 2 for x, y in xy])
if len(s) > 1:
    print(-1)
    exit(0)

d = []
w = ["" for _ in xy]
if s.pop() == 0:
    d = [1]
    w = ["L" for _ in xy]
    xy = [(x + 1, y) for x, y in xy]

b = 1
while True:
    if all(abs(x) + abs(y) == 1 for x, y in xy):
        d.append(b)
        for i in range(len(xy)):
            x, y = xy[i]
            if x > 0:
                w[i] += "R"
            elif x < 0:
                w[i] += "L"
            elif y > 0:
                w[i] += "U"
            else:
                w[i] += "D"
        break
    d.append(b)
    for i in range(len(xy)):
        x, y = xy[i]
        if x % 2 == 1:
            if y % 4 == 2 and (x - 1) % 4 == 0 or y % 4 == 0 and (x - 1) % 4 == 2:
                w[i] += "R"
                xy[i] = ((x - 1) // 2, y // 2)
            else:
                w[i] += "L"
                xy[i] = ((x + 1) // 2, y // 2)
        else:
            if x % 4 == 2 and (y - 1) % 4 == 0 or x % 4 == 0 and (y - 1) % 4 == 2:
                w[i] += "U"
                xy[i] = (x // 2, (y - 1) // 2)
            else:
                w[i] += "D"
                xy[i] = (x // 2, (y + 1) // 2)
    b *= 2

print(len(d))
print(*d)
for t in w:
    print(t)


Error: TLE

Fixed submission:

n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
d = []
s = ["" for _ in xy]
while True:
    p = [max(abs(x), abs(y)) for x, y in xy]
    q = [abs(x) + abs(y) for x, y in xy]
    if max(q) == 0:
        break
    elif max(q) == 1 and min(q) == 0:
        d = None
        break
    d.append((max(p) + min(p)) // 2)
    for i in range(len(xy)):
        x, y = xy[i]
        if p[i] == abs(x):
            if x > 0:
                s[i] += "R"
                xy[i] = (x - d[-1], y)
            else:
                s[i] += "L"
                xy[i] = (x + d[-1], y)
        else:
            if y > 0:
                s[i] += "U"
                xy[i] = (x, y - d[-1])
            else:
                s[i] += "D"
                xy[i] = (x, y + d[-1])

if d is None or len(d) > 40:
    print(-1)
else:
    print(len(d))
    print(*d)
    for t in s:
        print(t)
Problem p03246 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())
V = tuple(map(int, input().split()))
X, Y = Counter(), Counter()
for i in range(0, N):
    if i & 1:
        Y[V[i]] += 1
    else:
        X[V[i]] += 1
if len(X) != 1:
    x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:2]
else:
    x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:1]
if len(Y) != 1:
    y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:2]
else:
    y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:1]
if x[0][0] == y[0][0]:
    ans = N
    tmp = 0
    if len(y) == 1:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0] + 1:
                    tmp += 1
            else:
                if V[i] != x[0][0]:
                    tmp += 1
    else:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[1][0]:
                    tmp += 1
            else:
                if V[i] != x[0][0]:
                    tmp += 1
    ans = min(ans, tmp)
    tmp = 0
    if len(x) == 1:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0]:
                    tmp += 1
            else:
                if V[i] != x[0][0] + 1:
                    tmp += 1
    else:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0]:
                    tmp += 1
            else:
                if V[i] != x[1][0]:
                    tmp += 1
    ans = min(ans, tmp)
else:
    ans = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                ans += 1
        else:
            if V[i] != x[0][0]:
                ans += 1
print(ans)


Error: 0

Fixed submission:

from collections import Counter

N = int(input())
V = tuple(map(int, input().split()))
X, Y = Counter(), Counter()
for i in range(0, N):
    if i & 1:
        Y[V[i]] += 1
    else:
        X[V[i]] += 1
x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:2]
y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:2]
if x[0][0] == y[0][0]:
    ans = N
    tmp = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[1][0]:
                tmp += 1
        else:
            if V[i] != x[0][0]:
                tmp += 1
    ans = min(ans, tmp)
    tmp = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                tmp += 1
        else:
            if V[i] != x[1][0]:
                tmp += 1
    ans = min(ans, tmp)
else:
    ans = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                ans += 1
        else:
            if V[i] != x[0][0]:
                ans += 1
print(ans)
Problem p03250 (Python) — buggy submission, verdict: Runtime Error

a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + a + b + c)


Error: TypeError: sum() takes at most 2 arguments (3 given)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03250/Python/s348388771.py", line 2, in <module>
    print(max(a, b, c) * 9 + sum(a, b, c))
TypeError: sum() takes at most 2 arguments (3 given)


Fixed submission:

a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + sum(a, b, c))
Problem p03250 (Python) — buggy submission, verdict: Runtime Error

a, b, c = map(int, input().split())
print(max([a, b, c]) * 9 + sum([a, b, c]))


Error: TypeError: sum() takes at most 2 arguments (3 given)
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03250/Python/s838495112.py", line 2, in <module>
    print(max(a, b, c) * 9 + sum(a, b, c))
TypeError: sum() takes at most 2 arguments (3 given)


Fixed submission:

a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + sum(a, b, c))
Problem p03250 (Python) — buggy submission, verdict: Runtime Error

input_data = [int(i) for i in input().split(" ")]

ans = 0
for k1, v1 in enumerate(input_data):
    for k2, v2 in enumerate(input_data):
        for k3, v3 in enumerate(input_data):
            if k1 == k2 or k2 == k3 or k3 == k1:
                continue
            kou1 = int(str(v1) + str(v2))
            kou2 = v3
            if ans < kou1 + kou2:
                ans = kou1 + v3
print(ans)


Error: 0

Fixed submission:

input_data = [int(i) for i in input().split(" ")]

ans = 0
for k1, v1 in enumerate(input_data):
    for k2, v2 in enumerate(input_data):
        for k3, v3 in enumerate(input_data):
            if k1 == k2 or k2 == k3 or k3 == k1:
                continue
            kou1 = int(f"{v1}{v2}")
            if ans < kou1 + v3:
                ans = kou1 + v3
print(ans)
Problem p03251 (Python) — buggy submission, verdict: Runtime Error

# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))

print("No War" if xs < ys and x <= xs and ys <= y else "War")


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03251/Python/s312526263.py", line 7, in <module>
    n, m, x, y = map(int, input().split())
EOFError: EOF when reading a line


Fixed submission:

# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))
print("No War" if xs + 1 < ys else "War")
# max min
n, m, x, y = map(int, input().split())
xs = max(list(map(int, input().split())))
ys = min(list(map(int, input().split())))
print("No War" if xs + 1 <= ys else "War")
Problem p03252 (Python) — buggy submission, verdict: Time Limit Exceeded

S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
    if s in st and st[s] != t:
        print("No")
        exit()
    if t in ts and ts[t] != s:
        print("No")
        exit()
    st[s] = t
    ts[t] = s
print("Yes")


Error: TLE

Fixed submission:

S = input()
T = input()
n = len(S)
for i in range(n):
    s = S[i]
    t = T[i]
    S = S.translate(str.maketrans({s: t, t: s}))
if S == T:
    print("Yes")
else:
    print("No")
Problem p03252 (Python) — buggy submission, verdict: Time Limit Exceeded

# coding: utf-8

# https://atcoder.jp/contests/abc110


def main():
    S = input()
    T = input()
    N = len(S)

    memo1 = {}
    memo2 = {}
    for i in range(N):
        if S[i] not in memo1:
            memo1[S[i]] = T[i]
        else:
            if memo1[S[i]] != T[i]:
                return "No"
        if T[i] not in memo2:
            memo2[T[i]] = S[i]
        else:
            if memo2[T[i]] != S[i]:
                return "No"

    return "Yes"


print(main())


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-


def answer(S, T, N):
    i = 0
    while i < N:
        c1 = S[i]
        c2 = T[i]
        # print("c1:", str(c1))
        # print("c2:", str(c2))
        if c1 != c2:
            for j in range(N):
                # print([S[j], c1])
                # print([T[j], c2])
                if S[j] == c1 and T[j] != c2:
                    return False
        i += 1

    return True


S = list(input())
T = list(input())

N = len(S)

ST = [None] * N

for i in range(N):
    ST[i] = [S[i], T[i]]

ST.sort(key=lambda a_i: a_i[0])

for i in range(N):
    S[i] = ST[i][0]
    T[i] = ST[i][1]

ans1 = answer(S, T, N)

ST.sort(key=lambda a_i: a_i[1])

for i in range(N):
    S[i] = ST[i][0]
    T[i] = ST[i][1]

# print(S)
# print(T)

ans2 = answer(T, S, N)

if ans1 and ans2:
    print("Yes")
else:
    print("No")
Problem p03252 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict, Counter

S = input()
T = input()

d_s = defaultdict(int)
d_t = defaultdict(int)

no_flag = False
for s, t in zip(list(S), list(T)):
    d_s[s] += 1
    d_t[t] += 1

if sorted(d_s.values()) == sorted(d_t.values()):
    print("Yes")
else:
    print("No")


Error: TypeError: 'str' object does not support item assignment
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03252/Python/s005280607.py", line 12, in <module>
    S[i] = T[i]
TypeError: 'str' object does not support item assignment


Fixed submission:

from collections import defaultdict

S = input()
T = input()

d = defaultdict(str)

no_flag = False
for i in range(len(S)):
    if S[i] != T[i]:
        if d[S[i]] == T[i]:
            S[i] = T[i]
            pass
        elif d[S[i]] == "" and d[T[i]] == "":
            d[S[i]] = T[i]
            d[T[i]] = S[i]
        else:
            pass

S = sorted(S)
T = sorted(T)
if S == T:
    print("Yes")
else:
    print("No")