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

Fixed submission:
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
res = [[-1 for _ in range(W)] for _ in range(H)]
tmp = []
for i in range(N):
    for j in range(A[i]):
        tmp.append(i + 1)
        
for i in range(H):
    result = ''
    for j in range(W):
        if i%2 == 0:
            result = result + str(tmp[W * i + j])
            if j != W - 1:
                result = result + ' '
        else:
            result =  str(tmp[W * i + j]) + result
            if j != W - 1:
                result = ' ' + result 
            
    print(result)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
res = [[-1 for _ in range(W)] for _ in range(H)]

x = 0
y = 0
for i in range(N):
    if x + A[i] <= W:
        for j in range(A[i]):
            res[y][x + j] = i + 1
            
        x = x + A[i]
            
    else:
        for j in range(x, W):
            res[y][j] = i + 1
            
        y = y + 1
        
        for j in range(A[i] - (W - x) + 1):
            res[y][j] = i + 1
            
        x = 0
        
for i in range(H):
    result = ''
    for j in range(W):
        result =  result + str(res[i][j])
        if j != W - 1:
            result += ' '
        
    print(result)
Problem p03713 (python)

Fixed submission:
import math

H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    res = 10 ** 11
    for i in range(1, H):
        a = W*i
        b = math.ceil(W/2) * (H-i)
        m = W//2 * (H-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W):
        a = H*i
        b = math.ceil(H/2) * (W-i)
        m = H//2 * (W-i)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, H-1):
        a = W*i
        b = W * math.ceil((H-i)/2)
        m = W * ((H-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W-1):
        a = H*i
        b = H * math.ceil((W-i)/2)
        m = H * ((W-i)//2)
        res = min(res, max(a,b,m)-min(a,b,m))

               
    print(res)

Buggy submission (verdict: Runtime Error):
import math

H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    res = 10 ** 11
    for i in range(1, H):
        a = W*i
        b = math.ceil(W/2) * (H-i)
        m = W//2 * (H-i)

        res = min(res, max(a,b,m)-min(a,b,m))

    for i in range(1, W):
        a = H*i
        b = math.ceil(H/2) * (W-i)
        m = H//2 * (W-i)
        res = min(res, max(a,b,m)-min(a,b,m))

               
print(res)
Problem p03861 (python)

Fixed submission:
a, b, x = map(int, input().split())

def f(n, x):
    if n >= 0:
        return (n//x) + 1
    else:
        return 0

print(f(b, x) - f(a-1, x))

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

def f(n, x):
    if n >= 0:
        return int(n/x) + 1
    else:
        return 0

print(f(b, x) - f(a, n))

Buggy submission (verdict: Runtime Error):
import math
import numpy
a, b, x = map(uint64, input().split())

res = 0    
res += math.floor((b-a)/x)

if a%x == 0:
    res += 1

if b%x == 0:
    res += 1


print(res)
Problem p03937 (python)

Fixed submission:
H, W = map(int, input().split())
L = [input() for _ in range(H)]

count = 0
for i in range(H):
  for j in range(W):
    if L[i][j] == '#':
      count += 1
      
if count == W + H - 1:
  print('Possible')
else:
  print('Impossible')

Buggy submission (verdict: Runtime Error):
W, H = map(int, input().split())
L = [input() for _ in range(H)]

count = 0
for i in range(H):
  for j in range(W):
    if L[i][j] == '#':
      count += 1
      
if count == W + H - 1:
  print('Possible')
else:
  print('Impossible')
Problem p03998 (python)

Fixed submission:
A = input()
B = input()
C = input()

now = 'a'
a = 0
b = 0
c = 0

while True:
    if now == 'a':
        if a  == len(A):
            res = 'A'
            break
        now = A[a]
        a = a + 1
        
    elif now == 'b':
        if b  == len(B):
            res = 'B'
            break
        now = B[b]
        b = b + 1
        
    elif now == 'c':
        if c  == len(C):
            res = 'C'
            break
        now = C[c]
        c = c + 1

print(res)

Buggy submission (verdict: Runtime Error):
A = input()
B = input()
C = input()

now = A [0]
a = 1
b = 0
c = 0
while True:
    if now == 'a':
        if a + 1 == len(A):
            res = 'A'
            break
        now = A[a+1]
        a = a + 1
        
    if now == 'b':
        if b + 1 == len(B):
            res = 'B'
            break
        now = B[b+1]
        b = b + 1
        
    if now == 'c':
        if c + 1 == len(C):
            res = 'C'
            break
        now = C[c+1]
        c = c + 1

print(res)
Problem p04001 (python)

Fixed submission:
s = input()
n = len(s)
res = 0
for i in range(2**(n-1)):
    k = 0
    b = bin(i)[2:]
    for j in range(len(b)):
        if b[-(j+1)] == '1':
            res += int(s[k:j+1])
            k = j+1
    res += int(s[k:])

            
print(res)

Buggy submission (verdict: Runtime Error):
import itertools

def solve(S):
    '''
    数字の間に+を入れるパターンと入れないパターンを全てチェックする
    125であれば、 125, 1+25, 12+5, 1+2+5
    +が入る可能性のある場所は右の通り、 1  |ここ!| 2  |ここ!| 5
    よって、組み合わせは 2 ** (文字列数 - 1)
    '''
    count = 0
    bit_list = list(itertools.product([0, 1], repeat=len(S)-1))
    for pattern in bit_list:
            '''
            ビットの値が1の時に+が入ると考えて、0の時は入らない
            文字列を先頭から調べていき、次の文字との間に+が入る場合、そこまでの文字列をint型に変換して変数「count」に加算する
            
            '''
        start = 0
        for end in range(len(pattern)):
            if pattern[end] == 1:
                count += int(S[start:end+1])
                start = end + 1
                
            if end == len(bit) - 1:
                count += int(S[start:])
                
    print(count)


if __name__ == '__main__':
    S = input()
    solve(S)
Problem p03023 (python)

Fixed submission:
N = (int)(input())
print((N-2)*180)

Buggy submission (verdict: Runtime Error):
N = input()
print((N-2)*180)
Problem p02801 (python)

Fixed submission:
print(chr(ord(input()) + 1))

Buggy submission (verdict: Runtime Error):
import math

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

arr = list(sorted(map(int, input().split())))

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

result = 0
for i, e in enumerate(arr):
    result += e * (comb(i, k - 1) - comb(n - i - 1, k - 1))
    result %= const

print(result)
Problem p02843 (python)

Fixed submission:
x = int(input())

res = [False for i in range(x + 1)]
res[0] = True
for i in range(100, 106):
    if x < i:
        break
    res[i] = True

for i in range(106, x + 1):
    res[i] = res[i-100] or res[i-101] or res[i-102] or res[i-103] or res[i-104] or res[i-105]

if res[x]:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
x = int(input())

res = [False for i in range(x + 1)]
res[0] = True
for i in range(100, 106):
    res[i] = True

for i in range(106, x + 1):
    res[i] = res[i-100] or res[i-101] or res[i-102] or res[i-103] or res[i-104] or res[i-105]

if res[x]:
    print(1)
else:
    print(0)
Problem p02900 (python)

Fixed submission:
import math

a, b = map(int, input().split())

tmpA = max(a, b)
tmpB = min(a, b)

while tmpB != 0:
    newB = tmpA % tmpB
    tmpA = tmpB
    tmpB = newB

tmp = tmpA
res = 1

for i in range(2, int(math.sqrt(tmp)) + 1):
    if tmp % i == 0:
        res += 1
        tmp //= i
    else:
        continue

    while tmp % i == 0:
        tmp = tmp//i


if tmp != 1:
    res += 1

print(res)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
 
tmpA = max(a, b)
tmpB = min(a, b)
 
while tmpB != 0:
    newB = tmpA % tmpB
    tmpA = tmpB
    tmpB = newB
 
tmp = tmpA

ass = []
for i in range(2,int(tmp**0.5)+1):
    while tmp % i==0:
        ass.append(i)
        tmp = tmp//i
if tmp != 1:
    ass.append(n)

print(len(set(ass)) + 1)
Problem p03294 (python)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
lcm = 0
for e in arr:
    lcm += e - 1
print(lcm)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


n = int(input())
arr = list(map(int, input().split()))
lcm = 1
for e in arr:
    lcm = int(lcm * e / gcd(lcm, e))
lcm -= 1
res = 0
for e in arr:
    res += lcm % e
print(res)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
arr = list(map(int, input().split()))
lcm = 1
for e in arr:
    lcm = int(lcm * e / math.gcd(lcm, e))
lcm -= 1
res = 0
for e in arr:
    res += lcm % e
print(res)
Problem p03354 (python)

Fixed submission:
def ge(x):
    return int(x) - 1


(n, m) = tuple(map(int, input().split()))
inp = list(map(ge, input().split()))
arr = [i for i in range(n)]


def root(a):
    global arr
    if arr[a] == a:
        return a
    else:
        tmp = root(arr[a])
        arr[a] = tmp
        return tmp


def sameroot(x, y):
    return root(x) == root(y)


def merge(x, y):
    global arr
    if not sameroot(x, y):
        arr[root(y)] = root(x)


for i in range(m):
    merge(*tuple(map(ge, input().split())))

res = 0
for i in range(n):
    if sameroot(i, inp[i]):
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
(n, m) = list(map(int, input().split()))
p = list(map(int, input().split()))
cG = []
for i in range(0, m):
    e = list(map(int, input().split()))
    do = []
    for c in cG:
        if e[0] in c or e[1] in c:
            if not do == []:
                mix = do + c
                cG.remove(do)
                cG.remove(c)
                cG.append(mix)
                break
            else:
                do = c
        if e[0] in c:
            c.append(e[1])
        elif e[1] in c:
            c.append(e[0])
    if len(do) == 0:
        cG.append(e)

res = 0
bebe = [-1] * n
for i, c in enumerate(cG):
    for e in c:
        bebe[e - 1] = i

for i in range(n):
    if bebe[i] == bebe[p[i] - 1]:
        re += 1

print(res)

Buggy submission (verdict: Runtime Error):
(n, m) = list(map(int, input().split()))
p = list(map(int, input().split()))
cG = []
for i in range(0, m):
    e = list(map(int, input().split()))
    do = []
    for c in cG:
        if e[0] in c or e[1] in c:
            if not do == []:
                mix = do + c
                cG.remove(do)
                cG.remove(c)
                cG.append(mix)
                break
            else:
                do = c
        if e[0] in c:
            c.append(e[1])
        elif e[1] in c:
            c.append(e[0])
    if len(do) == 0:
        cG.append(e)

res = 0
bebe = [-1] * n
for c, i in enumerate(cG):
    for e in c:
        bebe[e - 1] = i

for i in range(n):
    if bebe[i] == bebe[p[i] - 1]:
        re += 1

print(res)
Problem p03378 (python)

Fixed submission:
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for e in k:
    if int(e) >= X:
        j = k.index(e)
        break
    cost1 = cost1 + 1

for i in range(j, M):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost2)
else:
    print(cost1)

Buggy submission (verdict: Runtime Error):
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for (e in k):
    if int(e) >= X:
        j = k.index(e)
    cost1 = cost1 + 1

for (i in range(j, M)):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost1)
else:
    print(cost2)
Problem p03050 (python)

Fixed submission:
def solve(N):
    s = 1
    e = int(pow(N, 0.5)) + 1
    ds = []
    for i in range(s, e):
        if N % i == 0:
            m = (N // i) - 1
            if m and N // m == N % m:
                ds.append(N // i)
                # print(f"{N} = {m} * {N // m} + {N % m}")

    return sum([i - 1 for i in ds])


assert (solve(8) == 3 + 7)
assert (solve(10) == 4 + 9)
assert (solve(1000000000000) == 2499686339916)
if __name__ == "__main__":
    N = int(input())
    print(solve(N))

Buggy submission (verdict: Runtime Error):
def solve(N):
    s = 1
    e = int(pow(N, 0.5)) + 1
    ds = []
    for i in range(s, e):
        if N % i == 0:
            m = N // i - 1
            if N // m == N % m:
                ds.append(N // i)

    return sum([i - 1 for i in ds])

if __name__ == "__main__":
    N = int(input())
    print(solve(N))
Problem p03085 (python)

Fixed submission:
if __name__ == "__main__":
    b = input()
    if b == "A":
        print("T")
    if b == "T":
        print("A")
    if b == "C":
        print("G")
    if b == "G":
        print("C")

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    b = tuple(map(int, input().split(" ")))
    if b == "A":
        print("T")
    if b == "T":
        print("A")
    if b == "C":
        print("G")
    if b == "G":
        print("C")
Problem p03214 (python)

Fixed submission:
def solve(N, As):
    avg = sum(As) / N
    return min([(abs(c - avg), i) for i, c in enumerate(As)])[1]

if __name__ == "__main__":
    N = int(input())
    As = [int(c) for c in input().split()]
    print(solve(N, As))

Buggy submission (verdict: Runtime Error):



def solve(N, K, As):
    alls = []
    for i in range(N):
        for j in range(i + 1, N + 1):
            alls.append("{:061b}".format(sum(As[i:j])))
    print("alls", len(alls))
    def find(i, alls):
        if i > 60:
            return []
        ones = [a for a in alls if a[i] == "1"]
        if len(ones) < K:
            return find(i + 1, alls)
        elif len(ones) == K:
            return ones
        elif len(ones) > K:
            ret = find(i + 1, ones)
            if len(ret) == 0:
                return ones[0:K]
            else:
                return ret

    ans = find(0, alls)
    if len(ans):
        a = 0xFFFFFFFFFFF
        for p in ans:
            a &= int(p, 2)
        return a
    else:
        return 0

if __name__ == "__main__":
    l = input()
    N = int(l.split(" ")[0])
    K = int(l.split(" ")[1])
    As = [int(c) for c in input().split()]
    print(solve(N, K, As))
Problem p03244 (python)

Fixed submission:
import collections
 
n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a).most_common(2)
bc = collections.Counter(b).most_common(2)
if ac[0][0] != bc[0][0]:
    print(n - ac[0][1] - bc[0][1])
else:
    if len(ac) == 1:
        print(n // 2)
    else:
        print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

Buggy submission (verdict: Runtime Error):
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter(V[1::2])
    even = Counter(V[::2])

    even_max = even.most_common(2)
    odd_max = odd.most_common(2)

    if odd_max[0][0] != even_max[0][0]:
        return n - odd_max[0][0] - even_max[0][0]
    elif len(odd_max[0][0]) != 1 and len(even_max[0][0]) == 1:
        return n - odd_max[1][0] - even_max[0][1]
    elif len(odd_max[0][0]) == 1 and len(even_max[0][0]) != 1:
        return n - odd_max[0][1] - even_max[1][1]
    else:
        return n - max(even_max[0][1] + odd_max[1][1],
                       even_max[1][1] + odd_max[0][1])

if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Buggy submission (verdict: Runtime Error):
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        return n - odd_maxs[0][0] - even_maxs[0][0]
    elif odd_2nd_max != None and even_2nd_max == None:
        return n - odd_maxs[1][0] - even_maxs[0][1]
    elif odd_2nd_max == None and even_2nd_max != None:
        return n - odd_maxs[0][1] - even_maxs[1][1]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        return n - max(even_maxs[0][1] + odd_maxs[1][1], 
                       even_maxs[1][1] + odd_maxs[0][1])

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))
Problem p03262 (python)

Fixed submission:

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    ans = min(dists)
    for d in dists:
        if d % ans == 0:
            continue
        else:
            ans = gcd(ans, d % ans)
    return ans

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Buggy submission (verdict: Runtime Error):
import math
def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    gcd = min(dists)
    for d in dists:
        if d % gcd == 0:
            continue
        else:
            gcd = math.gcd(gcd, d % gcd)
    return gcd

  
if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Buggy submission (verdict: Runtime Error):
import math
def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    gcd = min(dists)
    for d in dists:
        if d % gcd == 0:
            continue
        else:
            gcd = math.gcd(gcd, d)
    return gcd

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Buggy submission (verdict: Runtime Error):
import math
def solve(N, X, cities):
    dists = [abs(city - X) for city in cities]
    min_d = min(dists)
    return max([math.gcd(min_d, d) for d in dists])

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))

Buggy submission (verdict: Runtime Error):
import math
def solve(N, X, cities):
    dists = [city - X for city in cities]
    gcd = dists[0]
    for d in dists[1:]:
        gcd = math.gcd(gcd, d)
    return gcd

if __name__ == "__main__":
    l = input()
    N, X = int(l.split()[0]),int(l.split()[1])
    cities = [int(c) for c in input().split()]
    print(solve(N, X, cities))
Problem p03263 (python)

Fixed submission:
def solve(H, W, field):
    ret = []
    for y in range(0, H):
        for x in range(0, W):
            if field[y][x] % 2 == 1:
                for (xi, yi) in [(x + 1, y), (x, y + 1)]:
                    if 0 <= xi < W and 0 <= yi < H:
                            ret.append(" ".join([str(y + 1), str(x + 1), str(yi + 1), str(xi + 1)]))
                            field[y][x] -= 1
                            field[yi][xi] += 1
                            break
    return [len(ret)] + ret


if __name__ == "__main__":
    l = input()
    H, W = int(l.split()[0]), int(l.split()[1])
    field = [[int(c) for c in input().split(" ")] for _ in range(0, H)]
    [print(l) for l in solve(H, W, field)]

Buggy submission (verdict: Runtime Error):
def solve(H, W, field):
    ret = []
    operated = set()
    for y in range(0, H):
        for x in range(0, W):
            if field[y][x] % 2 == 0:
                continue
            else:
                for (xi, yi) in [(x + 1, y), (x, y + 1)]:
                    if 0 <= xi < W and 0 <= yi < H:
                        ret.append(" ".join([str(y + 1), str(x + 1), str(yi + 1), str(xi + 1)]))
                    field[yi][xi] += 1
                    field[y][x] -= 1
                    break
    return [len(ret)] + ret

if __name__ == "__main__":
    l = input()
    H, W = int(l.split()[0]), int(l.split()[1])
    field = [[int(c) for c in input().split(" ")] for _ in range(0, H)]
    [print(l) for l in solve(H, W, field)]

Buggy submission (verdict: Runtime Error):
def solve(H, W, field):
    ret = []
    operated = set()
    for y in range(0, H):
        for x in range(0, W):
            if field[y][x] % 2 == 0:
                continue
            else:
                for (xi, yi) in [(x + 1, y), (x, y + 1)]:
                    if 0 <= xi < W and 0 <= yi < H:
	                    ret.append(" ".join([str(y + 1), str(x + 1), str(yi + 1), str(xi + 1)]))
                        field[yi][xi] += 1
                        field[y][x] -= 1
                        break
 
    return [len(ret)] + ret
Problem p03266 (python)

Fixed submission:
def solve(N, K):
    ans = 0
    k = len([n for n in range(1, N + 1) if n % K == 0])
    ans += k * k * k
    if K % 2 == 0:
        k = len([n for n in range(1, N + 1) if n % K == K // 2])
        ans += k * k * k

    return ans

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    print(solve(N, K))

Buggy submission (verdict: Runtime Error):
def solve(N, K):
    ans = 0
    k = len([n for n in range(1, N + 1) if n % K == 0])
    ans += k * k * k
    if K % 2 == 0:
        k = len([n for n in range(1, N + 1) if n % K == K // 2])
        ans += k * k * k

    return ans

if __name__ == "__main__":
    N, K = tuple(map(int, input(" ")))
    print(solve(N, K))
Problem p03325 (python)

Fixed submission:
def solve(N, As):
    def f(n):
        c = 0
        while n % 2 == 0:
            c += 1
            n //= 2
        return c
    return sum([f(a) for a in As])


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Buggy submission (verdict: Runtime Error):
def solve(N, As):
    def f(n):
        c = 0
        while n % 2 == 0:
            c += 1
            n //= 2
        return c
    return sum([f(a) for a in As])


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N))
Problem p03575 (python)

Fixed submission:
def solve(N, M, ABs):
    ans = 0
    for i in range(M):
        adjMat = [[0 for _ in range(N)] for _ in range(N)]
        for k, (a, b) in enumerate(ABs):
            if k != i:
                adjMat[a - 1][b - 1] = 1
                adjMat[b - 1][a - 1] = 1

        def dps(a, visited):
            n = [i for i, b in enumerate(adjMat[a]) if b == 1]
            for nn in n:
                if nn not in visited:
                    visited.append(nn)
                    dps(nn, visited)
            return visited

        visited = dps(0, [])
        if len(visited) != N:
            ans += 1
    return ans


if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print(solve(N, M, ABs))

Buggy submission (verdict: Runtime Error):
def solve(N, M, ABs):
    ans = 0
    for i in range(M):
        m = {j: j for j in range(M)}
        for k, (a, b) in enumerate(ABs):
            a -= 1
            b -= 1
            if k == i:
                continue
            d = min(m[a], m[b])
            for mk in m:
                if m[mk] == m[a] or m[mk] == m[b]:
                    m[mk] = d
        if len(set(m.values())) != 1:
            ans += 1
    return ans

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print(solve(N, M, ABs))