QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#352484#7785. Three RectanglesOccDreamer#WA 503ms3908kbC++143.4kb2024-03-13 11:29:372024-03-13 11:29:41

Judging History

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

  • [2024-03-13 11:29:41]
  • 评测
  • 测评结果:WA
  • 用时:503ms
  • 内存:3908kb
  • [2024-03-13 11:29:37]
  • 提交

answer

// We are the dreamers , we make it happen !
// I see, I like, I go again !
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define db double
#define mkp make_pair
#define pii pair<int, int>
#define vc vector
#define pb emplace_back

//#define int long long

using namespace std;
const int N = 1e6 + 5, P = 1e9 + 7;
const int inf = 0x3f3f3f3f;
//const ll inf = 0x3f3f3f3f3f3f3f3f;

mt19937 gen(time(0));

inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
} 
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10); 
putchar(x % 10 + '0');
}
inline void writec(int x) { write(x); putchar(32); }
inline void writee(int x) { write(x); putchar(10); }

inline void inc(int &x, int y) { x += y - P; x += (x >> 31) & P; }
inline void dec(int &x, int y) { x -= y; x += (x >> 31) & P; }
inline int pls(int x, int y) { x += y - P; x += (x >> 31) & P; return x; }
inline int power(int a, int b) { int res = 1; for(; b; b >>= 1, a = 1ll * a * a % P) if(b & 1) res = 1ll * res * a % P; return res; } 

int H, W, ans, c[5], h[5], w[5];
vc<pii> o[5];

inline bool check(vc<pii> cur) {

auto ok = [&](vc<pii> cur, int lmt) -> bool {
sort(cur.begin(), cur.end()); int p = 0;
for(auto u: cur) 
if(u.first > p + 1) return 0;
else p = max(p, u.second);
return p == lmt; 
};

vc<int> pos; pos.pb(1); pos.pb(W);
for(int i = 1; i <= 3; i++) pos.pb(cur[i].second + w[i]);
for(auto u: pos) if(u <= W) {
vc<pii> now;
for(int i = 1; i <= 3; i++) if(cur[i].second <= u && cur[i].second + w[i] - 1 >= u)
now.pb(mkp(cur[i].first, cur[i].first + h[i] - 1));
if(!ok(now, H)) return 0;
}
return 1;
}

int TIME;
inline void solve() {
H = read(); W = read(); int all = 1, sum = 0; ans = 0;
ll mask = 0;
for(int i = 1, len; i <= 3; i++) {
h[i] = read(); w[i] = read(); mask += 1ll * h[i] * w[i];
c[i] = 1ll * (H - h[i] + 1) * (W - w[i] + 1) % P; 
all = 1ll * all * c[i] % P; inc(sum, c[i]);
o[i].clear();
o[i].pb(mkp(1, 1));
o[i].pb(mkp(1, W - w[i] + 1));
o[i].pb(mkp(H - h[i] + 1, 1));
o[i].pb(mkp(H - h[i] + 1, W - w[i] + 1));
sort(o[i].begin(), o[i].end()); 
len = unique(o[i].begin(), o[i].end()) - o[i].begin();
while(o[i].size() > len) o[i].pop_back();
}

if(mask < 1ll * H * W) return puts("0"), void();
for(int i = 1; i <= 3; i++) if(c[i] == 1) return writee(all), void();

for(int i = 1, l, r, k; i <= 3; i++) if(h[i] == H) 
for(int j = 1; j <= 3; j++) if(i != j && h[j] == H) {
l = w[i]; r = W - w[j] + 1; k = 6 - i - j;
if(l + 1 < r) {
if(h[k] == H) 
inc(ans, max(0, min(l + 1, W - w[k]) - max(r - w[k], 2) + 1));
}
else inc(ans, pls(c[k], P - o[k].size()));
}

for(int i = 1, l, r, k; i <= 3; i++) if(w[i] == W)
for(int j = 1; j <= 3; j++) if(i != j && w[j] == W) {
l = h[i]; r = H - h[j] + 1; k = 6 - i - j;
if(l + 1 < r) {
if(w[k] == W) 
inc(ans, max(0, min(l + 1, H - h[k]) - max(r - h[k], 2) + 1));
}
else inc(ans, pls(c[k], P - o[k].size()));
}

for(auto x: o[1]) for(auto y: o[2]) for(auto z: o[3]) {
vc<pii> cur; 
cur.pb(mkp(0, 0)); cur.pb(x); cur.pb(y); cur.pb(z);
if(check(cur)) ++ans;
}
writee(ans % P);
}

signed main() {
int t = read(); while(t--) solve();
return 0;
}



 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3724kb

input:

5
2 2
1 1
1 1
1 1
2 2
1 1
1 2
1 2
2 2
1 1
1 2
2 1
2 2
1 2
1 2
1 2
2 2
1 2
1 2
2 1

output:

0
8
4
6
4

result:

ok 5 number(s): "0 8 4 6 4"

Test #2:

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

input:

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

output:

6
12
14
6

result:

ok 4 number(s): "6 12 14 6"

Test #3:

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

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

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

input:

729
999999999 111111111
111111111 111111111
111111111 111111111
111111111 111111111
999999999 111111111
111111111 111111111
222222222 111111111
111111111 111111111
999999999 111111111
111111111 111111111
111111111 111111111
333333333 111111111
999999999 111111111
111111111 111111111
444444444 111111...

output:

0
0
0
0
0
0
6
777777753
456790164
0
0
0
0
0
6
222222208
555555531
135802502
0
0
0
0
6
222222208
222222208
333333309
814814847
0
0
0
6
222222208
222222208
222222208
111111087
493827185
0
0
6
222222208
222222208
222222208
222222208
888888872
172839523
0
6
222222208
222222208
222222208
222222208
222222...

result:

ok 729 numbers

Test #5:

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

input:

5832
999999999 222222222
111111111 111111111
111111111 111111111
111111111 111111111
222222222 999999999
111111111 111111111
111111111 111111111
111111111 222222222
222222222 999999999
111111111 111111111
111111111 111111111
111111111 333333333
999999999 222222222
111111111 111111111
111111111 11111...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
413046795
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
989330902
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
565615002
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
141899102
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
718183209
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
294467309
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
87...

result:

ok 5832 numbers

Test #6:

score: 0
Accepted
time: 68ms
memory: 3592kb

input:

19683
999999999 333333333
111111111 111111111
111111111 111111111
111111111 111111111
999999999 333333333
111111111 111111111
111111111 111111111
222222222 111111111
999999999 333333333
333333333 111111111
111111111 111111111
111111111 111111111
999999999 333333333
111111111 111111111
444444444 1111...

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
239292815
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
477213862
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
715134909
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
953055956
0
0
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 19683 numbers

Test #7:

score: 0
Accepted
time: 167ms
memory: 3688kb

input:

46656
999999999 444444444
111111111 111111111
111111111 111111111
111111111 111111111
999999999 444444444
111111111 111111111
111111111 111111111
222222222 111111111
444444444 999999999
111111111 333333333
111111111 111111111
111111111 111111111
999999999 444444444
444444444 111111111
111111111 1111...

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
935528231
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
599451396
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
263374561
0
0
0
0
0
0
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 46656 numbers

Test #8:

score: 0
Accepted
time: 323ms
memory: 3880kb

input:

91125
999999999 555555555
111111111 111111111
111111111 111111111
111111111 111111111
555555555 999999999
111111111 222222222
111111111 111111111
111111111 111111111
555555555 999999999
111111111 111111111
111111111 111111111
111111111 333333333
999999999 555555555
111111111 111111111
444444444 1111...

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
501753029
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
356043497
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
210333965
0
0
0
...

result:

ok 91125 numbers

Test #9:

score: 0
Accepted
time: 292ms
memory: 3688kb

input:

100000
666666666 999999999
111111111 111111111
111111111 111111111
111111111 111111111
999999999 666666666
222222222 111111111
111111111 111111111
111111111 111111111
666666666 999999999
111111111 111111111
111111111 111111111
111111111 333333333
999999999 666666666
111111111 111111111
444444444 111...

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
937967223
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
746990172
0
0
0
0
0
0
0
0
0
0
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 #10:

score: 0
Accepted
time: 266ms
memory: 3584kb

input:

57464
666666666 999999999
444444444 888888888
222222222 777777777
666666666 222222222
999999999 666666666
333333333 666666666
888888888 444444444
777777777 222222222
999999999 666666666
444444444 666666666
777777777 222222222
888888888 444444444
666666666 999999999
666666666 555555555
222222222 7777...

output:

4
4
4
4
4
4
4
232891329
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
4
4
109586954
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
4
271604940
4
4
4
4
4
4
4
4
271604940
4
4
4
4
4
4
4
4
986282586
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 57464 numbers

Test #11:

score: 0
Accepted
time: 230ms
memory: 3908kb

input:

100000
777777777 999999999
111111111 111111111
111111111 111111111
111111111 111111111
999999999 777777777
222222222 111111111
111111111 111111111
111111111 111111111
777777777 999999999
111111111 111111111
111111111 111111111
111111111 333333333
777777777 999999999
111111111 111111111
111111111 111...

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
244170799
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
772291414
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 428ms
memory: 3648kb

input:

100000
999999999 777777777
222222222 333333333
444444444 222222222
888888888 333333333
999999999 777777777
444444444 222222222
888888888 333333333
333333333 333333333
999999999 777777777
888888888 333333333
444444444 222222222
444444444 333333333
999999999 777777777
888888888 333333333
444444444 222...

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
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
669562568
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
980643199
0
0
0
0
0
0
0
0
0
0
0
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 #13:

score: 0
Accepted
time: 239ms
memory: 3624kb

input:

50047
777777777 999999999
555555555 333333333
333333333 777777777
666666666 666666666
999999999 777777777
777777777 333333333
666666666 666666666
444444444 555555555
777777777 999999999
666666666 666666666
333333333 777777777
555555555 555555555
777777777 999999999
555555555 666666666
333333333 7777...

output:

0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
4
4
4
4
4
4
356195704
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
4
4
4
4
4
4
377686331
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
4
4
4
4
4
296296298
0
0
4
4
4
4
4
4
296296298
0
...

result:

ok 50047 numbers

Test #14:

score: 0
Accepted
time: 192ms
memory: 3908kb

input:

100000
888888888 999999999
111111111 111111111
111111111 111111111
111111111 111111111
888888888 999999999
111111111 222222222
111111111 111111111
111111111 111111111
999999999 888888888
333333333 111111111
111111111 111111111
111111111 111111111
999999999 888888888
111111111 111111111
111111111 111...

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
420363771
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
431947...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 306ms
memory: 3820kb

input:

100000
888888888 999999999
888888888 222222222
333333333 333333333
333333333 222222222
888888888 999999999
333333333 222222222
333333333 333333333
888888888 333333333
999999999 888888888
333333333 333333333
444444444 888888888
222222222 333333333
999999999 888888888
222222222 333333333
333333333 333...

output:

0
0
0
0
0
0
0
638774850
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
584667189
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #16:

score: 0
Accepted
time: 471ms
memory: 3668kb

input:

100000
999999999 888888888
333333333 777777777
333333333 555555555
666666666 555555555
999999999 888888888
444444444 777777777
666666666 555555555
333333333 555555555
888888888 999999999
555555555 666666666
777777777 555555555
555555555 333333333
888888888 999999999
777777777 666666666
555555555 666...

output:

0
0
0
0
0
0
4
0
0
0
0
0
4
4
4
617283975
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
4
4
4
288065855
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
...

result:

ok 100000 numbers

Test #17:

score: 0
Accepted
time: 359ms
memory: 3816kb

input:

73248
888888888 999999999
777777777 444444444
666666666 444444444
777777777 999999999
888888888 999999999
666666666 555555555
777777777 999999999
777777777 444444444
999999999 888888888
666666666 666666666
444444444 777777777
999999999 777777777
999999999 888888888
444444444 777777777
999999999 7777...

output:

0
4
4
4
4
345679014
0
0
0
0
4
4
4
4
345679014
0
0
0
0
4
4
4
4
685871061
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
345679014
277091911
0
0
0
0
0
0
0
0
0
0
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 73248 numbers

Test #18:

score: 0
Accepted
time: 170ms
memory: 3652kb

input:

100000
999999999 999999999
111111111 111111111
111111111 111111111
111111111 111111111
999999999 999999999
111111111 222222222
111111111 111111111
111111111 111111111
999999999 999999999
111111111 333333333
111111111 111111111
111111111 111111111
999999999 999999999
111111111 111111111
111111111 111...

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
466546132
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #19:

score: 0
Accepted
time: 240ms
memory: 3904kb

input:

100000
999999999 999999999
333333333 222222222
666666666 222222222
222222222 777777777
999999999 999999999
333333333 666666666
222222222 333333333
777777777 222222222
999999999 999999999
222222222 777777777
333333333 222222222
666666666 444444444
999999999 999999999
222222222 333333333
555555555 666...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
783722091
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
480109819
0
0
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 #20:

score: 0
Accepted
time: 370ms
memory: 3724kb

input:

100000
999999999 999999999
444444444 555555555
444444444 444444444
333333333 222222222
999999999 999999999
222222222 444444444
444444444 444444444
555555555 444444444
999999999 999999999
222222222 555555555
444444444 444444444
555555555 444444444
999999999 999999999
555555555 444444444
222222222 666...

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
4
4
4
4
243560539
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
0
0
0
0
...

result:

ok 100000 numbers

Test #21:

score: 0
Accepted
time: 478ms
memory: 3820kb

input:

100000
999999999 999999999
666666666 111111111
777777777 444444444
777777777 555555555
999999999 999999999
111111111 666666666
555555555 777777777
555555555 777777777
999999999 999999999
555555555 777777777
111111111 666666666
666666666 777777777
999999999 999999999
777777777 777777777
111111111 666...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
409236420
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
919067235
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #22:

score: 0
Accepted
time: 503ms
memory: 3728kb

input:

100000
999999999 999999999
777777777 999999999
555555555 333333333
777777777 777777777
999999999 999999999
333333333 666666666
999999999 777777777
777777777 777777777
999999999 999999999
999999999 777777777
777777777 777777777
333333333 777777777
999999999 999999999
333333333 888888888
999999999 777...

output:

4
4
4
4
4
0
4
4
4
4
4
4
4
4
0
4
4
4
4
4
4
4
4
0
4
4
4
4
4
4
4
4
0
4
4
4
4
4
4
4
4
0
4
4
4
4
4
4
4
4
0
98765434
98765434
98765434
98765434
98765434
98765434
98765434
72702332
0
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
...

result:

ok 100000 numbers

Test #23:

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

input:

31441
999999999 999999999
888888888 666666666
999999999 555555555
222222222 888888888
999999999 999999999
555555555 999999999
777777777 888888888
888888888 222222222
999999999 999999999
888888888 888888888
888888888 222222222
555555555 999999999
999999999 999999999
999999999 888888888
888888888 2222...

output:

4
4
4
4
0
0
0
395061730
395061730
395061730
395061730
395061730
50754460
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
4
4
4
4
888888890
0
0
0
4
4
4
4
4
888888890
0
0
0
555555549
555555549
555555549
555555549
555555549
456790140
0...

result:

ok 31441 numbers

Test #24:

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

input:

1000
1000000000 100000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 100000000
100000000 100000000
100000000 100000000
200000000 100000000
1000000000 100000000
100000000 100000000
100000000 100000000
300000000 100000000
100000000 1000000000
100000000 100000000
100000000 4...

output:

0
0
0
0
0
0
0
6
799999979
130000029
0
0
0
0
0
0
6
199999988
599999979
660000029
0
0
0
0
0
6
199999988
199999988
399999979
190000022
0
0
0
0
6
199999988
199999988
199999988
199999979
720000022
0
0
0
6
199999988
199999988
199999988
199999988
999999986
250000015
0
0
6
199999988
199999988
199999988
1999...

result:

ok 1000 numbers

Test #25:

score: 0
Accepted
time: 27ms
memory: 3592kb

input:

8000
200000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 200000000
100000000 100000000
100000000 100000000
200000000 100000000
1000000000 200000000
100000000 100000000
300000000 100000000
100000000 100000000
1000000000 200000000
400000000 100000000
100000000 1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
781700008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
829400008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
877100008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
924800008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
972500008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
20200001
0
0
0
0
0
0
0...

result:

ok 8000 numbers

Test #26:

score: -100
Wrong Answer
time: 83ms
memory: 3620kb

input:

27000
300000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
300000000 1000000000
100000000 100000000
100000000 200000000
100000000 100000000
1000000000 300000000
300000000 100000000
100000000 100000000
100000000 100000000
1000000000 300000000
100000000 100000000
100000000 ...

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
500800008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
585600008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
670400008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
755200008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 148th numbers differ - expected: '0', found: '264000001'