Buggy python submission (verdict: Runtime Error):
import sympy.ntheory.modular

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+2, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    x = sympy.ntheory.modular.crt([a, b], [0, -1])
    if x is None:
        pass
    else:
        ans = min(ans, x[0])

print(ans)

Fixed submission:
import math
def extgcd(a, b):
    """
    ax + by = gcd(a,b) = d となる (x,y,d) を返す
    """
    if b == 0:
        return (1, 0, a)
    q, r = a // b, a % b
    x, y, d = extgcd(b, r)
    s, t = y, x - q * y
    return s, t, d

def inv_mod(a, N):
    """
    ax = 1 mod N となる x を返す
    """
    return extgcd(a, N)[0]

def CRT(a_1, a_2, m_1, m_2):
    """
    x = a_1 mod m_1, x = a_2 mod m_2 となる x を返す
    """
    y = (a_2 - a_1) * inv_mod(m_1, m_2) % m_2
    return a_1 + m_1 * y

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    if math.gcd(a, b) == 1:
        P = CRT(0, -1, a, b)
        if P != 0:
            ans = min(P, ans)
        Q = CRT(0, -1, b, a)
        if Q != 0:
            ans = min(Q, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = int(input())
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = 3*N
for i in range(len(K)):
    a, b = K[i]
    p = copy.copy(b)
    while(True):
        if b > ans:
            break
        if (2*b-1) % a == 0:
            ans = min(ans, 2*b-1)
        elif (2*b+1) % a == 0:
            ans = min(ans, 2*b)
        if b % 2 == 1:
            if ((b - 1) // 2) % a == 0:
                ans = min(ans, b - 1)
            elif ((b + 1) // 2) % a == 0:
                ans = min(ans, b)
        b += p

if N == 1:
    print(1)
elif N == 2:
    print(3)
else:
    print(ans)

Fixed submission:
import math
def extgcd(a, b):
    """
    ax + by = gcd(a,b) = d となる (x,y,d) を返す
    """
    if b == 0:
        return (1, 0, a)
    q, r = a // b, a % b
    x, y, d = extgcd(b, r)
    s, t = y, x - q * y
    return s, t, d

def inv_mod(a, N):
    """
    ax = 1 mod N となる x を返す
    """
    return extgcd(a, N)[0]

def CRT(a_1, a_2, m_1, m_2):
    """
    x = a_1 mod m_1, x = a_2 mod m_2 となる x を返す
    """
    y = (a_2 - a_1) * inv_mod(m_1, m_2) % m_2
    return a_1 + m_1 * y

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    if math.gcd(a, b) == 1:
        P = CRT(0, -1, a, b)
        if P != 0:
            ans = min(P, ans)
        Q = CRT(0, -1, b, a)
        if Q != 0:
            ans = min(Q, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N = 10**15
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = 3*N
for i in range(len(K)):
    a, b = K[i]
    p = copy.copy(b)
    while(True):
        if b > ans:
            break
        if (2*b-1) % a == 0:
            ans = min(ans, 2*b-1)
        elif (2*b+1) % a == 0:
            ans = min(ans, 2*b)
        if b % 2 == 1:
            if ((b - 1) // 2) % a == 0:
                ans = min(ans, b - 1)
            elif ((b + 1) // 2) % a == 0:
                ans = min(ans, b)
        b += p

if N == 1:
    print(1)
elif N == 2:
    print(3)
else:
    print(ans)

Fixed submission:
import math
def extgcd(a, b):
    """
    ax + by = gcd(a,b) = d となる (x,y,d) を返す
    """
    if b == 0:
        return (1, 0, a)
    q, r = a // b, a % b
    x, y, d = extgcd(b, r)
    s, t = y, x - q * y
    return s, t, d

def inv_mod(a, N):
    """
    ax = 1 mod N となる x を返す
    """
    return extgcd(a, N)[0]

def CRT(a_1, a_2, m_1, m_2):
    """
    x = a_1 mod m_1, x = a_2 mod m_2 となる x を返す
    """
    y = (a_2 - a_1) * inv_mod(m_1, m_2) % m_2
    return a_1 + m_1 * y

N = int(input())
N *= 2
K = [[1, N]]
for i in range(2, max(int(N**0.5)+1, 2)):
    if N % i == 0:
        K.append([i, N//i])

ans = float("inf")
for i in range(len(K)):
    a, b = K[i]
    if math.gcd(a, b) == 1:
        P = CRT(0, -1, a, b)
        if P != 0:
            ans = min(P, ans)
        Q = CRT(0, -1, b, a)
        if Q != 0:
            ans = min(Q, ans)

print(ans)