QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134504#6399. Classic: Classical Problemstefanbalaz2TL 622ms16052kbC++145.9kb2023-08-03 21:13:212023-08-03 21:13:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-03 21:13:22]
  • 评测
  • 测评结果:TL
  • 用时:622ms
  • 内存:16052kb
  • [2023-08-03 21:13:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
typedef pair<int,int> pii;

int mod=998244353;
const double dmod=(double)1/mod;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){

   /* ll ret=(ll)x*y;
    ret=ret-((ll)(dmod*ret))*mod;
    if(ret<0)ret+=mod;
    if(ret>=mod)ret-=mod;
    return ret;*/

    return ((ll)x*y)%mod;
}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}

const int maxn=(1<<20);

int proot=step(3,7*17*8);
int prekw[maxn];

int g,a[maxn],n,mp[maxn],b[maxn],c[maxn];
void prek(){
    for(int i=2;i<maxn;i++){
        if(mp[i])continue;
        for(int j=i;j<maxn;j+=i){
            if(!mp[j])mp[j]=i;
        }
    }

    prekw[0]=1;
    for(int i=1;i<maxn;i++)
        prekw[i]=mul(prekw[i-1],proot);

}
vector<int> factorise(int n){

    vector<int>ret;
    while(n>1){
        if(ret.size()==0)ret.pb(mp[n]);
        else if(ret.back()!=mp[n])ret.pb(mp[n]);
        n/=mp[n];
    }
    return ret;
}
int get_gen(int p){

    if(p==2)return 1;

    p--;

    vector<int>fact=factorise(p);

    for(int i=1;i<=p;i++){

        int e=1;
        for(int j=0;j<fact.size();j++){
            if(step(i,p/fact[j])==1){
                e=0;break;
            }
        }

        if(e)return i;
    }

    return -1;
}

vector<int>resetfb;
int resetb=0;
void fft(vector<int>&a,bool invert){

    int n=a.size();

    int j=0;
    for(int i=1;i<n;i++){

        int bit=n>>1;
        for(;bit&j;bit>>=1)j^=bit;
        j^=bit;

        if(i<j)swap(a[i],a[j]);
    }

    for(int len=2;len<=n;len<<=1){

        for(int i=0;i<n;i+=len){

            int cw=maxn/len;
            if(invert)cw=maxn-cw;
            int curr=0;
            for(int j=0;j<len/2;j++){

                int pom1=a[i+j];
                int pom2=mul(a[i+j+len/2],prekw[curr]);

                a[i+j]=add(pom1,pom2);
                a[i+j+len/2]=sub(pom1,pom2);

                curr+=cw;
                if(curr>=maxn)curr-=maxn;

            }

        }

    }


    if(invert){
        int invn=invv(n);
        for(int i=0;i<n;i++)
            a[i]=mul(a[i],invn);
    }

}

int brute_par=500;
vector<int>pol_mul_brute(vector<int>a,vector<int>b){

    int ppp=mod;
    mod=998244353;
    //printf("OPA1\n");
    ///cout<<(int)a.size()-1+(int)b.size()-1+1<<endl;
    vector<int>ret((int)a.size()-1+(int)b.size()-1+1);

    //printf("OPA2\n");
    for(int i=0;i<a.size();i++)
    for(int j=0;j<b.size();j++){
        ret[i+j]=add(ret[i+j], mul(a[i],b[j]) );
    }
    //printf("OPA3\n");

    mod=ppp;
    return ret;
}
void ispis(vector<int>a){
    for(int i=0;i<a.size();i++)printf("%d ",a[i]);
    printf(" ISPIS \n");
}

vector<int> pol_mul(vector<int>a,vector<int>b){

    //printf("OPA1 \n");


    /*if(a.size()*b.size()<brute_par){
        return pol_mul_brute(a,b);
    }*/

    int n=1;
    while(n<(int)a.size()-1+(int)b.size()-1+1)n<<=1;

    a.resize(n);
    b.resize(n);

    int ppp=mod;
    mod=998244353;

    //printf("OPA2 \n");
    fft(a,0);
    /*printf("START\n");
    ispis(b);
    ispis(resetfb);*/
    //fft(b,0);
    if(resetb){
        fft(b,0);
        resetfb=b;
        resetb=0;
    }
    else {
        b=resetfb;
    }

   /* ispis(b);
    ispis(resetfb);
    printf("END\n");*/

    for(int i=0;i<n;i++)
        a[i]=mul(a[i],b[i]);

    fft(a,1);
    mod=ppp;
    //printf("OPA3 \n");
    return a;
}

vector<int> va,vb;
vector<int> check(int x){

    va.clear();
    va.resize(2*mod-2);

    int cn=mod-1;

    for(int i=0;i<va.size();i++){
        if( b[i%cn]<=x )va[i]=1;
        else va[i]=0;
    }

   // printf("%d XXX\n",x);
   // ispis(va);

    vector<int>ret=pol_mul(va,vb);
    vector<int>bla=pol_mul_brute(va,vb);

    /*ispis(ret);
    ispis(bla);
    printf(" AHHA\n");*/

    vector<int>rr;
    for(int i=0;i<cn;i++){
        ///printf()
        if(ret[i+cn-1]==x)rr.pb(b[i]);
    }

    return rr;
}

int main() {

    prek();

    /*vector<int>bb,aa;
    aa.pb(1);
    aa.pb(1);
    bb.pb(2);
    bb.pb(3);
    aa=pol_mul(aa,bb);
    ispis(aa);*/


    ///freopen("test.txt","r",stdin);

    int t;
    scanf("%d",&t);
    while(t--){

        scanf("%d %d",&n,&mod);

        resetb=1;

        int e=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            if(a[i]==0){
                e=1;
                n--;
                i--;
            }
        }

        if(!e){
            printf("%d %d\n0\n",1,1);
            continue;
        }

        g=get_gen(mod);

        /// ako je mex==0 onda dodaj i 0 u rez

        ///printf("%d  GEN\n",g);

        int curr=1;
        for(int i=0;i<mod-1;i++){
            b[i]=curr;
            c[curr]=i;
            //printf("%d %d  BC\n",i,curr);
            curr=mul(curr,g);
        }

        vb.clear();
        vb.resize(mod-1);
        for(int i=1;i<=n;i++){
            vb[c[a[i]]]=1;
        }
        //ispis(vb);
        reverse(vb.begin(),vb.end());

        int l=0;
        int r=mod-1;
        int sr,ret=-1;
        while(l<=r){
            sr=(l+r)/2;

            vector<int>pom=check(sr);

            if(pom.size()==0){
                r=sr-1;
            }
            else{
                l=sr+1;
                ret=sr;
            }
        }
        vector<int>rr=check(ret);
        ret++;
        if(ret==1)rr.pb(0);

        printf("%d %d\n",rr.size(),ret);
        sort(rr.begin(),rr.end());
        for(int i=0;i<rr.size();i++)printf("%d ",rr[i]);
        printf("\n");

    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 17ms
memory: 15064kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 13ms
memory: 15572kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
1 2
1 

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 13ms
memory: 15308kb

input:

7
1 3
0
1 3
1
2 3
1 0
1 3
2
2 3
2 0
2 3
1 2
3 3
0 1 2

output:

3 1
0 1 2 
1 1
0
1 2
1 
1 1
0
1 2
2 
1 1
0
2 3
1 2 

result:

ok 14 lines

Test #4:

score: 0
Accepted
time: 18ms
memory: 15036kb

input:

31
1 5
0
1 5
1
2 5
1 0
1 5
2
2 5
0 2
2 5
2 1
3 5
1 0 2
1 5
3
2 5
0 3
2 5
1 3
3 5
0 1 3
2 5
3 2
3 5
0 2 3
3 5
2 1 3
4 5
2 0 1 3
1 5
4
2 5
4 0
2 5
1 4
3 5
1 4 0
2 5
2 4
3 5
2 4 0
3 5
4 2 1
4 5
1 0 4 2
2 5
4 3
3 5
0 4 3
3 5
3 1 4
4 5
1 4 3 0
3 5
4 3 2
4 5
2 4 0 3
4 5
2 1 4 3
5 5
1 3 0 2 4

output:

5 1
0 1 2 3 4 
1 1
0
1 2
1 
1 1
0
1 2
3 
1 1
0
1 3
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
2 2
2 3 
1 1
0
1 4
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
1 3
3 
1 1
0
1 4
3 
1 1
0
1 3
4 
1 1
0
1 4
2 
1 1
0
1 4
4 
1 1
0
4 5
1 2 3 4 

result:

ok 62 lines

Test #5:

score: 0
Accepted
time: 18ms
memory: 15488kb

input:

127
1 7
0
1 7
1
2 7
1 0
1 7
2
2 7
2 0
2 7
2 1
3 7
2 1 0
1 7
3
2 7
3 0
2 7
3 1
3 7
3 1 0
2 7
2 3
3 7
2 0 3
3 7
2 1 3
4 7
2 0 3 1
1 7
4
2 7
0 4
2 7
1 4
3 7
0 1 4
2 7
4 2
3 7
0 4 2
3 7
1 2 4
4 7
2 4 1 0
2 7
4 3
3 7
3 0 4
3 7
3 1 4
4 7
1 0 4 3
3 7
3 2 4
4 7
3 0 2 4
4 7
4 1 3 2
5 7
4 3 0 1 2
1 7
5
2 7
0 ...

output:

7 1
0 1 2 3 4 5 6 
1 1
0
1 2
1 
1 1
0
1 2
4 
1 1
0
1 3
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
2 2
4 5 
1 1
0
1 4
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
3 3
1 2 4 
1 1
0
2 2
2 5 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
1 5
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
2 2
3 4 
1 1
0
1 3
1 
1 1
0
1 3
3 
1 1
0
1...

result:

ok 254 lines

Test #6:

score: 0
Accepted
time: 22ms
memory: 14904kb

input:

2047
1 11
0
1 11
1
2 11
0 1
1 11
2
2 11
0 2
2 11
2 1
3 11
1 0 2
1 11
3
2 11
3 0
2 11
3 1
3 11
0 3 1
2 11
2 3
3 11
0 2 3
3 11
2 1 3
4 11
1 0 3 2
1 11
4
2 11
0 4
2 11
4 1
3 11
1 4 0
2 11
2 4
3 11
2 0 4
3 11
2 1 4
4 11
0 2 1 4
2 11
3 4
3 11
3 4 0
3 11
3 1 4
4 11
4 1 3 0
3 11
4 3 2
4 11
3 4 0 2
4 11
3 1...

output:

11 1
0 1 2 3 4 5 6 7 8 9 10 
1 1
0
1 2
1 
1 1
0
1 2
6 
1 1
0
1 3
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
2 2
4 6 
1 1
0
1 4
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
1 3
6 
1 1
0
2 3
1 6 
1 1
0
2 2
3 4 
1 1
0
3 2
1 3 4 
1 1
0
1 3
6 
1 1
0
1 5
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
6 9 
1 1
0
1 3
1 
1 1
0
...

result:

ok 4094 lines

Test #7:

score: 0
Accepted
time: 108ms
memory: 15284kb

input:

8191
1 13
0
1 13
1
2 13
0 1
1 13
2
2 13
2 0
2 13
2 1
3 13
2 1 0
1 13
3
2 13
0 3
2 13
1 3
3 13
1 0 3
2 13
2 3
3 13
2 0 3
3 13
3 1 2
4 13
1 3 2 0
1 13
4
2 13
4 0
2 13
4 1
3 13
0 1 4
2 13
2 4
3 13
0 2 4
3 13
2 4 1
4 13
0 1 4 2
2 13
3 4
3 13
3 0 4
3 13
4 1 3
4 13
4 1 0 3
3 13
4 2 3
4 13
3 2 0 4
4 13
3 4...

output:

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

result:

ok 16382 lines

Test #8:

score: 0
Accepted
time: 156ms
memory: 15240kb

input:

11764
1 17
0
1 17
1
2 17
0 1
1 17
2
2 17
0 2
2 17
2 1
3 17
2 1 0
1 17
3
2 17
3 0
2 17
1 3
3 17
3 0 1
2 17
2 3
3 17
0 3 2
3 17
3 2 1
4 17
3 2 0 1
1 17
4
2 17
0 4
2 17
4 1
3 17
1 4 0
2 17
4 2
3 17
0 2 4
3 17
2 1 4
4 17
2 4 1 0
2 17
3 4
3 17
3 4 0
3 17
4 1 3
4 17
4 1 0 3
3 17
2 4 3
4 17
2 0 3 4
4 17
2 ...

output:

17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
1 1
0
1 2
1 
1 1
0
1 2
9 
1 1
0
1 3
1 
1 1
0
1 2
6 
1 1
0
2 2
1 6 
1 1
0
2 2
6 9 
1 1
0
1 4
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
1 3
9 
1 1
0
2 3
1 9 
1 1
0
2 2
6 13 
1 1
0
3 2
1 6 13 
1 1
0
1 3
9 
1 1
0
1 5
1 
1 1
0
1 2
7 
1 1
0
2 2
1 7 
1 1
0
2 2
7 ...

result:

ok 23528 lines

Test #9:

score: 0
Accepted
time: 179ms
memory: 16052kb

input:

10526
1 19
0
1 19
1
2 19
0 1
1 19
2
2 19
2 0
2 19
2 1
3 19
0 2 1
1 19
3
2 19
0 3
2 19
3 1
3 19
1 0 3
2 19
3 2
3 19
2 0 3
3 19
1 3 2
4 19
1 2 0 3
1 19
4
2 19
0 4
2 19
4 1
3 19
0 1 4
2 19
4 2
3 19
4 0 2
3 19
2 4 1
4 19
4 2 0 1
2 19
4 3
3 19
0 3 4
3 19
1 3 4
4 19
3 4 0 1
3 19
4 3 2
4 19
0 4 3 2
4 19
1 ...

output:

19 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 
1 1
0
1 2
1 
1 1
0
1 2
10 
1 1
0
1 3
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
2 2
10 13 
1 1
0
1 4
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
1 3
10 
1 1
0
2 3
1 10 
1 1
0
2 2
5 13 
1 1
0
3 2
1 5 13 
1 1
0
1 3
10 
1 1
0
1 5
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
...

result:

ok 21052 lines

Test #10:

score: 0
Accepted
time: 538ms
memory: 14732kb

input:

10000
9 83
60 35 63 59 58 81 0 13 71
1 5
0
1 7
0
2 61
39 0
2 7
0 4
1 7
0
2 19
0 14
1 2
0
3 23
14 10 0
3 11
0 5 2
1 5
0
2 7
0 4
2 3
0 2
2 3
0 1
1 13
0
5 47
10 2 34 15 0
1 2
0
1 17
0
1 11
0
2 7
1 0
1 7
0
2 23
0 17
2 13
10 0
2 7
1 0
6 31
19 13 6 29 0 24
4 23
0 5 18 17
2 19
0 5
1 7
0
2 13
7 0
3 17
0 6 1...

output:

2 3
38 76 
5 1
0 1 2 3 4 
7 1
0 1 2 3 4 5 6 
1 2
36 
1 2
2 
7 1
0 1 2 3 4 5 6 
1 2
15 
2 1
0 1 
2 2
5 7 
2 2
6 9 
5 1
0 1 2 3 4 
1 2
2 
1 2
2 
1 2
1 
13 1
0 1 2 3 4 5 6 7 8 9 10 11 12 
4 2
18 22 24 33 
2 1
0 1 
17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
11 1
0 1 2 3 4 5 6 7 8 9 10 
1 2
1 
7 1
0 ...

result:

ok 20000 lines

Test #11:

score: 0
Accepted
time: 607ms
memory: 16028kb

input:

10000
10 11
6 8 0 1 7 3 2 9 4 5
21 23
21 19 10 17 11 20 6 3 2 18 9 16 13 14 4 12 8 7 1 0 15
7 7
6 2 4 0 1 5 3
17 19
4 6 5 11 17 15 0 10 3 8 12 18 13 7 9 2 14
15 17
11 15 8 2 12 3 1 13 16 6 7 0 9 10 5
2 2
0 1
2 2
0 1
33 37
11 20 9 16 19 32 33 31 3 29 36 10 8 25 22 17 5 6 15 28 14 0 4 27 18 12 34 21 3...

output:

1 10
1 
1 19
4 
6 7
1 2 3 4 5 6 
1 14
14 
1 14
12 
1 2
1 
1 2
1 
2 21
21 24 
1 8
8 
6 7
1 2 3 4 5 6 
10 11
1 2 3 4 5 6 7 8 9 10 
1 22
22 
1 6
1 
1 10
11 
1 26
22 
2 3
1 2 
1 14
16 
22 23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 
2 4
2 6 
1 18
3 
6 7
1 2 3 4 5 6 
1 2
1 
1 8
7 
1 28
15...

result:

ok 20000 lines

Test #12:

score: 0
Accepted
time: 574ms
memory: 14064kb

input:

10000
4 13
4 5 0 6
12 31
0 16 11 13 3 24 26 21 20 6 5 19
12 43
29 21 40 23 31 24 27 17 30 10 0 42
3 3
0 2 1
15 47
41 46 0 44 17 39 30 4 12 14 36 28 27 31 10
1 5
0
5 11
6 2 0 5 1
6 13
11 0 7 5 10 6
5 17
15 0 9 12 11
6 13
0 5 2 12 11 7
15 43
14 28 13 24 40 29 37 9 27 0 34 39 15 12 2
1 3
0
8 17
15 6 0 ...

output:

3 2
8 10 11 
1 6
6 
2 3
33 41 
2 3
1 2 
3 3
31 37 41 
5 1
0 1 2 3 4 
2 3
1 2 
2 3
4 8 
4 2
2 8 10 14 
1 3
12 
1 4
14 
3 1
0 1 2 
1 4
8 
2 1
0 1 
3 2
4 9 10 
4 2
1 3 5 12 
1 2
3 
5 2
3 12 15 16 18 
7 1
0 1 2 3 4 5 6 
5 2
2 5 15 16 18 
10 2
2 6 8 11 19 25 27 29 34 35 
3 2
2 7 9 
1 2
2 
3 3
7 14 15 
2 ...

result:

ok 20000 lines

Test #13:

score: 0
Accepted
time: 589ms
memory: 15868kb

input:

10000
13 19
13 6 0 9 15 2 4 10 3 5 11 12 14
5 11
5 8 10 0 6
2 3
0 1
1 2
0
10 19
6 16 2 1 17 0 4 10 5 7
4 7
0 1 4 2
41 73
55 47 13 35 18 68 3 25 67 36 70 69 62 37 56 64 49 72 12 0 4 17 31 8 66 63 2 16 65 60 24 26 7 21 33 52 54 39 29 53 71
1 3
0
26 61
43 0 37 54 47 49 17 38 19 28 35 18 39 36 33 34 8 2...

output:

1 6
13 
2 3
7 9 
1 2
1 
2 1
0 1 
1 4
10 
3 3
1 2 4 
1 12
72 
3 1
0 1 2 
2 5
10 17 
1 7
11 
1 7
27 
1 4
8 
2 3
1 2 
2 3
1 2 
1 2
1 
1 2
2 
1 6
6 
1 8
31 
1 4
13 
1 3
3 
1 4
12 
3 5
1 2 7 
1 7
5 
1 2
4 
3 1
0 1 2 
2 1
0 1 
2 4
4 6 
1 2
4 
2 2
1 10 
2 4
10 12 
2 4
4 6 
1 2
2 
2 6
3 5 
7 1
0 1 2 3 4 5 6...

result:

ok 20000 lines

Test #14:

score: 0
Accepted
time: 597ms
memory: 14932kb

input:

10000
2 3
0 2
38 61
50 55 35 52 17 40 15 51 39 11 5 41 2 33 49 25 0 24 53 13 30 59 9 34 57 37 38 27 29 1 19 31 46 8 45 58 6 42
11 17
5 13 1 11 2 0 6 7 4 12 10
6 11
3 0 4 7 10 6
21 29
17 14 7 18 20 28 23 25 16 3 22 5 21 2 0 9 13 1 12 11 19
5 5
0 3 2 1 4
20 23
19 16 0 1 15 18 14 12 21 6 22 8 11 13 20 ...

output:

1 2
2 
2 10
15 45 
1 7
3 
1 5
8 
2 8
7 24 
4 5
1 2 3 4 
1 14
20 
1 9
16 
1 6
7 
1 7
29 
1 6
6 
2 2
1 4 
1 6
8 
1 3
4 
2 4
2 3 
1 8
5 
1 7
8 
2 4
1 3 
1 6
3 
1 9
14 
1 6
5 
1 2
1 
2 7
11 22 
1 8
12 
2 5
2 8 
2 6
3 10 
1 7
2 
1 4
2 
1 2
1 
1 4
1 
1 5
11 
1 14
28 
2 3
1 2 
1 2
1 
1 10
8 
1 8
6 
1 6
5 
...

result:

ok 20000 lines

Test #15:

score: 0
Accepted
time: 622ms
memory: 14792kb

input:

10000
17 17
1 5 10 2 16 6 12 13 15 3 8 9 11 4 14 7 0
67 67
34 11 54 25 8 40 33 24 2 44 22 5 28 46 23 59 30 1 38 18 55 15 35 6 39 64 27 51 65 12 52 53 58 20 14 19 29 43 0 9 62 45 41 42 47 49 31 32 26 57 37 48 7 36 17 13 10 50 63 3 16 21 4 61 66 56 60
3 3
1 0 2
3 3
2 0 1
5 5
4 0 2 1 3
13 13
8 1 5 10 4...

output:

16 17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
66 67
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 
2 3
1 2 
2 3
1 2 
4 5
1 2 3 4 
12 13
1 2 3 4 5 6 7 8 9 10 ...

result:

ok 20000 lines

Test #16:

score: -100
Time Limit Exceeded

input:

1000
2 11
0 1
23 173
145 124 4 130 41 45 115 53 102 156 68 85 49 100 114 75 0 90 81 96 93 61 91
37 293
0 206 166 68 220 15 58 256 125 182 239 67 116 32 114 261 8 106 137 89 130 120 128 202 75 2 110 5 233 133 145 74 259 164 264 10 56
19 181
18 165 71 52 170 177 81 114 124 46 103 20 43 94 144 96 0 125...

output:

1 2
1 
2 3
50 60 
1 4
176 
18 2
27 38 42 44 45 51 52 58 66 80 94 100 122 127 147 148 171 172 
5 2
3 9 13 23 33 
1 3
126 
3 3
101 318 624 
1 3
16 
1 3
60 
8 2
8 10 24 31 32 38 39 44 
1 3
35 
8 2
17 19 24 44 51 59 61 69 
5 3
44 95 108 126 216 
6 3
82 100 284 471 479 501 
2 3
276 298 
5 3
72 181 186 19...

result: