Problem: 2N players are running a competitive table tennis training on N tables numbered from 1 to N.  The training consists of _rounds_. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses.  The winner of the match on table X plays on table X-1 in the next round, except for the winner of the match on table 1 who stays at table 1.  Similarly, the loser of the match on table X plays on table X+1 in the next round, except for the loser of the match on table N who stays at table N.  Two friends are playing their first round matches on distinct tables A and B. Let's assume that the friends are strong enough to win or lose any match at will. What is the smallest number of rounds after which the friends can get to play a match against each other?

Submission attempts (in order):
import time

def fib(n):
    if n == 0 or n == 1:
        return 1
    
    return fib(n-1) + fib(n-2)

class Fib_memo:
    def __init__(self):
        self.fib_memo = {}

    def cal_fib(self, n):
        if n == 0 or n == 1:
            self.fib_memo[n] = 1
            return 1

        if n in self.fib_memo.keys():
            return self.fib_memo[n]
        
        self.fib_memo[n] = self.cal_fib(n-1) + self.cal_fib(n-2)
        return self.fib_memo[n]

def fib_dynamic(n):
    
    cal_result = {}

    
    cal_result[0] = 1
    cal_result[1] = 1

    for i in range(2, n+1):
        cal_result[i] = cal_result[i-1] + cal_result[i-2]

    return cal_result[n]

# n = int(input())
cost_1 = []
cost_2 = []
cost_3 = []

max_n = 15
for n in range(1, max_n+1):
    print("n:{}".format(n))
    time_sta = time.perf_counter()
    fib(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_1.append(time_end-time_sta)

    time_sta = time.perf_counter()
    fib_memo = Fib_memo()
    fib_memo.cal_fib(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_2.append(time_end-time_sta)

    time_sta = time.perf_counter()
    fib_dynamic(n)
    time_end = time.perf_counter()
    print("It takes {} seconds".format(time_end-time_sta))
    cost_3.append(time_end-time_sta)

import matplotlib.pyplot as plt
x = [i for i in range(1, max_n+1)]
fig = plt.figure()
fig.subplots_adjust(left=0.15)
plt.plot(x, cost_1, label="Normal")
plt.plot(x, cost_2, label="Memo")
plt.plot(x, cost_3, label="Dynamic")
plt.xlim([0, max_n])
plt.xticks(x)

plt.legend()
plt.title("Cost Time")
plt.xlabel("n")
plt.ylabel("time[s]")

plt.savefig("./cal_time.png")


n, a, b = map(int, input().split())

def jud(n,a,b):
    distance_dic_before_a = []
    distance_dic_before_b = []
    distance_dic_before_a.append(a)
    distance_dic_before_b.append(b)

    turn_count = 1
    while True:
        distance_dic_after_a = []
        for a_dir in distance_dic_before_a:
            a_dir_plus = a_dir + 1
            a_dir_minus = a_dir - 1
            if a_dir_plus > n:
                a_dir_plus = n
            if a_dir_minus == 0:
                a_dir_minus = 1
            distance_dic_after_a.append(a_dir_plus)
            distance_dic_after_a.append(a_dir_minus)
        distance_dic_before_a = distance_dic_after_a

        distance_dic_after_b = []
        for a_dir in distance_dic_before_b:
            a_dir_plus = a_dir + 1
            a_dir_minus = a_dir - 1
            if a_dir_plus > n:
                a_dir_plus = n
            if a_dir_minus == 0:
                a_dir_minus = 1
            distance_dic_after_b.append(a_dir_plus)
            distance_dic_after_b.append(a_dir_minus)
        distance_dic_before_b = distance_dic_after_b

        set_a = set(distance_dic_after_a)
        set_b = set(distance_dic_after_b)
        print(set_a, set_b)
        result_set = set_a & set_b
        if len(result_set) > 0:
            return turn_count

        turn_count +=1

def jud_2(n,a,b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2
 
    x = n - a
    y = b - 1
 
    if x > y:
        choice_1 = a-1+1 + (y-a) // 2
        if choice_1 > y:
            return y
        else:
            return choice_1
    else:
        choice_2 = n-b+1 + (x-(n-b+1)) // 2
        if choice_2 > x:
            return x
        else:
            return choice_2
# print(jud(n, a, b))
print(jud_2(n,a,b))

Verdicts: Runtime Error

Accepted