QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779263#1210. AAQQZUrd100 ✓180ms38924kbC++172.4kb2024-11-24 18:05:332024-11-24 18:05:35

Judging History

This is the latest submission verdict.

  • [2024-11-24 18:05:35]
  • Judged
  • Verdict: 100
  • Time: 180ms
  • Memory: 38924kb
  • [2024-11-24 18:05:33]
  • Submitted

answer

#include <bits/stdc++.h>
#define ALL(v) begin(v), end(v)

using i64 = int64_t;

const int kMaxN = 3E3 + 5;

int n, c, ans;
std::array<int, kMaxN> s, cnt;
std::array<std::array<int, kMaxN>, kMaxN> f;

std::vector<int> col;
std::array<int, kMaxN> cl, cr, sm;
auto Proc(int l, int r, int c) -> int {
  for (int i = 1; i <= ::c; ++i) cl[i] = cr[i] = 0;
  for (int i = l; i; --i) {
    ++cl[s[i]];
    if (s[i - 1] < s[i]) break;
  }
  col.clear();
  for (int i = 1; i <= ::c; ++i) {
    sm[i] = cl[i] + sm[i - 1];
    if (cl[i]) col.emplace_back(i);
  }
  int ans = 0, cnt_c = 0, cur = 0, tp = 0;
  int mn = ::c;
  for (int i = r; i <= n; ++i) {
    if (s[i] < c) break;
    if (s[i] == c) {
      ++cnt_c;
    } else {
      ++cr[s[i]], ++cur;
      if (cr[s[i]] == cl[s[i]] + 1) mn = std::min(mn, s[i] - 1);
    }
    tp = std::min(tp, mn);
    while (tp < mn && cl[tp + 1] == cr[tp + 1]) ++tp;
    int ptr = sm[tp] + std::min(cl[tp + 1], cr[tp + 1]);
    ans = std::max(ans, 2 * ptr + cnt_c);
    if (ptr == cur) {
      ans = std::max(ans, 2 * ptr + cnt_c + f[l - ptr][r + ptr + cnt_c] * 2);
    }
  }
  return ans;
}
void Proc() {
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= i; --j) {
      f[i][j] = (s[i] == s[j] ? f[i - 1][j + 1] + 1 : 0);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int lp = i, rp = i;
    while (lp >= 1 && rp <= n && s[lp] == s[rp]) --lp, ++rp;
    ans = std::max(ans, Proc(lp, rp, -1) + rp - lp - 1);
    lp = i, rp = i + 1;
    while (lp >= 1 && rp <= n && s[lp] == s[rp]) --lp, ++rp;
    ans = std::max(ans, Proc(lp, rp, -1) + rp - lp - 1);
  }
  for (int l = 1; l <= n; ++l) {
    int r = l + 1;
    while (r <= n && s[r] >= s[l]) ++r;
    if (r <= n) ans = std::max(ans, Proc(l, l + 1, s[r]));
  }
}

auto main() -> int {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr), std::cout.tie(nullptr);

  std::cin >> n >> c;
  for (int i = 1; i <= n; ++i) std::cin >> s[i], ++cnt[s[i]];
  for (int i = 1; i <= n; ++i) {
    int r = 0;
    while (i - r && i + r <= n && s[i - r] == s[i + r]) ++r;
    ans = std::max(ans, 2 * r - 1), r = 0;
    while (i - r && i + r < n && s[i - r] == s[i + r + 1]) ++r;
    ans = std::max(ans, 2 * r);
  }
  for (int i = 1; i <= c; ++i) ans = std::max(ans, cnt[i]);
  Proc();
  std::reverse(s.data() + 1, s.data() + n + 1);
  for (int i = 1; i <= n; ++i) s[i] = c + 1 - s[i];
  Proc();
  std::cout << ans << '\n';

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3808kb

input:

50 50
1
17
19
22
18
32
33
34
31
14
47
23
44
8
40
26
50
39
46
27
24
29
48
41
7
5
11
43
37
10
6
3
35
13
30
42
25
12
9
20
21
49
2
28
4
15
16
45
38
36

output:

1

result:

ok single line: '1'

Test #2:

score: 10
Accepted
time: 1ms
memory: 5784kb

input:

50 50
28
5
43
17
25
32
16
17
20
32
16
40
3
20
23
16
17
32
32
20
25
27
50
30
28
16
27
20
41
12
16
23
27
8
16
23
28
30
17
12
9
20
25
20
17
12
30
28
27
8

output:

7

result:

ok single line: '7'

Test #3:

score: 10
Accepted
time: 1ms
memory: 3796kb

input:

50 50
43
24
23
21
39
34
31
26
31
42
39
34
21
23
28
35
43
24
28
35
39
10
31
24
35
23
21
1
24
26
31
19
19
34
35
28
31
48
11
35
19
31
34
35
19
26
34
8
46
23

output:

7

result:

ok single line: '7'

Test #4:

score: 10
Accepted
time: 1ms
memory: 5744kb

input:

50 50
2
2
2
2
2
5
5
7
9
11
11
11
12
13
19
25
27
34
34
35
35
40
47
35
34
34
35
47
40
35
35
34
34
27
25
19
13
12
11
11
11
9
7
5
5
2
2
2
2
48

output:

48

result:

ok single line: '48'

Test #5:

score: 10
Accepted
time: 1ms
memory: 3924kb

input:

50 50
3
49
49
49
49
46
46
44
42
40
40
40
39
38
32
26
24
17
17
16
16
11
4
16
17
17
16
4
11
16
16
17
17
24
26
32
38
39
40
40
40
42
44
46
46
49
49
49
49
49

output:

48

result:

ok single line: '48'

Test #6:

score: 10
Accepted
time: 1ms
memory: 5752kb

input:

50 50
25
25
43
25
25
25
43
21
5
25
21
25
25
25
25
21
25
25
25
21
43
25
43
43
25
25
21
21
25
25
48
25
43
21
21
25
43
21
21
43
48
25
5
25
5
21
21
21
25
25

output:

24

result:

ok single line: '24'

Test #7:

score: 10
Accepted
time: 1ms
memory: 3828kb

input:

50 50
26
26
30
30
30
46
26
46
26
3
8
30
30
8
26
30
30
8
26
3
26
26
30
30
26
26
8
8
26
8
30
26
26
26
30
26
26
26
26
30
26
46
30
8
26
26
26
8
26
26

output:

24

result:

ok single line: '24'

Test #8:

score: 10
Accepted
time: 1ms
memory: 3732kb

input:

50 50
27
40
16
36
28
16
29
22
24
41
39
34
31
14
13
12
10
2
50
36
39
8
21
2
10
10
10
2
21
8
39
36
50
39
34
13
14
2
9
31
34
12
10
22
29
16
32
7
28
38

output:

19

result:

ok single line: '19'

Test #9:

score: 10
Accepted
time: 1ms
memory: 5792kb

input:

50 50
13
23
44
19
35
22
29
41
39
17
20
42
49
37
38
17
12
1
15
12
43
30
49
41
41
41
49
30
43
12
15
1
49
41
39
38
37
20
17
12
10
27
29
22
35
23
15
35
11
24

output:

19

result:

ok single line: '19'

Test #10:

score: 10
Accepted
time: 1ms
memory: 5620kb

input:

50 50
48
10
34
14
35
34
7
34
38
38
33
33
27
17
9
31
1
33
1
1
1
27
9
38
17
1
33
1
1
23
1
1
1
1
1
1
1
1
38
34
35
14
34
10
48
37
44
49
22
3

output:

19

result:

ok single line: '19'

Test #11:

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

input:

50 50
48
29
2
7
14
3
41
17
37
16
17
13
50
50
50
50
50
50
50
50
28
50
50
18
50
34
13
42
24
50
50
50
18
50
20
42
34
24
18
18
13
13
17
44
17
16
37
17
41
3

output:

19

result:

ok single line: '19'

Test #12:

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

input:

50 50
13
44
13
45
49
26
44
43
45
43
40
31
29
14
45
32
31
18
19
6
39
39
6
19
18
31
32
45
29
40
45
43
31
14
43
44
26
49
45
13
44
13
43
49
18
29
2
35
3
25

output:

42

result:

ok single line: '42'

Test #13:

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

input:

50 50
26
48
16
49
22
33
2
8
38
7
38
6
2
25
7
8
37
20
8
6
11
22
6
19
20
33
32
45
12
12
45
32
33
20
19
6
37
22
20
11
8
6
8
7
25
2
6
38
7
38

output:

42

result:

ok single line: '42'

Test #14:

score: 10
Accepted
time: 1ms
memory: 3836kb

input:

50 50
30
40
35
47
29
19
35
36
4
12
1
13
8
32
36
29
41
43
36
30
29
18
6
6
6
29
6
6
30
6
6
18
36
6
6
43
6
6
6
6
6
41
29
36
32
8
13
25
50
39

output:

36

result:

ok single line: '36'

Test #15:

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

input:

50 50
12
1
26
38
43
19
15
22
10
45
45
45
45
45
8
45
45
15
33
45
45
21
45
45
22
45
45
45
33
22
21
15
8
10
22
15
19
43
38
50
39
47
15
16
32
22
4
16
11
21

output:

36

result:

ok single line: '36'

Test #16:

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

input:

50 50
10
5
30
5
10
5
39
5
10
5
30
5
10
5
40
5
10
5
30
5
10
5
39
5
10
5
30
5
10
5
50
5
10
5
30
5
10
5
39
5
10
5
30
5
10
5
40
5
10
5

output:

39

result:

ok single line: '39'

Test #17:

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

input:

50 50
46
41
46
11
46
41
46
21
46
41
46
12
46
41
46
21
46
41
46
1
46
41
46
21
46
41
46
12
46
41
46
21
46
41
46
11
46
41
46
21
46
41
46
12
46
41
46
21
46
41

output:

39

result:

ok single line: '39'

Test #18:

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

input:

50 50
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42
42

output:

50

result:

ok single line: '50'

Test #19:

score: 10
Accepted
time: 1ms
memory: 5696kb

input:

50 50
27
40
16
36
28
16
29
22
24
41
39
34
31
14
13
12
10
2
50
36
39
8
21
2
10
10
10
2
21
8
39
36
50
39
34
13
14
2
9
31
34
12
10
22
29
16
32
7
28
38

output:

19

result:

ok single line: '19'

Test #20:

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

input:

50 50
13
23
44
19
35
22
29
41
39
17
20
42
49
37
38
17
12
1
15
12
43
30
49
41
41
41
49
30
43
12
15
1
49
41
39
38
37
20
17
12
10
27
29
22
35
23
15
35
11
24

output:

19

result:

ok single line: '19'

Test #21:

score: 10
Accepted
time: 1ms
memory: 5616kb

input:

50 50
48
10
34
14
35
34
7
34
38
38
33
33
27
17
9
31
1
33
1
1
1
27
9
38
17
1
33
1
1
23
1
1
1
1
1
1
1
1
38
34
35
14
34
10
48
37
44
49
22
3

output:

19

result:

ok single line: '19'

Test #22:

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

input:

50 50
48
29
2
7
14
3
41
17
37
16
17
13
50
50
50
50
50
50
50
50
28
50
50
18
50
34
13
42
24
50
50
50
18
50
20
42
34
24
18
18
13
13
17
44
17
16
37
17
41
3

output:

19

result:

ok single line: '19'

Test #23:

score: 10
Accepted
time: 1ms
memory: 3836kb

input:

50 50
13
44
13
45
49
26
44
43
45
43
40
31
29
14
45
32
31
18
19
6
39
39
6
19
18
31
32
45
29
40
45
43
31
14
43
44
26
49
45
13
44
13
43
49
18
29
2
35
3
25

output:

42

result:

ok single line: '42'

Test #24:

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

input:

50 50
26
48
16
49
22
33
2
8
38
7
38
6
2
25
7
8
37
20
8
6
11
22
6
19
20
33
32
45
12
12
45
32
33
20
19
6
37
22
20
11
8
6
8
7
25
2
6
38
7
38

output:

42

result:

ok single line: '42'

Test #25:

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

input:

50 50
30
40
35
47
29
19
35
36
4
12
1
13
8
32
36
29
41
43
36
30
29
18
6
6
6
29
6
6
30
6
6
18
36
6
6
43
6
6
6
6
6
41
29
36
32
8
13
25
50
39

output:

36

result:

ok single line: '36'

Test #26:

score: 10
Accepted
time: 1ms
memory: 5708kb

input:

50 50
12
1
26
38
43
19
15
22
10
45
45
45
45
45
8
45
45
15
33
45
45
21
45
45
22
45
45
45
33
22
21
15
8
10
22
15
19
43
38
50
39
47
15
16
32
22
4
16
11
21

output:

36

result:

ok single line: '36'

Test #27:

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

input:

1 1
1

output:

1

result:

ok single line: '1'

Test #28:

score: 10
Accepted
time: 1ms
memory: 5792kb

input:

50 50
2
2
2
8
8
2
8
9
9
9
11
9
11
11
14
14
14
14
16
16
16
21
22
21
21
22
22
22
23
23
25
23
25
25
25
26
26
26
27
27
27
27
31
33
38
39
41
42
44
46

output:

4

result:

ok single line: '4'

Test #29:

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

input:

50 50
2
2
2
8
2
8
2
9
9
9
9
11
11
9
14
14
16
14
16
16
14
21
21
21
22
22
22
21
23
23
25
23
23
23
25
26
26
26
27
26
26
27
31
33
38
39
41
42
44
46

output:

5

result:

ok single line: '5'

Test #30:

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

input:

50 50
2
2
2
2
8
2
8
9
9
11
9
11
9
11
14
14
16
16
16
14
16
21
21
21
21
21
22
22
23
25
23
23
23
25
25
26
26
27
26
26
27
27
31
33
38
39
41
42
44
46

output:

5

result:

ok single line: '5'

Test #31:

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

input:

50 50
8
2
2
8
2
8
8
9
11
9
11
9
11
11
14
14
16
16
14
16
16
21
22
22
22
21
22
22
25
23
23
23
25
25
25
27
26
27
26
27
27
27
31
33
38
39
41
42
44
46

output:

5

result:

ok single line: '5'

Test #32:

score: 10
Accepted
time: 1ms
memory: 5940kb

input:

50 50
2
6
6
2
6
6
6
8
7
7
8
8
8
8
9
10
9
10
10
10
10
11
11
13
13
13
13
13
14
16
17
18
21
22
23
24
25
26
27
31
32
33
36
38
39
41
42
43
44
46

output:

5

result:

ok single line: '5'

Test #33:

score: 10
Accepted
time: 1ms
memory: 5660kb

input:

50 50
2
2
2
2
8
2
2
9
9
9
11
11
9
9
21
16
21
21
21
16
16
23
23
23
23
23
25
23
31
31
26
26
26
31
26
33
33
38
33
33
38
33
42
41
42
41
41
42
41
44

output:

6

result:

ok single line: '6'

Test #34:

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

input:

50 50
2
2
8
8
2
8
2
11
9
11
11
9
11
9
21
16
16
16
21
21
16
23
25
23
23
25
25
23
31
26
26
31
31
31
26
33
38
33
38
38
38
33
41
41
42
42
42
42
41
44

output:

6

result:

ok single line: '6'

Test #35:

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

input:

50 50
2
2
2
2
2
2
8
9
11
9
9
9
9
11
16
21
21
16
16
16
21
23
25
23
25
23
23
25
26
26
31
31
26
26
31
33
38
38
38
33
33
38
42
41
41
41
42
41
42
44

output:

6

result:

ok single line: '6'

Test #36:

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

input:

50 50
2
8
2
2
8
2
8
9
11
11
9
11
9
11
21
16
16
21
21
16
21
23
25
23
25
25
23
25
26
31
31
31
31
26
31
38
33
33
33
33
38
38
42
41
42
41
41
42
42
44

output:

6

result:

ok single line: '6'

Test #37:

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

input:

50 50
2
8
8
2
2
8
8
11
9
11
11
9
11
11
16
16
14
14
16
16
16
22
22
21
22
22
22
22
25
23
25
25
25
25
25
26
27
27
27
27
27
27
31
33
38
39
41
42
44
46

output:

6

result:

ok single line: '6'

Subtask #2:

score: 90
Accepted

Dependency #1:

100%
Accepted

Test #38:

score: 90
Accepted
time: 177ms
memory: 38596kb

input:

3000 3000
2490
1807
1830
1135
2223
2019
1405
154
304
922
1902
453
2664
565
1282
1131
1981
1729
918
161
1384
962
890
881
2685
1415
1844
2799
2641
513
1724
53
555
1723
801
150
2694
2027
2233
1732
2067
1413
2291
2813
2747
688
2720
2948
1628
505
1116
895
2828
1120
1223
26
2801
436
2791
1038
174
1596
7
2...

output:

1

result:

ok single line: '1'

Test #39:

score: 90
Accepted
time: 175ms
memory: 38904kb

input:

3000 3000
801
1677
864
1453
1858
1375
1814
989
864
2545
1420
988
1415
1847
1376
414
1200
1245
901
433
1470
1853
989
839
1562
1771
1594
989
1843
1956
767
1313
1842
1623
1356
2330
1594
1415
223
1980
1470
1200
1667
1741
2089
917
524
1190
979
1376
1594
1357
1470
1667
1682
1177
1444
1356
1623
2104
1415
9...

output:

54

result:

ok single line: '54'

Test #40:

score: 90
Accepted
time: 171ms
memory: 38360kb

input:

3000 3000
1626
2344
1324
875
1618
2013
1863
1439
2542
1303
897
2013
1644
1143
1548
1618
1863
1626
1951
1531
1688
1046
1143
1378
1335
1940
1381
1756
822
2417
1667
1756
293
2542
1531
1626
1869
2162
2084
1319
2011
1586
1625
1869
1792
1378
1628
1154
1792
1319
2460
1863
1048
2568
1586
2100
1564
1513
1801...

output:

54

result:

ok single line: '54'

Test #41:

score: 90
Accepted
time: 172ms
memory: 37676kb

input:

3000 3000
26
70
70
73
74
74
89
90
93
93
93
93
93
94
94
94
104
112
112
113
114
114
114
114
114
114
114
143
143
143
147
149
149
149
149
149
151
151
155
176
176
185
187
195
195
199
210
210
210
210
210
211
226
228
241
241
241
241
241
241
241
243
243
243
243
243
249
261
267
267
279
279
279
279
279
280
28...

output:

144

result:

ok single line: '144'

Test #42:

score: 90
Accepted
time: 167ms
memory: 38608kb

input:

3000 3000
2
17
23
24
42
42
42
48
60
61
79
79
84
91
91
91
91
94
94
94
100
109
109
109
125
126
126
126
133
133
133
137
137
145
145
145
145
145
171
199
203
2889
2888
2887
2887
2887
2887
2887
2887
2887
2858
2858
2858
2854
2852
2852
2852
2852
2852
2850
2850
2846
2825
2825
2816
2814
2806
2806
2802
2791
27...

output:

144

result:

ok single line: '144'

Test #43:

score: 90
Accepted
time: 180ms
memory: 38000kb

input:

3000 3000
622
622
622
622
1418
587
622
1442
622
587
2520
587
622
587
622
587
622
622
1442
1442
587
587
1106
622
1442
587
2520
1442
587
587
587
587
587
622
1442
622
587
587
587
622
587
622
1418
622
622
587
622
622
622
587
1442
622
622
622
622
622
622
622
587
587
2520
1442
622
1442
622
622
587
622
622...

output:

1491

result:

ok single line: '1491'

Test #44:

score: 90
Accepted
time: 176ms
memory: 38508kb

input:

3000 3000
2379
2379
2379
1559
2414
2379
2379
2379
2379
1559
2379
2379
2414
1559
2379
2379
1559
2414
2414
2379
2414
2379
2414
2414
1559
2379
2414
2414
1622
2379
481
2379
2379
2379
2414
2379
1559
1559
1622
1559
2379
2379
2379
2414
2379
2379
2379
2379
2414
1559
2379
2379
2379
2379
2414
2414
1559
2414
2...

output:

1491

result:

ok single line: '1491'

Test #45:

score: 90
Accepted
time: 173ms
memory: 38236kb

input:

3000 3000
2389
863
1152
2081
2402
2342
1892
1643
1361
618
1702
2694
2319
2351
2765
2036
2132
993
1922
1764
1957
583
2336
1622
1278
816
2283
511
206
1875
1180
1278
2032
2276
2856
1230
864
914
2367
2353
578
974
2404
1359
2766
1288
2336
2418
1129
2497
1627
655
2602
1769
2349
800
2102
1684
1368
690
1876...

output:

767

result:

ok single line: '767'

Test #46:

score: 90
Accepted
time: 173ms
memory: 38500kb

input:

3000 3000
1012
27
935
1432
7
2540
2923
124
2686
2974
1360
1175
1814
1830
1156
1685
720
2160
19
1879
669
2250
2987
2843
2357
699
51
1473
129
1109
20
2939
2192
2151
1272
2438
764
2255
1750
537
491
1100
2774
95
1426
704
59
1133
2013
209
345
1964
40
1976
1346
594
616
1172
1562
2909
958
745
1957
1081
172...

output:

767

result:

ok single line: '767'

Test #47:

score: 90
Accepted
time: 175ms
memory: 37848kb

input:

3000 3000
2979
1186
1713
1746
2403
1481
2530
181
2295
1585
1323
159
2530
1479
1905
2926
1933
2545
2514
2055
2940
99
179
2563
2705
891
1492
1491
1224
664
918
2260
178
639
43
2654
1237
36
350
7
1771
2930
2214
896
1214
1605
2127
1458
2894
2055
419
514
2214
1014
2037
393
6
2306
1850
1827
2686
1620
550
1...

output:

820

result:

ok single line: '820'

Test #48:

score: 90
Accepted
time: 177ms
memory: 37992kb

input:

3000 3000
2191
363
1536
130
1187
2815
1264
1528
335
1398
1213
80
278
142
320
2242
2575
593
917
1560
1916
420
80
1319
187
486
2517
195
1649
2426
1934
17
909
159
606
2976
723
357
1628
1752
514
199
2931
737
913
492
537
2064
518
113
1481
1419
2816
1599
2507
797
2879
78
2735
2574
1679
1497
1908
2990
390
...

output:

820

result:

ok single line: '820'

Test #49:

score: 90
Accepted
time: 175ms
memory: 37652kb

input:

3000 3000
461
612
1136
2473
815
2086
1537
2868
1415
589
1567
2010
1079
2674
756
1191
1947
2940
354
2346
765
741
19
2598
2520
109
1693
1765
1180
2858
1923
111
1274
146
303
1124
443
1750
2433
993
974
2948
2765
2073
2667
2157
790
2415
2689
2157
154
2367
2681
1288
1695
385
1650
2436
2710
2738
2838
2383
...

output:

2113

result:

ok single line: '2113'

Test #50:

score: 90
Accepted
time: 171ms
memory: 38044kb

input:

3000 3000
2936
796
1809
2109
2520
34
2888
111
1417
138
1102
2187
2093
2164
2813
64
1545
2783
1607
1726
36
1981
208
2810
1441
296
1799
2678
2799
464
673
400
2932
1569
67
548
686
1852
1977
2677
572
2632
137
1449
442
60
1516
2891
2427
280
2933
1347
2794
1338
398
1065
1619
2179
594
2277
2452
1912
1916
1...

output:

2113

result:

ok single line: '2113'

Test #51:

score: 90
Accepted
time: 173ms
memory: 38256kb

input:

3000 3000
1218
61
972
10
2224
2937
512
1944
923
2890
1862
522
2891
531
2888
2700
1973
179
1548
2575
1877
1574
52
2608
2369
2521
1958
1690
1222
2243
2541
1594
2774
2851
215
2542
69
642
1224
2140
2968
2983
2858
186
806
2945
5
62
2432
2272
2711
860
129
1227
1395
300
72
2550
177
735
2913
2974
396
1404
2...

output:

2388

result:

ok single line: '2388'

Test #52:

score: 90
Accepted
time: 168ms
memory: 38920kb

input:

3000 3000
513
1286
2435
758
158
275
1293
1419
2504
2154
939
988
564
455
2434
538
485
1645
2247
1409
1156
243
105
985
2990
161
604
1401
1024
2209
14
917
1786
2613
2697
1296
654
98
1896
598
591
1340
149
1709
73
2746
2107
536
926
154
839
811
2868
1018
1194
1310
608
1366
1365
1963
2848
2269
1912
530
104...

output:

2388

result:

ok single line: '2388'

Test #53:

score: 90
Accepted
time: 165ms
memory: 38816kb

input:

3000 3000
910
84
338
84
373
84
338
84
2079
84
338
84
373
84
338
84
910
84
338
84
373
84
338
84
978
84
338
84
373
84
338
84
910
84
338
84
373
84
338
84
1054
84
338
84
373
84
338
84
910
84
338
84
373
84
338
84
978
84
338
84
373
84
338
84
910
84
338
84
373
84
338
84
1221
84
338
84
373
84
338
84
910
84
...

output:

2047

result:

ok single line: '2047'

Test #54:

score: 90
Accepted
time: 165ms
memory: 37776kb

input:

3000 3000
2917
2663
2917
2628
2917
2663
2917
2091
2917
2663
2917
2628
2917
2663
2917
1947
2917
2663
2917
2628
2917
2663
2917
2091
2917
2663
2917
2628
2917
2663
2917
2023
2917
2663
2917
2628
2917
2663
2917
2091
2917
2663
2917
2628
2917
2663
2917
1504
2917
2663
2917
2628
2917
2663
2917
2091
2917
2663
...

output:

2047

result:

ok single line: '2047'

Test #55:

score: 90
Accepted
time: 135ms
memory: 38564kb

input:

3000 3000
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
1296
...

output:

3000

result:

ok single line: '3000'

Test #56:

score: 90
Accepted
time: 174ms
memory: 37836kb

input:

3000 3000
34
2365
476
2086
999
425
1978
2426
1548
2172
916
2663
2494
2123
1626
1167
1271
1318
2173
2652
378
81
2122
587
404
2901
133
72
408
102
898
254
182
2081
1007
1789
1386
81
2543
2577
2780
2955
2964
744
2797
1006
2998
1702
1418
674
1747
2449
1805
1600
1736
2667
1684
1018
2877
529
143
2497
2812
...

output:

1026

result:

ok single line: '1026'

Test #57:

score: 90
Accepted
time: 173ms
memory: 37844kb

input:

3000 3000
242
2166
36
33
57
1212
1720
132
38
99
1905
2863
1753
286
1379
1848
736
1064
1469
2754
621
1375
240
29
1575
2175
2578
1303
1058
88
2221
1663
2936
2993
69
2132
902
2969
2755
48
1964
2471
32
1738
725
1558
22
674
47
2970
1866
879
1976
2446
490
16
2521
2781
2324
1840
1336
345
470
1885
525
665
3...

output:

1026

result:

ok single line: '1026'

Test #58:

score: 90
Accepted
time: 177ms
memory: 38244kb

input:

3000 3000
2688
173
1520
1283
1535
1783
350
2895
2147
2470
2927
183
1527
2314
2055
223
2998
345
2089
1263
1823
1318
1980
2416
2986
2982
372
1713
160
2055
2516
400
2361
2961
1541
896
2175
1231
2357
2417
2981
2987
1816
2816
1844
476
868
2939
2152
2380
2668
59
1173
1848
1417
1271
2615
2955
2515
192
63
1...

output:

1130

result:

ok single line: '1130'

Test #59:

score: 90
Accepted
time: 171ms
memory: 38924kb

input:

3000 3000
38
1394
2476
1327
2089
414
2486
2784
44
3000
130
2663
2945
2997
464
2993
2227
2446
738
1229
656
2531
258
2480
2030
1972
986
1054
1544
2200
2067
774
2773
1829
231
2970
1031
73
2676
1581
247
1057
2069
2675
32
2632
1176
304
933
2979
587
2095
2018
2036
2037
176
2634
1187
2092
2922
472
2965
246...

output:

1130

result:

ok single line: '1130'

Test #60:

score: 90
Accepted
time: 164ms
memory: 38772kb

input:

3000 3000
1211
1615
2991
263
802
2048
68
429
214
253
1424
2927
2484
1575
2951
875
1258
2331
1129
2973
2518
1915
1605
704
2885
1136
605
206
428
1638
2864
2846
2822
1045
1347
1662
28
760
114
1034
795
2988
417
168
2736
2497
500
102
511
887
754
2748
2993
2140
1057
2884
1521
885
1166
2338
162
688
2639
37...

output:

1899

result:

ok single line: '1899'

Test #61:

score: 90
Accepted
time: 169ms
memory: 38308kb

input:

3000 3000
2282
2946
852
699
2670
2354
1784
171
2117
895
1699
188
2063
687
180
186
1629
1810
2769
2569
50
1584
730
2857
736
1809
690
2526
454
2776
2902
2745
647
2261
1730
339
1295
2782
2868
2177
2067
677
347
2730
2979
417
1505
2544
478
4
1288
53
1562
1828
2549
447
217
453
971
1263
2357
1599
911
2653
...

output:

1899

result:

ok single line: '1899'

Test #62:

score: 90
Accepted
time: 176ms
memory: 38476kb

input:

3000 3000
1975
1053
2605
980
2168
2684
2292
2997
2655
2622
1334
1565
1028
2808
2013
2414
1679
2849
1940
118
299
2729
1752
749
2814
311
1198
149
465
971
638
1096
716
574
1731
184
2477
2895
2134
2182
2879
18
602
1266
932
2937
2522
973
2994
595
102
1290
692
2097
779
2899
88
978
1635
379
299
1411
968
19...

output:

2174

result:

ok single line: '2174'

Test #63:

score: 90
Accepted
time: 176ms
memory: 37756kb

input:

3000 3000
2959
208
1465
2668
643
2737
144
1950
19
2842
1558
2285
530
2268
2604
727
546
626
491
2675
1169
2962
488
1502
1982
1618
63
1307
1984
784
2133
2871
2719
337
1021
1025
1261
917
2831
168
2092
2673
655
148
2591
2991
2054
154
2315
2916
2787
2986
1507
1505
414
666
2149
2911
2097
884
2962
1984
838...

output:

2174

result:

ok single line: '2174'

Test #64:

score: 90
Accepted
time: 144ms
memory: 38236kb

input:

3000 3000
1
1
1
1
2
2
2
1
2
3
3
3
5
3
5
3
5
5
6
6
6
6
7
7
6
7
7
8
8
8
9
9
9
8
9
9
11
11
12
11
11
11
12
12
12
13
13
13
14
13
13
14
14
14
15
15
15
15
16
15
16
16
16
17
17
18
17
18
17
18
18
18
19
19
19
20
20
19
20
20
20
21
21
21
21
21
22
22
22
22
23
24
23
23
23
24
24
24
24
25
25
26
25
25
26
26
26
26
27...

output:

5

result:

ok single line: '5'

Test #65:

score: 90
Accepted
time: 146ms
memory: 37888kb

input:

3000 3000
1
1
1
1
2
2
1
2
1
3
3
3
3
5
3
5
5
3
6
6
6
6
6
7
7
7
6
8
8
9
8
8
9
9
9
8
11
11
11
12
11
12
12
12
11
13
13
13
13
14
14
14
14
13
15
15
15
15
16
16
15
15
16
17
17
17
17
18
17
18
17
18
19
19
19
20
20
19
20
19
20
21
21
21
21
21
22
22
21
22
23
23
24
23
23
24
24
23
24
25
25
25
26
25
26
26
25
26
27...

output:

6

result:

ok single line: '6'

Test #66:

score: 90
Accepted
time: 145ms
memory: 37632kb

input:

3000 3000
1
2
2
1
1
1
2
1
1
3
7
3
7
3
3
7
3
3
8
8
8
8
9
8
9
8
8
11
11
11
11
11
13
13
11
11
14
15
14
14
14
15
15
14
14
16
16
16
18
16
18
18
16
16
19
19
19
19
20
20
20
19
19
21
21
21
22
21
21
21
22
21
23
23
24
24
23
23
23
24
23
25
25
25
25
26
25
25
26
25
27
27
28
27
28
27
27
28
27
30
30
30
30
30
31
30...

output:

7

result:

ok single line: '7'

Test #67:

score: 90
Accepted
time: 149ms
memory: 37944kb

input:

3000 3000
2
1
2
2
2
1
1
1
1
3
3
3
3
3
7
3
3
3
9
8
9
9
8
9
8
8
8
11
11
11
11
13
13
11
11
11
15
14
15
14
15
15
14
14
14
18
16
16
18
18
18
16
16
16
19
20
19
20
20
20
19
19
19
21
21
21
21
21
21
22
21
21
24
24
23
23
23
23
24
23
23
26
25
26
25
25
25
26
25
25
27
27
27
28
27
27
28
27
27
31
30
30
31
30
30
31...

output:

8

result:

ok single line: '8'

Extra Test:

score: 0
Extra Test Passed