/*#include <iostream>
#include <vector>
#include "happy.h"

using namespace std;

void djik(int x, int k, int val, int& a2[][101], bool& f2[]) {
    f2[x] = 1;
    if(x != k)
        a2[x][k] = a2[k][x] = val;
    int i;
    for(i = 0; i <= nod[x].size(); i++) {
        if(f2[nod[x][i].first] == 0)
            djik(nod[x][i].first, k, val ^ nod[x][i].second, a2, f2);
    }
}

vector<long long int> happy(int n, int q, vector<int> u, vector<int> v, vector<int> h, vector<int> t, vector<int> l, vector<int> r) {
    if(n <= 100) {
        int a[101][101], p[101], i, j, o;
        long long sol;
        vector<long long int> solutie;
        pair<int, int> per;
        vector<pair<int, int> > nod[101];
        for(i = 0; i < n - 1; i++) {
            per.first = v[i];
            per.second = h[i];
            nod[u[i]].push_back(per);
            per.first = u[i];
            nod[v[i]].push_back(per);
        }
        for(i = 1; i <= n; i++) {
            bool f[101] = {0};
            djik(i, i, 0, a, f);
        }
        for(i = 0; i < q; i++) {
            sol = 0;
            for(j = l[i]; j <= r[i]; j++) {
                p[j] = 2 - t[i];
            }
            for(j = 0; j < n; j++) {
                for(o = j + 1; o < n; o++) {
                    if(p[j] == 1 && p[o] == 1)
                        sol += a[j][o];
                }
            }
            solutie.push_back(sol);
        }
        return solutie;
    }
}*/

//bool v[1000005][36];
//int f[36], poz[1000005];

#include <iostream>
#include <map>
#include "partition.h"

using namespace std;

vector<int> solve(vector<int> v) {
    int sol[2000001], k1, k2, n, i;
    vector<int> solutie;
    map<int, bool> f;
    n = v.size();
    for(i = 0; i < n; i++) {
        f[v[i]] = 1 - f[v[i]];
        if(f[v[i]] == 1) {
            k1++;
            sol[k1] = v[i];
        }
        else {
            k2++;
            sol[n / 2 + k2] = v[i];
        }
    }
    for(i = 1; i <= n; i++)
        solutie.push_back(sol[i]);
    return solutie;
}

/*int main()
{
    int n, k, i, x, p, j, cnt, cnt1, cnt2, h, h2;
    long long sol = 0;
    cin >> n >> k;
    for(i = 1; i <= n; i++) {
        cin >> x;
        for(p = 1; x > 0; p++, x /= 2) {
            v[i][p] = x % 2;
            f[p] += x % 2;
        }
    }
    for(p = 34; p > 0 && f[p] < k; p--);
    x = p - 1;
    if(p > 0)
        sol += (1 << x);
    for(i = 1, h = 0; i <= n; i++)
        if(v[i][p] == 1) {
            h++;
            poz[h] = i;
        }
    for(j = p - 1; j > 0; j--) {
        if(f[j] < k)
            continue;
        cnt = cnt1 = cnt2 = 0;
        h2 = 1;
        for(i = 1; i <= n; i++) {
            if(i == poz[h2]) {
                cnt1++;
                h2++;
            }
            if(v[i][j] == 1)
                cnt2++;
            if(cnt1 > 0 && cnt2 > 0) {
                cnt1 = 0;
                cnt2 = 0;
                cnt++;
            }
        }
        if(cnt >= k) {
            x = j - 1;
            sol += (1 << x);
            cnt = cnt1 = cnt2 = 0;
            h2 = 1;
            for(i = 1; i <= n; i++) {
                if(i == poz[h2]) {
                    cnt1++;
                    h2++;
                }
                if(v[i][j] == 1)
                    cnt2++;
                if(cnt1 > 0 && cnt2 > 0) {
                    cnt1 = 0;
                    cnt2 = 0;
                    cnt++;
                    poz[cnt] = i;
                }
            }
        }
    }
    cout << sol;
    return 0;
}*/
