TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import sys
from collections import deque


def bfs(s):
    flag_list[s] = 1
    color_list[s] = 0
    q.append(s)
    while len(q)>0:
        u = q.popleft()
        for v, w in enumerate(m_list[u]):
            if w > 0 and flag_list[v] == 0:
                flag_list[v] = 1
                if w%2 == 0:
                    color_list[v] = color_list[u]
                else:
                    color_list[v] = (color_list[u]+1)%2
                q.append(v)
        flag_list[u] = 2


if __name__ == "__main__":
    input = sys.stdin.readline
    n = int(input())
    m_list = [[0]*n for _ in range(n)]
    color_list = [0]*n
    flag_list = [0]*n
    q = deque([])
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        m_list[u-1][v-1] = w
        m_list[v-1][u-1] = w
    bfs(0)
    for color in color_list:
        print(color)


import sys
import bisect


input = sys.stdin.readline
a, b, q = map(int, input().split())
inf = 10**12
s_list = [-inf] + [int(input()) for _ in range(a)] + [inf]
s_list.sort()
t_list = [-inf] + [int(input()) for _ in range(b)] + [inf]
t_list.sort()
ans_list =[]
for _ in range(q):
    x = int(input())
    s_idx = bisect.bisect_right(s_list, x)
    t_idx = bisect.bisect_right(t_list, x)
    ans = inf
    for s in [s_list[s_idx-1], s_list[s_idx]]:
        for t in [t_list[t_idx-1], t_list[t_idx]]:
            ans = min(ans, min(abs(x-s), abs(x-t)) + abs(s-t))
    print(ans)


Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import numpy as np
A, B, C = map(int, input().split())
s = np.array([int(input()) for _ in range(A)])
t = np.array([int(input()) for _ in range(B)])
x = np.array([int(input()) for _ in range(C)])
for i in x:
    si = i-s
    asi = list(abs(si))
    min_si = min(asi)
    s_idx = asi.index(min_si)
    ti = i-t
    ati = list(abs(ti))
    min_ti = min(ati)
    t_idx = ati.index(min_ti)
    if si[s_idx] * ti[t_idx] < 0:
        if min_si <= min_ti:
            print(min_si*2+min_ti)
        else:
            print(min_ti*2+min_si)
    else:
        print(max(min_si, min_ti))


import sys
import bisect
input = sys.stdin.readline
A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
s = sorted(s)
t = sorted(t)

for _ in range(Q):
    x = int(input())
    idx1 = bisect.bisect_right(s, x)
    idx2 = bisect.bisect_right(t, x)
    ans = float('inf')
    if idx1 > 0:
        left_s = s[idx1-1]
    else:
        left_s = float('inf')
    if idx2 > 0:
        left_t = t[idx2-1]
    else:
        left_t = float('inf')
    if idx1 < A:
        right_s = s[idx1]
    else:
        right_s = float('inf')
    if idx2 < B:
        right_t = t[idx2]
    else:
        right_t = float('inf')

    ls = x-left_s
    lt = x-left_t
    rs = right_s-x
    rt = right_t-x 
    if left_s <= x <= right_t:
        tmp = right_t-left_s + min(ls, rt)
        ans = min(ans, tmp)
    if left_t <= x <= right_s:
        tmp = right_s-left_t + min(lt, rs)
        ans = min(ans, tmp)
    ans = min(ans, max(abs(ls), abs(lt)))
    ans = min(ans, max(abs(rs), abs(rt)))
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect

A,B,Q=map(int,input().split())
inf = 10 ** 18
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]

for q in range(Q):
    x = int(input())
    s_l = bisect.bisect_left(s,x)
    s_h = s_l + 1
    t_l = bisect.bisect_left(t,x)
    t_h = t_l + 1

    ans = inf
    for s in [s_l,s_h]:
        for t in [t_l,t_h]:
            d1 = abs(s-x)+abs(t-s)
            d2 = abs(t-x)+abs(s-t)
            ans = min(ans,d1,d2)
    
    print(ans)


import bisect

A,B,Q=map(int,input().split())
inf = 10 ** 18
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]

for q in range(Q):
    x = int(input())
    s_l = bisect.bisect_left(s,x)
    s_h = s_l + 1
    t_l = bisect.bisect_left(t,x)
    t_h = t_l + 1

    ans = inf
    for s in [S[s_l],S[s_h]]:
        for t in [T[t_l],T[t_h]]:
            d1 = abs(s-x)+abs(t-s)
            d2 = abs(t-x)+abs(s-t)
            ans = min(ans,d1,d2)
    
    print(ans)


import bisect

A,B,Q=map(int,input().split())
inf = 10 ** 18
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]

for q in range(Q):
    x = int(input())
    s_h = bisect.bisect(S,x)
    s_l = s_h - 1
    t_h = bisect.bisect(T,x)
    t_l = t_h - 1

    ans = inf
    for s in [S[s_l],S[s_h]]:
        for t in [T[t_l],T[t_h]]:
            d1 = abs(s-x)+abs(t-s)
            d2 = abs(t-x)+abs(s-t)
            ans = min(ans,d1,d2)
    
    print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import sys

A, B, Q = map(int, input().split())
S = [int(sys.stdin.readline()) for _ in range(A)]
T = [int(sys.stdin.readline()) for _ in range(B)]
X = [int(sys.stdin.readline()) for _ in range(Q)]
INF = 10**12

def binary_search(query, arr):
    arr = [-INF] + arr + [INF]
    low = 0
    high = len(arr)
    t = (low+high)//2
    for _ in range(100):
        if low<high-1:
            break
        if query>arr[t]:
            low = t
        else:
            high = t
        t = (low+high)//2
    return arr[low], arr[high]

def find(query):
    s1, s2 = binary_search(query, S)
    t1, t2 = binary_search(query, T)
    return s1, s2, t1, t2

def main():
    for x in X:
        s1, s2, t1, t2 = find(x)
        cands = [
            abs(t1-x) + abs(s2-t1),
            abs(s1-x) + abs(t2-s1),
            abs(s2-x) + abs(t1-s2),
            abs(t2-x) + abs(s1-t2),
            abs(t1-x) + abs(s1-t1),
            abs(s1-x) + abs(t1-s1),
            abs(s2-x) + abs(t2-s2),
            abs(t2-x) + abs(s2-t2)
        ]
        print(min(cands))
    return

main()

A, B, Q = map(int, input().split())
INF = 10**12
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]


def binary_search(query, arr):
    low = 0
    high = len(arr)
    while high-low>1:
        mid = (low+high)//2
        if query>arr[mid]:
            low = mid
        else:
            high = mid
    return arr[low], arr[high]

def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        ans = [ abs(t-s)+min(abs(t-x), abs(s-x)) \
            for t in [t1, t2] for s in [s1, s2] ]
        print(min(ans))
    return

main()

Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
def main():
    A, B, Q = list(map(int, input().split()))
    ss = [int(input()) for _ in range(A)]
    ts = [int(input()) for _ in range(B)]
    xs = [int(input()) for _ in range(Q)]
    
    for i, x in enumerate(xs):
        ss_diff = [(s-x) for s in ss]
        ts_diff = [(t-x) for t in ts]
        #print(ss_diff + ts_diff)
        p = x
        min1 = 1e10
        for a in (ss_diff + ts_diff):
            if abs(a) < min1:
                min1 = abs(a)
                p = a

        #print("p = ", p)
        if p in ss_diff:
            q = sorted([abs(p-t) for t in ts_diff])[0]
            
        else:
            q = sorted([abs(p-s) for s in ss_diff])[0]
            
        #ans.append(p+q)
        print(abs(p)+q)


if __name__ == "__main__":
    main()


import bisect


def main():
    A, B, Q = map(int, input().split())
    INF = 10 ** 18
    s = [-INF] + [int(input()) for _ in range(A)] + [INF]
    t = [-INF] + [int(input()) for _ in range(B)] + [INF]
    for q in range(Q):
        x = int(input())
        b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
        res = INF
        for S in [s[b-1], s[b]]:
            for T in [t[d-1], t[d]]:
                d1 = abs(S-x) + abs(T-S)
                d2 = abs(T-x) + abs(S-T)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect

a,b,q=map(int,input().split())
s = []
t = []
for i in range(a):
  s.append(int(input()))
for i in range(b):
  t.append(int(input()))
for _ in range(q):
  x = int(input())
  
  ans = [0,0,0]
  
  if x in s:
    sl = 0
    sr = 0
  else:
    i = bisect.bisect_left(s,x)
    if i == 0:
      sl = 100000000000
    else:
      sl = abs(s[i-1]-x)
    if i == a:
      sr = 100000000000
    else:
      sr = abs(s[i]-x)
  if x in t:
    tl = 0
    tr = 0
  else:
    i = bisect.bisect_left(t,x)
    if i == 0:
      tl = 100000000000
    else:
      tl = abs(t[i-1]-x)
    if i == b:
      tr = 100000000000
    else:
      tr = abs(t[i]-x)
  ans[0] = max(tl,sl)
  ans[1] = max(tr,sr)
  ans[2] = min(2*tl+sr,2*sl+tr)
  print(min(ans))

import bisect

a,b,q=map(int,input().split())
s = []
t = []
for i in range(a):
  s.append(int(input()))
for i in range(b):
  t.append(int(input()))
for _ in range(q):
  x = int(input())
  
  ans = [0,0,0]
  
  i = bisect.bisect_left(s,x)
  if i == 0:
    sl = 100000000000
  else:
    sl = abs(s[i-1]-x)
  if i == a:
    sr = 100000000000
  else:
    sr = abs(s[i]-x)
  i = bisect.bisect_left(t,x)
  if i == 0:
    tl = 100000000000
  else:
    tl = abs(t[i-1]-x)
  if i == b:
    tr = 100000000000
  else:
    tr = abs(t[i]-x)
  ans[0] = max(tl,sl)
  ans[1] = max(tr,sr)
  ans[2] = min(2*tl+sr,2*sl+tr,2*sr+tl,2*tr+sl)
  print(min(ans))

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
from bisect import bisect_left, bisect_right

A,B,Q = map(int,input().split())
S = sorted(list(int(input()) for i in range(A)))
T = sorted(list(int(input()) for i in range(B)))
X = list(int(input()) for i in range(Q))


for i in range(len(X)) :
    calc1 = float("inf")
    calc2 = float("inf")
    calc3 = float("inf")
    calc4 = float("inf")
    
    ind_s_left  = bisect_left(S,X[i])
    ind_t_left  = bisect_left(T,X[i])
    ind_s_right = bisect_right(S,X[i])
    ind_t_right = bisect_right(T,X[i])
    
    
    res = []
    
    try :
        c1 = X[i] - min(S[ind_s_right], T[ind_t_right])
        res.append(c1)
    except IndexError :
        continue
    
    try :
        c2 = max(S[ind_s_left], T[ind_t_right]) - X[i]
        res.append(c2)
    except IndexError :
        continue

    try :
        c3 = abs(S[ind_s_left] - T[ind_t_right])
        c3 += min(abs(X[i] - S[ind_s_left]), abs(X[i] - T[ind_t_right]))
        
    except IndexError :
        continue
    
    
    try :
        c4 = abs(T[ind_t_left] - S[ind_s_right])
        c4 += min(abs(X[i] - T[ind_t_left]), abs(X[i] - S[ind_s_right]))
    except IndexError :
        continue
    print(min(res))
    

import bisect

A,B,Q = map(int,input().split())
INF = 10**12
S = [-INF]+[int(input()) for i in range(A)]+[INF]
T = [-INF]+[int(input()) for i in range(B)]+[INF]
for i in range(Q) :
    x = int(input())
    
    right_s = S[bisect.bisect_right(S,x)]
    right_t = T[bisect.bisect_right(T,x)]
    left_s = S[bisect.bisect_right(S,x) - 1]
    left_t = T[bisect.bisect_right(T,x) - 1]
    
    dist = []
    
    for i in [left_s,right_s] :
        for j in [left_t,right_t] :
            d = min(abs(x-i), abs(x-j)) + abs(i-j)
            dist.append(d)
    ans = min(dist)
    
    print(ans)
    

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return small, large


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    for _ in range(q):
        ans = INF

        x = ni()

        idxs = bisect.bisect_left(s, x)
        a1 = [disLR(s, idxs)]

        idxt = bisect.bisect_left(t, x)
        a2 = [disLR(t, idxt)]

        for ta1 in a1:
            for ta2 in a2:
                tmp1 = abs(x - a1) + abs(a2 - a1)
                tmp2 = abs(x - a2) + abs(a1 - a2)
                ans = min(ans, tmp1, tmp2)

        print(ans)


if __name__ == '__main__':
    main()


import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===



def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    def disLR(a, idx):
        small = a[max(0, idx - 1)]
        large = a[min(len(a) - 1, idx)]
        return [small, large]

    for _ in range(q):
        ans = INF

        x = ni()

        idxs = bisect.bisect_left(s, x)
        a1 = disLR(s, idxs)

        idxt = bisect.bisect_left(t, x)
        a2 = disLR(t, idxt)

        for ta1 in a1:
            for ta2 in a2:
                tmp1 = abs(x - ta1) + abs(ta2 - ta1)
                tmp2 = abs(x - ta2) + abs(ta1 - ta2)
                ans = min(ans, tmp1, tmp2)

        print(ans)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
jin,ter,q=map(int,input().split())
jil,tel=[-float("INF")]+[int(input()) for i in range(jin)]+[float("INF")],[-float("INF")]+[int(input()) for i in range(ter)]+[float("INF")]
from bisect import bisect_left as bl
for _ in range(q):
    x=int(input())
    ans=float("INF")
    b,d=bl(jil,x),bl(tel,x)
    for s in jil[b:b+2]:
        for t in tel[d:d+2]:
            ans=min(min(abs(x-s),abs(t-x))+abs(t-s),ans)
    print(ans)

jin,ter,q=map(int,input().split())
INF=10**19
jil,tel=[-INF]+[int(input()) for i in range(jin)]+[INF],[-INF]+[int(input()) for i in range(ter)]+[INF]
from bisect import bisect_right as bl
for _ in range(q):
    x=int(input())
    ans=INF
    b,d=bl(jil,x),bl(tel,x)
    for s in jil[b-1:b+1]:
        for t in tel[d-1:d+1]:
            ans=min(min(abs(x-s),abs(t-x))+abs(t-s),ans)
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
if __name__ == '__main__':
    A, B, Q = map(int, input().split())

    s_list = [int(input()) for i in range(A)]
    t_list = [int(input()) for i in range(B)]
    x_list = [int(input()) for i in range(Q)]

    for xi in x_list:
        distance_ti_right_xi = [ti-xi for ti in t_list if ti >= xi]
        distance_ti_left_xi = [xi-ti for ti in t_list if ti <= xi]
        distance_si_right_xi = [si-xi for si in s_list if si >= xi]
        distance_si_left_xi = [xi-si for si in s_list if si <= xi]
        
        first_move = min(distance_si_left_xi, distance_si_right_xi, distance_ti_left_xi, distance_ti_right_xi)
        if first_move == distance_ti_left_xi or first_move == distance_si_left_xi:
            first_move = -1 * first_move
        xi += first_move

        if abs(first_move) == distance_si_left_xi or abs(first_move) == distance_si_right_xi:
            distance_ti_right_xi = [ti-xi for ti in t_list if ti >= xi]
            distance_ti_left_xi = [xi-ti for ti in t_list if ti <= xi]
            second_move = min(distance_ti_left_xi, distance_ti_right_xi)

        if abs(first_move) == distance_ti_left_xi or abs(first_move) == distance_ti_right_xi:
            distance_si_right_xi = [si-xi for si in s_list if si >= xi]
            distance_si_left_xi = [xi-si for si in s_list if si <= xi]
            second_move = min(distance_si_left_xi, distance_si_right_xi)
        answer = abs(first_move) + abs(second_move)
        print(answer)

import bisect
import itertools
import sys


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]

if __name__ == '__main__':
    A, B, Q = map(int, input().split())


    s_list = [-sys.maxsize] + [int(input()) for i in range(A)] + [sys.maxsize]
    t_list = [-sys.maxsize] + [int(input()) for i in range(B)] + [sys.maxsize]
    x_list = [int(input()) for i in range(Q)]


    for xi in x_list:
        s_RL = most_simRL(s_list, xi)
        t_RL = most_simRL(t_list, xi)

        answer = sys.maxsize

        for a, b in itertools.product(s_RL, t_RL):
            answer = min(answer, min(abs(xi-a), abs(xi-b)) + abs(a-b))

        print(answer)

Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
        print(res)

import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
    from bisect import bisect
    A,B,Q=map(int, input().split())
    s=[int(input()) for _ in range(A)] + [99**99]
    t=[int(input()) for _ in range(B)] + [99**99]
    snt=[0]*A + [99**99]
    tns=[0]*B + [99**99]
    for i in range(A):
    	p = bisect(t, s[i])
    	snt[i] = min(abs(s[i] - t[p-1]), abs(s[i] - t[p]))
    for i in range(B):
    	p = bisect(s, t[i])
    	tns[i] = min(abs(t[i] - s[p-1]), abs(t[i] - s[p]))
    for _ in range(Q):
    	x = int(input())
    	ans = []
    	p = bisect(s, x)
    	ans.append(abs(s[p] - x) + snt[p])
    	ans.append(abs(s[p-1] - x) + snt[p-1])
    	p = bisect(t, x)
    	ans.append(abs(t[p] - x) + tns[p])
    	ans.append(abs(t[p-1] - x) + tns[p-1])
    	print(min(ans))

from bisect import bisect
A,B,Q=map(int, input().split())
s=[int(input()) for _ in range(A)] + [99**99]
t=[int(input()) for _ in range(B)] + [99**99]
snt=[0]*A + [99**99]
tns=[0]*B + [99**99]
for i in range(A):
	p = bisect(t, s[i])
	snt[i] = min(abs(s[i] - t[p-1]), abs(s[i] - t[p]))
for i in range(B):
	p = bisect(s, t[i])
	tns[i] = min(abs(t[i] - s[p-1]), abs(t[i] - s[p]))
for _ in range(Q):
	x = int(input())
	ans = []
	p = bisect(s, x)
	ans.append(abs(s[p] - x) + snt[p])
	ans.append(abs(s[p-1] - x) + snt[p-1])
	p = bisect(t, x)
	ans.append(abs(t[p] - x) + tns[p])
	ans.append(abs(t[p-1] - x) + tns[p-1])
	print(min(ans))

Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
print(s, t, x)
for i in x:
    si = bisect.bisect_left(s,i)
    ti = bisect.bisect_left(t,i)
    sl = 100000000000 if si == 0 else i - s[si-1]
    sr = 100000000000 if si == a else s[si] - i
    tl = 100000000000 if ti == 0 else i - t[ti-1]
    tr = 100000000000 if ti == b else t[ti] - i
    print(min(max(sl,tl), max(sr,tr), max(sl,tr) + min(sl, tr)*2, max(sr,tl) + min(sr,tl)*2))


import bisect
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
x = [int(input()) for _ in range(q)]
for i in x:
    si = bisect.bisect_left(s,i)
    ti = bisect.bisect_left(t,i)
    sl = 100000000000 if si == 0 else i - s[si-1]
    sr = 100000000000 if si == a else s[si] - i
    tl = 100000000000 if ti == 0 else i - t[ti-1]
    tr = 100000000000 if ti == b else t[ti] - i
    print(min(max(sl,tl), max(sr,tr), max(sl,tr) + min(sl, tr)*2, max(sr,tl) + min(sr,tl)*2))


Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect
a,b,q=map(int,input().split())
A=[-10**11]
for i in range(a):
  A.append(int(input()))
A.append(10**11)
print(A)
B=[-10**11]
for i in range(b):
  B.append(int(input()))
B.append(10**11)
for i in range(q):
  x=int(input())
  c=bisect.bisect_left(A,x,hi=len(A))
  print(c)
  d=bisect.bisect_left(B,x,hi=len(B))
  ans=min(abs(A[c-1]-x)+abs(B[d-1]-A[c-1]),abs(A[c-1]-x)+abs(B[d]-A[c-1]),abs(A[c]-x)+abs(B[d-1]-A[c]),abs(A[c]-x)+abs(B[d]-A[c]),abs(B[d-1]-x)+abs(B[d-1]-A[c-1]),abs(B[d-1]-x)+abs(B[d-1]-A[c]),abs(B[d]-x)+abs(B[d]-A[c-1]),abs(B[d]-x)+abs(B[d]-A[c]))
  print(ans)

import bisect
a,b,q=map(int,input().split())
A=[-10**11]
for i in range(a):
  A.append(int(input()))
A.append(10**11)
B=[-10**11]
for i in range(b):
  B.append(int(input()))
B.append(10**11)
for i in range(q):
  x=int(input())
  c=bisect.bisect_left(A,x,hi=len(A))
  d=bisect.bisect_left(B,x,hi=len(B))
  ans=min(abs(A[c-1]-x)+abs(B[d-1]-A[c-1]),abs(A[c-1]-x)+abs(B[d]-A[c-1]),abs(A[c]-x)+abs(B[d-1]-A[c]),abs(A[c]-x)+abs(B[d]-A[c]),abs(B[d-1]-x)+abs(B[d-1]-A[c-1]),abs(B[d-1]-x)+abs(B[d-1]-A[c]),abs(B[d]-x)+abs(B[d]-A[c-1]),abs(B[d]-x)+abs(B[d]-A[c]))
  print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect
a,b,q=map(int,input().split())
S,T=[],[]
for i in range(a):
  S.append(int(input()))
for i in range(b):
  T.append(int(input()))
def f(list,n):
  if n<list[0]:
    return [-float("inf"),list[0]]
  elif list[-1]<n:
    return [list[-1],float("inf")]
  else:
    i=bisect.bisect_left(list,n)
    return [list[i],list[i+1]]
def g(SS,TT,x):
  a,b,c,d=x-SS[0],SS[1]-x,x-TT[0],TT[1]-x
  dis1=max(a,c)
  dis2=min(2*a+d,2*d+a)
  dis3=max(b,d)
  dis4=min(2*b+c,2*c+b)
  return min([dis1,dis2,dis3,dis4])
for i in range(q):
  x=int(input())
  print(g(f(S,x),f(T,x),x))

import bisect
import sys
input = sys.stdin.readline
a,b,q=map(int,input().split())
S,T=[],[]
for i in range(a):
  S.append(int(input()))
for i in range(b):
  T.append(int(input()))
def f(list,n):
  if n<list[0]:
    return [-float("inf"),list[0]]
  elif list[-1]<n:
    return [list[-1],float("inf")]
  else:
    i=bisect.bisect_left(list,n)
    return [list[i-1],list[i]]
def g(SS,TT,x):
  a,b,c,d=x-SS[0],SS[1]-x,x-TT[0],TT[1]-x
  dis1=max(a,c)
  dis2=min(2*a+d,2*d+a)
  dis3=max(b,d)
  dis4=min(2*b+c,2*c+b)
  return min([dis1,dis2,dis3,dis4])
for i in range(q):
  x=int(input())
  print(g(f(S,x),f(T,x),x))

Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
#ABC119 D - Lazy Faith
from bisect import bisect_left,bisect_right
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

a,b,q = map(int, input().split())
INF = 10**11
S = [-INF]+[int(input()) for _ in range(a)]+[INF]
T = [-INF]+[int(input()) for _ in range(b)]+[INF]
X = [int(input()) for _ in range(q)]

for i in range(q):
    idx_s = bisect_left(S,X[i])
    idx_t = bisect_left(T,X[i])
    ans = INF
    for s in [S[idx_s-1],S[idx_s]]:
        for t in [T[idx_s-1],T[idx_s]]:
            d1,d2 = abs(s-X[i])+abs(s-t),abs(t-X[i])+abs(t-s)
            ans = min(ans,d1,d2)
    print(ans)


uwaaaaaaaaaaaaaaaaaaaaaa

a,b,q = map(int, input().split())
inf=10**18
s=[-inf]+[int(input()) for _ in range(a)]+[inf]
t=[-inf]+[int(input()) for _ in range(b)]+[inf]
x=[int(input()) for _ in range(q)]
from bisect import bisect_left,bisect_right
for i in range(q):
    idx_s=bisect_right(s,x[i])
    idx_t=bisect_right(t,x[i])
    ans=inf
    for ss in [s[idx_s-1],s[idx_s]]:
        for tt in [t[idx_t-1],t[idx_t]]:
            d1,d2=abs(ss-x[i])+abs(ss-tt),abs(tt-x[i])+abs(tt-ss)
            ans=min(ans,d1,d2)
    print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect

a, b, q = map(int, input().split())
S = [int(input()) for i in range(a)]
T = [int(input()) for i in range(b)]
X = [int(input()) for i in range(q)]

for i in range(q):
    id = bisect.bisect_left(S, X[i])
    if id == 0:
        s = S[id]
    elif id == len(S):
        s = S[id - 1]
    else:
        if abs(X[i] - S[id]) < abs(X[i] - S[id - 1]):
            s = S[id]
        else:
            s = S[id - 1]
    
    id2 = bisect.bisect_left(T, X[i])
    if id2 == 0:
        t = T[id2]
    elif id2 == len(T):
        t = T[id2 - 1]
    else:
        if abs(X[i] - T[id2]) < abs(X[i] - T[id2 - 1]):
            t = T[id2]
        else:
            t = T[id2 - 1]
        
    if abs(X[i] - s) < abs(X[i] - t):
        ans = abs(X[i] - s)
        id3 = bisect.bisect_left(T, s)
        if id3 == 0:
            ans += abs(s - T[id3])
        elif id3 == len(T):
            ans += abs(s - T[id3 -1])
        else:
            if abs(s - T[id3]) < abs(s - T[id3 - 1]):
                ans += abs(s - T[id3])
            else:
                ans += abs(s - T[id3 -1])
                
    elif abs(X[i] - s) > abs(X[i] - t):
        ans = abs(X[i] - t)
        id4 = bisect.bisect_left(S, t)
        if id4 == 0:
            ans += abs(t - S[id4])
        elif id4 == len(S):
            ans += abs(t - S[id4 -1])
        else:
            if abs(t - S[id4]) < abs(t - S[id4 - 1]):
                ans += abs(t - S[id4])
            else:
                ans += abs(t - S[id4 -1])
    
    print(ans)

import bisect
a, b, q = map(int, input().split())
inf = float('inf')
S = [- inf] + [int(input()) for i in range(a)] + [inf]
T = [- inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
    x = int(input())
    s_idx = bisect.bisect_left(S, x)
    s1, s2 = S[s_idx - 1], S[s_idx]
    
    t_idx = bisect.bisect_left(T, x)
    t1, t2 = T[t_idx - 1], T[t_idx]
    
    ans = inf
    for i in s1, s2:
        for j in t1, t2:
            ans = min(ans, abs(x - i) + abs(i - j))
            ans = min(ans, abs(x - j) + abs(i - j))
                
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect
import numpy as np
INF=10**18
A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
s=[-INF]+s+[INF]
t=[-INF]+t+[INF]
s=np.array(s)
t=np.array(t)
for q in range(G):
    X=int(input())
    t1=bisect.bisect_right(t,X)
    l1=X-t[t1]
    if (t[t1]-X)>(X-t[t1-1]):
        l1=X-t[t1-1]
    s1=bisect.bisect_right(s,X)
    l2=X-s[s1]
    if (s[s1]-X)>(X-s[s1-1]):
        l2=X-s[s1-1]
    l3=bisect.bisect_right(s,X-l1)
    l4=bisect.bisect_right(t,X-l2)
    print(min(abs(l1)+min(s[l3]-X+l1,X-l1-s[l3-1]),abs(l2)+min(t[l4]-X+l2,X-l2-t[l4-1])))



import bisect
INF=10**18
A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
s=[-INF]+s+[INF]
t=[-INF]+t+[INF]
for q in range(Q):
    X=int(input())
    t1=bisect.bisect_right(t,X)
    s1=bisect.bisect_right(s,X)
    res=INF
    for T in [t[t1],t[t1-1]]:
        for S in [s[s1],s[s1-1]]:
            ans1=abs(X-T)+abs(S-T)
            ans2=abs(X-S)+abs(S-T)
            res=min(res,ans1,ans2)
    print(res)



Verdicts: Runtime Error

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
from bisect import bisect, bisect_left
inf = float('inf')

A,B,Q = map(int,input().split())
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def solve(x):
    si = bisect(S,x)
    sl,sr = S[si-1],S[si]
    ti = bisect(T,x)
    tl,tr = T[ti-1],T[ti]
    ans = inf
    for s in [sl,sr]:
        for t in [tl,tr]:
            res = min(abs(s-x),abs(t-x)) + abs(s-t)
            ans = min(res,ans)
    return ans

for x in X:
    ans = solve(x)
    print(ans)

from bisect import bisect, bisect_left
inf = float('inf')

A,B,Q = map(int,input().split())
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def solve(x):
    si = bisect(S,x)
    sl,sr = S[si-1],S[si]
    ti = bisect(T,x)
    tl,tr = T[ti-1],T[ti]
    ans = inf
    for s in [sl,sr]:
        for t in [tl,tr]:
            res0 = abs(s-x) + abs(s-t)
            res1 = abs(t-x) + abs(s-t)
            ans = min(ans,res0,res1)
    return ans

for x in X:
    ans = solve(x)
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.  Answer the following Q queries:    * Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Submission attempts (in order):
import bisect

a,b,q=map(int,input().split())
tem=[-10**18]+[int(input()) for _ in range(a)]+[10**18]
shr=[-10**18]+[int(input()) for _ in range(b)]+[10**18]
ans=[]

for _ in range(q):
    x=int(input())
    t=bisect.bisect_right(tem, x)
    s=bisect.bisect_right(shr, x)
    dt=[x-tem[t-1], tem[t]-x]
    ds=[x-shr[s-1], shr[s]-x]

    m=min(dt+ds)
    if m in dt:
        m_ind=dt.index(m)
        m2=min(ds)
        m2_ind=ds.index(m2)
    else:
        m_ind=ds.index(m)
        m2=min(dt)
        m2_ind=dt.index(m2)

    if m_ind==m2_ind:
        ans.append(m2)
    else:
        ans.append(m2 + m*2)

print(*ans, sep="\n")
    



import sys
import bisect
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
bl = bisect.bisect_left

A, B, Q = map(int, input().split())
inf = 10**18
S = [-inf]+[int(input()) for _ in range(A)]+[inf]
T = [-inf]+[int(input()) for _ in range(B)]+[inf]


def path(x):
    sl = S[bl(S, x) - 1]
    sr = S[bl(S, x)]
    tl = T[bl(T, x) - 1]
    tr = T[bl(T, x)]

    res = 10 ** 18
    res = min(res, abs(x - sl) + abs(sl - tl))
    res = min(res, abs(x - sl) + abs(sl - tr))
    res = min(res, abs(x - sr) + abs(sr - tr))
    res = min(res, abs(x - sr) + abs(sr - tl))
    res = min(res, abs(x - tr) + abs(tr - sl))
    res = min(res, abs(x - tr) + abs(tr - sr))
    res = min(res, abs(x - tl) + abs(tl - sl))
    res = min(res, abs(x - tl) + abs(tl - sr))
    return res


X = [int(input()) for _ in range(Q)]
for x in X:
    print(path(x))

Verdicts: Wrong Answer

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
# -*- coding: utf-8 -*-

def parse_input():
    line = [int(e) for e in input().split(" ")]
    a = line[0]
    b = line[1]

    returnr (a, b)


def solve(a, b):

    result = 0
    if b % a == 0:
        result = a + b
    else:
        result = b - a

    return str(result)

def main():
    

    a, b = parse_input()
    print(solve(a, b))

if __name__ == '__main__':

    main()


# -*- coding: utf-8 -*-

def parse_input(lines_as_string = None):

    if lines_as_string is None:
        lines = [e for e in input()]
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    params = lines[0].split(" ")
    a = int(params[0])
    b = int(params[1])

    return (a, b)


def solve(a, b):

    result = 0
    if b % a == 0:
        result = a + b
    else:
        result = b - a

    return result

def main():
    

    a, b = parse_input()
    print("%d" % solve(a, b))

if __name__ == '__main__':

    main()


# -*- coding: utf-8 -*-

import sys
import math

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    params = lines[0].split(" ")
    a = int(params[0])
    b = int(params[1])

    return (a, b)


def solve(a, b):

    result = 0
    if b % a == 0:
        result = a + b
    else:
        result = b - a

    return result

def main():
    

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
A,B = map(int,input().split())

if A%B == 0:
    print(A+B)
else:
    print(B-A)


A,B = map(int,input().split())

if A%B == 0:
    print(A+B)
else:
    print(B-A)


A,B = map(int,input().split())

if 0<A<21 and 0<B<21:
    if A%B == 0:
        print(A+B)
    else:
        print(B-A)
else :
    print("error")


A,B = map(int,input().split())

if 0<A<21 and 0<B<21:
    if B%A == 0:
        print(A+B)
    else:
        print(B-A)
else :
    print("error")


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
a=map(int,input().split())
if a[1]%a[0]==0:
    print(a[0]+a[1])
else:
    print(a[1]-a[0])

a=list(map(int,input().split()))
if a[1]%a[0]==0:
    print(a[0]+a[1])
else:
    print(a[1]-a[0])

Verdicts: Runtime Error

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
def check(A):
  check_result = []
  for i in range(1, len(A)):
    check_result.append(list(set(A[i-1])&set(A[i])))
  if len(check_result) != len(A):
    return check_result
  return False

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(len(A)):
  A[i].pop(0)
while True:
  check_result = check(A)
  if check_result:
    A = check_result
  else:
    if not A[0]:
      print(0)
      break
    else:
      print(len(A[0]))
      break

a,b=map(int,input().split());print([b-a,a+b][b%a==0])

Verdicts: Runtime Error

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
A, B = map(int, input().split())

if B // A != 0:
  print(B - A)
else:
  print(A+B)

A, B = map(int, input().split())

if B % A != 0:
  print(B - A)
else:
  print(A+B)

Verdicts: Wrong Answer

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
a,b=map(int,input().split())
if a%b==0:
    print(a+b)
else:
    print(b-a)

a,b=map(int,input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)

Verdicts: Wrong Answer

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
x,y=[int(i) for i in input().split()]

if x%y==0:
	print(x%y)
else:
	print(x-y)

x,y=[int(i) for i in input().split()]

if x%y==0:
	print(x+y)
else:
	print(x-y)

x,y=[int(i) for i in input().split()]

if x-y>0:
  A=x
  B=y
else:
  A=y
  B=x

if A%B==0:
	print(A+B)
else:
	print(A-B)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
a,b = map (int , input().split())
if b % a == 0 ;
    c = a+b
else;
    c = b-a
print (c)

a,b = map (int , input().split())
if b % a == 0 ;
    c = a+b
else;
    c = b-a
print (c)

a,b = map (int , input().split())
if b % a == 0 :
    c = a+b
else:
    c = b-a
print (c)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given positive integers A and B.  If A is a divisor of B, print A + B; otherwise, print B - A.

Submission attempts (in order):
a,b = map(int, input().split())
if a%b==0:
    print(a+b)
else:
    print(b-a)


a,b = map(int, input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)


Verdicts: Wrong Answer

Accepted