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: Runtime Error

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

med = N / 2 + 0.5

for i in range(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: Runtime Error

Solution code:
def even(d):
    return d // 2

def odd(A, B, N):
    if abs(A-1) > abs(B-(N)):
        dist2edge = abs(B-(N))
        A += dist2edge
        B += dist2edge 
        assert B == N

        return even(abs((A+1)- B)) + 1 + dist2edge

    else:
        dist2edge = abs(A)
        A -= dist2edge
        B -= dist2edge
        assert A == 1
    
        return even(abs(A- (B-1))) + 1 + dist2edge


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

    if diff % 2 == 0:
        print(even(diff))
    else:
        print(odd(A, B, N))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

print(int(ans))

Submission status: Runtime Error

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

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

else:
    upper = max(a-1, b-1)
    lower = max(n-a, n-b)

	print(min(upper, lower))

Submission status: Runtime Error

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

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

else:
    upper = max(a-1, b-1)
    lower = max(n-a, n-b)

print(min(upper, lower))

Submission status: Runtime Error

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
/*
--- My CPP Template ---
@Handle: pruvi007 :)
@Name: Praveen Kumar :)
@Institution: IIIT Guwahati :)
*/

#include<bits/stdc++.h>
using namespace std;

#define fast  ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL)
#define ll long long int 
#define ld long double
#define pb  push_back
#define mp  make_pair
#define mod 1000000007

ll power(ll x, ll n){
    if(n==0)
    return 1;
    
    if(n%2)
    return (x*power((x*x)%mod, (n-1)/2))%mod;
    else
    return power((x*x)%mod, n/2);
}

template<typename T>
class DSU{
    public:
      T parent [200005];
      T size [200005];
      void init(T x){
          parent[x] = x;
          size[x] = 1;
      }
      T root(T x){
          if(parent[x] == x)
          return x;
          return parent[x] = root(parent[x]);
      }
      void Union(T x, T y){
          x = root(x);
          y = root(y);
          if(x != y){
              if(size[x] < size[y])
              swap(x, y);
              parent[y] = x;
              size[x] += size[y];
          }
      }
};

template <typename T>
class Segment_Tree{
    public:
      ll tree[4*100005];
      ll a[100005];
      void build(ll node, ll s, ll e){
          if(s == e)
          tree[node] = a[s];
          else{
              ll mid = (s + e)/2;
              build(2*node, s, mid);
              build(2*node+1, mid+1, e);
              tree[node] = (tree[2*node] | tree[2*node+1]);
          }
      }
 
      void update(ll node, ll s, ll e, ll pos, ll val){
          if(s == e){
              tree[node] = val;
              a[pos] = val;
          }
          else{
              ll mid = (s + e)/2;
              if(pos <= mid)
              update(2*node, s, mid, pos, val);
              else
              update(2*node+1, mid+1, e, pos, val);
              tree[node] = (tree[2*node] | tree[2*node+1]);
          }
      }
 
      ll query(ll node, ll s, ll e, ll l, ll r){
          if(s >= l && e <= r)
          return tree[node];
          else if(e < l || s > r)
          return 0ll;
          else{
              ll mid = (s + e)/2;
              ll left = query(2*node, s, mid, l, r);
              ll right = query(2*node+1, mid+1, e, l, r);
              return (left | right);
          }
      }
};  

int main()
{
    fast;
    /////////////////////////////////////////////////////////////////////////
    ll n,a,b;
    cin >> n >> a >> b;
    ll d = b-a;
    if(d%2==0)
        cout << d/2 << endl;
    else
    {
        ll left = a-1;
        ll right = n-b;
        ll ans;
        if(  left>right )
            ans =  d + (n-b)+1;
           
        else
            ans = d + (a);
        cout << ans << endl;
        
    }
    


    ////////////////////////////////////////////////////////////////////////
    return 0;
}

Submission status: Runtime Error

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

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

    else:
        print((b-a)//2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split())
min_=min(a,b)
max_=max(a,b)

k=max_-min_-1
if k%2!=0:#間の卓が奇数
    if k==1:
        print(k)
    else:
        ans=(k-1)//2+""
        print(ans)
else:#偶数
    ans=min(max_-1,n-min_)
    print(ans)

Submission status: Runtime Error

Solution code:
n,a,b= map(int,input().split())
if a<b:
  tmp=a
  a=b
  b=a
if abs(a-b)%2==0:
  c=abs(a-b)//2
else:
  if abs(a-b)>=3:
    c = c-abs(a-b)//2
  elif abs(a-b)<3:
	c=min(abs(1-a),abs(n-b))

print(c)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


def main():
    N,A,B = (int(x) for x in input().split())


    def calc(n, a, b, ans):
        if abs(a-b)%2 == 0:
            return ans + (abs(a-b)//2)
        else:
            if min(a,b) - (n - max(a,b)) <= 0:
                a -= 1 if not a==1 else 0
                b -= 1 if not b==1 else 0
            else:
                a += 1 if not a==n else 0
                b += 1 if not b==n else 0
            ans += 1
            return calc(n,a,b,ans)



    # お互いに近づくのが最高のパターン
    if abs(A-B)%2 == 0:
        print(abs(a-b)//2)
        quit()
    
    # どちらかの端に寄ってから考えるパターン
    # 寄るための試合数
    left = min(A,B) -1
    right = N - max(A,B) - 1
    
    # 左によるパターン
    if left - right <= 0:
        print(calc(N, 1, B-left, left))
    else:
        print(calc(N, A+right, N, right))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = int(input())
B = int(input())

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = int(input())
b = int(input())
r = 0

if (b-a)%2==0:
    print(int((b-a)/2))
else:
    if a<n/2:
        while b!=1:
            b-=1
            r+=1
        print(r)
    else:
        while a!=n:
            a+=1
            r+=1
        print(r)

Submission status: Runtime Error

Solution code:
n = int(input())
x = int(input())
y= int(input())
a=max(x,y)
b=min(x,y);
 
if a-b%2==0:
	print((a-b)/2)
 
else:
	print(max(a-1,n-b))

Submission status: Runtime Error

Solution code:
from decimal import Decimal
N, A, B = input().split()
n=Decimal(N)
a=Decimal(A)
b=Decimal(B)
if (b-a) % 2==0:
    print((b-a)//2))
elif (b-1) < (n-a):
    print(b-1)
else:
    print(n-a)

Submission status: Runtime Error

Solution code:
n,a,b=map(int,input().split()))
cnt=0
if (b-a) != 1:
    while a:
        a+=1
        b-=1
        cnt+=1
        if a == b:
            print(cnt)
            exit()
if (b-a) == 1:
    if a-1 > n-b:
        while a:
            if b != n:
                b+=1
                a+=1
                cnt+=1
            if b == n:
                a+=1
                cnt+=1
            if a == n and b == n:
                print(cnt)
                exit()
    if a-1 < n-b:
        while a:
            if a != 1:
                a-=1
                b-=1
                cnt+=1
            if a == 1:
                b-=1
                cnt+=1
            if a == 1 and b == 1:
                print(cnt)
                exit()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)

def main():
    N,A,B = (int(x) for x in input().split())
    
    def calc(n, a, b, ans):
        if abs(a-b)%2 == 0:
            return ans + (abs(a-b)//2)
        else:
            if min(a,b) - (n - max(a,b)) <= 0:
                a -= 1 if not a==1 else 0
                b -= 1 if not b==1 else 0
            else:
                a += 1 if not a==n else 0
                b += 1 if not b==n else 0
            ans += 1
            return calc(n,a,b,ans)
            
    print(calc(N,A,B,0))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, a_, b_ = map(int, input().split())
a = a_-1
b = b_-1
A = [0]*n
B = [0]*n
for i in range(n):
  A[i] = abs(i-a)
  B[i] = abs(i-b)
for i in range(n):
  if A[i]==B[i]:
    print(A[i])
    exit()
m = [A[0], B[0], A[n-1], B[n-1]]
M = m.index(min(m))
if M == 0:
  print(m[1])
elif M == 1:
  print(m[0])
elif M == 2:
  print(m[3])
elif M == 3:
  print(m[2])

Submission status: Runtime Error

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

if C == 1:
    kabe = int(min(N-B,A-1))
    print(kabe + 1)
elif C % 2 == 0:
    print(int(C / 2))
else:
    NB = N-B
    A1 = A-1
    if NB < A1:
        NA = N-A
        zan = int((NA-NB-1)/2)
        print(int(NB+1+zan))
    else:
        zan = int(((B-1)-A1-1)/2)
        print(int(A1+1+zan)

Submission status: Runtime Error

Solution code:
n,a,b = map(int, raw_input().split())
if (b-a == 1 or a-b==1):
    print(1)
if (b-a == 2 or a-b ==2):
    print(2)
if (b-a > 3 or a-b > 3):
    if (b>a):
        print(b-1)
    elif (a>b): 
        print(a-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input("Number of Table: "))
a = int(input("Friend A: "))
b = int(input("Friend B: "))
r = 0

if (b-a)%2==0:
    print(int((b-a)/2))
else:
    if a<n/2:
        while b!=1:
            b-=1
            r+=1
        print(r)
    else:
        while a!=n:
            a+=1
            r+=1
        print(r)

Submission status: Runtime Error

Solution code:
N,A,B = (int(x) for x in input().split())

def calc(n, a, b, ans):
    if abs(a-b)%2 == 0:
        return ans + (abs(a-b)//2)
    else:
        if min(a,b) - (n - max(a,b)) <= 0:
            a -= 1 if not a==1 else 0
            b -= 1 if not b==1 else 0
        else:
            a += 1 if not a==n else 0
            b += 1 if not b==n else 0
        ans += 1
        return calc(n,a,b,ans)
        
print(calc(N,A,B,0))

Submission status: Runtime Error

Solution code:
a = A - 1
b = N - B
if a == b:
    print(a)
else:
    ans = (a if a < b else b) + 1
    print(ans)

Submission status: Runtime Error

Solution code:
# このくらい10秒で実装しろ。。。
 n, a, b = map(int, input().split())

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

Submission status: Runtime Error

Solution code:
//#pragma GCC optimize("O3")
//#pragma GCC target("avx")

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

// Types
using ll = long long int;
using str = string;
template <class T> using u_set = unordered_set<T>;
template <class K, class V> using u_map = unordered_map<K, V>;
template <class V> using graph = u_map<V, u_set<V>>;
template <class F,
          typename enable_if<is_function<F>::value, nullptr_t>::type = nullptr>
using fun = function<F>;

namespace io {
// Input
using IS = istream;
IS &in(IS &i);
IS &in(IS &i) { return i; }
template <class T, class... Ts> IS &in(IS &i, T &a, Ts &... as) {
  return in(i >> a, as...);
}
template <class V> IS &operator>>(IS &i, vector<V> &a) {
  for_each(a.begin(), a.end(), [&i](auto &e) { i >> e; });
  return i;
}
template <class F, class S> IS &operator>>(IS &i, pair<F, S> &p) {
  return in(i, p.first, p.second);
}
template <class... Ts, size_t... I>
IS &tuple_in(IS &i, tuple<Ts...> &t, index_sequence<I...>) {
  return in(i, get<I>(t)...);
}
template <class... Ts> IS &operator>>(IS &i, tuple<Ts...> &t) {
  return tuple_in(i, t, make_index_sequence<sizeof...(Ts)>());
}
// Output
using OS = ostream;
OS &out(OS &o) { return o << endl; }
template <class T> OS &out(OS &o, T const &a) { return o << a << endl; }
template <class T, class... Ts> OS &out(OS &o, T const &a, Ts const &... as) {
  return out(o << a << " ", as...);
}
template <class F, class S> OS &operator<<(OS &o, pair<F, S> const &p) {
  return o << p.first << ":" << p.second;
}
template <class... Ts> OS &args_out(OS &o, Ts const &... ts);
OS &args_out(OS &o) { return o; }
template <class T> OS &args_out(OS &o, T const &t) { return o << t; }
template <class T0, class T1, class... Ts>
OS &args_out(OS &o, T0 const &t0, T1 const &t1, Ts const &... ts) {
  return args_out(o << t0 << ",", t1, ts...);
}
template <class... Ts, size_t... I>
OS &tuple_out(OS &o, tuple<Ts...> const &t, index_sequence<I...>) {
  return args_out(o, get<I>(t)...);
}
template <class... Ts> OS &operator<<(OS &o, tuple<Ts...> const &t) {
  return tuple_out(o << "(", t, make_index_sequence<sizeof...(Ts)>()) << ")";
}
template <
    class C,
    class T = typename iterator_traits<typename C::iterator>::value_type,
    typename enable_if<!is_same<C, str>::value, nullptr_t>::type = nullptr>
OS &operator<<(OS &o, C const &a) {
  return a.empty() ? (o << "[]") : ([&o, &a]() -> OS & {
    o << "[" << *a.begin();
    for_each(next(a.begin()), a.end(), [&o](auto const &e) { o << "," << e; });
    return o << "]";
  }());
}
} // namespace io
auto input = [](auto &... a) { io::in(cin, a...); };
auto print = [](auto const &... a) { io::out(cout, a...); };
#ifdef JUMPAKU_DEBUG
auto dump = [](auto const &... a) { io::out(cerr, a...); };
#else
auto dump = [](auto const &... a) {};
#endif

// Hash
namespace hashcode {
template <class... Ts> size_t hash_args(size_t h, Ts const &... ts);
size_t hash_args(size_t h) { return h; }
template <class T, class... Ts>
size_t hash_args(size_t h, T const &t, Ts const &... ts) {
  return hash_args(((h << 10) - h + hash<T>{}(t)), ts...);
}
template <class... Ts, size_t... I>
size_t hash_tuple(tuple<Ts...> const &t, index_sequence<I...>) {
  return hash_args(17, get<I>(t)...);
}
} // namespace hashcode
namespace std {
template <class... Ts> struct hash<tuple<Ts...>> {
  size_t operator()(tuple<Ts...> const &t) const {
    return hashcode::hash_tuple(t, index_sequence_for<Ts...>());
  }
};
} // namespace std

// Range
vector<ll> range(ll const &begin, ll const &end) {
  vector<ll> ret(max(0LL, end - begin));
  iota(ret.begin(), ret.end(), begin);
  return ret;
}
vector<ll> range(ll const &end) { return range(0, end); }
template <class T = ll> vector<T> vec(size_t n, T &&init = T()) {
  return vector<T>(n, init);
}
template <class Itr, class T = typename iterator_traits<Itr>::value_type>
vector<T> vec(Itr begin, Itr end) {
  return vector<T>(begin, end);
}

ll bisect(ll ng, ll ok, fun<bool(ll)> const &is_ok) {
  while (ok - ng > 1) {
    dump(ng, ok);
    ll m = ng + (ok - ng) / 2;
    (is_ok(m) ? ok : ng) = m;
  }
  return ok;
}
ll gcd(ll p, ll q) { return (q == 0) ? p : gcd(q, p % q); }
ll lcm(ll p, ll q) { return p / gcd(q, p) * q; }

// MOD
ll pow(ll a, ll n, ll m) {
  if (n == 0)
    return 1;
  if (n & 1)
    return ((a % m) * pow(a, n - 1, m)) % m;
  auto b = pow(a, n / 2, m);
  return (b * b) % m;
}
ll inv(ll a, ll p) { return pow(a, p - 2, p); }
constexpr ll MOD = 1e9 + 7;

int main() {
  ll N, A, B;
  input(N, A, B);
  dump(N, A, B);
  if ((B - A) % 2 == 0) {
    return print((B - A) / 2), 0;
  }
  if (A - 1 < N - B) {
    return print(A + (B - A - 1) / 2), 0;
  }
  print(N - B + 1 + (N - (A + N - B + 1)) / 2);
}

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

d = b - a + 1
print(math.ceil(d/2))

Submission status: Runtime Error

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

if (abs(A-B)==1):
    return min(A,B)
elif: abs(A-B)==2:
    return abs(A-B)-1

Submission status: Runtime Error

Solution code:
import sys
import math

(N, A, B) = (input(), input(), input())
print(math.ceil(B-A))

Submission status: Runtime Error

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
N,A,B = [int(x) for x in stdin.readline().rstrip().split()]
if (B - A) % 2 == 0:
    print(min((B-A)//2),N-A,B-1)
else:
    print(min(N-A,B-1))

Submission status: Runtime Error

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

if C%2==0:
  print(C/2/)
else:
  dist_a=A-1
  dist_b=N-B
  base=min(dist_a,dist_b)
  print(base+(B-A+1)//2)

Submission status: Runtime Error

Solution code:
    for _ in range(test_case):
import sys
readline = sys.stdin.readline

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = int(input())
B = int(input())
ans = N-B
print(ans)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
#include <numeric>
#include <array>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n, int mod) {
    if (n == 0) { return 1 % mod; }
    int x = rui(a, n / 2, mod);
    x *= x; x %= mod;
    if (n % 2 == 1) { x *= a; x %= mod; }
    return x;
}
vel pa;
vel siz;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; siz[y] += siz[x]; siz[x] = 0; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vel uni(vel x) {
    if (x.size() == 0) { return x; }
    sor(x);
    int n = x.size();
    vel ans(1, x[0]);
    for (int j = 1; j < n; j++) {
        if (x[j - 1] != x[j]) { ans.push_back(x[j]); }
    }
    x = ans;
    return x;
}
void pr(vel& v) {
    int n = v.size();
    if (n != 0) {
        cout << v[0];
        rep(i, n - 1) {
            cout << " " << v[i + 1];
        }
        cout << endl;
    }
}
int sol(int x, int k) {
    if (x == 0 || k == 0) { return 0; }
    return x + sol(x / 2, k - 1);
}
vel pri(int n) {
    veb ans(n, true);
    vel prime;
    for (int j = 2; j < n; j++) {
        if (ans[j]) {
            prime.push_back(j);
            for (int k = 2; j * k < n; k++) {
                ans[j * k] = false;
            }
        }
    }
    return prime;
}
bool solve(vel& a, int se, int k, int m) {
    int n = a.size();
    rep(i, n) {
        if (a[i] < se) { a[i] = se; k = k + a[i] - se; }
    }
    if (k < 0) { return false; }
    int ex1 = 0;
    int ex2 = 0;
    rep(i, n) {
        ex1 += n - se;
        mmax(ex2, a[i] - se);
    }
    return true;
}
vel solve(int i, vel& a, vvel& b, vel& back) {
    int n = a.size();
    vel dp(n);
    vel list(n);
    int now_i = -1;
    rep(j, n) {
        if (a[j] != i) {
            if (back[j] == -1) {
                if (now_i == -1) { dp[j] = 1; }
                else { dp[j] = 2; }
            }
            else if (back[j] < now_i) {
                dp[j] = dp[back[j]] + 2;
            }
            else {
                dp[j] = dp[back[j]];
            }
        }
        else {
            now_i = j;
        }
    }
    rep(j, n) {
        if ((b[j].size() > 0) && j != i) {
            int back_j = b[j][b[j].size() - 1];
            if (back_j < now_i) { dp[back_j]++; }
            list[j] = dp[back_j];
        }
        else {
            if (b[i].size() > 0) { list[j] = 1; }
        }
    }
    return list;
}
void distu(int n, int m, int k, int l, V<string> &S) {
    int H = S.size();
    if (k != 0 || l != 0) {
        n += k;
        m += l;
        bool fl = false;
        while (0<=n&&n<H&&0<=m&&m<H) {
            if (S[n][m] == 'Q'||S[n][m]=='#') { break; }
            if (S[n][m] == 'X') { fl = true; break; }
            n += k;
            m += l;
        }
        if (fl) {
            n -= k; m -= l;
            S[n][m] = '#';
        }
    }
    return;
}
vel bfs(int st, V<V<pin>>& way) {
    int n = way.size();
    vel dist(n, -1); dist[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int x = q.front(); q.pop();
        for (auto nex : way[x]) {
            if (dist[nex.first] >= 0) { dist[nex.first] = dist[x] + 1; }
        }
    }
    return dist;
}
V<V<pin>> dbl(V<pin>& v) {
    int n = v.size();
    V<V<pin>> ans(19, V<pin>(n));
    ans[0] = v;
    rep(i, 18) {
        rep(j, n) { 
            ans[i + 1][j] = mkp(ans[i][ans[i][j].first].first,ans[i][ans[i][j].first].second+ans[i][j].second); 
        }
    }
    return ans;
}
signed main(){
    int n,a, b; cin >> n>>a >> b;
    if (a % 2 == b % 2) {
        cout << abs(b - a) / 2 << endl;
        return 0;
    }
    if (a > b) { swap(a, b); }
    cout << min(b - 1, n - a) << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,A,B=map(int,input().split())
if (B-A)%2==0:5 2 
    print((B-A)//2)
else:
    print(min(B-1,N-A))