QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#119716#3. Fireworksmyee100 ✓179ms28840kbC++112.3kb2023-07-05 15:24:062023-07-05 15:24:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-05 15:24:09]
  • 评测
  • 测评结果:100
  • 用时:179ms
  • 内存:28840kb
  • [2023-07-05 15:24:06]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

// 容易发现闵可夫斯基和。
// 知道可并堆可以维护这种信息后就没了,但是前提是得想到……
// 懒了,写斜堆。
// 感觉这种做法是全网统一的?虽然似乎可以直接启发式合并,但是复杂度明显劣了。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
struct node{node*L,*R;ullt x;node(ullt x):L(NULL),R(NULL),x(x){}};
node*merge(node*a,node*b){
    if(!a)return b;
    if(!b)return a;
    if(a->x<b->x)std::swap(a,b);
    std::swap(a->L,a->R=merge(a->R,b));
    return a;
}
node*pop(node*p){
    if(!p)return p;
    node*ans=merge(p->L,p->R);p->L=p->R=NULL;
    return ans;
}
uint Fath[300005],Deg[300005];
ullt C[300005];
node*T[300005];
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
#endif
    uint n,m;scanf("%u%u",&n,&m);
    for(uint i=1;i<n+m;i++)scanf("%u%llu",Fath+i,C+i),Deg[--Fath[i]]++;
    for(uint i=n+m-1;i;i--){
        if(i>=n)T[i]=merge(new node(0),new node(0));
        else while(--Deg[i])T[i]=pop(T[i]);
        node*a=pop(T[i]);
        a->x+=C[i],T[i]->x+=C[i];
        T[i]=merge(a,T[i]);
        T[Fath[i]]=merge(T[i],T[Fath[i]]);
    }
    while(--Deg[0])T[0]=pop(T[0]);
    ullt x=T[0]->x,k=0,ans=0;
    for(uint i=1;i<n+m;i++)ans+=C[i];
    while((T[0]=pop(T[0])))ans-=k++*(x-T[0]->x),x=T[0]->x;
    ans-=k*x;
    printf("%llu\n",ans);
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

详细

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 2ms
memory: 7200kb

input:

1 1
1 594911537

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 7200kb

input:

1 9
1 825879648
1 544663269
1 523587648
1 265820061
1 715816315
1 46975056
1 181647299
1 679235405
1 657226464

output:

1860127768

result:

ok single line: '1860127768'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7124kb

input:

1 91
1 385900550
1 26102977
1 667546315
1 172015997
1 279290345
1 307280944
1 617208234
1 356267123
1 736729319
1 625308102
1 760176838
1 58322561
1 791921572
1 668621731
1 363109524
1 158699815
1 131392063
1 584992804
1 691545613
1 974934420
1 997953539
1 876137720
1 564678478
1 746582187
1 8674083...

output:

22110262696

result:

ok single line: '22110262696'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7172kb

input:

1 89
1 82978004
1 725546925
1 824854855
1 134535238
1 182588700
1 121005200
1 274161085
1 287432242
1 765301085
1 762002231
1 14627523
1 160221425
1 835613649
1 891489782
1 963032877
1 232634649
1 551893622
1 78012995
1 298144433
1 402762010
1 455684005
1 921659880
1 244327108
1 567279640
1 40490786...

output:

22880340918

result:

ok single line: '22880340918'

Test #5:

score: 0
Accepted
time: 2ms
memory: 7184kb

input:

1 84
1 887742276
1 580594619
1 950555150
1 771426100
1 465681669
1 469566475
1 651054119
1 538349774
1 623278516
1 795673458
1 647508726
1 643240398
1 182322569
1 832568327
1 160387299
1 114691531
1 329968342
1 620479904
1 652768604
1 98506590
1 198564634
1 538477498
1 754322865
1 94590693
1 9102737...

output:

17356166508

result:

ok single line: '17356166508'

Test #6:

score: 0
Accepted
time: 2ms
memory: 7096kb

input:

1 91
1 162454772
1 470082830
1 143610614
1 831070014
1 146983411
1 789045826
1 82582863
1 652480352
1 119027154
1 612678289
1 544551347
1 937361107
1 925273426
1 143655813
1 9085899
1 588299483
1 859313272
1 294149571
1 735356175
1 55633143
1 366991221
1 687012588
1 773929825
1 737277036
1 229399700...

output:

22730104544

result:

ok single line: '22730104544'

Test #7:

score: 0
Accepted
time: 2ms
memory: 7112kb

input:

1 98
1 492984845
1 603301504
1 827779013
1 543424271
1 353910948
1 498019066
1 188352400
1 421972590
1 541331626
1 790810535
1 384601943
1 691547921
1 617300120
1 647962561
1 650218429
1 425228920
1 274801429
1 550676594
1 641040777
1 380212377
1 634255275
1 713589024
1 320089450
1 691185086
1 94179...

output:

22934390057

result:

ok single line: '22934390057'

Test #8:

score: 0
Accepted
time: 2ms
memory: 7172kb

input:

1 96
1 676422399
1 383144101
1 908806402
1 195899706
1 858455939
1 680490408
1 612812422
1 205243456
1 937363104
1 467111199
1 445555414
1 213343027
1 415956505
1 963661454
1 937156337
1 556569608
1 344720216
1 835918329
1 893856969
1 184325381
1 53110184
1 524825668
1 356433261
1 686051960
1 263022...

output:

22860762666

result:

ok single line: '22860762666'

Test #9:

score: 0
Accepted
time: 1ms
memory: 7096kb

input:

1 87
1 411199713
1 407170309
1 411199713
1 690858790
1 411199713
1 411199713
1 411199713
1 407170309
1 973231939
1 108775390
1 108775390
1 973231939
1 973231939
1 973231939
1 176781105
1 690858790
1 407170309
1 176781105
1 411199713
1 176781105
1 493892183
1 411199713
1 493892183
1 411199713
1 69085...

output:

15512296902

result:

ok single line: '15512296902'

Test #10:

score: 0
Accepted
time: 2ms
memory: 7104kb

input:

1 95
1 556207110
1 813583629
1 263051757
1 263051757
1 556207110
1 263051757
1 813583629
1 263051757
1 813583629
1 263051757
1 813583629
1 813583629
1 556207110
1 263051757
1 263051757
1 556207110
1 556207110
1 813583629
1 813583629
1 263051757
1 813583629
1 556207110
1 556207110
1 813583629
1 81358...

output:

18060215274

result:

ok single line: '18060215274'

Subtask #2:

score: 19
Accepted

Test #11:

score: 19
Accepted
time: 0ms
memory: 7164kb

input:

6 7
1 65
1 115
2 33
1 298
1 42
3 33
4 6
1 180
5 2
6 126
5 2
2 177

output:

302

result:

ok single line: '302'

Test #12:

score: 0
Accepted
time: 1ms
memory: 7224kb

input:

13 23
1 48
2 167
1 248
2 48
3 61
1 194
1 126
4 33
4 47
5 138
1 262
1 299
6 24
6 7
4 18
6 7
7 49
8 53
4 11
9 3
10 2
4 41
11 39
6 5
12 2
2 172
5 123
10 4
8 63
6 5
13 1
4 47
13 1
13 1
13 1

output:

374

result:

ok single line: '374'

Test #13:

score: 0
Accepted
time: 1ms
memory: 7196kb

input:

21 38
1 24
1 32
2 177
3 203
4 47
3 59
5 5
1 1
6 48
1 181
7 92
7 68
8 1
4 8
9 106
10 1
11 22
12 108
13 6
13 5
4 61
1 11
14 6
12 52
15 35
16 55
2 10
17 1
7 100
8 56
10 3
2 106
17 1
18 1
11 104
8 2
13 116
19 5
10 3
9 195
6 4
9 100
20 128
9 243
13 110
3 82
4 96
8 46
13 31
11 77
7 22
21 124
9 287
7 169
3...

output:

1917

result:

ok single line: '1917'

Test #14:

score: 0
Accepted
time: 0ms
memory: 7104kb

input:

33 38
1 18
1 81
2 100
1 245
3 102
4 5
2 204
5 26
6 37
7 10
8 41
6 52
7 100
4 71
9 25
3 172
10 61
11 144
12 33
9 9
9 17
11 46
13 15
5 17
14 20
15 87
14 73
2 223
8 41
1 283
11 96
16 1
17 4
18 5
19 7
9 17
20 4
17 31
8 2
13 58
21 9
22 2
23 121
7 102
24 50
9 2
25 7
26 13
27 14
28 4
29 45
16 3
20 2
1 219
...

output:

804

result:

ok single line: '804'

Test #15:

score: 0
Accepted
time: 2ms
memory: 7212kb

input:

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

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 2ms
memory: 9260kb

input:

55 62
1 118
2 144
1 264
1 113
1 5
3 27
4 12
5 68
2 21
6 44
7 7
8 15
9 80
2 65
8 3
5 32
10 151
11 137
12 1
2 153
13 5
8 15
7 5
14 24
15 70
1 73
16 13
17 122
5 135
10 131
13 8
4 31
18 5
3 17
19 52
14 6
11 243
20 1
21 10
9 42
14 24
22 1
23 5
3 37
14 33
24 1
25 1
3 26
26 30
9 59
22 2
27 43
24 5
4 33
28 ...

output:

1219

result:

ok single line: '1219'

Test #17:

score: 0
Accepted
time: 0ms
memory: 9264kb

input:

63 67
1 121
2 106
1 147
3 4
4 87
3 36
5 52
6 21
7 21
2 169
8 8
2 165
2 46
7 33
8 13
9 34
10 7
4 119
3 43
1 225
1 2
11 5
12 4
1 137
1 215
13 12
14 1
15 2
3 55
16 3
14 95
17 3
12 7
18 6
19 1
20 12
19 29
21 53
22 71
8 10
5 24
8 4
23 3
24 1
25 100
11 9
12 8
4 60
4 36
14 47
26 44
9 22
27 1
25 76
13 3
28 ...

output:

934

result:

ok single line: '934'

Test #18:

score: 0
Accepted
time: 2ms
memory: 9128kb

input:

66 88
1 246
2 6
3 2
4 21
2 34
2 40
5 10
6 2
5 11
7 3
1 231
8 1
8 11
4 25
4 42
1 253
9 5
4 30
10 1
11 3
12 20
12 9
13 3
7 12
14 2
15 10
16 1
17 44
6 17
1 6
18 5
4 29
19 7
1 252
20 6
21 1
22 30
23 12
20 11
24 7
25 1
8 9
14 2
26 1
20 7
27 1
28 2
29 2
30 2
31 292
21 3
21 1
32 3
15 14
33 3
28 1
34 8
25 1...

output:

594

result:

ok single line: '594'

Test #19:

score: 0
Accepted
time: 1ms
memory: 7104kb

input:

78 99
1 204
1 105
1 137
2 3
3 125
4 21
5 65
6 39
7 41
2 41
8 6
6 14
9 17
10 46
4 44
11 20
1 183
4 103
12 13
13 18
14 9
13 17
3 37
15 1
16 4
17 9
18 78
2 56
11 39
19 8
20 2
21 29
13 12
22 3
2 64
1 125
23 32
24 119
5 89
9 27
25 39
26 16
27 7
28 8
29 3
29 19
7 30
30 4
16 112
14 12
22 1
31 51
32 3
33 3
...

output:

1443

result:

ok single line: '1443'

Test #20:

score: 0
Accepted
time: 2ms
memory: 7088kb

input:

89 101
1 120
2 60
1 229
1 156
3 32
4 44
5 105
2 85
2 53
6 11
7 7
4 62
8 15
3 24
9 32
10 94
11 23
12 4
13 5
14 7
10 82
3 98
5 44
15 28
16 43
1 146
16 5
17 25
9 59
17 16
2 118
17 31
18 47
19 10
20 2
8 34
21 8
22 3
23 3
24 65
25 34
26 14
27 61
10 75
2 175
3 89
6 71
28 9
29 3
30 4
31 10
32 16
33 1
34 2
...

output:

1341

result:

ok single line: '1341'

Test #21:

score: 0
Accepted
time: 0ms
memory: 7116kb

input:

101 112
1 172
2 49
3 19
4 3
1 86
1 217
5 28
1 141
6 160
7 35
8 9
9 25
9 109
9 36
6 103
10 37
3 56
11 31
7 58
12 12
2 99
13 88
5 3
14 6
11 39
15 84
16 19
13 106
9 100
17 12
10 41
18 1
17 7
19 10
20 16
21 5
22 16
23 23
1 222
24 33
25 30
26 3
27 7
28 14
29 14
20 20
30 32
2 43
30 40
31 3
23 32
3 17
2 93...

output:

939

result:

ok single line: '939'

Test #22:

score: 0
Accepted
time: 1ms
memory: 7204kb

input:

109 126
1 111
2 115
3 33
1 55
4 26
5 110
6 9
1 188
5 125
7 21
7 102
2 42
2 49
8 1
9 20
10 36
11 19
12 11
4 6
5 154
5 97
7 123
13 5
7 106
14 130
3 51
3 43
6 4
15 2
4 31
11 13
16 2
17 33
18 90
19 6
5 128
7 131
14 87
20 23
21 21
22 25
21 79
10 45
3 25
23 2
24 132
14 77
25 25
22 145
14 18
26 1
27 21
4 3...

output:

1725

result:

ok single line: '1725'

Test #23:

score: 0
Accepted
time: 2ms
memory: 7212kb

input:

117 141
1 107
1 44
2 46
3 99
4 37
5 127
6 46
7 1
1 210
8 59
1 175
1 68
5 56
6 28
9 13
3 86
10 66
11 1
12 38
13 228
12 94
13 180
12 38
8 22
14 1
15 64
16 11
13 159
17 112
18 21
17 47
7 15
19 1
11 1
18 11
20 67
21 2
22 10
23 38
12 53
24 19
25 1
15 34
26 20
27 6
28 1
29 28
30 1
3 204
7 27
10 58
21 1
31...

output:

1931

result:

ok single line: '1931'

Test #24:

score: 0
Accepted
time: 0ms
memory: 7120kb

input:

134 137
1 232
2 11
1 91
1 60
3 47
4 156
5 192
5 103
6 2
1 200
7 16
5 2
8 15
9 26
10 2
11 41
12 23
4 27
9 64
13 131
14 21
2 2
15 92
4 140
16 1
17 50
5 151
18 4
11 17
19 99
20 50
1 155
19 139
21 53
1 188
17 3
22 5
23 31
24 11
25 42
12 22
26 2
23 46
27 1
15 61
10 4
28 69
29 7
26 2
30 57
31 63
32 14
33 ...

output:

1934

result:

ok single line: '1934'

Test #25:

score: 0
Accepted
time: 1ms
memory: 7208kb

input:

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

output:

0

result:

ok single line: '0'

Test #26:

score: 0
Accepted
time: 1ms
memory: 7200kb

input:

139 161
1 108
2 10
2 10
3 51
1 274
4 101
5 3
1 26
6 13
6 2
7 21
4 129
1 253
8 7
2 116
9 98
10 5
11 9
12 28
4 9
13 34
14 12
15 64
16 21
17 86
18 4
2 21
5 25
19 3
16 9
20 3
2 178
12 4
21 104
7 29
22 8
15 90
23 2
15 46
17 169
24 19
25 50
26 12
13 22
20 22
27 1
28 152
9 196
5 95
29 25
30 9
31 57
32 11
3...

output:

2627

result:

ok single line: '2627'

Test #27:

score: 0
Accepted
time: 2ms
memory: 7164kb

input:

130 170
1 166
2 66
1 9
1 94
1 133
3 2
4 244
5 100
6 127
7 20
8 6
6 85
9 65
4 223
10 14
6 142
11 16
8 4
9 4
5 83
1 279
8 23
6 139
12 11
13 50
12 34
9 43
14 31
15 47
16 8
3 62
14 7
17 5
12 38
18 26
12 38
19 19
7 11
17 19
20 68
21 82
16 3
22 19
9 99
23 3
9 5
24 6
25 13
25 27
14 4
26 20
27 3
28 8
17 22
...

output:

1683

result:

ok single line: '1683'

Test #28:

score: 0
Accepted
time: 1ms
memory: 7112kb

input:

137 163
1 14
2 97
3 91
1 91
4 28
5 89
3 55
6 47
1 159
7 33
5 116
8 19
9 2
10 103
11 78
1 170
1 261
12 10
13 43
1 41
14 8
15 5
10 14
16 5
17 82
18 3
17 99
19 75
20 43
21 140
18 10
7 16
18 19
22 2
15 22
22 2
8 2
16 1
18 4
12 16
23 23
24 10
25 1
26 10
27 29
28 12
29 5
1 235
30 11
31 50
32 19
33 51
34 3...

output:

1711

result:

ok single line: '1711'

Test #29:

score: 0
Accepted
time: 2ms
memory: 7180kb

input:

140 160
1 116
2 62
1 228
3 54
4 14
3 112
3 33
5 14
6 23
1 44
7 2
2 124
2 7
2 9
8 76
9 9
10 4
11 240
11 7
2 69
12 1
1 123
13 34
14 119
15 36
16 3
17 16
5 7
18 7
19 2
20 94
21 5
22 1
8 30
18 22
23 37
24 11
19 7
3 22
25 4
26 79
27 3
8 55
22 1
5 54
28 7
29 13
1 51
30 4
11 22
31 6
32 64
7 6
12 4
33 51
34...

output:

2102

result:

ok single line: '2102'

Test #30:

score: 0
Accepted
time: 1ms
memory: 7176kb

input:

121 179
1 16
1 66
2 7
3 69
4 14
1 273
5 64
6 71
1 121
7 9
8 65
7 4
9 150
10 75
11 3
2 277
5 52
12 10
13 2
8 87
8 27
14 22
15 7
11 5
9 104
16 4
17 3
12 5
18 107
19 13
5 28
1 107
2 164
20 15
21 7
16 7
22 15
23 2
17 5
12 29
22 34
6 186
24 54
25 9
7 25
26 28
27 3
28 1
29 28
11 13
30 3
31 3
30 2
1 112
5 ...

output:

2300

result:

ok single line: '2300'

Subtask #3:

score: 29
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #31:

score: 29
Accepted
time: 1ms
memory: 7224kb

input:

301 162
1 920419098
2 13883963
3 922640814
4 576832601
5 458005774
6 627831463
7 637684083
8 363092299
9 608472070
10 993759086
11 191942487
12 177579899
11 778884458
13 475677264
14 618356404
15 782795435
16 407631159
17 814281326
18 753827889
19 190238739
20 344692223
21 212165514
22 256037358
23 ...

output:

132811066618

result:

ok single line: '132811066618'

Test #32:

score: 0
Accepted
time: 0ms
memory: 7252kb

input:

717 419
1 376688158
2 38218218
3 741729439
4 690180775
5 143289985
6 639629931
7 279619166
8 81401288
9 360313680
10 194769290
11 24761187
12 251418858
13 152297565
14 472298949
15 441611798
16 961909797
17 565923038
18 624777680
19 854783150
20 459946195
21 786187234
22 504262463
23 604133263
24 15...

output:

346801924243

result:

ok single line: '346801924243'

Test #33:

score: 0
Accepted
time: 0ms
memory: 7252kb

input:

1039 570
1 763342664
2 630794
3 305459828
4 879255848
5 900380412
6 599712338
7 339885175
8 83275249
9 352596598
10 198141694
11 762445358
12 923992448
13 47801521
14 424346913
4 567981821
15 772530456
16 26119978
17 256886608
18 329480410
19 568425276
20 833205645
21 421390104
22 562202794
23 22678...

output:

507266242467

result:

ok single line: '507266242467'

Test #34:

score: 0
Accepted
time: 0ms
memory: 7280kb

input:

1426 825
1 21845067
2 830363113
3 417705301
4 289927464
5 437535695
6 751469381
7 546832677
8 845762062
9 308121229
10 519035372
11 930131981
12 76264594
13 334316135
14 410847902
15 84600782
16 64577703
17 769816534
18 923402308
19 471587430
20 857634912
21 18912000
22 613450475
23 316973077
24 709...

output:

697458913436

result:

ok single line: '697458913436'

Test #35:

score: 0
Accepted
time: 2ms
memory: 7304kb

input:

1870 1054
1 398066557
2 678052759
3 670475186
4 861116608
5 773321138
6 937239049
7 953430280
8 657951645
9 426251998
10 735428487
11 481848196
12 346087245
8 911283015
13 993057922
14 591673939
15 817915837
16 984331303
17 486190973
18 10049554
19 642301159
20 894607734
21 438105131
22 913310885
23...

output:

905295828241

result:

ok single line: '905295828241'

Test #36:

score: 0
Accepted
time: 3ms
memory: 7192kb

input:

2275 1322
1 418164933
2 775647573
3 736430086
4 987537454
5 209486744
6 17546
7 469060248
8 394145046
9 251495602
10 187675560
11 601481752
12 391420587
13 784661212
14 26939760
15 147656809
16 42133747
17 436410803
18 283704828
19 754349602
20 816052547
21 831053284
22 568655247
23 137154090
24 255...

output:

1095328057433

result:

ok single line: '1095328057433'

Test #37:

score: 0
Accepted
time: 0ms
memory: 7332kb

input:

2587 1483
1 499164205
2 221727844
3 930497471
4 520918543
5 208865162
6 121777946
7 375261020
8 979185681
9 368487058
10 176303026
11 429699232
12 199269283
13 556946849
14 464979024
15 539431406
16 788299689
17 778688657
18 471605859
19 282547751
20 555232934
21 886757378
22 522088193
23 610918707
...

output:

1297800304292

result:

ok single line: '1297800304292'

Test #38:

score: 0
Accepted
time: 2ms
memory: 7264kb

input:

2987 1757
1 82381521
2 474824518
3 920067780
4 425601747
5 635345786
6 51606401
7 734314641
8 414123511
9 583010473
10 359136643
11 836886762
12 215412429
13 196470367
14 701930966
15 385076961
16 633601874
17 268928317
18 384687131
19 761766761
20 806090212
21 774808549
22 961943909
23 154108049
24...

output:

1488454586050

result:

ok single line: '1488454586050'

Test #39:

score: 0
Accepted
time: 3ms
memory: 7312kb

input:

3123 1877
1 831706841
2 781051540
3 70423592
4 648655398
5 158458556
6 611149549
7 396966782
8 617480824
9 214989801
10 294061539
11 684337379
12 110708324
13 221076634
14 474967492
15 372121526
16 470471163
17 385672322
18 94757906
19 547022828
20 567943653
21 444077661
22 188282505
23 509056361
24...

output:

1541144647994

result:

ok single line: '1541144647994'

Test #40:

score: 0
Accepted
time: 3ms
memory: 7260kb

input:

3151 1849
1 324493214
2 131808411
3 293261515
4 355022995
5 29873362
6 599664564
7 835662356
8 933482072
9 541691957
10 873329218
11 410787654
12 303482132
13 284242771
14 484832970
15 858674624
16 880571806
17 574083015
18 467202365
19 329656609
20 2293338
21 772198634
22 361183818
5 298303587
23 4...

output:

1541693936031

result:

ok single line: '1541693936031'

Test #41:

score: 0
Accepted
time: 0ms
memory: 7272kb

input:

4999 1
1 999993036
2 999994800
3 999993285
4 999997650
5 999997940
6 999990140
7 999993201
8 999999276
9 999999071
10 999993743
11 999998318
12 999991514
13 999995090
14 999999301
15 999995132
16 999994465
17 999992463
18 999998028
19 999992382
20 999999010
21 999991716
22 999993591
23 999993053
24 ...

output:

0

result:

ok single line: '0'

Test #42:

score: 0
Accepted
time: 0ms
memory: 7220kb

input:

4998 2
1 999998194
2 999996844
3 999993710
4 999992665
5 999992557
6 999992584
7 999993134
8 999999644
9 999994554
10 999993257
11 999994252
12 999999337
13 999996816
14 999994751
15 999992337
16 999996042
17 999998574
18 999995011
19 999991262
20 999992554
21 999998979
22 999996349
23 999998149
24 ...

output:

4997974986577

result:

ok single line: '4997974986577'

Test #43:

score: 0
Accepted
time: 0ms
memory: 7164kb

input:

4900 100
1 999991561
2 999991023
1 999999431
3 999996825
4 999999376
1 999992285
5 999998086
6 999997485
7 999990084
1 999991950
8 999993135
9 999996894
10 999998611
11 999995713
1 999993078
12 999990674
13 999993528
14 999995213
15 999995084
16 999999507
1 999999999
17 999996140
18 999994248
19 999...

output:

2450987727801

result:

ok single line: '2450987727801'

Test #44:

score: 0
Accepted
time: 2ms
memory: 7292kb

input:

2499 2500
1 439460934
2 783025325
3 559459286
4 10655632
5 754555467
6 175379690
7 267810515
8 826564855
9 514616538
10 432833129
11 586659275
12 537666212
13 587511202
14 867749449
15 442072911
16 792455522
17 430082776
18 15270738
19 669713751
20 972536273
21 253824811
22 875736843
23 963067186
24...

output:

1873824603983

result:

ok single line: '1873824603983'

Test #45:

score: 0
Accepted
time: 1ms
memory: 9408kb

input:

2364 2635
1 800243976
2 560941019
3 611820188
4 110334476
5 653585207
6 73255039
7 55721869
8 492675013
9 672841239
10 558274347
11 695906535
12 19336760
13 475895478
14 320393876
15 784637116
16 973989669
17 665711154
18 786318273
19 779795065
20 54345337
21 423971980
22 828924854
23 486328381
24 3...

output:

1664606780993

result:

ok single line: '1664606780993'

Test #46:

score: 0
Accepted
time: 0ms
memory: 9408kb

input:

2396 2603
1 143164022
2 651107986
3 793461024
4 519935252
5 707437122
6 796625886
7 758986319
8 279582210
9 552992089
10 904220500
11 772924575
12 555594519
13 753901465
14 541269303
15 629634339
16 589254516
17 344548855
18 517628181
19 658109611
20 838928925
21 136407119
22 252769354
23 68158164
2...

output:

1661418840499

result:

ok single line: '1661418840499'

Test #47:

score: 0
Accepted
time: 3ms
memory: 9552kb

input:

53 4943
1 108701533
1 762016066
2 158864139
2 229999782
2 715410397
2 163820409
2 966678446
2 613380142
2 945872922
2 704482790
2 204038648
2 596548544
3 372743765
3 162866106
3 851451963
3 657877743
3 536191158
3 182343668
3 132574004
1 322562600
1 171055898
1 639777706
1 152989795
1 706582237
1 51...

output:

1247558162340

result:

ok single line: '1247558162340'

Test #48:

score: 0
Accepted
time: 4ms
memory: 7448kb

input:

48 4911
1 614868110
2 916120791
2 285591885
2 743652924
2 845514194
2 580273340
2 464847323
2 423348016
2 413536741
2 457069744
2 667830491
2 233015744
2 627828401
2 526677681
2 818440202
2 901083373
2 447934950
2 126282434
2 765771761
2 273471556
2 879518874
2 968316988
2 611124813
2 398175119
2 68...

output:

1234131077649

result:

ok single line: '1234131077649'

Test #49:

score: 0
Accepted
time: 0ms
memory: 7400kb

input:

5 4504
1 890856182
1 78084000
1 16801616
1 466720154
2 589876776
2 807786152
2 719506874
2 160993093
2 76194773
2 535428398
2 157769551
2 206652352
2 129941210
2 917191586
2 567805164
2 257949749
2 836704375
2 656249964
2 458611620
2 976148277
2 259862819
2 312525943
2 925359719
2 816243053
2 614506...

output:

1102143195362

result:

ok single line: '1102143195362'

Test #50:

score: 0
Accepted
time: 3ms
memory: 7448kb

input:

6 4994
1 456281990
1 365849799
1 791098247
1 586851273
1 318572198
2 433461526
2 813265522
2 34581226
2 340305299
2 177232589
2 289532934
2 164014007
2 504775473
2 537364884
2 967517769
2 67477974
2 180646637
2 512956835
2 49621198
2 210136320
2 246610136
2 997359957
2 391536302
2 801647537
2 398463...

output:

1233299707784

result:

ok single line: '1233299707784'

Test #51:

score: 0
Accepted
time: 3ms
memory: 7464kb

input:

2 4275
1 170424242
2 157296367
2 45154595
2 278995331
2 724266140
2 369993724
2 280188774
2 601418859
2 343732082
2 97347826
2 467160686
2 24041524
2 178804849
2 198259179
2 533348580
2 581895147
2 924498865
2 732721030
2 360402368
2 785752880
2 121075840
2 765506692
2 937671044
2 854745655
2 818916...

output:

1063932478026

result:

ok single line: '1063932478026'

Test #52:

score: 0
Accepted
time: 3ms
memory: 7508kb

input:

2 4163
1 790277286
2 763894393
2 322193685
2 724891720
2 477186471
2 130318815
2 448598387
2 934582586
2 755424724
2 408157030
2 383717615
2 361736424
2 885848767
2 415478506
2 433214016
2 249463387
2 86227659
2 381128704
2 180941538
2 230260809
2 313401061
2 874038533
2 781675685
2 339357136
2 1614...

output:

1034079385209

result:

ok single line: '1034079385209'

Test #53:

score: 0
Accepted
time: 1ms
memory: 7400kb

input:

110 4388
1 129329989
2 290770655
3 399085375
4 480394263
5 998084599
6 601669068
7 976030367
7 654350436
8 380191293
9 128462385
10 435930271
11 617820729
8 509826083
12 773630320
13 29155358
14 40756873
15 676289561
16 597719328
17 853617983
18 727413460
18 728104236
19 517523345
20 136755862
12 54...

output:

1127480276183

result:

ok single line: '1127480276183'

Test #54:

score: 0
Accepted
time: 3ms
memory: 7548kb

input:

133 4533
1 981373360
2 950241053
2 691321246
2 34700278
2 304373714
3 769268909
3 524168686
4 230905187
4 758609460
5 799069986
5 987124992
6 894207766
6 412045712
2 987074888
7 576433866
7 16062561
7 66876089
7 399361925
7 143989268
7 576793183
7 604689553
7 152226793
7 313746254
7 728803328
7 5207...

output:

1141003981040

result:

ok single line: '1141003981040'

Test #55:

score: 0
Accepted
time: 1ms
memory: 9480kb

input:

1 4999
1 295391035
1 196472221
1 340660725
1 715185782
1 936519692
1 307450161
1 364305579
1 609135879
1 14555582
1 691886765
1 96885367
1 666972226
1 696216099
1 886834387
1 705696297
1 241496338
1 760998611
1 221849757
1 169070630
1 392736300
1 443509648
1 42218117
1 555255985
1 844348180
1 301198...

output:

1243420232820

result:

ok single line: '1243420232820'

Subtask #4:

score: 45
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #56:

score: 45
Accepted
time: 4ms
memory: 7488kb

input:

8275 4844
1 107176958
2 220278740
3 824198376
4 659292090
5 583192157
6 160643819
7 557329363
8 260681680
9 496275861
10 858165732
11 732553326
12 772560828
13 783345064
14 711374681
15 492845246
16 860862812
17 196965386
18 820776112
19 455804299
20 350615945
21 278193443
22 837935011
23 828959959
...

output:

4075544302733

result:

ok single line: '4075544302733'

Test #57:

score: 0
Accepted
time: 14ms
memory: 8752kb

input:

31089 18103
1 220776148
2 692381056
3 346957199
4 713647714
5 714759568
6 924734592
7 659276882
8 851637822
9 448371335
10 809574888
11 340376373
12 726397625
13 330389128
14 815108721
15 739332880
16 680592803
17 89540638
18 865581855
19 124042339
20 134606221
21 882819008
22 659695235
23 979295548...

output:

15494390766791

result:

ok single line: '15494390766791'

Test #58:

score: 0
Accepted
time: 14ms
memory: 10084kb

input:

53299 30967
1 855240498
2 154546935
3 234034227
4 308783540
5 567404088
6 936699401
7 175478476
8 275564115
9 593725435
10 709911797
11 183871063
12 165826746
13 216306032
14 856542036
15 584479452
16 720403214
17 830100662
18 615363483
19 983834172
20 524083998
21 210643476
22 406935995
23 37216820...

output:

26365637274114

result:

ok single line: '26365637274114'

Test #59:

score: 0
Accepted
time: 19ms
memory: 10936kb

input:

67684 39423
1 255518383
2 383661588
3 4810446
4 525628041
5 379438718
6 49421468
7 213128275
8 125716504
9 857695694
10 624656565
11 772321426
12 201754727
13 254786355
14 942071029
15 273736495
16 102807767
17 551341975
18 345946666
19 621677927
20 583679679
21 993753318
22 183768877
23 538570621
2...

output:

33302307710368

result:

ok single line: '33302307710368'

Test #60:

score: 0
Accepted
time: 35ms
memory: 12148kb

input:

90485 52695
1 805472417
2 142689110
3 189995996
4 810067756
5 661480709
6 278044642
7 97014836
8 386959386
9 977471172
10 22636387
11 573815741
12 694548433
13 125152039
14 225054605
15 299499113
16 479863003
17 640033253
18 282736250
19 245410175
20 105257314
21 11870447
22 801974433
23 213321971
2...

output:

44808404427421

result:

ok single line: '44808404427421'

Test #61:

score: 0
Accepted
time: 41ms
memory: 13348kb

input:

112735 65518
1 770253575
2 702318170
3 60500435
4 804626739
5 813851632
6 484971768
7 24909175
8 12890887
9 89428361
10 754404032
11 957005697
12 178803175
13 722313583
14 575657518
15 58038477
16 764832669
17 626600690
18 826603573
19 332205771
20 536935132
21 385919441
22 749816896
23 599294667
24...

output:

55559390823214

result:

ok single line: '55559390823214'

Test #62:

score: 0
Accepted
time: 40ms
memory: 14220kb

input:

128111 74216
1 594119529
2 260263871
3 829129790
4 61304166
5 811667305
6 29091825
7 808999584
8 630333265
9 908673310
10 326488311
11 347753141
12 993128333
13 521976795
14 106445243
15 202368820
16 295607568
17 332963552
18 628933468
19 449004697
20 703192018
21 347147017
22 659973506
23 617736879...

output:

63232674003693

result:

ok single line: '63232674003693'

Test #63:

score: 0
Accepted
time: 44ms
memory: 14936kb

input:

141176 82297
1 693896082
2 79828028
3 185755259
4 302343462
5 101215041
6 392777750
7 496547882
8 961959873
9 975630380
10 86825681
11 193034187
12 958787727
13 600476297
14 574954348
15 258881306
16 386482322
17 653190785
18 300244850
19 299002936
20 56767592
21 44074865
22 61313002
23 387756829
24...

output:

69570597946144

result:

ok single line: '69570597946144'

Test #64:

score: 0
Accepted
time: 45ms
memory: 16120kb

input:

168797 97750
1 953762145
2 799653575
3 1693874
4 481530444
5 618905386
6 84586432
7 604558470
8 733939636
9 119634667
10 378779334
11 393137791
12 88373950
13 834382536
14 286343064
15 631643377
16 388571861
17 805499739
18 673163352
19 149875713
20 29527414
21 136717980
22 759353773
23 516523087
24...

output:

83148807654414

result:

ok single line: '83148807654414'

Test #65:

score: 0
Accepted
time: 62ms
memory: 16336kb

input:

178123 103497
1 799897547
2 350049341
3 602276190
4 239135262
5 449577991
6 201935059
7 670043933
8 23173584
9 651774829
10 143862754
11 148567463
12 969988892
13 330401500
14 639067340
15 2839664
16 766746197
17 317219594
18 904299165
19 701510656
20 657600489
21 308303150
22 806929977
23 703531873...

output:

87922013507367

result:

ok single line: '87922013507367'

Test #66:

score: 0
Accepted
time: 36ms
memory: 10032kb

input:

299999 1
1 999997465
2 999994753
3 999993664
4 999996715
5 999991685
6 999998127
7 999997919
8 999997810
9 999993252
10 999993638
11 999992883
12 999993745
13 999997176
14 999995711
15 999998055
16 999991642
17 999993988
18 999997447
19 999997938
20 999996156
21 999990673
22 999998809
23 999999052
2...

output:

0

result:

ok single line: '0'

Test #67:

score: 0
Accepted
time: 34ms
memory: 10132kb

input:

299998 2
1 999993391
2 999996797
3 999991089
4 999993962
5 999994302
6 999990803
7 999998852
8 999997178
9 999998736
10 999991151
11 999996817
12 999994568
13 999996902
14 999990160
15 999998260
16 999996451
17 999999867
18 999994198
19 999998818
20 999997700
21 999997168
22 999992567
23 999993149
2...

output:

299996497393509

result:

ok single line: '299996497393509'

Test #68:

score: 0
Accepted
time: 25ms
memory: 10080kb

input:

299225 775
1 999998776
2 999997156
1 999995160
3 999995715
4 999991136
1 999998420
5 999995988
6 999990059
7 999997337
1 999993785
8 999996221
9 999995600
10 999990545
11 999998417
1 999994805
12 999995940
13 999998401
14 999998355
15 999996967
16 999998722
1 999994420
17 999996725
18 999997240
19 9...

output:

150081246669606

result:

ok single line: '150081246669606'

Test #69:

score: 0
Accepted
time: 66ms
memory: 19388kb

input:

149999 150000
1 554189173
2 861829121
3 829225860
4 213727479
5 709963472
6 663058323
7 106603412
8 193968115
9 684958486
10 798003824
11 988653395
12 973775624
13 965416432
14 199873632
15 223220546
16 543610533
17 555993281
18 779801339
19 287656905
20 403322991
21 754473197
22 649725593
23 710654...

output:

111986891597599

result:

ok single line: '111986891597599'

Test #70:

score: 0
Accepted
time: 77ms
memory: 19428kb

input:

147647 152352
1 628094974
2 266020444
3 538104237
4 313406555
5 376225212
6 128442827
7 546510616
8 627079273
9 108509057
10 181584742
11 73186271
12 23935714
13 255254909
14 420517059
15 227071778
16 795557107
17 759470503
18 95306732
19 556905309
20 23904052
21 321104723
22 723218408
23 160861032
...

output:

106170824468065

result:

ok single line: '106170824468065'

Test #71:

score: 0
Accepted
time: 70ms
memory: 19064kb

input:

147747 152252
1 913818026
2 961911782
3 181336455
4 413853399
5 275487951
6 239850086
7 971859410
8 981567962
9 419692709
10 306792960
11 384634970
12 110167204
13 346432546
14 552870783
15 402364107
16 840562262
17 963948724
18 859518188
19 132069845
20 51081807
21 491020892
22 908407419
23 7429238...

output:

106256085275254

result:

ok single line: '106256085275254'

Test #72:

score: 0
Accepted
time: 118ms
memory: 28596kb

input:

2982 297006
1 930075003
1 590093806
1 117783415
1 856438532
1 835931093
1 631019809
1 95609726
1 802210206
1 640533192
1 221717347
1 427822138
1 204492427
1 377719638
1 502396171
1 269726069
1 980303145
1 961558794
1 442356860
1 258344489
1 454601583
1 690144959
1 263078306
1 757926942
1 385004851
1...

output:

73845050003347

result:

ok single line: '73845050003347'

Test #73:

score: 0
Accepted
time: 105ms
memory: 28452kb

input:

3003 296965
1 205758931
1 101020775
1 713047771
1 241600845
1 596510598
1 395330454
1 430561222
1 386119238
1 842754861
1 7950041
1 537941351
1 634350197
1 643217738
1 648841046
1 558326891
1 486190744
1 102100148
1 983564385
1 454316863
1 404848895
1 111019746
1 676950906
1 691826059
1 609373972
1 ...

output:

74124179113620

result:

ok single line: '74124179113620'

Test #74:

score: 0
Accepted
time: 103ms
memory: 28840kb

input:

556 299213
1 822254263
1 461344563
1 969727098
1 2496619
1 186391023
1 291140655
1 996031902
1 405953538
1 788833448
1 655320287
1 674646536
1 520107569
1 61546150
1 524559096
1 55461590
1 440979833
1 890852005
1 967585214
1 514337445
1 908507406
1 587038393
1 681472967
1 964152371
1 631056337
1 276...

output:

74536361263414

result:

ok single line: '74536361263414'

Test #75:

score: 0
Accepted
time: 124ms
memory: 28312kb

input:

547 299336
1 275207239
2 158520026
2 78057664
2 471627439
2 621640300
2 165817560
2 848725133
2 842810653
2 965141122
2 921076897
2 284741537
2 418043038
2 150458729
2 429072536
2 26319012
2 692526144
2 552639828
2 828179266
2 986781761
2 869245937
2 712337880
2 40836642
2 275740910
2 570367791
2 83...

output:

74670326835464

result:

ok single line: '74670326835464'

Test #76:

score: 0
Accepted
time: 126ms
memory: 28624kb

input:

148 297658
1 249902206
1 621047085
1 329925101
1 425583316
1 161422118
1 766418544
1 567889954
1 784643568
1 850331315
1 181127169
1 70463852
1 196004175
1 88959060
1 701839941
1 682149357
1 465573745
1 287028458
1 939109514
1 41770546
1 272965804
1 930530350
1 332458655
1 632709369
1 973853010
1 16...

output:

74066800366955

result:

ok single line: '74066800366955'

Test #77:

score: 0
Accepted
time: 100ms
memory: 28224kb

input:

153 298512
1 287723200
1 471371331
1 378527194
1 664526236
1 907761024
1 943332544
1 305349563
1 769592690
1 250866047
1 420524898
1 364429598
1 919503755
1 770786360
1 507537547
1 874398336
1 794562188
1 941623177
1 552523675
1 296022121
1 567074456
1 544191981
1 384676502
1 603998526
1 727879900
1...

output:

74331631754273

result:

ok single line: '74331631754273'

Test #78:

score: 0
Accepted
time: 141ms
memory: 28272kb

input:

2066 290658
1 615414698
2 862401797
3 543802391
4 120919462
5 612877381
6 234741699
7 621336369
8 788191097
9 630325559
10 170877791
11 51807792
12 222341418
13 220007702
14 767870581
15 530213700
16 467384622
17 988490051
18 693337882
19 20065180
20 721071134
21 973950188
22 374085805
23 770993972
...

output:

72818357741108

result:

ok single line: '72818357741108'

Test #79:

score: 0
Accepted
time: 136ms
memory: 27748kb

input:

780 292489
1 997556321
2 910768044
2 663206818
2 848566643
2 917636268
1 397166348
1 589877005
3 329139941
4 270376275
4 69707215
4 531962798
5 57155005
5 754759950
6 562340510
6 175076539
6 900793148
6 105536877
7 601467796
7 597554666
7 44679342
7 473400890
8 272444719
9 273651546
9 975360347
9 42...

output:

73036155725083

result:

ok single line: '73036155725083'

Test #80:

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

input:

1 299999
1 607350158
1 653685957
1 456250530
1 316455876
1 943455503
1 939680458
1 128374332
1 928290756
1 425429964
1 714366369
1 220313558
1 62798931
1 883042613
1 811385014
1 260869576
1 256247862
1 933328890
1 92087534
1 74810109
1 591454527
1 261609331
1 153721086
1 806353774
1 136220434
1 6852...

output:

74718409994641

result:

ok single line: '74718409994641'