QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102831#3190. GatheringPetroTarnavskyi#AC ✓57ms8604kbC++172.8kb2023-05-03 18:28:522023-05-03 18:28:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 18:28:55]
  • 评测
  • 测评结果:AC
  • 用时:57ms
  • 内存:8604kb
  • [2023-05-03 18:28:52]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second


typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define int LL

struct point
{
	int x, y;
};

pair<point, point> inter(pair<point, point> a, pair<point, point> b)
{
	return {{max(a.F.x, b.F.x), max(a.F.y, b.F.y)}, {min(a.S.x, b.S.x), min(a.S.y, b.S.y)}};
}

vector<point> v;

LL calc(point p)
{
	int n = SZ(v);
	LL ans = 0;
	FOR(i, 0, n)
	{
		ans += abs(v[i].x - p.x) + abs(v[i].y - p.y);
	}	
	return ans;
}

bool bad(point p)
{
	return (p.x & 1) ^ (p.y & 1);
}

LL ter(point a, point b, point di)
{
	if (bad(a))
		a.x += di.x, a.y += di.y;
	if (bad(b))
		b.x -= di.x, b.y -= di.y;
	
	a = {(a.x + a.y) / 2, (a.x - a.y) / 2};	
	b = {(b.x + b.y) / 2, (b.x - b.y) / 2};	
	
	int len = abs(a.x - b.x);
	if (len == 0) return calc(a);
	int l = 0, r = len;
	int dx = (b.x - a.x) / len;
	
	int dy = (b.y - a.y) / len;
	assert(1ll * dy * len == (b.y - a.y));
	
	while (l + 2 < r)
	{
		int d = (r - l) / 3;
		int l2 = l + d;
		int r2 = r - d;
		if (calc({a.x + dx * l2, a.y + dy * l2}) < calc({a.x + dx * r2, a.y + dy * r2}))
			r = r2;
		else
			l = l2;
	}
	LL best = 4e18;
	FOR(L, l, r + 1)
		best = min(best, calc({a.x + dx * L, a.y + dy * L}));
	return best;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	v.resize(n);
	VI x(n), y(n);
	FOR(i, 0, n) 
	{
		cin >> v[i].x >> v[i].y;
		x[i] = v[i].x;
		y[i] = v[i].y;
	}

	int d;
	cin >> d;
	
	vector<pair<point, point>> a(n);
	FOR(i, 0, n)
	{
		a[i] = {{x[i] - d + y[i], x[i] - d - y[i]}, {x[i] + d + y[i], x[i] + d - y[i]}};
	}
	pair<point, point> sq = a[0];
	FOR(i, 1, n)
	{
		sq = inter(sq, a[i]);
	}
	if (sq.F.x > sq.S.x || sq.F.y > sq.S.y || (sq.F.x == sq.S.x && sq.F.y == sq.S.y && bad(sq.F)))
	{
		cout << "impossible\n";
		return 0;
	}
	sort(ALL(x));
	sort(ALL(y));
	pair<point, point> b = {{x[n / 2] + y[n / 2], x[n / 2] - y[n / 2]}, {x[n / 2] + y[n / 2], x[n / 2] - y[n / 2]}};
	
	auto res = inter(sq, b);
	if (res.F.x <= res.S.x && res.F.y <= res.S.y)
	{
		point p = {(b.F.x + b.F.y) / 2, ((b.F.x - b.F.y) / 2)};
		cout << calc(p) << endl;
		return 0;
	}
	
	LL ans = 4e18;
	point p1 = {sq.F.x, sq.F.y};
	point p2 = {sq.F.x, sq.S.y};
	point p3 = {sq.S.x, sq.S.y};
	point p4 = {sq.S.x, sq.F.y};
	
	ans = min(ans, ter(p1, p2, {0, 1}));
	ans = min(ans, ter(p2, p3, {1, 0}));
	ans = min(ans, ter(p3, p4, {0, -1}));
	ans = min(ans, ter(p4, p1, {-1, 0}));
	
	cout << ans << endl;	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3 1
4 1
5 9
2 6
5 3
10

output:

18

result:

ok single line: '18'

Test #2:

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

input:

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

output:

20

result:

ok single line: '20'

Test #3:

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

input:

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

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

2
0 0
0 0
0

output:

0

result:

ok single line: '0'

Test #5:

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

input:

2
0 0
0 1
1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2
0 0
0 1
0

output:

impossible

result:

ok single line: 'impossible'

Test #7:

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

input:

4
0 0
0 10
10 0
10 10
10

output:

40

result:

ok single line: '40'

Test #8:

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

input:

5
0 0
0 10
9 0
9 10
0 0
10

output:

47

result:

ok single line: '47'

Test #9:

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

input:

5
0 0
0 10
9 0
9 10
9 0
10

output:

47

result:

ok single line: '47'

Test #10:

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

input:

6
0 0
0 10
10 0
10 10
1 8
9 2
12

output:

54

result:

ok single line: '54'

Test #11:

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

input:

6
0 0
0 10
10 0
10 10
1 8
9 2
15

output:

54

result:

ok single line: '54'

Test #12:

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

input:

7
0 0
0 100
100 0
100 100
0 0
10 10
23 28
150

output:

481

result:

ok single line: '481'

Test #13:

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

input:

5
0 0
0 100
100 0
100 100
50 20
130

output:

400

result:

ok single line: '400'

Test #14:

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

input:

5
0 0
0 100
100 0
100 100
50 10
130

output:

410

result:

ok single line: '410'

Test #15:

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

input:

5
0 0
0 100
100 0
100 100
60 0
130

output:

430

result:

ok single line: '430'

Test #16:

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

input:

5
0 0
0 100
100 0
100 100
60 10
130

output:

420

result:

ok single line: '420'

Test #17:

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

input:

5
0 0
0 100
100 0
100 100
65 35
130

output:

400

result:

ok single line: '400'

Test #18:

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

input:

5
0 0
0 100
100 0
100 100
70 30
130

output:

410

result:

ok single line: '410'

Test #19:

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

input:

5
0 0
0 100
100 0
100 100
90 10
130

output:

450

result:

ok single line: '450'

Test #20:

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

input:

7
0 0
0 75
100 25
100 100
10 60
10 60
10 90
125

output:

391

result:

ok single line: '391'

Test #21:

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

input:

7
100 0
25 0
75 100
0 100
40 10
40 10
10 10
125

output:

391

result:

ok single line: '391'

Test #22:

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

input:

7
100 100
100 25
0 75
0 0
90 40
90 40
90 10
125

output:

391

result:

ok single line: '391'

Test #23:

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

input:

7
0 100
75 100
25 0
100 0
60 90
60 90
90 90
125

output:

391

result:

ok single line: '391'

Test #24:

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

input:

7
100 0
100 75
0 25
0 100
90 60
90 60
90 90
125

output:

391

result:

ok single line: '391'

Test #25:

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

input:

7
100 100
25 100
75 0
0 0
40 90
40 90
10 90
125

output:

391

result:

ok single line: '391'

Test #26:

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

input:

7
0 100
0 25
100 75
100 0
10 40
10 40
10 10
125

output:

391

result:

ok single line: '391'

Test #27:

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

input:

7
0 0
75 0
25 100
100 100
60 10
60 10
90 10
125

output:

391

result:

ok single line: '391'

Test #28:

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

input:

7
0 0
0 75
100 25
100 100
20 20
20 30
10 80
125

output:

445

result:

ok single line: '445'

Test #29:

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

input:

7
100 0
25 0
75 100
0 100
80 20
70 20
20 10
125

output:

445

result:

ok single line: '445'

Test #30:

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

input:

7
100 100
100 25
0 75
0 0
80 80
80 70
90 20
125

output:

445

result:

ok single line: '445'

Test #31:

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

input:

7
0 100
75 100
25 0
100 0
20 80
30 80
80 90
125

output:

445

result:

ok single line: '445'

Test #32:

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

input:

7
100 0
100 75
0 25
0 100
80 20
80 30
90 80
125

output:

445

result:

ok single line: '445'

Test #33:

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

input:

7
100 100
25 100
75 0
0 0
80 80
70 80
20 90
125

output:

445

result:

ok single line: '445'

Test #34:

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

input:

7
0 100
0 25
100 75
100 0
20 80
20 70
10 20
125

output:

445

result:

ok single line: '445'

Test #35:

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

input:

7
0 0
75 0
25 100
100 100
20 20
30 20
80 10
125

output:

445

result:

ok single line: '445'

Test #36:

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

input:

8534
116302263 676752
668674805 908095735
71666532 896336333
736731265 314989458
535244751 391441865
108520141 206814702
534045436 974836612
238077914 413854218
705377000 397905153
440974757 972995558
282367380 881784893
823504433 879663491
70219520 215814456
726604669 318196447
939145515 30877684
9...

output:

impossible

result:

ok single line: 'impossible'

Test #37:

score: 0
Accepted
time: 48ms
memory: 7476kb

input:

81186
32136890 931344747
142033094 612429664
615834245 42381126
65593714 138671771
634339601 802658530
946304224 323905944
750713949 324946495
702821643 940601429
475865193 905399131
916652024 597291728
899826486 18853429
677992867 225924365
751262914 328663250
446106639 47265033
60274957 927220015
...

output:

42340175200180

result:

ok single line: '42340175200180'

Test #38:

score: 0
Accepted
time: 28ms
memory: 5536kb

input:

49449
674969554 715452579
788759967 466619736
844510493 747369471
304661964 869123604
279572266 62247195
268595896 38738065
716507637 222009846
573388899 473672909
738357121 33769619
345642703 944275144
818848205 997527790
172964348 548658820
622439641 873360650
1992166 374753281
47733925 926038247
...

output:

25861458047878

result:

ok single line: '25861458047878'

Test #39:

score: 0
Accepted
time: 13ms
memory: 5348kb

input:

39941
323632827 570123844
980089241 697211594
794293416 458473920
248624485 770146983
160150356 672604925
798384625 243245635
312127680 37220857
562514749 904929183
960450283 727837364
296109898 448861883
220925399 219211569
5503508 239442326
816617860 274449773
284011425 195221554
52152816 77814205...

output:

20885246556192

result:

ok single line: '20885246556192'

Test #40:

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

input:

17683
342110200 330675005
734502302 74629356
116828339 475213642
158667962 101411798
538322224 679619605
582541718 900874628
559514476 317349282
60647987 382988784
536512872 708096494
314209935 260272923
304528677 935198458
324477610 247809287
397084321 828182726
518039687 946541492
382757853 995269...

output:

9224304488700

result:

ok single line: '9224304488700'

Test #41:

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

input:

76066
540790134 502539747
491506765 571712258
328414227 228744271
117118536 94170446
208862831 331058555
12086788 593399898
591415434 164930919
383012737 660953126
53524581 125835796
29347515 532598962
132546050 391037824
555380153 76526076
858494814 178034604
904604789 875283466
907654267 806453912...

output:

39893902760956

result:

ok single line: '39893902760956'

Test #42:

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

input:

84606
667465262 902174268
780529605 359877914
142367817 63358502
601539393 894326501
932346918 127622354
78940284 378955122
495145922 649479744
444832121 331783357
783995679 61076074
31834163 51616968
682145850 997446487
792329905 892440470
675495190 122069762
153357036 181683489
707919283 577566063...

output:

impossible

result:

ok single line: 'impossible'

Test #43:

score: 0
Accepted
time: 17ms
memory: 6160kb

input:

58696
680877833 344220942
241348910 909454139
984343237 134937113
359701323 390408488
12014143 431046117
108399909 482141651
652256637 2486897
554458818 802106175
951865976 381641661
692686367 217996139
881409332 99392969
948104507 789471831
429580721 396113558
948852758 850441732
936044525 57652995...

output:

impossible

result:

ok single line: 'impossible'

Test #44:

score: 0
Accepted
time: 5ms
memory: 4028kb

input:

16675
369369502 215231211
6709429 504136522
888527034 456239575
828986161 779927573
991735703 243332484
607397740 73361313
113056305 71244783
534474088 54014444
387971727 814706972
33312035 416909561
237744299 739621127
313106592 86287558
301116551 280231347
664539101 278625617
17692193 48933664
953...

output:

8685371319336

result:

ok single line: '8685371319336'

Test #45:

score: 0
Accepted
time: 9ms
memory: 3784kb

input:

13188
231342659 918544685
545389665 316914162
956590256 189503784
97473196 374907470
673486299 205405924
44168633 103054955
768646600 654017632
99032454 242207814
37080692 5430171
663194642 156258275
545297375 159475865
961435486 900597567
64152586 551299924
914997609 47203417
768280824 140756944
55...

output:

6893801167939

result:

ok single line: '6893801167939'

Test #46:

score: 0
Accepted
time: 9ms
memory: 3712kb

input:

13262
8585928 290541409
735349382 358088519
579778931 567785116
56543506 720404194
471163616 383827864
131884126 115997757
629342987 292693589
879468137 384575322
140553720 201052881
931125045 87640119
129572258 318701836
744987330 833971922
345799183 849677065
731422990 803407663
221548860 87309075...

output:

6947996358505

result:

ok single line: '6947996358505'

Test #47:

score: 0
Accepted
time: 11ms
memory: 4288kb

input:

25115
368347559 98120896
78490725 808903590
22676052 553698813
676696818 482784066
981397440 134085368
705372733 268034206
346586603 957855669
336629322 839419834
588445400 35882543
64046358 747668630
741124228 148463212
64948384 993096498
403556592 253564008
71557358 703115150
463373340 483143204
4...

output:

13109464328912

result:

ok single line: '13109464328912'

Test #48:

score: 0
Accepted
time: 23ms
memory: 5644kb

input:

46593
441487437 896703854
729301627 423067396
856425305 489884555
885159016 649293953
802790181 415552871
964587284 116391867
781640625 673486594
324888704 127708857
386462462 1537629
768983723 684752245
612188426 182578555
622132631 825785329
943088598 253224535
940243779 373810733
485629281 517071...

output:

24410461172146

result:

ok single line: '24410461172146'

Test #49:

score: 0
Accepted
time: 10ms
memory: 4188kb

input:

21485
787642472 717380224
938688293 866625895
84928787 548833213
71406002 737899779
453635200 950933688
204674814 154558047
425808044 101446005
740664586 946976634
417909656 414658545
469829590 576174679
275450180 150854189
482541921 672717554
991341487 368058920
483474350 540988238
598752476 388126...

output:

11228872243459

result:

ok single line: '11228872243459'

Test #50:

score: 0
Accepted
time: 32ms
memory: 6096kb

input:

54376
811329018 888438186
847184903 536041889
936877509 209236871
931250868 993010908
159543377 117978914
305630239 972149208
120629662 832212095
517387340 260526740
383711145 710242715
205913911 901391120
300909685 292864630
735737571 527400780
608492546 400980243
572308815 245654344
814607437 1275...

output:

28418368182810

result:

ok single line: '28418368182810'

Test #51:

score: 0
Accepted
time: 26ms
memory: 6704kb

input:

65472
104557236 226236343
536822051 835970701
703301185 75162705
301905296 109745288
940729485 348145327
96574140 509710404
173122970 951702730
745252520 150113216
345276774 106350757
227392339 910017276
20743153 16601666
70427328 470495736
546622 175861662
218049260 715560116
699312458 808374459
85...

output:

34107139349363

result:

ok single line: '34107139349363'

Test #52:

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

input:

36568
358832396 408307905
969768658 701070352
855040777 312921869
30004526 504856379
671538372 771897370
109786442 22934311
880470593 63317988
246971174 739621331
944433533 515354738
982139586 38171966
814143096 533488062
650228255 666401132
947388724 172888521
136559929 47117911
739711920 923148437...

output:

impossible

result:

ok single line: 'impossible'

Test #53:

score: 0
Accepted
time: 7ms
memory: 3452kb

input:

9216
562508066 571394080
778722264 344943518
309615742 600669259
261703317 141023657
41528219 888765240
387233553 197087350
84398709 308744932
39971148 499645954
353891091 452229456
451819337 471936589
63904109 548395644
2386691 71860569
374911371 643703400
151029377 190839077
899603303 338099476
19...

output:

4836869445216

result:

ok single line: '4836869445216'

Test #54:

score: 0
Accepted
time: 24ms
memory: 5272kb

input:

40342
131030655 464868427
361067668 436878250
67462043 65800503
907226897 380135542
919379575 953622755
516940108 170563074
432529682 248828240
547939656 61870158
558032239 775795324
76478213 392567129
312975242 62645862
9240193 247402789
778834791 519899923
923402685 358463921
67220738 135029887
89...

output:

21134034770512

result:

ok single line: '21134034770512'

Test #55:

score: 0
Accepted
time: 42ms
memory: 6912kb

input:

69578
985431119 607858652
441831140 277497273
443453035 111059911
654054496 302280070
88792134 12637299
520224669 613356049
60214241 523461599
459878040 640343389
719001407 48411658
663913813 851499882
96359513 443354871
296245200 310985782
788442935 392006820
585908236 6805952
193267667 272158480
8...

output:

36376672126854

result:

ok single line: '36376672126854'

Test #56:

score: 0
Accepted
time: 39ms
memory: 8552kb

input:

100000
309359797 588156342
895372068 904078989
166315585 383184466
673983375 401120905
968139917 911574703
271782075 756600900
601351578 972938955
727784615 662214081
614725477 344562855
14809939 943181053
954568178 713986626
22367934 152990200
320851261 393968031
245066476 826842805
363470665 38674...

output:

52168807763548

result:

ok single line: '52168807763548'

Test #57:

score: 0
Accepted
time: 51ms
memory: 8468kb

input:

100000
402072292 630765900
796823042 531841811
366657359 46270281
984661581 470089071
640805500 352322820
608244057 326317962
777414759 105431679
367809318 280912230
708854547 303959996
329232817 799558914
736487040 69096633
127601916 307634271
889383596 583435125
739364618 550214010
906626456 72568...

output:

52139178213752

result:

ok single line: '52139178213752'

Test #58:

score: 0
Accepted
time: 50ms
memory: 8468kb

input:

100000
352961490 31331087
170995721 133142541
352676398 870051899
756611524 234080025
369484875 225997863
890361665 91530470
288469030 634866387
803448445 112942961
138870209 84940350
285814137 901685437
317832478 603662956
342239285 572697289
98675770 983990616
375263921 363205526
229784343 7664012...

output:

52297223847844

result:

ok single line: '52297223847844'

Test #59:

score: 0
Accepted
time: 55ms
memory: 8400kb

input:

100000
691089869 552020719
432111611 733902981
615515866 738901258
310853607 888346625
855436453 983795943
426185363 903702844
234395442 402326146
728378880 782171192
504689790 222553054
34510378 820481269
436722314 178931963
434093336 141624177
636898133 365590999
268748995 423716269
50751201 18696...

output:

52137748373574

result:

ok single line: '52137748373574'

Test #60:

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

input:

100000
417342276 962949785
554835914 48076200
602020033 360365669
57197477 642409556
698070524 843512561
481557826 991130048
315970808 19428413
41011870 312338924
661645236 420886089
11525051 299560663
679588913 319215382
544635031 117017220
646734445 98286240
40530737 264686320
790214761 777630446
...

output:

52449178517578

result:

ok single line: '52449178517578'

Test #61:

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

input:

100000
822468968 755240832
823349285 830269031
64362514 501124285
574023857 46970882
828812159 13725112
160005629 718682975
231238060 435473524
98442249 743255675
254309528 223356145
506236629 41301847
971077699 722883884
985148514 404891634
236797616 397246761
89514669 933935695
620022747 552863461...

output:

impossible

result:

ok single line: 'impossible'

Test #62:

score: 0
Accepted
time: 52ms
memory: 8540kb

input:

100000
703158849 92709349
140798758 956675028
848662396 428367986
990196418 123301695
928204408 861751229
274782238 216588139
932933940 411353545
447182650 488449623
228349361 630364822
351202326 827125763
550818284 592824866
661232819 455635568
438058984 388654702
867993358 58344860
787307429 32889...

output:

52330818155614

result:

ok single line: '52330818155614'

Test #63:

score: 0
Accepted
time: 57ms
memory: 8488kb

input:

100000
100170644 760290364
482725426 834156419
125184254 890953528
838769534 507300063
620027691 723768820
80357257 122622971
675897879 76250224
640195670 601238230
50065860 250416812
581576674 432749938
755866671 402018985
415686702 915384271
499837787 783839333
702861626 453571051
54971208 2615548...

output:

52119108325296

result:

ok single line: '52119108325296'

Test #64:

score: 0
Accepted
time: 51ms
memory: 8532kb

input:

100000
617965634 568852672
954742776 173873981
582935966 866937068
451462325 47416136
137602747 711796696
74998575 263099413
139536790 226027908
867816813 685407137
121413169 750931951
294687080 837505005
48114317 806479132
991249701 45999866
647476395 323710215
425673888 276003014
595601030 5319774...

output:

52280111916982

result:

ok single line: '52280111916982'

Test #65:

score: 0
Accepted
time: 17ms
memory: 8484kb

input:

100000
581168894 152196703
603922091 980724085
885783818 638922618
712513943 458792432
152704469 387967062
572432708 522897452
417093985 55450867
275497903 605430825
99778476 721996622
356439260 784587237
105575097 76770666
884447431 467480417
128117382 299636038
804526451 886857885
35151633 8341526...

output:

impossible

result:

ok single line: 'impossible'

Test #66:

score: 0
Accepted
time: 47ms
memory: 8536kb

input:

100000
474622908 999355587
698237367 959022816
318084622 34267464
702858756 956999261
32010449 323972218
860366920 153394053
375403292 984226868
687434957 963538711
84518644 221835943
154767312 138317279
465471022 1193676
908694490 788043076
574654062 994395359
815443576 112062698
46988461 711614143...

output:

62416303705859

result:

ok single line: '62416303705859'

Test #67:

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

input:

100000
64259605 934946214
995044114 965270890
916777313 944066638
912874000 36313583
939481755 955778971
951266265 903242579
971199435 961563032
931742056 969568740
961408291 63027469
75064594 911877143
72071370 945032531
40604581 1883070
951432266 20584369
9443524 908394057
953152046 985186920
9347...

output:

89969167274708

result:

ok single line: '89969167274708'

Test #68:

score: 0
Accepted
time: 50ms
memory: 8528kb

input:

100000
103260814 396996981
761129205 513665683
490655026 767651275
323320327 176573407
530278927 784686691
762557721 504035006
520077706 750469764
698764050 414189952
5284820 504941693
408964736 91071565
777853723 550862752
169098363 331222595
215064135 285686068
578919783 679328482
581554805 306644...

output:

42083678792686

result:

ok single line: '42083678792686'

Test #69:

score: 0
Accepted
time: 55ms
memory: 8600kb

input:

100000
863335402 914241582
998731112 999960433
978359177 653177364
749939938 991054020
813898131 819400931
994315701 995389613
929712715 739886420
828505431 972962795
537903976 967708384
563552461 988401790
917502816 794942326
844074262 848402499
839347327 820879374
636440880 896332215
907312439 802...

output:

17416379670964

result:

ok single line: '17416379670964'

Test #70:

score: 0
Accepted
time: 29ms
memory: 8400kb

input:

100000
1000000000 1000000000
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0...

output:

100000000000000

result:

ok single line: '100000000000000'

Test #71:

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

input:

10
0 2
0 2
0 2
0 2
0 2
0 2
0 2
0 2
1 4
3 0
3

output:

22

result:

ok single line: '22'

Test #72:

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

input:

10
0 3
0 3
0 3
0 3
0 3
0 3
0 3
2 1
1 0
1 6
3

output:

16

result:

ok single line: '16'

Test #73:

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

input:

10
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 3
1 3
3

output:

13

result:

ok single line: '13'

Test #74:

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

input:

10
982195403 346136310
507835422 147644431
797109505 774940706
999377046 381866699
654202186 765284360
742424078 213034030
930525496 614521208
685394404 114065055
157629960 955711240
24032643 199801066
718517856

output:

6258861428

result:

ok single line: '6258861428'

Test #75:

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

input:

3
0 0
0 0
10 10
19

output:

21

result:

ok single line: '21'