QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643859#7963. 多折较差验证hos_lyric#AC ✓1694ms178104kbC++147.5kb2024-10-16 03:13:062024-10-16 03:13:07

Judging History

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

  • [2024-10-16 03:13:07]
  • 评测
  • 测评结果:AC
  • 用时:1694ms
  • 内存:178104kb
  • [2024-10-16 03:13:06]
  • 提交

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")


// T: monoid representing information of an interval.
//   T()  should return the identity.
//   T(S s)  should represent a single element of the array.
//   T::pull(const T &l, const T &r)  should pull two intervals.
template <class T> struct SegmentTreePoint {
  int logN, n;
  vector<T> ts;
  SegmentTreePoint() : logN(0), n(0) {}
  explicit SegmentTreePoint(int n_) {
    for (logN = 0, n = 1; n < n_; ++logN, n <<= 1) {}
    ts.resize(n << 1);
  }
  template <class S> explicit SegmentTreePoint(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 pull(int u) {
    ts[u].pull(ts[u << 1], ts[u << 1 | 1]);
  }

  // Changes the value of point a to s.
  template <class S> void change(int a, const S &s) {
    assert(0 <= a); assert(a < n);
    ts[a += n] = T(s);
    for (; a >>= 1; ) pull(a);
  }

  // Applies T::f(args...) to point a.
  template <class F, class... Args>
  void ch(int a, F f, Args &&... args) {
    assert(0 <= a); assert(a < n);
    (ts[a += n].*f)(args...);
    for (; a >>= 1; ) pull(a);
  }

  // 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();
    T prodL, prodR, t;
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) { t.pull(prodL, ts[a++]); prodL = t; }
      if (b & 1) { t.pull(ts[--b], 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();
    auto prodL = e(), prodR = e();
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) prodL = op(prodL, (ts[a++].*f)(args...));
      if (b & 1) prodR = op((ts[--b].*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 (; ; a >>= 1) if (a & 1) {
      if ((ts[a].*f)(args...)) {
        for (; a < n; ) {
          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 (; ; b >>= 1) if ((b & 1) || b == 2) {
      if ((ts[b - 1].*f)(args...)) {
        for (; b <= n; ) {
          if (!(ts[(b <<= 1) - 1].*f)(args...)) --b;
        }
        return b - n - 1;
      }
      --b;
      if (!(b & (b - 1))) return -1;
    }
  }
};  // SegmentTreePoint<T>

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

constexpr int INF = 1001001001;

struct NodeMin {
  int mn;
  NodeMin() : mn(+INF) {}
  NodeMin(int val) : mn(val) {}
  void pull(const NodeMin &l, const NodeMin &r) {
    mn = min(l.mn, r.mn);
  }
  void ch(int val) {
    mn = val;
  }
  void chmin(int val) {
    if (mn > val) mn = val;
  }
  bool test(int tar) const {
    return (mn <= tar);
  }
};
struct NodeMax {
  int mx;
  NodeMax() : mx(-INF) {}
  NodeMax(int val) : mx(val) {}
  void pull(const NodeMax &l, const NodeMax &r) {
    mx = max(l.mx, r.mx);
  }
  void ch(int val) {
    mx = val;
  }
  void chmax(int val) {
    if (mx < val) mx = val;
  }
  bool test(int tar) const {
    return (mx >= tar);
  }
};

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


int N;
char S[5010];

pair<int, int> dp[5010][5010];

int main() {
  for (; ~scanf("%d", &N); ) {
    scanf("%s", S);
    
    vector<int> rads(N, 0);
    for (int i = 0; i < N; ++i) {
      for (int l = i - 1, r = i + 1; 0 <= l && r < N && S[l] != S[r]; --l, ++r) {
        ++rads[i];
      }
    }
// cerr<<"rads = "<<rads<<endl;
    
    SegmentTreePoint<NodeMax> segL(N), segR(N);
    for (int m = 0; m < N; ++m) {
      segL.at(m) = rads[m] - m;
      segR.at(m) = rads[m] + (m + 1);
    }
    segL.build();
    segR.build();
    
    for (int l = 0; l <= N; ++l) for (int r = l; r <= N; ++r) {
      dp[l][r] = make_pair(INF, INF);
    }
    for (int i = 0; i <= N; ++i) {
      dp[i][i] = make_pair(0, 0);
    }
    for (int l = N; --l >= 0; ) {
      for (int r = l + 1; r <= N; ++r) {
        /*
        for (int m = (l + r - 1) / 2; --m >= l; ) if (rads[m] >= m - l) {
          chmin(dp[l][r], make_pair(dp[m + 1][r].first + 1, dp[m + 1][r].second + ((r - (m + 1)) - (m - l))));
          break;
        }
        for (int m = (l + r) / 2; m < r; ++m) if (rads[m] >= r - (m + 1)) {
          chmin(dp[l][r], make_pair(dp[l][m].first + 1, dp[l][m].second + ((m - l) - (r - (m + 1)))));
          break;
        }
        */
        {
          const int m = segL.findLeft((l + r - 1) / 2 + 1, &NodeMax::test, -l);
          if (l <= m) {
            chmin(dp[l][r], make_pair(dp[m + 1][r].first + 1, dp[m + 1][r].second + ((r - (m + 1)) - (m - l))));
          }
        }
        {
          const int m = segR.findRight((l + r) / 2, &NodeMax::test, r) - 1;
          if (m < r) {
            chmin(dp[l][r], make_pair(dp[l][m].first + 1, dp[l][m].second + ((m - l) - (r - (m + 1)))));
          }
        }
      }
    }
    
    printf("%d %d\n", dp[0][N].first, dp[0][N].second);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1618ms
memory: 146764kb

input:

5000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

output:

5000 12497500

result:

ok single line: '5000 12497500'

Test #2:

score: 0
Accepted
time: 1671ms
memory: 150796kb

input:

4991
^^vv^v^^^^vvv^^^^^^vvvv^^^^^^^vv^^^^^^^^v^^^^^^v^^^v^^v^^^v^^^^^v^^v^^^^^^^^vv^^^^^^^^^^vvvvvvv^v^^^^^v^v^^^^^v^^^^^^^^^^^v^^^^^vv^v^^^^^v^^^^vvv^^^v^^^^v^^^^^vv^^v^^^^^^^v^^^^^^^^^v^v^^^v^^v^^^^^v^^^vv^v^^^v^^^v^v^v^^^^v^^^vv^^^^vv^^v^^v^^^^^^^v^^^^^^v^^^^v^^^^^^v^^v^v^^^^^^^^v^^^^^v^^^v^v^^^^...

output:

2748 6735487

result:

ok single line: '2748 6735487'

Test #3:

score: 0
Accepted
time: 1680ms
memory: 157408kb

input:

5000
vvvvvv^v^vvvv^^^vv^^v^v^^^vvvv^v^v^v^v^v^v^vvvvvvvv^^vvv^vvvvvvvvvvvv^vvvv^^^^vvvv^vv^^vv^vvv^vvvvvvvv^^vv^^vv^vvvvv^vvv^vvvvvvvvv^v^^vv^v^vvvvv^v^v^vvvv^vvv^vvv^^vvvvv^^vvvvvvv^v^vvvvv^v^^^^v^vvv^v^vv^vvvvv^vv^vvvvvv^vvvvvv^vvvvvv^vvv^^vvvvvvv^^^^vv^vv^v^vvvv^vv^vvv^vvv^vvv^vvvvv^^^^vvvv^vvvvv...

output:

2793 6922268

result:

ok single line: '2793 6922268'

Test #4:

score: 0
Accepted
time: 1681ms
memory: 158248kb

input:

4996
vv^^vvvv^^v^^^vvvv^vv^vvvvv^vv^^^vvvv^vv^^^vvv^^v^vvvvv^vvv^v^^vv^^vv^vvvvv^v^vvvvvv^^vv^v^vvv^^vv^vvvvvv^vvvv^vvvvvvvvvvvvv^vvvvv^vvv^vvv^vvv^^vv^vv^vvvvvvv^^vvv^vv^vvvv^vvvvvv^vv^vvvv^v^vvv^v^^vvv^vvvv^^vvvvvvvvvvv^^vv^v^vv^vv^vv^^v^v^^^^vvvvvv^^vvvv^vvv^vvv^v^vv^vvvvvvvv^vvv^v^^vv^vvv^vv^v^v...

output:

2784 6803847

result:

ok single line: '2784 6803847'

Test #5:

score: 0
Accepted
time: 1694ms
memory: 157168kb

input:

5000
vvvvvvvvvvvvvvvvvvvvv^^vvvvvvvv^vvvvvvvvvvv^vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv^v^vvvv^vv^vvvv^vvvvvvvvvvvvvvvvvvvvvv^vv^vvvvvvvvvvvvvvvvvvvvvvvvvvvv^^vvvvvvvvvvvvvv^vvvvvvvv^vvvvvvvvvvvvvvvvv^vvv^vvvv^vvvvvvvvvvvvvvv^v^vvvvv^vvvvvv^vv^vvvvvvvvvvv^vv^vvvvvvvvvvvvv^vvvvvvvvvvvvv^vvvvvvvvvvvvv^vvvv...

output:

4052 10043778

result:

ok single line: '4052 10043778'

Test #6:

score: 0
Accepted
time: 1686ms
memory: 157072kb

input:

4992
vvvvvvvvvv^vvvvvvvvvvvvvvvvvvv^vvvvvvvvvvvvvvvvv^vvv^vvv^vvv^vvvvvv^vvvvvvvv^v^vvvvvvvvvvvvvvv^vvvvvv^vvvv^vvvvvvvvvvv^v^^vvvvvvvvvvvvvvvvvvvvv^^vvvvvvvvvvvv^vv^vvvvvv^vvvvvvvvvvv^vvvvvvvvvvvvvvvvvvvvvvvvvvvv^vvv^v^vvvv^vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv^vvvvvv^v^vvvvvvvvv^vvvvvvvvv...

output:

4094 10183595

result:

ok single line: '4094 10183595'

Test #7:

score: 0
Accepted
time: 1655ms
memory: 157504kb

input:

4992
^^^^vvvvvvvvvv^^^^^vv^^^^^^^^^^vvv^^^^^^vvvvvvv^^^vv^vvvvvvvvv^vvvvvvvvv^^^^^^^^^vvvvvvvvvv^^v^vvvvvvv^^^vvvvvvvvv^^^^^^^^^^vvvvvvv^^^^^vvvvvvvvv^^^^^^^^vvvv^vvvvvvvv^^^^^^^^^^vvv^^^^^^^vvvv^^^^^^^^^vvvvvvv^^^^^^^^vvvv^^^^^vvvvvvv^^^^^^^^vvvvvvvvvv^^^vvvvvvv^^^v^^^^^^^^^vvvvvvvv^^^^^vvv^^^^^^^^...

output:

1513 3793047

result:

ok single line: '1513 3793047'

Test #8:

score: 0
Accepted
time: 1667ms
memory: 155072kb

input:

4999
vvvvvvv^^^^vv^^^^^^^^^^vvvvvvvvv^^^^^^^^^^v^^^^^^^^^vvvv^vvvvv^^^^^^^^^vvvvv^vvv^^^^^^^^vvvvv^^^^^^^vvvvvvvvv^^^vvvv^^^^^^^^^^vvvvvv^^^^^vvvv^^^^^^vvvvvvvvv^^^^^^v^^^^vvvv^^^^^^^^^vvvv^^^^vvvvvvv^^^^vvvv^^^^^^^^vvvvvvvv^^^^^^^vvvvvvvv^^^^^^vvvvvvvvvv^^^^^vvvv^^^^^vv^^^^^^vvvvvvvvv^^vvvv^^vvvvvv...

output:

1641 3991610

result:

ok single line: '1641 3991610'

Test #9:

score: 0
Accepted
time: 1659ms
memory: 155412kb

input:

4997
vvvvv^^^^vv^^^vv^^vvvv^^^^^vvvvvvvvvv^^^^^^^^^vvvv^^^^^^^^^vvvv^vvvvv^vvvvvvvvvv^^^^^vvv^^^^^^^^vvvv^^^^vvvvvvvvv^^^^^^vv^^^^^^^^^vv^^^^^^^vvvvvvvvv^^^^^^vvvvvvv^^^^^^^vvvvvvvvv^^^^^^^^vvvvvvv^^^^^^^^^^vvvv^^^v^^^^^vvvvv^^^^vvvvvv^^^^^^^^^vvvvvvv^^^^^vvvvvvv^^^^^^^v^^^^^^^^^vvvvvvvv^^^^vvv^vvvv...

output:

1572 3933114

result:

ok single line: '1572 3933114'

Test #10:

score: 0
Accepted
time: 1655ms
memory: 155056kb

input:

4999
^v^^^^^^^vvvvvv^^^^^^^^^^vvvvvv^^^^vvvv^^vvv^^^^^^^^^vvvvv^vvvvvvvvv^^vvv^^^^v^^^^^^^^^^vv^^^^^^^^^v^^^^^^vvvvvvvv^^^^^vv^^^^^^^^^vvvvvvvvvv^^^^^vv^^^^vvvvvvv^^^^^^^^^^vvvvvvv^^^^^^vvvvvvvv^^^vvvv^^^^^^vvvvvv^^^^vvvvvv^^^^^^v^^vvvvvvv^^^^vv^^vvvvv^^^vvvv^^^^vvvv^^^vvvvvvvvvv^^^^^^^^^vvvvv^^^^v^...

output:

1485 3659494

result:

ok single line: '1485 3659494'

Test #11:

score: 0
Accepted
time: 1408ms
memory: 158856kb

input:

5000
v^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^...

output:

13 2184

result:

ok single line: '13 2184'

Test #12:

score: 0
Accepted
time: 1623ms
memory: 158264kb

input:

5000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

5000 12497500

result:

ok single line: '5000 12497500'

Test #13:

score: 0
Accepted
time: 1410ms
memory: 155692kb

input:

5000
v^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^v...

output:

13 2580

result:

ok single line: '13 2580'

Test #14:

score: 0
Accepted
time: 890ms
memory: 151056kb

input:

4095
vv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^^vv^vv^^...

output:

12 0

result:

ok single line: '12 0'

Test #15:

score: 0
Accepted
time: 893ms
memory: 144956kb

input:

4095
v^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^...

output:

12 0

result:

ok single line: '12 0'

Test #16:

score: 0
Accepted
time: 1460ms
memory: 148492kb

input:

4994
^vv^^^vvv^vv^vv^^v^^^^vvv^vv^^v^^v^^^vvv^^v^^v^^vvvv^^^vv^vv^vv^^^vvv^vv^vv^^v^^^vvvv^vv^^v^^v^^^vvv^^v^^v^^vv^vv^^^vvv^vv^vv^^v^^^^vvv^vv^^v^^v^^^vvv^^v^^v^^vvvv^vvvvvvv^vv^^vvv^^v^^^^^^^v^^^^vv^vv^vv^^^vvv^vv^vv^^v^^^vvvv^vv^^v^^v^^^vvv^^v^^vv^vv^vv^^^vvv^vv^vv^^v^^^^vvv^vv^^v^^v^^^vvv^^v^^v^...

output:

27 2053

result:

ok single line: '27 2053'

Test #17:

score: 0
Accepted
time: 1418ms
memory: 160492kb

input:

4992
v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^...

output:

14 2351

result:

ok single line: '14 2351'

Test #18:

score: 0
Accepted
time: 1434ms
memory: 164132kb

input:

4997
^^v^^^v^^^^^^vvv^^^vv^^^vv^^v^^vv^^vvv^^vvv^^^^vvv^^^vv^^^vv^^vv^vv^^vvv^^vvv^^^vvvvv^^^^vvv^^^vv^^^vv^^v^^vv^^vvv^^vvv^^^vvvv^^^vv^^^vv^^vv^vv^^vvv^^vvv^^^vvvvv^^^^vvv^^^vv^^^vv^^v^^vv^^vvv^^vvv^^^^vvv^^^vv^^^vv^^vv^vv^^vvv^^vvv^^^vvvv^^^^^vvv^^^vv^^^vv^^v^^vv^^vvv^^vvv^^^vvvv^^^vv^^^vv^^vv^vv...

output:

28 671

result:

ok single line: '28 671'

Test #19:

score: 0
Accepted
time: 1435ms
memory: 154824kb

input:

4999
^v^^^v^^^^v^v^^v^v^vvvv^vvv^v^vv^^^v^v^^^v^^^vvvv^vvv^v^vvv^^v^v^^^v^^^^v^v^^^vv^^v^^vvv^v^vvvv^vvv^v^vv^^^v^v^^^v^^^^vvv^vvv^v^vvv^^v^v^^^v^^^^v^v^vv^v^vvvv^vvv^v^vv^^^v^v^^^v^^^vvvv^vvv^v^vvv^^v^v^^^v^^^^v^v^^^vvvv^v^vvvv^vvv^v^vv^^^v^v^^^v^^^^vvv^vvv^v^vvv^^v^v^^^v^^^^v^v^^v^v^vvvv^vvv^v^vv^...

output:

35 2652

result:

ok single line: '35 2652'

Test #20:

score: 0
Accepted
time: 1466ms
memory: 154004kb

input:

4999
^v^^v^^vvv^^^^^^^^vvvvvvv^^^v^^vvv^^^^^^^vvvvvvvv^^^v^^vvv^^^^^^^^vvvvvvv^^^vv^vvv^^^^^^^vvvvvvvv^^^v^^vvv^^^^^^^^vvvvvvv^^^v^^vvv^^^^^^^vvvvvvvv^^^vv^vvv^^^^^^^^vvvvvvv^^^vv^vvv^^^^^^^vvvvvvvv^^^v^^vvv^^^^^^^^vvvvvvv^^^v^^vvv^^^^^^^vvvvvvvv^^^v^^vvv^^^^^^^^vvvvvvv^^^vv^vvv^^^^^^^vvvvvvvv^^^vv^...

output:

29 5816

result:

ok single line: '29 5816'

Test #21:

score: 0
Accepted
time: 1455ms
memory: 166636kb

input:

4999
^^^vv^vv^^^vv^vvv^^v^^vvvv^^^vv^vv^^^^^vv^^^vvvvv^^v^^vvv^^^^vv^vv^^^v^^vvv^^v^^vvvv^^^vv^vv^^^v^vv^vvv^^v^^vvv^^^^vv^vv^^^vv^vvv^^v^^vvvv^^^vv^vv^^^^^vvv^^vvvvv^^v^^vvv^^^^vv^vv^^^v^^vvv^^v^^vvvv^^^vv^vv^^vv^vv^^^v^^vv^^v^^vvv^^^^vv^vv^^^vv^vvv^^v^^vvvv^^^vv^vv^^^^^vv^^^vvvvv^^v^^vvv^^^^vv^vv^...

output:

21 1650

result:

ok single line: '21 1650'

Test #22:

score: 0
Accepted
time: 1421ms
memory: 155888kb

input:

4991
^^vv^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv...

output:

13 2490

result:

ok single line: '13 2490'

Test #23:

score: 0
Accepted
time: 1679ms
memory: 166180kb

input:

5000
^^^v^v^vv^^vv^^v^v^vvvv^^^vv^^vvvvvv^vvvvvvvvvvvv^vvvvvv^^^^v^vv^vvv^^v^^^^v^vvvvvvv^^v^vv^^vvvvvv^vv^^v^^^^^v^^vv^vvvv^^vvv^^^vvvvv^v^vv^^vvv^v^v^vvvv^vvv^^^vv^v^vvv^^^v^^vv^vv^^v^^^^vvvv^vvv^^vv^vv^v^v^vvv^vvv^^^v^vv^^v^^vv^vvv^^v^^vvv^vvv^vv^^v^v^vvv^^^^vv^v^vvvvv^vvv^^vvvvv^v^^vv^^^^^^^v^^v...

output:

2264 5574395

result:

ok single line: '2264 5574395'

Test #24:

score: 0
Accepted
time: 1399ms
memory: 164976kb

input:

4996
v^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^...

output:

13 2218

result:

ok single line: '13 2218'

Test #25:

score: 0
Accepted
time: 1428ms
memory: 165660kb

input:

4995
vvv^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vv^^^vv...

output:

13 2575

result:

ok single line: '13 2575'

Test #26:

score: 0
Accepted
time: 1375ms
memory: 174288kb

input:

4999
vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^...

output:

13 1662

result:

ok single line: '13 1662'

Test #27:

score: 0
Accepted
time: 1411ms
memory: 159564kb

input:

4996
vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^v^^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^v^^vvv^^v^^vv^^^vv^vvv^^vv^vv^^^vv^vvv^^v^^vv^^^v^...

output:

13 2457

result:

ok single line: '13 2457'

Test #28:

score: 0
Accepted
time: 1391ms
memory: 178104kb

input:

4997
vv^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^^v^^^vv^vv^^vvv^vv^^^vv^^v^^vvv^vv^^^vv^vv^^vvv^^v^^^vv...

output:

13 2235

result:

ok single line: '13 2235'

Test #29:

score: 0
Accepted
time: 1408ms
memory: 164444kb

input:

4991
^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^^vv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^vvv^^v^^^vv^vv^^vvv^^v^^vvv^vv^^^vv^^v^^^vv^vv^^^v...

output:

13 1932

result:

ok single line: '13 1932'

Test #30:

score: 0
Accepted
time: 1403ms
memory: 164300kb

input:

4991
v^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vv^^^v^^vvv^^vv^vvv^^v^^vv^^^vv^vvv^^v^^vvv^^vv^vv^^^v^^vv^^^vv^vvv^^v^^v...

output:

13 2369

result:

ok single line: '13 2369'

Test #31:

score: 0
Accepted
time: 1671ms
memory: 164084kb

input:

5000
^vvvvvvv^^vvv^^^v^^v^vvv^v^^^vv^^vvvvvv^^^vvv^^^v^^vvv^^^v^v^v^vv^v^^v^v^v^^v^^^vv^vvv^^^v^vvvvv^v^vvvvvvvvv^^^^v^vv^^vvv^v^vvvv^v^vv^^^^^^vv^^^^^^vv^vv^v^^^v^v^^^^^v^^v^^^^^vvvvv^vvv^v^^vv^v^^vvvvv^^^^vv^vvv^^v^v^^vv^vv^^^^v^vv^^v^^^v^^^^^^^v^v^vv^^^v^^^v^^vv^^^v^^^^^v^^^v^^vvvvv^v^^^v^vvv^v^v...

output:

2188 5310449

result:

ok single line: '2188 5310449'

Test #32:

score: 0
Accepted
time: 1672ms
memory: 164232kb

input:

5000
^vv^^^^^^vv^vv^v^^vv^^^vv^v^v^^^^^^^^v^^vvv^v^^^^v^v^^^^^^^v^^^vv^^vvv^v^^^^vv^^vvvv^v^^^^^vvvvvv^vv^^^v^vvvvv^vvv^^^^v^vvvv^^^^^^^v^vvvvvv^v^^^^^vvvvv^v^^^^v^^^v^vv^vv^vvv^v^^^v^vv^v^^v^^v^vv^vvvv^^^vv^vvv^^^^vv^^^vv^v^v^v^vvvv^^^vv^^^vvvvvvv^v^vvvv^^^vv^v^^v^v^vvv^vvv^vvvvvv^v^^vvvvv^^vv^vv^v...

output:

2146 5271567

result:

ok single line: '2146 5271567'

Test #33:

score: 0
Accepted
time: 1681ms
memory: 164880kb

input:

5000
^v^v^v^vvvvvvvv^^v^v^^vv^^v^^^v^v^^^v^v^^vvvvv^vvv^^^^v^^^vvvvv^^v^v^v^^^v^v^^vv^^v^^^^v^v^vv^v^^v^^v^^vv^^vv^^^vvvv^v^vvv^^vv^v^^^^^vvvv^v^^^vv^vv^vvv^v^^vv^v^^^v^v^^^^vv^v^^^v^^^vv^vvv^^^v^vvvv^^v^^^^v^vv^v^v^^^vvvv^v^^^v^^^vv^^v^v^^^vv^v^^v^^^v^v^vvvv^vvvvv^v^vv^^^v^^v^^^^^v^v^^^^v^v^^v^^v^^...

output:

2213 5408180

result:

ok single line: '2213 5408180'

Test #34:

score: 0
Accepted
time: 1682ms
memory: 164716kb

input:

5000
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^^^^^^^^v^^^^^^v^^^^^^^^^^^v^^^^^^^^^^^^^^^^^^^^^^^^^^v^^^^^^^^v^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^^v^^^^^^vv^^^^^^^v^^^^^^^^^v^^^^^v^v^^^^^^^^^^^^v^^^^^^^^^^^^v^^v^^^^^^v^^^^^^^^^^^^^^^v^^^v^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^^^^^^^v^^^^^^^^^^^^^^^v^^^^^^...

output:

4115 10169791

result:

ok single line: '4115 10169791'

Test #35:

score: 0
Accepted
time: 1681ms
memory: 163804kb

input:

4995
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^^v^^^^^^^^v^^v^^^^^^^^^^^^^^^^^^^v^v^^^^^^^^^^v^^^^^^^^^v^^v^^v^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^v^^^^^v^^^^^^^^v^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^v^^^^^^^v^^^v^^^^^^^^^^^^v^^^^^v^^^^^^^^^^^^^^^^^^^v^^^^^^^^^^^^^^...

output:

4082 10186253

result:

ok single line: '4082 10186253'

Test #36:

score: 0
Accepted
time: 1679ms
memory: 164888kb

input:

5000
^^^v^^^^v^v^^v^^^^vvv^^^vv^^v^^^^vv^^^^^^^^v^v^^^^^^v^^v^v^v^v^^vv^^v^^^^v^^^^^^^v^v^v^^^^^^^^v^v^^^^^^^v^^v^v^^^^v^^^^^v^^^^^^vvv^^v^vv^^vvv^v^vvv^^^vvv^^^v^^^^^vv^^^^^v^v^v^^^^^^v^v^^^vv^^^^^^^^vv^^vv^v^^v^^v^v^^^^^^^^^^^^v^^v^v^^v^^^^^^vvv^^^^^^^^^^vv^v^^vv^v^vv^^v^^v^^^^^^^v^^vv^v^^^^vv^^vv...

output:

2753 6808711

result:

ok single line: '2753 6808711'