<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

193. Chinese Girls' Amusement
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



You must have heard that the Chinese culture is quite different from that of Europe or Russia. So some Chinese habits seem quite unusual or even weird to us.

So it is known that there is one popular game of Chinese girls. N girls stand forming a circle and throw a ball to each other. First girl holding a ball throws it to the K-th girl on her left (1 ≤ K ≤ N/2). That girl catches the ball and in turn throws it to the K-th girl on her left, and so on. So the ball is passed from one girl to another until it comes back to the first girl. If for example N = 7 and K = 3, the girls receive the ball in the following order: 1, 4, 7, 3, 6, 2, 5, 1.

To make the game even more interesting the girls want to choose K as large as possible, but they want one condition to hold: each girl must own the ball during the game.

Input

Input file contains one integer number N (3 ≤ N ≤ 102000) - the number of Chinese girls taking part in the game.

Output

Output the only number - K that they should choose.

Sample test(s)

Input
Test #1
7

Test #2
6


Output
Test #1
3

Test #2
1

Author:	Alexander Maximov, Andrew Stankevich
Resource:	Petrozavodsk Winter Trainings 2003
Date:	2003-02-06

<|response|>
1. Abridged Problem Statement  
You have N girls standing in a circle, numbered 1 through N. They pass a ball by always moving it K steps to the left (1 ≤ K ≤ N/2). Starting from girl 1, the ball returns to girl 1 after L = N / gcd(N, K) throws. We require that every girl touches the ball exactly once before it returns, i.e. L = N ⇒ gcd(N, K) = 1. Among all 1 ≤ K ≤ N/2 with gcd(N, K)=1, find the largest K. N can be up to 10^2000 (2000 decimal digits).

2. Key Observations  
- After t throws, the ball is at position (1 + t·K) mod N.  
- The first return to girl 1 occurs when t·K ≡ 0 (mod N), i.e. t = N / gcd(N, K).  
- We need each girl exactly once, so t = N ⇒ gcd(N, K) = 1.  
- We want the maximum K ≤ N/2 satisfying gcd(N, K)=1.  
- Most integers are coprime to N, so starting from K = ⌊N/2⌋ and decrementing, we’ll usually find a coprime quickly.  

3. Full Solution Approach  
1. Read N as a big integer (up to 2000 digits).  
2. Compute K = ⌊N/2⌋.  
3. While K ≥ 1:  
   a. Compute g = gcd(N, K) via Euclid’s algorithm on big integers.  
   b. If g == 1, output K and stop.  
   c. Otherwise, decrement K by 1 and repeat.  
Because the density of numbers coprime to N is φ(N)/N, on average we need only a few gcd checks. Each gcd on D‐digit numbers costs O(D²), which is fast enough for D≤2000.

4. C++ Implementation (using Boost.Multiprecision)  
```cpp
#include <iostream>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::multiprecision::cpp_int;

// Compute gcd(a, b) using Euclid's algorithm
cpp_int big_gcd(cpp_int a, cpp_int b) {
    while (b != 0) {
        cpp_int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Read N as a decimal string
    string s;
    if (!(cin >> s)) 
        return 0;

    // Convert to big integer N
    cpp_int N = 0;
    for (char c : s) {
        N = N * 10 + (c - '0');
    }

    // Start from floor(N/2)
    cpp_int K = N / 2;

    // Decrement K until gcd(N,K) == 1
    while (K > 0) {
        if (big_gcd(N, K) == 1) {
            // Found the largest valid K
            cout << K << "\n";
            break;
        }
        --K;
    }
    return 0;
}
```

5. Python Implementation  
```python
import sys
sys.setrecursionlimit(10000)

def gcd(a, b):
    # Standard Euclid's algorithm
    return a if b == 0 else gcd(b, a % b)

def main():
    s = sys.stdin.readline().strip()
    if not s:
        return

    # Convert input to Python int (unbounded precision)
    N = int(s)
    K = N // 2  # initial candidate

    # Decrement until we find a coprime
    while K > 0:
        if gcd(N, K) == 1:
            print(K)
            return
        K -= 1

if __name__ == "__main__":
    main()
```