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

Fixed submission:
n = int(input())
d = {}

for i in range(n):
    s = "".join(sorted(input()))
    if s in d: d[s] += 1
    else: d[s] = 1
ans = 0
for i in d.values():
    ans += (i*i-i)//2
print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
from sys import stdin

n = int(input())
ss = [sorted(stdin.readline()) for i in range(n)]
ss.sort()

tmp = ss[0]
cnt = 0
ans = 0
for i in range(n):
    if tmp == ss[i]: cnt+=1
    else:
        tmp = ss[i]
        ans += comb(cnt, 2)
        cnt=1
print(int(ans+comb(cnt,2)))
Problem p02983 (python)

Fixed submission:
s, e = map(int, input().split())
ans = 10 ** 9
b = min(s+2019, e)
for i in range(s, b + 1):
    for j in range(i+1, b+1):
        ans = min(ans, i*j%2019)
print(ans)

Buggy submission (verdict: Runtime Error):
s, e = map(int,input().split())
mn = min(map(lambda x:x%2019,range(s,e+1)))
for i in range(s, e+1):
  ans = min(ans, mn*i)
print(ans)
Problem p03032 (python)

Fixed submission:
n, k, *v = map(int, open(0).read().split())

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i+j>k: continue
        cand = sorted([v[I] for I in range(n) if I<i or n-j<=I])
        cnt = sum(cand)
        ans = max(ans, cnt)
        for l in range(min(k-i-j, len(cand))):
            cnt -= cand[l]
            ans = max(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k, *v = map(int, open(0).read().split())

lrui = [0] + v + [0]
for i in range(n): lrui[i+1] += lrui[i]
rrui = [0] + v + [0]
for i in range(n, 0, -1): rrui[i] += rrui[i+1]

lminus = [[] for i in range(n+2)]
for i in range(n+1):
    lminus[i+1] = lminus[i].copy()
    if i<n and v[i]<=0: lminus[i+1].append(v[i])

rminus = [[] for i in range(n+2)]
for i in range(n, -1, -1):
    rminus[i] = rminus[i+1].copy()
    if i>=0 and v[i-1]<=0: rminus[i].append(v[i-1])

ans = 0
for i in range(min(n, k)+1):
    for j in range(n+1, n-k+i, -1):
        tmp = lrui[i] + rrui[j]
        st = sorted(lminus[i] or rminus[j])
        for l in range(min(k-(i+n-j+1), len(st))):
            tmp -= st[l]
            ans = max(ans, tmp)
print(ans)
Problem p03240 (python)

Fixed submission:
n = int(input())

xyh = [list(map(int,input().split()))for i in range(n)]
i = 0
while i<n:
    if xyh[i][2]==0:
        xyh.pop(i)
        n -= 1
    else: i += 1

if(n==1):
    print(*xyh[0])
    exit()

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()

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

xyh = [list(map(int,input().split()))for i in range(n)]
while xyh[0][2]==0: xyh.pop(0)

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if xyh[k][2]==0: continue
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()
Problem p03241 (python)

Fixed submission:
def prime_factor(a):
    ret = []
    for i in range(1, int(a**0.5)):
        if a%i==0:
            ret.append(i)
            ret.append(a//i)
    return ret

n, m = map(int, input().split())
ans = 1
for i in prime_factor(m):
    if i<=m/n: ans = max(ans, i)
print(ans)

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

fact = []
for i in range(1, int(m**0.5)):
    if m%i==0:
        fact.append(i)
        fact.append(m//i)
fact.sort()

for i in fact:
    if n*i<=m: ans = i
print(ans)

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

fact = []
for i in range(2, int(m**0.5)):
    if m%i==0:
        fact.append(i)
        fact.append(m//i)
fact.sort()

for i in fact:
    if n*i<=m: ans = i
print(ans)
Problem p03356 (python)

Fixed submission:
class unionFind:
    def __init__(self, n):
        self.data = [-1] * (n+10)

    def find(self, x):
        if self.data[x]>=0:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
        else: return x

    def unite(self, x, y):
        a, b = self.find(x), self.find(y)
        if a!=b:
            self.data[b] += self.data[a]
            self.data[a] = b


n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = unionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    tree.unite(p[x-1], p[y-1])

ans = 0
for i in range(n):
    if tree.find(i+1)==tree.find(p[i]): ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
class unionFind:
    def __init__(self, n):
        self.data = [-1] * (n+10)

    def find(self, x):
        if self.data[x]>=0: return self.find(self.data[x])
        else: return x

    def unite(self, x, y):
        a, b = self.find(x), self.find(y)
        if a!=b:
            self.data[b] += self.data[a]
            self.data[a] = b


n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = unionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    tree.unite(p[x-1], p[y-1])

ans = 0
for i in range(n):
    if tree.find(i+1)==tree.find(p[i]): ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
class unionFind:
    def __init__(self, n, p):
        self.data = [-1] * n

    def find(self, x):
        if self.data[x]>=0: return self.find(self.data[x])
        else: return x

    def unite(self, x, y):
        a, b = self.find(x), self.find(y)
        if a!=b:
            self.data[b] += self.data[a]
            self.data[a] = b


n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = unionFind(n, p)
for i in range(m):
    x, y = map(int, input().split())
    tree.unite(p[x-1]-1, p[y-1]-1)

ans = 0
for i in range(n):
    if tree.find(i)==tree.find(p[i]-1): ans += 1
print(ans)
Problem p03370 (python)

Fixed submission:
n, x, *m = map(int, open(0).read().split())
ans = 0
for i in sorted(m):
    if x>=i:
        x -= i
        ans+=1
mx = min(m)
print(ans + (x//mx))

Buggy submission (verdict: Runtime Error):
n, x, *m = map(int, open(0).read().split())
ans = -1
for i in sorted(m):
    if x>=i:
        x -= i                                                                                                                                                                                ans+=1
print(ans+x//min(m))
Problem p03424 (python)

Fixed submission:
n, *s = open(0).read().split()
if "Y" in s: print("Four")
else: print("Three")

Buggy submission (verdict: Runtime Error):
import strutils;var n,a=stdin.readline.split;echo if a.contains("Y"):"Four"else:"Three"
Problem p03694 (python)

Fixed submission:
_,*a=map(int,open(0).read().split());print(max(a)-min(a))

Buggy submission (verdict: Runtime Error):
_,a=map(int,open(0).read().split());print(max(a)-min(a))
Problem p02615 (python)

Fixed submission:
from sys import stdin
N = int(stdin.readline().rstrip())
ran = [int(x) for x in stdin.readline().rstrip().split()]
ran.sort(reverse=True)

gen = len(ran) - 2
goukei = ran[0]
if gen % 2 == 0:
  for i in range(int(gen/2)):
    goukei += 2 * ran[i + 1]
else:
  for i in range(int((gen-1)/2)):
    goukei += 2 * ran[i + 1]
  goukei += ran[i + 2]

print(goukei)

Buggy submission (verdict: Runtime Error):
from sys import stdin
N = int(stdin.readline().rstrip())
ran = [int(x) for x in stdin.readline().rstrip().split()]
ran.sort(reverse=True)

gen = len(ran) - 2
goukei = ran[0]
if gen % 2 == 0:
  for i in range(int(gen/2)):
    goukei += 2 * ran[i + 1]
else:
  for i in rangen(int((gen-1)/2)):
    goukei += 2 * ran[i + 1]
  goukei += ran[i + 2]

print(goukei)
Problem p02642 (python)

Fixed submission:
#import time

def main():
    N = int(input())
    As = list(map(int, input().split()))

    As.sort()
    amax = max(As) + 1
    lis = [True] * amax
    ans = 0

    for i in range(N-1):
        if lis[As[i]]:
            for j in range(As[i], amax, As[i]):
                lis[j] = False
            if As[i] < As[i+1]:
                ans += 1
    if lis[-1]:
        ans += 1

    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Buggy submission (verdict: Runtime Error):
#import time

def main():
    N = int(input())
    As = list(map(int, input().split()))

    As.sort()
    amax = max(As) + 1
    lis = [True] * amax
    ans = 0

    for i in range(N-1):
        if lis[As[i]]:
            for j in range(As[i], amax, As[i]):
                lis[j] = False
            if a[i] < a[i+1]:
                ans += 1
    if lis[-1]:
        ans += 1

    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
Problem p02677 (python)

Fixed submission:
#import time
import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = absolute(kakuH, kakuM)
    #print(kakuH, kakuM, kakuS)
    ans =(A**2 + B**2 - 2*A*B*cos(radians(kakuS)) )**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Buggy submission (verdict: Runtime Error):
#import time
import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = kakuH - kakuM
    #print(kakuH, kakuM, kakuS)
    ans =(A**2 + B**2 - 2*A*B*np.cos(kakuS*pai/180)) )**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
Problem p02684 (python)

Fixed submission:
#import time

def main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))
    As = [0]+As
    ikisaki = As[1]
    aru = {1}
    itta = [1]
    imaitta = 1
  
    while not ikisaki in aru:
        imaitta = ikisaki
        ikisaki = As[ikisaki]
        itta.append(imaitta)
        aru.add(imaitta)
    ind = itta.index(ikisaki)
    kurikaesi = itta[ind:]
    itidokiri = itta[:ind]
    ans = itidokiri[K] if len(itidokiri) > K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]


    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Buggy submission (verdict: Runtime Error):
#import time

def main():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))
    As = [0]+As
    ikisaki = As[1]
    aru = {1}
    itta = [1]
    imaitta = 1
  
    while not ikisaki in aru:
        imaitta = ikisaki
        ikisaki = As[ikisaki]
        itta.append(imaitta)
        aru.add(imaitta)
    ind = itta.index(ikisaki)
    kurikaesi = itta[ind:]
    itidokiri = itta[:ind]
    ans = itidokiri[K-1] if len(itidokiri) <= K else kurikaesi[(K-len(itidokiri))%len(kurikaesi)]


    return itta, itidokiri, kurikaesi, ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
Problem p02541 (python)

Fixed submission:
import math
def extgcd(a, b):
    """
    ax + by = gcd(a,b) = d となる (x,y,d) を返す
    """
    if b == 0:
        return (1, 0, a)
    q, r = a // b, a % b
    x, y, d = extgcd(b, r)
    s, t = y, x - q * y
    return s, t, d

def inv_mod(a, N):
    """
    ax = 1 mod N となる x を返す
    """
    return extgcd(a, N)[0]

def CRT(a_1, a_2, m_1, m_2):
    """
    x = a_1 mod m_1, x = a_2 mod m_2 となる x を返す
    """
    y = (a_2 - a_1) * inv_mod(m_1, m_2) % m_2
    return a_1 + m_1 * y

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    if math.gcd(a, b) == 1:
        P = CRT(0, -1, a, b)
        if P != 0:
            ans = min(P, ans)
        Q = CRT(0, -1, b, a)
        if Q != 0:
            ans = min(Q, ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import sympy.ntheory.modular

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+2, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    x = sympy.ntheory.modular.crt([a, b], [0, -1])
    if x is None:
        pass
    else:
        ans = min(ans, x[0])

print(ans)
Problem p02556 (python)

Fixed submission:
N = int(input())
A = []
B = []
for i in range(N):
    x, y = map(int, input().split())
    A.append(x+y)
    B.append(x-y)
print(max(max(A)-min(A), max(B)-min(B)))

Buggy submission (verdict: Runtime Error):
N = int(input())
K = []
for i in range(N):
    x, y = map(int,input().split())
    t = x + y
    if x <= 0:
        t -= 4*abs(x)
    if y <= 0:
        t -= 4*abs(y)
    K.append([t, x, y])

K.sort()
ans = K[-1][0] - K[0][0]
for i in range(N-1):
    if K[i][0] == K[i+1][0]:
        A.append(K[i+1][1])
    else:
        ans = max(ans, max(A) - min(A))
        A = [K[i][1]]
print(ans)
Problem p02609 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
X = list(input())
d = defaultdict(int)

for i in range(1, N):
    c = 0
    t = 0
    k = format(i, "b")
    for j in k:
        if j == "1":
            c += 1
    d[i] = d[i%c] + 1


n = 0
for i in X:
    if i == "1":
        n += 1

p1 = 1
p2 = 1
total1 = 0
total2 = 0
for i in X[::-1]:
    if i == "1":
        total1 += p1 % (n+1)
        if n-1 > 0:
            total2 += p2 % (n-1)
    p1 *= 2
    p1 %= n+1
    if n-1 > 0:
        p2 *= 2
        p2 %= n-1

total1 %= (n+1)
if n-1 > 0:
    total2 %= (n-1)
Ans = []
p1 = 1
p2 = 1
for i in X[::-1]:
    c = 1
    if n - 1 <= 0 and i == "1":
        Ans.append(0)
    else:
        if i == "0":
            start = total1
            start += p1
            start %= (n+1)
        else:
            start = total2
            start -= p2
            start += n - 1
            start %= (n-1)
        Ans.append(c+d[start])
    p1 *= 2
    p1 %= n+1
    if n-1 > 0:
        p2 *= 2
        p2 %= n-1

for i in Ans[::-1]:
    print(i)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
X = list(input())
d = defaultdict(int)

for i in range(1, N):
    c = 0
    k = format(i, "b")
    for j in k:
        if j == "1":
            c += 1
    d[i] = i % c

n = 0
for i in X:
    if i == "1":
        n += 1

p = 1
total1 = 0
total2 = 0
for i in X[::-1]:
    if i == "1":
        total1 += p % (n+1)
        total2 += p % (n-1)
    p *= 2

total1 %= (n+1)
total2 %= (n-1)
Ans = []
p = 1
for i in X[::-1]:
    c = 1
    if i == "0":
        start = total1
        start += p % (n+1)
        start %= (n+1)
    else:
        start = total2
        start -= p % (n-1)
        start += n - 1
        start %= (n-1)
    if start == 0:
        Ans.append(c)
    else:
        while(True):
            start = d[start]
            c += 1
            if start == 0:
                break
        Ans.append(c)
    p *= 2

for i in Ans[::-1]:
    print(i)
Problem p02690 (python)

Fixed submission:
import sys
X = int(input())
for i in range(-1000,1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            sys.exit()

Buggy submission (verdict: Runtime Error):
X = int(input())
t = X**(0.2)
if t.is_integer():
    print(int(t),0)
else:
    b = 1
    while(True):
        k = b**5
        t = (X+k)**(0.2)
        if t.is_integer():
            print(int(t),b)
            break
        t = (X-k)**(0.2)
        if t.is_integer():
            print(int(t),-b)
            break
        b += 1
Problem p02703 (python)

Fixed submission:
import heapq

N, M, S = map(int, input().split())
Cost = [[] for _ in range(N)]
Change = [[0]*2 for _ in range(N)]
A_m = 0
for i in range(M):
    u, v, a, b = map(int, input().split())
    A_m = max(A_m, a)
    Cost[u-1].append([v-1, a, b])
    Cost[v-1].append([u-1, a, b])
for i in range(N):
    c, d = map(int, input().split())
    Change[i][0] = c
    Change[i][1] = d
if S > A_m*N:
    S = A_m*N

def dijkstra(N, start, Cost, Change):
    rich = [[] for _ in range(N+1)]
    Ans = [10**18]*N
    Ans[0] = 0
    minHeap = []
    used = [[10**18]*(A_m*N + 1) for _ in range(N)]
    used[start][S] = 0
    heapq.heappush(minHeap, (0, S, start))
    while minHeap:
        (c, hold, current) = heapq.heappop(minHeap)
        if rich[current] and rich[current][-1] >= hold:
            continue
        rich[current].append(hold)
        j = 1
        for i in range(N):
            if Ans[i] > c:
                j = 0
                break
        if j == 1:
            break
        for P in Cost[current]:
            road, a, b = P
            if hold >= a:
                if used[road][hold - a] > c + b:
                    used[road][hold - a] = c + b
                    heapq.heappush(minHeap, (c + b, hold - a, road))
                if Ans[road] > c + b:
                    Ans[road] = c + b
        if hold + Change[current][0] <= A_m*N:
            if used[current][hold + Change[current][0]] > c + Change[current][1]:
                heapq.heappush(minHeap, (c + Change[current][1], hold + Change[current][0], current))
    return Ans

T = dijkstra(N, 0, Cost, Change)
for i in T[1:]:
    print(i)

Buggy submission (verdict: Runtime Error):
import heapq

N, M, S = map(int, input().split())
Cost = [[[-1, -1] for _ in range(N)] for _ in range(N)]
Change = [[0]*2 for _ in range(N)]
A_m = 0
for i in range(M):
    u, v, a, b = map(int, input().split())
    A_m = max(A_m, a)
    Cost[u-1][v-1][0] = a
    Cost[u-1][v-1][1] = b
    Cost[v-1][u-1][0] = a
    Cost[v-1][u-1][1] = b
for i in range(N):
    c, d = map(int, input().split())
    Change[i][0] = c
    Change[i][1] = d
if S > 2500:
    S = 2500

def dijkstra(N, start, Cost, Change):
    minHeap = []
    used = [[10**12]*(A_m*N + 1) for _ in range(N)]
    used[start][S] = 0
    heapq.heappush(minHeap, (0, S, start))
    while minHeap:
        (c, hold, current) = heapq.heappop(minHeap)
        for road in range(N):
            if Cost[current][road][0] != -1:
                if hold >= Cost[current][road][0]:
                    if used[road][hold - Cost[current][road][0]] > c + Cost[current][road][1]:
                        used[road][hold - Cost[current][road][0]] = c + Cost[current][road][1]
                        heapq.heappush(minHeap, (c + Cost[current][road][1], hold - Cost[current][road][0], road))
        if hold + Change[current][0] <= A_m*N:
            if used[current][hold + Change[current][0]] > c + Change[current][1]:
                heapq.heappush(minHeap, (c + Change[current][1], hold + Change[current][0], current))
    return used

T = dijkstra(N, 0, Cost, Change)
for i in T[1:]:
    print(min(i))
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = [10**10]*(10**5)
a.extend(p[:X])
b = [10**10]*(10**5)
b.extend(q[:Y])
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(p[:X])+sum(q[:Y])
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0


ans = sum(a)+sum(b)
while(True):
    if p_c < - X or a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c] and q_c >= - Y:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = p[:X]
b = q[:Y]
p_c = -1
q_c = -1
r_c = 0
k = 0

ans = sum(a)+sum(b)
while(True):
    if a[p_c] >= b[q_c]:
        if b[q_c] < r[r_c]:
            ans += ( r[r_c] - b[q_c] )
            r_c += 1
            q_c -= 1
        else:
            k = 1

    else:
        if a[p_c] < r[r_c]:
            ans += (r[r_c] - a[p_c])
            r_c += 1
            p_c -= 1
        else:
            k = 1

    if k == 1 or r_c >= C:
        break

print(ans)
Problem p02803 (python)

Fixed submission:
H,W = map(int,input().split())
A = []

for i in range(H):
    t = list(input())
    A.append(t)

tate = (-1,1,0,0)
yoko = (0,0,-1,1)
answer = 0

for i in range(H):
    for j in range(W):
        dp = [[10**4 for i in range(W)] for j in range(H)]
        if A[i][j] == '.':
            dp[i][j] = 0
            Q = list()
            Q.append([i,j])
            while(len(Q) > 0 ):
                s = Q[0][0]
                t = Q[0][1]
                for p, q in zip(tate, yoko):
                    m = s + p
                    n = t + q
                    if m >= 0 and m < H:
                        if n >= 0 and n < W:
                            if A[m][n] == '.':
                                if dp[m][n] == 10**4 :
                                    dp[m][n] = dp[s][t] + 1
                                    Q.append([m,n])
                Q.remove(Q[0])

            for k in range(H):
                for l in range(W):
                    if dp[k][l] < 10**4:
                        answer = max(answer,dp[k][l])

print(answer)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
A = []

for i in range(H):
    t = list(input())
    A.append(t)

print(A)

move = [[-1,0],[1,0],[0,-1],[0,1]]
for i in range(H):
    for j in range(W):
        dp = [[float('inf') for i in range(W)] for j in range(H)]
        if A[i][j] == '.':
            for p,q in zip(move):
                if
Problem p02807 (python)

Fixed submission:
N = int(input())
d = list( map(int, input().split() ) )
kai = 1
mod = 10**9+7
result = 0

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

for i in range(1,N):
    kai = (kai%mod)*i

for i in range(N-1):    
    result += ( kai * (d[N-1] - d[i]) * modinv(i+1) ) % mod 

print( result%mod )

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list( map(int, input().split() ) )
result = float()
for i in range(N-1):
    result += (a[N-1] - a[i]) / ( i+1 )

for i in range(1,N):
    result *= i

if result.is_integer():
    result = int(result)
else:
    result = int(result)+1
    
print( result % (10**9+7) )