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# (.NET Core 3.1.201) (judge verdict: Time Limit Exceeded)

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ACLContest1
{
    class Program
    {
        static void Main(string[] args)
        {
            // 課題B - Sum is Multiple(2020/9/20)

            long item = long.Parse(Console.ReadLine());
            //sring[] result;

            //List<string[]> iptList = new List<string[]>();
            //long x = 0, y = 0, tmpX = 0, tmpY = 0;
            long ptnCnt = 1;
            long result = 0;

            while (true)
            {
                result = result + ptnCnt + ptnCnt +1;

                if ((result-ptnCnt- 1) % item == 0)
                {
                    Console.Write(ptnCnt);
                    break;

                }
                if (result % item == 0)
                {
                    Console.Write(ptnCnt+1);
                    break;

                }
                ptnCnt = ptnCnt +2;

            }

            

            ////var valueDict = new Dictionary<string, long>();

            //for (long i = 0; i < item; i++)
            //{
            //    //iptList.Add(Console.ReadLine().Split(' '));
            //    iptList.Add(Console.ReadLine().Split(' '));

            //}


            //for(long i= 0; i< item; i++)
            //{

            //    x = long.Parse(iptList[i].GetValue(0).ToString());
            //    y = long.Parse(iptList[i].GetValue(1).ToString());
            //    result[i]++;

            //    for (long j = 0; j < item; j++)
            //    {
            //        if (i == j) break;

            //        tmpX = long.Parse(iptList[j].GetValue(0).ToString());
            //        tmpY = long.Parse(iptList[j].GetValue(1).ToString());

            //        if (x > tmpX && y > tmpY)
            //        {
            //            result[i]++;
            //            result[j]++;
            //            continue;
            //        }

            //        if (x < tmpX && y < tmpY)
            //        {
            //            result[i]++;
            //            result[j]++;
            //        }

            //    }



            //}


            //for (long i = 0; i < item; i++)
            //{
            //    Console.WriteLine(result[i]);

            //}

            //Console.WriteLine(ptnCnt);


            //if(getStr.Equals("s")) Console.Write(str + "es");
            //else Console.Write(str + "s");
        }
    }
}