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

Fixed submission:
from fractions import gcd

def answer():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        divisors.sort()
        return divisors

    a, b = map(int, input().split())
    g = gcd(a, b)
    divisors = make_divisors(g)

    length = len(divisors)
    removed = 1

    for i in range(1, length):
        d1 = divisors[i]
        for d2 in divisors[i:-1]:
            if d1 * d2 in divisors:
                divisors.remove(d1*d2)
                removed += 1
        if i + removed >= length:
            break

    print(length - removed + 1)


if __name__ == '__main__':
    answer()

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


def answer():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        # divisors.sort()
        return divisors

    a, b = map(int, input().split())
    g = gcd(a, b)
    divisors = make_divisors(g)
    set_divisors = set(divisors)

    for div1 in divisors[1:]:
        for div2 in divisors[1:]:
            item = div1*div2
            if item in set_divisors:
                set_divisors.remove(item)

    print(len(set_divisors))


if __name__ == '__main__':
    answer()
Problem p02947 (python)

Fixed submission:
def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = ''.join(sorted(input()))
        if word not in word_dict.keys():
            word_dict[word] = 1
        else:
            count += word_dict[word]
            word_dict[word] += 1

    print(count)

if __name__ == '__main__':
    C()

Buggy submission (verdict: Runtime Error):
def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = sorted(input())
        if word not in word_dict:
            word_dict[word] = 1
        else:
            count += 1

    print(count)
    
if __name__ == '__main__':
    C()
Problem p02982 (python)

Fixed submission:
import numpy as np

N, D = map(int, input().split())

points = np.array([list(map(int, input().split())) for _ in range(N)])

def distance(p1, p2):
  squares = np.square(p1 - p2)
  return np.sqrt(squares.sum())

count = 0
for i in range(N):
  for j in range(i+1, N):
    dist = distance(points[i], points[j])
    count += dist.is_integer() * 1

print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, D = map(int, input().split())

points = [list(map(int, input().split())) for _ in range(N)]

def distance(p1, p2):
  squares = np.square(np.arange(p1) - np.arange(p2))
  return np.sqrt(squares.sum())

count = 0
for i in range(N):
  for j in range(N):
    if i != j:
      dist = distance(points[i], points[j])
      count += dist.is_integer() * 1

print(count)
Problem p02988 (python)

Fixed submission:
def code_for_B(test=None):

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

    pre = list_p[0]
    count = 0

    for i in range(1,n-1):
        cur = list_p[i]
        nxt = list_p[i+1]

        if pre >= cur > nxt:
            count += 1
        elif pre < cur < nxt:
            count += 1

        pre, cur = cur, nxt

    print(count)

code_for_B()

Buggy submission (verdict: Runtime Error):
def code_for_B(test=None):

    n = int(input)
    list_p = list(map(int, input().split()))
    
    pre = list_p[0]
    count = 0

    for i in range(1,n-1):
        cur = list_p[i]
        nxt = list_p[i+1]
        
        if pre >= cur > nxt:
            count += 1
        elif pre < cur < nxt:
            count += 1
        
        pre, cur = cur, nxt

    print(count)

code_for_B()
Problem p02996 (python)

Fixed submission:
def code_for_D(test=None):

    N = int(input())

    works = [list(map(int, input().split())) for _ in range(N)]
    works = sorted(works, key=lambda x: x[1])

    time_now = 0
    answer = 'Yes'

    for work in works:
        time_now += work[0]
        time_by = work[1]

        if time_now > time_by:
            answer = 'No'

    print(answer)


def main():
    code_for_D()


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def code_for_D(test=None):

    N = int(input())

    works = [map(int, input().split()) for _ in range(N)]
    works = sorted(works, key=lambda x: x[1])

    time_now = 0
    time_by = 0
    answer = 'Yes'

    for i in range(N):
        time_now += works[0]
        time_by = works[1]
        
        if time_now > time_by:
            answer = 'No'
        
    print(answer)


def main():
    code_for_C()


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

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

list_l = [int(x) for x in input().split()]

position = 0
count = 1

for l in list_l:
    position += l
    if position <= X:
        count += 1

print(count)

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

# list_l = [int(x) for x in input().split()]

position  = 0
count = 0

for i in range(N):
    position += int(input())
    if position <+ X:
        count += 1

print(count)
Problem p03061 (python)

Fixed submission:
def gcd(x, y):
    a = max(x, y)
    b = min(x, y)
    if b == 0:
        return a
    remainder = a % b
    if remainder == 0:
        return b
    return gcd(b, remainder)


N = int(input())
integers = [int(x) for x in input().split()]

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], integers[i]))
    right.append(gcd(right[-1], integers[-i-1]))

# right.reverse()

lr = []
for i in range(N):
    lr.append(gcd(left[i], right[-i-2]))

print(max(lr))

Buggy submission (verdict: Runtime Error):
 def gcd(x, y):
    a = max(x, y)
    b = min(x, y)
    if b == 0:
        return a
    remainder = a % b
    if remainder == 0:
        return b
    return gcd(b, remainder)


N = int(input())
integers = [int(x) for x in input().split()]

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], integers[i]))
    right.append(gcd(right[-1], integers[-i-1]))

# left[0] = 0
# right[0] = 0
right.reverse()

lr = []
for i in range(N-1):
    lr.append(gcd(left[i+1], right[i+2]))

print(max(lr))
Problem p03086 (python)

Fixed submission:
S = input()

ns = [0]
n = 0

for s in S:
    if s in 'ACGT':
        n += 1
    else:
        ns.append(n)
        n = 0
ns.append(n)

print(max(ns))

Buggy submission (verdict: Runtime Error):
S = input()

ns = []
n = 0
for s in S:
    if s in 'ACGT':
        n += 1
    else:
        ns.append(n)
        n = 0

print(max(ns))

Buggy submission (verdict: Runtime Error):
S = input()

ns = []
n = 0
for s in S:
    if s in 'ACGT':
        n += 1
    else:
        ns.append(n)
        n = 0

print(max(ns))

Buggy submission (verdict: Runtime Error):
S = input()

ns = []
for s in S:
    if s in 'ACGT':
        n += 1
    else:
        ns.append(n)
        n = 0
print(max(ns))
Problem p03103 (python)

Fixed submission:
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])

ans = 0
s = 0
for i in range(N):
    t = AB[i][1]
    c = min(M-s, t)
    ans += c*AB[i][0]
    s += c
    if s>=M: break

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
PNs = [list(map(int,input().split())) for _ in range(N)]
#price_and_number_of_drinks

PNs.sort(key=lambda x: x[0])

ans = 0
sum_drinks = 0 #sum of drinks which Takahashi has bought
for i in range(N):
    nos = PNs[i][1] #number of drinks at i_th shop
    nob = min(M-sum_drinks, nos) #number of drinks which he can buy at the shop
    ans += nob*PNs[i][0] #add money he spent at the shop
    sum_drinks += nob
    if s>=M: break

print(ans)
Problem p03111 (python)

Fixed submission:
N,A,B,C = map(int, input().split())

bms = [int(input()) for _ in range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9
        return s
    s_0 = dfs(cur+1,a,b,c)
    s_a = dfs(cur+1,a+bms[cur],b,c) + 10
    s_b = dfs(cur+1,a,b+bms[cur],c) + 10
    s_c = dfs(cur+1,a,b,c+bms[cur]) + 10
    return min(s_0,s_a,s_b,s_c)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
N,A,B,C = map(int, input().split())
 
bms = [int(input()) for _ in Range(N)]
 
def dfs(cur,a,b,c):
    if cur == N:
        s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9
        return s
    s_0 = dfs(cur+1,a,b,c)
    s_a = dfs(cur+1,a+bms[cur],b,c) + 10
    s_b = dfs(cur+1,a,b+bms[cur],c) + 10
    s_c = dfs(cur+1,a,b,c+bms[cur]) + 10
    return min(s_0,s_a,s_b,s_c)

print(dfs(0,0,0,0))

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

bms = [int(input()) for _ in Range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9
        return s
    s_0 = dfs(cur+1,a,b,c)
    s_a = dfs(cur+1,a+bms[cur],b,c) + 10
    s_b = dfs(cur+1,a,b+bms[cur],c) + 10
    s_c = dfs(cur+1,a,b,c+bms[cur]) + 10
    return min(s_0,s_a,s_b,s_c)

print(dfs(0,0,0,0))
Problem p03136 (python)

Fixed submission:
N = input()
L = list(map(int, input().split(' ')))

flg = 0
for l in L:
  if not sum(L)-l > l:
    print('No')
    flg = 1

if not flg: print('Yes')

Buggy submission (verdict: Runtime Error):
X,T = map(int, input().split(' '))

print(f'{T/X/1.0}000')

Buggy submission (verdict: Runtime Error):
X,T = map(int, input().split(' '))

print(f'{T/X/1.0}000)
Problem p03146 (python)

Fixed submission:
def next_num(n):
  if n%2:
    return 3*n+1
  else:
    return n/2

s = int(input())

n = s
for i in range(1000000):
  if n in [1,2,4]:
    print(i+4)
    break
  n = next_num(n)

Buggy submission (verdict: Runtime Error):
def next_num(n):
  if n%2:
    return 3*n+1
  else:
    return n/2

s = int(input())

n = s
for i in range(1000000):
  if n in [1,2,4]:
    print(i+4)
    break
  except:
    n = next_num(n)

Buggy submission (verdict: Runtime Error):
def next_num(n):
  if n%2:
    return 3*n+1
  else:
    return n/2

s = int(input())

n = s
for i in range(1000000):
  ind = [1,2,4].index(n)
  if n >= 0:
    print(ind+i+2)
    break
  n = next_num(n)
Problem p03147 (python)

Fixed submission:
class flowers:
    def __init__(self, str_h):
        self.str = str_h.split()
        self.int = []
        self.min = 0
        self.water = 0
        
        self.update_int()
        self.update_min()
    
    def update_str(self):
        self.str = list(map(str, self.int))
        return

    def update_int(self):
        self.int = list(map(int, self.str))
        return
    
    def update_min(self):
        self.min = min(self.int)
        return
    
    def minimize(self):
        self.int = [n-self.min for n in self.int]
        self.water += self.min
        self.update_str()
        self.min = 0
        return
    
    def str_split0(self):
        idxs = [-1] + [i for i,n in enumerate(self.int) if n==0]
        if len(idxs)==1:
            return [self.str]
        else:
            temp_ls = []
            for i in range(len(idxs)-1):
                s = self.str[idxs[i]+1:idxs[i+1]]
                if len(s)>0: temp_ls.append(s)
            if self.int[-1]!=0:
                temp_ls.append(self.str[idxs[-1]+1:])
        return temp_ls

N = input()
str_h = input()

fls = flowers(str_h)
ls_fls = fls.str_split0()
water = 0

while(len(ls_fls)>0):
    #print(f'ls_fls = {ls_fls}')
    temp_ls_fls = []
    for fls in ls_fls:
        if len(fls)<=2:
            water += max([int(s) for s in fls])
            continue
        else:
            _fls = flowers(' '.join(fls))
            _fls.minimize()
            _ls_fls = _fls.str_split0()
            water += _fls.water
            temp_ls_fls += _ls_fls
            flg=1
    ls_fls = temp_ls_fls
print(water)

Buggy submission (verdict: Runtime Error):
N = input()
str_h = input()

fls = flowers(str_h)
ls_fls = fls.str_split0()
water = 0

while(len(ls_fls)>0):
    #print(f'ls_fls = {ls_fls}')
    temp_ls_fls = []
    for fls in ls_fls:
        if len(fls)<=2:
            water += max([int(s) for s in fls])
            continue
        else:
            _fls = flowers(' '.join(fls))
            _fls.minimize()
            _ls_fls = _fls.str_split0()
            water += _fls.water
            temp_ls_fls += _ls_fls
            flg=1
    ls_fls = temp_ls_fls
print(water)
Problem p03206 (python)

Fixed submission:
D = int(input())
names = {
	25:'Christmas', 
	24:'Christmas Eve', 
	23:'Christmas Eve Eve', 
	22:'Christmas Eve Eve Eve'
  }

print(names[D])

Buggy submission (verdict: Runtime Error):
N,K = map(int, input().split())
trees = [int(input()) for _ in range(N)]

trees.sort()

print(min([max_h-min_h for min_h,max_h in zip(trees,trees[K-1:])]))
Problem p03212 (python)

Fixed submission:
N = int(input())
 
def dfs(s):
    if int(s) > N:
        return 0
    r = 1 if all([i in s for i in '357']) else 0
    for c in '357':
        r += dfs(s+c)
    return r

print(dfs('0'))

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

def dfs(s):
    if int(s) > N:
        return 0
    r = 1 if all([i in s for i in '357']) else 0
    for c in '357':
        r += dfs(s+c)
    return r

return(dfs('0'))
Problem p03219 (python)

Fixed submission:
X,Y = map(int, input().split())

print(int(X+Y/2))

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*M

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
citys = [list(map(int,input().split()))+[i] for i in range(M)]

citys.sort(key = lambda x:x[1])
nums = [0]*(N+1)
states = [None]*(M+1)

for p,y,i in citys:
    nums[p] += 1
    states[i] = [str(p), str(nums[p])]

for s in states:
    print(s[0].zfill(6)+s[1].zfill(6))
Problem p03220 (python)

Fixed submission:
N = int(input())
T,A = map(int, input().split())
list_H = list(map(int, input().split()))

ls = [abs(A-(T-x*6/1000)) for x in list_H]
print(ls.index(min(ls))+1)

Buggy submission (verdict: Runtime Error):
ls = [abs(A-(T-x*6/1000)) for x in list_H]
ls.index(min(ls)+1)
Problem p03238 (python)

Fixed submission:
N = int(input())
if N==1:
  print('Hello World')
else:
  A,B = [int(input()) for _ in range(2)]
  print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N==1:
  print('Hello World')
else:
  A,B = map(int, input().split())
  print(A+B)
Problem p03281 (python)

Fixed submission:
N = int(input())
s = 0
for i in range(1,N+1,2):
  t = 0
  for j in range(1,i+1,2):
    if not i%j:
      t+=1
  if t==8:
    s+=1

print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = 0
for i in range(1,N,2):
	t = 0
    for j in range(1,N,2):
		if not N%n:
			t+=1
    if t==8:
		s+=1

print(s)
Problem p03288 (python)

Fixed submission:
R = int(input())
r = 'AGC'
if R<2800: r='ARC'
if R<1200: r='ABC'
print(r)

Buggy submission (verdict: Runtime Error):
R = int(input())
r = 'AGC'
if R<2800:
    r[1]='R'
if R<1200:
    r[1]='B'
print(r)
Problem p03293 (python)

Fixed submission:
S = input()
T = input()

ans = ''

if set(S)!=set(T):
    ans = 'No'

for i in range(len(S)):
    if ans:
        break
    U = S[i:]+S[:i]
    if U==T:
        ans = 'Yes'

if not ans:
    ans = 'No'

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

if set(S)!=set(T):
    ans = 'No'

for i in range(len(S)):
    if ans:
        break
    U = S[i:]+S[:i]
    if U==T:
        ans = 'Yes'

if not ans:
    ans = 'No'

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

if set(S)!=set(T):
    ans = 'No'

for i in len(S):
    if ans:
        break
    U = S[i:]+S[:i]
    if U==T:
        ans = 'Yes'

if not ans:
    ans = 'No'

print(ans)
Problem p02731 (python)

Fixed submission:
n = int(input())
print((n/3)**3)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define length(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, length(a))cin >> a[i]
#define ccin(i, j, a) rep(i, length(a))rep(j, length(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define sqrtl sqrt
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-9;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
int main(){
    ld n;
    cin >> n;
    cout << fixed;
    cout << (n/3)*(n/3)*(n/3) << endl;
    return 0;
}

Buggy submission (verdict: Runtime Error):
n = map(int,input().split())
print(n*n*n/27)
Problem p02806 (python)

Fixed submission:
入力 = input
出力 = print
ぜろ = 0
いち = 1
曲の数 = 入力()
整数化 = int
浮動小数点化 = float
曲の数 = 整数化(曲の数)
曲名 = [ぜろ]
時間 = [ぜろ]
曲名.remove(ぜろ)
時間.remove(ぜろ)
範囲 = range
for 制御変数 in 範囲(ぜろ,曲の数):
    入力された値 = 入力().split()
    曲名.append(入力された値[ぜろ])
    時間.append(入力された値[いち])
    時間[制御変数] = 整数化(浮動小数点化(時間[制御変数]))
寝た時の曲名 = 入力()
まだわからん = ぜろ
寝たタイミング = まだわからん
for 制御変数 in 範囲(ぜろ,曲の数):
    if(曲名[制御変数] == 寝た時の曲名):
        寝たタイミング = 制御変数
        break
寝ていたときに流れていた曲の時間 = まだわからん
for 制御変数 in 範囲(寝たタイミング + いち,曲の数):
    寝ていたときに流れていた曲の時間 += 時間[制御変数]
出力(寝ていたときに流れていた曲の時間)

Buggy submission (verdict: Runtime Error):
入力 = input
出力 = print
ぜろ = 0
いち = 1
曲の数 = 入力()
整数化 = int
浮動小数点化 = float
曲の数 = 整数化(曲の数)
曲名 = [ぜろ]
時間 = [ぜろ]
曲名.remove(ぜろ)
時間.remove(ぜろ)
範囲 = range
for 制御変数 in 範囲(ぜろ,曲の数):
    入力された値 = 入力()
    曲名.append(入力された値)
    入力された値 = 入力()
    時間.append(入力された値)
    時間[制御変数] = 整数化(浮動小数点化(時間[制御変数]))
寝た時の曲名 = 入力()
まだわからん = ぜろ
寝たタイミング = まだわからん
for 制御変数 in 範囲(ぜろ,曲の数):
    if(曲名[制御変数] == 寝た時の曲名):
        寝たタイミング = 制御変数
        break
寝ていたときに流れていた曲の時間 = まだわからん
for 制御変数 in 範囲(寝たタイミング + いち,曲の数):
    寝ていたときに流れていた曲の時間 += 時間[制御変数]
出力(寝ていたときに流れていた曲の時間)
Problem p02780 (python)

Fixed submission:
(N, K) = list(map(int,input().split()))
P = list(map(int, input().split()))

def max_expected(L, K):
  length = len(L)
  if (length < K):
    return -1
  if (length == K):
    return (sum(L) + K) / 2
  mid = length // 2
  s_left = max_expected(L[0:mid], K)
  s_right = max_expected(L[mid:], K)
  offset = 0

  if (mid - K + 1 < 0):
    offset = - (mid - K + 1)
  end_offset = 0
  if (mid + K - 1 >= length):
    end_offset = mid + K - 1 - length
  max_p = sum(L[mid - K + 1 + offset:mid + 1 + offset])
  prev = max_p
  for i in range(mid - K + 1 + offset + 1, mid - end_offset):
    prev = prev - L[i - 1] + L[i + K - 1]
    if max_p < prev:
      max_p = prev
  
  return max((max_p + K) / 2, s_left, s_right)
print("{}".format(max_expected(P, K)))

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

def max_expected(L, K):
  length = len(L)
  if (length < K):
    return -1
  mid = length // 2
  s_left = max_expected(L[0:mid], K)
  #print("left array:{}, max: {}".format(L[0:mid], s_left))
  s_right = max_expected(L[mid:], K)
  #print("right array:{}, max: {}".format(L[mid:], s_right))
  offset = 0

  if (mid - K + 1 < 0):
    offset = - (mid - K + 1)
  end_offset = 0
  if (mid + K - 1 >= length):
    end_offset = mid + K - 1 - length
  max_p = sum(L[mid - K + 1 + offset:mid + 1 + offset])
  for i in range(mid - K + 1 + offset, mid - end_offset):
    j = sum(L[i:(i + K)])
    #print("{}[{}]..{}[{}]: {}".format(L[i], i, L[i + K - 1], i + K - 1, j))
    if max_p < j:
      max_p = j
  #print("mid: {}".format((max_p + K) / 2));
  
  return max((max_p + K) / 2, s_left, s_right)
print("{}".format(max_expected(P, K)))
Problem p02909 (python)

Fixed submission:
import sys

def resolve():
  s = input()
  if s == 'Sunny':
      print('Cloudy')
  elif s == 'Cloudy':
      print('Rainy')
  else:
      print('Sunny')

if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
  s = input()
  if s == 'Sunny':
    print('Cloudy')
  elif s == 'Cloudy':
    print(Rainy)
  else:
    print('Sunny')

  return

if __name__ == "__main__":
  resolve()
Problem p03112 (python)

Fixed submission:
# ABC 119 D

import bisect

def resolve():
    A, B, Q = map(int, input().split())
    s = [int(input()) for _ in range(A)]
    t = [int(input()) for _ in range(B)]

    for _ in range(Q):
        i = int(input())
        s1 = -1 if bisect.bisect_left(s, i) == 0 else s[bisect.bisect_left(s, i)-1]
        s2 = -1 if bisect.bisect_right(s, i) >= A else s[bisect.bisect_right(s, i)]
        t1 = -1 if bisect.bisect_left(t, i) == 0 else t[bisect.bisect_left(t, i)-1]
        t2 = -1 if bisect.bisect_left(t, i) >= B else t[bisect.bisect_right(t, i)]
        tmp = []

        if s1 != -1 and t1 != -1:
            tmp.append(max(i-s1, i-t1))
        if s2 != -1 and t2 != -1:
            tmp.append(max(s2-i, t2-i))
        if s1 != -1 and t2 != -1:
            tmp.append(min(i-s1, t2-i) + t2-s1)
        if t1 != -1 and s2 != -1:
            tmp.append(min(i-t1, s2-i) + s2-t1)

        print(min(tmp))


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
# ABC 119 D

import bisect

def resolve():
    A, B, Q = map(int, input().split())
    s = [int(input()) for _ in range(A)]
    t = [int(input()) for _ in range(B)]

    for _ in range(Q):
        i = int(input())
        s1 = -1 if bisect.bisect_left(s, i) == 0 else s[bisect.bisect_left(s, i)-1]
        s2 = -1 if bisect.bisect_right(s, i) >= A else s[bisect.bisect_right(s, i)]
        t1 = -1 if bisect.bisect_left(t, i) == 0 else t[bisect.bisect_left(t, i)-1]
        t2 = -1 if bisect.bisect_left(t, i) >= A else t[bisect.bisect_right(t, i)]
        tmp = []

        if s1 != -1 and t1 != -1:
            tmp.append(max(i-s1, i-t1))
        if s2 != -1 and t2 != -1:
            tmp.append(max(s2-i, t2-i))
        if s1 != -1 and t2 != -1:
            tmp.append(min(i-s1, t2-i) + t2-s1)
        if t1 != -1 and s2 != -1:
            tmp.append(min(i-t1, s2-i) + s2-t1)

        print(min(tmp))


if __name__ == "__main__":
    resolve()