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

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())

lcm = c*d // gcd(c,d)

def calc(x):
    return x-(x//c)-(x//d)+(x//lcm)

print(calc(b)-calc(a-1))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

lcm = c*d // math.gcd(c,d)

def calc(x):
    return x-(x//c)-(x//d)+(x//lcm)

print(calc(b)-calc(a-1))
Problem p03773 (python)

Fixed submission:
A,B = [int(i) for i in input().split()]

hour = (A + B) % 24

print(hour)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N,A,B = [int(i) for i in input().split()]

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

if v[-A] != v[-A-1]:
    print(sum(v[-A:]) / A)
    print(1)
elif v[-1] :
    # AAと同じ数のカウント
    # Aよりも大きい数のカウント
    cnt = 0
    bigger = 0
    for i in range(N):
        if v[A] < v[i]:
            bigger += 1
        if v[i] == v[A]:
            cnt += 1

    ans = 0
    mini = min(B, cnt+bigger)
    for i in range(A,mini):
        ans += len(list(combinations(range(cnt), i - bigger)))

    print(sum(v[-A:]) / A)
    print(ans)
Problem p03297 (python)

Fixed submission:
def main():
    import math

    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(input())
    ABCD = [list(map(int, input().split())) for i in range(N)]
    for A,B,C,D in ABCD:
        # 在庫が買う本数以下 or 在庫追加が買う本数以下
        if A < B or D < B:
            print("No")
            continue

        A %= B
        # 在庫が買う本数以下になり、補給出来ない
        if C < A:
            print("No")
            continue
        if B == D:
            print("Yes")
            continue

        flag = True
        #print((B-A-1)%(D-B) ,">", (B-1)-(C+1))
        if (B-A-1)%(gcd(D,B)) <= (B-1)-(C+1):
            flag = False
        
        print("Yes" if flag else "No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import math

    def lcm(x, y):
        return (x * y) // math.gcd(x, y)
    N = int(input())
    ABCD = [list(map(int, input().split())) for i in range(N)]
    for A,B,C,D in ABCD:
        # 在庫が買う本数以下 or 在庫追加が買う本数以下
        if A < B or D < B:
            print("No")
            continue

        A %= B
        # 在庫が買う本数以下になり、補給出来ない
        if C < A:
            print("No")
            continue
        if B == D:
            print("Yes")
            continue

        flag = True
        #print((B-A-1)%(D-B) ,">", (B-1)-(C+1))
        if (B-A-1)%(math.gcd(D,B)) <= (B-1)-(C+1):
            flag = False
        
        print("Yes" if flag else "No")


if __name__ == '__main__':
    main()
Problem p03309 (python)

Fixed submission:
from collections import Counter

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

N = int(input())
A = list(map(int, input().split()))

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)

if N==1:
    print(0)

elif N==2:
    print(sum(map(abs,map(lambda x:x-min(A2),A2))))

else:
    pl = count(mapdict(A2[N//2 +1],Adic))
    mn = count(mapdict(A2[N//2 -1],Adic))
    if pl<=res:
        tmp = pl
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 + tmpc > N-1:
                break
            res = tmp
            Adic = mapdict(A2[N//2 +tmpc], Adic)
            tmp = count(Adic)
    elif mn<=res:
        tmp = mn
        tmpc = 1
        while tmp <= res:
            tmpc += 1
            if N//2 - tmpc < 0:
                break
            res = tmp
            Adic = mapdict(A2[N//2 -tmpc], Adic)
            tmp = count(Adic)

    print(res)

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

def mapdict(n, dictionary):
    return dict(map(lambda t:(t[0]-n,t[1]), dictionary.items()))

def count(dic):
    count = 0
    for k,v in dic.items():
        count += abs(k*v)
    return count

N = int(input())
A = list(map(int, input().split()))

A2 = sorted([A[i-1]-i for i in range(1,N+1)])


Adic = Counter(A2)
Ax  = A2[N//2]
Adic = mapdict(Ax, Adic)

res = count(Adic)
pl = count(mapdict(A2[N//2 +1],Adic))
mn = count(mapdict(A2[N//2 -1],Adic))


if pl<=res:
    tmp = pl
    tmpc = 1
    while tmp <= res:
        tmpc += 1
        if N//2 + tmpc > N-1:
            break
        res = tmp
        Adic = mapdict(A2[N//2 +tmpc], Adic)
        tmp = count(Adic)
        

elif mn<=res:
    tmp = mn
    tmpc = 1
    while tmp <= res:
        tmpc += 1
        if N//2 - tmpc < 0:
            break
        res = tmp
        Adic = mapdict(A2[N//2 -tmpc], Adic)
        tmp = count(Adic)

print(res)
Problem p03324 (python)

Fixed submission:
D, N = map(int, input().split())


if D==2:
    dp = [10000*i for i in range(1,10010)]
    print(dp[N-1] if N!=100 else dp[N])
elif D==1:
    dp = [100*i for i in range(1,10010)]
    print(dp[N-1] if N!=100 else dp[N])
else:
    print(N if N!=100 else 101)

Buggy submission (verdict: Runtime Error):
D, N = map(int, input().split())


if D==2:
    dp = [10000*i for i in range(1,10010)]
    print(dp[N-1] N!=100 else dp[N])
elif D==1:
    dp = [100*i for i in range(1,10010)]
    print(dp[N-1] N!=100 else dp[N])
else:
    print(N if N!=100 else 101)
Problem p03328 (python)

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

sa = abs(b-a)
tmp1 = 0
for i in range(1,1000):
    tmp2 = int(i*(i+1)/2)
    if tmp2 - tmp1 == sa:
        print(tmp1 - a)
        sys.exit()
    tmp1 = tmp2
print(1)

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

ls = [0]*999
for i in range(999):
    ls[i] = int(i*(i+1)/2)

sa = abs(b-a)
for i in range(999):
    if ls[i+1]-ls[i] == sa:
        print(ls[i] - a)
        break
Problem p03340 (python)

Fixed submission:
n = int(input())
*A, = map(int, input().split())

result,right,asum=0,0,0
for left in range(n):
    for r in range(right,n):
        if asum&A[right]:
            break
        asum|=A[right]
        right += 1
    asum -= A[left]
    result += right-left
print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

ans, anstmp = 0
tmp = 0
head = 0
for n1, i in enumerate(A):
    if tmp^i == tmp+i:
        anstmp += 1
        tmp ^= i
    else:
        ans += anstmp 
        for j in A[head:]:
            tmp - A[0]
            anstmp -= 1
            head += 1
            if tmp^i == tmp+i:
                anstmp += 1
                break
print(ans)
Problem p03354 (python)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):

        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [map(int,input().split()) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):

        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):

        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [(*map(int,input().split()),) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        self.par = [i for i in range(n)]
        # 木の高さを格納する（初期状態は0）
        self.rank = [0] * (n)
    
    def find(self, x):
        """検索"""
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        # 根でないなら、親の要素で再検索
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """併合"""
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        """同じ集合に属するか判定"""
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
*p, = map(int, input().split())
xy = [(*map(int,input().split()),) for _ in range(M)]
result = 0

union = UnionFind(N)
for x,y in xy:
    union.union(x-1,y-1)

for i in p:
    if union.same_check(p[i-1]-1,i-1):
        result += 1

print(result)
Problem p03355 (python)

Fixed submission:
s = input()
K = int(input())
ls = []

for i in range(1,K+1):
    for j in range(len(s)):
        ls.append(s[j:j+i])
print(sorted(set(ls))[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(sorted(list(set([s[i:j+1] for i in range(len(s)) for j in range(i,len(s))])))[int(input())-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
print(sorted(list(set([s[i:j+1] for i in range(len(s)) for j in range(i,len(s))])))[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
ls = []
for i in range(1,len(s)+1):
    for j in range(i,len(s)+1):
        tmp = s[i:j]
        if tmp != "":
            ls.append(s[i:j])
print(sorted(list(set(ls)))[K-1])
Problem p03415 (python)

Fixed submission:
c1 = input()
c2 = input()
c3 = input()

print(c1[0]+c2[1]+c3[2])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

if N==1 or M==1:
    if N==M==1:
        print(0)
    else:
        if N<M:
            N,M = M,N
        print(N-2)

else:
    print((N*M) - N*2 - M*2 + 4)
Problem p03487 (python)

Fixed submission:
from collections import Counter
input()
a = map(int,input().split())

result = 0
for k, v in Counter(a).items():
    if k > v:
        result += v
    elif k < v:
        result += v-k
print(result)

Buggy submission (verdict: Runtime Error):
input()
ls = list(map(int,input().split()))
for i in set(ls):
    while True:
        if ls.count(i) == 0 or ls.count(i) == i:
            break
        ls.remove(i)
        n += 1
print(n)

Buggy submission (verdict: Runtime Error):
input()
ls = list(map(int,input().split()))
for i in set(ls):
    while True:
        if ls.count(i) == 0 or ls.count(i) == i:
            break
        ls.remove(i)
        n += 1
Problem p03549 (python)

Fixed submission:
N, M = map(int, input().split())
print((1900*M + 100*(N-M))*2**M)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
print((1900*M + 100(N-M))*2**M)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
print((1900*M + 100(N-M))*2**M)
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a%b
	return a
def lcm(a, b):
	return a*b // gcd(a, b)
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
result = ls[0]
for i in ls[1:]:
    result = lcm(i,result)
print(result)

Buggy submission (verdict: Runtime Error):
import math
def lcm(a, b):
	return a*b // math.gcd(a, b)
n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
result = ls[0]
for i in ls[1:]:
    result = lcm(i,result)
print(result)
Problem p03854 (python)

Fixed submission:
import sys
S = input()[::-1]
ls = ["maerd", "remaerd", "esare", "resare"]
n = 0
while n != len(S):
    flag = False
    for i in ls:
        tmp_n = len(i)
        if S[n:n+tmp_n] == i:
            n += len(i)
            flag = True
            break
    if not flag:
        print("NO")
        sys.exit()
print("YES")

Buggy submission (verdict: Runtime Error):
import sys
S = input()
S = S.split("er")



for s in S:
    if s not in {'asedream', 'dream', 'as'}:
        if s != '':
            print("NO")
            sys.exit()
    else:
        flag = False
    if s == "":
        if flag:
            print("NO")
            sys.exit()
        flag = True

print("YES")
Problem p02713 (python)

Fixed submission:
from functools import reduce
import math
import sys
 
K = int(input())
 
def gcd(*args):
  return reduce(math.gcd, args)
 
if K==1:
  print("1")
  sys.exit()
elif K==2:
  print("9")
  sys.exit()
 
ans = K * (K+1)//2
for i in range(1,K):
  for j in range(i+1,K+1):
    ans += 6*math.gcd(i,j)
  
for i in range(1,K-1):
  for j in range(i+1, K):
    for k in range(j+1, K+1):
      ans += 6 * gcd(i,j,k)
      
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
import math
import sys

K = int(input())

def gcd(*args):
  return reduce(math.gcd, args)

if K==1:
  print("1")
elif K==2:
  print("9")
  sys.exit()

ans = math.sum(K)
for i in range(1,K):
  for j in range(i+1,K+1):
    ans += 6*math.gcd(i,j)
  
for i in range(1,K-1):
  for j in range(i+1, K):
    for k in range(j+1, K+1):
      ans += 6 * gcd(i,j,k)
      
print(ans)
Problem p02887 (python)

Fixed submission:
N = int(input())
S = input()

ans = 1

for i in range(N-1):
  if S[i] != S[i +1]:
    ans += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))

ans = 0

for i in range(N-2):
  for j in range((i+1),N-1):
    for k in range((j+1),N):
      print("i=",i)
      print("j=",j)
      print("k=",k)
      if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[j] + L[i]:
        ans += 1
          

    
print(ans)
Problem p02917 (python)

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
 
def A(N,B):
   sum = B[0] + B[N-2]
   for i in range(N-2):
       sum += min(B[i],B[i+1])
   print(sum)
 
if __name__=='__main__':
   A(N,B)

Buggy submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split())

def A(N,B):
   sum = B[0] + B[N]
   for i in range(N-1):
       sum += min(B[i],B[i+1])
   print(sum)

if __name__='__main__':
   A(N,B)
Problem p02811 (python)

Fixed submission:
a,b = map(int, input().split())
rest = a*500

if rest >= b:
   ans = "Yes"
else:
   ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
if rest >= b:
   print('Yes')
else:
   print('No')
Problem p02995 (python)

Fixed submission:
from fractions import gcd
# def gcd(x, y):
#     while(y != 0):
#         temp = y
#         y = x%y
#         x = temp
#     return y

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    a, b = sorted([a, b])
    while(b != 0):
        a, b = (b, a%b)
    return b

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))

Buggy submission (verdict: Runtime Error):
import math
# def gcd(x, y):
#     while(y != 0):
#         temp = y
#         y = x%y
#         x = temp
#     return y

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//math.gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))

Buggy submission (verdict: Runtime Error):
from math import gcd

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))

Buggy submission (verdict: Runtime Error):
from math import gcd

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))
Problem p03231 (python)

Fixed submission:
def gcd(a, b):
    c = a%b
    while(c != 0):
        a = b
        b = c
        c = a%b
    return b

def answer(s, t):
    a = len(s)
    b = len(t)
    if s[0] != t[0]:
        return -1
    if a < b:
        temp = a
        a = b
        b = temp
        temp = s
        s = t
        t = temp
    gcdAB = gcd(a, b)
    if gcdAB == 1:
        return a*b
    else:
        stack = 0
        sl = (gcdAB * (a//gcdAB) * (b//gcdAB))
        aJump = sl//a
        bJump = sl//b
        for i in range(b):
            if stack%aJump == 0:
                if s[stack//aJump] != t[i]:
                    return -1
            stack = bJump*(i+1)
        return sl
                

sl, tl = map(int, input().split())
s = input()
t = input()
print(answer(s, t))

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

def answer(s, t):
    a = len(s)
    b = len(t)
    if a[0] != b[0]:
        return -1
    if a < b:
        temp = a
        a = b
        b = temp
    gcdAB = gcd(a, b)
    if gcdAB == 1:
        return a*b
    else:
        stack = 0
        sl = (gcdAB * (a//gcdAB) * (b//gcdAB))
        aJump = sl//a
        bJump = sl//b
        for i in range(b):
            if stack%aJump == 0:
                if s[stack//aJump] != t[i]:
                    return -1
            stack = bJump*(i+1)
        return sl
                

sl, tl = map(int, input().split())
s = input()
t = input()
print(answer(s, t))

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

def answer(s, t):
    a = len(s)
    b = len(t)
    if a < b:
        temp = a
        a = b
        b = temp
    gcdAB = gcd(a, b)
    if gcdAB == 1:
        return a*b
    else:
        stack = 0
        sl = (gcdAB * (a//gcdAB) * (b//gcdAB))
        for i in range(gcdAB):
            if s[stack//gcdAB] != t[stack//(sl//b)]:
                return -1
            stack += a
        return a*gcdAB

sl, tl = map(int, input().split())
s = input()
t = input()
print(answer(s, t))

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

def answer(s, t):
    a = len(s)
    b = len(t)
    if a < b:
        temp = a
        a = b
        b = temp
    gcdAB = gcd(a, b)
    if gcdAB == 1:
        return a*b
    else:
        stack = 0
        c = (a*gcdAB)//b
        for i in range(b):
            if s[i+stack] != t[i]:
                return -1
            stack += c
        return a*gcdAB

sl, tl = map(int, input().split())
s = input()
t = input()
print(answer(s, t))
Problem p03534 (python)

Fixed submission:
import collections

def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()], reverse=True)
    if len(vals) == 1:
        if vals[0] == 1: return YES
        else: return NO
    elif len(vals) == 2:
        if vals[0] == 1 and vals[1] == 1: return YES
        else: return NO
    
    _max = vals[0]
    _sum = sum(vals[1:])
    if (_max-1)*2 <= _sum:
        if vals[1]-vals[2] > 1: return NO
        else: return YES
    return NO

s = input()
print(answer(s))

Buggy submission (verdict: Runtime Error):
def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()], reverse=True)
    if len(vals) == 1: return YES
    elif len(vals) == 2:
        if vals[0] == 1 and vals[1] == 1: return YES
        else: return NO
    
    _max = vals[0]
    _sum = sum(vals[1:])
    if (_max-1)*2 <= _sum:
        if vals[1]-vals[2] > 1: return NO
        else: return YES
    return NO
s = input()
print(answer(s))

Buggy submission (verdict: Runtime Error):
import collections

def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()])
    _max = vals[0]
    print(_max
    if _max < 2:
        return YES
    if len(keys) == 2:
        return NO
    if (_max-1)*2 > sum(vals[1:]):
        return YES
    if (_max-1)*2 == sum(vals[1:]):
        if _max == vals[1]:
            return NO
        return YES
s = input()
print(answer(s))
Problem p03645 (python)

Fixed submission:
def answer(destination, services):
    P, M = ("POSSIBLE", "IMPOSSIBLE")
    dic = {}
    for a, b in services:
        if dic.get(a) is None:
            dic[a] = [b]
        else:
            dic[a].append(b)
        if dic.get(b) is None:
            dic[b] = [a]
        else:
            dic[b].append(a)
    if dic.get(destination) is None: return M
    arr = dic[destination]
    for i in arr:
        if 1 in dic[i]:
            return P
    return M

n, m = map(int, input().split())
services = []
for _ in range(m):
    a, b = map(int, input().split())
    services.append((a, b))
print(answer(n, services))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
P, M = ("POSSIBLE", "IMPOSSIBLE")
dic = {}
for _ in range(m):
    a, b = map(int, input().split())
    if dic.get(a) is None: dic[a] = [b]
    else: dic[a] = dic[a] + [b]
    if dic.get(b) is None: dic[b] = [a]
    else: dic[b] = dic[b] + [a]
if dic.get(n) is None: print(M)
arr = dic[n]
for i in arr:
    if 1 in dic[i]: print(P)