QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#831645#8905. Ультра mexthomaswmy100 ✓1117ms77644kbC++204.0kb2024-12-25 15:51:422024-12-25 15:51:44

Judging History

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

  • [2024-12-25 15:51:44]
  • 评测
  • 测评结果:100
  • 用时:1117ms
  • 内存:77644kb
  • [2024-12-25 15:51:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace PolyNTT{
    int PMod=998244353,PG=3;
    typedef long long ll;
    
    int qpow(int x,ll y) {
        int z=1;
        for(;y;y>>=1) {
            if(y&1) z=1ll*z*x%PMod;
            x=1ll*x*x%PMod;
        }
        return z;
    }
    
    void NTT(vector<ll> &a,int len,int op) {
        static vector<int> rev,W;
        rev.resize(len),W.resize(len);
        for(int i=1;i<len;i++) rev[i]=(rev[i>>1]>>1)|(i&1? len>>1:0);
        for(int i=1;i<len;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
        for(int h=2,p=1;h<=len;p=h,h<<=1) {
            W[0]=1,W[1]=qpow(PG,(PMod-1)/h);
            if(op==-1) W[1]=qpow(W[1],h-1);
            for(int i=2;i<p;i++) W[i]=1ll*W[i-1]*W[1]%PMod;
            for(int i=0;i<len;i+=h) {
                for(int j=i;j<i+p;j++) {
                    ll u=a[j],v=1ll*W[j-i]*a[j+p]%PMod;
                    a[j]=u+v,a[j+p]=u-v;
                }
            }
        }
        for(int i=0;i<len;i++) a[i]=(a[i]%PMod+PMod)%PMod;
        if(op==-1) {
            int inv=qpow(len,PMod-2);
            for(int i=0;i<len;i++) a[i]=1ll*a[i]*inv%PMod;
        }
    }
    
    typedef vector<ll> Poly;
    
    Poly operator+(Poly x,Poly y) {
        x.resize(max(x.size(),y.size()));
        for(int i=0;i<y.size();i++) x[i]+=y[i];
        return x;
    }

    Poly upd(Poly x) {
        for(int i=0;i<x.size();i++) x[i]=(x[i]%PMod+PMod)%PMod;
        return x;
    }
    
    Poly operator*(Poly x,Poly y) {
        int l=1,ll=x.size()+y.size()-1;
        while(l<ll) l<<=1;
        x.resize(l),y.resize(l);
        NTT(x,l,1),NTT(y,l,1);
        for(int i=0;i<l;i++) x[i]=1ll*x[i]*y[i]%PMod;
        NTT(x,l,-1);
        x.resize(ll);
        return x;
    }

    Poly Shift(Poly x,int s) {
        if(x.size()+s<=0) return {};
        if(!s) return x;
        if(s>0) {
            x.resize(x.size()+s);
            for(int i=x.size()-1;i>=0;i--) x[i]=i<s? 0:x[i-s];
        }
        else {
            for(int i=0;i<x.size();i++) x[i]=i-s<x.size()? x[i-s]:0;
            x.resize(x.size()+s);
        }
        return x;
    }
}using namespace PolyNTT;

const int N=20;
const int M=1<<17|10;

int T,Mod;
int lg[M];
Poly f[N][N],g[N][N];
int fac[M],inv[M];

int lowbit(int x) {
    return x&-x;
}

int C(int x,int y) {
    if(x<y || y<0) return 0;
    return 1ll*fac[x]*inv[y]%Mod*inv[x-y]%Mod;
}

bool chkg(int g) {
    int x=Mod-1;
    for(int i=2;i*i<=x;i++) {
        if(x%i) continue;
        if(qpow(g,(Mod-1)/i)==1) return 0;
        while(x%i==0) x/=i;
    }
    if(x>1) {
        if(qpow(g,(Mod-1)/x)==1) return 0;
    }
    return 1;
}

int main() {
    scanf("%d%d",&Mod,&T);
    PMod=Mod;
    PG=2;
    while(!chkg(PG)) PG++;
    int n=M-10;
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%Mod;
    inv[n]=qpow(fac[n],Mod-2);
    for(int i=n-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
    for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
    f[1][0]=g[1][0]={0,1};
    for(int i=2;i<=17;i++) {
        for(int j=0;j<i;j++) f[i][j].resize(1<<i),g[i][j].resize(1<<i);
        Poly p;
        p.resize((1<<i-1)+1);
        for(int j=0;j<=1<<i-1;j++) p[j]=C(1<<i-1,j);
        for(int j=0;j<i-1;j++) f[i][j]=f[i][j]+f[i-1][j]*p;
        for(int j=0;j<=1<<i-1;j++) p[j]=C((1<<i-1)-1,j);
        for(int j=0;j<i-1;j++) g[i][j]=g[i][j]+f[i-1][j]*p;
        for(int j=0;j<i;j++) f[i][j]=f[i][j]+Shift(f[i-1][j],1<<i-1),g[i][j]=g[i][j]+Shift(g[i-1][j],1<<i-1);
        for(int j=0;j<(1<<i-1)-1;j++) f[i][i-1][j+(1<<i-1)]+=C((1<<i-1)-2,j),g[i][i-1][j+(1<<i-1)]+=C((1<<i-1)-2,j);
        for(int j=0;j<i;j++) f[i][j]=f[i][j]+Shift(g[i-1][j],1<<i-1);
        for(int j=0;j<i;j++) f[i][j]=upd(f[i][j]);
    }
    while(T--) {
        int k,n,m;
        scanf("%d%d%d",&k,&n,&m);
        if(lowbit(m)!=m) printf("0\n");
        else if(n==(1<<k)) printf("%d\n",m==(1<<k));
        else printf("%d\n",n<f[k][lg[m]].size()? f[k][lg[m]][n]:0);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 1070ms
memory: 77420kb

input:

118751233
10
1 2 2
1 2 1
1 2 2
1 2 2
1 2 2
1 1 1
1 1 2
1 1 1
1 1 1
1 1 2

output:

1
0
1
1
1
1
0
1
1
0

result:

ok 10 numbers

Test #2:

score: 3
Accepted
time: 1070ms
memory: 77344kb

input:

64749569
10
1 1 1
1 1 2
1 1 2
1 2 2
1 1 2
1 2 1
1 1 2
1 2 1
1 2 1
1 1 2

output:

1
0
0
1
0
0
0
0
0
0

result:

ok 10 numbers

Test #3:

score: 3
Accepted
time: 1090ms
memory: 77512kb

input:

5767169
10
1 2 1
1 1 1
1 2 2
1 1 1
1 1 2
1 1 1
1 1 1
1 1 2
1 2 1
1 1 1

output:

0
1
1
1
0
1
1
0
0
1

result:

ok 10 numbers

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #4:

score: 5
Accepted
time: 1082ms
memory: 77344kb

input:

120586241
10
2 4 1
2 4 1
2 4 4
2 1 2
2 1 3
2 4 1
2 4 4
2 1 1
2 1 1
2 2 2

output:

0
0
1
0
0
0
1
1
1
1

result:

ok 10 numbers

Test #5:

score: 5
Accepted
time: 1070ms
memory: 77344kb

input:

434896897
10
1 2 2
2 2 1
2 2 2
2 2 1
1 2 2
2 2 2
2 1 1
2 3 1
1 1 1
2 4 4

output:

1
2
1
2
1
1
1
3
1
1

result:

ok 10 numbers

Test #6:

score: 5
Accepted
time: 1072ms
memory: 77436kb

input:

103284737
10
2 4 4
2 3 1
2 3 1
2 1 1
2 2 2
2 4 4
2 2 2
2 1 1
2 2 1
2 2 1

output:

1
3
3
1
1
1
1
1
2
2

result:

ok 10 numbers

Test #7:

score: 5
Accepted
time: 1069ms
memory: 77344kb

input:

120586241
10
2 3 1
2 1 1
2 4 4
2 1 1
2 2 1
2 4 4
2 3 1
2 2 2
2 1 1
2 2 2

output:

3
1
1
1
2
1
3
1
1
1

result:

ok 10 numbers

Test #8:

score: 5
Accepted
time: 1076ms
memory: 77556kb

input:

478937089
10
2 2 1
2 2 1
2 2 1
2 4 1
2 3 1
2 4 1
2 4 1
2 3 1
2 2 1
2 3 1

output:

2
2
2
0
3
0
0
3
2
3

result:

ok 10 numbers

Test #9:

score: 5
Accepted
time: 1082ms
memory: 77432kb

input:

23068673
10
2 1 1
2 1 1
2 2 1
2 4 1
2 3 1
2 2 1
2 3 1
2 4 1
2 1 1
2 2 1

output:

1
1
2
0
3
2
3
0
1
2

result:

ok 10 numbers

Test #10:

score: 5
Accepted
time: 1099ms
memory: 77432kb

input:

786432001
10
1 1 2
1 1 2
2 1 4
2 1 1
2 3 1
1 2 1
2 4 2
1 2 2
2 1 1
1 1 2

output:

0
0
0
1
3
0
0
1
1
0

result:

ok 10 numbers

Subtask #3:

score: 7
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 7
Accepted
time: 1088ms
memory: 77440kb

input:

244842497
10
3 4 1
3 4 3
3 3 4
3 6 4
3 2 6
3 2 1
3 4 4
3 3 6
3 3 8
3 8 5

output:

28
0
0
1
0
6
1
0
0
0

result:

ok 10 numbers

Test #12:

score: 7
Accepted
time: 1085ms
memory: 77508kb

input:

288882689
10
3 4 2
3 2 2
3 6 2
3 3 1
1 1 1
3 8 8
3 1 1
2 2 1
2 3 1
3 2 1

output:

6
1
3
17
1
1
1
2
3
6

result:

ok 10 numbers

Test #13:

score: 7
Accepted
time: 1081ms
memory: 77436kb

input:

483655681
10
3 4 1
3 3 1
3 6 1
3 6 2
3 2 1
3 5 2
3 6 4
3 4 2
3 5 1
3 3 2

output:

28
17
17
3
6
4
1
6
29
4

result:

ok 10 numbers

Test #14:

score: 7
Accepted
time: 1096ms
memory: 77444kb

input:

244842497
10
3 3 1
3 4 1
3 1 1
3 6 2
3 5 1
3 7 1
3 2 1
3 4 2
3 6 1
3 5 2

output:

17
28
1
3
29
7
6
6
17
4

result:

ok 10 numbers

Test #15:

score: 7
Accepted
time: 1072ms
memory: 77420kb

input:

404226049
10
3 4 1
3 8 1
3 6 1
3 7 1
3 5 1
3 8 1
3 5 1
3 4 1
3 8 1
3 7 1

output:

28
0
17
7
29
0
29
28
0
7

result:

ok 10 numbers

Test #16:

score: 7
Accepted
time: 1094ms
memory: 77404kb

input:

935329793
10
3 2 1
3 3 1
3 3 1
3 1 1
3 2 1
3 2 1
3 7 1
3 2 1
3 7 1
3 7 1

output:

6
17
17
1
6
6
7
6
7
7

result:

ok 10 numbers

Test #17:

score: 7
Accepted
time: 1104ms
memory: 77340kb

input:

23068673
10
1 2 2
3 8 1
1 2 2
2 2 2
3 7 4
1 2 1
1 1 2
3 6 2
2 4 2
1 2 2

output:

1
0
1
1
0
0
0
3
0
1

result:

ok 10 numbers

Subtask #4:

score: 8
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #18:

score: 8
Accepted
time: 1063ms
memory: 77640kb

input:

263454721
10
4 5 2
4 11 12
4 6 8
4 12 6
4 14 6
4 12 12
4 8 12
4 13 10
4 2 14
4 5 4

output:

220
0
0
0
0
0
0
0
0
10

result:

ok 10 numbers

Test #19:

score: 8
Accepted
time: 1089ms
memory: 77428kb

input:

302252033
10
4 6 4
4 16 16
4 8 1
3 6 4
4 9 4
4 12 8
4 8 4
4 13 2
4 13 4
2 1 1

output:

45
1
5244
1
252
15
210
33
14
1

result:

ok 10 numbers

Test #20:

score: 8
Accepted
time: 1098ms
memory: 77444kb

input:

983826433
10
4 13 1
4 16 16
4 8 8
4 12 8
4 10 2
4 12 2
4 15 1
4 13 2
4 10 8
4 2 2

output:

402
1
1
15
637
131
15
33
15
1

result:

ok 10 numbers

Test #21:

score: 8
Accepted
time: 1050ms
memory: 77404kb

input:

263454721
10
4 10 1
4 12 1
4 15 1
4 13 1
4 11 1
4 14 1
4 7 1
4 8 1
4 9 1
4 6 1

output:

4143
1172
15
402
2524
94
4077
5244
5273
2461

result:

ok 10 numbers

Test #22:

score: 8
Accepted
time: 1099ms
memory: 77644kb

input:

772538369
10
4 16 1
4 13 1
4 11 1
4 8 1
4 13 1
4 8 1
4 11 1
4 14 1
4 11 1
4 11 1

output:

0
402
2524
5244
402
5244
2524
94
2524
2524

result:

ok 10 numbers

Test #23:

score: 8
Accepted
time: 1055ms
memory: 77380kb

input:

536608769
10
4 12 1
4 7 1
4 12 1
4 15 1
4 15 1
4 5 1
4 3 1
4 3 1
4 5 1
4 5 1

output:

1172
4077
1172
15
15
1135
93
93
1135
1135

result:

ok 10 numbers

Test #24:

score: 8
Accepted
time: 1086ms
memory: 77552kb

input:

611844097
10
4 16 16
4 13 2
4 9 16
2 4 4
1 1 2
1 2 2
3 8 1
3 5 4
2 4 2
3 7 1

output:

1
33
0
1
0
1
0
2
0
7

result:

ok 10 numbers

Subtask #5:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 3
Accepted
time: 1070ms
memory: 77644kb

input:

444334081
10
5 30 11
5 3 5
5 17 28
5 9 31
5 26 13
5 30 24
5 20 20
5 6 23
5 32 21
5 27 19

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #26:

score: 3
Accepted
time: 1080ms
memory: 77576kb

input:

199229441
10
5 30 4
4 11 8
5 4 2
5 25 2
5 25 16
4 14 1
5 27 2
5 11 4
5 22 1
5 15 4

output:

7
20
378
217076
2002
94
10754
657800
37584676
7727792

result:

ok 10 numbers

Test #27:

score: 3
Accepted
time: 1108ms
memory: 77444kb

input:

347078657
10
5 24 2
5 14 2
5 10 1
5 14 1
5 9 4
5 17 16
5 24 8
5 29 8
5 19 1
5 18 1

output:

721828
31901421
16800255
168965000
65780
14
74615
34
171017538
218803879

result:

ok 10 numbers

Test #28:

score: 3
Accepted
time: 1082ms
memory: 77340kb

input:

444334081
10
5 31 1
5 28 1
5 24 1
5 30 1
5 23 1
5 26 1
5 29 1
5 25 1
5 27 1
5 22 1

output:

31
28767
6821585
439
17247943
652697
4186
2300857
152825
37584676

result:

ok 10 numbers

Test #29:

score: 3
Accepted
time: 1085ms
memory: 77424kb

input:

561774593
10
5 25 1
5 19 1
5 20 1
5 30 1
5 23 1
5 18 1
5 27 1
5 16 1
5 28 1
5 18 1

output:

2300857
171017538
117726724
439
17247943
218803879
152825
246451240
28767
218803879

result:

ok 10 numbers

Test #30:

score: 3
Accepted
time: 1098ms
memory: 77324kb

input:

329515009
10
5 4 1
5 32 1
5 10 1
5 25 1
5 4 1
5 4 1
5 18 1
5 14 1
5 21 1
5 32 1

output:

4116
0
16800255
2300857
4116
4116
218803879
168965000
71150929
0

result:

ok 10 numbers

Test #31:

score: 3
Accepted
time: 1065ms
memory: 77400kb

input:

167772161
10
3 3 2
4 2 1
2 3 4
3 6 1
3 1 4
1 2 2
3 6 1
3 8 8
5 13 32
1 1 2

output:

4
14
0
17
0
1
17
1
0
0

result:

ok 10 numbers

Subtask #6:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #32:

score: 3
Accepted
time: 1107ms
memory: 77444kb

input:

104857601
100000
4 3 1
5 4 29
5 5 28
4 11 12
5 14 23
5 30 28
5 24 19
4 8 15
4 11 12
4 3 4
5 21 7
5 5 29
5 5 4
5 5 2
5 3 30
5 1 4
5 5 4
5 20 4
5 7 17
5 18 13
5 6 8
5 10 14
4 3 8
5 22 14
4 9 13
5 22 13
5 13 20
5 23 24
5 16 20
4 14 6
5 13 9
5 17 25
4 16 14
4 5 8
5 32 10
5 31 16
5 4 8
5 1 8
5 27 3
4 8 3...

output:

93
0
0
0
0
0
0
0
0
0
0
0
26
3276
0
0
26
5399253
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
904
0
0
0
0
0
0
0
0
0
1658
439
0
0
0
4388
0
0
0
0
0
0
0
0
0
0
0
0
0
5312041
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5273
0
0
0
0
69710060
0
0
12869123
0
0
0
0
0
0
3276
0
33
0
705432
657800
0
0
0
0
0
0
721828
...

result:

ok 100000 numbers

Test #33:

score: 3
Accepted
time: 1109ms
memory: 77340kb

input:

36175873
100000
5 10 16
5 32 32
5 15 21
5 21 4
5 14 10
5 28 27
5 25 10
5 3 17
5 14 20
5 32 10
5 7 13
5 26 7
4 2 9
4 3 10
5 24 14
5 17 13
5 9 21
5 7 24
3 6 2
5 15 7
5 26 30
5 29 5
5 12 4
4 7 6
5 8 2
5 5 18
5 2 27
5 17 20
5 14 26
5 6 15
5 13 11
5 14 13
5 5 7
5 12 2
5 28 12
5 26 9
3 8 5
5 22 6
5 11 1
5...

output:

0
1
0
3221809
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
0
1562277
0
377292
0
0
0
0
0
0
0
0
13392663
0
0
0
0
525005
0
0
0
0
0
0
0
0
0
0
721828
0
0
980
0
0
497420
0
4794844
91
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3124586
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1408803
0
0
0
6821585
0
0
0
0
0
0
0
0
0
0
0
0
26346
969482...

result:

ok 100000 numbers

Test #34:

score: 3
Accepted
time: 1099ms
memory: 77436kb

input:

980156417
100000
5 21 26
4 6 8
4 6 9
4 8 6
4 1 7
4 12 1
5 27 2
5 27 9
4 16 1
5 24 27
5 5 29
5 7 9
5 30 22
4 8 16
4 3 1
5 2 1
5 7 3
5 7 17
5 1 5
5 27 1
5 23 27
5 18 3
5 30 23
5 23 24
5 25 7
5 12 21
5 31 16
5 27 2
4 2 13
5 30 5
4 14 15
5 16 21
5 18 15
5 7 3
2 1 2
5 1 1
4 7 8
5 25 17
5 30 26
4 9 5
5 26...

output:

0
0
0
0
0
1172
10754
0
0
0
0
0
0
0
93
30
0
0
0
152825
0
0
0
0
0
0
0
10754
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
217199841
0
0
0
4
0
0
0
65780
0
0
20477
0
0
364
0
0
1
497420
0
0
0
0
0
0
0
0
0
0
0
0
0
20477
0
0
0
0
0
0
0
79
0
0
9694828
0
0
0
0
0
0
0
0
0
79
7315
0
0
0
0
3221809
0
0
0
1
0
0
0
0
0
...

result:

ok 100000 numbers

Subtask #7:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #35:

score: 3
Accepted
time: 1063ms
memory: 77440kb

input:

605028353
10
6 55 51
6 58 47
6 12 17
6 54 25
6 54 37
6 48 35
6 48 43
6 48 19
6 31 27
6 17 2

output:

0
0
0
0
0
0
0
0
0
376489392

result:

ok 10 numbers

Test #36:

score: 3
Accepted
time: 1075ms
memory: 77324kb

input:

206307329
10
4 3 2
6 21 16
5 11 1
4 9 4
6 57 16
6 35 16
5 5 4
4 6 4
6 23 2
6 2 2

output:

12
1370754
36700878
252
1374758
42295216
26
45
109394043
1

result:

ok 10 numbers

Test #37:

score: 3
Accepted
time: 1093ms
memory: 77404kb

input:

875298817
10
6 58 32
6 17 16
6 42 1
6 52 8
6 34 16
6 16 8
6 53 8
6 44 8
6 59 32
6 3 1

output:

27405
46
433414087
368754382
490908090
165166973
392867548
767382538
4060
1893

result:

ok 10 numbers

Test #38:

score: 3
Accepted
time: 1079ms
memory: 77392kb

input:

605028353
10
6 62 1
6 54 1
6 60 1
6 55 1
6 61 1
6 63 1
6 56 1
6 57 1
6 59 1
6 58 1

output:

1896
370890940
566688
346008829
38193
63
525234207
511521913
6619392
63383108

result:

ok 10 numbers

Test #39:

score: 3
Accepted
time: 1067ms
memory: 77424kb

input:

167772161
10
6 46 1
6 41 1
6 40 1
6 37 1
6 40 1
6 57 1
6 33 1
6 33 1
6 39 1
6 44 1

output:

135666587
68402026
62808346
33127970
62808346
8205430
112595466
112595466
81966335
93400264

result:

ok 10 numbers

Test #40:

score: 3
Accepted
time: 1074ms
memory: 77640kb

input:

69206017
10
6 19 1
6 45 1
6 37 1
6 37 1
6 46 1
6 17 1
6 55 1
6 22 1
6 30 1
6 11 1

output:

10417366
54228612
22067610
22067610
5649932
38234650
68135914
31694638
3293939
46648038

result:

ok 10 numbers

Test #41:

score: 3
Accepted
time: 1075ms
memory: 77336kb

input:

568066049
10
5 29 32
3 4 8
5 18 1
5 11 32
4 2 2
4 2 16
2 3 1
1 1 2
6 47 64
3 1 8

output:

0
0
218803879
0
1
0
3
0
0
0

result:

ok 10 numbers

Subtask #8:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #42:

score: 3
Accepted
time: 1081ms
memory: 77644kb

input:

383778817
100000
6 58 4
6 56 19
4 7 9
6 49 39
5 28 1
6 45 39
6 14 37
6 49 27
6 20 16
6 54 3
6 50 32
6 33 16
5 9 1
6 5 28
6 34 4
5 28 19
6 21 10
6 21 35
6 62 30
6 58 37
6 28 18
2 4 1
6 58 43
5 1 23
6 6 51
6 30 17
6 48 42
6 47 30
6 25 53
4 2 9
6 40 17
5 7 9
6 8 35
6 4 54
4 2 11
6 15 2
6 52 49
6 43 15
...

output:

1171696
0
0
0
28767
0
0
0
163185
0
86493225
47400157
6634835
0
177603276
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
238725430
0
0
0
0
0
356274786
34220
0
0
0
0
1
0
0
0
0
246451240
0
0
0
0
0
0
49034390
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
238318...

result:

ok 100000 numbers

Test #43:

score: 3
Accepted
time: 1097ms
memory: 77384kb

input:

302252033
100000
6 7 16
6 14 5
4 7 15
6 53 31
6 18 64
6 18 21
6 49 16
6 47 33
6 51 17
5 4 19
6 11 38
6 44 45
6 9 5
6 15 35
4 9 11
6 8 63
5 32 15
6 58 17
6 53 14
6 5 53
6 17 3
6 21 19
5 12 8
6 34 51
6 20 5
6 19 9
5 26 24
6 41 37
5 23 9
6 28 56
6 7 49
6 39 43
5 32 8
6 29 8
6 58 31
6 3 11
6 60 47
6 35 ...

output:

0
0
0
0
0
0
209547730
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7315
0
0
0
0
0
0
0
0
0
0
68360890
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
228107848
0
0
0
0
0
0
0
0
0
0
0
0
0
0
289817379
0
41277404
0
0
0
0
0
0
0
0
0
0
0
0
149109
0
0
0
0
0
0
0
0
0
0
0
301045919
0
0
0
0
0
0
1893
0...

result:

ok 100000 numbers

Test #44:

score: 3
Accepted
time: 1090ms
memory: 77324kb

input:

234356737
100000
6 31 17
5 13 21
6 8 25
6 13 6
5 16 10
3 7 1
5 22 1
6 9 24
2 2 1
5 24 11
6 2 20
6 54 56
6 11 55
6 62 41
6 44 13
6 50 15
5 31 11
6 3 35
6 34 1
5 22 29
6 40 60
6 52 45
6 35 44
5 24 2
5 8 1
5 22 10
6 2 4
6 55 16
6 61 59
6 23 5
6 42 56
5 27 8
5 18 12
6 19 9
6 55 61
6 39 5
6 40 47
5 10 13...

output:

0
0
0
0
0
7
37584676
0
2
0
0
0
0
0
0
0
0
0
208610490
0
0
0
0
721828
2237332
0
0
53531544
0
0
0
1580
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
36323545
0
0
0
0
0
0
0
0
0
0
12704252
0
0
0
0
0
0
0
0
0
30856
0
0
43996282
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
165532995
0
0
0
0
0
0
0
0
0
0
0
0
48492634
0
0
0
904
0
0
0
...

result:

ok 100000 numbers

Subtask #9:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Test #45:

score: 3
Accepted
time: 1075ms
memory: 77372kb

input:

748158977
10
7 112 28
7 81 120
7 103 69
7 3 115
7 83 61
7 34 111
7 12 3
7 26 80
7 125 66
7 102 81

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #46:

score: 3
Accepted
time: 1079ms
memory: 77560kb

input:

103284737
10
7 87 2
6 35 16
7 123 32
4 4 1
6 39 32
6 21 8
7 126 8
6 16 16
5 9 1
6 14 2

output:

62775825
31265083
142164
388
2035800
34158907
15
1
6634835
6764241

result:

ok 10 numbers

Test #47:

score: 3
Accepted
time: 1083ms
memory: 77340kb

input:

340000769
10
7 24 8
7 40 1
7 103 4
7 116 4
7 99 8
7 125 8
7 11 1
7 99 2
7 19 16
7 75 4

output:

182921195
204633926
18389275
180060849
50998419
800
45294489
49350516
215820
45786976

result:

ok 10 numbers

Test #48:

score: 3
Accepted
time: 1093ms
memory: 77428kb

input:

748158977
10
7 122 1
7 118 1
7 120 1
7 119 1
7 125 1
7 127 1
7 126 1
7 124 1
7 121 1
7 123 1

output:

486253792
33593217
54405428
397386111
326535
127
7881
10060804
248185140
246054291

result:

ok 10 numbers

Test #49:

score: 3
Accepted
time: 1102ms
memory: 77568kb

input:

204472321
10
7 111 1
7 106 1
7 94 1
7 91 1
7 94 1
7 121 1
7 72 1
7 104 1
7 87 1
7 67 1

output:

125376307
28752045
100470324
39349265
100470324
68878340
197007194
145336025
26551847
37666762

result:

ok 10 numbers

Test #50:

score: 3
Accepted
time: 1066ms
memory: 77336kb

input:

621281281
10
7 49 1
7 85 1
7 28 1
7 78 1
7 125 1
7 88 1
7 101 1
7 96 1
7 49 1
7 48 1

output:

533812042
453709831
215932390
247876328
326535
19728581
618236608
321774803
533812042
76576609

result:

ok 10 numbers

Test #51:

score: 3
Accepted
time: 1061ms
memory: 77376kb

input:

261881857
10
1 1 2
3 4 1
3 3 8
6 12 1
2 3 2
4 2 16
3 8 8
7 25 1
3 6 8
3 6 8

output:

0
28
0
246960085
0
0
1
66865912
0
0

result:

ok 10 numbers

Subtask #10:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #52:

score: 3
Accepted
time: 1100ms
memory: 77340kb

input:

687603713
100000
7 83 44
6 34 53
7 41 22
7 105 59
7 62 25
7 59 101
7 88 122
7 113 82
7 8 112
7 83 70
7 24 58
7 65 76
7 79 50
7 67 11
7 62 24
5 17 12
7 38 19
7 12 112
1 1 2
6 9 37
6 27 48
5 16 3
7 59 80
6 25 10
7 15 7
7 102 92
6 36 47
7 112 73
7 47 96
7 96 38
7 15 14
7 98 8
7 78 81
7 24 82
7 1 76
5 2...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
645219654
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
346083593
0
...

result:

ok 100000 numbers

Test #53:

score: 3
Accepted
time: 1095ms
memory: 77572kb

input:

626262017
100000
7 60 33
7 79 69
6 42 6
7 74 94
6 48 4
6 60 38
7 17 111
5 24 25
7 50 30
7 52 96
7 102 103
7 68 14
6 20 46
7 98 52
7 76 7
7 110 105
7 51 61
7 85 78
6 54 42
7 18 69
7 74 19
6 56 49
7 20 82
7 128 125
7 61 26
7 87 40
7 85 3
6 10 2
7 26 11
5 23 6
7 68 54
6 21 62
7 119 82
7 123 90
7 90 96
...

output:

0
0
0
0
183601470
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
54307359
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
74333832
0
0
0
0
44105364
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1171696
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
147760313
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 numbers

Test #54:

score: 3
Accepted
time: 1093ms
memory: 77424kb

input:

555220993
100000
6 5 62
7 26 5
6 56 33
7 29 101
5 1 26
7 113 51
7 124 61
7 84 103
7 48 35
7 53 20
7 59 61
7 128 27
6 4 38
7 115 56
7 75 12
7 47 44
7 27 103
7 93 36
5 20 28
6 38 22
6 63 29
6 28 52
7 62 73
7 73 63
5 18 29
7 75 2
7 123 82
7 53 52
7 38 59
7 13 112
7 36 24
7 86 103
5 25 30
7 10 75
7 93 2...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
254342298
0
0
0
0
0
0
0
0
0
0
0
0
0
0
225809003
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
516269123
0
0
0
52989436
170544
0
0
0
14
0
0
0
0
0
0
0
15180
0
0
0
0
0
0
404306335
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
554181012
0...

result:

ok 100000 numbers

Subtask #11:

score: 2
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Test #55:

score: 2
Accepted
time: 1066ms
memory: 77512kb

input:

880803841
10
8 168 133
8 41 65
8 130 121
8 144 204
8 47 20
8 84 186
8 104 91
8 196 77
8 92 232
8 252 160

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #56:

score: 2
Accepted
time: 1081ms
memory: 77336kb

input:

111149057
10
7 87 64
7 68 32
7 116 8
8 47 1
8 103 1
8 173 32
6 36 2
8 241 16
8 89 8
5 22 2

output:

23472580
17773574
110247822
59889865
103988871
8790117
72242044
2913366
35609687
4794844

result:

ok 10 numbers

Test #57:

score: 2
Accepted
time: 1096ms
memory: 77404kb

input:

769130497
10
8 38 4
8 147 4
8 18 2
8 141 4
8 225 8
8 214 8
8 184 32
8 153 1
8 161 16
8 213 8

output:

343286308
350334162
724357620
27051973
751262219
299452958
302733849
744519580
19980772
560746783

result:

ok 10 numbers

Test #58:

score: 2
Accepted
time: 1080ms
memory: 77328kb

input:

880803841
10
8 254 1
8 246 1
8 247 1
8 253 1
8 250 1
8 248 1
8 249 1
8 255 1
8 252 1
8 251 1

output:

32138
806704367
244697613
2701756
279493682
703744397
513188328
255
169646196
561657944

result:

ok 10 numbers

Test #59:

score: 2
Accepted
time: 1067ms
memory: 77568kb

input:

690749441
10
8 130 1
8 219 1
8 148 1
8 212 1
8 200 1
8 251 1
8 157 1
8 130 1
8 141 1
8 207 1

output:

361080833
553642606
290950783
14674871
609262424
199899221
248399546
361080833
563405500
486293195

result:

ok 10 numbers

Test #60:

score: 2
Accepted
time: 1076ms
memory: 77392kb

input:

881590273
10
8 83 1
8 28 1
8 199 1
8 136 1
8 146 1
8 163 1
8 84 1
8 231 1
8 147 1
8 129 1

output:

711405973
332120484
535613738
406040708
733602900
398880089
41736405
97809176
834833596
428990665

result:

ok 10 numbers

Test #61:

score: 2
Accepted
time: 1068ms
memory: 77428kb

input:

758906881
10
8 54 16
5 28 32
6 12 2
4 14 1
5 21 32
6 41 64
1 1 2
2 2 4
4 10 4
7 16 128

output:

741311789
0
327185820
94
0
0
0
0
210
0

result:

ok 10 numbers

Subtask #12:

score: 2
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Test #62:

score: 2
Accepted
time: 1076ms
memory: 77560kb

input:

69206017
100000
7 127 9
8 172 173
8 230 29
8 108 95
8 207 34
8 147 131
8 80 205
7 82 26
8 132 4
8 234 210
8 79 68
8 8 39
8 237 223
8 113 99
8 160 203
5 10 31
8 7 137
8 76 104
6 34 35
7 109 13
6 43 37
8 211 216
8 183 105
8 44 106
8 230 210
8 188 126
8 100 19
6 20 38
8 74 119
7 24 99
8 105 233
8 198 9...

output:

0
0
0
0
0
0
0
0
68501522
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
19032062
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
64604732
0
0
0
0
0
0
6
49948712
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8844286
0
...

result:

ok 100000 numbers

Test #63:

score: 2
Accepted
time: 1111ms
memory: 77640kb

input:

10223617
100000
8 94 165
7 5 67
8 178 187
8 34 143
8 205 26
8 45 125
7 100 118
6 2 45
8 214 155
8 46 245
8 14 215
8 212 155
8 149 34
8 210 194
6 47 50
7 27 111
8 24 245
8 113 42
7 44 33
7 11 89
8 29 18
7 109 126
8 201 86
8 99 37
7 35 21
7 9 38
8 27 9
8 237 227
8 144 9
8 148 192
5 17 26
8 6 210
7 56 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1033125
0
5844323
4258748
0
0
0
0
0
0
0
9454279
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #64:

score: 2
Accepted
time: 1095ms
memory: 77560kb

input:

946339841
100000
8 147 206
8 113 50
8 81 37
8 251 17
7 14 31
8 149 231
8 4 90
8 246 200
8 10 63
8 205 190
8 198 33
8 32 125
8 130 103
8 62 200
8 230 228
8 11 162
8 189 123
6 32 51
6 59 43
8 145 179
8 46 228
8 231 207
8 6 76
8 78 209
8 106 25
7 58 97
5 21 3
8 147 159
8 25 122
8 135 115
8 227 115
8 87...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
582237607
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
523427708
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
351330860
0
0
0
0
0
221663770
0
0
0
0
0
0
1
0
812885755
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
696153612
...

result:

ok 100000 numbers

Subtask #13:

score: 2
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Test #65:

score: 2
Accepted
time: 1064ms
memory: 77572kb

input:

899678209
10
9 97 237
9 384 139
9 157 429
9 413 38
9 139 364
9 6 6
9 324 178
9 238 329
9 58 398
9 17 111

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #66:

score: 2
Accepted
time: 1059ms
memory: 77512kb

input:

114032641
10
8 156 1
9 417 8
7 77 2
7 115 1
9 66 4
7 10 4
9 449 1
9 102 1
9 129 64
8 100 16

output:

4659919
88851396
39156860
101244
84773084
50973643
79311619
35756927
65200813
110140772

result:

ok 10 numbers

Test #67:

score: 2
Accepted
time: 1075ms
memory: 77344kb

input:

218628097
10
9 139 128
9 461 256
9 447 256
9 42 16
9 404 2
9 119 64
9 408 8
9 3 2
9 194 8
9 186 4

output:

136508010
58740035
12919024
114240252
109030378
10131145
44231491
508
4912286
151334888

result:

ok 10 numbers

Test #68:

score: 2
Accepted
time: 1100ms
memory: 77432kb

input:

899678209
10
9 507 1
9 503 1
9 506 1
9 502 1
9 510 1
9 508 1
9 509 1
9 511 1
9 504 1
9 505 1

output:

546006123
695483672
895927972
200456093
129803
88249358
21985712
511
616584338
572298238

result:

ok 10 numbers

Test #69:

score: 2
Accepted
time: 1077ms
memory: 77388kb

input:

167772161
10
9 315 1
9 284 1
9 487 1
9 283 1
9 357 1
9 292 1
9 343 1
9 317 1
9 397 1
9 305 1

output:

63180067
81224457
121353371
6495501
92016773
119533
84481372
66626245
21845292
139479670

result:

ok 10 numbers

Test #70:

score: 2
Accepted
time: 1079ms
memory: 77328kb

input:

85196801
10
9 111 1
9 111 1
9 39 1
9 414 1
9 99 1
9 355 1
9 293 1
9 272 1
9 398 1
9 29 1

output:

59820348
59820348
34379401
6995552
81312980
1127172
1307825
54705589
79073111
21432708

result:

ok 10 numbers

Test #71:

score: 2
Accepted
time: 1082ms
memory: 77436kb

input:

10223617
10
5 11 32
8 154 256
1 2 2
4 12 16
8 250 256
6 52 64
1 1 2
7 47 4
9 21 128
2 2 4

output:

0
0
1
0
0
0
0
8197277
0
0

result:

ok 10 numbers

Subtask #14:

score: 2
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Test #72:

score: 2
Accepted
time: 1092ms
memory: 77348kb

input:

526123009
100000
9 274 400
9 295 277
9 155 10
9 465 434
9 292 287
9 190 362
9 207 263
9 237 409
9 394 16
9 184 245
9 445 304
9 289 435
9 312 201
9 350 504
9 92 443
9 167 130
9 392 176
9 63 408
9 198 420
9 449 47
9 439 436
9 430 350
9 444 296
9 51 4
9 102 451
9 63 184
9 33 330
9 198 497
9 284 83
9 79...

output:

0
0
0
0
0
0
0
0
148470368
0
0
0
0
0
0
0
0
0
0
0
0
0
0
468160339
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
261108642
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
449498417
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #73:

score: 2
Accepted
time: 1101ms
memory: 77572kb

input:

569638913
100000
9 142 2
9 273 2
8 44 4
8 225 128
9 120 2
9 344 4
9 67 2
9 338 16
9 375 64
9 148 64
9 296 64
9 501 16
8 155 2
9 335 128
7 102 32
9 497 16
8 145 128
8 244 64
9 502 64
8 243 128
9 87 32
8 105 8
9 223 64
9 113 4
9 468 64
9 422 256
9 283 256
9 21 16
7 84 4
9 87 4
7 24 1
9 360 256
9 484 6...

output:

291661186
41649301
2615919
524573396
391324505
187363414
432977478
306132068
455365558
551420152
374797291
400851886
330862599
59415334
447250969
284371981
137184279
349853278
548001522
70583238
366555216
443843324
342337635
232923128
22033576
294525647
8395200
416473725
305568230
52989290
173100903...

result:

ok 100000 numbers

Test #74:

score: 2
Accepted
time: 1082ms
memory: 77344kb

input:

872153089
100000
9 367 1
9 487 1
9 328 1
9 359 1
9 438 1
9 421 1
9 372 1
9 497 1
9 464 1
9 492 1
9 476 1
9 322 1
9 460 1
9 473 1
9 338 1
9 410 1
9 338 1
9 376 1
9 343 1
9 327 1
9 265 1
9 377 1
9 352 1
9 261 1
9 373 1
9 265 1
9 470 1
9 392 1
9 271 1
9 492 1
9 330 1
9 406 1
9 345 1
9 406 1
9 414 1
9 3...

output:

722342015
455321612
811811396
156853028
504452208
737818612
476289405
215467544
163935553
343218277
543789329
813898988
731651175
545116215
673560475
428531985
673560475
813865627
300351859
381435156
381447886
669193089
548560066
798732509
139232299
381447886
722194125
150624509
387375566
343218277
...

result:

ok 100000 numbers

Test #75:

score: 2
Accepted
time: 1068ms
memory: 77340kb

input:

234356737
100000
9 164 1
9 322 1
9 367 1
9 63 1
9 427 1
9 380 1
9 495 1
9 49 1
9 6 1
9 307 1
9 138 1
9 425 1
9 449 1
9 269 1
9 440 1
9 102 1
9 415 1
9 196 1
9 100 1
9 252 1
9 146 1
9 166 1
9 364 1
9 84 1
9 325 1
9 276 1
9 291 1
9 297 1
9 404 1
9 5 1
9 208 1
9 395 1
9 16 1
9 131 1
9 46 1
9 93 1
9 382...

output:

207714867
48620493
8591762
112253028
212020686
76971727
106432409
109339045
34244114
106089885
116481769
213009210
220002681
56165942
221510187
199028135
77390792
88406485
202190153
190803559
81872691
232458181
204555545
34246566
199647838
153156772
113678056
37255109
142498769
208123536
130921102
1...

result:

ok 100000 numbers

Test #76:

score: 2
Accepted
time: 1094ms
memory: 77328kb

input:

163577857
100000
3 8 8
5 13 16
3 1 8
7 110 64
1 1 2
2 1 4
1 2 2
1 2 2
3 5 8
6 59 8
2 2 4
4 5 16
9 119 32
5 27 32
9 57 4
6 52 2
4 9 16
1 1 2
7 36 8
4 4 8
7 83 4
9 371 1
1 1 1
7 5 8
9 134 64
1 2 2
1 2 2
6 39 1
1 2 2
5 29 32
6 43 64
6 63 1
9 472 512
1 1 2
1 2 2
4 7 16
8 79 128
8 103 16
5 7 32
8 29 16
1...

output:

1
0
0
91552054
0
0
1
1
0
43486
0
0
21242993
0
49742838
38855806
0
0
62847862
0
127564719
62768539
1
0
35065236
1
1
63379444
1
0
0
63
0
0
1
0
0
41155660
0
22117359
0
127791314
0
153969374
1
27405
31
118420421
0
0
117555081
128636519
0
0
88035393
85194243
0
0
0
10393881
0
0
0
267694
0
0
0
10417736
914...

result:

ok 100000 numbers

Subtask #15:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Test #77:

score: 3
Accepted
time: 1083ms
memory: 77404kb

input:

475267073
10
10 988 319
10 412 311
10 318 840
10 553 372
10 222 865
10 866 873
10 287 535
10 756 175
10 418 656
10 992 647

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #78:

score: 3
Accepted
time: 1069ms
memory: 77564kb

input:

824442881
10
10 914 512
9 41 2
10 695 4
10 737 32
8 93 4
6 35 2
10 740 32
8 222 32
8 139 2
9 388 1

output:

290391973
141730001
628582967
705723764
482429991
711394598
289810078
298688080
339223503
690582952

result:

ok 10 numbers

Test #79:

score: 3
Accepted
time: 1087ms
memory: 77444kb

input:

239337473
10
10 865 1
10 405 128
10 84 1
10 610 64
10 62 2
10 325 8
10 104 32
10 871 512
10 961 8
10 633 256

output:

77409514
112901472
144643385
225692406
216872621
42936257
200079361
32738217
90836854
207861769

result:

ok 10 numbers

Test #80:

score: 3
Accepted
time: 1079ms
memory: 77568kb

input:

475267073
10
10 1014 1
10 1021 1
10 1019 1
10 1017 1
10 1018 1
10 1016 1
10 1023 1
10 1022 1
10 1015 1
10 1020 1

output:

197538729
177406371
348770442
180756207
387228810
192317796
1023
521740
333158307
46991005

result:

ok 10 numbers

Test #81:

score: 3
Accepted
time: 1095ms
memory: 77404kb

input:

442761217
10
10 1015 1
10 842 1
10 688 1
10 787 1
10 679 1
10 747 1
10 706 1
10 614 1
10 684 1
10 995 1

output:

43969984
362362126
197545970
441920728
157631339
341551874
325197279
241970392
226250777
138601206

result:

ok 10 numbers

Test #82:

score: 3
Accepted
time: 1086ms
memory: 77436kb

input:

704905217
10
10 70 1
10 49 1
10 586 1
10 627 1
10 762 1
10 340 1
10 15 1
10 32 1
10 727 1
10 797 1

output:

652068509
468731102
617806712
537661872
609655957
345882127
75341968
267995213
181336646
337293204

result:

ok 10 numbers

Test #83:

score: 3
Accepted
time: 1082ms
memory: 77448kb

input:

29884417
10
4 15 16
6 51 64
9 204 128
1 2 2
1 2 2
9 205 4
3 2 8
4 16 16
4 6 2
5 13 32

output:

0
0
17913132
1
1
20374785
0
1
497
0

result:

ok 10 numbers

Subtask #16:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Test #84:

score: 3
Accepted
time: 1089ms
memory: 77508kb

input:

985661441
100000
10 780 658
10 453 421
10 1019 400
10 289 387
10 561 940
10 142 358
10 221 234
10 546 141
10 720 754
10 136 191
10 184 939
10 863 10
10 667 281
10 212 444
10 151 627
10 131 674
10 729 648
10 907 128
10 219 852
10 496 209
10 994 734
10 309 705
10 184 342
10 58 103
10 166 108
10 83 840...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
252311200
0
0
0
0
0
0
0
0
0
913046257
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
634819606
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
661699721
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #85:

score: 3
Accepted
time: 1078ms
memory: 77336kb

input:

710934529
100000
10 136 1
5 17 2
10 582 512
7 90 16
8 63 2
7 120 32
8 181 2
10 646 256
9 329 256
10 143 64
10 657 1
5 9 4
10 137 1
10 948 256
10 815 8
10 74 2
10 619 4
10 249 128
9 317 256
10 601 512
9 195 64
10 607 1
10 505 16
10 231 2
10 253 2
9 76 16
9 419 8
10 46 2
10 795 512
8 210 8
10 859 4
10...

output:

219301879
42564036
47943247
480732282
499966150
104469788
612981717
576203878
315007387
619021953
588757775
65780
455373106
117421889
8975685
78617761
582298638
428335996
482506046
668437203
596771798
511327429
601595914
684015725
191393526
296947849
262694822
498637376
283049299
266962434
705839984...

result:

ok 100000 numbers

Test #86:

score: 3
Accepted
time: 1079ms
memory: 77572kb

input:

468713473
100000
10 531 1
10 914 1
10 777 1
10 955 1
10 894 1
10 873 1
10 818 1
10 886 1
10 962 1
10 559 1
10 1010 1
10 1024 1
10 533 1
10 834 1
10 571 1
10 810 1
10 922 1
10 815 1
10 872 1
10 747 1
10 715 1
10 851 1
10 815 1
10 730 1
10 890 1
10 868 1
10 786 1
10 861 1
10 703 1
10 831 1
10 680 1
10...

output:

239097246
68348807
362612246
179598872
111092297
356794622
241307200
157605183
122768583
79990496
14038698
0
467672274
278982116
320968817
298471326
7301191
447940125
157447345
404357176
415045861
132721266
447940125
268508620
432351925
272522952
49524356
344948345
379429339
96920809
36667288
132721...

result:

ok 100000 numbers

Test #87:

score: 3
Accepted
time: 1105ms
memory: 77340kb

input:

10223617
100000
10 792 1
10 317 1
10 632 1
10 456 1
10 130 1
10 416 1
10 464 1
10 493 1
10 180 1
10 465 1
10 915 1
10 490 1
10 129 1
10 779 1
10 542 1
10 54 1
10 433 1
10 990 1
10 643 1
10 91 1
10 637 1
10 942 1
10 5 1
10 630 1
10 277 1
10 562 1
10 926 1
10 697 1
10 796 1
10 759 1
10 891 1
10 234 1
...

output:

5940329
2734338
154237
2472425
8504878
8944137
822843
9501293
3608706
5398333
9801876
2373890
7088979
2256577
4744477
1021316
2949167
5997071
1596167
2822304
2708281
5472710
2382807
3118276
8984679
8495519
8673550
2040531
150105
9488143
3732747
8401708
9816515
6997946
6409716
1060465
2614650
6735885...

result:

ok 100000 numbers

Test #88:

score: 3
Accepted
time: 1071ms
memory: 77640kb

input:

336855041
100000
3 1 8
5 30 32
4 10 16
10 229 128
5 32 8
2 1 4
7 115 128
2 1 4
8 115 4
7 97 2
7 92 128
10 144 128
1 1 2
2 3 4
8 15 64
9 373 256
6 43 4
9 240 32
2 2 4
1 2 2
6 44 64
2 2 2
1 2 2
3 7 2
10 266 256
5 6 32
7 103 2
10 727 4
8 31 64
4 14 16
1 2 2
1 1 2
7 5 16
8 62 256
6 23 64
9 394 64
4 14 2...

output:

0
0
0
28832998
0
0
0
0
18177949
271208710
0
227500234
0
0
0
48985450
87574052
94997262
0
1
0
1
1
0
102891032
0
127084739
161843681
0
0
1
0
0
0
0
22489039
7
261661092
301613149
202565880
0
0
27405
1
14
0
17
0
70719654
3274728
1
0
0
0
0
0
0
0
0
0
276380108
0
265110645
0
1
0
0
0
74293160
1374758
0
1827...

result:

ok 100000 numbers

Subtask #17:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Test #89:

score: 3
Accepted
time: 1074ms
memory: 77440kb

input:

638058497
10
11 917 936
11 756 129
11 1881 1148
11 55 718
11 58 1721
11 1300 1460
11 1019 878
11 1310 172
11 1664 1591
11 758 854

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #90:

score: 3
Accepted
time: 1069ms
memory: 77344kb

input:

829685761
10
10 854 128
8 156 1
10 1017 8
11 1577 1
11 560 512
10 912 512
10 340 2
11 1667 4
11 99 1
10 71 64

output:

482956117
359996694
660922958
463765272
291583021
170636728
806617857
264901841
652187955
558479401

result:

ok 10 numbers

Test #91:

score: 3
Accepted
time: 1071ms
memory: 77640kb

input:

793509889
10
11 58 4
11 877 8
11 2033 1
11 957 256
11 1001 8
11 1419 512
11 1383 16
11 1295 32
11 770 256
11 2044 1

output:

589928947
556764672
279517118
263635850
275548330
109790521
574523809
279297555
532367505
398871521

result:

ok 10 numbers

Test #92:

score: 3
Accepted
time: 1058ms
memory: 77572kb

input:

638058497
10
11 2041 1
11 2040 1
11 2038 1
11 2042 1
11 2045 1
11 2046 1
11 2044 1
11 2043 1
11 2039 1
11 2047 1

output:

624500742
130397793
333006592
150815298
149300115
2092045
22694657
117800145
471686369
2047

result:

ok 10 numbers

Test #93:

score: 3
Accepted
time: 1089ms
memory: 77516kb

input:

204472321
10
11 1225 1
11 1466 1
11 1894 1
11 1532 1
11 1755 1
11 1230 1
11 1385 1
11 1896 1
11 1492 1
11 1255 1

output:

136802553
162672251
192688359
131040106
182544728
144706992
115920356
143015342
181731606
23951185

result:

ok 10 numbers

Test #94:

score: 3
Accepted
time: 1069ms
memory: 77556kb

input:

40370177
10
11 824 1
11 1707 1
11 180 1
11 1713 1
11 1673 1
11 1771 1
11 185 1
11 25 1
11 2027 1
11 1176 1

output:

23029223
12717890
40235975
21265894
17058755
29098812
12481281
19438833
1030983
32876787

result:

ok 10 numbers

Test #95:

score: 3
Accepted
time: 1089ms
memory: 77348kb

input:

340000769
10
5 23 1
2 1 4
1 1 2
11 672 2048
4 7 16
5 13 16
5 22 32
8 224 32
1 1 2
8 147 8

output:

17247943
0
0
0
0
0
0
9284752
0
296406711

result:

ok 10 numbers

Subtask #18:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Test #96:

score: 3
Accepted
time: 1089ms
memory: 77432kb

input:

120324097
100000
11 1732 250
11 796 1262
11 534 708
11 814 733
11 397 772
11 576 1970
11 953 1602
11 1100 137
11 1966 1689
11 926 1422
11 565 702
11 1186 164
11 818 1873
11 2034 1111
11 1878 1636
11 1696 1797
11 518 330
11 1217 1608
11 907 162
11 1594 1702
11 1915 1699
11 463 892
11 1895 1962
11 164...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #97:

score: 3
Accepted
time: 1081ms
memory: 77508kb

input:

639631361
100000
11 1681 2
11 1752 128
11 584 1
10 955 32
11 1966 64
10 475 32
10 842 1
9 403 128
11 2045 2
8 213 1
11 1363 8
10 36 4
10 399 8
11 1660 32
11 1853 16
11 1645 16
9 499 256
11 543 64
10 780 16
10 318 8
11 67 1
11 611 16
10 602 128
11 983 512
9 443 16
11 528 512
11 1806 4
9 406 8
11 1998...

output:

232273813
529571653
294484455
301326489
54769642
596074577
267016526
398283536
1040396
452666982
457462177
152443463
455231878
409657607
538626859
394021583
624163932
198701207
29240454
92876034
587875436
577323620
603050507
510974792
602393047
296190251
159432272
84009959
599045097
472949191
529770...

result:

ok 100000 numbers

Test #98:

score: 3
Accepted
time: 1090ms
memory: 77340kb

input:

666894337
100000
11 1334 1
11 1143 1
11 1073 1
11 1546 1
11 1427 1
11 1197 1
11 1427 1
11 1781 1
11 1524 1
11 1644 1
11 1131 1
11 1554 1
11 1080 1
11 1498 1
11 1362 1
11 1105 1
11 1692 1
11 1975 1
11 1870 1
11 2041 1
11 1741 1
11 1751 1
11 1612 1
11 1783 1
11 1067 1
11 1371 1
11 1673 1
11 1581 1
11 ...

output:

602309711
653314864
416735106
48688413
527174284
323165242
527174284
107162337
300152626
510918958
314421549
60197695
319361241
285130158
428705079
392017699
619728671
93953576
417083791
195242743
213681225
566793604
45871716
415837816
598195888
436272626
568572184
151726559
321407041
106307338
4868...

result:

ok 100000 numbers

Test #99:

score: 3
Accepted
time: 1100ms
memory: 77404kb

input:

360972289
100000
11 522 1
11 950 1
11 1250 1
11 1542 1
11 1041 1
11 824 1
11 1658 1
11 1510 1
11 1480 1
11 1868 1
11 1845 1
11 438 1
11 663 1
11 1831 1
11 940 1
11 75 1
11 423 1
11 1952 1
11 251 1
11 1248 1
11 871 1
11 1202 1
11 579 1
11 145 1
11 1801 1
11 764 1
11 1575 1
11 991 1
11 4 1
11 322 1
11...

output:

82545332
327980891
46843871
3556798
312743003
335728850
123724972
195582960
19480228
199271037
240628173
217931722
293657967
282545087
41803981
31111995
54270737
116770678
265717936
339108859
87670884
236407056
151273707
13366085
169458879
256665213
336390277
69453661
342460401
338187433
70440090
14...

result:

ok 100000 numbers

Test #100:

score: 3
Accepted
time: 1094ms
memory: 77328kb

input:

820248577
100000
2 1 4
2 1 4
11 1291 1
11 501 8
4 15 16
4 10 16
4 7 16
5 13 32
6 11 16
11 1352 512
6 59 64
5 31 1
11 1080 64
4 14 16
5 16 32
4 3 16
9 490 16
10 542 1024
11 1154 4
11 648 2048
7 38 128
9 353 128
3 8 8
4 13 16
6 5 8
11 624 2
2 3 2
1 1 2
7 55 128
11 1738 1
1 2 2
7 64 128
4 12 16
8 98 2
...

output:

0
0
490156610
558743056
0
0
0
0
0
193247644
0
31
278542471
0
0
0
438634206
0
348265764
0
0
293441654
1
0
0
513612586
0
0
0
156986017
1
0
0
503184210
497420
0
0
1
0
142983584
0
379227628
0
0
0
0
0
225793766
0
1
0
279735617
0
1
361884680
0
0
3129359
15
211209622
0
696375984
0
744190052
0
0
0
360874108...

result:

ok 100000 numbers

Subtask #19:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Test #101:

score: 3
Accepted
time: 1065ms
memory: 77328kb

input:

790364161
10
12 846 2577
12 75 4042
12 1396 432
12 3652 2087
12 1942 3601
12 2758 4096
12 3799 2246
12 1864 2216
12 2911 2525
12 2572 37

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #102:

score: 3
Accepted
time: 1078ms
memory: 77340kb

input:

725876737
10
12 1236 16
10 613 64
12 2265 256
12 3478 1
11 235 32
11 256 8
12 2124 32
9 302 16
12 1020 512
12 3085 16

output:

566519420
238674449
210127689
187272084
477387437
683871240
230420727
395276711
405364299
394094654

result:

ok 10 numbers

Test #103:

score: 3
Accepted
time: 1074ms
memory: 77340kb

input:

132120577
10
12 2924 64
12 1497 1
12 1901 8
12 2339 2048
12 253 32
12 3925 64
12 3552 2
12 213 2
12 2161 1
12 3504 1

output:

85609535
119524581
47132959
44299876
116552257
53224509
49862120
84069547
131303993
71882172

result:

ok 10 numbers

Test #104:

score: 3
Accepted
time: 1057ms
memory: 77416kb

input:

790364161
10
12 4093 1
12 4090 1
12 4086 1
12 4094 1
12 4088 1
12 4089 1
12 4091 1
12 4087 1
12 4092 1
12 4095 1

output:

363106168
446279025
148351386
8378382
91848591
728935909
527343976
109646150
368525372
4095

result:

ok 10 numbers

Test #105:

score: 3
Accepted
time: 1079ms
memory: 77340kb

input:

93585409
10
12 3676 1
12 3786 1
12 3944 1
12 2171 1
12 3131 1
12 2697 1
12 2878 1
12 3635 1
12 2755 1
12 2519 1

output:

77146555
36033353
82329581
65938166
38453874
51474533
61653764
53179531
27990329
84823034

result:

ok 10 numbers

Test #106:

score: 3
Accepted
time: 1073ms
memory: 77368kb

input:

979107841
10
12 3328 1
12 1963 1
12 3087 1
12 2403 1
12 291 1
12 1290 1
12 1072 1
12 1619 1
12 2998 1
12 1312 1

output:

281588719
673862616
733612034
322332331
534255844
168369551
4282163
281295327
499375971
749307706

result:

ok 10 numbers

Test #107:

score: 3
Accepted
time: 1080ms
memory: 77552kb

input:

483655681
10
2 2 4
6 7 64
8 223 256
12 548 2
8 3 128
10 22 1024
5 6 32
7 65 128
2 4 4
2 3 4

output:

0
0
0
375902127
0
0
0
0
1
0

result:

ok 10 numbers

Subtask #20:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Test #108:

score: 3
Accepted
time: 1087ms
memory: 77444kb

input:

140771329
100000
12 1661 3939
12 115 1080
12 2097 2041
12 2363 2103
12 2281 603
12 2034 510
12 1685 922
12 3702 134
12 3213 575
12 691 2653
12 2994 465
12 1509 3391
12 1993 1418
12 1808 2802
12 1556 1621
12 3261 3943
12 2355 2059
12 503 3087
12 1594 2543
12 645 1147
12 3859 3688
12 617 2104
12 3606 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #109:

score: 3
Accepted
time: 1103ms
memory: 77436kb

input:

576716801
100000
12 364 1
11 1302 256
9 468 256
11 1552 1
12 848 4
11 632 512
12 3521 256
11 1564 64
11 1374 4
10 468 1
11 973 4
12 1113 64
12 3170 16
12 769 64
12 709 256
11 1837 4
8 193 32
12 2379 256
12 598 64
12 402 4
12 3420 2
10 932 2
12 981 256
12 3955 16
8 94 1
11 1765 1
12 2247 64
11 512 8
...

output:

111945729
161031778
147569371
90786851
314541921
403991046
57470010
450370132
31569376
233455140
322155353
91383188
187420406
197181124
511527647
465840878
55336543
473954466
36435453
274725756
169482206
207028833
129542174
165460264
356677863
3515247
325760563
566035845
385919994
137876626
13727500...

result:

ok 100000 numbers

Test #110:

score: 3
Accepted
time: 1091ms
memory: 77400kb

input:

549978113
100000
12 2616 1
12 3981 1
12 3012 1
12 2511 1
12 2746 1
12 2702 1
12 3746 1
12 3770 1
12 2499 1
12 3033 1
12 2803 1
12 3859 1
12 2775 1
12 2445 1
12 4052 1
12 2141 1
12 4089 1
12 2474 1
12 3961 1
12 3004 1
12 2301 1
12 3651 1
12 4038 1
12 2132 1
12 2833 1
12 2905 1
12 3629 1
12 4065 1
12 ...

output:

312275906
341901347
344266760
193485099
400441771
452193649
435037423
340855802
118543619
28809003
530011215
315975745
284717895
210998014
88165012
101057816
182135138
10644004
128515683
151403833
461488706
114313523
136673097
256615758
328038376
159267816
124276546
85708841
218619793
477269157
3601...

result:

ok 100000 numbers

Test #111:

score: 3
Accepted
time: 1084ms
memory: 77428kb

input:

416808961
100000
12 3026 1
12 1206 1
12 61 1
12 2232 1
12 3755 1
12 343 1
12 497 1
12 1056 1
12 2451 1
12 2005 1
12 3745 1
12 618 1
12 466 1
12 1600 1
12 3806 1
12 2720 1
12 289 1
12 2939 1
12 1390 1
12 3169 1
12 1328 1
12 2752 1
12 1735 1
12 2910 1
12 3874 1
12 3865 1
12 153 1
12 2781 1
12 782 1
12...

output:

325099009
232447977
162401735
215085705
141294146
377073363
86120789
277980279
321811916
292344429
405334202
204178635
80648529
321950393
326269091
345782700
242627864
227776448
5076294
283959597
148519935
378753768
259343615
17963611
368933622
161577308
80513890
336360853
209164555
305582905
278643...

result:

ok 100000 numbers

Test #112:

score: 3
Accepted
time: 1090ms
memory: 77376kb

input:

820510721
100000
1 2 2
11 402 512
4 13 8
5 25 8
6 11 32
3 2 8
4 7 16
5 14 32
2 1 2
12 572 8
11 228 64
7 86 2
2 3 2
10 860 2
7 54 32
3 2 8
10 749 1024
1 2 2
6 20 8
3 4 8
7 63 64
8 221 32
5 23 4
3 5 8
9 165 16
6 44 64
6 31 4
11 1423 16
5 17 8
11 1952 128
7 78 8
6 34 4
6 54 64
2 1 4
10 329 4
7 2 4
2 1 ...

output:

1
0
6
26346
0
0
0
0
0
414047771
628223800
656800125
0
360058408
189813416
0
0
1
33407392
0
0
653197370
721652
0
160434120
0
705174141
179794191
497420
95187639
689655885
484498580
0
0
663302528
0
0
583943392
0
519256580
69242822
0
83842854
613767792
0
0
4077
1
0
0
0
0
0
3
567748859
320019384
2161856...

result:

ok 100000 numbers

Subtask #21:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #19:

100%
Accepted

Test #113:

score: 3
Accepted
time: 1066ms
memory: 77432kb

input:

802160641
10
13 6919 121
13 3490 1811
13 7055 3813
13 7249 7553
13 7923 5480
13 4216 587
13 6579 1566
13 370 2213
13 6205 7556
13 2337 5364

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #114:

score: 3
Accepted
time: 1082ms
memory: 77388kb

input:

734527489
10
12 1357 64
13 3038 1
12 387 1
11 390 16
13 4903 1
13 2967 4
12 895 1
13 7327 2
12 1892 1024
12 1164 1

output:

1013453
419546429
495625874
698241927
533988127
253995943
330656175
150227480
393727973
566235116

result:

ok 10 numbers

Test #115:

score: 3
Accepted
time: 1085ms
memory: 77512kb

input:

660078593
10
13 7144 512
13 2962 4
13 6965 512
13 964 1
13 4727 128
13 3397 64
13 4538 32
13 5277 128
13 877 32
13 6187 1024

output:

38288330
43806552
657604241
159351899
318345122
294959954
504269787
418504903
171659804
587709797

result:

ok 10 numbers

Test #116:

score: 3
Accepted
time: 1052ms
memory: 77444kb

input:

802160641
10
13 8184 1
13 8188 1
13 8191 1
13 8189 1
13 8182 1
13 8187 1
13 8183 1
13 8185 1
13 8186 1
13 8190 1

output:

370478667
211490399
8191
79281924
470450840
83082935
681406104
343475553
37067739
33533967

result:

ok 10 numbers

Test #117:

score: 3
Accepted
time: 1068ms
memory: 77448kb

input:

888668161
10
13 5191 1
13 7571 1
13 5020 1
13 4180 1
13 5309 1
13 7155 1
13 4421 1
13 7253 1
13 7391 1
13 7710 1

output:

287833222
689391427
110676897
501388824
864606637
359853598
547966618
82894150
481397603
866698999

result:

ok 10 numbers

Test #118:

score: 3
Accepted
time: 1067ms
memory: 77328kb

input:

655360001
10
13 6919 1
13 7904 1
13 3250 1
13 3597 1
13 6527 1
13 7767 1
13 5430 1
13 5921 1
13 3847 1
13 6658 1

output:

179156259
529979790
71065623
37707882
390395888
280004611
372413757
437135804
334170517
457814262

result:

ok 10 numbers

Test #119:

score: 3
Accepted
time: 1081ms
memory: 77572kb

input:

93847553
10
11 722 2
12 1098 4
4 9 16
12 928 128
1 1 2
9 299 1
9 358 512
12 2357 8
3 1 8
9 212 16

output:

59572605
5816163
0
69293457
0
93827459
0
38146196
0
80265120

result:

ok 10 numbers

Subtask #22:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #20:

100%
Accepted

Dependency #21:

100%
Accepted

Test #120:

score: 3
Accepted
time: 1087ms
memory: 77440kb

input:

261881857
100000
13 7734 1484
13 7627 2945
13 7756 5421
13 5960 3472
13 4165 6579
13 7588 1097
13 4465 241
13 2208 4227
13 6507 1509
13 457 3884
13 7472 2276
13 3881 4569
13 1120 962
13 7726 4494
13 7379 1606
13 6874 1994
13 6240 1741
13 7981 6615
13 233 4925
13 1744 592
13 3755 3629
13 4867 1267
13...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
15565187
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 numbers

Test #121:

score: 3
Accepted
time: 1098ms
memory: 77328kb

input:

261881857
100000
13 3637 128
13 6865 4096
13 5041 64
13 580 64
13 701 512
13 3953 1024
13 5642 16
13 1698 2
13 6678 32
13 3761 4
13 5861 256
13 3447 128
13 7586 4
13 7958 4
13 5371 256
13 7199 1024
13 1163 512
13 1414 128
13 7260 512
13 4705 1
13 6886 64
13 6036 64
13 5069 2
13 7443 2
13 3810 8
13 1...

output:

119029375
38600885
40494020
10728006
224548679
234921883
71227660
168791097
34783930
184197086
168400192
82473149
144353863
197408064
74497586
139556259
139097061
159157870
58714421
248969452
120469766
250827619
196917704
254700030
147523714
190755388
140344421
214216900
116406919
159564094
6940187
...

result:

ok 100000 numbers

Test #122:

score: 3
Accepted
time: 1092ms
memory: 77436kb

input:

52166657
100000
12 1045 32
13 6582 1
11 1276 1024
13 3578 512
12 3890 16
13 6058 4
13 2862 2
12 2943 1024
11 1010 512
12 1471 8
10 736 32
13 3229 4
12 2986 2048
12 153 1
12 1160 16
13 7918 64
13 2561 8
11 1435 16
12 1037 512
12 3879 4
11 540 2
12 3341 8
13 4133 1
13 2542 512
12 2643 2
12 3738 2048
1...

output:

24139611
37166004
9106163
13694567
18187745
4181153
38429455
47183689
13323566
41850734
48315197
40121405
18296073
48060584
5562529
7850275
14587781
30741951
40538054
5701751
1584259
18940350
49711317
10387186
14846815
7681543
6137030
29069796
48082892
32799569
13887515
7875548
38545845
35413905
145...

result:

ok 100000 numbers

Test #123:

score: 3
Accepted
time: 1101ms
memory: 77372kb

input:

277086209
100000
13 4698 1
13 5115 1
13 6479 1
13 7518 1
13 4448 1
13 6767 1
13 7306 1
13 4969 1
13 5385 1
13 6488 1
13 6115 1
13 7459 1
13 6542 1
13 5766 1
13 7907 1
13 6289 1
13 7708 1
13 5260 1
13 6406 1
13 8009 1
13 6554 1
13 5435 1
13 5010 1
13 7932 1
13 6955 1
13 4312 1
13 5013 1
13 4828 1
13 ...

output:

10717373
105805243
167251993
208473407
243585713
274864816
102015284
248264046
156519622
4398010
272817799
198099401
125681688
114816226
188355125
191907047
12341974
98174094
4478907
159820829
160563310
247607855
245757407
199075372
125897076
59206275
136779909
36841370
28147526
198019880
133115001
...

result:

ok 100000 numbers

Test #124:

score: 3
Accepted
time: 1116ms
memory: 77328kb

input:

77070337
100000
13 2521 1
13 3052 1
13 4320 1
13 7522 1
13 5895 1
13 2723 1
13 4855 1
13 1262 1
13 7397 1
13 3254 1
13 3193 1
13 54 1
13 4865 1
13 1080 1
13 7640 1
13 4898 1
13 3345 1
13 7746 1
13 2663 1
13 3419 1
13 3177 1
13 2160 1
13 4578 1
13 6097 1
13 391 1
13 1635 1
13 6629 1
13 4660 1
13 7562...

output:

12040556
17020218
22244180
40110269
1965327
33769814
59986396
49182630
31323209
54134626
53317281
43585738
10599279
4507574
32020670
31931356
66466895
12544365
15151842
36644380
41149239
36672315
69249844
52719375
40730820
68924707
43182964
37195014
54824965
38640127
16449792
71932567
1811488
516646...

result:

ok 100000 numbers

Test #125:

score: 3
Accepted
time: 1092ms
memory: 77440kb

input:

552861697
100000
12 420 256
6 21 16
13 2135 32
1 1 2
9 103 32
12 2423 32
4 7 4
8 2 256
7 110 128
7 8 128
12 889 1024
10 838 64
10 643 64
13 3196 2
1 1 1
7 109 1
2 1 4
6 25 64
8 173 256
9 314 512
8 72 8
5 29 32
10 212 1024
6 2 64
4 2 16
13 534 32
11 777 2048
12 3120 256
11 1822 64
12 2858 2
2 1 4
5 1...

output:

498747051
1370754
178645306
0
328155662
361017399
120
0
0
0
0
480970719
34150928
352924998
1
159081791
0
0
0
0
171713722
0
0
0
0
529225382
0
315386485
488346665
274987647
0
0
0
281317772
220599587
0
0
368075304
0
76199059
191712789
0
74615
0
0
0
196776841
1
196366093
0
0
1
515643444
0
0
1
80435075
1...

result:

ok 100000 numbers

Subtask #23:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #21:

100%
Accepted

Test #126:

score: 3
Accepted
time: 1088ms
memory: 77336kb

input:

925892609
10
14 703 9954
14 11002 7773
14 12714 11289
14 6750 8923
14 1615 11456
14 5674 1175
14 1167 885
14 15259 10401
14 5403 4394
14 14391 10691

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #127:

score: 3
Accepted
time: 1086ms
memory: 77336kb

input:

615776257
10
13 693 2
14 14404 2048
14 2224 4
13 656 2
13 3514 2048
14 8456 1
14 4682 16
14 8864 1024
14 1753 256
12 1245 4

output:

361202044
257047105
465353530
385922828
37148730
274627959
367769204
19043935
140353231
500742709

result:

ok 10 numbers

Test #128:

score: 3
Accepted
time: 1077ms
memory: 77568kb

input:

22806529
10
14 13815 32
14 5134 1024
14 2568 512
14 10213 2
14 5062 32
14 4760 256
14 3725 2048
14 14201 64
14 4376 128
14 13821 128

output:

15709177
10620430
7340232
10923470
13001711
2572099
6566323
19909075
19576699
10101565

result:

ok 10 numbers

Test #129:

score: 3
Accepted
time: 1087ms
memory: 77420kb

input:

925892609
10
14 16383 1
14 16380 1
14 16382 1
14 16379 1
14 16374 1
14 16381 1
14 16378 1
14 16377 1
14 16376 1
14 16375 1

output:

16383
8683329
134176784
331557748
517390091
224713806
830633516
314994403
650417339
331714109

result:

ok 10 numbers

Test #130:

score: 3
Accepted
time: 1091ms
memory: 77396kb

input:

770703361
10
14 11749 1
14 10353 1
14 9257 1
14 10711 1
14 12641 1
14 13325 1
14 15498 1
14 12570 1
14 14915 1
14 13523 1

output:

535310110
337629126
390855919
691367429
519251310
370047407
569244417
760942021
445449146
544391579

result:

ok 10 numbers

Test #131:

score: 3
Accepted
time: 1067ms
memory: 77340kb

input:

825753601
10
14 8226 1
14 8315 1
14 10170 1
14 4779 1
14 11276 1
14 14883 1
14 14000 1
14 9766 1
14 7224 1
14 2826 1

output:

62940032
318945443
212292084
410422477
699105790
415098226
104201031
761388502
587832047
803297316

result:

ok 10 numbers

Test #132:

score: 3
Accepted
time: 1071ms
memory: 77392kb

input:

615776257
10
10 702 8
11 1503 32
14 6065 16
10 107 128
9 104 512
3 5 8
9 162 16
3 5 4
2 4 4
11 84 4

output:

36860798
52782592
571033014
0
0
0
342929886
2
1
533627620

result:

ok 10 numbers

Subtask #24:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #20:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #22:

100%
Accepted

Dependency #23:

100%
Accepted

Test #133:

score: 3
Accepted
time: 1067ms
memory: 77328kb

input:

442761217
100000
14 1519 3124
14 15138 8906
14 13415 12897
14 5461 4842
14 14242 12555
14 854 9877
14 15437 7753
14 8905 12415
14 5706 14732
14 12510 9211
14 7853 4086
14 6252 13939
14 12535 12795
14 9548 2089
14 9106 13879
14 6392 12333
14 6029 1422
14 7267 1950
14 15257 11402
14 2843 4133
14 7747 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #134:

score: 3
Accepted
time: 1117ms
memory: 77432kb

input:

950009857
100000
13 5322 4
14 11700 128
14 3312 1
14 15823 1
13 4574 2
14 8253 32
14 9216 2048
13 8051 4
11 1190 512
14 7809 128
14 10940 1
14 5290 4096
14 11545 2048
12 1484 8
14 8078 2
14 8551 2048
13 1980 64
14 8675 16
13 2183 4
14 6605 32
14 9751 2048
13 6400 64
14 14818 16
13 6590 256
14 6770 5...

output:

210102203
859879253
417750329
548881905
493880790
704128162
472685293
886779779
657916964
527040419
940434195
924327850
361062506
239068808
63421060
219979194
678796961
574975544
35617883
944736608
741594894
803326916
496785631
518796789
651764895
914524031
169082726
4001134
277710869
882399767
2644...

result:

ok 100000 numbers

Test #135:

score: 3
Accepted
time: 1100ms
memory: 77388kb

input:

90439681
100000
14 2729 512
14 4981 32
14 16320 8192
14 11901 2
14 12751 8192
14 2643 8
14 7812 1024
14 16154 32
14 13881 8
14 1151 32
14 15540 16
14 15553 2048
14 12865 16
14 7242 1024
14 3035 8
14 13232 8
14 14529 4
14 15332 32
14 4830 512
14 11331 16
14 14047 1024
14 13879 8
14 13405 32
14 13387 ...

output:

63510750
72230604
11412110
68110843
61573502
64299255
72597241
46443314
12630266
78087793
58605474
72292410
45663840
30444988
25275966
52543545
10331321
62947945
18984547
47256488
44136040
10088749
84953089
55947339
83186614
48151079
19631934
30924498
41589939
21808932
16355776
8743742
56423317
4301...

result:

ok 100000 numbers

Test #136:

score: 3
Accepted
time: 1099ms
memory: 77416kb

input:

442761217
100000
14 3656 2
14 15469 4
14 8801 2
14 951 4
14 1684 4
14 915 8
14 16277 16
14 4744 4
14 9227 16
14 3246 32
14 12167 2
14 15174 32
14 3271 1
14 7571 4
14 10287 4
14 12931 4
14 2895 8
14 1557 8
14 3857 8
14 12457 2
14 5663 8
14 8218 1
14 4456 32
14 3035 4
14 4965 8
14 6170 32
14 8961 16
1...

output:

385269493
185799552
355928654
208895635
111637104
237255686
275884735
302685263
434862068
421356600
34002737
179395508
383141758
272264275
143537684
221708353
292685875
294057734
339128271
213268872
247118949
212355425
270465411
234473563
106552870
83912429
186847127
375927814
322556984
416643358
10...

result:

ok 100000 numbers

Test #137:

score: 3
Accepted
time: 1092ms
memory: 77448kb

input:

684982273
100000
14 13462 1
14 12728 1
14 16235 1
14 9990 1
14 12174 1
14 9014 1
14 15485 1
14 16278 1
14 11087 1
14 11940 1
14 11640 1
14 13274 1
14 13486 1
14 14438 1
14 11239 1
14 8777 1
14 11668 1
14 14880 1
14 10013 1
14 16022 1
14 12394 1
14 9297 1
14 13760 1
14 14350 1
14 15401 1
14 12145 1
1...

output:

197178518
97995744
12594709
93103857
609762277
402555023
455562943
452300886
460688545
199124622
275837744
580515538
324628413
660852475
201562477
643597579
338518432
107009897
438584446
437214684
52575298
383290197
344241923
440589951
653818240
154557739
117503644
521668341
658523508
20473162
21253...

result:

ok 100000 numbers

Test #138:

score: 3
Accepted
time: 1108ms
memory: 77440kb

input:

518520833
100000
14 15139 1
14 8972 1
14 13716 1
14 2050 1
14 10111 1
14 10531 1
14 173 1
14 12373 1
14 4407 1
14 14148 1
14 7363 1
14 8385 1
14 2307 1
14 13147 1
14 875 1
14 12604 1
14 14898 1
14 10566 1
14 1164 1
14 15726 1
14 5670 1
14 6744 1
14 6626 1
14 7220 1
14 4052 1
14 7385 1
14 2685 1
14 1...

output:

379142873
374721079
333257560
344284401
167509660
239134859
296716742
207742858
11979100
416147263
375382923
116201532
145934940
313303567
371964698
175286812
376092843
473997650
183096163
16274267
495770960
132238978
421220427
485135797
281741358
233289612
402843448
156572780
6750176
216690375
8119...

result:

ok 100000 numbers

Test #139:

score: 3
Accepted
time: 1089ms
memory: 77640kb

input:

261881857
100000
1 1 2
6 47 64
13 1420 256
1 2 2
2 3 4
12 2957 32
5 31 32
13 2059 4096
2 3 4
11 1166 2048
4 16 1
14 5447 1024
13 1424 1
6 18 16
14 11319 256
2 1 4
11 352 2048
12 2170 4
13 7990 8192
11 1115 1
6 52 1
2 2 4
8 143 128
13 4961 2048
5 1 32
2 3 4
8 153 4
4 3 16
8 34 16
2 4 2
13 2769 32
2 1...

output:

0
0
93684538
1
0
233793838
0
0
0
0
0
78219965
198031090
1035
100488475
0
0
187901911
0
126004261
124742119
0
150215841
180760330
0
0
243578360
0
66337522
0
51186693
0
209825165
0
0
0
188738262
0
0
230188133
0
167167481
0
84977022
0
0
0
201843510
125283297
219123226
183958877
0
37584676
0
0
0
3251137...

result:

ok 100000 numbers

Subtask #25:

score: 4
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #23:

100%
Accepted

Test #140:

score: 4
Accepted
time: 1045ms
memory: 77344kb

input:

70254593
10
15 10872 3403
15 26705 30118
15 26565 18765
15 14443 10292
15 3499 1048
15 31708 26339
15 28523 24781
15 30149 2206
15 29178 25808
15 18252 7826

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #141:

score: 4
Accepted
time: 1059ms
memory: 77416kb

input:

626262017
10
15 11891 512
15 16346 4096
12 45 8
15 28035 128
10 757 32
15 139 8
15 26218 4
15 21889 16384
15 10403 8192
15 19622 2048

output:

307687340
242733704
587381110
248433920
68146380
24275249
258730409
314751695
384529966
71723054

result:

ok 10 numbers

Test #142:

score: 4
Accepted
time: 1062ms
memory: 77436kb

input:

536608769
10
15 15706 4096
15 29169 2
15 27397 8192
15 32502 1
15 20203 16384
15 8626 4096
15 3106 4
15 10086 4096
15 19299 512
15 7100 64

output:

332086744
53179401
104385417
492700190
16087893
38199547
274323896
409865892
73792759
377703565

result:

ok 10 numbers

Test #143:

score: 4
Accepted
time: 1086ms
memory: 77376kb

input:

70254593
10
15 32761 1
15 32764 1
15 32762 1
15 32759 1
15 32767 1
15 32765 1
15 32758 1
15 32760 1
15 32763 1
15 32766 1

output:

12338225
66563173
11507927
19484203
32767
58423646
10214056
32917179
8395082
45006858

result:

ok 10 numbers

Test #144:

score: 4
Accepted
time: 1068ms
memory: 77396kb

input:

710934529
10
15 30906 1
15 26080 1
15 25039 1
15 28245 1
15 25095 1
15 28047 1
15 17115 1
15 31443 1
15 22271 1
15 25728 1

output:

67841163
315688058
642428807
489284668
136257647
577617986
148343620
310872312
608680299
353689259

result:

ok 10 numbers

Test #145:

score: 4
Accepted
time: 1077ms
memory: 77384kb

input:

234356737
10
15 17983 1
15 5691 1
15 22072 1
15 5284 1
15 3266 1
15 7690 1
15 6081 1
15 16013 1
15 1202 1
15 26413 1

output:

118084652
229508113
66092453
139412668
136696404
18282386
68280048
25457930
107676974
75080204

result:

ok 10 numbers

Test #146:

score: 4
Accepted
time: 1076ms
memory: 77344kb

input:

215482369
10
3 1 8
10 246 1024
10 811 16
15 20923 16384
14 9557 512
1 1 2
6 7 2
12 2903 4096
7 34 32
10 675 2

output:

0
0
134551392
158527477
99551152
0
5461624
0
4371
161291942

result:

ok 10 numbers

Subtask #26:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #20:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #22:

100%
Accepted

Dependency #23:

100%
Accepted

Dependency #24:

100%
Accepted

Dependency #25:

100%
Accepted

Test #147:

score: 3
Accepted
time: 1100ms
memory: 77380kb

input:

597688321
100000
15 28072 29341
15 14457 31252
15 10882 3990
15 13154 6212
15 16126 2146
15 26888 2272
15 26408 31649
15 23795 4220
15 29480 19762
15 32756 6346
15 24618 5897
15 25007 31502
15 23950 51
15 27754 32452
15 2640 9767
15 5909 22671
15 30394 1104
15 14745 13669
15 13896 1496
15 28518 7674...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #148:

score: 3
Accepted
time: 1104ms
memory: 77428kb

input:

957349889
100000
11 852 8
15 28471 1024
15 15194 1024
15 5565 512
15 26156 8
12 649 32
14 5803 2048
13 6840 512
14 1745 1024
15 24921 128
15 19329 2
15 32507 16384
8 79 8
15 17863 128
14 14389 1
15 13833 4096
13 5930 16
15 27792 16384
15 14596 8192
13 1777 128
15 25676 1024
15 31245 64
15 17715 4096...

output:

197315454
501123910
58299734
339605554
886163597
374526341
432805066
384171875
532267714
654283370
237671642
904817030
308914328
145503484
797538476
828042393
465197392
932652826
10637946
535191575
463670054
599602458
744329548
741942920
565121427
476265188
496832514
281860756
357237599
28872452
484...

result:

ok 100000 numbers

Test #149:

score: 3
Accepted
time: 1093ms
memory: 77276kb

input:

471072769
100000
15 8160 4
15 19310 16384
15 25945 1024
15 9222 4096
15 8903 128
15 31366 64
15 5892 2
15 31946 2
15 31454 16
15 27562 8
15 17292 16384
15 31829 16384
15 15598 8192
15 17027 16384
15 29289 512
15 31941 1024
15 20160 64
15 8828 16
15 7599 16
15 14223 256
15 28131 1
15 26706 128
15 259...

output:

69389784
147639163
67774150
370077541
168507828
438977550
168831892
270345777
429718475
58336609
421202360
279672749
457183168
90195366
233163902
397502358
249854670
234093458
26945329
425653929
113309402
376444468
182629006
258940123
375624407
132120159
181335212
172461427
172289983
312043298
28267...

result:

ok 100000 numbers

Test #150:

score: 3
Accepted
time: 1089ms
memory: 77432kb

input:

597688321
100000
15 27452 2
15 408 1
15 17850 2
15 23160 4
15 29331 2
15 23837 1
15 32198 4
15 1042 2
15 26169 4
15 1643 2
15 3723 2
15 28057 4
15 31700 4
15 7853 4
15 24488 1
15 13163 2
15 30249 1
15 11737 1
15 19210 1
15 21875 1
15 4487 1
15 4745 2
15 16619 4
15 32569 4
15 21754 4
15 31165 2
15 85...

output:

18369551
233876722
221477790
438292918
519044326
357569261
368944304
267744844
66780790
588801189
443630740
211390997
115655420
30066034
567055643
54865009
595894524
539427386
46983307
439768823
131312828
479573087
278714872
209171659
427817576
238945504
317044597
430165497
444696621
335965008
23067...

result:

ok 100000 numbers

Test #151:

score: 3
Accepted
time: 1093ms
memory: 77432kb

input:

958136321
100000
15 20311 1
15 30562 1
15 21256 1
15 28104 1
15 19560 1
15 30874 1
15 26132 1
15 31730 1
15 21057 1
15 21953 1
15 22826 1
15 25939 1
15 19727 1
15 16536 1
15 31059 1
15 19787 1
15 28080 1
15 18782 1
15 32744 1
15 25365 1
15 23728 1
15 27394 1
15 21282 1
15 26430 1
15 29538 1
15 28710...

output:

811015240
101549472
30238889
87289145
754115730
928223574
486646181
615510139
125520021
762375735
534589181
376254930
399726588
317829160
122993901
150664361
855862866
616190590
143148143
922865169
399329270
472573643
293829824
762856751
675117812
316226261
525123834
157017064
618441017
204560224
24...

result:

ok 100000 numbers

Test #152:

score: 3
Accepted
time: 1096ms
memory: 77444kb

input:

958922753
100000
15 24896 1
15 22732 1
15 9234 1
15 18939 1
15 18485 1
15 19721 1
15 8639 1
15 18620 1
15 31152 1
15 4967 1
15 7699 1
15 25135 1
15 14162 1
15 21375 1
15 24281 1
15 12489 1
15 13039 1
15 17279 1
15 25553 1
15 22865 1
15 30224 1
15 21416 1
15 13869 1
15 24163 1
15 6515 1
15 10705 1
15...

output:

955304597
954462896
525480982
58440835
661031366
7777670
519329329
883130328
601725624
922677543
824262214
684448473
154443364
642170075
101773551
518798595
737297269
459740895
591589959
327926049
850931260
484932223
238912444
643904984
128852778
528322608
669207213
357447497
142138908
496473946
165...

result:

ok 100000 numbers

Test #153:

score: 3
Accepted
time: 1084ms
memory: 77400kb

input:

37224449
100000
6 50 1
13 6023 256
3 5 8
9 274 512
8 200 256
4 9 16
10 388 16
8 134 128
1 2 2
12 3805 4096
10 107 128
11 1034 1
13 1191 256
5 27 2
3 6 8
8 90 128
9 329 4
4 14 16
2 2 4
4 2 2
10 953 256
9 421 16
11 830 2
2 3 4
7 110 1
8 84 64
11 1928 2048
10 676 2
10 930 64
9 242 512
9 368 128
8 173 6...

output:

6553667
14131104
0
0
0
0
3064584
11529507
1
0
0
17344602
30981395
10754
0
0
17282971
0
0
1
17451263
17172717
16938814
0
33270548
9872824
0
1566958
24531716
0
790687
30323200
0
24947004
0
688
1
32812644
0
28532904
0
11330254
16371428
22322435
0
0
24460117
0
0
23929988
4615696
36902073
10066197
278128...

result:

ok 100000 numbers

Subtask #27:

score: 4
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #23:

100%
Accepted

Dependency #25:

100%
Accepted

Test #154:

score: 4
Accepted
time: 1065ms
memory: 77644kb

input:

200540161
10
16 37425 62387
16 9640 3311
16 56800 9857
16 22136 60814
16 5383 7023
16 24974 51502
16 6727 32293
16 45039 26779
16 52952 30839
16 54882 4961

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #155:

score: 4
Accepted
time: 1084ms
memory: 77376kb

input:

495452161
10
14 16160 1
16 22835 2
16 4157 4
15 4696 128
16 62197 4096
16 65297 512
15 11036 64
15 19754 2048
16 9797 128
15 1328 16

output:

451442908
444898364
472738136
88328610
418750249
210790680
156240273
130220940
247866483
448250498

result:

ok 10 numbers

Test #156:

score: 4
Accepted
time: 1071ms
memory: 77328kb

input:

907542529
10
16 24520 1024
16 63488 2
16 10050 8
16 26093 1
16 58886 1024
16 15021 64
16 1239 1
16 47811 128
16 19680 64
16 11166 32

output:

373941112
761858729
127584601
94347063
321007935
791205930
133466860
321100263
525332695
83844877

result:

ok 10 numbers

Test #157:

score: 4
Accepted
time: 1084ms
memory: 77444kb

input:

200540161
10
16 65533 1
16 65534 1
16 65527 1
16 65528 1
16 65529 1
16 65530 1
16 65526 1
16 65535 1
16 65531 1
16 65532 1

output:

114584982
141918216
142520006
181602528
22478619
36382447
78521989
65535
66092991
175489431

result:

ok 10 numbers

Test #158:

score: 4
Accepted
time: 1098ms
memory: 77428kb

input:

862978049
10
16 43546 1
16 62230 1
16 46901 1
16 35153 1
16 44243 1
16 52113 1
16 63504 1
16 39887 1
16 65144 1
16 46012 1

output:

467684607
512020531
155457101
257726742
463623413
94969894
787513123
172623817
502594583
162679545

result:

ok 10 numbers

Test #159:

score: 4
Accepted
time: 1070ms
memory: 77340kb

input:

107216897
10
16 35974 1
16 63539 1
16 2905 1
16 20105 1
16 34606 1
16 42352 1
16 40406 1
16 63749 1
16 20582 1
16 63652 1

output:

24968759
8019959
54044170
75732178
15825747
94639470
64031944
74070654
72639227
47929531

result:

ok 10 numbers

Test #160:

score: 4
Accepted
time: 1065ms
memory: 77416kb

input:

518520833
10
15 31053 16384
7 71 64
14 9542 64
7 120 1
14 7159 1
3 5 1
13 7534 8192
9 227 4
2 2 4
9 70 64

output:

207430765
491796152
203149825
333850177
200909208
29
0
237958251
0
443596826

result:

ok 10 numbers

Subtask #28:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #20:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #22:

100%
Accepted

Dependency #23:

100%
Accepted

Dependency #24:

100%
Accepted

Dependency #25:

100%
Accepted

Dependency #26:

100%
Accepted

Dependency #27:

100%
Accepted

Test #161:

score: 3
Accepted
time: 1081ms
memory: 77512kb

input:

621281281
100000
16 54624 22790
16 62929 4445
16 8349 27850
16 20847 56733
16 18010 8122
16 52922 27436
16 37380 6392
16 5917 61560
16 20487 24793
16 36618 36249
16 24999 40476
16 43763 65448
16 18980 36460
16 62344 46431
16 28943 54808
16 38194 33010
16 38375 33554
16 38608 25389
16 45303 57125
16 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #162:

score: 3
Accepted
time: 1099ms
memory: 77556kb

input:

962592769
100000
15 11246 128
16 2145 128
15 24709 8192
15 15896 256
15 10782 2
12 1455 128
15 25734 8
15 8490 32
16 64723 8
15 21188 1
16 13556 1
16 36032 4
16 15001 1
15 19925 128
16 46299 1
15 11625 256
16 20513 2048
15 16273 128
16 29516 64
16 17014 64
13 3534 1
14 7702 512
16 56435 8192
15 3151...

output:

308407942
196083128
391133704
921331385
168898446
43787657
326440109
282008950
783377326
844774962
633980785
818981021
954107988
251310542
589037947
75595516
5424367
823226752
259861901
337616633
951805801
461460922
873881981
305124104
61038577
946547682
807560940
22392939
681249232
660834616
656204...

result:

ok 100000 numbers

Test #163:

score: 3
Accepted
time: 1080ms
memory: 77556kb

input:

975175681
100000
16 40902 256
16 61495 512
16 47643 8
16 5970 4096
16 43005 16384
16 50955 32768
16 59449 32
16 3690 64
16 51921 256
16 42941 32
16 42151 64
16 54046 2
16 2266 32
16 58052 2048
16 40385 64
16 55256 2048
16 33415 128
16 44925 4096
16 28648 64
16 10339 4096
16 5599 128
16 26393 1
16 13...

output:

8930882
489538598
8394281
75024591
396439105
581371060
131655731
642265691
944322438
525621664
741091167
321259986
233500005
299418812
514397558
626761845
128433712
637520399
913593158
479377006
145760609
205565826
661726235
419576331
266725076
717812168
606714018
121389459
54042579
437186646
941656...

result:

ok 100000 numbers

Test #164:

score: 3
Accepted
time: 1081ms
memory: 77340kb

input:

621281281
100000
16 62034 1
16 30928 1
16 54980 2
16 63104 1
16 6476 1
16 42067 2
16 56644 2
16 11393 1
16 33586 1
16 59686 2
16 17479 1
16 19091 1
16 62873 1
16 54086 2
16 62266 1
16 12219 1
16 64364 1
16 32911 1
16 30561 1
16 61979 2
16 53046 2
16 60769 1
16 3172 1
16 62015 1
16 62114 2
16 32968 1...

output:

519033150
300517616
86454577
618236784
538105592
348560696
444704424
268210218
189581645
296329718
478373474
572583092
367545131
203920900
572139508
11006593
449737345
24168340
238172788
140812078
20563931
152726195
97245052
57481061
198835190
553040862
606897849
279136170
507070253
47367427
2399881...

result:

ok 100000 numbers

Test #165:

score: 3
Accepted
time: 1107ms
memory: 77344kb

input:

111149057
100000
16 39192 1
16 52158 1
16 60587 1
16 40145 1
16 42246 1
16 49156 1
16 60905 1
16 33969 1
16 48811 1
16 64557 1
16 52467 1
16 53654 1
16 62132 1
16 57637 1
16 44452 1
16 55574 1
16 52942 1
16 37760 1
16 63256 1
16 57553 1
16 57981 1
16 42001 1
16 43852 1
16 53178 1
16 35521 1
16 45749...

output:

94896726
56213040
50133446
91727115
87925888
105786206
94955958
12488921
37590008
91905044
4674161
32054496
5142039
27204524
105122866
75639556
95870630
15441892
57678422
79203978
85804506
99370484
4164732
85388871
85830733
75922387
48346179
26951329
81611413
5436389
55980602
105136874
37421073
6830...

result:

ok 100000 numbers

Test #166:

score: 3
Accepted
time: 1110ms
memory: 77436kb

input:

925892609
100000
16 42887 1
16 47812 1
16 55603 1
16 33761 1
16 17057 1
16 54384 1
16 42964 1
16 819 1
16 50533 1
16 9438 1
16 24653 1
16 32130 1
16 3057 1
16 63034 1
16 53871 1
16 25369 1
16 11048 1
16 42322 1
16 60302 1
16 62890 1
16 7728 1
16 58139 1
16 60420 1
16 53706 1
16 1012 1
16 1580 1
16 1...

output:

411302265
734400302
136712247
98257122
656273588
325793826
671767069
606294981
575966251
723243120
598461643
77961250
807176977
355728501
437429790
189740239
403447496
108707344
570554133
917690077
340204637
545276043
599470535
269857064
671634210
794383161
82884023
321550206
128022410
656684505
530...

result:

ok 100000 numbers

Test #167:

score: 3
Accepted
time: 1093ms
memory: 77344kb

input:

186646529
100000
5 14 32
10 728 1
7 32 2
9 79 64
7 106 2
12 3973 2
7 108 2
10 273 8
10 105 1
14 13952 16384
8 225 8
1 1 2
2 2 4
7 122 16
7 29 128
12 3698 1
7 46 128
14 11036 16384
7 15 16
13 2111 8192
4 4 16
1 2 2
12 3450 32
12 1599 4096
10 797 1
1 1 2
1 1 2
3 4 8
12 764 4096
2 2 4
5 18 1
2 4 4
3 5 ...

output:

0
105597899
22123645
24976772
102497008
121612469
123979506
156584939
42170025
0
25390973
0
0
8806413
0
65539255
0
0
0
0
0
1
154853103
0
116674237
0
0
0
0
0
32157350
1
2
107043321
0
0
0
70893155
46363918
0
33764460
93390039
0
28487738
176640406
3
4783843
125573167
149792037
66073394
1
0
171131136
87...

result:

ok 100000 numbers

Subtask #29:

score: 4
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #23:

100%
Accepted

Dependency #25:

100%
Accepted

Dependency #27:

100%
Accepted

Test #168:

score: 4
Accepted
time: 1069ms
memory: 77432kb

input:

336068609
10
17 96746 88604
17 58112 74809
17 87035 99254
17 95365 45800
17 7268 78535
17 18240 43898
17 50467 7037
17 59929 18583
17 11191 35869
17 124280 2096

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #169:

score: 4
Accepted
time: 1056ms
memory: 77344kb

input:

511967233
10
16 29226 16
16 19045 16384
17 46702 1
15 22568 4096
17 83816 128
16 9586 1
15 12026 4096
15 32437 4096
15 2015 8
17 109754 64

output:

162966702
309526516
237579411
219696223
15059087
151792513
225488476
200025967
146443313
496600349

result:

ok 10 numbers

Test #170:

score: 4
Accepted
time: 1066ms
memory: 77376kb

input:

390332417
10
17 5641 8
17 84951 512
17 33315 32
17 13024 16
17 47381 32
17 124830 8192
17 123528 256
17 23746 32
17 51800 16384
17 598 128

output:

216225433
190823700
324772168
110683562
277800010
289024450
355780463
81198274
270500793
182869125

result:

ok 10 numbers

Test #171:

score: 4
Accepted
time: 1072ms
memory: 77424kb

input:

336068609
10
17 131067 1
17 131069 1
17 131063 1
17 131066 1
17 131070 1
17 131071 1
17 131062 1
17 131064 1
17 131068 1
17 131065 1

output:

322752204
170194233
330482380
154197140
187891706
131071
316723843
156405480
44415797
197511701

result:

ok 10 numbers

Test #172:

score: 4
Accepted
time: 1065ms
memory: 77376kb

input:

657719297
10
17 110739 1
17 108092 1
17 94750 1
17 88088 1
17 117263 1
17 126916 1
17 105287 1
17 115181 1
17 69766 1
17 109922 1

output:

73895168
326592265
278617564
601852710
239446073
536768167
75403092
25516793
418011317
582390569

result:

ok 10 numbers

Test #173:

score: 4
Accepted
time: 1086ms
memory: 77576kb

input:

219676673
10
17 122647 1
17 58116 1
17 14488 1
17 74158 1
17 105625 1
17 1537 1
17 32473 1
17 89510 1
17 30864 1
17 92657 1

output:

160613472
40368373
140415322
203941209
57436073
134359859
137085513
8442334
50014708
171067578

result:

ok 10 numbers

Test #174:

score: 4
Accepted
time: 1064ms
memory: 77556kb

input:

253493249
10
12 1168 32
14 10418 16
1 1 2
12 3578 16
11 664 2048
6 7 64
3 1 8
9 51 4
4 8 16
9 203 256

output:

79874723
123006574
0
154190829
0
0
0
213731137
0
0

result:

ok 10 numbers

Subtask #30:

score: 3
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Dependency #10:

100%
Accepted

Dependency #11:

100%
Accepted

Dependency #12:

100%
Accepted

Dependency #13:

100%
Accepted

Dependency #14:

100%
Accepted

Dependency #15:

100%
Accepted

Dependency #16:

100%
Accepted

Dependency #17:

100%
Accepted

Dependency #18:

100%
Accepted

Dependency #19:

100%
Accepted

Dependency #20:

100%
Accepted

Dependency #21:

100%
Accepted

Dependency #22:

100%
Accepted

Dependency #23:

100%
Accepted

Dependency #24:

100%
Accepted

Dependency #25:

100%
Accepted

Dependency #26:

100%
Accepted

Dependency #27:

100%
Accepted

Dependency #28:

100%
Accepted

Dependency #29:

100%
Accepted

Test #175:

score: 3
Accepted
time: 1082ms
memory: 77576kb

input:

771489793
100000
17 113945 49006
17 45864 75942
17 104120 117246
17 94076 107255
17 19894 79634
17 111724 19831
17 81120 112208
17 86343 53365
17 109797 95359
17 40479 33384
17 58149 9519
17 128054 66627
17 46779 40101
17 96933 125946
17 120781 67081
17 70479 10581
17 79124 66003
17 29702 4340
17 11...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #176:

score: 3
Accepted
time: 1088ms
memory: 77348kb

input:

862978049
100000
15 26059 64
15 8933 2
16 16188 128
14 2702 512
17 31569 16
15 21328 1
17 16857 512
14 4583 64
12 3988 8
17 38341 1024
16 19996 1
17 108459 16
17 3213 8
17 6965 128
16 38633 8
17 6780 8
15 15606 4096
17 58198 2048
16 29342 1024
16 58407 8
16 32709 2
17 1179 8
16 63670 256
17 59394 1
...

output:

623172044
738819116
738174415
386872672
135830038
472973766
590072515
795223046
198231019
738961341
722677491
352265137
305182721
359080929
573806778
790828823
124790933
26366493
263859077
831418776
698782150
215526257
763316542
159195134
100241663
461213751
322246621
630977222
375630590
779648150
8...

result:

ok 100000 numbers

Test #177:

score: 3
Accepted
time: 1087ms
memory: 77640kb

input:

330301441
100000
17 96331 2
17 83471 4
17 62443 32
17 2143 2
17 58252 16384
17 17503 8
17 89763 2
17 45798 8
17 110596 65536
17 105751 128
17 6374 16
17 43334 2048
17 88452 16384
17 25023 1
17 64066 4
17 59946 1
17 118502 128
17 84284 1
17 47991 32768
17 126409 512
17 92212 256
17 69529 4096
17 6277...

output:

46716200
71950947
148468497
234361784
84386145
235728410
53431411
262807328
283198648
191974422
319159773
265406353
183926650
91135422
64600654
221198672
70712188
221230881
161295652
213492340
228967061
163667920
226887195
254863732
309597067
287774916
221035806
273920684
155729763
27041035
21142271...

result:

ok 100000 numbers

Test #178:

score: 3
Accepted
time: 1087ms
memory: 77404kb

input:

771489793
100000
17 116374 1
17 69665 1
17 77405 1
17 90016 1
17 92117 1
17 46011 1
17 112017 1
17 113027 1
17 41932 1
17 129160 1
17 111986 1
17 70596 1
17 54407 1
17 67173 1
17 128034 1
17 103343 1
17 103079 1
17 84769 1
17 111389 1
17 93242 1
17 111713 1
17 91408 1
17 41923 1
17 34906 1
17 67048 ...

output:

700361557
424204378
623065491
250608191
769894736
375910067
229236787
625206758
326469500
37935590
607270511
656681508
61342329
283695900
5550704
688233833
708571825
245976238
599328713
34464849
480224651
336061398
359077322
730505036
201534145
254190012
234221972
769618433
120515655
732862596
10742...

result:

ok 100000 numbers

Test #179:

score: 3
Accepted
time: 1083ms
memory: 77432kb

input:

597688321
100000
17 126814 1
17 77643 1
17 93614 1
17 83425 1
17 129498 1
17 68356 1
17 71768 1
17 105836 1
17 117743 1
17 89006 1
17 126272 1
17 96933 1
17 107084 1
17 130192 1
17 129413 1
17 96316 1
17 121906 1
17 103634 1
17 94611 1
17 101245 1
17 107296 1
17 66843 1
17 117537 1
17 86096 1
17 129...

output:

493055280
273568580
227966388
543335536
176524843
108360461
298262443
406279251
327086921
38752262
412054813
140164398
374446685
522492264
112801308
316484665
298277042
509017184
87318990
391348730
547581180
417764459
274494777
505507041
245157894
506743027
52895468
502583530
185215664
264574208
183...

result:

ok 100000 numbers

Test #180:

score: 3
Accepted
time: 1086ms
memory: 77340kb

input:

141557761
100000
17 77140 1
17 75339 1
17 92673 1
17 106048 1
17 123014 1
17 112664 1
17 64079 1
17 63414 1
17 21258 1
17 105289 1
17 47179 1
17 97689 1
17 121215 1
17 75408 1
17 46099 1
17 112140 1
17 2021 1
17 38116 1
17 24555 1
17 6201 1
17 97058 1
17 33535 1
17 74170 1
17 70091 1
17 111232 1
17 ...

output:

91080891
11783935
87923346
52960693
63546441
113224667
86208169
92968813
17078278
12002956
87059387
104080194
69669823
70419417
56849038
95308472
63840263
74011126
247427
50194994
60936401
19622279
129569255
81441241
1986525
11420774
88022007
64885651
42402142
11281588
59450160
130716955
120688171
6...

result:

ok 100000 numbers

Test #181:

score: 3
Accepted
time: 1093ms
memory: 77428kb

input:

175636481
100000
8 205 256
17 11258 4096
5 30 32
11 652 2
1 2 2
3 7 8
9 239 512
10 66 1024
5 2 32
6 35 64
17 14894 32
3 8 8
6 18 64
17 38700 16
1 2 2
3 6 8
17 94262 32768
7 116 2
3 5 8
12 2790 1024
10 546 1024
6 9 64
4 7 16
17 42378 65536
10 320 4
10 13 1024
12 138 512
13 1517 8192
8 44 2
16 62005 1...

output:

0
72883075
0
103045120
1
0
0
0
0
0
146218763
1
0
71032741
1
0
134666647
173789785
0
66740198
0
0
0
0
34278522
0
0
0
114941748
98926268
17346901
0
0
159373516
47826390
0
0
91996075
0
160837186
46808734
160933914
0
0
0
0
0
4610492
0
1
1
86647808
134959117
0
95309290
0
82638746
48825237
77076441
0
6024...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed