QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#867728#9685. nim 游戏thomaswmy97 1139ms133304kbC++206.9kb2025-01-23 22:17:322025-01-26 18:56:02

Judging History

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

  • [2025-01-27 09:19:35]
  • hack成功,自动添加数据
  • (/hack/1490)
  • [2025-01-27 08:19:11]
  • hack成功,自动添加数据
  • (/hack/1488)
  • [2025-01-26 18:56:02]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:97
  • 用时:1139ms
  • 内存:133304kb
  • [2025-01-26 18:55:44]
  • hack成功,自动添加数据
  • (/hack/1475)
  • [2025-01-23 22:17:37]
  • 评测
  • 测评结果:100
  • 用时:1139ms
  • 内存:133352kb
  • [2025-01-23 22:17:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int M=2e4+10;
const int P=133331;
typedef long long ll;
const ll Mod=1e18+3;
const ll inf=4e18;

int T;
int n,m;
ll A[N];
ll a[N],b[N];
vector<pair<ll,int> > aa[61];
// bool vis[N];
ll mnc;

struct Node{
    vector<pair<int,ll> >  arr;

    void clear() {
        arr.clear();
    }

    void ins(int x,ll y) {
        arr.push_back({x,y});
    }

    void upd() {
        sort(arr.begin(),arr.end());
        static ll add[N];
        for(auto i:arr) add[i.first]=0;
        for(auto i:arr) add[i.first]+=i.second;
        vector<pair<int,ll> > res;
        for(auto i:arr) {
            if(!add[i.first]) continue;
            res.push_back({i.first,add[i.first]});
            add[i.first]=0;
        }
        swap(arr,res);
    }

    ll geth() {
        ll res=0;
        for(auto i:arr) res=((__int128)res*P+i.first)%Mod;
        for(auto i:arr) res=((__int128)res*P+(__int128)i.first*i.second)%Mod;
        return res;
    }

    void print() {
        printf("%d\n",arr.size());
        for(auto i:arr) printf("%d ",i.first);printf("\n");
        for(auto i:arr) printf("%lld ",i.second);printf("\n");
    }

    bool chk(ll xr) {
        ll sum=0;
        for(auto i:arr) xr^=A[i.first],xr^=A[i.first]+i.second,sum+=i.second;
        return !xr && sum==mnc;
    }
};

vector<Node> ans;
set<ll> st;
vector<int> valid;

void init() {
    ans.clear(),st.clear(),valid.clear();
    // for(int i=1;i<=n;i++) vis[i]=0;
    for(ll i=0;i<=60;i++) {
        aa[i].clear();
        for(int j=1;j<=n;j++) {
            if(a[j]>>i&1ll) continue;
            ll val=a[j]&((1ll<<i)-1);
            aa[i].push_back({val,j});
        }
        sort(aa[i].begin(),aa[i].end());
        reverse(aa[i].begin(),aa[i].end());
    }
}

ll calc(ll *a,ll now,ll xr,vector<int> arr) {
    if(now<0) return 0;
    if(!(xr>>now&1ll)) return calc(a,now-1,xr,arr);
    ll ans=0;
    pair<ll,int> mx={-1,0};
    // for(int i:arr) vis[i]=1;
    for(auto j:aa[now]) {
        if(j.first!=(a[j.second]&((1ll<<now)-1))) continue;
        mx=j;
        break;
    }
    // for(int i:arr) vis[i]=0;
    for(int i:arr) {
        if(a[i]>>now&1ll) continue;
        ll val=a[i]&((1ll<<now)-1);
        mx=max(mx,{val,i});
    }
    if(!mx.second) {
        if(a==b) {
            return inf;
        }
        for(int j=1;j<=n;j++) b[j]=a[j];
        ll mn=inf;
        for(int j=1;j<=n;j++) {
            ll cnt=(1ll<<now+1)-(a[j]&((1ll<<now+1)-1));
            xr^=b[j];
            b[j]+=cnt;
            xr^=b[j];
            arr.push_back(j);
            ll res=calc(b,60,xr,arr)+cnt;
            if(res<mn) {
                mn=res;
                valid.clear();
            }
            if(mn==res) valid.push_back(j);
            arr.pop_back();
            xr^=b[j];
            b[j]-=cnt;
            xr^=b[j];
        }
        return mn;
    }
    ll cnt=(1ll<<now)-mx.first;
    arr.push_back({mx.second});
    xr^=a[mx.second];
    ans+=cnt,a[mx.second]+=cnt;
    xr^=a[mx.second];
    ans+=calc(a,now-1,xr,arr);
    a[mx.second]-=cnt;
    return ans;
}

void solve(ll *a,ll now,ll xr,vector<int> arr,Node nd,ll sum) {
    // printf("%lld %lld:%lld\n",now,xr,sum);
    // for(int i=1;i<=n;i++) printf("%lld ",a[i]);printf("\n");
    // for(int i:arr) printf("%d ",i);printf("\n");
    sort(arr.begin(),arr.end()),arr.erase(unique(arr.begin(),arr.end()),arr.end());
    if(ans.size()>=m) return ;
    if(now<0) {
        nd.upd();
        ll h=nd.geth();
        if(st.find(h)!=st.end()) return ;
        st.insert(h);
        ans.push_back(nd);
        // if(!nd.chk(1)) printf("??????????????\n");
        return ;
    }
    if(!(xr>>now&1ll)) return solve(a,now-1,xr,arr,nd,sum);
    pair<ll,int> mx={-1,0};
    // for(int i:arr) vis[i]=1;
    for(auto j:aa[now]) {
        if(j.first!=(a[j.second]&((1ll<<now)-1))) continue;
        mx=j;
        break;
    }
    // for(int i:arr) vis[i]=0;
    for(int i:arr) {
        if(a[i]>>now&1ll) continue;
        ll val=a[i]&((1ll<<now)-1);
        mx=max(mx,{val,i});
    }
    if(!mx.second) {
        if(a==b) return ;
        for(int j=1;j<=n;j++) b[j]=a[j];
        for(int j:valid) {
            ll cnt=(1ll<<now+1)-(a[j]&((1ll<<now+1)-1));
            xr^=b[j];
            b[j]+=cnt;
            xr^=b[j];
            arr.push_back(j);
            Node v=nd;
            v.ins(j,cnt);
            solve(b,60,xr,arr,v,sum+cnt);
            if(ans.size()>=m) return ;
            arr.pop_back();
            xr^=b[j];
            b[j]-=cnt;
            xr^=b[j];
        }
        return ;
    }
    // for(int i:arr) vis[i]=1;
    for(auto j:aa[now]) {
        if(j.first!=(a[j.second]&((1ll<<now)-1))) continue;
        ll cnt=(1ll<<now)-(a[j.second]&((1ll<<now)-1));
        bool flag=a[j.second]==mx.first;
        Node v=nd;
        arr.push_back({j.second});
        v.ins(j.second,cnt);
        xr^=a[j.second];
        a[j.second]+=cnt;
        xr^=a[j.second];
        // printf(" %lld %lld-> %d %lld %d\n",now,xr,j.second,j.first,vis[j.second]);
        flag|=calc(a,now-1,xr,arr)+sum+cnt==mnc;
        if(flag) solve(a,now-1,xr,arr,v,sum+cnt);
        if(ans.size()>=m) return ;
        arr.pop_back();
        xr^=a[j.second];
        a[j.second]-=cnt;
        xr^=a[j.second];
        if(!flag) break;
    }
    // for(int i:arr) vis[i]=0;
    vector<pair<ll,int> > arrr;
    for(int i:arr) {
        if(a[i]>>now&1ll) continue;
        ll val=a[i]&((1ll<<now)-1);
        arrr.push_back({val,i});
    }
    sort(arrr.begin(),arrr.end());
    reverse(arrr.begin(),arrr.end());
    for(auto j:arrr) {
        ll cnt=(1ll<<now)-(a[j.second]&((1ll<<now)-1));
        bool flag=a[j.second]==mx.first;
        Node v=nd;
        arr.push_back({j.second});
        v.ins(j.second,cnt);
        xr^=a[j.second];
        a[j.second]+=cnt;
        xr^=a[j.second];
        flag|=calc(a,now-1,xr,arr)+sum+cnt==mnc;
        // printf("%lld %lld-> %d %lld\n",now,xr,j.second,j.first);
        if(flag) solve(a,now-1,xr,arr,v,sum+cnt);
        if(ans.size()>=m) return ;
        arr.pop_back();
        xr^=a[j.second];
        a[j.second]-=cnt;
        xr^=a[j.second];
        if(!flag) break;
    }
    return ;
}

int main() {
    // freopen("nim.in","r",stdin);
    // freopen("nim.out","w",stdout);
    scanf("%*d%d",&T);
    while(T--) {
        scanf("%d%d",&n,&m);
        ll xr=0;
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]),A[i]=a[i],xr^=a[i];
        init();
        mnc=calc(a,60,xr,{});
        printf("%lld\n",mnc);
        Node nd;
        nd.clear();
        solve(a,60,xr,{},nd,0);
        printf("%lld\n",ans.size());
        // assert(ans.size()<=m);
        for(Node i:ans) {
            if(!i.chk(xr)) printf("???????????????\n"),assert(0);
            i.print();
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 167ms
memory: 3840kb

input:

1 10000
2 1
324097321 555675086
2 1
304655177 991244276
2 1
9980291 383616352
2 1
1071036550 795625380
2 1
682098056 68370721
2 1
969101726 685975156
2 1
973896269 354857775
2 1
196188000 606494155
2 1
754416123 467588829
2 1
495704303 558090120
2 1
618002000 491488050
2 1
741575237 9937018
2 1
1002...

output:

231577765
1
1
1 
231577765 
686589099
1
1
1 
686589099 
373636061
1
1
1 
373636061 
275411170
1
1
2 
275411170 
613727335
1
1
2 
613727335 
283126570
1
1
2 
283126570 
619038494
1
1
2 
619038494 
410306155
1
1
1 
410306155 
286827294
1
1
2 
286827294 
62385817
1
1
1 
62385817 
126513950
1
1
2 
12651...

result:

ok correct answer

Subtask #2:

score: 12
Accepted

Test #2:

score: 12
Accepted
time: 0ms
memory: 3840kb

input:

2 5
5 2000
0 13 3 4 10
5 2000
0 3 9 1 11
5 2000
0 13 7 3 5
5 2000
0 1 13 9 2
5 2000
0 8 14 7 13

output:

0
1
0


0
1
0


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

result:

ok correct answer

Test #3:

score: 12
Accepted
time: 0ms
memory: 5968kb

input:

2 5
5 2000
0 4 14 5 7
5 2000
0 2 15 0 12
5 2000
0 1 14 0 5
5 2000
0 13 4 12 3
5 2000
0 10 10 1 11

output:

6
2
3
1 4 5 
4 1 1 
2
4 5 
1 5 
1
4
1
5 
1 
1
4 
1 
1
2 
1 
1
1 
1 
8
8
3
2 4 5 
3 2 3 
3
1 2 5 
2 3 3 
2
2 5 
3 5 
2
2 5 
5 3 
3
2 4 5 
1 4 3 
3
1 2 5 
4 1 3 
2
2 5 
1 7 
2
2 5 
7 1 
2
4
2
4 5 
1 1 
2
3 5 
1 1 
2
1 5 
1 1 
1
5 
2 
10
13
3
1 3 4 
2 1 7 
3
1 2 4 
2 1 7 
2
1 4 
3 7 
2
1 4 
2 8 
2
3 4 ...

result:

ok correct answer

Test #4:

score: 12
Accepted
time: 0ms
memory: 3840kb

input:

2 5
5 2000
0 6 15 10 1
5 2000
0 15 0 13 10
5 2000
0 5 7 5 1
5 2000
0 13 3 2 15
5 2000
0 2 4 7 0

output:

2
5
2
4 5 
1 1 
2
2 5 
1 1 
2
1 5 
1 1 
1
5 
2 
1
1 
2 
8
2
1
3 
8 
1
1 
8 
4
2
2
4 5 
1 3 
2
2 5 
1 3 
1
1
1
2 
1 
1
4
1
5 
1 
1
3 
1 
1
2 
1 
1
1 
1 

result:

ok correct answer

Subtask #3:

score: 12
Accepted

Dependency #2:

100%
Accepted

Test #5:

score: 12
Accepted
time: 2ms
memory: 4224kb

input:

3 5
6 2000
0 45 517 811 107 132
6 2000
0 382 576 805 419 579
6 2000
0 379 809 441 331 67
6 2000
0 565 776 959 852 383
6 2000
0 613 383 829 47 441

output:

146
20
4
2 3 5 6 
19 1 1 125 
5
1 2 3 5 6 
1 19 1 1 124 
4
2 3 5 6 
19 1 2 124 
4
2 3 5 6 
19 2 1 124 
4
2 3 5 6 
20 1 1 124 
3
2 5 6 
19 1 126 
4
1 2 5 6 
2 19 1 124 
3
2 5 6 
19 3 124 
3
2 5 6 
21 1 124 
4
2 3 4 6 
19 1 1 125 
5
1 2 3 4 6 
1 19 1 1 124 
4
2 3 4 6 
19 1 2 124 
4
2 3 4 6 
19 2 1 124...

result:

ok correct answer

Test #6:

score: 12
Accepted
time: 0ms
memory: 5964kb

input:

3 5
6 2000
0 75 173 555 637 905
6 2000
0 934 118 906 367 728
6 2000
0 244 321 598 625 469
6 2000
0 573 489 24 480 459
6 2000
0 424 356 750 623 871

output:

557
483
5
1 2 3 5 6 
11 53 339 131 23 
5
1 2 3 5 6 
10 53 339 131 24 
5
1 2 3 5 6 
10 53 339 132 23 
5
1 2 3 5 6 
10 53 340 131 23 
5
1 2 3 5 6 
10 54 339 131 23 
5
1 2 3 5 6 
9 53 339 131 25 
5
1 2 3 5 6 
8 53 339 131 26 
5
1 2 3 5 6 
8 53 339 132 25 
5
1 2 3 5 6 
8 53 340 131 25 
5
1 2 3 5 6 
8 54...

result:

ok correct answer

Test #7:

score: 12
Accepted
time: 3ms
memory: 6088kb

input:

3 5
6 2000
0 886 972 226 813 407
6 2000
0 219 190 742 101 572
6 2000
0 590 423 516 1017 46
6 2000
0 388 807 207 205 647
6 2000
0 408 180 238 300 694

output:

176
25
5
1 2 4 5 6 
12 10 30 19 105 
5
1 2 4 5 6 
8 10 30 19 109 
5
1 2 4 5 6 
8 10 30 23 105 
5
1 2 4 5 6 
8 10 34 19 105 
5
1 2 4 5 6 
8 14 30 19 105 
5
1 2 4 5 6 
4 10 30 19 113 
4
2 4 5 6 
10 30 19 117 
4
2 4 5 6 
10 30 23 113 
4
2 4 5 6 
10 34 19 113 
4
2 4 5 6 
14 30 19 113 
5
1 2 4 5 6 
4 10 ...

result:

ok correct answer

Subtask #4:

score: 12
Accepted

Test #8:

score: 12
Accepted
time: 497ms
memory: 132076kb

input:

4 257
100000 100
32768 65536 262144 32768 8388608 1048576 4 67108864 16384 32768 262144 8192 512 134217728 65536 4194304 262144 67108864 1024 262144 64 32 65536 2097152 268435456 1 2048 4194304 16777216 8 16384 2 2048 16777216 268435456 262144 1048576 8388608 16 268435456 2 128 4194304 262144 32768 ...

output:

303389274
100
13
99915 99935 99958 99963 99973 99976 99978 99979 99983 99985 99987 99992 99998 
2 1048576 262144 8 4096 2048 16 33554432 16384 64 268435456 65536 512 
13
99906 99935 99958 99963 99973 99976 99978 99979 99983 99985 99987 99992 99998 
2 1048576 262144 8 4096 2048 16 33554432 16384 64 2...

result:

ok correct answer

Test #9:

score: 12
Accepted
time: 495ms
memory: 132744kb

input:

4 266
100000 100
134217728 524288 8388608 4 8 8388608 33554432 4 536870912 4 16 8 33554432 33554432 256 65536 8 16 64 8 256 2048 268435456 256 8192 2 1024 65536 32 2048 134217728 8 1048576 8 16777216 33554432 1024 33554432 131072 16 2 33554432 8192 512 4194304 2048 268435456 256 536870912 16777216 1...

output:

269988539
100
15
99897 99925 99938 99958 99960 99964 99965 99970 99972 99975 99985 99995 99997 99999 100000 
8 8192 2 512 1 16 32 4096 1048576 32768 262144 268435456 65536 128 131072 
15
99897 99925 99938 99941 99958 99964 99965 99970 99972 99975 99985 99995 99997 99999 100000 
8 8192 2 1 512 16 32 ...

result:

ok correct answer

Test #10:

score: 12
Accepted
time: 487ms
memory: 132072kb

input:

4 269
100000 100
1048576 2 64 67108864 1024 67108864 268435456 32768 8388608 32 256 2 268435456 262144 524288 262144 2 524288 64 8192 262144 536870912 2097152 64 1024 2 1048576 128 2 8388608 512 32768 1 8388608 4 2 268435456 128 67108864 65536 2 8388608 2048 16 2048 4096 32768 1048576 32768 32 83886...

output:

471323918
100
15
99857 99900 99949 99955 99958 99959 99968 99978 99979 99983 99984 99986 99988 99992 99996 
1048576 131072 16384 8 4 262144 256 32768 268435456 1024 2 134217728 4096 65536 67108864 
15
99857 99900 99949 99955 99958 99959 99968 99972 99978 99979 99983 99986 99988 99992 99996 
1048576 ...

result:

ok correct answer

Test #11:

score: 12
Accepted
time: 937ms
memory: 132712kb

input:

4 2
100000 5000
32768 2 1024 1 65536 32768 4194304 4 2 33554432 1048576 268435456 4194304 268435456 268435456 4194304 32768 2097152 131072 16777216 1024 262144 2048 65536 512 1024 8388608 128 512 33554432 1 32 134217728 8388608 2097152 4 2097152 1048576 1024 33554432 536870912 536870912 33554432 327...

output:

362412129
5000
15
99944 99961 99963 99970 99973 99975 99976 99979 99984 99985 99986 99991 99994 99995 100000 
1048576 268435456 524288 16384 8192 16777216 1 67108864 4096 65536 32768 32 8388608 64 2048 
15
99897 99944 99961 99963 99970 99973 99975 99979 99984 99985 99986 99991 99994 99995 100000 
1 ...

result:

ok correct answer

Test #12:

score: 12
Accepted
time: 480ms
memory: 133304kb

input:

4 1
100000 10000
32 536870912 4194304 32768 8 16777216 16384 32768 131072 131072 128 8192 32 32 256 4096 8 268435456 65536 1024 64 1024 4194304 4194304 128 268435456 2097152 64 8192 1048576 33554432 128 4194304 16 134217728 128 16384 4 33554432 67108864 2048 33554432 524288 1048576 4 4096 268435456 ...

output:

454096
10000
11
99903 99925 99966 99969 99974 99982 99986 99987 99993 99997 100000 
256 131072 128 8192 262144 16384 64 1024 2048 32768 16 
11
99900 99903 99925 99966 99969 99974 99982 99986 99987 99993 99997 
16 256 131072 128 8192 262144 16384 64 1024 2048 32768 
11
99897 99903 99925 99966 99969 9...

result:

ok correct answer

Test #13:

score: 12
Accepted
time: 248ms
memory: 5964kb

input:

4 10000
20 1
536870912 131072 2048 8388608 2097152 128 4 67108864 8 128 1048576 8388608 32768 8 2097152 2 256 512 256 8388608
20 1
67108864 134217728 64 8 1024 134217728 536870912 256 268435456 65536 16777216 4 4096 4194304 131072 16384 128 16384 65536 2
20 1
16 1048576 16384 33554432 131072 128 204...

output:

477201922
1
6
8 11 13 15 16 18 
469762048 1048576 98304 6291456 2 1536 
322833594
1
7
4 5 9 11 15 17 20 
56 3072 268435456 50331648 4063232 128 2 
437384810
1
9
2 4 11 12 14 15 17 18 20 
1048576 33554432 402653184 12288 2 96 8 114688 1536 
28919934
1
7
5 7 11 14 17 19 20 
25165824 2048 14 16384 112 ...

result:

ok correct answer

Test #14:

score: 12
Accepted
time: 621ms
memory: 8012kb

input:

4 100
2000 100
524288 1 4096 16 32768 8 2048 262144 512 512 268435456 2048 256 32 1048576 524288 536870912 134217728 2048 64 33554432 65536 4 8388608 512 67108864 67108864 1048576 8388608 524288 256 4096 32 131072 536870912 2 8388608 2 67108864 128 32 8192 67108864 268435456 524288 8388608 8388608 1...

output:

352738786
100
14
1910 1941 1953 1962 1971 1972 1977 1979 1984 1986 1988 1992 1996 2000 
32 131072 2048 262144 1024 16384 128 268435456 64 256 16777216 2 4096 67108864 
14
1910 1941 1953 1962 1971 1972 1977 1979 1981 1984 1986 1988 1996 2000 
32 131072 2048 262144 1024 16384 128 268435456 2 64 256 16...

result:

ok correct answer

Test #15:

score: 12
Accepted
time: 199ms
memory: 128084kb

input:

4 1
69901 10000
524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 5242...

output:

280444
10000
11
5724 15516 33111 34071 37820 40503 41849 48015 55228 67967 69901 
262144 16384 1024 512 256 64 32 16 8 3 1 
12
5724 15516 33111 34071 37820 40503 41849 48015 55228 67966 67967 69901 
262144 16384 1024 512 256 64 32 16 8 1 2 1 
12
5724 15516 33111 34071 37820 40503 41849 48015 55228 6...

result:

ok correct answer

Test #16:

score: 12
Accepted
time: 286ms
memory: 50992kb

input:

4 2
48360 5000
524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 524288 52428...

output:

253569
5000
10
7219 9597 10867 14140 21895 25109 26305 29036 33988 48360 
131072 65536 32768 16384 4096 2048 1024 512 128 1 
10
7219 9597 10867 14140 21895 25109 26305 29036 33988 48359 
131072 65536 32768 16384 4096 2048 1024 512 128 1 
10
7219 9597 10867 14140 21895 25109 26305 29036 33988 48358 
...

result:

ok correct answer

Test #17:

score: 12
Accepted
time: 23ms
memory: 5968kb

input:

4 100
34 100
536870912 536870912 268435456 134217728 67108864 67108864 33554432 16777216 8388608 1048576 524288 262144 131072 65536 65536 32768 32768 16384 8192 8192 4096 4096 2048 2048 1024 512 512 64 64 32 32 16 4 4
36 100
536870912 536870912 268435456 134217728 134217728 67108864 67108864 1677721...

output:

158712816
100
11
4 8 10 12 15 17 18 27 29 31 32 
134217728 16777216 7340032 262144 65536 32768 16384 512 448 32 16 
11
4 8 10 12 15 17 18 27 29 30 32 
134217728 16777216 7340032 262144 65536 32768 16384 512 448 32 16 
10
4 8 10 12 15 17 18 27 29 32 
134217728 16777216 7340032 262144 65536 32768 1638...

result:

ok correct answer

Subtask #5:

score: 12
Accepted

Test #18:

score: 12
Accepted
time: 321ms
memory: 5916kb

input:

5 10000
10 1
0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823
10 1
0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823
10 1
0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741...

output:

1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 
...

result:

ok correct answer

Test #19:

score: 12
Accepted
time: 517ms
memory: 94128kb

input:

5 2323
100000 1
0 3170633 888529329 347839787 101667249 273239696 1028446182 411994109 710973319 298677951 299452068 519308796 361451040 488605068 74238166 997794448 478367019 532094220 747266199 217905213 682359917 774814810 234838947 456387659 38459020 434013070 633290806 173828476 94076883 568288...

output:

11962
1
15
5529 8448 33798 38129 47454 49541 78515 92451 93848 98306 99366 99572 99856 99867 99986 
19 54 8212 139 1 2165 1364 1 1 1 1 1 1 1 1 
1607036
1
11
4 6 7 12 15 16 22 26 28 29 36 
65471 32512 6 520064 978944 6136 3836 4 60 2 1 
106
1
3
1 2 3 
40 21 45 
3
1
2
5 6 
2 1 
126
1
4
3 5 9 10 
12 7 ...

result:

ok correct answer

Test #20:

score: 12
Accepted
time: 517ms
memory: 94792kb

input:

5 2205
100000 1
0 684191025 220215685 982495864 602362406 687396179 439432236 81065680 398068897 269754402 306183653 309939439 664994998 1011962742 338161922 629593565 926305057 1026259775 711874360 69406110 426672919 208267066 551253027 9384823 26156203 778817402 654214308 527029151 1065024353 2870...

output:

22539
1
18
9642 11813 14681 21599 38540 38873 86392 89268 92825 94825 98800 99251 99679 99698 99981 99988 99998 99999 
18405 5 1 2826 14 846 1 404 28 1 1 1 1 1 1 1 1 1 
5296170
1
10
8 9 11 14 16 19 20 23 30 38 
1048320 64 4194240 30 6142 31744 15360 2 16 252 
2997548
1
3
3 4 5 
7998 1031664 1957886 ...

result:

ok correct answer

Test #21:

score: 12
Accepted
time: 519ms
memory: 94008kb

input:

5 2166
100000 1
0 58930516 543560994 783997157 728082180 789115629 549794748 81818067 214839912 203394814 711969322 908524000 570262778 992867922 359455295 88035653 412186516 937931728 331800409 545354553 535440658 894562512 657466952 555070606 469471475 1055263866 874958292 76960239 478302168 68009...

output:

8241
1
16
66 26786 29190 54258 68234 72809 82425 95831 96789 98518 99162 99656 99924 99975 99999 100000 
63 5 7798 156 192 4 14 1 1 1 1 1 1 1 1 1 
2846999
1
4
1 2 4 5 
202000 103522 1978946 562531 
1605
1
5
6 10 12 21 23 
96 1023 480 1 5 
21150
1
4
1 2 3 5 
40 13205 4050 3855 
13
1
2
1 2 
6 7 
0
1
0...

result:

ok correct answer

Subtask #6:

score: 16
Accepted

Test #22:

score: 16
Accepted
time: 2ms
memory: 6728kb

input:

6 23
1000 10
0 357293452 452461848 986047039 546588280 762710079 767831017 39741545 416114273 515599366 1018969624 603342125 928112286 1053016142 240953466 533088067 1028134429 504727014 371307863 834428873 968387878 478550336 1047217797 1046651542 777749850 866989319 92995163 251915198 363285573 10...

output:

264227
10
12
134 203 355 565 673 786 876 955 983 996 999 1000 
5 2638 9 531 1 697 251113 10 1 5226 3995 1 
12
134 203 355 565 673 786 876 955 983 996 998 999 
5 2638 9 531 1 697 251113 10 1 5226 1 3995 
12
134 203 355 565 673 786 876 955 983 996 997 999 
5 2638 9 531 1 697 251113 10 1 5226 1 3995 
1...

result:

ok correct answer

Test #23:

score: 16
Accepted
time: 2ms
memory: 6612kb

input:

6 23
1000 10
0 978686021 287986921 276311856 889616598 739968417 1060147652 463275477 172393699 591333230 983197307 235514434 330494755 449056272 882229818 781111474 275587745 980041928 334198691 305313012 415758352 947298893 950211162 909723054 961622596 917454340 161928901 404346316 369133631 1038...

output:

709905
10
15
32 279 283 482 656 677 727 842 904 917 966 977 978 989 999 
56 3862 6 12836 4 1 47 693086 1 1 1 1 1 1 1 
15
32 279 283 482 656 677 727 842 904 917 966 977 978 989 996 
56 3862 6 12836 4 1 47 693086 1 1 1 1 1 1 1 
15
32 279 283 482 656 677 727 842 904 917 966 977 978 989 995 
56 3862 6 1...

result:

ok correct answer

Test #24:

score: 16
Accepted
time: 3ms
memory: 6984kb

input:

6 15
1000 10
0 631723071 149784582 965844254 515554472 887253148 467825521 981769969 1054193550 627909969 590277818 159342752 658063143 667914173 169490051 25536270 337269419 1056885019 980490575 750858271 553446484 347553447 376197986 1053224035 473470890 123586 97769047 761755924 510998818 2560945...

output:

737485
10
15
172 265 384 474 599 625 747 790 831 880 922 924 952 988 1000 
27 227 215546 2917 6 7 87404 1600 16 41649 1 388082 1 1 1 
15
172 265 384 474 599 625 747 790 831 880 922 924 952 988 995 
27 227 215546 2917 6 7 87404 1600 16 41649 1 388082 1 1 1 
15
172 265 384 474 599 625 747 790 831 880 ...

result:

ok correct answer

Test #25:

score: 16
Accepted
time: 3ms
memory: 4736kb

input:

6 25
1000 10
0 751950140 901599329 987895071 306253500 278530668 539473653 911723672 948474628 722632384 369217860 428703545 999113214 567923990 53499297 1013528916 263060554 669297221 349021033 832596533 893306880 892438572 345611286 331257977 488113061 578929864 881846255 320356815 76057168 704694...

output:

1119212
10
14
97 122 215 236 431 528 552 576 678 717 887 920 950 995 
7 5641 149775 107 6002 26620 674 1237 1 6239 922903 1 4 1 
14
97 122 215 236 431 528 552 576 678 717 887 920 950 989 
7 5641 149775 107 6002 26620 674 1237 1 6239 922903 1 4 1 
14
97 122 215 236 431 528 552 576 678 717 887 920 950...

result:

ok correct answer

Test #26:

score: 16
Accepted
time: 1ms
memory: 6476kb

input:

6 2
1000 1
0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1...

output:

1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 

result:

ok correct answer

Subtask #7:

score: 16
Accepted

Dependency #3:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #27:

score: 16
Accepted
time: 388ms
memory: 93900kb

input:

7 195
100000 1000
0 828483622 617711013 242092397 1034026464 456205583 731635466 382894773 533786631 582730039 74863848 661821965 368857719 541353387 662605236 580923280 798012506 54823622 333416217 39292129 995195996 477140985 1014499425 362164396 970752859 879997855 96768859 1005365898 576674982 4...

output:

23456
1000
17
7223 8651 12609 26970 27646 70487 78081 91597 94288 94649 96808 98603 99454 99814 99965 99992 99998 
1743 3 20988 34 4 3 1 1 279 1 393 1 1 1 1 1 1 
17
7223 8651 12609 26970 27646 70487 78081 91597 94288 94649 96808 98603 99454 99814 99954 99965 99992 
1743 3 20988 34 4 3 1 1 279 1 393 ...

result:

ok correct answer

Test #28:

score: 16
Accepted
time: 391ms
memory: 94148kb

input:

7 228
100000 1000
0 230727359 951312015 741711018 367230626 775024687 130794976 435788836 781961691 736694220 427610697 1016199868 798240399 340962994 1006804448 708169239 976753368 364431996 495851435 246658001 190094424 1054346726 639713727 218794912 229693460 313349630 85091951 418997497 27345904...

output:

5906
1000
18
31031 36690 49706 57375 60712 63184 67455 67985 94039 94258 96652 97479 97656 99982 99995 99996 99998 100000 
2 71 1 2 11 28 3 4034 20 1 1 1071 656 1 1 1 1 1 
18
31031 36690 49706 57375 60712 63184 67455 67985 94039 94258 96652 97479 97656 99982 99995 99996 99998 99999 
2 71 1 2 11 28 3...

result:

ok correct answer

Test #29:

score: 16
Accepted
time: 388ms
memory: 94128kb

input:

7 221
100000 1000
0 716795222 632538294 1008333912 248043863 1023411987 11954597 917179098 100756831 19780613 336926235 768679016 371044675 360783184 402042708 1056697208 567354265 284551620 146863144 1008241012 536649321 680142584 506474136 80860918 973856876 30288601 668537691 877380398 131785980 ...

output:

13893
1000
15
8817 12957 31013 49780 68169 82418 90592 94588 94709 99263 99963 99968 99990 99999 100000 
307 22 10 2415 2 33 1 11096 1 1 1 1 1 1 1 
15
8817 12957 31013 49780 68169 82418 90592 94588 94709 99263 99963 99968 99990 99998 100000 
307 22 10 2415 2 33 1 11096 1 1 1 1 1 1 1 
15
8817 12957 3...

result:

ok correct answer

Test #30:

score: 16
Accepted
time: 36ms
memory: 3840kb

input:

7 1000
3 10
0 729041606 776089922
3 10
0 73695624 783752411
3 10
0 820372959 215264354
3 10
0 919645823 161862972
3 10
0 416211733 881194269
3 10
0 275811209 281074929
3 10
0 582815620 342763006
3 10
0 922520113 399127881
3 10
0 299636294 328307001
3 10
0 666654277 503934330
3 10
0 2735358 732598564...

output:

47048316
10
2
1 2 
37892418 9155898 
2
1 2 
37892416 9155900 
2
1 2 
37892354 9155962 
2
1 2 
37892352 9155964 
2
1 2 
37892162 9156154 
2
1 2 
37892160 9156156 
2
1 2 
37892098 9156218 
2
1 2 
37892096 9156220 
2
1 2 
37888322 9159994 
2
1 2 
37888320 9159996 
710056787
10
2
1 2 
246881496 46317529...

result:

ok correct answer

Test #31:

score: 16
Accepted
time: 48ms
memory: 3968kb

input:

7 2000
3 5
0 3978360 573616453
3 5
0 547375641 97549509
3 5
0 710402134 567209414
3 5
0 712013879 1031360933
3 5
0 118351677 538884285
3 5
0 96665729 441728559
3 5
0 1021357084 735021028
3 5
0 882151625 958055123
3 5
0 521548745 517316479
3 5
0 162247430 426447555
3 5
0 423460219 408674001
3 5
0 247...

output:

569638093
5
2
1 2 
36745536 532892557 
2
1 2 
36745537 532892556 
2
1 2 
36745540 532892553 
2
1 2 
36745541 532892552 
2
1 2 
36745472 532892621 
449826132
5
2
1 3 
10504729 439321403 
2
1 3 
10504728 439321404 
2
1 3 
10504721 439321411 
2
1 3 
10504720 439321412 
2
1 3 
10504713 439321419 
143192...

result:

ok correct answer

Test #32:

score: 16
Accepted
time: 34ms
memory: 5968kb

input:

7 1000
4 10
0 827032080 596299879 377757837
4 10
0 139678996 620475310 982977750
4 10
0 327504523 973136882 1056046317
4 10
0 703538140 645917988 869157682
4 10
0 453817111 255127787 753233051
4 10
0 503195344 905031432 746786602
4 10
0 615183881 988518844 555461556
4 10
0 932813811 356392410 858830...

output:

28167702
10
3
1 2 3 
8659072 11828733 7679897 
3
1 2 3 
8659073 11828732 7679897 
3
1 2 3 
8659072 11828732 7679898 
3
1 2 3 
8659076 11828729 7679897 
3
1 2 3 
8659077 11828728 7679897 
3
1 2 3 
8659076 11828728 7679898 
3
1 2 3 
8659072 11828729 7679901 
3
1 2 3 
8659073 11828728 7679901 
3
1 2 3 ...

result:

ok correct answer

Test #33:

score: 16
Accepted
time: 136ms
memory: 71332kb

input:

7 2
100000 1
0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823...

output:

1073741823
1
1
1 
1073741823 
1073741823
1
1
1 
1073741823 

result:

ok correct answer

Test #34:

score: 16
Accepted
time: 400ms
memory: 94112kb

input:

7 204
100000 1000
0 867143449 289720871 62880653 256495758 373546157 114942061 524281177 164218453 261500635 241690011 911469619 794136322 460604293 201667773 1001245336 873383805 136426866 731765422 1036091702 428463064 474020221 916532901 913755707 704796468 745115429 387268771 611877390 101588067...

output:

1241
1000
11
17963 47178 55333 66676 72308 98251 98425 99833 99990 99994 100000 
132 11 1 119 970 1 3 1 1 1 1 
11
17963 47178 55333 66676 72308 98251 98425 99833 99990 99994 99998 
132 11 1 119 970 1 3 1 1 1 1 
11
17963 47178 55333 66676 72308 98251 98425 99833 99990 99994 99997 
132 11 1 119 970 1 ...

result:

ok correct answer

Subtask #8:

score: 8
Accepted

Dependency #7:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #1:

100%
Accepted

Test #35:

score: 8
Accepted
time: 409ms
memory: 97144kb

input:

8 259
99999 1000
0 184042404 114860590 81955939 149152356 141033215 259145072 144981065 194732174 87943638 3239431 196977178 27923106 209711053 259763893 143914852 152580789 5161376 220134523 49139129 179593854 115442954 268238166 42599190 6509126 76156465 153820967 111093283 89981466 186373935 6842...

output:

553
1000
13
28126 37309 74516 77278 89972 95837 96126 99109 99490 99929 99945 99993 99994 
253 1 11 1 279 1 1 1 1 1 1 1 1 
13
28126 37309 74516 77278 89972 95837 96126 99109 99490 99929 99945 99990 99994 
253 1 11 1 279 1 1 1 1 1 1 1 1 
13
28126 37309 74516 77278 89972 95837 96126 99109 99490 99929 ...

result:

ok correct answer

Test #36:

score: 8
Accepted
time: 46ms
memory: 5888kb

input:

8 2000
4 5
775795058 434974743 31074946 428696702
4 5
373180095 760380481 419902862 1049258222
4 5
667161035 673656536 537091509 513688618
4 5
724027945 494292286 644201747 822331951
4 5
661539617 30050732 358848696 134411535
4 5
385734187 236947885 562514730 169874287
4 5
600384888 205880481 862584...

output:

260593779
5
3
1 2 3 
29511310 101896169 129186300 
3
1 2 3 
29511310 101896171 129186298 
3
1 2 3 
29511312 101896169 129186298 
3
1 2 3 
29511310 101896173 129186296 
3
1 2 3 
29511310 101896175 129186294 
56241154
5
3
2 3 4 
44925887 1624690 9690577 
3
2 3 4 
44925887 1624691 9690576 
3
2 3 4 
449...

result:

ok correct answer

Test #37:

score: 8
Accepted
time: 32ms
memory: 5968kb

input:

8 1000
5 10
925022554 416509837 681820051 569347404 420577661
5 10
676949322 809105046 710668968 622139077 525882012
5 10
1016024766 383498611 324818602 167492568 583945990
5 10
607262806 436684746 91524379 563713486 399361534
5 10
34445929 59287234 604627291 374306204 356825324
5 10
397715954 64098...

output:

178944881
10
4
2 3 4 5 
19697779 6045805 34632374 118568923 
4
2 3 4 5 
19697779 6045805 34632372 118568925 
4
2 3 4 5 
19697779 6045807 34632372 118568923 
4
2 3 4 5 
19697781 6045805 34632372 118568923 
4
2 3 4 5 
19697779 6045805 34632382 118568915 
4
2 3 4 5 
19697779 6045805 34632380 118568917 ...

result:

ok correct answer

Test #38:

score: 8
Accepted
time: 53ms
memory: 5968kb

input:

8 2000
5 5
473869931 296333033 588516074 759843895 35958055
5 5
953551548 127791846 1067155511 142228569 808428787
5 5
977517289 585648677 426698807 253563544 406251869
5 5
686608779 801530488 616526809 555449962 916117338
5 5
348008156 65221769 877389953 1015414374 793534370
5 5
655907997 32966869 ...

output:

16644274
5
4
1 2 3 4 
12669333 413975 29975 3530991 
4
1 2 3 4 
12669333 413975 29974 3530992 
4
1 2 3 4 
12669333 413976 29974 3530991 
4
1 2 3 4 
12669334 413975 29974 3530991 
4
1 2 3 4 
12669333 413975 29977 3530989 
645767497
5
4
1 2 4 5 
53081414 140643611 394642343 57400129 
4
1 2 4 5 
530814...

result:

ok correct answer

Test #39:

score: 8
Accepted
time: 374ms
memory: 96244kb

input:

8 1
100000 10000
915290977 22868788 1025329403 347856861 420729394 1031706586 333760509 169548927 301431481 435455016 662381372 586742635 364996906 344073612 411728519 737579061 507676813 207760998 366591424 858197674 366805311 138854539 67574619 198712646 669454189 994338754 531742435 589428670 190...

output:

3351
10000
16
8436 10572 34186 46966 54923 77748 77898 96158 97523 99138 99943 99947 99949 99996 99998 99999 
616 4 312 97 1 1 182 1 2130 1 1 1 1 1 1 1 
16
8436 10572 34186 46966 54923 77748 77898 96158 97523 99138 99943 99947 99949 99994 99998 99999 
616 4 312 97 1 1 182 1 2130 1 1 1 1 1 1 1 
16
84...

result:

ok correct answer

Test #40:

score: 8
Accepted
time: 704ms
memory: 71376kb

input:

8 2
99999 5000
1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823...

output:

1073741825
5000
2
1 99999 
1 1073741824 
2
1 99999 
2 1073741823 
2
1 99999 
3 1073741822 
2
1 99999 
4 1073741821 
2
1 99999 
5 1073741820 
2
1 99999 
6 1073741819 
2
1 99999 
7 1073741818 
2
1 99999 
8 1073741817 
2
1 99999 
9 1073741816 
2
1 99999 
10 1073741815 
2
1 99999 
11 1073741814 
2
1 999...

result:

ok correct answer

Test #41:

score: 8
Accepted
time: 405ms
memory: 97264kb

input:

8 229
99999 1000
0 67684423 27530736 262933500 210540490 87986446 142495215 8108489 162333902 7472566 74649932 22340176 96113149 105072940 96282592 479313 231805795 113210597 21907161 131354773 137785844 44861082 60046190 195538723 185926550 49537906 255986573 48373131 153611664 98228321 259354412 1...

output:

1406
1000
14
7858 28521 39604 40342 42925 46982 70009 73472 73671 88604 99667 99693 99938 99984 
15 81 187 207 1 130 1 47 731 2 1 1 1 1 
14
7858 28521 39604 40342 42925 46982 70009 73472 73671 88604 99667 99693 99938 99981 
15 81 187 207 1 130 1 47 731 2 1 1 1 1 
14
7858 28521 39604 40342 42925 4698...

result:

ok correct answer

Subtask #9:

score: 8
Accepted

Dependency #8:

100%
Accepted

Test #42:

score: 8
Accepted
time: 366ms
memory: 58772kb

input:

9 299
99999 2000
0 46856671573051356 144451722821279396 194202742420356088 42768202435393968 146930968341077918 121735975802283045 43381059403904591 9790356926653248 90585698509588415 182205406048046442 106698163084666387 83495547377102990 95530264027271484 151047337738852707 263069394355867183 2157...

output:

3144886350134
2000
27
2980 4700 6949 16115 19764 21141 25835 27859 30961 31845 46521 48368 49133 56329 71057 78175 88091 89626 91418 97499 98883 98974 99075 99584 99762 99896 99980 
169076 1497224288718 5830 933386637 67487321 91372840416 2152295861 1521611014901 1532 1 499432150 79 12269454815 1 12...

result:

ok correct answer

Test #43:

score: 8
Accepted
time: 382ms
memory: 58656kb

input:

9 308
99999 2000
0 62481075687254565 108220925926439751 147822046782831506 143330595029626008 266264147751224285 261103833765129444 47417861284547971 240063309104990334 57610062682346847 86133126920120030 166996559481841953 262167570538721871 37862622740033692 1564310050448344 238599881630673329 841...

output:

1899280322188
2000
31
1356 2278 3636 15132 17538 18067 19843 23023 34798 41115 41884 50818 57179 57679 66896 72504 75474 76054 79898 80838 83595 97728 97882 98598 99004 99882 99972 99988 99990 99993 99999 
64573475 1729 30706446 5081 76 3582624376 29658 783168 8 3128937444 1032 2314 1618610116420 35...

result:

ok correct answer

Test #44:

score: 8
Accepted
time: 572ms
memory: 61396kb

input:

9 2
100000 10000
545540578362523900 802534136160364409 809231497363184827 759501804930050980 1066479206576357239 113267640347273288 1107254323072039272 763295278607790739 912485685700691438 727288572379934749 272909272033889513 924743325654854239 64044479016101192 339140683670447461 9373897167684681...

output:

12275804674058
10000
35
4006 9145 15662 21253 22024 22366 22655 23389 28977 31363 34108 42059 45301 46404 49267 51828 52067 52825 62055 63090 63494 64589 74670 75164 83580 87329 88864 90252 90325 92155 99308 99589 99712 99798 99999 
6052736249 7844621 31895258 4884201630817 892589 4081678146670 1576...

result:

ok correct answer

Test #45:

score: 8
Accepted
time: 292ms
memory: 3968kb

input:

9 4000
5 5
524582397937493597 592236532825740338 21586345239448165 35636657892584584 82467454909981811
5 5
560534499250551966 1035104135447720083 393978030527830357 716060135880322165 215951553880947576
5 5
1051942003414886425 777605024087419586 912448182719431665 686402173473881719 2718408701626896...

output:

97375822640526071
5
4
1 2 3 4 
51878354365929891 2238617987165134 5435252524774811 37823597762656235 
4
1 2 3 4 
51878354365929891 2238617987165135 5435252524774811 37823597762656234 
4
1 2 3 4 
51878354365929891 2238617987165134 5435252524774812 37823597762656234 
4
1 2 3 4 
51878354365929892 22386...

result:

ok correct answer

Test #46:

score: 8
Accepted
time: 1139ms
memory: 9932kb

input:

9 2
99999 10000
1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152921504606846975 1152...

output:

1152921504606846977
10000
2
1 99999 
1 1152921504606846976 
2
1 99999 
2 1152921504606846975 
2
1 99999 
3 1152921504606846974 
2
1 99999 
4 1152921504606846973 
2
1 99999 
5 1152921504606846972 
2
1 99999 
6 1152921504606846971 
2
1 99999 
7 1152921504606846970 
2
1 99999 
8 1152921504606846969 
2
...

result:

ok correct answer

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 1
time: 1297ms
memory: 3968kb

input:

9 20000
5 1
290320068132385891 819316158291999388 806707996649909634 508206073858256833 696890216047283941
5 1
967260073357096260 1080611516924285625 423322742425293546 829525985365769043 120818727231358585
5 1
550965563655122829 230185600245023665 782378293413070531 307141616183743196 3072845879360...

output:

221357737230254045
1
4
1 2 4 5 
69967902057253789 45374970163135846 68254678445166655 37760186564697755 
170305764282731989
1
4
2 3 4 5 
252393644633415 153138009878129942 8143545325143213 8771815434825419 
47826592986311447
1
4
1 3 4 5 
25495188648300659 10255241004136765 3606758104821028 846940522...

result:

wrong answer jury has better answer