QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243328#7513. Palindromic BeadsmaspyAC ✓1168ms90728kbC++2031.9kb2023-11-08 03:23:572024-03-27 16:49:29

Judging History

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

  • [2024-03-27 16:49:29]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:1168ms
  • 内存:90728kb
  • [2024-03-27 16:34:54]
  • hack成功,自动添加数据
  • (/hack/584)
  • [2024-03-27 16:31:51]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:1163ms
  • 内存:90548kb
  • [2024-03-27 16:18:45]
  • hack成功,自动添加数据
  • (/hack/583)
  • [2023-11-08 03:23:58]
  • 评测
  • 测评结果:100
  • 用时:1076ms
  • 内存:90652kb
  • [2023-11-08 03:23:57]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sm = 0;
  for (auto &&a: A) sm += a;
  return sm;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    if (pil == pir) break;
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while (c >= '0') { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

#line 2 "library/ds/hashmap.hpp"

// u64 -> Val
template <typename Val, int LOG = 20, bool KEEP_IDS = false>
struct HashMap {
  using P = pair<u64, Val>;
  static constexpr int N = (1 << LOG);
  P* dat;
  vc<int> IDS;
  bitset<N> used;
  const int shift;
  const u64 r = 11995408973635179863ULL;
  HashMap() : dat(new P[N]), shift(64 - LOG) {}
  int hash(ll x) {
    static const u64 FIXED_RANDOM
        = std::chrono::steady_clock::now().time_since_epoch().count();
    return (u64(x + FIXED_RANDOM) * r) >> shift;
  }

  int index(const u64& key) {
    int i = 0;
    for (i = hash(key); used[i] && dat[i].fi != key; (i += 1) &= (N - 1)) {}
    return i;
  }

  Val& operator[](const u64& key) {
    int i = index(key);
    if (!used[i]) {
      used[i] = 1, dat[i] = {key, Val{}};
      if constexpr (KEEP_IDS) IDS.eb(i);
    }
    return dat[i].se;
  }

  Val get(const u64& key, Val default_value) {
    int i = index(key);
    if (!used[i]) return default_value;
    return dat[i].se;
  }

  bool count(const u64& key) {
    int i = index(key);
    return used[i] && dat[i].fi == key;
  }

  void reset() {
    static_assert(KEEP_IDS);
    for (auto&& i: IDS) used[i] = 0;
    IDS.clear();
  }

  // f(key, val)
  template <typename F>
  void enumerate_all(F f) {
    static_assert(KEEP_IDS);
    for (auto&& i: IDS) f(dat[i].fi, dat[i].se);
  }
};
#line 2 "library/ds/to_small_key.hpp"

// [30,10,20,30] -> [0,1,2,0] etc.
template <int LOG = 20, bool USE_RESET = false>
struct To_Small_Key {
  int kind = 0;
  HashMap<int, LOG, true> MP;

  int set_key(u64 x) {
    int idx = MP.index(x);
    if (!MP.used[idx]) {
      MP.used[idx] = 1;
      MP.dat[idx] = {u64(x), kind++};
    }
    return MP.dat[idx].se;
  }

  int query(u64 x) { return MP.get(x, -1); }

  void reset() {
    static_assert(USE_RESET);
    MP.reset();
  }
};
#line 5 "main.cpp"

#line 2 "library/alg/monoid/max.hpp"

template <typename E>
struct Monoid_Max {
  using X = E;
  using value_type = X;
  static constexpr X op(const X &x, const X &y) noexcept { return max(x, y); }
  static constexpr X unit() { return -infty<E>; }
  static constexpr bool commute = true;
};
#line 1 "library/ds/segtree/segtree_2d.hpp"
// 点の重複 OK
template <typename Monoid, typename XY, bool SMALL_X = false>
struct SegTree_2D {
  using MX = Monoid;
  using S = typename MX::value_type;
  static_assert(MX::commute);
  int N;
  // X to idx
  vc<XY> keyX;
  int minX;
  // top node の点列
  vc<XY> all_Y;
  vc<int> pos;
  // segtree data
  int NX, log, size;
  vc<int> indptr;
  vc<S> dat;
  // fractional cascading
  vc<int> to_left;

  SegTree_2D(vc<XY>& X, vc<XY>& Y)
      : SegTree_2D(len(X), [&](int i) -> tuple<XY, XY, S> {
          return {X[i], Y[i], MX::unit()};
        }) {}

  SegTree_2D(vc<XY>& X, vc<XY>& Y, vc<S>& vals)
      : SegTree_2D(len(X), [&](int i) -> tuple<XY, XY, S> {
          return {X[i], Y[i], vals[i]};
        }) {}

  // f(i) = (x,y,val)
  template <typename F>
  SegTree_2D(int N, F f) {
    vc<XY> X(N), Y(N);
    vc<S> wt(N);
    FOR(i, N) {
      auto [a, b, c] = f(i);
      X[i] = a, Y[i] = b, wt[i] = c;
    }
    if (!SMALL_X) {
      keyX = X;
      UNIQUE(keyX);
      NX = len(keyX);
    } else {
      minX = (X.empty() ? 0 : MIN(X));
      NX = (X.empty() ? 1 : MAX(X) - minX + 1);
    }

    log = 0;
    while ((1 << log) < NX) ++log;
    size = (1 << log);

    vc<int> IX(N);
    FOR(i, N) IX[i] = xtoi(X[i]);
    indptr.assign(2 * size, 0);
    for (auto i: IX) {
      i += size;
      while (i) indptr[i]++, i /= 2;
    }
    indptr = cumsum<int>(indptr);
    dat.assign(2 * indptr.back(), MX::unit());
    to_left.assign(indptr[size], 0);

    vc<int> ptr = indptr;
    vc<int> I = argsort(Y);
    pos.resize(N);
    FOR(i, N) pos[I[i]] = i;
    for (auto raw_idx: I) {
      int i = IX[raw_idx] + size;
      int j = -1;
      while (i) {
        int p = ptr[i];
        ptr[i]++;
        dat[indptr[i + 1] + p] = wt[raw_idx];
        if (j != -1) { to_left[p] = (j % 2 == 0); }
        j = i, i /= 2;
      }
    }
    to_left = cumsum<int>(to_left);

    FOR(i, 2 * size) {
      int off = 2 * indptr[i], n = indptr[i + 1] - indptr[i];
      FOR_R(j, 1, n) {
        dat[off + j] = MX::op(dat[off + 2 * j + 0], dat[off + 2 * j + 1]);
      }
    }
    all_Y = Y;
    sort(all(all_Y));
  }

  // 最初に与えた点群の index
  void multiply(int raw_idx, S val) {
    int i = 1, p = pos[raw_idx];
    while (1) {
      multiply_i(i, p - indptr[i], val);
      if (i >= size) break;
      int lc = to_left[p] - to_left[indptr[i]];
      int rc = (p - indptr[i]) - lc;
      if (to_left[p + 1] - to_left[p]) {
        p = indptr[2 * i + 0] + lc;
        i = 2 * i + 0;
      } else {
        p = indptr[2 * i + 1] + rc;
        i = 2 * i + 1;
      }
    }
  }

  // 最初に与えた点群の index
  void set(int raw_idx, S val) {
    int i = 1, p = pos[raw_idx];
    while (1) {
      set_i(i, p - indptr[i], val);
      if (i >= size) break;
      int lc = to_left[p] - to_left[indptr[i]];
      int rc = (p - indptr[i]) - lc;
      if (to_left[p + 1] - to_left[p]) {
        p = indptr[2 * i + 0] + lc;
        i = 2 * i + 0;
      } else {
        p = indptr[2 * i + 1] + rc;
        i = 2 * i + 1;
      }
    }
  }

  S prod(XY lx, XY rx, XY ly, XY ry) {
    int L = xtoi(lx), R = xtoi(rx);
    S res = MX::unit();
    auto dfs = [&](auto& dfs, int i, int l, int r, int a, int b) -> void {
      if (a == b || R <= l || r <= L) return;
      if (L <= l && r <= R) {
        res = MX::op(res, prod_i(i, a, b));
        return;
      }
      int la = to_left[indptr[i] + a] - to_left[indptr[i]];
      int ra = a - la;
      int lb = to_left[indptr[i] + b] - to_left[indptr[i]];
      int rb = b - lb;
      int m = (l + r) / 2;
      dfs(dfs, 2 * i + 0, l, m, la, lb);
      dfs(dfs, 2 * i + 1, m, r, ra, rb);
    };
    dfs(dfs, 1, 0, size, LB(all_Y, ly), LB(all_Y, ry));
    return res;
  }

  // 矩形内の全点を数える, NlogN
  int count(XY lx, XY rx, XY ly, XY ry) {
    int L = xtoi(lx), R = xtoi(rx);
    int res = 0;
    auto dfs = [&](auto& dfs, int i, int l, int r, int a, int b) -> void {
      if (a == b || R <= l || r <= L) return;
      if (L <= l && r <= R) {
        res += b - a;
        return;
      }
      int la = to_left[indptr[i] + a] - to_left[indptr[i]];
      int ra = a - la;
      int lb = to_left[indptr[i] + b] - to_left[indptr[i]];
      int rb = b - lb;
      int m = (l + r) / 2;
      dfs(dfs, 2 * i + 0, l, m, la, lb);
      dfs(dfs, 2 * i + 1, m, r, ra, rb);
    };
    dfs(dfs, 1, 0, size, LB(all_Y, ly), LB(all_Y, ry));
    return res;
  }

private:
  inline int xtoi(XY x) {
    if constexpr (SMALL_X) return clamp<XY>(x - minX, 0, NX);
    return LB(keyX, x);
  }

  S prod_i(int i, int a, int b) {
    int LID = indptr[i], n = indptr[i + 1] - indptr[i];
    int off = 2 * LID;
    int L = n + a, R = n + b;
    S val = MX::unit();
    while (L < R) {
      if (L & 1) val = MX::op(val, dat[off + (L++)]);
      if (R & 1) val = MX::op(dat[off + (--R)], val);
      L >>= 1, R >>= 1;
    }
    return val;
  }
  void multiply_i(int i, int j, S val) {
    int LID = indptr[i], n = indptr[i + 1] - indptr[i];
    int off = 2 * LID;
    j += n;
    while (j) {
      dat[off + j] = MX::op(dat[off + j], val);
      j >>= 1;
    }
  }
  void set_i(int i, int j, S val) {
    int LID = indptr[i], n = indptr[i + 1] - indptr[i];
    int off = 2 * LID;
    j += n;
    dat[off + j] = val;
    while (j > 1) {
      j /= 2;
      dat[off + j] = MX::op(dat[off + 2 * j + 0], dat[off + 2 * j + 1]);
    }
  }
};
#line 8 "main.cpp"

#line 2 "library/graph/tree.hpp"

#line 2 "library/graph/base.hpp"

template <typename T>
struct Edge {
  int frm, to;
  T cost;
  int id;
};

template <typename T = int, bool directed = false>
struct Graph {
  static constexpr bool is_directed = directed;
  int N, M;
  using cost_type = T;
  using edge_type = Edge<T>;
  vector<edge_type> edges;
  vector<int> indptr;
  vector<edge_type> csr_edges;
  vc<int> vc_deg, vc_indeg, vc_outdeg;
  bool prepared;

  class OutgoingEdges {
  public:
    OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}

    const edge_type* begin() const {
      if (l == r) { return 0; }
      return &G->csr_edges[l];
    }

    const edge_type* end() const {
      if (l == r) { return 0; }
      return &G->csr_edges[r];
    }

  private:
    const Graph* G;
    int l, r;
  };

  bool is_prepared() { return prepared; }

  Graph() : N(0), M(0), prepared(0) {}
  Graph(int N) : N(N), M(0), prepared(0) {}

  void build(int n) {
    N = n, M = 0;
    prepared = 0;
    edges.clear();
    indptr.clear();
    csr_edges.clear();
    vc_deg.clear();
    vc_indeg.clear();
    vc_outdeg.clear();
  }

  void add(int frm, int to, T cost = 1, int i = -1) {
    assert(!prepared);
    assert(0 <= frm && 0 <= to && to < N);
    if (i == -1) i = M;
    auto e = edge_type({frm, to, cost, i});
    edges.eb(e);
    ++M;
  }

#ifdef FASTIO
  // wt, off
  void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }

  void read_graph(int M, bool wt = false, int off = 1) {
    for (int m = 0; m < M; ++m) {
      INT(a, b);
      a -= off, b -= off;
      if (!wt) {
        add(a, b);
      } else {
        T c;
        read(c);
        add(a, b, c);
      }
    }
    build();
  }
#endif

  void build() {
    assert(!prepared);
    prepared = true;
    indptr.assign(N + 1, 0);
    for (auto&& e: edges) {
      indptr[e.frm + 1]++;
      if (!directed) indptr[e.to + 1]++;
    }
    for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
    auto counter = indptr;
    csr_edges.resize(indptr.back() + 1);
    for (auto&& e: edges) {
      csr_edges[counter[e.frm]++] = e;
      if (!directed)
        csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
    }
  }

  OutgoingEdges operator[](int v) const {
    assert(prepared);
    return {this, indptr[v], indptr[v + 1]};
  }

  vc<int> deg_array() {
    if (vc_deg.empty()) calc_deg();
    return vc_deg;
  }

  pair<vc<int>, vc<int>> deg_array_inout() {
    if (vc_indeg.empty()) calc_deg_inout();
    return {vc_indeg, vc_outdeg};
  }

  int deg(int v) {
    if (vc_deg.empty()) calc_deg();
    return vc_deg[v];
  }

  int in_deg(int v) {
    if (vc_indeg.empty()) calc_deg_inout();
    return vc_indeg[v];
  }

  int out_deg(int v) {
    if (vc_outdeg.empty()) calc_deg_inout();
    return vc_outdeg[v];
  }

#ifdef FASTIO
  void debug() {
    print("Graph");
    if (!prepared) {
      print("frm to cost id");
      for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
    } else {
      print("indptr", indptr);
      print("frm to cost id");
      FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
    }
  }
#endif

  vc<int> new_idx;
  vc<bool> used_e;

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    if (len(used_e) != M) used_e.assign(M, 0);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> history;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          history.eb(e.id);
          used_e[e.id] = 1;
          int eid = (keep_eid ? e.id : -1);
          G.add(new_idx[a], new_idx[b], e.cost, eid);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: history) used_e[eid] = 0;
    G.build();
    return G;
  }

private:
  void calc_deg() {
    assert(vc_deg.empty());
    vc_deg.resize(N);
    for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
  }

  void calc_deg_inout() {
    assert(vc_indeg.empty());
    vc_indeg.resize(N);
    vc_outdeg.resize(N);
    for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
  }
};
#line 4 "library/graph/tree.hpp"

// HLD euler tour をとっていろいろ。
template <typename GT>
struct Tree {
  using Graph_type = GT;
  GT &G;
  using WT = typename GT::cost_type;
  int N;
  vector<int> LID, RID, head, V, parent, VtoE;
  vc<int> depth;
  vc<WT> depth_weighted;

  Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }

  void build(int r = 0, bool hld = 1) {
    if (r == -1) return; // build を遅延したいとき
    N = G.N;
    LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
    V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
    depth.assign(N, -1), depth_weighted.assign(N, 0);
    assert(G.is_prepared());
    int t1 = 0;
    dfs_sz(r, -1, hld);
    dfs_hld(r, t1);
  }

  void dfs_sz(int v, int p, bool hld) {
    auto &sz = RID;
    parent[v] = p;
    depth[v] = (p == -1 ? 0 : depth[p] + 1);
    sz[v] = 1;
    int l = G.indptr[v], r = G.indptr[v + 1];
    auto &csr = G.csr_edges;
    // 使う辺があれば先頭にする
    for (int i = r - 2; i >= l; --i) {
      if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
    }
    int hld_sz = 0;
    for (int i = l; i < r; ++i) {
      auto e = csr[i];
      if (depth[e.to] != -1) continue;
      depth_weighted[e.to] = depth_weighted[v] + e.cost;
      VtoE[e.to] = e.id;
      dfs_sz(e.to, v, hld);
      sz[v] += sz[e.to];
      if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
    }
  }

  void dfs_hld(int v, int &times) {
    LID[v] = times++;
    RID[v] += LID[v];
    V[LID[v]] = v;
    bool heavy = true;
    for (auto &&e: G[v]) {
      if (depth[e.to] <= depth[v]) continue;
      head[e.to] = (heavy ? head[v] : e.to);
      heavy = false;
      dfs_hld(e.to, times);
    }
  }

  vc<int> heavy_path_at(int v) {
    vc<int> P = {v};
    while (1) {
      int a = P.back();
      for (auto &&e: G[a]) {
        if (e.to != parent[a] && head[e.to] == v) {
          P.eb(e.to);
          break;
        }
      }
      if (P.back() == a) break;
    }
    return P;
  }

  int heavy_child(int v) {
    int k = LID[v] + 1;
    if (k == N) return -1;
    int w = V[k];
    return (parent[w] == v ? w : -1);
  }

  int e_to_v(int eid) {
    auto e = G.edges[eid];
    return (parent[e.frm] == e.to ? e.frm : e.to);
  }
  int v_to_e(int v) { return VtoE[v]; }

  int ELID(int v) { return 2 * LID[v] - depth[v]; }
  int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }

  // 目標地点へ進む個数が k
  int LA(int v, int k) {
    assert(k <= depth[v]);
    while (1) {
      int u = head[v];
      if (LID[v] - k >= LID[u]) return V[LID[v] - k];
      k -= LID[v] - LID[u] + 1;
      v = parent[u];
    }
  }
  int la(int u, int v) { return LA(u, v); }

  int LCA(int u, int v) {
    for (;; v = parent[head[v]]) {
      if (LID[u] > LID[v]) swap(u, v);
      if (head[u] == head[v]) return u;
    }
  }
  // root を根とした場合の lca
  int LCA_root(int u, int v, int root) {
    return LCA(u, v) ^ LCA(u, root) ^ LCA(v, root);
  }
  int lca(int u, int v) { return LCA(u, v); }
  int lca_root(int u, int v, int root) { return LCA_root(u, v, root); }

  int subtree_size(int v, int root = -1) {
    if (root == -1) return RID[v] - LID[v];
    if (v == root) return N;
    int x = jump(v, root, 1);
    if (in_subtree(v, x)) return RID[v] - LID[v];
    return N - RID[x] + LID[x];
  }

  int dist(int a, int b) {
    int c = LCA(a, b);
    return depth[a] + depth[b] - 2 * depth[c];
  }

  WT dist_weighted(int a, int b) {
    int c = LCA(a, b);
    return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
  }

  // a is in b
  bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }

  int jump(int a, int b, ll k) {
    if (k == 1) {
      if (a == b) return -1;
      return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
    }
    int c = LCA(a, b);
    int d_ac = depth[a] - depth[c];
    int d_bc = depth[b] - depth[c];
    if (k > d_ac + d_bc) return -1;
    if (k <= d_ac) return LA(a, k);
    return LA(b, d_ac + d_bc - k);
  }

  vc<int> collect_child(int v) {
    vc<int> res;
    for (auto &&e: G[v])
      if (e.to != parent[v]) res.eb(e.to);
    return res;
  }

  vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
    // [始点, 終点] の"閉"区間列。
    vc<pair<int, int>> up, down;
    while (1) {
      if (head[u] == head[v]) break;
      if (LID[u] < LID[v]) {
        down.eb(LID[head[v]], LID[v]);
        v = parent[head[v]];
      } else {
        up.eb(LID[u], LID[head[u]]);
        u = parent[head[u]];
      }
    }
    if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
    elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
    reverse(all(down));
    up.insert(up.end(), all(down));
    return up;
  }

  vc<int> restore_path(int u, int v) {
    vc<int> P;
    for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
      if (a <= b) {
        FOR(i, a, b + 1) P.eb(V[i]);
      } else {
        FOR_R(i, b, a + 1) P.eb(V[i]);
      }
    }
    return P;
  }
};
#line 10 "main.cpp"

void solve() {
  LL(N);
  VEC(int, color, N);
  {
    To_Small_Key<20, 0> X;
    FOR(i, N) color[i] = X.set_key(color[i]);
  }

  // print(color);

  int K = MAX(color) + 1;
  vc<pi> pos(K, {-1, -1});
  FOR(i, N) {
    int c = color[i];
    if (pos[c].fi == -1)
      pos[c] = {i, i};
    else
      pos[c].se = i;
  }

  Graph<int, 0> G(N);
  G.read_tree();
  Tree<decltype(G)> tree(G);

  vc<int> sz(K);
  FOR(i, K) {
    auto [a, b] = pos[i];
    if (a == b) continue;
    sz[i] = tree.dist(a, b);
  }

  SegTree_2D<Monoid_Max<int>, int, true> seg(
      K, [&](int k) -> tuple<int, int, int> {
        auto [a, b] = pos[k];
        int x = tree.LID[a], y = tree.LID[b];
        return {x, y, 0};
      });

  vc<int> dp1(K, -infty<int>);
  vc<int> dp2(K, -infty<int>);

  auto I = argsort(sz);
  reverse(all(I));
  for (auto& k: I) {
    auto [a, b] = pos[k];
    if (a != b) {
      int best = 0;
      // longer path
      int c = tree.lca(a, b);
      if (a != c) swap(a, b);
      if (a == c) {
        int d = tree.jump(a, b, 1);
        // subtree of b, outtree of d
        int Lb = tree.LID[b], Rb = tree.RID[b];
        int Ld = tree.LID[d], Rd = tree.RID[d];
        chmax(best, seg.prod(Lb, Rb, 0, Ld));
        chmax(best, seg.prod(Lb, Rb, Rd, N));
        chmax(best, seg.prod(0, Ld, Lb, Rb));
        chmax(best, seg.prod(Rd, N, Lb, Rb));
      } else {
        int La = tree.LID[a], Ra = tree.RID[a];
        int Lb = tree.LID[b], Rb = tree.RID[b];
        chmax(best, seg.prod(La, Ra, Lb, Rb));
        chmax(best, seg.prod(Lb, Rb, La, Ra));
      }
      chmax(dp2[k], best + 2);
    }

    for (auto& v: {a, b}) {
      int best = 0;
      // v を center
      for (auto& e: G[v]) {
        if (e.to == tree.parent[v]) continue;
        int L = tree.LID[e.to], R = tree.RID[e.to];
        chmax(best, seg.prod(L, R, 0, L));
        chmax(best, seg.prod(L, R, R, N));
        chmax(best, seg.prod(0, L, L, R));
        chmax(best, seg.prod(R, N, L, R));
      }
      chmax(dp1[k], best + 1);
    }
    seg.multiply(k, dp2[k]);
    // print(k, a, b, dp1[k], dp2[k]);
  }

  int ANS = 0;
  FOR(k, K) chmax(ANS, dp1[k]);
  FOR(k, K) chmax(ANS, dp2[k]);
  print(ANS);
}

signed main() {
  solve();
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 20476kb

input:

4
1 1 2 2
1 2
2 3
2 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

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

output:

4

result:

ok single line: '4'

Test #3:

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

input:

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

output:

2

result:

ok single line: '2'

Test #4:

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

input:

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

output:

1

result:

ok single line: '1'

Test #5:

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

input:

2000
845 1171 345 282 1181 625 754 289 681 493 423 840 1494 318 266 1267 967 379 135 14 39 191 60 972 116 1216 1205 19 194 185 1360 861 379 430 1262 1151 756 65 389 488 277 53 1283 1438 101 1465 195 714 737 980 80 298 961 1326 163 1163 1317 1152 992 35 334 802 1502 486 710 234 555 88 1278 146 46 696...

output:

5

result:

ok single line: '5'

Test #6:

score: 0
Accepted
time: 609ms
memory: 78640kb

input:

200000
48015 47923 20609 71806 43752 68214 95683 89449 25809 58110 19878 52931 7845 45206 86245 82945 62977 37876 12456 105915 10509 92943 66950 88545 26442 26545 42278 66977 3970 9631 21524 43638 7979 58240 25719 56260 276 89721 9553 16550 52161 30307 82748 108443 36676 48581 59069 57412 62453 7965...

output:

5

result:

ok single line: '5'

Test #7:

score: 0
Accepted
time: 608ms
memory: 77908kb

input:

200000
13011 51198 65374 107045 66506 14385 35784 94265 71449 41817 24646 60714 53382 68358 9354 840 3139 71282 72215 69550 2121 41498 13675 76444 67690 40513 56439 12832 51976 35333 47208 59602 98993 9383 77866 10464 41517 89125 58804 91741 66160 74208 70991 63865 84870 14282 2441 78046 73372 36311...

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 601ms
memory: 78560kb

input:

200000
38715 33241 65919 39407 27500 36200 2259 42301 79147 57505 20 81399 69499 23658 14534 86934 14352 69558 59763 43318 35360 3281 38188 40058 40571 103709 75625 8434 53802 87159 98628 69421 53711 47986 18350 6079 37362 39377 71936 89573 25983 66882 48999 58918 66432 17453 82515 9588 95375 87287 ...

output:

45

result:

ok single line: '45'

Test #9:

score: 0
Accepted
time: 707ms
memory: 79920kb

input:

200000
36449 57574 3145 38591 832 17710 66613 78947 27635 83275 89878 48329 94614 584 96832 9321 72046 44873 5396 61452 63224 63740 26579 13706 108490 19092 89439 85884 12016 5105 48638 74004 41569 35006 22276 45609 25350 49906 35479 15875 68938 77699 48828 21628 11242 77040 70838 45771 27704 64865 ...

output:

135

result:

ok single line: '135'

Test #10:

score: 0
Accepted
time: 1058ms
memory: 84800kb

input:

200000
13528 65006 30352 8565 36687 6748 5507 44320 7189 17847 46996 82728 102722 4727 36914 74228 21460 87970 11733 47170 67282 104558 66436 64504 57055 88619 42995 25569 101298 90984 76491 51994 62257 103424 8221 69668 99170 6808 29043 73058 5277 26614 23654 25152 64939 38418 78518 5330 37531 4305...

output:

425

result:

ok single line: '425'

Test #11:

score: 0
Accepted
time: 1168ms
memory: 90728kb

input:

200000
92279 5566 62695 50240 45387 51097 57743 94873 53220 29260 72584 38043 86335 33441 12946 30267 12932 18258 4560 8896 64393 39608 53183 34285 36518 18501 51940 8658 101018 48522 21336 104735 25785 73132 33489 81905 94563 18128 87872 24765 54563 57218 61869 50458 75919 63764 48155 4489 35212 44...

output:

839

result:

ok single line: '839'

Test #12:

score: 0
Accepted
time: 630ms
memory: 80892kb

input:

200000
96438 84772 88103 81186 60908 116093 94738 28602 35022 91108 60687 75572 100094 50553 58445 117024 96154 53539 23185 112280 90369 32413 95244 11077 91008 109781 6404 2285 3544 111712 49414 10399 113626 81435 11321 52557 17023 113260 14225 66464 61352 98403 36521 110038 57172 42868 68512 69031...

output:

31

result:

ok single line: '31'

Test #13:

score: 0
Accepted
time: 620ms
memory: 81180kb

input:

200000
50750 86282 92049 114579 8296 28675 45880 47381 71400 43379 111535 32316 37104 35968 100241 6914 81284 48969 62890 63486 107557 80178 76322 31515 24682 85646 12681 106054 5167 50339 39004 16152 112081 10605 66750 51623 96332 77287 75452 50609 1549 1652 45229 73171 10015 66323 90164 97491 1007...

output:

8108

result:

ok single line: '8108'

Test #14:

score: 0
Accepted
time: 1035ms
memory: 85252kb

input:

200000
103710 58811 65880 57203 97861 52397 63433 39586 97768 103209 103882 94183 50235 39832 92390 90699 48046 43740 86592 19659 27107 39892 7594 27400 95581 16516 29641 51389 17391 97193 93724 70446 91047 67946 5821 96978 101553 35096 54450 104968 93366 64974 46399 81084 97703 64161 38168 55002 10...

output:

16254

result:

ok single line: '16254'

Test #15:

score: 0
Accepted
time: 697ms
memory: 84284kb

input:

200000
88202 74369 54948 48433 90064 106858 57479 24810 31634 66587 14453 9546 77108 81830 36583 76158 5411 103453 9138 44425 55569 108655 29336 6156 33 78407 12653 61049 89911 48056 85840 41409 60932 69039 50823 604 57680 30956 7683 35427 99677 86508 44657 42731 105490 13120 101415 3024 32965 10326...

output:

4

result:

ok single line: '4'

Test #16:

score: 0
Accepted
time: 607ms
memory: 80852kb

input:

200000
10797 110783 14050 78735 2502 18514 116854 6066 7024 88298 49894 5068 113306 111164 293 38365 84020 117567 109538 103830 69630 28231 107911 18477 95413 78305 59492 112114 12973 20189 93556 49731 50223 69605 54609 74804 42990 28998 22878 45999 93363 7282 71880 49057 46461 94559 53582 109357 25...

output:

6

result:

ok single line: '6'

Test #17:

score: 0
Accepted
time: 582ms
memory: 77868kb

input:

200000
48737 28745 46719 51708 55344 100505 22387 88659 52750 92399 63371 63773 69558 28543 3923 23010 101235 32115 106541 2327 42175 67610 109244 77794 49476 70063 4296 22615 9227 107435 58380 27995 78950 8976 80501 71538 73668 82538 68732 86931 19515 54326 85071 28871 46614 56610 53551 67531 47246...

output:

5

result:

ok single line: '5'

Test #18:

score: 0
Accepted
time: 549ms
memory: 77760kb

input:

200000
26426 62873 30891 26591 23480 10950 50429 4430 25803 27494 14124 45946 2115 72645 23096 45892 34188 62963 63230 4026 19204 52592 84051 81275 101029 63022 83786 69487 46792 97893 25402 11283 50048 59942 53521 52133 12216 16801 24535 31962 102839 71080 53210 8687 6049 56323 74430 81175 55370 64...

output:

5

result:

ok single line: '5'

Test #19:

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

input:

200000
64192 51123 57775 25958 30138 51389 48055 24350 73959 42882 73159 20060 24764 56730 79344 32622 98700 1752 102538 20803 89788 11428 16935 19307 25767 38250 64733 76253 69835 40964 8146 21818 64392 104263 78420 57145 46240 44745 28359 28598 38527 60156 9818 30837 20404 99634 75031 71165 60654 ...

output:

4

result:

ok single line: '4'

Test #20:

score: 0
Accepted
time: 403ms
memory: 78416kb

input:

200000
30875 49873 48854 101512 66585 67679 13806 38786 40598 83034 6738 61701 26783 17734 29228 34850 55071 61098 88072 20496 60333 53325 32602 102521 99956 17288 105589 74068 66276 21670 78040 75943 2292 87380 76885 55439 897 82814 36764 80920 53230 16085 36883 61234 106576 28271 6915 11089 21463 ...

output:

3

result:

ok single line: '3'

Test #21:

score: 0
Accepted
time: 480ms
memory: 78740kb

input:

200000
75618 85661 92814 29954 24466 50323 95886 9384 11050 57981 86917 38495 12021 82933 13692 5285 32566 29306 59046 47309 90373 70494 81527 6001 62574 94496 70347 31615 21329 91026 46255 26717 108227 71208 49245 29004 99849 61951 46547 72596 51712 22511 4844 20109 60399 24412 104182 14880 40185 2...

output:

3

result:

ok single line: '3'

Extra Test:

score: 0
Extra Test Passed