Submission #892146

# Submission time Handle Problem Language Result Execution time Memory
892146 2023-12-25T01:11:18 Z MilosMilutinovic New Home (APIO18_new_home) C++14
100 / 100
4162 ms 340176 KB
#include <bits/stdc++.h>
 
using namespace std;

const int N = (int) 4e6;

const int inf = (int) 1e9;

int mn[N], mx[N], sz;

void Build(int x, int l, int r) {
  mn[x] = inf;
  mx[x] = -inf;
  if (l == r) {
    return;
  }
  int mid = l + r >> 1;
  Build(x << 1, l, mid);
  Build(x << 1 | 1, mid + 1, r);
}

void ModifyMin(int x, int l, int r, int p, int v) {
  if (l == r) {
    mn[x] = v;
    return;
  }
  int mid = l + r >> 1;
  if (p <= mid) {
    ModifyMin(x << 1, l, mid, p, v);
  } else {
    ModifyMin(x << 1 | 1, mid + 1, r, p, v);
  }
  mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
}

void ModifyMax(int x, int l, int r, int p, int v) {
  if (l == r) {
    mx[x] = v;
    return;
  }
  int mid = l + r >> 1;
  if (p <= mid) {
    ModifyMax(x << 1, l, mid, p, v);
  } else {
    ModifyMax(x << 1 | 1, mid + 1, r, p, v);
  }
  mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}

void ChangeMin(int p, int v) {
  ModifyMin(1, 0, sz - 1, p, v);
}

void ChangeMax(int p, int v) {
  ModifyMax(1, 0, sz - 1, p, v);
}

int query_max(int x, int l, int r, int ll, int rr) {
  if (l > r || l > rr || r < ll) {
    return -inf;
  }
  if (ll <= l && r <= rr) {
    return mx[x];
  }
  int mid = l + r >> 1;
  return max(query_max(x << 1, l, mid, ll, rr), query_max(x << 1 | 1, mid + 1, r, ll, rr));
}

int query_min(int x, int l, int r, int ll, int rr) {
  if (l > r || l > rr || r < ll) {
    return inf;
  }
  if (ll <= l && r <= rr) {
    return mn[x];
  }
  int mid = l + r >> 1;
  return min(query_min(x << 1, l, mid, ll, rr), query_min(x << 1 | 1, mid + 1, r, ll, rr));
}

int get_max(int l, int r) {
  return query_max(1, 0, sz - 1, l, r);
}

int get_min(int l, int r) {
  return query_min(1, 0, sz - 1, l, r);
}

vector<multiset<tuple<int, int, int>>> open;
vector<array<int, 4>> ev;
vector<multiset<int>> my;

void Insert(int t, int x, int y) {
  auto ptr = my[t].lower_bound(x);
  if (ptr != my[t].begin() && ptr != my[t].end()) {
    auto it = open[t].lower_bound({*prev(ptr), *ptr, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  } else if (ptr != my[t].begin()) {
    auto it = open[t].lower_bound({*prev(ptr), inf, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  } else if (ptr != my[t].end()) {
    auto it = open[t].lower_bound({-inf, *ptr, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  }
  if (ptr != my[t].end()) {
    open[t].emplace(x, *ptr, y);
  } else {
    open[t].emplace(x, inf, y);
  }
  if (ptr != my[t].begin()) {
    ptr = prev(ptr);
    open[t].emplace(*ptr, x, y);
  } else {
    open[t].emplace(-inf, x, y);
  }
  my[t].insert(x);
}

void Remove(int t, int x, int y) {
  auto ptr = my[t].lower_bound(x);
  if (ptr != prev(my[t].end())) {
    auto it = open[t].lower_bound({x, *next(ptr), -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  } else {
    auto it = open[t].lower_bound({x, inf, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  }
  if (ptr != my[t].begin()) {
    auto it = open[t].lower_bound({*prev(ptr), x, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  } else {
    auto it = open[t].lower_bound({-inf, x, -1});
    ev.push_back({get<0>(*it), get<1>(*it), get<2>(*it), y});
    open[t].erase(it);
  }
  if (ptr != my[t].begin() && ptr != prev(my[t].end())) {
    open[t].emplace(*prev(ptr), *next(ptr), y);
  } else if (ptr != my[t].begin()) {
    open[t].emplace(*prev(ptr), inf, y);
  } else if (ptr != prev(my[t].end())) {
    open[t].emplace(-inf, *next(ptr), y);
  }
  my[t].erase(my[t].find(x));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> x(n);
  vector<int> t(n);
  vector<int> a(n);
  vector<int> b(n);
  map<pair<int, int>, vector<pair<int, int>>> mp;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> t[i] >> a[i] >> b[i];
    --t[i]; ++b[i];
    mp[{x[i], t[i]}].emplace_back(a[i], b[i]);
  }
  vector<int> new_x;
  vector<int> new_t;
  vector<int> new_a;
  vector<int> new_b;
  for (auto& p : mp) {
    vector<pair<int, int>> v = p.second;
    sort(v.begin(), v.end());
    int sz = (int) v.size();
    for (int i = 0; i < sz; i++) {
      int ptr = i;
      int mx = v[i].second;
      while (ptr + 1 < sz && v[ptr + 1].first < mx) {
        ptr += 1;
        mx = max(mx, v[ptr].second);
      }
      new_x.push_back(p.first.first);
      new_t.push_back(p.first.second);
      new_a.push_back(v[i].first);
      new_b.push_back(mx);
      i = ptr;
    }
  }
  x = new_x;
  t = new_t;
  a = new_a;
  b = new_b;
  n = (int) x.size();
  vector<int> l(q);
  vector<int> y(q);
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> y[i];
  }
  vector<int> xs(1, 1e9);
  for (int i = 0; i < n; i++) {
    xs.push_back(a[i]);
    xs.push_back(b[i]);
  }
  for (int i = 0; i < q; i++) {
    xs.push_back(y[i]);
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    a[i] = (int) (lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin());
    b[i] = (int) (lower_bound(xs.begin(), xs.end(), b[i]) - xs.begin());
  }
  for (int i = 0; i < q; i++) {
    y[i] = (int) (lower_bound(xs.begin(), xs.end(), y[i]) - xs.begin());
  }
  int T = (int) xs.size();
  vector<vector<int>> ids(T);
  for (int i = 0; i < n; i++) {
    ids[a[i]].push_back(i);
    ids[b[i]].push_back(~i);
  }
  open.resize(k);
  my.resize(k);
  for (int i = 0; i < T; i++) {
    sort(ids[i].begin(), ids[i].end());
    for (int j : ids[i]) {
      if (j >= 0) {
        Insert(t[j], x[j], i);
      } else {
        j = ~j;
        Remove(t[j], x[j], i);
      }
    }
  }
  for (int i = 0; i < k; i++) {
    for (auto& p : open[i]) {
      ev.push_back({get<0>(p), get<1>(p), get<2>(p), T - 1});
    }
  }
  vector<vector<int>> qs(T);
  for (int i = 0; i < q; i++) {
    qs[y[i]].push_back(i);
  }
  vector<pair<int, int>> min_with;
  vector<pair<int, int>> max_with;
  for (auto& p : ev) {
    int L = p[0];
    int R = p[1];
    int mid = (L + R) / 2;
    min_with.emplace_back(L, mid);
    max_with.emplace_back(R, mid + (L % 2 != R % 2));
  }
  sort(min_with.begin(), min_with.end(), [&](pair<int, int> p, pair<int, int> q) {
    return p.second > q.second;
  });
  sort(max_with.begin(), max_with.end(), [&](pair<int, int> p, pair<int, int> q) {
    return p.second < q.second;
  });
  sz = (int) ev.size();
  vector<int> order_mn(sz);
  iota(order_mn.begin(), order_mn.end(), 0);
  sort(order_mn.begin(), order_mn.end(), [&](int i, int j) {
    return (ev[i][0] + ev[i][1]) / 2 > (ev[j][0] + ev[j][1]) / 2;
  });
  vector<int> order_mx(sz);
  iota(order_mx.begin(), order_mx.end(), 0);
  sort(order_mx.begin(), order_mx.end(), [&](int i, int j) {
    return (ev[i][0] + ev[i][1]) / 2 + (ev[i][0] % 2 != ev[i][1] % 2) < 
           (ev[j][0] + ev[j][1]) / 2 + (ev[j][0] % 2 != ev[j][1] % 2);
  });
  vector<int> idx_mn(sz);
  vector<int> idx_mx(sz);
  for (int i = 0; i < sz; i++) {
    idx_mn[order_mn[i]] = i;
    idx_mx[order_mx[i]] = i;
  }
  vector<vector<int>> qs_mn(T);
  vector<vector<int>> qs_mx(T);
  for (int i = 0; i < sz; i++) {
    int L = ev[i][0];
    int R = ev[i][1];
    int from = ev[i][2];
    int to = ev[i][3];
    int mid = (L + R) / 2;
    {
      int idx = idx_mn[i];
      qs_mn[from].push_back(idx);
      qs_mn[to].push_back(~idx);
    }
    {
      int idx = idx_mx[i];
      qs_mx[from].push_back(idx);
      qs_mx[to].push_back(~idx);
    }
  }
  Build(1, 0, sz - 1);
  vector<int> res(q);
  for (int i = 0; i < T; i++) {
    for (int j : qs_mn[i]) {
      if (j >= 0) {
        ChangeMin(j, min_with[j].first);
      } else {
        j = ~j;
        ChangeMin(j, inf);
      }
    }
    for (int j : qs_mx[i]) {
      if (j >= 0) {
        ChangeMax(j, max_with[j].first);
      } else {
        j = ~j;
        ChangeMax(j, -inf);
      }
    }
    for (int j : qs[i]) {
      {
        int low = 0, high = sz - 1, pos = -1;
        while (low <= high) {
          int mid = low + high >> 1;
          if (min_with[mid].second >= l[j]) {
            pos = mid;
            low = mid + 1;
          } else {
            high = mid - 1;
          }
        }
        if (pos != -1) {
          res[j] = max(res[j], l[j] - get_min(0, pos));
        }
      }
      {
        int low = 0, high = sz - 1, pos = -1;
        while (low <= high) {
          int mid = low + high >> 1;
          if (max_with[mid].second <= l[j]) {
            pos = mid;
            low = mid + 1;
          } else {
            high = mid - 1;
          }
        }
        if (pos != -1) {
          res[j] = max(res[j], get_max(0, pos) - l[j]);
        }
      }
    }
  }
  vector<vector<int>> qs_type(T);
  for (int i = 0; i < n; i++) {
    qs_type[a[i]].push_back(t[i]);
    qs_type[b[i]].push_back(~t[i]);
  }
  int bal = 0;
  vector<int> cnt(k);
  for (int i = 0; i < T; i++) {
    for (int j : qs_type[i]) {
      if (j >= 0) {
        cnt[j] += 1;
        if (cnt[j] == 1) {
          bal += 1;
        }
      } else {
        j = ~j;
        cnt[j] -= 1;
        if (cnt[j] == 0) {
          bal -= 1;
        }
      }
    }
    for (int j : qs[i]) {
      if (bal != k) {
        res[j] = -1;
      }
    }
  }
  for (int i = 0; i < q; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}

/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10


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


1 1 1
100000000 1 1 1
1 1
*/

Compilation message

new_home.cpp: In function 'void Build(int, int, int)':
new_home.cpp:17:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |   int mid = l + r >> 1;
      |             ~~^~~
new_home.cpp: In function 'void ModifyMin(int, int, int, int, int)':
new_home.cpp:27:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |   int mid = l + r >> 1;
      |             ~~^~~
new_home.cpp: In function 'void ModifyMax(int, int, int, int, int)':
new_home.cpp:41:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |   int mid = l + r >> 1;
      |             ~~^~~
new_home.cpp: In function 'int query_max(int, int, int, int, int)':
new_home.cpp:65:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |   int mid = l + r >> 1;
      |             ~~^~~
new_home.cpp: In function 'int query_min(int, int, int, int, int)':
new_home.cpp:76:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |   int mid = l + r >> 1;
      |             ~~^~~
new_home.cpp: In function 'int main()':
new_home.cpp:283:9: warning: unused variable 'mid' [-Wunused-variable]
  283 |     int mid = (L + R) / 2;
      |         ^~~
new_home.cpp:318:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  318 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
new_home.cpp:333:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  333 |           int mid = low + high >> 1;
      |                     ~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2892 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2904 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2868 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2524 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2892 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2904 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2868 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2524 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 464 ms 66704 KB Output is correct
32 Correct 35 ms 6352 KB Output is correct
33 Correct 462 ms 67184 KB Output is correct
34 Correct 439 ms 67904 KB Output is correct
35 Correct 466 ms 65592 KB Output is correct
36 Correct 475 ms 66104 KB Output is correct
37 Correct 401 ms 66152 KB Output is correct
38 Correct 400 ms 65852 KB Output is correct
39 Correct 347 ms 66272 KB Output is correct
40 Correct 367 ms 65788 KB Output is correct
41 Correct 421 ms 65848 KB Output is correct
42 Correct 394 ms 65804 KB Output is correct
43 Correct 37 ms 8440 KB Output is correct
44 Correct 392 ms 67304 KB Output is correct
45 Correct 392 ms 66040 KB Output is correct
46 Correct 380 ms 66344 KB Output is correct
47 Correct 276 ms 63932 KB Output is correct
48 Correct 265 ms 63156 KB Output is correct
49 Correct 305 ms 65216 KB Output is correct
50 Correct 319 ms 66204 KB Output is correct
51 Correct 317 ms 64440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1735 ms 191492 KB Output is correct
2 Correct 1678 ms 185568 KB Output is correct
3 Correct 1136 ms 207884 KB Output is correct
4 Correct 1663 ms 194236 KB Output is correct
5 Correct 1744 ms 185008 KB Output is correct
6 Correct 1622 ms 184796 KB Output is correct
7 Correct 1133 ms 207712 KB Output is correct
8 Correct 1648 ms 191264 KB Output is correct
9 Correct 1840 ms 185396 KB Output is correct
10 Correct 1728 ms 186084 KB Output is correct
11 Correct 1276 ms 184160 KB Output is correct
12 Correct 1408 ms 186712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2936 ms 242304 KB Output is correct
2 Correct 155 ms 19908 KB Output is correct
3 Correct 2827 ms 247072 KB Output is correct
4 Correct 1774 ms 263060 KB Output is correct
5 Correct 2677 ms 253144 KB Output is correct
6 Correct 2528 ms 253504 KB Output is correct
7 Correct 2938 ms 247584 KB Output is correct
8 Correct 2784 ms 248764 KB Output is correct
9 Correct 1723 ms 270700 KB Output is correct
10 Correct 2570 ms 256828 KB Output is correct
11 Correct 2918 ms 250312 KB Output is correct
12 Correct 2897 ms 248092 KB Output is correct
13 Correct 1522 ms 243328 KB Output is correct
14 Correct 1481 ms 240696 KB Output is correct
15 Correct 1685 ms 245896 KB Output is correct
16 Correct 1849 ms 248464 KB Output is correct
17 Correct 1805 ms 243108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2892 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2904 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2868 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2524 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 464 ms 66704 KB Output is correct
32 Correct 35 ms 6352 KB Output is correct
33 Correct 462 ms 67184 KB Output is correct
34 Correct 439 ms 67904 KB Output is correct
35 Correct 466 ms 65592 KB Output is correct
36 Correct 475 ms 66104 KB Output is correct
37 Correct 401 ms 66152 KB Output is correct
38 Correct 400 ms 65852 KB Output is correct
39 Correct 347 ms 66272 KB Output is correct
40 Correct 367 ms 65788 KB Output is correct
41 Correct 421 ms 65848 KB Output is correct
42 Correct 394 ms 65804 KB Output is correct
43 Correct 37 ms 8440 KB Output is correct
44 Correct 392 ms 67304 KB Output is correct
45 Correct 392 ms 66040 KB Output is correct
46 Correct 380 ms 66344 KB Output is correct
47 Correct 276 ms 63932 KB Output is correct
48 Correct 265 ms 63156 KB Output is correct
49 Correct 305 ms 65216 KB Output is correct
50 Correct 319 ms 66204 KB Output is correct
51 Correct 317 ms 64440 KB Output is correct
52 Correct 322 ms 68128 KB Output is correct
53 Correct 302 ms 68160 KB Output is correct
54 Correct 419 ms 67136 KB Output is correct
55 Correct 358 ms 66756 KB Output is correct
56 Correct 362 ms 66492 KB Output is correct
57 Correct 382 ms 67008 KB Output is correct
58 Correct 386 ms 66364 KB Output is correct
59 Correct 371 ms 68512 KB Output is correct
60 Correct 404 ms 67228 KB Output is correct
61 Correct 127 ms 34796 KB Output is correct
62 Correct 293 ms 68292 KB Output is correct
63 Correct 381 ms 66812 KB Output is correct
64 Correct 406 ms 67132 KB Output is correct
65 Correct 447 ms 67392 KB Output is correct
66 Correct 419 ms 66588 KB Output is correct
67 Correct 211 ms 31284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 2 ms 2892 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 2 ms 2908 KB Output is correct
9 Correct 2 ms 2908 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 2 ms 2908 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 2 ms 2908 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 2 ms 2904 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2868 KB Output is correct
26 Correct 2 ms 2908 KB Output is correct
27 Correct 2 ms 2524 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 464 ms 66704 KB Output is correct
32 Correct 35 ms 6352 KB Output is correct
33 Correct 462 ms 67184 KB Output is correct
34 Correct 439 ms 67904 KB Output is correct
35 Correct 466 ms 65592 KB Output is correct
36 Correct 475 ms 66104 KB Output is correct
37 Correct 401 ms 66152 KB Output is correct
38 Correct 400 ms 65852 KB Output is correct
39 Correct 347 ms 66272 KB Output is correct
40 Correct 367 ms 65788 KB Output is correct
41 Correct 421 ms 65848 KB Output is correct
42 Correct 394 ms 65804 KB Output is correct
43 Correct 37 ms 8440 KB Output is correct
44 Correct 392 ms 67304 KB Output is correct
45 Correct 392 ms 66040 KB Output is correct
46 Correct 380 ms 66344 KB Output is correct
47 Correct 276 ms 63932 KB Output is correct
48 Correct 265 ms 63156 KB Output is correct
49 Correct 305 ms 65216 KB Output is correct
50 Correct 319 ms 66204 KB Output is correct
51 Correct 317 ms 64440 KB Output is correct
52 Correct 1735 ms 191492 KB Output is correct
53 Correct 1678 ms 185568 KB Output is correct
54 Correct 1136 ms 207884 KB Output is correct
55 Correct 1663 ms 194236 KB Output is correct
56 Correct 1744 ms 185008 KB Output is correct
57 Correct 1622 ms 184796 KB Output is correct
58 Correct 1133 ms 207712 KB Output is correct
59 Correct 1648 ms 191264 KB Output is correct
60 Correct 1840 ms 185396 KB Output is correct
61 Correct 1728 ms 186084 KB Output is correct
62 Correct 1276 ms 184160 KB Output is correct
63 Correct 1408 ms 186712 KB Output is correct
64 Correct 2936 ms 242304 KB Output is correct
65 Correct 155 ms 19908 KB Output is correct
66 Correct 2827 ms 247072 KB Output is correct
67 Correct 1774 ms 263060 KB Output is correct
68 Correct 2677 ms 253144 KB Output is correct
69 Correct 2528 ms 253504 KB Output is correct
70 Correct 2938 ms 247584 KB Output is correct
71 Correct 2784 ms 248764 KB Output is correct
72 Correct 1723 ms 270700 KB Output is correct
73 Correct 2570 ms 256828 KB Output is correct
74 Correct 2918 ms 250312 KB Output is correct
75 Correct 2897 ms 248092 KB Output is correct
76 Correct 1522 ms 243328 KB Output is correct
77 Correct 1481 ms 240696 KB Output is correct
78 Correct 1685 ms 245896 KB Output is correct
79 Correct 1849 ms 248464 KB Output is correct
80 Correct 1805 ms 243108 KB Output is correct
81 Correct 322 ms 68128 KB Output is correct
82 Correct 302 ms 68160 KB Output is correct
83 Correct 419 ms 67136 KB Output is correct
84 Correct 358 ms 66756 KB Output is correct
85 Correct 362 ms 66492 KB Output is correct
86 Correct 382 ms 67008 KB Output is correct
87 Correct 386 ms 66364 KB Output is correct
88 Correct 371 ms 68512 KB Output is correct
89 Correct 404 ms 67228 KB Output is correct
90 Correct 127 ms 34796 KB Output is correct
91 Correct 293 ms 68292 KB Output is correct
92 Correct 381 ms 66812 KB Output is correct
93 Correct 406 ms 67132 KB Output is correct
94 Correct 447 ms 67392 KB Output is correct
95 Correct 419 ms 66588 KB Output is correct
96 Correct 211 ms 31284 KB Output is correct
97 Correct 2486 ms 323716 KB Output is correct
98 Correct 171 ms 17212 KB Output is correct
99 Correct 4045 ms 302288 KB Output is correct
100 Correct 2384 ms 336300 KB Output is correct
101 Correct 3659 ms 326548 KB Output is correct
102 Correct 4162 ms 316272 KB Output is correct
103 Correct 2486 ms 319752 KB Output is correct
104 Correct 2523 ms 318436 KB Output is correct
105 Correct 2108 ms 317980 KB Output is correct
106 Correct 2166 ms 318956 KB Output is correct
107 Correct 2585 ms 318448 KB Output is correct
108 Correct 2500 ms 312256 KB Output is correct
109 Correct 2897 ms 322088 KB Output is correct
110 Correct 2829 ms 324992 KB Output is correct
111 Correct 2764 ms 329500 KB Output is correct
112 Correct 3084 ms 321604 KB Output is correct
113 Correct 711 ms 183972 KB Output is correct
114 Correct 2424 ms 340176 KB Output is correct
115 Correct 3270 ms 328472 KB Output is correct
116 Correct 3492 ms 324152 KB Output is correct
117 Correct 3567 ms 323568 KB Output is correct
118 Correct 3194 ms 321976 KB Output is correct
119 Correct 1516 ms 141544 KB Output is correct
120 Correct 1341 ms 296572 KB Output is correct
121 Correct 1611 ms 308536 KB Output is correct
122 Correct 1583 ms 307760 KB Output is correct
123 Correct 1830 ms 314004 KB Output is correct
124 Correct 1976 ms 317336 KB Output is correct
125 Correct 1927 ms 314904 KB Output is correct
126 Correct 2000 ms 316620 KB Output is correct