Problem:


Score : 300 points

Problem Statement

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?

Constraints

2 \leq N \leq 10^{18}

1 \leq A < B \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the smallest number of rounds after which the friends can get to play a match against each other.

Sample Input 1

5 2 4

Sample Output 1

1

If the first friend loses their match and the second friend wins their match, they will both move to table 3 and play each other in the next round.

Sample Input 2

5 2 3

Sample Output 2

2

If both friends win two matches in a row, they will both move to table 1.



Sample input:
5 2 4


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
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)
        result_set = set_a & set_b
        if len(result_set) > 0:
            return turn_count

        turn_count +=1

print(jud(n, a, b))

Submission status: Time Limit Exceeded

Solution code:
inputs = input()

inputs = inputs.split(" ")

inputs[0] = int(inputs[0])
inputs[1] = int(inputs[1])
inputs[2] = int(inputs[2])

result = 0

if inputs[1]<inputs[2]:
    p1=inputs[1]
    p2=inputs[2]
elif inputs[2]<inputs[1]:
    p1=inputs[2]
    p2=inputs[1]

if (p1 - p2)%2 != 0 : 
    tmp1 = p1 - 1
    tmp2 = inputs[0] - p2
    if tmp1 < tmp2 :
        p1 = 1
        p2 -= tmp1+1
        result += tmp1+1
    elif tmp2 < tmp1 :
        p1 += tmp2+1
        p2 = inputs[0]
        result += tmp2+1


while p1 != p2 :
    p1+=1
    p2-=1
    result+=1

print(result)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5
maxAB = 10 ** 18

Max = max([A, B])
Min = min([A, B])

for i in range(maxAB):
    if (Max - Min) % 2 == 0:
            Max = Max - 1
            Min = Min + 1
    else:
        medAB = (Max + Min) / 2
        if medAB > med:
            Max = Max + 1
            Min = Min + 1

            if Max > N:
                Max = N
            elif Min > N:
                Min = N
        else:
            Max = Max - 1
            Min = Min - 1
        
            if Max < 1:
                Max = 1
            elif Min < 1:
                Min = 1
        

    round_count = round_count + 1

    if Max == Min:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5
maxAB = 10 ** 18

Max = max([A, B])
Min = min([A, B])

for i in range(maxAB):
    if (Max - Min) % 2 == 0:
            Max = Max - 1
            Min = Min + 1
    else:
        medAB = (Max + Min) / 2
        if medAB > med:
            Max = Max + 1
            Min = Min + 1
        else:
            Max = Max - 1
            Min = Min - 1

    if Max < 1:
        Max = 1
    elif Max > N:
        Max = N
    elif Min < 1:
        Min = 1
    elif Min > N:
        Min = N

    round_count = round_count + 1

    if Max == Min:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5
maxAB = 10 ** 18

for i in range(maxAB):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1
        else:
            A = A + 1
            B = B - 1
    else:
        medAB = (A + B) / 2
        if medAB > med:
            A = A + 1
            B = B + 1
        else:
            A = A - 1
            B = B - 1

    if A < 1:
        A = 1
    elif A > N:
        A = N
    elif B < 1:
        B = 1
    elif B > N:
        B = N

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5
maxAB = 10 ** 18

for i in range(maxAB):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1

            if A < 1:
                A = 1
            elif B > N:
                B = N
        else:
            A = A + 1
            B = B - 1

            if A > N:
                A = N
            elif B < 1:
                B = 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        medAB = (Max + Min) / 2
        if medAB > med:
            A = A + 1
            B = B + 1

            if A > N:
                A = N
            elif B > N:
                B = N
        else:
            A = A - 1
            B = B - 1

            if A < 1:
                A = 1
            elif B < 1:
                B = 1

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = input().split()
n = int(n)
a = int(a)
b = int(b)

counter = 0

while True:
    if abs(a-b) %2 != 0:
        if a == 1:
            b -= 1
        elif b == 1:
            a -= 1
        else:
            a -= 1
            b -= 1
        counter += 1
    if abs(a-b) %2 == 0:
        if a-b == 0:
            break
        elif a-b > 0:
            a -= 1
            b += 1
            counter += 1
        else:
            a += 1
            b -= 1
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5
maxAB = 10 ** 18

for i in range(maxAB):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1

            if A < 1:
                A = 1
            elif B > N:
                B = N
        else:
            A = A + 1
            B = B - 1

            if A > N:
                A = N
            elif B < 1:
                B = 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1

            if A > N:
                A = N
            elif B > N:
                B = N
        else:
            A = A - 1
            B = B - 1

            if A < 1:
                A = 1
            elif B < 1:
                B = 1

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
i = 1
p = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a <= (n//2):
        for i in range(1,n):
            b -= 1
            if p == 1:
                a += 1
            elif a <= 1:
                a = 1
                p += 1
            else:
                a -= 1
            if a == b:
                print(i)
                break
    else:
        for i in range(1,n):
            a += 1
            if p == 1:
                b -= 1
            elif b >= n:
                b = n
                p += 1
            else:
                b += 1
            if a == b:
                print(i)
                break

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split(' '))

cnt = 0
for i in range(n):
    if a == b:
        break
    avg = (a + b) % 2
    if avg == 0:
        if a > b:
            a = a - 1 if a > 1 else a
            b = b + 1 if b < n else b
        else:
            a = a + 1 if a < n else a
            b = b - 1 if b > 1 else b
    else:
        a = a - 1 if a > 1 else a
        b = b - 1 if b > 1 else b
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())
i = 1
p = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a <= math.floor(n/2):
        while True:
            b -= 1
            if p == 1:
                a += 1
            elif a <= 1:
                a = 1
                p += 1
            else:
                a -= 1
            if a == b:
                print(i)
                break
            i += 1
    else:
        while True:
            a += 1
            if p == 1:
                b -= 1
            elif b >= n:
                b = n
                p += 1
            else:
                b += 1
            if a == b:
                print(i)
                break
            i += 1

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split(' '))

cnt = 0
for i in range(n):
    avg = (a + b) % 2
    if avg == 0:
        if a > b:
            a = a - 1 if a > 1 else a
            b = b + 1 if b < n else b
        else:
            a = a + 1 if a < n else a
            b = b - 1 if b > 1 else b
    else:
        a = a - 1 if a > 1 else a
        b = b - 1 if b > 1 else b
    cnt += 1
    if a == b:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5

for i in range(int(1e18)):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1

            if A < 1:
                A = 1
            elif B > N:
                B = N
        else:
            A = A + 1
            B = B - 1

            if A > N:
                A = N
            elif B < 1:
                B = 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1

            if A > N:
                A = N
            elif B > N:
                B = N
        else:
            A = A - 1
            B = B - 1

            if A < 1:
                A = 1
            elif B < 1:
                B = 1

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5

while(True):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1

            if A < 1:
                A = 1
            elif B > N:
                B = N
        else:
            A = A + 1
            B = B - 1

            if A > N:
                A = N
            elif B < 1:
                B = 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1

            if A > N:
                A = N
            elif B > N:
                B = N
        else:
            A = A - 1
            B = B - 1

            if A < 1:
                A = 1
            elif B < 1:
                B = 1

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
nc, ac, bc = map(int, input().split())

n = nc - 1
a = ac - 1
b = bc - 1

if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    left = a
    right = n - b
    if left <= right:
        ran = b - a
        flag = 0
        ans = 0
        while (ran % 2 != 0):
            b -= 1
            if a != 0:
                a -= 1
            else:
                if flag == 0:
                    flag = 1
                else:
                    a += 1
            ran = b - a
            ans += 1
        print(ans + (ran // 2))
    else:
        ran = b - a
        flag = 0
        ans = 0
        while (ran % 2 != 0):
            a += 1
            if b != n:
                b += 1
            else:
                if flag == 0:
                    flag = 1
                else:
                    b -= 1
            ran = b - a
            ans += 1
        print(ans + (ran // 2))

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())

if (b-a)%2==0:
    print((b-a)//2)
else:
    if n >= 10**5:
        if a < math.floor(n/2):
            i = 0
            while True:
                b -= i
                if a <= 1:
                    a = 1
                else:
                    a -= i
                if a == b:
                    a += 10000
                    b += 10000
                    for j in range(1,10001):
                        a -= j
                        b -= j
                        if a <= 1:
                            a = 1
                        if a == b:
                            print(i+j)
                            break
                    break
                i += 10000
        else:
            i = 0
            while True:
                a += i
                if b >= n:
                    b = n
                else:
                    b += i
                if a == b:
                    a -= 10000
                    b -= 10000
                    for j in range(1,10001):
                        a += j
                        b += j
                        if b >= n:
                            b = n
                        if a == b:
                            print(i+j)
                            break
                    break
                i += 10000
    else:
        if a < math.floor(n/2):
            i = 0
            while True:
                b -= i
                if a <= 1:
                    a = 1
                else:
                    a -= i
                if a == b:
                    print(i)
                    break
                i += 1
        else:
            i = 0
            while True:
                a += i
                if b >= n:
                    b = n
                else:
                    b += i
                if a == b:
                    print(i)
                    break
                i += 1
    
#min  median max

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())

if (b-a)%2==0:
    print((b-a)//2)
else:
    if n >= 10**5:
        if a < math.floor(n/2):
            i = 0
            while True:
                a -= i
                b -= i
                if a <= 1:
                    a = 1
                if a == b:
                    a += 1000
                    b += 1000
                    for j in range(1,1001):
                        a -= j
                        b -= j
                        if a <= 1:
                            a = 1
                        if a == b:
                            print(i+j)
                            break
                    break
                i += 1000
        else:
            i = 0
            while True:
                a += i
                b += i
                if b >= n:
                    b = n
                if a == b:
                    a -= 1000
                    b -= 1000
                    for j in range(1,1001):
                        a += j
                        b += j
                        if b >= n:
                            b = n
                        if a == b:
                            print(i+j)
                            break
                    break
                i += 1000
    else:
        if a < math.floor(n/2):
            i = 0
            while True:
                a -= i
                b -= i
                if a <= 1:
                    a = 1
                if a == b:
                    print(i)
                    break
                i += 1
        else:
            i = 0
            while True:
                a += i
                b += i
                if b >= n:
                    b = n
                if a == b:
                    print(i)
                    break
                i += 1

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
round_count = 0

med = N / 2 + 0.5

while(True):
    if abs(A - B) % 2 == 0:
        if A > B:
            A = A - 1
            B = B + 1
        else:
            A = A + 1
            B = B - 1
    else:
        Max = max([A, B])
        Min = min([A, B])
        if (Max + Min) / 2 > med:
            A = A + 1
            B = B + 1
        else:
            A = A - 1
            B = B - 1

    if A < 1:
        A = 1
    elif A > N:
        A = N
    elif B < 1:
        B = 1
    elif B > N:
        B = N

    round_count = round_count + 1

    if A == B:
        break

print(round_count)

Submission status: Time Limit Exceeded

Solution code:
import sys
temp=list(map(int, input().split()))
N=temp[0]
A=temp[1]
B=temp[2]
cnt=0
if (B-A)%2==1:
  if A-1<=N-B:
    cnt=A
    B-=A
    A=1
  else:
    cnt=N-B+1
    A+=(N-B)+1
    B=N
while A!=B:
    if B-A>=2:
      A+=1
      B-=1
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())

if (b-a)%2==0:
    print((b-a)//2)
else:
    if a < math.floor(n/2):
        i = 0
        while True:
            b -= i
            if a <= 1:
                a = 1
            else:
                a -= i
            if a == b:
                print(i)
                break
            i += 1
    else:
        i = 0
        while True:
            a += i
            if b >= n:
                b = n
            else:
              b += i
            if a == b:
                print(i)
                break
            i += 1

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())

if (b-a)%2==0:
    print((b-a)//2)
else:
    if a < math.floor(n/2):
        i = 0
        while True:
            a -= i
            b -= i
            if a <= 1:
                a = 1
            if a == b:
                print(i)
                break
            i += 1
    else:
        i = 0
        while True:
            a += i
            b += i
            if b >= n:
                b = n
            if a == b:
                print(i)
                break
            i += 1
    
#min  median max

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split()))
ans_list = [i for i in range(2 ** N)]

loc = (A + B) / 2
if int((loc - A)) == 0:
    print(A)
else:
    print(int(loc - A))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if (B-A)%2 == 0:
  print((B-A)//2)
else:
  print(min((A+B)//2, (2*N-B-A+1)//2))

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
if (A + B) % 2 == 0:
  print(abs(A - B) // 2)
else:
  print(min((2 * N - A - B + 1) // 2, (A + B - 1) // 2))

Submission status: Accepted

Solution code:
n, a, b = map(int,input().split())
if a % 2 == b % 2:
    print((b-a)//2)
else:
    ans = min(n-b, a-1) + 1 + (b-a-1)//2
    print(ans)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())

if abs(A-B) % 2 == 0:
  print(abs(A-B) // 2)
  exit()
  
if abs(A-B) == 1:
  print(min(max(A-1,B-1),max(N-A,N-B)))
  exit()
  
print(min(min(A-1,B-1),min(N-A,N-B))+1+(abs(A-B)-1)//2)

Submission status: Accepted

Solution code:
N,A,B = map(int, input().split())
if A % 2 == B % 2:
    print((B-A) // 2)
else:
    x = min(B - 1, N - A)
    y = 1 + min(A - 1, N - B) + (B - A) // 2
    print(min(x, y))

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    N, A, B = map(int, input().split())

    ans = (B - A) // 2 if (B - A) % 2 == 0 else min(A - 1, N - B) + 1 + (B - A - 1) // 2

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, A, B = map(int, input().split())
    diff = abs(A-B)
    if diff%2 == 0:
        ans = diff//2
    else:
        # 端に行く
        # 一回端のままになる => 偶数のときと同じ
        ans = min(A-1, N-B)
        diff -= 1; ans += 1
        ans += diff//2
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,a,b=map(int, input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    print(min(a+(b-a-1)//2, n-b+1+(b-a-1)//2))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if (b-a)%2 ==0:
    print((b-a)//2)

else:
    min_sabun = min(a-1,n-b)
    kyori = (b-a-1)//2
    print(min_sabun+kyori+1)

Submission status: Accepted

Solution code:
N,a,b = map(int,input().split())

if (b-a)%2 ==0:
  ans = (b-a)//2
else:
  ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, a, b = map(int, input().split())
if abs(a - b) % 2 == 0:
    print(abs(a - b) // 2)
else:
    small, big = min(a, b), max(a, b)
    print(min(
        (small - 1) + 1 + ((big - (small - 1) - 1 - 1) // 2),
        (n - big) + 1 + ((n - (small + (n - big) + 1)) // 2)
    ))

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2);exit()
a-=1;b-=1
# print(min(b,n-1-a))
ans1=0; ans2=0
ans1+= a
aa=0 ; bb=b-a 
ans1+= (bb//2+1)

ans2=n-1-b 
b=n-1
a+=ans2
ans2+= (b-a)//2+1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, a, b = LI()
    a, b = min(a,b), max(a,b)
    ans = 0
    if (b-a)%2 == 0:
        ans = (b-a)//2
    else:
        ans = min(a+(b-a-1)//2, n-b+1+(n-(a+n-b+1))//2)
    print(ans)
main()

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())

if (B-A) % 2 == 0:
    print((B-A) // 2)
else:
    straight = min(B - 1, N - A)
    wrap = 1 + min(A - 1, N - B) + (B - A) // 2
    print(min(straight, wrap))

Submission status: Accepted

Solution code:
def solve():
    N, A, B = [int(i) for i in input().split()]
    if (A - B) % 2 == 0:
        print(abs(A - B) // 2)
    else:
        ans1 = ((N - A) + (N - B) + 1) // 2
        ans2 = ((A - 1) + (B - 1) + 1) // 2
        print(min(ans1, ans2))

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def solve():
    N, A, B = [int(i) for i in input().split()]
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        print(min(N - B, A - 1) + 1 + (B - A - 1) // 2)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    n, a, b = [int(x) for x in input().rstrip().split(" ")]

    if a > n - b + 1:
        tmp = a
        a = n - b
        b = n - tmp
    else:
        a = a - 1
        b = b - 1

    if (b - a) % 2 == 0:
        print(abs(a - b) // 2)
    else:
        count = a + 1 + ((b - a - 1) // 2)
        print(count)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
if abs(b-a)%2 == 0:
    print((b-a)//2)
else:
    print(min((2*n-a-b+1)//2,(a+b-1)//2))

Submission status: Accepted

Solution code:
n,a,b = map(int,input().split())
if (a%2 + b%2) %2 == 0:
    print(abs(a-b) // 2)
elif n - b < a - 1:
    p = n-b+1
    a += n-b
    b = n
    print(abs(a-b) // 2 + p)
else:
    p = a
    b -= a-1
    a = 1
    print(abs(a-b) // 2 + p)

Submission status: Accepted

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

ans = min((b - a - 1) // 2 + a, (n - b + 1 + (b - a - 1) // 2))

if (b - a) % 2 == 0:
    ans = (b - a) // 2

print(ans)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
d = min((b - a - 1) // 2 + a, (n - b + 1 + (b - a - 1) // 2))
 
if (b - a) % 2 == 0:
    d = (b - a) // 2
    
print(d)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print((B - A)//2)
elif A - 1 < N -B:
    print((A-1)+(B-A+1)//2)
else:
    print((N-B)+(B-A+1)//2)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,A,B = MI()
print((B-A)//2 if (B-A) % 2 == 0 else min((A+B-1)//2,N-(A+B-1)//2))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
if abs(A-B)%2==0:
    print(abs(A-B)//2)
else:
    if A>B:
        A, B, = B, A
    c = A + (B-A-1)//2
    d = (N-B+1) + (B-A-1)//2
    print(min(c, d))

Submission status: Accepted

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

p = b-a-1

if p%2==0:
    ans=0
    if a <=n-b:
        k = a-1
        a-=k
        b-=(k+1)
        ans+=k+1
    else:
        k = n-b
        a+=(k+1)
        b+=k
        ans += k+1
    p=b-a-1

    print(ans + (p+1)//2)
else:
    print((p+1)//2)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
ans=min(A-1,N-B)+1+(B-A-1)//2
sum=0
if (B-A)%2==0:
    sum=(B-A)//2
    ans=min(sum,ans)
print(ans)

Submission status: Accepted

Solution code:
import math

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

sa = B - A + 1;

if sa % 2 == 1 :
	ans = min(N - A, B - 1);
	#chmin(ans, (B - A) / 2);
	ans = min(ans, (B - A) // 2)

	print(ans)
else :
	ans = 10**30;

	# A を 1 に移動させて1勝
	ca = A
	cb = B

	ca = 1;
	cb -= A;

	cand = (cb - ca) // 2 + A;
	ans = min(ans, cand);

	# B を N に移動させて1敗
	ca = A
	cb = B
	cb = N;
	ca += N - B + 1;
	cand = (cb - ca) // 2 + (N - B + 1);

	ans = min(ans, cand);


	print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# 差が偶数だったら/2
# 奇数だったら端に行くまで対戦を続けないと行けない 折り返すのも考える
N, A, B = ints()
if (B - A) % 2 == 0:
    exit((B - A) // 2)
else:
    exit(min(A + (B - A) // 2, (N - B + 1) + (B - A) // 2))

Submission status: Accepted

Solution code:
'''
Created on 2020/09/03

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,A,B=map(int,pin().split())
  if (B-A)%2==0:
    print((B-A)//2)
    return 
  if A<N-B+1:
    print(A+(B-A-1)//2)
  else:
    print(N-B+1+(B-A-1)//2)
  return 
main()

Submission status: Accepted

Solution code:
import sys

N, A, B = map(int, sys.stdin.readline().split())
if (B - A) % 2 == 0:
    print((B - A) // 2)
else:
    print(min(A + (B - A - 1) // 2, N - B + 1 + (B - A - 1) // 2))

Submission status: Accepted

Solution code:
import sys


def LI():
    return list(map(int, input().split()))


N, A, B = LI()
if (B-A) % 2 == 0:
    print((B-A)//2)
    sys.exit()
a = 1
b = B-A
L = A+(b-a)//2
b = N
R = N-B+1
a = A+R
R += (b-a)//2
print(min(R, L))

Submission status: Accepted

Solution code:
import sys
n, a, b = map(int, input().split())

# 2で割って余り1ならすれ違わない
if (b - a) % 2 == 0:
    print((b - a) // 2)

else:
    # 左で折り返す場合
    left = ((a - 1) + (b - 1) + 1) // 2

    # 右で折り返す場合
    right = ((n - b) + (n - a) + 1) // 2

    print(min(left, right))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,A,B = MI()

if (B-A) % 2 == 0:
    print((B-A)//2)
else:
    if B-1 <= N-A:
        print((A+B-1)//2)
    else:
        print(N-(A+B-1)//2)

Submission status: Accepted

Solution code:
N,A,B = map(int,input().split())
if (B-A)%2==0:
    print((B-A)//2)
else:
    print(min(A,N-B+1)+(B-A-1)//2)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
if (b-a)%2==0:
  print((b-a)//2)
else:
  c=min(b-1,n-a)
  e=min(a-1,n-b)
  d=(b-a-1)//2+e+1
  print(min(c,d))

Submission status: Accepted

Solution code:
def main():
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        ans = min(n - b, a - 1) + 1 + (b - a - 1) // 2
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        if b - 1 < n - a:
            g = (b - a + 1) // 2
            ans = a + g - 1
        else:
            g = (2 * n + a - b + 1) // 2
            ans = 2 * n - b - g + 1
    
    print(ans)


if __name__ == "__main__":
    main()