QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369512#3549. 262144 Revisitedhos_lyric69.565217 1373ms82288kbC++1412.2kb2024-03-28 13:18:482024-03-28 13:18:48

Judging History

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

  • [2024-03-28 13:18:48]
  • 评测
  • 测评结果:69.565217
  • 用时:1373ms
  • 内存:82288kb
  • [2024-03-28 13:18:48]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// root: max (tie-break: left)
struct MaxCartesianTree {
  int n, rt;
  vector<int> par, lef, rig;
  template <class T> void build(int n_, T *as) {
    assert(n_ >= 1);
    n = n_;
    rt = 0;
    par.assign(n, -1);
    lef.assign(n, -1);
    rig.assign(n, -1);
    int top = 0;
    vector<int> stack(n, 0);
    for (int u = 1; u < n; ++u) {
      if (as[stack[top]] < as[u]) {  // <
        for (; top >= 1 && as[stack[top - 1]] < as[u]; --top) {}  // <
        if (top == 0) {
          rt = par[lef[u] = stack[top]] = u;
        } else {
          par[lef[u] = stack[top]] = u;
          rig[par[u] = stack[top - 1]] = u;
        }
        stack[top] = u;
      } else {
        rig[par[u] = stack[top]] = u;
        stack[++top] = u;
      }
    }
  }
  template <class T> void build(const T &as) {
    build(as.size(), as.data());
  }
};

////////////////////////////////////////////////////////////////////////////////


// T: monoid representing information of an interval.
//   T()  should return the identity.
//   T(S s)  should represent a single element of the array.
//   T::push(T &l, T &r)  should push the lazy update.
//   T::pull(const T &l, const T &r)  should pull two intervals.
template <class T> struct SegmentTreeRec {
  int logN, n;
  vector<T> ts;
  SegmentTreeRec() : logN(0), n(0) {}
  explicit SegmentTreeRec(int n_) {
    for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
    ts.resize(n << 1);
  }
  template <class S> explicit SegmentTreeRec(const vector<S> &ss) {
    const int n_ = ss.size();
    for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
    ts.resize(n << 1);
    for (int i = 0; i < n_; ++i) at(i) = T(ss[i]);
    build();
  }
  T &at(int i) {
    return ts[n + i];
  }
  void build() {
    for (int u = n; --u; ) pull(u);
  }

  inline void push(int u) {
    ts[u].push(ts[u << 1], ts[u << 1 | 1]);
  }
  inline void pull(int u) {
    ts[u].pull(ts[u << 1], ts[u << 1 | 1]);
  }

  // Applies T::f(args...) to [a, b).
  //   f should return true on success. It must succeed for a single element.
  template <class F, class... Args>
  void ch(int a, int b, F f, Args &&... args) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return;
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) chRec(aa++, f, args...);
      if (bb & 1) chRec(--bb, f, args...);
    }
    for (int h = 1; h <= logN; ++h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) pull(aa);
      } else {
        if ((aa << h) != a) pull(aa);
        if ((bb << h) != b) pull(bb);
      }
    }
  }
  template <class F, class... Args>
  void chRec(int u, F f, Args &&... args) {
    const int u0 = u;
    for (; ; ) {
      if ((ts[u].*f)(args...)) {
        for (; u0 < u && (u & 1); pull(u >>= 1)) {}
        if (u0 == u) return;
        ++u;
      } else {
        push(u);
        u <<= 1;
      }
    }
  }

  // Calculates the product for [a, b).
  T get(int a, int b) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return T();
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    T prodL, prodR, t;
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) { t.pull(prodL, ts[aa++]); prodL = t; }
      if (bb & 1) { t.pull(ts[--bb], prodR); prodR = t; }
    }
    t.pull(prodL, prodR);
    return t;
  }

  // Calculates T::f(args...) of a monoid type for [a, b).
  //   op(-, -)  should calculate the product.
  //   e()  should return the identity.
  template <class Op, class E, class F, class... Args>
#if __cplusplus >= 201402L
  auto
#else
  decltype((std::declval<T>().*F())())
#endif
  get(int a, int b, Op op, E e, F f, Args &&... args) {
    assert(0 <= a); assert(a <= b); assert(b <= n);
    if (a == b) return e();
    a += n; b += n;
    for (int h = logN; h; --h) {
      const int aa = a >> h, bb = b >> h;
      if (aa == bb) {
        if ((aa << h) != a || (bb << h) != b) push(aa);
      } else {
        if ((aa << h) != a) push(aa);
        if ((bb << h) != b) push(bb);
      }
    }
    auto prodL = e(), prodR = e();
    for (int aa = a, bb = b; aa < bb; aa >>= 1, bb >>= 1) {
      if (aa & 1) prodL = op(prodL, (ts[aa++].*f)(args...));
      if (bb & 1) prodR = op((ts[--bb].*f)(args...), prodR);
    }
    return op(prodL, prodR);
  }

  // Find min b s.t. T::f(args...) returns true,
  // when called for the partition of [a, b) from left to right.
  //   Returns n + 1 if there is no such b.
  template <class F, class... Args>
  int findRight(int a, F f, Args &&... args) {
    assert(0 <= a); assert(a <= n);
    if ((T().*f)(args...)) return a;
    if (a == n) return n + 1;
    a += n;
    for (int h = logN; h; --h) push(a >> h);
    for (; ; a >>= 1) if (a & 1) {
      if ((ts[a].*f)(args...)) {
        for (; a < n; ) {
          push(a);
          if (!(ts[a <<= 1].*f)(args...)) ++a;
        }
        return a - n + 1;
      }
      ++a;
      if (!(a & (a - 1))) return n + 1;
    }
  }

  // Find max a s.t. T::f(args...) returns true,
  // when called for the partition of [a, b) from right to left.
  //   Returns -1 if there is no such a.
  template <class F, class... Args>
  int findLeft(int b, F f, Args &&... args) {
    assert(0 <= b); assert(b <= n);
    if ((T().*f)(args...)) return b;
    if (b == 0) return -1;
    b += n;
    for (int h = logN; h; --h) push((b - 1) >> h);
    for (; ; b >>= 1) if ((b & 1) || b == 2) {
      if ((ts[b - 1].*f)(args...)) {
        for (; b <= n; ) {
          push(b - 1);
          if (!(ts[(b <<= 1) - 1].*f)(args...)) --b;
        }
        return b - n - 1;
      }
      --b;
      if (!(b & (b - 1))) return -1;
    }
  }
};

////////////////////////////////////////////////////////////////////////////////


int N;
vector<int> A;


/*
  greedy
  x consecutive min elements -> ceil(x/2) (min+1)'s
*/
namespace slow {
Int ans;
vector<int> pre, suf;
int rec(int l, int r) {
  int mid = l;
  for (int i = l; i < r; ++i) if (A[mid] < A[i]) mid = i;
  if (l < mid) {
    const int res = rec(l, mid);
    const int da = min(A[mid] - res, 31);
    for (int i = l; i < mid; ++i) {
      ++(--pre[i] >>= da);
      ++(--suf[i] >>= da);
    }
  }
  if (mid + 1 < r) {
    const int res = rec(mid + 1, r);
    const int da = min(A[mid] - res, 31);
    for (int i = mid + 1; i < r; ++i) {
      ++(--pre[i] >>= da);
      ++(--suf[i] >>= da);
    }
  }
  Int here = 0;
  for (int i = l; i <= mid; ++i) for (int j = mid; j < r; ++j) {
    const int b = suf[i] + 1 + pre[j];
    const int e = (b == 1) ? 0 : ((31 - __builtin_clz(b - 1)) + 1);
// cerr<<"["<<i<<", "<<j<<"]: "<<A[mid]<<" + "<<e<<endl;
    here += A[mid] + e;
  }
  ans += here;
  {
    const int db = ((l < mid) ? pre[mid - 1] : 0) + 1;
    for (int i = mid; i < r; ++i) pre[i] += db;
  }
  {
    const int db = ((mid + 1 < r) ? suf[mid + 1] : 0) + 1;
    for (int i = l; i <= mid; ++i) suf[i] += db;
  }
cerr<<"[rec] ["<<l<<", "<<r<<"): here = "<<here<<endl;
cerr<<"  pre = ";pv(pre.begin()+l,pre.begin()+r);
cerr<<"  suf = ";pv(suf.begin()+l,suf.begin()+r);
  return A[mid];
}

Int run() {
  ans = 0;
  pre.assign(N, 0);
  suf.assign(N, 0);
  rec(0, N);
  return ans;
}
}  // slow


namespace fast {
constexpr int INF = 1001001001;
struct Node {
  int mn, mx;
  int lz;
  Node() : mn(+INF), mx(-INF), lz(0) {}
  Node(int val) : mn(val), mx(val), lz(0) {}
  void push(Node &l, Node &r) {
    if (lz) {
      l.add(lz);
      r.add(lz);
      lz = 0;
    }
  }
  void pull(const Node &l, const Node &r) {
    mn = min(l.mn, r.mn);
    mx = max(l.mx, r.mx);
  }
  bool add(int val) {
    mn += val;
    mx += val;
    lz += val;
    return true;
  }
  // x -> ceil(x / 2^e)
  bool div(int e) {
    if (mn == mx) {
      chmin(e, 30);
      const int tar = (mn + (1 << e) - 1) >> e;
      add(tar - mn);
      return true;
    } else {
      return false;
    }
  }
};

Int ans;
MaxCartesianTree ct;

SegmentTreeRec<Node> segPre, segSuf;
int pre(int i) { return segPre.get(i, i + 1).mn; }
int suf(int i) { return segSuf.get(i, i + 1).mn; }

int rec(int l, int mid, int r) {
  if (l < mid) {
    const int res = rec(l, ct.lef[mid], mid);
    const int da = A[mid] - res;
    segPre.ch(l, mid, &Node::div, da);
    segSuf.ch(l, mid, &Node::div, da);
  }
  if (mid + 1 < r) {
    const int res = rec(mid + 1, ct.rig[mid], r);
    const int da = A[mid] - res;
    segPre.ch(mid + 1, r, &Node::div, da);
    segSuf.ch(mid + 1, r, &Node::div, da);
  }
  const int lim = suf(l) + 1 + pre(r - 1);
  Int here = 0;
  if (mid - l + 1 <= r - mid) {
    for (int e = 0; 1 << e < lim; ++e) {
      for (int i = l; i <= mid; ++i) {
        // mid <= j < r s.t. suf(i) + 1 + pre(j) > 2^e
        const int sufI = suf(i);
        int jL = mid - 1, jR = r;
        for (; jL + 1 < jR; ) {
          const int jMid = (jL + jR) / 2;
          ((sufI + 1 + pre(jMid) > 1 << e) ? jR : jL) = jMid;
        }
        here += (r - jR);
      }
    }
  } else {
    for (int e = 0; 1 << e < lim; ++e) {
      for (int j = mid; j < r; ++j) {
        // l <= i <= mid s.t. suf(i) + 1 + pre(j) > 2^e
        const int preJ = pre(j);
        int iL = l - 1, iR = mid + 1;
        for (; iL + 1 < iR; ) {
          const int iMid = (iL + iR) / 2;
          (((suf(iMid) + 1 + preJ) > 1 << e) ? iL : iR) = iMid;
        }
        here += (iL - l + 1);
      }
    }
  }
  here += (Int)(mid - l + 1) * (r - mid) * A[mid];
  ans += here;
  {
    const int db = ((l < mid) ? pre(mid - 1) : 0) + 1;
    segPre.ch(mid, r, &Node::add, db);
  }
  {
    const int db = ((mid + 1 < r) ? suf(mid + 1) : 0) + 1;
    segSuf.ch(l, mid + 1, &Node::add, db);
  }
// cerr<<"[rec] ["<<l<<", "<<r<<"): here = "<<here<<endl;
// cerr<<"  pre = ";for(int i=l;i<r;++i)cerr<<pre(i)<<" ";cerr<<endl;
// cerr<<"  suf = ";for(int i=l;i<r;++i)cerr<<suf(i)<<" ";cerr<<endl;
  return A[mid];
}

Int run() {
  ans = 0;
  ct.build(A);
  segPre = SegmentTreeRec<Node>(vector<int>(N, 0));
  segSuf = SegmentTreeRec<Node>(vector<int>(N, 0));
  rec(0, ct.rt, N);
  return ans;
}
}  // fast


int main() {
  for (; ~scanf("%d", &N); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    
    const Int ans = fast::run();
    printf("%lld\n", ans);
#ifdef LOCAL
const Int slw=slow::run();
cerr<<"slw = "<<slw<<endl;
assert(slw==ans);
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.34783
Accepted
time: 0ms
memory: 3804kb

input:

6
1 3 1 2 1 10

output:

115

result:

ok single line: '115'

Test #2:

score: 4.34783
Accepted
time: 1229ms
memory: 26740kb

input:

262144
1 1 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 8 8 8 8 8 8 8 8 8 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 14 14 14 14 14 14 14 14 14 14 14 14 14 15 16 16 16 16 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 19 20 20 20 20 20 20 ...

output:

666881324292484

result:

ok single line: '666881324292484'

Test #3:

score: 4.34783
Accepted
time: 526ms
memory: 63656kb

input:

262144
1 9 9 9 9 11 12 13 15 21 21 22 23 23 33 34 34 39 39 42 43 46 46 46 46 46 50 50 51 51 52 55 55 56 56 59 64 66 70 70 77 79 83 88 92 97 97 98 102 108 108 112 113 114 121 121 124 126 129 131 132 138 141 141 147 147 148 152 154 155 161 162 163 165 166 166 168 169 169 169 170 175 176 177 178 183 18...

output:

14050699806935958

result:

ok single line: '14050699806935958'

Test #4:

score: 4.34783
Accepted
time: 838ms
memory: 49024kb

input:

262144
99996 99995 99993 99993 99990 99990 99991 99990 99988 99989 99990 99989 99988 99988 99987 99989 99988 99982 99983 99983 99984 99984 99983 99981 99981 99981 99978 99978 99977 99976 99976 99977 99971 99968 99968 99968 99967 99965 99965 99965 99964 99967 99966 99965 99963 99961 99960 99960 99964...

output:

2433548647154743

result:

ok single line: '2433548647154743'

Test #5:

score: 4.34783
Accepted
time: 860ms
memory: 48816kb

input:

262144
199998 199997 199998 199997 199996 199997 199996 199996 199992 199992 199988 199988 199988 199990 199986 199986 199988 199988 199984 199984 199984 199985 199986 199987 199984 199984 199984 199979 199980 199980 199982 199977 199977 199976 199975 199976 199975 199976 199977 199972 199973 199973...

output:

5874338879559722

result:

ok single line: '5874338879559722'

Test #6:

score: 0
Time Limit Exceeded

input:

262144
499992 499989 499989 499988 499988 499988 499988 499989 499989 499990 499985 499985 499986 499986 499985 499984 499984 499985 499985 499985 499985 499986 499986 499985 499985 499984 499984 499984 499984 499985 499985 499986 499986 499986 499986 499985 499985 499988 499988 499989 499986 499986...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

262144
999991 999991 999990 999990 999991 999993 999991 999991 999991 999990 999990 999989 999989 999989 999989 999988 999988 999989 999987 999987 999987 999985 999984 999984 999986 999987 999987 999988 999988 999988 999989 999989 999989 999990 999988 999988 999989 999991 999989 999988 999985 999984...

output:


result:


Test #8:

score: 4.34783
Accepted
time: 861ms
memory: 48636kb

input:

262144
1000000 999996 999991 999987 999988 999987 999988 999988 999986 999985 999986 999986 999984 999982 999983 999985 999984 999982 999981 999981 999979 999978 999977 999975 999974 999975 999974 999973 999974 999971 999972 999972 999972 999973 999971 999970 999970 999965 999964 999956 999957 99995...

output:

33356297291315697

result:

ok single line: '33356297291315697'

Test #9:

score: 4.34783
Accepted
time: 860ms
memory: 48848kb

input:

262144
999997 999998 999996 999992 999992 999994 999989 999986 999985 999985 999985 999987 999984 999982 999982 999982 999984 999984 999981 999979 999980 999976 999976 999976 999976 999974 999974 999975 999974 999973 999974 999968 999968 999965 999965 999967 999965 999965 999960 999960 999959 999959...

output:

33358042175183584

result:

ok single line: '33358042175183584'

Test #10:

score: 0
Time Limit Exceeded

input:

262144
1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1000000 1 1...

output:


result:


Test #11:

score: 4.34783
Accepted
time: 1373ms
memory: 20596kb

input:

262144
518701 585574 345076 642315 75617 893688 485383 696337 31086 682159 969846 943380 254864 406197 509965 126319 135623 147440 7593 120839 163643 128819 324108 935846 334903 804212 668986 900274 503397 603547 238961 51946 697501 412370 426586 80682 390652 730017 13011 254438 357154 142380 587176...

output:

34357316353722230

result:

ok single line: '34357316353722230'

Test #12:

score: 4.34783
Accepted
time: 1ms
memory: 4104kb

input:

300
216080 283804 812393 874518 459351 285947 246394 558391 105329 831354 487737 667446 725110 860965 686619 499108 856557 662571 474888 145951 754627 969797 89658 936887 391068 461211 376147 310350 185753 576410 821006 745593 39979 592437 80465 176087 47907 190517 291417 351610 276193 277438 392732...

output:

43964210127

result:

ok single line: '43964210127'

Test #13:

score: 4.34783
Accepted
time: 377ms
memory: 82288kb

input:

262144
1000000 999999 999998 999997 999996 999995 999994 999993 999992 999991 999990 999989 999988 999987 999986 999985 999984 999983 999982 999981 999980 999979 999978 999977 999976 999975 999974 999973 999972 999971 999970 999969 999968 999967 999966 999965 999964 999963 999962 999961 999960 99995...

output:

31357504048070656

result:

ok single line: '31357504048070656'

Test #14:

score: 4.34783
Accepted
time: 599ms
memory: 78112kb

input:

262144
999996 999994 999992 999988 999984 999979 999979 999977 999975 999974 999974 999972 999972 999970 999966 999964 999960 999960 999958 999958 999956 999954 999953 999951 999947 999947 999944 999942 999942 999939 999938 999936 999932 999929 999927 999926 999924 999923 999921 999920 999917 999916...

output:

31357492587251043

result:

ok single line: '31357492587251043'

Test #15:

score: 0
Time Limit Exceeded

input:

262144
999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 999999 1000000 999999 ...

output:


result:


Test #16:

score: 4.34783
Accepted
time: 1361ms
memory: 42000kb

input:

262144
13108 13108 13108 13107 13108 13107 13107 13107 13107 13107 13107 13108 13108 13107 13106 13106 13107 13106 13107 13106 13107 13106 13107 13106 13106 13105 13105 13105 13106 13106 13106 13106 13105 13105 13104 13104 13104 13105 13105 13105 13105 13105 13104 13103 13104 13103 13104 13103 13104...

output:

300435587621709

result:

ok single line: '300435587621709'

Test #17:

score: 4.34783
Accepted
time: 1ms
memory: 3860kb

input:

300
999994 999993 999992 999992 999994 999993 999993 999994 999993 999993 999994 999994 999989 999989 999987 999987 999988 999988 999988 999989 999988 999987 999987 999988 999988 999988 999988 999991 999990 999990 999991 999991 999988 999988 999987 999987 999987 999987 999990 999988 999988 999988 99...

output:

44825213269

result:

ok single line: '44825213269'

Test #18:

score: 4.34783
Accepted
time: 7ms
memory: 3932kb

input:

3000
913347 411708 830707 139908 468414 282707 863947 767999 450119 677303 995373 830927 170138 485956 92253 450159 17536 876709 396157 624566 138039 747050 536096 755345 809347 388938 533086 633605 903211 209505 775942 150544 645398 777384 784526 972509 651132 777038 644255 300305 83761 999139 1441...

output:

4486507743420

result:

ok single line: '4486507743420'

Test #19:

score: 4.34783
Accepted
time: 12ms
memory: 4276kb

input:

3000
999988 999988 999989 999990 999991 999990 999989 999987 999986 999986 999987 999986 999985 999985 999990 999990 999990 999990 999990 999990 999991 999988 999988 999989 999990 999988 999987 999986 999985 999985 999989 999988 999987 999985 999985 999986 999988 999987 999986 999986 999986 999986 9...

output:

3872120136367

result:

ok single line: '3872120136367'

Test #20:

score: 0
Time Limit Exceeded

input:

262144
1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1...

output:


result:


Test #21:

score: 0
Time Limit Exceeded

input:

262144
1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 5 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 3 1 1 2 1 1 2 1 1 4 1 1 2 1 1 2 1 1 3 1 1 2...

output:


result:


Test #22:

score: 0
Time Limit Exceeded

input:

262144
1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 5 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 7 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1 1 1 3 1 1...

output:


result:


Test #23:

score: 4.34783
Accepted
time: 389ms
memory: 82092kb

input:

262144
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

6004868222550016

result:

ok single line: '6004868222550016'