Problem:
Score : 600 points

Problem Statement

Given is an integer N.
Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N.
It can be proved that such a positive integer k always exists.

Constraints

1 \leq N \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer in a line.

Sample Input 1

11

Sample Output 1

10

1+2+\cdots+10=55 holds and 55 is indeed a multple of N=11.
There are no positive integers k \leq 9 that satisfy the condition, so the answer is k = 10.

Sample Input 2

20200920

Sample Output 2

1100144

Solution in PyPy3 (7.3.0) (judge verdict: Wrong Answer)

#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
delta = 8*n
t = 1
from math import sqrt
while True:
    t += delta
    sq = t**(0.5)
    a = (-1+sq)/2
    b = (-1-sq)/2
    ans = float('inf')
    if a > 0 and a.is_integer():
        ans = min(ans,a)
    if b > 0 and b.is_integer():
        ans = min(ans,b)
    if ans != float('inf'):
        print(int(ans))
        break