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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

namespace ConsoleApp2
{
    class Program
    {
        static void Main()
        {

            int input = int.Parse(Console.ReadLine());

            int sum = 0;
            for (int i = 1; i < input; i++)
            {
                sum += i;
                if (sum % input ==0)
                {
                    Console.WriteLine(i);
                    break;
                }
            }


        //    int count = 0;
        //    var list = new List<int[]>();
        //    var listMove = new List<List<int>>();

        //    while (true)
        //    {

        //        string line = Console.ReadLine();
        //        // 読み込める文字列が無くなった
        //        if (line == null)
        //        {
        //            break;
        //        }

        //        //初回はスキップ
        //        if (count == 0)
        //        {
        //            count++;
        //            continue;
        //        }

        //        var a = new int[] { line[0], line[2] };
        //        list.Add(a);

        //        count++;
        //    }

        //    for (int i = 0; i < list.Count(); i++)
        //    {
        //        int point = 1;
        //        var a = new List<int>();

        //        count = 0;
        //        foreach (var item in list)
        //        {
        //            if ((list[i][0] > item[0] && list[i][1] > item[1]) || (list[i][0] < item[0] && list[i][1] < item[1]))
        //            {
        //                point++;
        //                a.Add(count);
        //            }
        //            count++;
        //        }


        //        Console.WriteLine(point);

        //    }

        //    for (int i = 0; i < listMove.Count(); i++)
        //    {
        //        var a = new List<int>();


        //        foreach (var item in listMove[i])
        //        {
        //            if (a.Any(b => b.Equals(item)) == false)
        //            {
        //                a.Add(item);

        //                while (true)
        //                {
        //                    if (a.Any(b => b.Equals(item)) == false)
        //                    {
                            
        //                    }
        //                }
        //            }
        //        }


        //    }
        }
    }
}