QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#829067#9776. Best Friend, Worst EnemyCrysflyAC ✓366ms19224kbC++143.3kb2024-12-24 01:15:472024-12-24 01:15:48

Judging History

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

  • [2024-12-24 01:15:48]
  • 评测
  • 测评结果:AC
  • 用时:366ms
  • 内存:19224kb
  • [2024-12-24 01:15:47]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ull unsigned long long
//#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?-x:x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 400005
#define inf 0x3f3f3f3f

int n,x[maxn],y[maxn];
int mxx[23],mx;

bool vis[maxn];

int nn;

int R;
int rx,ry;
int tx[maxn],ty[maxn],tim[maxn];

map<pii,int>mp;
void add(int u,bool fl=0){
    int xx=x[u]/R,yy=y[u]/R;
    if(mp.count(mkp(xx,yy))){
    	int u=mp[mkp(xx,yy)];
    	if(u!=-1) tim[u]=min(tim[u],nn);//cout<<"QAQ "<<u<<" "<<nn+1<<endl;
        mp[mkp(xx,yy)]=-1;
    }else{
        mp[mkp(xx,yy)]=u;
        if(!fl) vis[u]=1,tim[u]=n;
    }
}

void rebuild(int qwq){
    R=max(qwq,1);
    mp.clear();
    For(i,1,nn) add(i,1);
    //for(auto [x,y]:mp) if(y!=-1) vis[y]=1;
}

int getmx(int x,int y){
    int mx=0;
    For(s,0,3){
        int sum=((s&1)?(-x):(x))+((s&2)?(-y):y);
        mx=max(mx,sum+mxx[s^3]);
    }
    return mx;
}

int d1[maxn],d2[maxn],res[maxn];
int mxs[maxn],mns[maxn];
int nxt[maxn];
void solve(int u){
//    cout<<"solve "<<u<<" "<<tim[u]<<"\n";
    int mn=inf,mx=0;
    int n=tim[u];
    For(i,1,n){
        if(i!=u){
            mx=max(mx,abs(x[i]-x[u])+abs(y[i]-y[u]));
            mn=min(mn,max(abs(x[i]-x[u]),abs(y[i]-y[u])));
        }
        mxs[i]=mx;
        mns[i]=mn;
    }
    nxt[n]=n+1;
    Rep(i,n-1,1){
        nxt[i]=nxt[i+1];
        if(mns[i+1]!=mns[i] || mxs[i+1]!=mxs[i]) nxt[i]=i+1;
    }
    For(i,1,n){
        if(i!=u){
            int d1=abs(x[i]-x[u])+abs(y[i]-y[u]);
            int d2=max(abs(x[i]-x[u]),abs(y[i]-y[u]));
            
            int t=max(i,u);
            if(d1==mxs[t] && d2==mns[t]) {
                int t2=nxt[t];
                res[t]++;
                res[t2]--;
            }
        }
    }
}

void work()
{
    cin>>n;
    For(i,1,n)cin>>x[i]>>y[i];
    memset(mxx,-63,sizeof mxx);
	vis[1]=vis[2]=1;
	tim[1]=tim[2]=n;
    For(i,1,n){
        nn=i;
        int lstmx=mx;
        For(s,0,3){
            int sum=((s&1)?(-x[i]):(x[i]))+((s&2)?(-y[i]):y[i]);
            mx=max(mx,sum+mxx[s^3]);
        }
        For(s,0,3){
            int sum=((s&1)?(-x[i]):(x[i]))+((s&2)?(-y[i]):y[i]);
            mxx[s]=max(mxx[s],sum);
        }
        if(i==1) continue;
        int R1=max(mx/4-1,1);
        if(i==2 || R1>R*1.2){
            nn=i-1;rebuild(R1);
			nn=i;add(i);
        }else{
            nn=i;add(i);
        }
    }
    For(i,1,n) if(vis[i]) {
        solve(i);
    }
    For(i,1,n){
        res[i]+=res[i-1];
        cout<<res[i]<<"\n";
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    while(T--)work();
    return 0;
}
/*

*/

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

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

input:

4
2 5
5 3
5 7
8 5

output:

0
2
4
4

result:

ok 4 number(s): "0 2 4 4"

Test #3:

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

input:

9
3 4
3 6
4 3
4 7
5 5
6 3
6 7
7 4
7 6

output:

0
2
1
0
4
5
6
7
8

result:

ok 9 numbers

Test #4:

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

input:

13
3 5
4 4
4 5
4 6
5 3
5 4
5 5
5 6
5 7
6 4
6 5
6 6
7 5

output:

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

result:

ok 13 numbers

Test #5:

score: 0
Accepted
time: 178ms
memory: 18960kb

input:

384010
200000 1000000
200000 1000001
199999 1000000
200001 1000000
200000 999999
200000 1000002
200002 1000000
200000 999998
199998 1000000
199997 1000000
200003 1000000
200000 999997
200000 1000003
199996 1000000
200004 1000000
200000 1000004
200000 999996
199995 1000000
200000 1000005
200000 99999...

output:

0
2
4
7
12
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 384010 numbers

Test #6:

score: 0
Accepted
time: 191ms
memory: 16284kb

input:

400000
4991900 4984622
5004814 4985991
5008541 4983572
4988786 4997631
4995878 5010759
5026284 4998073
5034229 5000047
4983273 5019232
5007885 4993982
5010953 5021220
5026656 5007819
4976562 5013785
4978425 4988215
5000231 4977049
4987937 5023473
5024616 5009522
5002045 4977502
4988899 5014905
49866...

output:

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #7:

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

input:

399999
420000 500000
420001 500001
420002 500002
420003 500003
420004 500004
420005 500005
420006 500006
420007 500007
420008 500008
420009 500009
420010 500010
420011 500011
420012 500012
420013 500013
420014 500014
420015 500015
420016 500016
420017 500017
420018 500018
420019 500019
420020 500020...

output:

0
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 399999 numbers

Test #8:

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

input:

400000
5000000 5000000
4637207 1362793
6296942 2296942
6971218 2971218
6214485 2214485
8086725 4086725
8414337 5585663
5685949 1685949
1702684 5702684
6472899 7527101
5941033 1941033
7192827 3192827
6379191 2379191
2347274 6347274
7180991 6819009
8685943 5314057
7160303 3160303
6928903 7071097
44215...

output:

0
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 400000 numbers

Test #9:

score: 0
Accepted
time: 83ms
memory: 19168kb

input:

399913
5000000 7000000
5000000 6000000
3000000 5000000
4000000 5000000
5000000 5000000
6000000 5000000
7000000 5000000
5000000 4000000
5000000 3000000
5357589 6392898
4901211 6444181
5188225 6102824
4788614 6242360
4802804 6288663
4734311 6103748
5031314 6227375
5100725 6211516
5247076 6358750
48076...

output:

0
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 399913 numbers

Test #10:

score: 0
Accepted
time: 75ms
memory: 17116kb

input:

400000
3000000 8000000
3012636 7948165
6021732 4424572
3110512 7383392
2224678 6167889
6730174 3825314
2667414 7371648
3292265 6926643
2241546 6521035
6270139 1705913
4006880 6643854
4088241 6232389
3768770 6333837
3755946 6344466
6239447 3896690
7067142 2259147
2791441 7083567
2045838 6505125
72353...

output:

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #11:

score: 0
Accepted
time: 58ms
memory: 15528kb

input:

400000
4000000 1000000
2000000 4000000
3971122 1730490
4198723 1332093
1891848 4399763
3883748 1754618
1318432 3775511
3824641 1583152
1718804 3837530
1992199 4221010
1863470 4175370
1634863 4587694
4261069 1328631
1796332 3690458
1611836 4116653
1635254 4407379
1317068 4297964
4046238 1937867
14548...

output:

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #12:

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

input:

400000
4000003 1000001
2000003 4000001
1681540 4618492
1721680 4192318
1986524 4256472
1682732 4538323
1731436 4480115
1471609 3827694
1879802 4357249
1140557 4064455
1809962 4461028
4628899 1636633
1535641 3964206
1953510 3671812
1904251 3298566
4092976 1434705
1481816 4156505
1609477 4445491
36394...

output:

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #13:

score: 0
Accepted
time: 98ms
memory: 19152kb

input:

400000
4999997 8000001
3999997 5000001
5999997 5000001
5217659 2801801
5912267 2981691
4977175 2078224
4984213 2609315
5732901 2796477
4700507 2763210
4857500 7076015
5146689 7537378
4975916 2227084
5335767 2678476
5297317 2382545
4938482 2612155
5002716 7491341
4254058 7030846
4488940 2584804
48196...

output:

0
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #14:

score: 0
Accepted
time: 90ms
memory: 19168kb

input:

400000
4999998 7999993
3999998 4999993
5999998 4999993
4911385 2736908
5207358 7506133
5316688 2415833
4377390 7356539
5572531 2832663
5714897 7236169
4979803 2143629
4162191 2938526
4670816 7342922
4673690 7616930
5257771 2409424
5363441 7609733
5096353 7467363
5288304 7395497
4847351 2920398
49314...

output:

0
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #15:

score: 0
Accepted
time: 366ms
memory: 16012kb

input:

381785
5000000 5000000
4999998 5000000
5000001 5000001
5000002 5000000
5000001 4999999
5000000 4999998
4999999 5000001
4999999 4999999
5000000 5000002
5000003 5000001
5000003 4999999
5000001 5000003
4999996 5000000
4999998 4999998
4999998 5000002
5000001 4999997
4999999 5000003
4999999 4999997
50000...

output:

0
2
1
1
2
3
3
4
4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 381785 numbers

Test #16:

score: 0
Accepted
time: 107ms
memory: 19224kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #17:

score: 0
Accepted
time: 61ms
memory: 17068kb

input:

400000
1000568 5000255
1000132 4999980
1000533 4999684
1000547 4999977
4980604 8000000
1000405 4999821
1000471 4999645
1000393 5000195
1000520 5000355
1000499 4999653
1000329 5000235
1000590 5000281
1000577 4999772
1000111 4999960
1000419 5000408
1000589 4999499
1000443 5000383
1000519 4999953
10005...

output:

0
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #18:

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

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #19:

score: 0
Accepted
time: 64ms
memory: 16084kb

input:

400000
1000541 4999918
1000333 4999730
1000399 4999825
1000399 5000033
1000565 4999952
1000473 5000367
1000406 4999735
1000437 5000266
1000600 4999825
1000556 4999830
1000596 5000282
1000417 4999850
1000582 5000260
4991889 8000000
4990475 2000000
1000534 5000400
1000563 4999657
1000433 4999610
10005...

output:

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #20:

score: 0
Accepted
time: 88ms
memory: 17052kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
...

result:

ok 400000 numbers

Test #21:

score: 0
Accepted
time: 82ms
memory: 16036kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #22:

score: 0
Accepted
time: 91ms
memory: 17120kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #23:

score: 0
Accepted
time: 92ms
memory: 17040kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
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 400000 numbers

Test #24:

score: 0
Accepted
time: 87ms
memory: 17132kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Test #25:

score: 0
Accepted
time: 90ms
memory: 16544kb

input:

400000
1000000 5000000
1000001 4999999
1000001 5000000
1000001 5000001
1000002 4999998
1000002 4999999
1000002 5000000
1000002 5000001
1000002 5000002
1000003 4999997
1000003 4999998
1000003 4999999
1000003 5000000
1000003 5000001
1000003 5000002
1000003 5000003
1000004 4999996
1000004 4999997
10000...

output:

0
2
4
7
2
2
5
2
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 400000 numbers

Extra Test:

score: 0
Extra Test Passed