Problem: cf1404_d
Difficulty: medium
Categories: graph, math, game
Time limit: 4000 ms, memory limit: 256 MB

This is an interactive problem.

Consider a fixed positive integer $n$. Two players, First and Second play a game as follows:

1. First considers the $2n$ numbers $1, 2, \dots, 2n$, and partitions them as he wants into $n$ disjoint pairs.
2. Then, Second chooses exactly one element from each of the pairs that First created (he chooses elements he wants).

To determine the winner of the game, we compute the sum of the numbers chosen by Second. If the sum of all these numbers is a multiple of $2n$, then Second wins. Otherwise, First wins.

You are given the integer $n$. Your task is to decide which player you wish to play as and win the game.

Interaction

The interaction begins by reading the integer $n$ ($1 \le n \le 5 \cdot 10^5$).

After reading, print a single line containing either First or Second, denoting who you want to play as. The interaction then varies depending on who you chose to play as.

If you chose to play as First, print a single line containing $2n$ integers $p_1, p_2, \dots, p_{2n}$, denoting that the number $i$ belongs to the $p_i$-th pair for $1\le i \le 2n$. Thus, $1 \le p_i \le n$, and every number between $1$ and $n$ inclusive should appear exactly twice.

If you chose to play as Second, the interactor will print $2n$ integers $p_1, p_2, \dots, p_{2n}$, denoting that the number $i$ belongs to the $p_i$-th pair. As a response, print $n$ integers $a_1, a_2, \dots, a_n$ in a single line. These should contain exactly one number from each pair.

Regardless of who you chose to play as the interactor will finish by printing a single integer: $0$ if your answer for the test case is correct (that is, you are playing as First and it cannot choose adequate numbers from your pairs, or you are playing as Second and your chosen numbers add up to a multiple of $2n$), or $-1$ if it is incorrect. In particular, the interactor will not print the chosen numbers if you choose to play First and lose. In either case, your program should terminate immediately after reading this number.

If at any point you make an invalid interaction, the interactor will print $-1$ and finish the interaction. You will receive a Wrong Answer verdict. Make sure to terminate immediately to avoid getting other verdicts.

After printing something do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.

Examples

Input

```
2

1 1 2 2

0
```

Output

```
Second

1 3
```

Input

```
2

0
```

Output

```
First
2 1 2 1
```

Note

In the first sample, $n = 2$, and you decide to play as Second. The judge chooses the pairs $(1, 2)$ and $(3, 4)$, and you reply with the numbers $1$ and $3$. This is a valid choice since it contains exactly one number from each pair, and the sum $1 + 3 = 4$ is divisible by $4$.

In the second sample, $n = 2$ again, and you play as First. You choose the pairs $(2, 4)$ and $(1, 3)$. The judge fails to choose a number from each pair such that their sum is divisible by $4$, so the answer is correct.

Note that the sample tests are just for illustration of the interaction protocol, and don't necessarily correspond to the behavior of the real interactor.

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
#include <csignal>
using namespace std;

static long long queries = 0;
static long long query_limit = 1;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {
        
    }
}

[[noreturn]] static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static string lower_ascii(string s) {
    for (char& c : s) c = (char)tolower((unsigned char)c);
    return s;
}

static void send_result(int v) {
    cout << v << "\n";
    cout.flush();
}

[[noreturn]] static void accept(const string& msg) {
    send_result(0);
    finish(_ok, msg);
}

[[noreturn]] static void reject(const string& msg) {
    send_result(-1);
    finish(_wa, msg);
}

static vector<int> read_player_pairing_from_ouf(int n) {
    vector<int> p(2 * n + 1, 0);
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= 2 * n; i++) {
        long long v;
        if (!(cin >> v)) reject("Unexpected EOF while reading pairing");
        if (v < 1 || v > n) reject("Invalid pairing label");
        p[i] = (int)v;
        cnt[p[i]]++;
    }
    for (int k = 1; k <= n; k++) {
        if (cnt[k] != 2) reject("Each pair label must appear exactly twice");
    }
    return p;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);
    signal(SIGPIPE, SIG_IGN);

    int n = inf.readInt(1, 500000, "n");
    vector<int> label_of_number(2 * n + 1, 0);
    vector<int> pair_cnt(n + 1, 0);
    for (int i = 1; i <= 2 * n; i++) {
        int lab = inf.readInt(1, n, "p_i");
        label_of_number[i] = lab;
        pair_cnt[lab]++;
    }
    for (int k = 1; k <= n; k++) {
        if (pair_cnt[k] != 2) finish(_fail, "Corrupted case: pairing label counts invalid");
    }

    cout << n << "\n";
    cout.flush();

    string role;
    if (!(cin >> role)) reject("Unexpected EOF while reading role");
    role = lower_ascii(role);

    if (role == "first") {
        vector<int> p = read_player_pairing_from_ouf(n);
        queries = 1;

        if (n % 2 != 0) reject("Choosing First is impossible for odd n");
        for (int i = 1; i <= n; i++) {
            if (p[i] != p[i + n]) reject("Expected pairing (i, i+n) for all i");
        }
        accept("OK");
    }

    if (role == "second") {
        
        for (int i = 1; i <= 2 * n; i++) {
            if (i > 1) cout << ' ';
            cout << label_of_number[i];
        }
        cout << "\n";
        cout.flush();

        vector<char> used_number(2 * n + 1, 0);
        vector<char> used_label(n + 1, 0);
        long long sum = 0;
        for (int i = 0; i < n; i++) {
            long long x;
            if (!(cin >> x)) reject("Unexpected EOF while reading chosen numbers");
            if (x < 1 || x > 2LL * n) reject("Chosen number out of range");
            if (used_number[(int)x]) reject("Duplicate chosen number");
            int lab = label_of_number[(int)x];
            if (lab < 1 || lab > n) finish(_fail, "Internal label map corrupted");
            if (used_label[lab]) reject("Two numbers chosen from the same pair");
            used_number[(int)x] = 1;
            used_label[lab] = 1;
            sum += x;
        }
        for (int k = 1; k <= n; k++) {
            if (!used_label[k]) reject("Must choose exactly one number from each pair");
        }
        queries = 1;

        if (sum % (2LL * n) != 0) reject("Sum is not divisible by 2n");
        accept("OK");
    }

    reject("Role must be First or Second");
}



Adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
#include <csignal>
using namespace std;

static long long queries = 0;
static long long query_limit = 1;

static void log_metrics() {
    try {
        tout << "queries=" << queries << "\n";
        tout << "query_limit=" << query_limit << "\n";
        tout.flush();
    } catch (...) {
        
    }
}

[[noreturn]] static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static string lower_ascii(string s) {
    for (char& c : s) c = (char)tolower((unsigned char)c);
    return s;
}

static void send_result(int v) {
    cout << v << "\n";
    cout.flush();
}

[[noreturn]] static void accept(const string& msg) {
    send_result(0);
    finish(_ok, msg);
}

[[noreturn]] static void reject(const string& msg) {
    send_result(-1);
    finish(_wa, msg);
}

static vector<int> read_player_pairing_from_ouf(int n) {
    vector<int> p(2 * n + 1, 0);
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= 2 * n; i++) {
        long long v;
        if (!(cin >> v)) reject("Unexpected EOF while reading pairing");
        if (v < 1 || v > n) reject("Invalid pairing label");
        p[i] = (int)v;
        cnt[p[i]]++;
    }
    for (int k = 1; k <= n; k++) {
        if (cnt[k] != 2) reject("Each pair label must appear exactly twice");
    }
    return p;
}

static vector<int> make_pairing_labels(int n, int family, int a, int b) {
    vector<int> p(2 * n + 1, 0);
    if (family == 0) {
        
        for (int k = 1; k <= n; k++) {
            p[2 * k - 1] = k;
            p[2 * k] = k;
        }
        return p;
    }
    if (family == 1) {
        
        for (int k = 1; k <= n; k++) {
            int x = k;
            int y = 2 * n + 1 - k;
            p[x] = k;
            p[y] = k;
        }
        return p;
    }
    if (family == 2) {
        
        int s = (n == 0 ? 0 : (a % n));
        if (s < 0) s += n;
        if (s == 0) s = 1;
        bool rev = (b & 1) != 0;
        for (int i = 1; i <= n; i++) {
            int j = rev ? (i - s) : (i + s);
            j %= n;
            if (j < 0) j += n;
            if (j == 0) j = n;
            
            p[i] = i;
            p[n + j] = i;
        }
        return p;
    }
    
    for (int k = 1; k <= n; k++) {
        p[k] = k;
        p[k + n] = k;
    }
    return p;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);
    signal(SIGPIPE, SIG_IGN);

    int n = inf.readInt(1, 500000, "n");
    int family = inf.readInt(0, 1000000000, "family");
    int a = inf.readInt(-1000000000, 1000000000, "a");
    int b = inf.readInt(-1000000000, 1000000000, "b");

    vector<int> label_of_number = make_pairing_labels(n, family, a, b);
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= 2 * n; i++) {
        int lab = label_of_number[i];
        if (lab < 1 || lab > n) finish(_fail, "Generated pairing label out of range");
        cnt[lab]++;
    }
    for (int k = 1; k <= n; k++) {
        if (cnt[k] != 2) finish(_fail, "Generated pairing labels are not a valid pairing");
    }

    cout << n << "\n";
    cout.flush();

    string role;
    if (!(cin >> role)) reject("Unexpected EOF while reading role");
    role = lower_ascii(role);

    if (role == "first") {
        vector<int> p = read_player_pairing_from_ouf(n);
        queries = 1;
        if (n % 2 != 0) reject("Choosing First is impossible for odd n");
        for (int i = 1; i <= n; i++) {
            if (p[i] != p[i + n]) reject("Expected pairing (i, i+n) for all i");
        }
        accept("OK");
    }

    if (role == "second") {
        for (int i = 1; i <= 2 * n; i++) {
            if (i > 1) cout << ' ';
            cout << label_of_number[i];
        }
        cout << "\n";
        cout.flush();

        vector<char> used_number(2 * n + 1, 0);
        vector<char> used_label(n + 1, 0);
        long long sum = 0;
        for (int i = 0; i < n; i++) {
            long long x;
            if (!(cin >> x)) reject("Unexpected EOF while reading chosen numbers");
            if (x < 1 || x > 2LL * n) reject("Chosen number out of range");
            if (used_number[(int)x]) reject("Duplicate chosen number");
            int lab = label_of_number[(int)x];
            if (used_label[lab]) reject("Two numbers chosen from the same pair");
            used_number[(int)x] = 1;
            used_label[lab] = 1;
            sum += x;
        }
        for (int k = 1; k <= n; k++) {
            if (!used_label[k]) reject("Must choose exactly one number from each pair");
        }
        queries = 1;

        if (sum % (2LL * n) != 0) reject("Sum is not divisible by 2n");
        accept("OK");
    }

    reject("Role must be First or Second");
}



Test generator (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static vector<int> makePermutationPairs(int n, int type) {
    
    vector<int> p(2 * n + 1, 0);

    if (type == 0) {
        
        for (int k = 1; k <= n; k++) {
            p[2 * k - 1] = k;
            p[2 * k] = k;
        }
    } else if (type == 1) {
        
        for (int k = 1; k <= n; k++) {
            int a = k;
            int b = 2 * n + 1 - k;
            p[a] = k;
            p[b] = k;
        }
    } else if (type == 2) {
        
        for (int k = 1; k <= n; k++) {
            p[k] = k;
            p[k + n] = k;
        }
    } else if (type == 3) {
        
        
        vector<int> order;
        order.reserve(2 * n);
        int l = 1, r = 2 * n;
        while ((int)order.size() < 2 * n) {
            order.push_back(l++);
            if ((int)order.size() >= 2 * n) break;
            order.push_back(l + n - 1 <= 2 * n ? (l + n - 1) : r--); 
            if ((int)order.size() >= 2 * n) break;
            order.push_back(r--);
            if ((int)order.size() >= 2 * n) break;
        }
        
        vector<int> used(2 * n + 1, 0);
        vector<int> perm;
        perm.reserve(2 * n);
        for (int x : order) if (x >= 1 && x <= 2 * n && !used[x]) { used[x] = 1; perm.push_back(x); }
        for (int x = 1; x <= 2 * n; x++) if (!used[x]) perm.push_back(x);
        for (int k = 1; k <= n; k++) {
            int a = perm[2 * k - 2];
            int b = perm[2 * k - 1];
            p[a] = k;
            p[b] = k;
        }
    } else {
        
        vector<int> perm(2 * n);
        iota(perm.begin(), perm.end(), 1);
        for (int i = 2 * n - 1; i > 0; --i) {
            int j = rnd.next(0, i);
            swap(perm[i], perm[j]);
        }
        for (int k = 1; k <= n; k++) {
            int a = perm[2 * k - 2];
            int b = perm[2 * k - 1];
            p[a] = k;
            p[b] = k;
        }
    }

    
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= 2 * n; i++) {
        if (p[i] < 1 || p[i] > n) p[i] = 1;
        cnt[p[i]]++;
    }
    
    
    vector<int> need, extraPos;
    for (int k = 1; k <= n; k++) {
        while (cnt[k] < 2) { need.push_back(k); cnt[k]++; }
    }
    for (int i = 1; i <= 2 * n; i++) {
        int k = p[i];
        if (cnt[k] > 2) {
            extraPos.push_back(i);
            cnt[k]--;
        }
    }
    int m = min((int)need.size(), (int)extraPos.size());
    for (int t = 0; t < m; t++) p[extraPos[t]] = need[t];

    return p;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int seed = 1;
    if (argc >= 2) {
        
        seed = atoi(argv[1]);
        if (seed <= 0) seed = 1;
    }

    
    int maxN = opt<int>("maxN", 500000);

    if (mode == "non") {
        int n;
        int pat = -1;

        if (seed == 1) { n = 1; pat = 0; }
        else if (seed == 2) { n = 2; pat = 1; }
        else if (seed == 3) { n = max(3, min(7, maxN)); pat = 2; }
        else {
            
            
            int choose = rnd.next(0, 99);
            if (choose < 55) n = maxN;
            else if (choose < 80) n = rnd.next(max(1, maxN - 200000), maxN);
            else n = rnd.next(1, maxN);

            int t = rnd.next(0, 99);
            if (t < 30) pat = 1;       
            else if (t < 55) pat = 2;  
            else if (t < 75) pat = 0;  
            else if (t < 90) pat = 3;  
            else pat = 4;              
        }

        auto p = makePermutationPairs(n, pat);

        
        cout << n << "\n";
        for (int i = 1; i <= 2 * n; i++) {
            if (i > 1) cout << ' ';
            cout << p[i];
        }
        cout << "\n";
        return 0;
    }

    if (mode == "adp") {
        
        
        
        
        
        
        
        
        int n;
        int family;
        int a = 0, b = 0;

        if (seed == 1) { n = 1; family = 0; a = 0; b = 0; }
        else if (seed == 2) { n = 2; family = 1; a = 1; b = 0; }
        else if (seed == 3) { n = max(3, min(9, maxN)); family = 2; a = 1; b = 1; }
        else {
            int choose = rnd.next(0, 99);
            if (choose < 60) n = maxN;
            else n = rnd.next(max(1, maxN - 150000), maxN);

            
            
            
            
            
            int t = rnd.next(0, 99);
            if (t < 10) family = 0;
            else if (t < 25) family = 1;
            else if (t < 75) family = 2;
            else family = 3;

            if (family == 2) {
                
                int s = rnd.next(0, n - 1) * 2 + 1; 
                a = s;
                b = rnd.next(0, 1); 
            } else if (family == 3) {
                
                a = 1; 
                b = 2; 
            } else {
                a = 0; b = 0;
            }
        }

        cout << n << "\n";
        cout << family << " " << a << " " << b << "\n";
        return 0;
    }

    
    int n = opt<int>("n", min(500000, 500000));
    auto p = makePermutationPairs(n, 2);
    cout << n << "\n";
    for (int i = 1; i <= 2 * n; i++) {
        if (i > 1) cout << ' ';
        cout << p[i];
    }
    cout << "\n";
    return 0;
}