Submission details
Task:Sort
Sender:Luisito0101
Submission time:2026-04-17 12:25:13 +0300
Language:C++ (C++17)
Status:READY
Result:11
Feedback
subtaskverdictscore
#1ACCEPTED6
#2ACCEPTED5
#30
#40
#50
#60
#70
Test results
testverdicttimesubtask
#1ACCEPTED0.00 s2, 6, 7details
#2ACCEPTED0.00 s1, 2, 3, 6, 7details
#3ACCEPTED0.00 s2, 6, 7details
#4ACCEPTED0.00 s1, 2, 3, 6, 7details
#5ACCEPTED0.00 s1, 2, 3, 6, 7details
#6ACCEPTED0.00 s1, 2, 3, 6, 7details
#7ACCEPTED0.00 s1, 2, 3, 6, 7details
#8ACCEPTED0.00 s1, 2, 3, 6, 7details
#9ACCEPTED0.00 s1, 2, 3, 6, 7details
#10ACCEPTED0.00 s1, 2, 3, 6, 7details
#11ACCEPTED0.00 s2, 6, 7details
#12ACCEPTED0.00 s2, 6, 7details
#13ACCEPTED0.00 s2, 6, 7details
#14ACCEPTED0.00 s2, 6, 7details
#15ACCEPTED0.01 s2, 6, 7details
#16--3, 7details
#17--3, 7details
#18--3, 7details
#19--3, 7details
#20--3, 7details
#21--3, 7details
#22--3, 7details
#23--3, 7details
#24--4, 7details
#25--4, 7details
#26--4, 7details
#27--4, 7details
#28--4, 7details
#29--4, 7details
#30--5, 6, 7details
#31--5, 6, 7details
#32--5, 6, 7details
#33--5, 6, 7details
#34ACCEPTED0.07 s5, 6, 7details
#35--5, 6, 7details
#36--6, 7details
#37--6, 7details
#38--6, 7details
#39--6, 7details
#40ACCEPTED0.07 s6, 7details
#41--6, 7details
#42--7details
#43--7details
#44--7details
#45--7details
#46--7details
#47--7details
#48--7details
#49--7details
#50--7details
#51--7details
#52ACCEPTED0.00 s1, 2, 3, 5, 6, 7details
#53ACCEPTED0.00 s1, 2, 3, 4, 5, 6, 7details
#54ACCEPTED0.00 s2, 5, 6, 7details
#55ACCEPTED0.00 s1, 2, 3, 4, 6, 7details
#56ACCEPTED0.00 s1, 2, 3, 6, 7details
#57ACCEPTED0.00 s6, 7details
#58ACCEPTED1.50 s3, 4, 7details
#59ACCEPTED1.56 s3, 7details
#60ACCEPTED0.00 s2, 6, 7details
#61ACCEPTED0.00 s2, 6, 7details
#62ACCEPTED0.00 s2, 6, 7details
#63ACCEPTED0.00 s2, 6, 7details
#64ACCEPTED0.00 s2, 6, 7details

Code

//I love my template

#include <bits/extc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define int long long

//Constant Values
const int mod=998244353;
const int inf=INT64_MAX;
const int oo=1e18;
const double pi=acos(-1);


//Utilities
#define opt ios_base::sync_with_stdio(0),cin.tie(0);cout.tie(0)
#define tests int testcases;cin>>testcases;while(testcases--)
#define vec vector
#define vii vec<int>
#define pii pair<int,int>
#define fi first
#define se second
#define deb cerr<<"."<<endl
#define inv(x) qp(x,mod-2)
#define all(x) x.begin(),x.end()
#define srt(x) sort(all(x))
#define rev(x) reverse(all(x))
#define left u<<1,l,(l+r)>>1
#define right (u<<1)|1,((l+r)>>1)+1,r

//ERRORS
vii testvec;
#define WA return 0;
#define RTE testvec[2]=1;
#define TLE while(1){}
#define OLE while(1){cout<<".\n";}

int get(){int x;cin>>x;return x;}

typedef __gnu_pbds::tree<pii,__gnu_pbds::null_type,less<pii>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>ordered_set;

//Math
vec<int>fact;
vec<int>inverse;
vec<int>catalan;
int qp(int a,int b){
    if(!b)return 1;
    return (qp((a*a)%mod,b>>1)*(b&1?a:1))%mod;
}
int qpmod(int a,int b,int md){
    if(!b)return 1;
    return (qpmod((a*a)%md,b>>1,md)*(b&1?a:1))%md;
}
__int128 qp128(__int128 a,__int128 b){
    if(!b)return 1;
    return (qp128((a*a)%mod,b>>1)*(b&1?a:1))%mod;
}
int phi(int n){
    int ans=n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
            }
            ans-=ans/i;
        }
    }
    if(n>1)ans-=ans/n;
    return ans;
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return (a/gcd(a,b))*b;
}
int gauss(int n){
    return (n*(n+1))/2;
}
int dig(int n){
    if(n==0)return 1;
    int ans=1;
    while(n/=10)ans++;
    return ans;
}
void DO_MATH(int MAXN){
    fact.push_back(1);
    inverse.push_back(1);
    catalan.push_back(1);
    for(int i=1;i<=MAXN;i++){
        fact.push_back((fact[i-1]*i)%mod);
        inverse.push_back(qp(fact[i],mod-2));
        catalan.push_back((((catalan[i-1]*(4*i-2))%mod)*qp(i+1,mod-2))%mod);
    }
}
int C(const int& n,const int& k){
    return (((fact[n]*inverse[n-k])%mod)*inverse[k])%mod;
}
int Euler(const int& n,const int& k){
    int ans=0;
    for(int i=0;i<=k;i++){
        int sum=(C(n+1,i)*qp(k+1-i,n))%mod;
        if(i%2==0)ans+=sum;
        else ans-=sum;
    }
    return (ans%mod+mod)%mod;
}
map<int,int>fibonac;
int fib(int n){
    if(n==0)return 0;
    if(n==1||n==2)return 1;
    if(fibonac[n]!=0)return fibonac[n];
    int a=n/2,b=n/2+n%2;
    return fibonac[n]=(((fib(b-1)*fib(a))%mod)+((fib(a+1)*fib(b))%mod))%mod;
}

//Binary Search algorithms
int lbound(const vector<int>& v,const int& val){
    int l=0,r=v.size()-1,ans=0,mid;
    while(l<=r){
        mid=(l+r)/2;
        if(v[mid]<=val){
            ans=v[mid];
            l=mid+1;
        }
        else r=mid-1;
    }
    return ans;
}

//Number Handle
string tostr(int n){
    string ans;
    do{
        ans+=n%10+48;
    }while(n/=10);
    rev(ans);
    return ans;
}
void cout_128(__int128 n){
    if(n<0){
        n=-n;cout<<'-';
    }
    string s;
    do{
        s+=(char)((n%10)+'0');
    }while(n/=10);
    rev(s);
    cout<<s;
}

//SegTree Configurations
constexpr int crash_val=0;
int merge(const int& l,const int& r){
    return l+r;
}
//SegTree
struct SegTree{
    vii ar;
    vii tree;
    SegTree(){}
    //Constructor
    SegTree(const int& n){
        ar.assign(n+1,crash_val);
        tree.assign((n<<2)|1,crash_val);
    }
    //Inicialization
    void build(const int& u,const int& l,const int& r){
        if(l==r){
            tree[u]=ar[l];
            return;
        }
        const int mid=(l+r)>>1;
        build(u<<1,l,mid);
        build((u<<1)|1,mid+1,r);
        tree[u]=merge(tree[u<<1],tree[(u<<1)|1]);
    }
    //Query
    int query(const int& u,const int& l,const int& r,const int& ql,const int& qr){
        if(l>qr||r<ql)return crash_val;
        if(l>=ql&&r<=qr)return tree[u];
        const int mid=(l+r)>>1;
        return merge(query(u<<1,l,mid,ql,qr),query((u<<1)|1,mid+1,r,ql,qr));
    }
    //Update
    void update(const int& u,const int& l,const int& r,const int& pos,const int& k){
        if(l>pos||r<pos)return;
        if(l==r){
            ar[l]=k;
            tree[u]=ar[l];
            return;
        }
        const int mid=(l+r)>>1;
        update(u<<1,l,mid,pos,k);
        update((u<<1)|1,mid+1,r,pos,k);
        tree[u]=merge(tree[u<<1],tree[(u<<1)|1]);
    }
};
//Lazy Update
constexpr int def_lazy_val=0;
struct SegTreeLazy{
    vii ar;
    vii tree;
    vii lazy;
    SegTreeLazy(){}
    //Constructor
    SegTreeLazy(const int& n){
        ar.assign(n+1,crash_val);
        tree.assign((n<<2)|1,crash_val);
        lazy.assign((n<<2)|1,def_lazy_val);
    }
    //Inicialization
    void build(const int& u,const int& l,const int& r){
        if(l==r){
            tree[u]=ar[l];
            lazy[u]=def_lazy_val;
            return;
        }
        const int mid=(l+r)>>1;
        build(u<<1,l,mid);
        build((u<<1)|1,mid+1,r);
        tree[u]=merge(tree[u<<1],tree[(u<<1)|1]);
        lazy[u]=def_lazy_val;
    }
    //Push Lazy Val
    void push(const int& u,const int& l,const int& r){
        if(lazy[u]==def_lazy_val)return;
        tree[u]+=lazy[u]*(r-l+1);
        if(l!=r){
            lazy[u<<1]+=lazy[u];
            lazy[(u<<1)|1]+=lazy[u];
        }
        lazy[u]=def_lazy_val;
    }
    //Range Query
    int query(const int& u,const int& l,const int& r,const int& ql,const int& qr){
        push(u,l,r);
        if(l>=ql&&r<=qr)return tree[u];
        if(l>qr||r<ql)return crash_val;
        const int mid=(l+r)>>1;
        return merge(query(u<<1,l,mid,ql,qr),query((u<<1)|1,mid+1,r,ql,qr));
    }
    //Range Update
    void update(const int& u,const int& l,const int& r,const int& a,const int& b,const int& k){
        push(u,l,r);
        if(l>b||r<a)return;
        if(l>=a&&r<=b){
            lazy[u]+=k;
            push(u,l,r);
            return;
        }
        const int mid=(l+r)>>1;
        update(u<<1,l,mid,a,b,k);
        update((u<<1)|1,mid+1,r,a,b,k);
        tree[u]=merge(tree[u<<1],tree[(u<<1)|1]);
    }
};

//Disjoint Set Union
struct DSU{
    vii parent,siz;
    int comp;
    //Constructor
    DSU(const int& n):comp(n){
        parent.resize(n+1);
        iota(all(parent),0);
        siz.assign(n+1,1);
    }
    //Find
    int find(const int& u){
        if(parent[u]==u)return u;
        return parent[u]=find(parent[u]);
    }
    //Unite
    void unite(const int& u,const int& v){
        int pu=find(u);
        int pv=find(v);
        if(pu==pv)return;
        if(siz[pu]>siz[pv])swap(pu,pv);
        parent[pu]=pv;
        siz[pv]+=siz[pu];
        comp--;
    }
    //Same Component Check
    bool same(const int& u,const int& v){
        return find(u)==find(v);
    }
    //Size Of Component
    int size(const int& u){
        return siz[find(u)];
    }
};

//DSU with rollback
struct DSUrollback{
    vii parent,siz;
    stack<tuple<int,int,int> >hist;
    int comp;
    //Constructor
    DSUrollback():comp(0){}
    DSUrollback(const int& n):comp(n){
        parent.resize(n+1);
        iota(all(parent),0);
        siz.assign(n+1,1);
    }
    //Find
    int find(int n){
        while(n!=parent[n])n=parent[n];
        return n;
    }
    //Unite
    bool unite(const int& u,const int& v){
        int pu=find(u);
        int pv=find(v);
        if(pu==pv)return 0;
        if(siz[pu]<siz[pv])swap(pu,pv);
        hist.push({pu,pv,siz[pu]});
        parent[pv]=pu;
        siz[pu]+=siz[pv];
        comp--;
        return 1;
    }
    //Undo last union
    void undo(){
        auto[pu,pv,szpu]=hist.top();
        hist.pop();
        parent[pv]=pv;
        siz[pu]=szpu;
        comp++;
    }
    //Same Component Check
    bool same(const int& u,const int& v){
        return find(u)==find(v);
    }
    //Size Of Component
    int size(const int&u){
        return siz[find(u)];
    }
};

//Hashing
//Multiple Hash Value Storing
struct HashVal{
    int h0,h1,h2,h3,h4,h5;
    bool operator == (const HashVal& val){
        return h0==val.h0&&h1==val.h1&&h2==val.h2&&h3==val.h3&&h4==val.h4&&h5==val.h5;
    }
};
//VERY strong Hashing
struct Hashing{
    vii hash[6];
    vii pot[6];
    Hashing(){}
    //Constructor
    Hashing(const string& s){
        for(int i=0;i<6;i++){
            hash[i].assign(s.size()+1,0);
            pot[i].assign(s.size()+1,1);
        }
        for(int i=1;i<=(int)s.size();i++){
            hash[0][i]=(hash[0][i-1]*31+s[i-1])%1000000007;
            hash[1][i]=(hash[1][i-1]*37+s[i-1])%1000000007;
            hash[2][i]=(hash[2][i-1]*41+s[i-1])%1000000007;
            hash[3][i]=(hash[3][i-1]*31+s[i-1])%1000000009;
            hash[4][i]=(hash[4][i-1]*37+s[i-1])%1000000009;
            hash[5][i]=(hash[5][i-1]*41+s[i-1])%1000000009;
            pot[0][i]=(pot[0][i-1]*31)%1000000007;
            pot[1][i]=(pot[1][i-1]*37)%1000000007;
            pot[2][i]=(pot[2][i-1]*41)%1000000007;
            pot[3][i]=(pot[3][i-1]*31)%1000000009;
            pot[4][i]=(pot[4][i-1]*37)%1000000009;
            pot[5][i]=(pot[5][i-1]*41)%1000000009;
        }
    }
    //Get Val From Range
    HashVal get(const int& l,const int& r){
        HashVal ans;
        ans.h0=((hash[0][r]-((hash[0][l-1]*pot[0][r-l+1])%1000000007))+1000000007)%1000000007;
        ans.h1=((hash[1][r]-((hash[1][l-1]*pot[1][r-l+1])%1000000007))+1000000007)%1000000007;
        ans.h2=((hash[2][r]-((hash[2][l-1]*pot[2][r-l+1])%1000000007))+1000000007)%1000000007;
        ans.h3=((hash[3][r]-((hash[3][l-1]*pot[3][r-l+1])%1000000009))+1000000009)%1000000009;
        ans.h4=((hash[4][r]-((hash[4][l-1]*pot[4][r-l+1])%1000000009))+1000000009)%1000000009;
        ans.h5=((hash[5][r]-((hash[5][l-1]*pot[5][r-l+1])%1000000009))+1000000009)%1000000009;
        return ans;
    }
};

//Checking Palindromes easily
struct PalHash{
    const int n;
    Hashing normal,revers;
    PalHash(string s):n((int)s.size()){
        normal=Hashing(s);
        rev(s);
        revers=Hashing(s);
    }
    HashVal get(const int& l,const int& r){
        return normal.get(l,r);
    }
    bool pal(const int& l,const int& r){
        return normal.get(l,r)==revers.get(n-r+1,n-l+1);
    }
};

//Hashing with updates (WHY)
const int md1=1e9+7,md2=1e9+9,md3=1e9+21,md4=1e9+33;
vii p1,p2,p3,p4,i1,i2,i3,i4;
void precomp(const int& MXN){
    p1.push_back(1);i1.push_back(1);
    p2.push_back(1);i2.push_back(1);
    p3.push_back(1);i3.push_back(1);
    p4.push_back(1);i4.push_back(1);
    for(int i=1;i<=MXN;i++){
        p1.push_back((p1[i-1]*131LL)%md1);
        p2.push_back((p2[i-1]*131LL)%md2);
        p3.push_back((p3[i-1]*131LL)%md3);
        p4.push_back((p4[i-1]*131LL)%md4);
        i1.push_back((qpmod(p1[i],md1-2,md1)));
        i2.push_back((qpmod(p2[i],md2-2,md2)));
        i3.push_back((qpmod(p3[i],md3-2,md3)));
        i4.push_back((qpmod(p4[i],md4-2,md4)));
    }
}

struct Node{
    int val1,val2,val3,val4;
    Node():val1(0),val2(0),val3(0),val4(0){}
    Node(const char& c,const int& pos){
        val1=(p1[pos]*(int)c)%md1;
        val2=(p2[pos]*(int)c)%md2;
        val3=(p3[pos]*(int)c)%md3;
        val4=(p4[pos]*(int)c)%md4;
    }
    Node(const Node& l,const Node& r){
        val1=(l.val1+r.val1)%md1;
        val2=(l.val2+r.val2)%md2;
        val3=(l.val3+r.val3)%md3;
        val4=(l.val4+r.val4)%md4;
    }
    bool operator == (const Node& x){
        return val1==x.val1&&val2==x.val2&&val3==x.val3&&val4==x.val4;
    }
};

struct HashUpdate{
    string str;
    vec<Node>arr,tree;
    HashUpdate(){}
    HashUpdate(const string s){
        str=s;
        arr.resize(str.size()+1);
        tree.resize((str.size()<<2)|1);
        for(int i=1;i<=(int)str.size();i++){
            arr[i]=Node(str[i-1],i);
        }
    }
    void build(const int& u,const int& l,const int& r){
        if(l==r){
            tree[u]=arr[l];
            return;
        }
        build(left);
        build(right);
        tree[u]=Node(tree[u<<1],tree[(u<<1)|1]);
    }
    void update(const int& u,const int& l,const int& r,const int& pos,const char& val){
        if(l>pos||r<pos)return;
        if(l==r){
            arr[l]=Node(val,l);
            tree[u]=arr[l];
            return;
        }
        update(left,pos,val);
        update(right,pos,val);
        tree[u]=Node(tree[u<<1],tree[(u<<1)|1]);
    }
    Node query(const int& u,const int& l,const int& r,const int& a,const int& b){
        if(l>b||r<a)return Node();
        if(l>=a&&r<=b)return tree[u];
        return Node(query(left,a,b),query(right,a,b));
    }
    Node get(const int& l,const int& r){
        Node n=query(1,1,str.size(),l,r);
        n.val1=(n.val1*i1[l-1])%md1;
        n.val2=(n.val2*i2[l-1])%md2;
        n.val3=(n.val3*i3[l-1])%md3;
        n.val4=(n.val4*i4[l-1])%md4;
        return n;
    }
};

struct PalHashUpdate{
    HashUpdate normal,revers;
    int MX;
    PalHashUpdate(string s){
        normal=HashUpdate(s);
        rev(s);
        revers=HashUpdate(s);
        MX=s.size();
        normal.build(1,1,MX);
        revers.build(1,1,MX);
    }
    void update(const int& pos,const char& val){
        normal.update(1,1,MX,pos,val);
        revers.update(1,1,MX,MX-pos+1,val);
    }
    bool pal(const int& l,const int& r){
        return normal.get(l,r)==revers.get(MX-r+1,MX-l+1);
    }
};

//Trie
struct Trie{
    struct Nod{
        int pref,word;
        unordered_map<char,int>m;
        Nod():pref(0),word(0){}
    };
    vec<Nod>v;
    Trie(){
        v.push_back(Nod());
    }
    void insert(string &s){
        int act=0;
        for(char c:s){
            if(v[act].m[c]==0){
                v[act].m[c]=v.size();
                v.push_back(Nod());
            }
            act=v[act].m[c];
            v[act].pref++;
        }
        v[act].word++;
    }
    void erase(string &s){
        int act=0;
        for(char c:s){
            act=v[act].m[c];
            v[act].pref--;
        }
        v[act].word--;
    }
    int pref(string &s){
        int act=0;
        for(char c:s){
            if(v[act].m[c]==0){
                return 0;
            }
            act=v[act].m[c];
        }
        return v[act].pref;
    }
    int word(string &s){
        int act=0;
        for(char c:s){
            if(v[act].m[c]==0){
                return 0;
            }
            act=v[act].m[c];
        }
        return v[act].word;
    }
};

int32_t main(){
    int n,q;
    cin>>n>>q;
    int a[n],s[n],aux1[n],aux2[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        s[i]=a[i];
        aux1[i]=a[i];
        aux2[i]=a[i];
    }
    sort(s,s+n);
    while(q--){
        int A,B;
        cin>>A>>B;
        int ans=0;
        bool b=0;
        while(ans<=30){
            bool a1=1,a2=1;
            for(int i=0;i<n;i++){
                if(aux1[i]!=s[i])a1=0;
                if(aux2[i]!=s[i])a2=0;
            }
            if(a1||a2){
                cout<<ans<<endl;
                b=1;
                break;
            }
            ans++;
            if(ans%2==0){
                sort(aux1,aux1+A);
                sort(aux2+(n-B),aux2+n);
            }
            else{
                sort(aux2,aux2+A);
                sort(aux1+(n-B),aux1+n);
            }
        }
        if(!b){
            cout<<-1<<endl;
        }
        for(int i=0;i<n;i++){
            aux1[i]=a[i];
            aux2[i]=a[i];
        }
    }
}

Test details

Test 1

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
6 3
3 1 4 1 5 9
4 1
3 3
2 5

correct output
1
-1
2

user output
1
-1
2

Test 2

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
2 1
548813503 548813503
1 1

correct output
0

user output
0

Test 3

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
1 1
417021999
1 1

correct output
0

user output
0

Test 4

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
20751947 20751947 20751947 494...

correct output
-1
-1
1
1
-1
...

user output
-1
-1
1
1
-1
...

Test 5

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
12780811 19475241 19475241 683...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 6

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
14574963 14574963 14574963 864...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 7

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
237541216 237541216 35036522 6...

correct output
-1
-1
-1
2
-1
...

user output
-1
-1
-1
2
-1
...

Test 8

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
319425549 513116712 539199939 ...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 9

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
54363219 54363219 110986323 11...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 10

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 5
55687086 550701455 326656159 5...

correct output
-1
-1
-1
-1
-1

user output
-1
-1
-1
-1
-1

Test 11

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
35889584 588130796 815837475 8...

correct output
-1
-1
1
1
1
...

user output
-1
-1
1
1
1
...

Test 12

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
679842175 48724877 720966351 6...

correct output
2
3
2
1
1
...

user output
2
3
2
1
1
...

Test 13

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
893310183 811950921 338863962 ...

correct output
2
1
1
2
5
...

user output
2
1
1
2
5
...

Test 14

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
221045363 282395847 441913686 ...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 15

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
509019662 983949268 960017302 ...

correct output
3
-1
3
3
3
...

user output
3
-1
3
3
3
...

Test 16

Subtask: 3, 7

Verdict:

input
200000 200000
2277053 2277053 2277053 227705...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 17

Subtask: 3, 7

Verdict:

input
200000 200000
6767 16596 16596 27202 37272 4...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 18

Subtask: 3, 7

Verdict:

input
200000 200000
5393 5910 9099 15755 15755 164...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 19

Subtask: 3, 7

Verdict:

input
200000 200000
3779 4629 8999 10468 22605 227...

correct output
-1
1
2
-1
-1
...

user output
(empty)

Test 20

Subtask: 3, 7

Verdict:

input
200000 200000
878 2791 10849 11861 13405 239...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 21

Subtask: 3, 7

Verdict:

input
200000 200000
430 1479 1992 2829 7152 14093 ...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 22

Subtask: 3, 7

Verdict:

input
199997 200000
2733 10526 13882 14035 14689 3...

correct output
-1
-1
-1
-1
-1
...

user output
(empty)

Test 23

Subtask: 3, 7

Verdict:

input
200000 200000
12345 13538 15407 18490 18984 ...

correct output
0
0
0
0
0
...

user output
(empty)

Test 24

Subtask: 4, 7

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
-1
1
-1
-1
-1
...

user output
(empty)

Test 25

Subtask: 4, 7

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1
-1
1
-1
1
...

user output
(empty)

Test 26

Subtask: 4, 7

Verdict:

input
200000 200000
2 2 1 1 2 1 2 1 2 2 2 1 1 1 2 ...

correct output
4
3
2
2
6
...

user output
(empty)

Test 27

Subtask: 4, 7

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
0
0
0
0
0
...

user output
(empty)

Test 28

Subtask: 4, 7

Verdict:

input
200000 200000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

correct output
8513
1099
35939
9299
19597
...

user output
(empty)

Test 29

Subtask: 4, 7

Verdict:

input
200000 200000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

correct output
178345
169257
62115
96143
64796
...

user output
(empty)

Test 30

Subtask: 5, 6, 7

Verdict:

input
5000 5000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1
1
-1
1
-1
...

user output
(empty)

Test 31

Subtask: 5, 6, 7

Verdict:

input
5000 5000
1 2 3 4 5 6 7 8 9 72 145 47 19...

correct output
-1
2
-1
2
-1
...

user output
(empty)

Test 32

Subtask: 5, 6, 7

Verdict:

input
4999 5000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
-1
2
-1
-1
-1
...

user output
(empty)

Test 33

Subtask: 5, 6, 7

Verdict:

input
5000 5000
4033 4368 3086 3208 4313 388 8...

correct output
3
3
3
3
11
...

user output
(empty)

Test 34

Subtask: 5, 6, 7

Verdict: ACCEPTED

input
5000 5000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 35

Subtask: 5, 6, 7

Verdict:

input
5000 5000
5000 4999 4998 4997 4996 4995 ...

correct output
2039
1910
-1
687
673
...

user output
(empty)

Test 36

Subtask: 6, 7

Verdict:

input
5000 5000
202010 457852 826471 926337 10...

correct output
-1
-1
2
-1
-1
...

user output
(empty)

Test 37

Subtask: 6, 7

Verdict:

input
5000 5000
190583 326486 431922 462939 72...

correct output
-1
-1
-1
-1
2
...

user output
(empty)

Test 38

Subtask: 6, 7

Verdict:

input
5000 5000
821998255 400550008 71790232 5...

correct output
5
3
3
2
5
...

user output
(empty)

Test 39

Subtask: 6, 7

Verdict:

input
5000 5000
266174928 446601941 191252234 ...

correct output
3
3
414
4
3
...

user output
(empty)

Test 40

Subtask: 6, 7

Verdict: ACCEPTED

input
5000 5000
11621 243915 243915 949123 137...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 41

Subtask: 6, 7

Verdict:

input
5000 5000
999767052 998555066 997822810 ...

correct output
919
459
505
833
809
...

user output
(empty)

Test 42

Subtask: 7

Verdict:

input
200000 200000
478025 478025 478025 478025 47...

correct output
-1
-1
2
2
2
...

user output
(empty)

Test 43

Subtask: 7

Verdict:

input
200000 200000
1810 2088 3022 3097 7459 7943 ...

correct output
2
-1
-1
2
-1
...

user output
(empty)

Test 44

Subtask: 7

Verdict:

input
199531 200000
11328 26391 30353 37063 44412 ...

correct output
-1
2
-1
2
2
...

user output
(empty)

Test 45

Subtask: 7

Verdict:

input
200000 200000
106738201 369187074 412614650 ...

correct output
2
12
3
19
3
...

user output
(empty)

Test 46

Subtask: 7

Verdict:

input
200000 200000
670611290 43427363 8475380 309...

correct output
3
5
3
3
3
...

user output
(empty)

Test 47

Subtask: 7

Verdict:

input
200000 200000
907542569 504758282 948727805 ...

correct output
3
33
3
3
3
...

user output
(empty)

Test 48

Subtask: 7

Verdict:

input
200000 200000
487056731 460461648 142698485 ...

correct output
3
3
3
3
3
...

user output
(empty)

Test 49

Subtask: 7

Verdict:

input
200000 200000
12772 23236 23236 23236 41149 ...

correct output
0
0
0
0
0
...

user output
(empty)

Test 50

Subtask: 7

Verdict:

input
200000 200000
999993539 999993361 999993361 ...

correct output
125375
16687
-1
84781
46147
...

user output
(empty)

Test 51

Subtask: 7

Verdict:

input
200000 200000
999993539 999993361 999993361 ...

correct output
94788
177608
95881
56377
179957
...

user output
(empty)

Test 52

Subtask: 1, 2, 3, 5, 6, 7

Verdict: ACCEPTED

input
5 1
2 1 3 5 4
2 2

correct output
2

user output
2

Test 53

Subtask: 1, 2, 3, 4, 5, 6, 7

Verdict: ACCEPTED

input
2 1
1 2
1 1

correct output
0

user output
0

Test 54

Subtask: 2, 5, 6, 7

Verdict: ACCEPTED

input
4 1
2 1 4 3
3 2

correct output
2

user output
2

Test 55

Subtask: 1, 2, 3, 4, 6, 7

Verdict: ACCEPTED

input
10 10
1 1 1 1 2 2 1 1 2 2
7 1
2 6
4 5
...

correct output
-1
1
-1
-1
-1
...

user output
-1
1
-1
-1
-1
...

Test 56

Subtask: 1, 2, 3, 6, 7

Verdict: ACCEPTED

input
10 10
181777772 181777772 181777772 ...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 57

Subtask: 6, 7

Verdict: ACCEPTED

input
100 10
92800811 524548163 939127795 9...

correct output
-1
-1
3
-1
3
...

user output
-1
-1
3
-1
3
...

Test 58

Subtask: 3, 4, 7

Verdict: ACCEPTED

input
100 100000
2 2 2 1 2 2 2 2 1 2 1 1 1 2 2 ...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 59

Subtask: 3, 7

Verdict: ACCEPTED

input
100 100000
172695325 172695325 172695325 ...

correct output
-1
-1
-1
-1
-1
...

user output
-1
-1
-1
-1
-1
...

Test 60

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
4 10
869194539 239439572 968540665 ...

correct output
-1
2
-1
-1
-1
...

user output
-1
2
-1
-1
-1
...

Test 61

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
55366041 112170735 112170735 5...

correct output
-1
-1
2
1
1
...

user output
-1
-1
2
1
1
...

Test 62

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
156018639 156018639 445832758 ...

correct output
-1
1
-1
-1
2
...

user output
-1
1
-1
-1
2
...

Test 63

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
702507512 702507512 892090406 ...

correct output
-1
2
-1
2
2
...

user output
-1
2
-1
2
2
...

Test 64

Subtask: 2, 6, 7

Verdict: ACCEPTED

input
10 10
720324490 720324490 720324490 ...

correct output
-1
2
2
1
-1
...

user output
-1
2
2
1
-1
...