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 C# (Mono-mcs 6.8.0.105) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;


class Test
{
    class A
    {
        public int num;
        public int freq;
    }
    static int mod = (int)1000000007;
    static long[] fact = new long[500001];
    static long[] factinv = new long[500001];
    static Dictionary<string, int> memo = new Dictionary<string, int>();
    // Driver code 
    public static void Main()
    {

        //var input = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        //var t = input[0];
        //while (t > 0)
        {
            //t--;
            var input1 = Console.ReadLine().Split(' ').Select(xx => long.Parse(xx)).ToArray();
            var n = input1[0];
            //var arr = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();

            for (long i = 1; i < n; i++)
            {
                long sum = ((i) * (i + 1)) / 2;
                if (sum % n == 0)
                {
                    Console.WriteLine(i);
                    break;
                }
            }

        }

    }




    public static void Run()
    {
        fact[0] = 1;
        factinv[0] = fast_pow(fact[0], mod - 2);
        for (int i = 1; i <= 500000; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
            factinv[i] = fast_pow(fact[i], mod - 2);
        }
    }
    public static long GetCom(int n, int r)
    {
        return fact[n] * factinv[r] % mod * factinv[n - r] % mod;
    }
    public static long fast_pow(long a, long b)
    {
        if (b == 0)
            return 1;
        long val = fast_pow(a, b / 2);
        if (b % 2 == 0)
            return val * val % mod;
        else
            return val * val % mod * a % mod;
    }

}