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

Fixed submission:
N, M = [int(i) for i in input().split()]
di = {}
flag = True
for _ in range(M):
    s, c = [int(i) for i in input().split()]
    if(s in di):
        if(di[s] != c):
            print(-1)
            flag = False
            break
    else:
        di[s] = c

if(1 in di):
    if(di[1]==0):
        if(N==1):
            print(0)
        else:
            print(-1)
        flag = False

if(N==1 and M==0):
    print(0)
    flag=False

if(flag):
    for i in range(10**(N-1), 10**N):
        x = str(i)
        ok = True
        for ind, s in enumerate(x):
            if(ind+1 in di):
                if(di[ind+1] != int(s)):
                    ok = False
                    continue
        if(ok):
            print(i)
            break
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
di = {}
flag = True
for _ in range(M):
    s, c = [int(i) for i in input().split()]
    if(s in di):
        if(di[s] != c):
            print(-1)
            flag = False
            break
    else:
        di[s] = c

if(1 in di):
    if(di[1]==0):
        print(-1)
        break

if(flag):
    for i in range(10**(N-1), 10**N):
        x = str(i)
        ok = True
        for ind, s in enumerate(x):
            if(ind+1 in di):
                if(di[ind+1] != int(s)):
                    ok = False
                    continue
        if(ok):
            print(i)
            break
    else:
        print(-1)
Problem p02817 (python)

Fixed submission:
S, T = [i for i in input().split()]
print(T+S)

Buggy submission (verdict: Runtime Error):
S, T = [int(i) for i in input().split()]
print(T+S)
Problem p02850 (python)

Fixed submission:
N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*(N-1)
di = {}
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    K=max(K,len(edges[a-1]),len(edges[b-1]))
    di[(a-1,b-1)] = i
    di[(b-1,a-1)] = i
    A.append((a-1,b-1))
#%%
#K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = 1
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        if(available_color == used_color):
            available_color += 1
        next_stk.append((next,available_color))
        i = di[(next,n)]
        colors[i] = available_color
        available_color += 1
    stk += next_stk
    seen.add(n)

print(K)
for col in colors:
    print(col)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*((N+2)*(10**5))
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    cnt_edges[a-1]+=1
    cnt_edges[b-1]+=1
    A.append((a-1,b-1))
#%%
K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = [i for i in range(1,K+1)]
    if(used_color!=0):
        available_color.remove(used_color)
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        col = available_color.pop()
        next_stk.append((next,col))

        colors[next*(10**5)+n] = col
        colors[n*(10**5)+next] = col
    stk = next_stk + stk
    seen.add(n)

print(K)
for edge in A:
    a,b = edge
    col = colors[a*(10**5)+b]
    print(col)

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
cnt_edges = [0]*N
colors = [0]*(N*(10**5)+10)
A = []
K = 0
for i in range(N-1):
    a,b = [int(x) for x in input().split()]
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

    cnt_edges[a-1]+=1
    cnt_edges[b-1]+=1
    A.append((a-1,b-1))
#%%
K = max(cnt_edges)

stk = [(0,0)]
seen = set()
while(stk):
    n,used_color = stk.pop()
    available_color = [i for i in range(1,K+1)]
    if(used_color!=0):
        available_color.remove(used_color)
    next_stk = []
    for next in edges[n]:
        if(next in seen):
            continue
        col = available_color.pop()
        next_stk.append((next,col))

        colors[next*(10**5)+n] = col
        colors[n*(10**5)+next] = col
    stk = next_stk + stk
    seen.add(n)

print(K)
for edge in A:
    a,b = edge
    col = colors[a*(10**5)+b]
    print(col)

Buggy submission (verdict: Runtime Error):
N = int(input())
cnt_edges = [0]*N
A = []
K = 0
for _ in range(N-1):
    a,b = [int(x) for x in input().split()]
    cnt_edges[a-1]+=1
    cnt_edges[b-1]+=1
    A.append((a,b))

K = max(cnt_edges)

color = [set([i for i in range(1,K+1)]) for _ in range(N)]
print(K)
for edge in A:
    a,b = edge
    col = list(color[a-1] & color[b-1])[0]
    print(col)
    color[a-1].discard(col)
    color[b-1].discard(col)
Problem p02868 (python)

Fixed submission:
from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = []
event = []
dists = [float('inf')]*N
dists[0] = 0
cnt_key = 0
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    event.append((l-1, c, 1, cnt_key))
    event.append((r-1, c, -1, cnt_key))
    cnt_key += 1

event.sort(key=itemgetter(0))
paths = {}
now_dist = 0
for ev in event:
    x = ev[0]
    for s in paths:
        if(dists[x]<paths[s][1]):
            paths[s][1] = dists[x]
        dists[x] = min(dists[x], paths[s][0]+paths[s][1])

    if(ev[2]==1):
        paths[ev[3]] = [ev[1], dists[ev[0]]]
    else:
        del paths[ev[3]]

if(dist[-1]==float('inf')):
    print(-1)
else:
    print(dist[-1])
Problem p02918 (python)

Fixed submission:
N,K = [int(x) for x in input().split()]
S = input()
#%%
li = [1]
ans = 0
cnt = 0

for ind,s in enumerate(S[:-1]):
    if(s==S[ind+1]):
        li[-1]+=1
    else:
        li.append(1)

#%%
for ind,i in enumerate(li):
    if(ind==0):
        ans += i-1
    elif(ind<=2*K):
        ans += i
    else:
        ans += max(i-1,0)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = [int(x) for x in input().split()]
S = input()
li = [1]
ans = 0
cnt = 0
for ind,s in enumerate(S[:-1]):
    if(s==S[ind+1]):
        li[-1]+=1
    else:
        li.append(1)
for ind,i in enumerate(li):
    if(ind%2==1 and cnt<=K):
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,Q = [int(x) for x in input().split()]
    li = [0]*N
    gp = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = input().split()
        a = int(a)
        b = int(b)
        gp[a-1].append(b-1)
        gp[b-1].append(a-1)

    for _ in range(Q):
        p,x = input().split()
        li[int(p)-1] += int(x)

    st = []
    seen = set()
    st.append(0)
    while(st):
        x = st.pop()
        if(x in seen):continue
        seen.add(x)
        for i in gp[x]:
            if(i in seen):continue
            li[i]+=li[x]
            st.append(i)
    print(*li)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def dfs(gr,li,n,fr):
    if(len(gr[n])==1 and gr[n][0]==fr):
        li[n].add(n)
        return set([n])
    else:
        ans = set([n])
        for i in gr[n]:
            if(i==fr):continue
            ans |= dfs(gr,li,i,n)
        li[n] |= ans
        return ans
#%%
N,Q = [int(x) for x in input().split()]
nlist = [set() for _ in range(N)]
gp = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = [int(x) for x in input().split()]
    gp[a-1].append(b-1)
    gp[b-1].append(a-1)

qu = [[int(x) for x in input().split()]for _ in range(Q)]
#%%
li = [0]*N
dfs(gp,nlist,0,-1)
for p,x in qu:
    for j in nlist[p-1]:
        li[j] += x
print(*li)
Problem p02949 (python)

Fixed submission:
def BellmanFord(edges,num_v,source):
    #グラフの初期化
    inf=float("inf")
    dist=[inf for i in range(num_v)]
    dist[source-1]=0
    flag = False

    #辺の緩和
    for i in range(num_v):
        for edge in edges:
          if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
            dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
            if i==num_v-1:
                if edge[1] == num_v:
                    return -1
                else:
                    dist[edge[1]-1] = -inf
                    flag = True
    if flag:
        for i in range(num_v):
            for edge in edges:
                if dist[edge[1]-1]>dist[edge[0]-1] + edge[2]:
                    dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
                    if edge[1] == num_v :
                        return -1

    return dist

N,M,P = [int(x) for x in input().split()]
gp = []
for _ in range(M):
    A,B,C = [int(x) for x in input().split()]
    gp.append([A,B,P-C])

li = BellmanFord(gp,N,1)
if(li==-1):
    print(-1)
else:
    print(max(0,-li[N-1]))

Buggy submission (verdict: Runtime Error):
def BellmanFord(edges,num_v,source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0

  #辺の緩和
  for i in range(num_v):
    for edge in edges:
      if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
        dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
        if i==num_v-1 and edge[1]==num_v : return -1
  return dist

N,M,P = [int(x) for x in input().split()]
gp = []
for _ in range(M):
    A,B,C = [int(x) for x in input().split()]
    gp.append([A,B,P-C])

li = BellmanFord(gp,M,1)
if(li==-1):
    print(-1)
else:
    print(max(0,-li[N-1]))

Buggy submission (verdict: Runtime Error):
def BellmanFord(edges,num_v,source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source-1]=0

  #辺の緩和
  for i in range(num_v):
    for edge in edges:
      if edge[0] != inf and dist[edge[1]-1] > dist[edge[0]-1] + edge[2]:
        dist[edge[1]-1] = dist[edge[0]-1] + edge[2]
        if i==num_v-1 and edge[1]==num_v : return -1
  return dist

N,M,P = [int(x) for x in input().split()]
gp = []
for _ in range(M):
    A,B,C = [int(x) for x in input().split()]
    gp.append([A,B,min(P-C,0)])

li = BellmanFord(gp,M,1)
if(li==-1):
    print(-1)
else:
    print(-li[N-1])
Problem p02996 (python)

Fixed submission:
from operator import itemgetter

N = int(input())
AB = [[int(x) for x in input().split()]for _ in range(N)]
sum_time = sum([a for a,b in AB])
AB.sort(key=itemgetter(0))
AB.sort(key=itemgetter(1),reverse=True)
for a,b in AB:
    if(sum_time>b):
        print('No')
        break
    else:
        sum_time-=a
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N = int(input())
AB = [[int(x) for x in input().split()]for _ in range(N)]
sum_time = sum([a for a,b in AB])
AB.sort(key=itemgetter(0))
AB.sort(key=itemgetter(1),reverse=True)
for a,b,t in AB:
    if(sum_time>b):
        print('No')
        break
    else:
        sum_time-=a
else:
    print('Yes')
Problem p03044 (python)

Fixed submission:
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

class graph:
    def __init__(self,n):
        self.n = n
        self.con = []
        self.team = -1

    def connect(self,n,dist):
        self.con.append((n,dist))

    def is_edge(self):
        if(len(self.con)==1):
            return True
        else: return False

    def set_team(self,team):
        self.team = team

N = int(input())
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
li = []
edge = -1
for i in range(1,N+1):
    li.append(graph(i))
for i in uvw:
    li[i[0]-1].connect(i[1],i[2])
    li[i[1]-1].connect(i[0],i[2])
for i in li:
    if(i.is_edge()):
        edge=i.n
        break
before = edge
next = edge
li[edge-1].set_team(0)
for i in range(N):
    print(li[next-1].team)
    if(i==N-1):break
    if(li[next-1].con[0][0]==before):
        before = next
        next = li[next-1].con[1][0]
        li[next-1].set_team((li[before-1].team+li[before-1].con[1][1])%2)
    else:
        before = next
        next = next = li[next-1].con[0][0]
        li[next-1].set_team((li[before-1].team+li[before-1].con[0][1])%2)
Problem p03112 (python)

Fixed submission:
def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))

Buggy submission (verdict: Runtime Error):
def bisearch(li,target):
    l=0
    r=len(li)-1
    if(target<li[0][0]):
        return li[m][0]-target+li[m][1]
    if(li[-1][0]<target):
        return target-li[-1][0]+li[-1][1]
    while(l<=r):
        m=int((l+r)/2)
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1


inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q


for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1
        

for i in x:
    print(bisearch(li,i))

Buggy submission (verdict: Runtime Error):
def bisearch(li,target):
    l=0
    r=len(li)-1
    if(target<li[0][0]):
        return li[m][0]-target+li[m][1]
    elif(li[-1][0]<target):
        return target-li[-1][0]+li[-1][1]
    while(l<=r):
        m=int((l+r)/2)
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1


inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q


for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

x.append(500)

for i in x:
    print(bisearch(li,i))
Problem p03145 (python)

Fixed submission:
AB,BC,CA = map(int,input().split())
print(int(AB*BC/2))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

def inpl(): return [int(i) for i in input().split()]

N,K = inpl()
d = {}
ans = 0
n0 = []
n1 = []

for i in range(N):
    ti,di = inpl()
    if (ti in d.keys()):
        d[ti].append(di)
    else:
        d[ti] = [di]

for i in d.keys():
    sortedd = sorted(d[i],reverse = True)
    n1.append(sortedd[0])
    n0 += sortedd[1:]

n0.sort(reverse = True)
n1.sort(reverse = True)

for i in range(K+1):
    if(K-i <= len(n0) and 0<=K-i):
        total = sum(n1[:i])+sum(n0[:K-i])+(i)**2
        if(ans<total):
            ans = total

print(ans)
Problem p03147 (python)

Fixed submission:
import array
def count_mizuyari(l):
    count = 0
    arr = array.array('i',[0])
    arr.extend(l)
    for i in range(len(arr)-1):
        if(arr[i]==0 and arr[i+1]!=0):
            count += 1
    return count
    

def mizuyari2(l):
    count = 0
    stopper = 0

    #要素が全部0かどうかの判定
    for i in l:
        stopper+=i 
    if(stopper == 0):
        return 0 
    else:     
        count=count_mizuyari(l)
    for index,i in enumerate(l):           
        l[index]-=1
        if(l[index]<0):
            l[index]=0

    return count+mizuyari2(l)

N = int(input())
h = array.array('i')

li = input().rstrip().split()
for i in li:
    h.append(int(i))


print(mizuyari2(h))

Buggy submission (verdict: Runtime Error):
def mizuyari2(l):
    count = 0
    stopper = 0

    for i in l:
        stopper+=i 
    if(stopper == 0):
        return 0        

    if(l[0]!=0):
        count+=1
    for i in range(len(l)-1):
        if(l[i]==0 and l[i+1]!=0):
            count+=1
    if(l[len(l)-2]==0 and l[len(l)-1!=0]):
        count+=1

    for index,i in enumerate(l):           
        l[index]-=1
        if(l[index]<0):
            l[index]=0

    return count+mizuyari2(l)

N = int(input())
h = []

for i in range(N):
    h.append(int(input()))

print(mizuyari2(h))

Buggy submission (verdict: Runtime Error):
def mizuyari2(l):
    count = 0
    stopper = 0

    for i in l:
        stopper+=i 
    if(stopper == 0):
        return 0        

    if(l[0]!=0):
        count+=1
    for i in range(len(l)-1):
        if(l[i]==0 and l[i+1]!=0):
            count+=1

    for index,i in enumerate(l):           
        l[index]-=1
        if(l[index]<0):
            l[index]=0

    return count+mizuyari2(l)

N = int(input())
h = []

for i in range(N):
    h.append(int(input()))

print(mizuyari2(h))

Buggy submission (verdict: Runtime Error):
def mizuyari2(l):
    count = 0
    stopper = 0

    for i in l:
        stopper+=i 
    if(stopper == 0):
        return 0        

    if(l[0]!=0):
        count+=1
    for i in range(len(l)-1):
        if(l[i]==0 and l[i+1]!=0):
            count+=1

    for index,i in enumerate(l):           
        l[index]-=1
        if(l[index]<0):
            l[index]=0

    return count+mizuyari2(l)

N = int(input())
h = []

for i in range(N):
    h.append(int(input()))

print(mizuyari2(h))
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

def search_obj(x,y,grids):
    ans = [0,0]
    curr_state = grids[y][x]
    grids[y][x] = '0'    
    obj_state = '.'
    if(curr_state == '.'):
        ans[0] += 1
        obj_state = '#'
    elif(curr_state == '#'):
        ans[1] += 1
    
    if(grids[y-1][x] == obj_state):
        a,b = search_obj(x,y-1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x-1] == obj_state):
        a,b = search_obj(x-1,y,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y+1][x] == obj_state):
        a,b = search_obj(x,y+1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x+1] == obj_state):
        a,b = search_obj(x+1,y,grids)
        ans[0] += a
        ans[1] += b

    return ans
    

H,W = (int(x) for x in input().split())
s = ""
ans = 0
for _ in range(W+2):
    s+="0"
s = list(s)
grids = [s]

for _ in range(H):
    si = input()
    si = "0"+si+"0"
    grids.append(list(si))
    
grids.append(s)

for i in range(W):
    for j in range(H):
        if(grids[j+1][i+1]!='0'):
            a,b = search_obj(i+1,j+1,grids)
            ans += a*b

print(ans)

Buggy submission (verdict: Runtime Error):
def search_obj(x,y,grids):
    ans = [0,0]
    curr_state = grids[y][x]
    grids[y][x] = '0'    
    obj_state = '.'
    if(curr_state == '.'):
        ans[0] += 1
        obj_state = '#'
    elif(curr_state == '#'):
        ans[1] += 1
    
    if(grids[y-1][x] == obj_state):
        a,b = search_obj(x,y-1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x-1] == obj_state):
        a,b = search_obj(x-1,y,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y+1][x] == obj_state):
        a,b = search_obj(x,y+1,grids)
        ans[0] += a
        ans[1] += b

    if(grids[y][x+1] == obj_state):
        a,b = search_obj(x+1,y,grids)
        ans[0] += a
        ans[1] += b

    return ans
    

H,W = (int(x) for x in input().split())
s = ""
ans = 0
for _ in range(W+2):
    s+="0"
s = list(s)
grids = [s]

for _ in range(H):
    si = input()
    si = "0"+si+"0"
    grids.append(list(si))
    
grids.append(s)

for i in range(W):
    for j in range(H):
        a,b = search_obj(i+1,j+1,grids)
        ans += a*b

print(ans)
Problem p03260 (python)

Fixed submission:
A,B = [int(x) for x in input().split()]
if(A%2==0 or B%2==0):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
A,B = [int(x) for x in input().split()]
if(A%2==0 or B%2===0):
  print('No')
else:
  print('Yes')