QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605367#7785. Three RectanglesShwStoneTL 856ms3848kbC++144.3kb2024-10-02 16:52:482024-10-02 16:52:48

Judging History

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

  • [2024-10-02 16:52:48]
  • 评测
  • 测评结果:TL
  • 用时:856ms
  • 内存:3848kb
  • [2024-10-02 16:52:48]
  • 提交

answer

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

// #define FILE_IO
namespace io {
    #ifdef FILE_IO
    #define FREAD
    #define FWRITE
    #endif

    #ifdef FREAD
    static char ibuf[100000], *p1 = ibuf, *p2 = ibuf;
    #define getchar() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
    #endif
    
    #ifdef FWRITE
    static char obuf[100000], *p3 = obuf;
    #define putchar(x) ((p3 - obuf < 100000) ? (*p3++ = (x)) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = (x)))
    struct flasher { ~flasher() { fwrite(obuf, p3 - obuf, 1, stdout); } }flash;
    #endif
    //读入失败返回true
    template <class T> bool read(T &r) {
        r = 0; static char ch = getchar(); bool f = false;
        while (ch < 48 || ch > 57) { if (ch == EOF) return true; if (ch == 45) f ^= 1; ch = getchar(); }
        while (ch >= 48 && ch <= 57) { r = r * 10 + ch - 48; ch = getchar(); }
        if (f) r = -r; return false;
    }
    template <class T> void write(T w, char end = '\n') {
        static char write_buf[55]; char *pos = write_buf;
        if (w == 0) { putchar('0'); putchar(end); return; }
        if (w < 0) { putchar('-'); w = -w; }
        while (w) {
            *(pos++) = w % 10 + '0';
            w /= 10;
        }
        while (pos != write_buf) putchar(*(--pos));
        putchar(end);
    }
};
using namespace io;

#pragma GCC optimize(4)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")

const int MOD(1e9 + 7);

int h, w;
int a[5], b[5];
const int p[4][2] = {
	{0, 0}, 
	{1, 0},
	{0, 1}, 
	{1, 1}
};

int ans;
int cover[5];
pair<int, int> need[5];
set<pair<int, int>> noneed[5];
int mh[5], mw[5];

void dfs(int id) {
	if (id == 4) {
		int sp = -1;
		for (int j = 0; j < 3; j++) 
			if (need[j] == make_pair(-1, -1)) 
				sp = j;
		
		if (sp != -1) {
			int jl = (sp + 1) % 3, jr = (sp + 2) % 3;
			if (need[jr] == make_pair(0, 0)) swap(jl, jr);

			if (a[jl] == h) {
				if (b[jl] + b[jr] < w) {
					if (a[sp] != h) return;
					int l = max(1, w - b[jr] - b[sp]);
					int r = min(w - b[sp] - 1, b[jl]);
					if (l <= r) ans = (ans + r - l + 1) % MOD;
					else return;
				} else ans = (ans + 1ll * (h - a[sp] + 1) * (w - b[sp] + 1) - noneed[sp].size()) % MOD;
			} else {
				if (a[jl] + a[jr] < h) {
					if (b[sp] != w) return;
					int l = max(1, h - a[jr] - a[sp]);
					int r = min(h - a[sp] - 1, a[jl]);
					if (l <= r) ans = (ans + r - l + 1) % MOD;
					else return;
				} else ans = (ans + 1ll * (h - a[sp] + 1) * (w - b[sp] + 1) - noneed[sp].size()) % MOD;
			}
		} else {
			if (
				mh[0] + mh[1] >= h && 
				mh[2] + mh[3] >= h &&
				mw[0] + mw[2] >= w &&
				mw[1] + mw[3] >= w
			) ans = (ans + 1) % MOD;
		}
		return;
	}

	for (cover[id] = 1; cover[id] < 7; cover[id]++) {
		bool book[5] = {0,0,0,0,0};
		mh[id] = mw[id] = 0;
		bool flag = true;
		
		for (int j = 0; j < 3; j++) {
			auto po = make_pair(
				p[id][0] * (h - a[j]), 
				p[id][1] * (w - b[j])
			);
			if ((cover[id] >> j) & 1) {
				mh[id] = max(mh[id], a[j]);
				mw[id] = max(mw[id], b[j]);
				if (need[j] == make_pair(-1, -1)) {
					book[j] = true;
					need[j] = po;
				}
				else if (need[j] != po) flag = false;
			} else if (!noneed[j].count(po)) {
				noneed[j].emplace(po);
				book[j] = true;
			}
			if (noneed[j].count(need[j])) flag = false;
		}
		if (flag) dfs(id + 1);
		for (int j = 0; j < 3; j++) {
			if (book[j]) {
				auto po = make_pair(
					p[id][0] * (h - a[j]), 
					p[id][1] * (w - b[j])
				);
				if ((cover[id] >> j) & 1) need[j] = make_pair(-1, -1);
				else noneed[j].erase(po);
			}
		}
	}
}

void solve() {
	read(h); read(w);
	for (int i = 0; i < 3; i++) {
		read(a[i]); read(b[i]);
	}
	bool flag = false;
	for (int i = 0; i < 3; i++) {
		if (a[i] == h && b[i] == w) {
			write(
				1ll * (h - a[0] + 1) % MOD * (w - b[0] + 1) % MOD *
				(h - a[1] + 1) % MOD * (w - b[1] + 1) % MOD *
				(h - a[2] + 1) % MOD * (w - b[2] + 1) % MOD
			);
			return;
		}
		if (a[i] == h || b[i] == w) flag = true;
		need[i] = make_pair(-1, -1);
	}
	ans = 0;
	if (flag) dfs(0);
	write(ans);
}

int main() {
	int _;
	read(_);
	while (_--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3540kb

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: 3488kb

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

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

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: 46ms
memory: 3436kb

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: 165ms
memory: 3436kb

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: 357ms
memory: 3540kb

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: 633ms
memory: 3604kb

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: 554ms
memory: 3540kb

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: 467ms
memory: 3596kb

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: 523ms
memory: 3544kb

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: 552ms
memory: 3596kb

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: 466ms
memory: 3604kb

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: 518ms
memory: 3768kb

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: 519ms
memory: 3844kb

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: 516ms
memory: 3544kb

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: 644ms
memory: 3808kb

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: 472ms
memory: 3540kb

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: 518ms
memory: 3804kb

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: 519ms
memory: 3580kb

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: 471ms
memory: 3608kb

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: 731ms
memory: 3844kb

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: 290ms
memory: 3488kb

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: 6ms
memory: 3844kb

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: 75ms
memory: 3540kb

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: 0
Accepted
time: 226ms
memory: 3596kb

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:

ok 27000 numbers

Test #27:

score: 0
Accepted
time: 484ms
memory: 3596kb

input:

64000
1000000000 400000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 400000000
100000000 100000000
100000000 100000000
200000000 100000000
1000000000 400000000
300000000 100000000
100000000 100000000
100000000 100000000
400000000 1000000000
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
0
0
0
0
0
0
0
0
0
0
287300036
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
928600036
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
569900029
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 64000 numbers

Test #28:

score: 0
Accepted
time: 596ms
memory: 3580kb

input:

100000
1000000000 500000000
100000000 100000000
100000000 100000000
100000000 100000000
500000000 1000000000
100000000 200000000
100000000 100000000
100000000 100000000
500000000 1000000000
100000000 100000000
100000000 100000000
100000000 300000000
500000000 1000000000
100000000 400000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
141200092
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
858400085
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #29:

score: 0
Accepted
time: 259ms
memory: 3608kb

input:

25000
500000000 1000000000
500000000 100000000
100000000 100000000
100000000 100000000
1000000000 500000000
200000000 100000000
100000000 100000000
100000000 500000000
1000000000 500000000
300000000 100000000
100000000 500000000
100000000 100000000
500000000 1000000000
500000000 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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
560000023
365999952
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
920000023
411999959
0
0
0
0
0
0
0
0
0
0
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 25000 numbers

Test #30:

score: 0
Accepted
time: 530ms
memory: 3572kb

input:

100000
600000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 600000000
200000000 100000000
100000000 100000000
100000000 100000000
1000000000 600000000
100000000 100000000
300000000 100000000
100000000 100000000
1000000000 600000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
62500176
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
375000155
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 #31:

score: 0
Accepted
time: 699ms
memory: 3576kb

input:

100000
1000000000 600000000
100000000 500000000
800000000 300000000
700000000 500000000
600000000 1000000000
500000000 700000000
300000000 800000000
500000000 200000000
600000000 1000000000
500000000 700000000
300000000 800000000
500000000 300000000
600000000 1000000000
500000000 400000000
500000000...

output:

0
0
0
0
0
0
0
0
0
4
0
0
4
4
4
4
4
4
4
163600001
0
0
0
0
0
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
0
4
0
0
0
0
0
0
0
0
0
4
0
4
4
4
4
4
4
4
4
150400001
0
0
0
0
0
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
0
4
0
0
0
0
0
0
0
0
0
4
0
4
4
4
4
4
4
4
4
137200...

result:

ok 100000 numbers

Test #32:

score: 0
Accepted
time: 145ms
memory: 3544kb

input:

16000
600000000 1000000000
300000000 100000000
600000000 600000000
400000000 400000000
1000000000 600000000
200000000 300000000
600000000 600000000
400000000 400000000
600000000 1000000000
600000000 600000000
300000000 300000000
400000000 400000000
1000000000 600000000
400000000 300000000
400000000 ...

output:

0
0
0
4
4
4
4
4
4
4
0
0
0
4
4
4
4
4
4
4
0
0
0
4
4
4
4
4
4
4
0
0
0
920000009
920000009
920000009
920000009
920000009
920000009
472000001
0
0
0
0
0
0
0
0
0
0
0
0
0
4
4
4
4
4
4
4
0
0
0
4
4
4
4
4
4
4
0
0
0
4
4
4
4
4
4
4
0
0
0
4
4
4
4
4
4
4
0
0
0
2
2
2
2
2
2
400000001
0
0
0
0
0
0
0
0
0
0
0
0
0
4
4
4
4
4
...

result:

ok 16000 numbers

Test #33:

score: 0
Accepted
time: 522ms
memory: 3612kb

input:

100000
700000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 700000000
200000000 100000000
100000000 100000000
100000000 100000000
700000000 1000000000
100000000 100000000
100000000 300000000
100000000 100000000
700000000 1000000000
100000000 400000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
51200288
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
478400253
0
0
0...

result:

ok 100000 numbers

Test #34:

score: 0
Accepted
time: 520ms
memory: 3616kb

input:

100000
1000000000 700000000
900000000 300000000
100000000 500000000
100000000 300000000
1000000000 700000000
100000000 300000000
200000000 500000000
900000000 300000000
700000000 1000000000
300000000 100000000
300000000 900000000
500000000 300000000
700000000 1000000000
500000000 400000000
300000000...

output:

0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
878800001
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
560000023
0
0
0
0
0
0
0
0
0
560000023
0
0
0
0
0
0
0
0
0
560000023
0
0
0
0
0
0
0
0
0
595999987
0
0
0
0
0
0
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 #35:

score: 0
Accepted
time: 577ms
memory: 3544kb

input:

100000
700000000 1000000000
600000000 800000000
200000000 100000000
500000000 100000000
700000000 1000000000
600000000 800000000
200000000 200000000
500000000 100000000
1000000000 700000000
300000000 200000000
100000000 500000000
800000000 600000000
1000000000 700000000
400000000 200000000
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
0
0
0
0
0
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
179200001
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
0
4
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
4
115600001
0
0
0
0
0
0
0
0
4
680000...

result:

ok 100000 numbers

Test #36:

score: 0
Accepted
time: 444ms
memory: 3608kb

input:

43000
1000000000 700000000
600000000 200000000
200000000 700000000
100000000 600000000
1000000000 700000000
600000000 200000000
200000000 600000000
200000000 700000000
1000000000 700000000
600000000 200000000
300000000 600000000
200000000 700000000
1000000000 700000000
600000000 200000000
400000000 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
9
9
99999980
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
500000009
500000009
949999994
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 43000 numbers

Test #37:

score: 0
Accepted
time: 473ms
memory: 3808kb

input:

100000
800000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 800000000
200000000 100000000
100000000 100000000
100000000 100000000
1000000000 800000000
100000000 100000000
300000000 100000000
100000000 100000000
1000000000 800000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
107300428
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #38:

score: 0
Accepted
time: 526ms
memory: 3536kb

input:

100000
1000000000 800000000
100000000 100000000
600000000 200000000
100000000 600000000
800000000 1000000000
100000000 200000000
600000000 100000000
200000000 600000000
800000000 1000000000
200000000 600000000
600000000 100000000
100000000 300000000
1000000000 800000000
100000000 600000000
600000000...

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
4
398400015
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #39:

score: 0
Accepted
time: 475ms
memory: 3576kb

input:

100000
800000000 1000000000
400000000 200000000
300000000 100000000
100000000 100000000
1000000000 800000000
200000000 100000000
200000000 400000000
100000000 300000000
1000000000 800000000
100000000 300000000
300000000 100000000
200000000 400000000
800000000 1000000000
300000000 100000000
400000000...

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
470000113
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #40:

score: 0
Accepted
time: 530ms
memory: 3600kb

input:

100000
1000000000 800000000
100000000 800000000
100000000 100000000
700000000 500000000
800000000 1000000000
500000000 700000000
100000000 200000000
800000000 100000000
800000000 1000000000
500000000 700000000
100000000 300000000
800000000 100000000
800000000 1000000000
500000000 700000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
940000009
58999994
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #41:

score: 0
Accepted
time: 856ms
memory: 3576kb

input:

100000
1000000000 800000000
100000000 500000000
300000000 700000000
100000000 100000000
1000000000 800000000
100000000 500000000
200000000 100000000
300000000 700000000
800000000 1000000000
700000000 300000000
500000000 100000000
100000000 300000000
1000000000 800000000
100000000 500000000
400000000...

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
4
117299994
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #42:

score: 0
Accepted
time: 67ms
memory: 3772kb

input:

12000
800000000 1000000000
100000000 100000000
800000000 900000000
200000000 100000000
1000000000 800000000
100000000 200000000
900000000 800000000
200000000 100000000
800000000 1000000000
200000000 100000000
800000000 900000000
100000000 300000000
1000000000 800000000
400000000 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
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
4
4
4
4
4
4
4
4
4
4
4
4
440000037
440000037
440000037
440000037
440000037
440000037
440000037
440000037
440000037
416000008
0
0
0
0
0
0
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 12000 numbers

Test #43:

score: 0
Accepted
time: 468ms
memory: 3536kb

input:

100000
900000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
900000000 1000000000
100000000 100000000
100000000 200000000
100000000 100000000
1000000000 900000000
100000000 100000000
100000000 100000000
300000000 100000000
900000000 1000000000
100000000 400000000
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
230800596
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #44:

score: 0
Accepted
time: 467ms
memory: 3608kb

input:

100000
1000000000 900000000
200000000 400000000
100000000 200000000
300000000 200000000
900000000 1000000000
400000000 200000000
200000000 300000000
200000000 200000000
1000000000 900000000
200000000 400000000
300000000 200000000
300000000 200000000
1000000000 900000000
200000000 400000000
300000000...

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
155000176
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #45:

score: 0
Accepted
time: 477ms
memory: 3436kb

input:

100000
1000000000 900000000
500000000 300000000
300000000 700000000
100000000 300000000
900000000 1000000000
300000000 500000000
700000000 300000000
300000000 200000000
1000000000 900000000
300000000 300000000
500000000 300000000
300000000 700000000
900000000 1000000000
300000000 500000000
300000000...

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
4
4
4
360000015
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #46:

score: 0
Accepted
time: 496ms
memory: 3720kb

input:

100000
900000000 1000000000
400000000 100000000
100000000 400000000
400000000 800000000
1000000000 900000000
800000000 400000000
400000000 100000000
200000000 400000000
900000000 1000000000
400000000 300000000
100000000 400000000
400000000 800000000
1000000000 900000000
400000000 100000000
400000000...

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

result:

ok 100000 numbers

Test #47:

score: 0
Accepted
time: 499ms
memory: 3596kb

input:

100000
1000000000 900000000
100000000 500000000
1000000000 500000000
500000000 400000000
900000000 1000000000
500000000 200000000
400000000 500000000
500000000 1000000000
1000000000 900000000
500000000 400000000
300000000 500000000
1000000000 500000000
1000000000 900000000
500000000 400000000
400000...

output:

0
0
0
0
4
4
4
4
4
500000016
0
0
0
0
4
4
4
4
4
500000016
0
0
0
0
4
4
4
4
4
500000016
0
0
0
0
4
4
4
4
4
500000016
0
0
0
0
4
4
4
4
4
749999994
0
0
0
0
0
0
0
0
0
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
9
0
0
0
4
4
4
4
4
4
9
0
0
0
4
4
4
4
4
4
9
0
0
0
4
4
4
4
4
4
9
0
0
0
4
4
4
4
4
4
9
...

result:

ok 100000 numbers

Test #48:

score: 0
Accepted
time: 476ms
memory: 3544kb

input:

100000
900000000 1000000000
600000000 100000000
700000000 600000000
700000000 200000000
1000000000 900000000
600000000 700000000
200000000 700000000
200000000 600000000
1000000000 900000000
600000000 700000000
200000000 700000000
300000000 600000000
900000000 1000000000
700000000 600000000
700000000...

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
4
4
953600008
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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
27200001
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 numbers

Test #49:

score: 0
Accepted
time: 855ms
memory: 3612kb

input:

100000
1000000000 900000000
100000000 700000000
500000000 800000000
700000000 100000000
900000000 1000000000
800000000 500000000
700000000 200000000
100000000 700000000
900000000 1000000000
700000000 300000000
100000000 700000000
800000000 500000000
1000000000 900000000
500000000 800000000
400000000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
4
4
4
4
4
685000001
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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
4
4
4
4
4
340000001
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 #50:

score: 0
Accepted
time: 248ms
memory: 3540kb

input:

29000
900000000 1000000000
400000000 800000000
900000000 700000000
800000000 100000000
900000000 1000000000
800000000 200000000
900000000 700000000
400000000 800000000
1000000000 900000000
300000000 800000000
700000000 900000000
800000000 400000000
1000000000 900000000
400000000 800000000
700000000 ...

output:

0
0
4
4
4
4
4
4
4
4
0
0
2
2
2
2
2
2
2
300000001
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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
0
0
4
4
4
4
4
4
4
4
0
0
4
4
4
4
4
4
4
4
0
0
4
4
4
4
4
4
4
4
0
0
500000002
500000002
500000002
500000002
500000002
500000002
500000002
25000001
0
0
0
0
0...

result:

ok 29000 numbers

Test #51:

score: 0
Accepted
time: 475ms
memory: 3600kb

input:

100000
1000000000 1000000000
100000000 100000000
100000000 100000000
100000000 100000000
1000000000 1000000000
200000000 100000000
100000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
100000000 100000000
100000000 300000000
1000000000 1000000000
100000000 100000000
10000...

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
421700792
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #52:

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

input:

100000
1000000000 1000000000
100000000 100000000
200000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
200000000 100000000
100000000 200000000
1000000000 1000000000
200000000 100000000
100000000 100000000
100000000 300000000
1000000000 1000000000
100000000 400000000
10000...

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
309400687
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #53:

score: 0
Accepted
time: 472ms
memory: 3836kb

input:

100000
1000000000 1000000000
100000000 300000000
100000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
300000000 100000000
100000000 200000000
1000000000 1000000000
100000000 300000000
100000000 100000000
300000000 100000000
1000000000 1000000000
400000000 100000000
10000...

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
197100582
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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: 0
Accepted
time: 467ms
memory: 3800kb

input:

100000
1000000000 1000000000
100000000 100000000
400000000 100000000
100000000 100000000
1000000000 1000000000
100000000 400000000
100000000 100000000
200000000 100000000
1000000000 1000000000
400000000 100000000
100000000 300000000
100000000 100000000
1000000000 1000000000
400000000 100000000
10000...

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
84800477
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #55:

score: 0
Accepted
time: 475ms
memory: 3596kb

input:

100000
1000000000 1000000000
500000000 100000000
100000000 100000000
100000000 100000000
1000000000 1000000000
100000000 200000000
100000000 100000000
500000000 100000000
1000000000 1000000000
500000000 100000000
100000000 300000000
100000000 100000000
1000000000 1000000000
500000000 100000000
10000...

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
972500379
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #56:

score: 0
Accepted
time: 473ms
memory: 3512kb

input:

100000
1000000000 1000000000
100000000 100000000
100000000 100000000
100000000 600000000
1000000000 1000000000
200000000 100000000
100000000 100000000
100000000 600000000
1000000000 1000000000
100000000 600000000
300000000 100000000
100000000 100000000
1000000000 1000000000
400000000 100000000
10000...

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
860200274
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #57:

score: 0
Accepted
time: 474ms
memory: 3488kb

input:

100000
1000000000 1000000000
700000000 100000000
100000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
100000000 700000000
200000000 100000000
1000000000 1000000000
100000000 300000000
700000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
10000...

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
747900169
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #58:

score: 0
Accepted
time: 473ms
memory: 3848kb

input:

100000
1000000000 1000000000
100000000 100000000
100000000 100000000
100000000 800000000
1000000000 1000000000
800000000 100000000
100000000 200000000
100000000 100000000
1000000000 1000000000
800000000 100000000
100000000 100000000
100000000 300000000
1000000000 1000000000
100000000 100000000
80000...

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
635600064
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #59:

score: 0
Accepted
time: 466ms
memory: 3468kb

input:

100000
1000000000 1000000000
100000000 100000000
900000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
200000000 100000000
100000000 900000000
1000000000 1000000000
100000000 900000000
300000000 100000000
100000000 100000000
1000000000 1000000000
100000000 100000000
40000...

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
4
523299959
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 #60:

score: -100
Time Limit Exceeded

input:

100000
1000000000 1000000000
100000000 100000000
100000000 1000000000
100000000 100000000
1000000000 1000000000
100000000 1000000000
100000000 100000000
200000000 100000000
1000000000 1000000000
100000000 100000000
100000000 1000000000
300000000 100000000
1000000000 1000000000
100000000 1000000000
4...

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
260000058
410999854
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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: