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
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define RFOR(i,p,n) for(int i=(p);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ssize(x) int((x).size())
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define C const
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pn putchar_unlocked('\n')
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef V<int> vi;
typedef V<ll> vll;
typedef const int ci;
typedef const ll cll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
void chmin(auto &a, auto b){a=min(a,b);}
void chmax(auto &a, auto b){a=max(a,b);}
ci inf = 2.1e9;
cll infll = 4.5e18;
int I(){
    int z;
    int c = gc();
    while(c < '0' || c > '9') c = gc();
    for(z = 0; c >= '0' && c <= '9'; c = gc()) z = 10*z+c-'0';
    return z;
}
void O(int a){
    static int tab[20];
    int it = 0;
    do{
        tab[it++] = int('0'+a%10);
    } while(a /= 10);
    while(it) pc(tab[--it]);
}

mt19937 mt(691312137);
int los(ci a, ci b){
    uniform_int_distribution<int> dist(a, b);
    return dist(mt);
}

void answer(){
    ci n = I();
    ci q = I();
    vi dzielpier(n+1, 0);
    FOR(i, 2, n) if(!dzielpier[i]) for(int j = i; j <= n; j += i) dzielpier[j] = i;

    vi kamien(n, 0);
    vi xd;
    V<pair<pii, int>> info;
    int budzik = 0;
    REP(_, q){
        ci poz = I()-1;
        if(kamien[poz] ^= 1) xd.eb(poz);
        ci delta = kamien[poz] ? 1 : -1;

        if(budzik == 0){
            sort(all(xd));
            xd.erase(unique(all(xd)), xd.end());
            erase_if(xd, [&](ci i){return !kamien[i];});

            V<pii> pary = {{2, 0}, {2, 1}};
            auto rozroz = [&](ci a, ci b){
                for(int x = abs(a-b); x > 1; x /= dzielpier[x]){
                    ci p = dzielpier[x];
                    pary.eb(p, a%p);
                }
            };
            if(ssize(xd) <= 150){
                for(int i = 0; i+2 < ssize(xd); i += 3){
                    rozroz(xd[i], xd[i+1]);
                    rozroz(xd[i], xd[i+2]);
                    rozroz(xd[i+1], xd[i+2]);
                }
                FOR(i, max(0, ssize(xd)-6), ssize(xd)-1){
                    FOR(j, i+1, ssize(xd)-1) rozroz(xd[i], xd[j]);
                }
            }
            else{
                REP(__, 150){
                    ci i = los(0, ssize(xd)-1);
                    ci j = los(0, ssize(xd)-1);
                    rozroz(xd[i], xd[j]);
                }
            }
            sort(all(pary));
            pary.erase(unique(all(pary)), pary.end());

            info.clear();
            for(auto [mod, resz] : pary){
                int ile = 0;
                for(ci i : xd) if(i%mod == resz) ++ile;
                if(ile*3 >= ssize(xd)) info.eb(pii{mod, resz}, ile);
            }

            budzik = ssize(xd)/3;
        }
        else{
            for(auto &[para, ile] : info) if(poz%para.fi == para.se) ile += delta;
            --budzik;
        }

        int wyn = 0;
        for(auto [para, ile] : info) chmax(wyn, ile);
        O(wyn), pn;
    }
}

int main(){
    int tt = 1;
    while(tt--) answer();
}