1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma GCC optimize("O3,unroll-loops,inline")
#include <iterator>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int mxN = 1e7 + 10;
bool isprime[mxN];
// vi primes;
basic_string<int> pdivs[mxN];

// vector<int> pdivs(int n){
//     vi ans;
//     for(auto d : primes) {
//         if (d*d > n) break;
//         if (n % d == 0){
//             ans.push_back(d);
//             while(n%d==0) {
//                 n /= d;
//             }
//         }
//     }
//     if (n > 1) ans.push_back(n);
//     return ans;
// }

mt19937 rng(232423);
int rnd(int l, int r){
    return uniform_int_distribution(l,r)(rng);
}

int BLOCKS[3][1000];
int num;

void recalc(unordered_set<int>& sa) {
    num = 0;
    if (sz(sa)==0) return;
    vi a(all(sa));
    const int PS = min(60, sz(a) + 6);
    rep(i,0,min(PS,sz(a))) swap(a[i], a[rnd(0,sz(a)-1)]);
    vector<pair<int,int>> prec(PS);
    rep(i,0,PS) {
        int at = a[i%sz(a)];
        int g = 0, off = at;
        const int LIM = min(6, sz(a)/3+3);
        rep(j,0,LIM) {
            int ng = __gcd(g, abs(at - a[rnd(0,sz(a)-1)]));
            if (ng > 1){
                g = ng;
                off %= ng;
            }
        }
        prec[i] = {g,off};
    }
    sort(all(prec));
    prec.erase(unique(all(prec)),end(prec));
    set<pair<int,int>> offs;
    for(auto& [m,o] : prec) {
        for(auto p : pdivs[m]){
            offs.insert({p,o%p});
        }
    }
    num = 0;
    for(auto& [k,v] : offs) {
        BLOCKS[0][num] = k;
        BLOCKS[1][num] = v;
        BLOCKS[2][num] = 0;
        ++num;
    }

    rep(i,0,sz(a)){
        rep(j,0,num) {
            BLOCKS[2][j] += (a[i] % BLOCKS[0][j] == BLOCKS[1][j]);
        }
    }
}

int main(){
    cin.tie(NULL),ios::sync_with_stdio(false);
    
    rep(i,2,mxN) isprime[i] = 1;
    rep(p,2,mxN) if (isprime[p]) {
        for(int j = p; j < mxN; j += p) {
            isprime[j] = 0;
            pdivs[j].push_back(p);
        }
    }

    int q; cin >> q >> q;

    int T = 0;

    unordered_set<int> active;
    vector<array<int,3>> classes;

    rep(iter,0,q){
        int x; cin >> x;
        auto it = active.find(x);
        if (it != end(active)){
            active.erase(it);
            rep(j,0,num){
                BLOCKS[2][j] -= (x % BLOCKS[0][j] == BLOCKS[1][j]);
            }
        }else{
            active.insert(x);
            rep(j,0,num){
                BLOCKS[2][j] += (x % BLOCKS[0][j] == BLOCKS[1][j]);
            }
        }

        if (iter == T){
            recalc(active);
            T += max(1,sz(active)/2);
        }

        int ans = (sz(active) + 1) / 2;
        rep(j,0,num){
            ans = max(ans, BLOCKS[2][j]);
        }

        cout << ans << '\n';
    }
}