QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632016#8509. Expanding STACKS!maspyAC ✓1ms4012kbC++2020.1kb2024-10-12 11:29:462024-10-12 11:29:46

Judging History

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

  • [2024-10-12 11:29:46]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:4012kb
  • [2024-10-12 11:29:46]
  • 提交

answer

#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/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;
  if (pir < SZ) ibuf[pir++] = '\n';
}

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();
    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 ('0' <= c) { 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;

#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif

#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 "/home/maspy/compro/library/ds/unionfind/unionfind.hpp"

struct UnionFind {
  int n, n_comp;
  vc<int> dat; // par or (-size)
  UnionFind(int n = 0) { build(n); }

  void build(int m) {
    n = m, n_comp = m;
    dat.assign(n, -1);
  }

  void reset() { build(n); }

  int operator[](int x) {
    while (dat[x] >= 0) {
      int pp = dat[dat[x]];
      if (pp < 0) { return dat[x]; }
      x = dat[x] = pp;
    }
    return x;
  }

  ll size(int x) {
    x = (*this)[x];
    return -dat[x];
  }

  bool merge(int x, int y) {
    x = (*this)[x], y = (*this)[y];
    if (x == y) return false;
    if (-dat[x] < -dat[y]) swap(x, y);
    dat[x] += dat[y], dat[y] = x, n_comp--;
    return true;
  }

  vc<int> get_all() {
    vc<int> A(n);
    FOR(i, n) A[i] = (*this)[i];
    return A;
  }
};
#line 2 "/home/maspy/compro/library/graph/blackbox/unionfind.hpp"

// 頂点を削除しながら、適当なデータ構造により次の辺を探す。
// 中身はただの bfs しているので、01 最短路にも流用可能
template <typename F1, typename F2>
UnionFind blackbox_unionfind(int N, F1 set_used, F2 find_unused) {
  UnionFind uf(N);
  vc<bool> done(N);
  deque<int> que;
  FOR(v, N) if (!done[v]) {
    que.eb(v);
    done[v] = 1;
    set_used(v);
    while (!que.empty()) {
      int x = que.front();
      que.pop_front();
      set_used(x);
      done[x] = 1;
      while (1) {
        int to = find_unused(x);
        if (to == -1) break;
        uf.merge(v, to);
        que.eb(to);
        done[to] = 1;
        set_used(to);
      }
    }
  }
  return uf;
}
#line 2 "/home/maspy/compro/library/ds/segtree/segtree.hpp"

template <class Monoid>
struct SegTree {
  using MX = Monoid;
  using X = typename MX::value_type;
  using value_type = X;
  vc<X> dat;
  int n, log, size;

  SegTree() {}
  SegTree(int n) { build(n); }
  template <typename F>
  SegTree(int n, F f) {
    build(n, f);
  }
  SegTree(const vc<X>& v) { build(v); }

  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, MX::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }

  X get(int i) { return dat[size + i]; }
  vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }

  void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
  void set(int i, const X& x) {
    assert(i < n);
    dat[i += size] = x;
    while (i >>= 1) update(i);
  }

  void multiply(int i, const X& x) {
    assert(i < n);
    i += size;
    dat[i] = Monoid::op(dat[i], x);
    while (i >>= 1) update(i);
  }

  X prod(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    X vl = Monoid::unit(), vr = Monoid::unit();
    L += size, R += size;
    while (L < R) {
      if (L & 1) vl = Monoid::op(vl, dat[L++]);
      if (R & 1) vr = Monoid::op(dat[--R], vr);
      L >>= 1, R >>= 1;
    }
    return Monoid::op(vl, vr);
  }

  X prod_all() { return dat[1]; }

  template <class F>
  int max_right(F check, int L) {
    assert(0 <= L && L <= n && check(Monoid::unit()));
    if (L == n) return n;
    L += size;
    X sm = Monoid::unit();
    do {
      while (L % 2 == 0) L >>= 1;
      if (!check(Monoid::op(sm, dat[L]))) {
        while (L < size) {
          L = 2 * L;
          if (check(Monoid::op(sm, dat[L]))) { sm = Monoid::op(sm, dat[L++]); }
        }
        return L - size;
      }
      sm = Monoid::op(sm, dat[L++]);
    } while ((L & -L) != L);
    return n;
  }

  template <class F>
  int min_left(F check, int R) {
    assert(0 <= R && R <= n && check(Monoid::unit()));
    if (R == 0) return 0;
    R += size;
    X sm = Monoid::unit();
    do {
      --R;
      while (R > 1 && (R % 2)) R >>= 1;
      if (!check(Monoid::op(dat[R], sm))) {
        while (R < size) {
          R = 2 * R + 1;
          if (check(Monoid::op(dat[R], sm))) { sm = Monoid::op(dat[R--], sm); }
        }
        return R + 1 - size;
      }
      sm = Monoid::op(dat[R], sm);
    } while ((R & -R) != R);
    return 0;
  }

  // prod_{l<=i<r} A[i xor x]
  X xor_prod(int l, int r, int xor_val) {
    static_assert(Monoid::commute);
    X x = Monoid::unit();
    for (int k = 0; k < log + 1; ++k) {
      if (l >= r) break;
      if (l & 1) { x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]); }
      if (r & 1) { x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]); }
      l /= 2, r /= 2, xor_val /= 2;
    }
    return x;
  }
};
#line 2 "/home/maspy/compro/library/alg/monoid/min.hpp"

template <typename E>
struct Monoid_Min {
  using X = E;
  using value_type = X;
  static constexpr X op(const X &x, const X &y) noexcept { return min(x, y); }
  static constexpr X unit() { return infty<E>; }
  static constexpr bool commute = true;
};
#line 2 "/home/maspy/compro/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 8 "main.cpp"

void solve() {
  INT(N);
  vc<int> L(N), R(N);
  vc<int> idx(2 * N);
  FOR(k, 2 * N) {
    STR(S);
    int i = stoi(S.substr(1)) - 1;
    if (S[0] == '-') R[i] = k;
    if (S[0] == '+') L[i] = k;
    idx[k] = i;
  }
  // SHOW(L);
  // SHOW(R);

  SegTree<Monoid_Min<int>> seg1(2 * N, [&](int i) -> int {
    int k = idx[i];
    return (R[k] == i ? L[k] : infty<int>);
  });
  SegTree<Monoid_Max<int>> seg2(2 * N, [&](int i) -> int {
    int k = idx[i];
    return (L[k] == i ? R[k] : -infty<int>);
  });

  vc<int> color(N);
  auto set_used = [&](int v) -> void {
    seg1.set(R[v], infty<int>);
    seg2.set(L[v], -infty<int>);
  };
  auto find_unused = [&](int v) -> int {
    vc<int> cand;
    cand.eb(seg1.prod(L[v], R[v]));
    cand.eb(seg2.prod(L[v], R[v]));
    for (auto& x: cand) {
      if (abs(x) == infty<int>) continue;
      int k = idx[x];
      if ((L[v] < L[k] && L[k] < R[v] && R[v] < R[k]) || (L[k] < L[v] && L[v] < R[k] && R[k] < R[v])) {
        color[k] = color[v] ^ 1;
        return k;
      }
    }
    return -1;
  };
  blackbox_unionfind(N, set_used, find_unused);
  vc<int> st[2];
  FOR(i, 2 * N) {
    int k = idx[i];
    int c = color[k];
    if (L[k] == i)
      st[c].eb(k);
    else {
      if (st[c].back() != k) return print("*");
      st[c].pop_back();
    }
  }

  string ANS;
  FOR(i, N) ANS += (color[i] ? "S" : "G");
  print(ANS);
}

signed main() { solve(); }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3976kb

input:

2
+2 +1 -1 -2

output:

GG

result:

ok correct

Test #2:

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

input:

2
+1 +2 -1 -2

output:

GS

result:

ok correct

Test #3:

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

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

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

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

GGGGGGGGGG

result:

ok correct

Test #5:

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

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

GGGGGGGGGS

result:

ok correct

Test #6:

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

input:

42
+26 -26 +12 +8 -12 -8 +30 +5 +22 +3 -3 +2 -30 +10 -10 -2 -22 +23 +39 -39 +17 -17 -23 +38 +24 -24 +27 +29 -29 -27 -38 -5 +37 -37 +21 +16 +28 -28 +6 +40 +14 +19 -19 -14 +11 +35 -35 -11 +4 +25 -25 -4 -40 -6 +13 +20 +1 -1 +33 +34 +7 -7 -34 +41 -41 +36 +31 -31 -36 +42 +32 -32 +15 +18 -18 -15 +9 -9 -42...

output:

GGGGGGGGGGGSGGGGGGGGGGGGGGGGGSGGGGGGGGGGGG

result:

ok correct

Test #7:

score: 0
Accepted
time: 1ms
memory: 3984kb

input:

42
+40 +18 +42 +2 +1 +21 +33 -2 +8 -33 -8 +14 -40 +34 +30 +31 -31 -30 +5 -5 +4 -34 +13 +3 -13 -3 -4 +28 -28 +17 -17 +35 +10 -10 +16 +39 +36 +37 -37 -36 -39 +25 +6 +41 -41 +20 +12 +32 -32 -25 -12 -16 -35 +38 -20 -38 -14 +15 -15 +9 +26 +23 -21 -1 +7 -23 +22 +24 -7 -24 -42 -18 -22 -26 -9 -6 +27 +29 -29...

output:

GSGGGSGSSGGSSGGGGGGSGSSSGSGGGGGGGSGGGGGSGG

result:

ok correct

Test #8:

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

input:

42
+29 +6 +7 +2 -7 -2 +23 -23 -6 -29 +19 -19 +16 +8 -16 -8 +32 -32 +3 +37 +17 -17 -37 -3 +22 -22 +18 +1 +40 +36 -1 -36 -40 -18 +9 -9 +30 +25 -25 +14 +39 +5 +20 -5 +12 -39 +28 +10 -14 +24 -24 +35 +15 -15 +41 -30 +33 -33 -41 -35 -10 -28 -12 +21 +38 -38 -21 +11 +13 -13 +4 +42 +27 +34 -34 +31 -31 +26 -2...

output:

GGGGGGSGGSGSGGGSGGGSGGGGGGGSGGGGGGSSGGGSSG

result:

ok correct

Test #9:

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

input:

100
+39 -39 +4 +71 -71 +53 -53 +46 -46 -4 +91 -91 +97 -97 +6 -6 +54 -54 +76 +35 -35 +50 +89 -89 +98 -50 -76 -98 +34 +55 +95 -34 +36 -36 +73 -95 -55 +18 +47 +20 +30 +33 -30 -33 +80 -73 +51 -51 -80 -20 +69 +77 -69 +85 +62 +84 -84 -77 +48 +49 -49 +1 -1 -48 +19 -19 -62 -85 +41 +16 -16 -41 +63 +2 -2 +65 ...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGSGGGGGGGGGGGGGGGGGGGGSGG

result:

ok correct

Test #10:

score: 0
Accepted
time: 1ms
memory: 3984kb

input:

100
+5 -5 +61 +48 +60 +69 +7 -7 -69 -60 +45 -45 -48 -61 +68 +4 +82 +57 -57 +12 -12 +22 +46 -46 -22 +14 +30 -30 +47 -47 -14 +94 -94 -82 +44 +27 -27 -44 +86 -86 -4 +50 +15 -15 -50 -68 +58 -58 +28 +83 -83 -28 +53 +1 +56 -56 +67 +13 +73 +87 +19 +65 +18 -18 +17 -17 +89 +62 -62 -89 +72 -72 +25 -25 -65 +98...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG

result:

ok correct

Test #11:

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

input:

100
+96 +64 -64 +41 +11 +62 +18 +25 +3 +26 -26 -3 +22 +61 +59 +73 -59 -73 -61 -62 +20 -41 -20 +46 -46 -22 +2 +10 -10 -2 -25 -18 +9 -9 -11 +60 +33 +97 +38 -38 +5 -5 -97 +81 +29 -29 -81 +92 +1 +52 -52 +87 +19 -19 +90 -90 -87 -1 -92 -33 -60 -96 +47 +6 +72 -72 +79 +98 +45 -45 +23 -23 -98 +35 -35 +27 -27...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGG

result:

ok correct

Test #12:

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

input:

171
+118 +125 +156 +76 +123 +61 +107 +15 +160 -15 -107 -160 +98 +127 -127 +152 -61 -123 +48 +139 +86 -86 +43 +129 +164 +167 +6 +9 +137 +20 +16 -20 -16 +11 +12 +133 +24 -24 -137 -133 +81 +71 +88 +142 -142 +105 -88 +93 +33 -33 -105 +85 +64 -64 +150 +5 -150 +121 -85 +1 -121 +41 -5 +53 +67 +3 -3 +72 +10...

output:

GGGGSSGGSGGGGGGGSSGSSGGGSGGGGGGGGGSSSSSSGGGGGGSSGSGGGGSGSGSGGGGGGGGGGGGGGSGGSGGGGSGGGGGSSGGGSSGGSSSSGGSGGGGSGGGGGGGGSGSGSGGGSGGGGGGGGGGSSGSGSGGGSGGGGGGSSGGSGSSSGGGGGGSGSGG

result:

ok correct

Test #13:

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

input:

171
+47 -47 +50 -50 +108 +130 +146 -146 +76 +87 -87 -76 -108 -130 +158 -158 +161 -161 +133 -133 +63 +132 +144 -132 +61 +21 +109 -61 -109 -21 -144 +104 -63 +69 -69 +123 +110 -123 -104 +94 +20 +55 -55 -20 -94 -110 +64 +119 +103 +12 -103 +139 -139 +28 +72 +165 -72 +90 +67 +9 +107 +166 -166 -67 -90 -165...

output:

GGGGGGGGSGGSGGGGGGGGGGGGGGGSGGGGGGGGGSGGGGGGGGGSGGGGGGGGGGGGSGGSGSGGGGGSGGGGGGSGGGGGSGGSGGGGSGGGGGGGGGGSGGSGGGGGGSSGGSGGSGSGGGSGGSGGGGGGGGGGGGGSSGGSGGGGSSGGGGGGGGGGGGGGGGS

result:

ok correct

Test #14:

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

input:

171
+148 -148 +41 -41 +7 +113 -7 +28 +100 +92 -28 -92 -100 +46 -46 -113 +149 +67 +68 -68 +88 +150 +157 -157 -150 +161 +133 +171 -171 +103 -103 -133 +60 -60 +44 +4 -4 -44 +75 -75 -161 +116 -116 -88 -67 -149 +170 +160 +124 -124 +101 +163 +129 +78 -78 -129 -163 +43 -43 -101 -160 +71 -71 -170 +166 -166 ...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGSGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG

result:

ok correct

Test #15:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

666
+486 -486 +361 +23 +422 +664 +601 -601 -664 +85 +516 -85 +561 -561 +462 -516 -422 -462 +618 -618 -23 -361 +630 +189 +63 +520 -63 -189 +435 +172 -172 +535 +282 +44 -44 -282 -535 -520 -435 -630 +637 -637 +346 +336 -346 +624 +200 -200 +125 -125 -624 +187 +382 -187 +355 -336 +365 -365 +521 -521 -355...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGSSGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGSGGGGGGSSGGGGGGGGSGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...

result:

ok correct

Test #16:

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

input:

666
+596 +130 +656 +93 -130 +308 +537 +485 -308 +89 -89 +144 +40 -40 -485 +30 +510 +559 -559 +646 -510 +191 -191 +644 -644 +7 +553 +409 -646 -30 -537 +331 -409 -331 -553 -7 -596 +187 -187 -144 +517 +528 -517 -528 -93 -656 +420 +391 +61 -61 -391 +259 -259 -420 +282 +45 -45 +299 -299 -282 +625 +469 -4...

output:

GGGGGGGGGGGSGGGGGGGGSGSGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGSGGGGGGGGGGSGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGSGGSGGGGSGGGGGGGGGGGGGGSGGGGGG...

result:

ok correct

Test #17:

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

input:

666
+477 +406 -477 -406 +396 -396 +59 -59 +145 -145 +190 +426 +384 -426 +236 -236 +590 -384 +520 +132 -132 -520 -590 +218 +429 +382 -382 +664 -218 -664 +61 -61 -429 -190 +591 -591 +385 -385 +241 -241 +186 +294 -294 -186 +333 +13 -13 -333 +587 +465 -465 +275 -275 -587 +362 +123 +640 +305 +151 +350 -3...

output:

GGGGGGGSGSGGGSGGGGSGSGGGGGGGGGGGSGSGGGGGGGSGGGGGGGGSGGGGSGGGGGGSGGGGGGSGGGGGGGSSGSGGGGGGGGSGGGGGGGSGGSGGSGGGGGGGGGGSGGGGSGGGGGGGGGGGGSGGSGGGGGSGGGSGGGSGGGGSGGGGSSGSGGGGGGSGGGGSGGGGGGSGGGGGGGSGSGGGGGGGSGGGGGGGGGGSGSGGGGGSSGGGGGGGSGGSGGGGGGGGGGGGGGSGGGGGSGGGGGGGGGGSSGGSGGGGSGGGGGGGGGSGGSGSGGGGGGGGGSSS...

result:

ok correct

Test #18:

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

input:

1000
+478 -478 +298 +39 -39 +715 -298 +753 -753 -715 +718 -718 +547 +955 -547 -955 +787 -787 +22 -22 +71 +111 -111 -71 +442 +653 +690 -690 -653 +816 +130 +366 +441 -441 -366 -130 +950 -950 -816 +849 +423 +564 -564 +960 +294 +563 +360 -960 +24 +742 +979 +361 -361 -979 +452 +188 +500 +526 +77 -77 +373...

output:

GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGG...

result:

ok correct

Test #19:

score: 0
Accepted
time: 1ms
memory: 4000kb

input:

1000
+750 +840 -840 +962 -750 -962 +79 -79 +517 -517 +100 -100 +777 -777 +261 +442 +668 -442 -668 -261 +161 +421 -161 -421 +961 +221 +159 +933 -159 +304 +569 +201 -201 -569 -304 -933 -221 +987 +537 -961 +258 -258 +779 -779 +73 +480 -73 -480 -537 -987 +190 +472 +830 -472 -830 +863 -190 +188 +59 +464 ...

output:

GGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGSGGGGGGGSSGGGGGSGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGSGSSGGGGGGGGGGSGGGGGGGGGGSGGGGSSSGGSSGGGGGGGGGSGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGSGGGGGSGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGSGSGGGGGGGSGGGGGGGGGGSGGGGSGGGGGSGSSGGGSGGGSGGSSGGGGGGSGGGGGGGGGSGGSGGGGGGGGGGGSGGGGGSGGGGGSGSGGGG...

result:

ok correct

Test #20:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

1000
+358 +199 +801 -801 -199 -358 +761 -761 +781 -781 +93 -93 +638 -638 +159 -159 +175 -175 +622 +558 -622 -558 +993 -993 +164 +537 +862 -862 +948 +838 +742 -537 -742 -838 +594 -948 -594 -164 +498 -498 +412 -412 +832 -832 +420 -420 +805 +821 -821 -805 +377 +699 -377 -699 +775 +256 -775 -256 +577 -5...

output:

GGGGGGGGGGGGGGGGSSGGSGGSGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGSGGSGGSGGGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGGGGGGGGSGGGGGGSGGGGSGGGGGGGGGGGGGGGGSGGGGGSSGGGGGGGSGGGGGGGSGGGGGGSSGGGGGSSGGGGGGGGGSGGGGGGSGGGGGGGGSGGSGGGGGGGGGGGGGSGGGGGGGGGGGGSGGGGGGGGGGGGGGGGGSGGSGGGGGGGGGGGGGSGGGGGGGGGGGGSGGG...

result:

ok correct

Test #21:

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

input:

13
+7 -7 +4 -4 +3 +10 +5 -10 -3 +12 +6 +2 -2 +8 +1 -5 -1 +9 +13 -6 +11 -13 -12 -11 -9 -8

output:

*

result:

ok correct

Test #22:

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

input:

13
+6 +5 -6 +4 +10 -4 -10 -5 +12 -12 +9 +3 -9 +11 -3 +13 -13 +7 -7 -11 +2 +8 -2 -8 +1 -1

output:

GGGGGSGSSSSGG

result:

ok correct

Test #23:

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

input:

77
+29 -29 +12 +51 +66 +33 -12 +46 -66 +69 -69 +49 -33 -49 -46 -51 +60 +22 +25 -60 -25 +74 -22 +71 +52 -71 -52 -74 +9 -9 +31 -31 +64 -64 +77 +17 +57 -57 +20 +55 +62 +48 -77 -20 -62 +30 -48 +68 +3 -17 -30 -3 -55 +41 +6 +19 -6 -68 -19 +43 -43 -41 +72 -72 +28 -28 +59 +34 +65 -34 -65 +4 +53 +39 -53 -4 -...

output:

*

result:

ok correct

Test #24:

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

input:

77
+53 +45 +19 +15 -45 +6 -53 +72 +58 -58 +11 -15 -6 +37 +66 +4 +49 +5 -37 -19 +7 +69 +46 +57 -69 +55 +73 -72 +56 +38 +26 -38 -66 +1 -7 +67 -49 -26 +36 -4 -73 -36 -5 -46 +59 +31 +18 -56 +12 -55 -59 -18 +13 +40 -11 +3 -1 +54 +32 +48 +70 +76 -32 +74 -48 -12 +33 -40 -76 +22 -13 +51 -74 -57 -3 +27 -67 +...

output:

*

result:

ok correct

Test #25:

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

input:

77
+2 -2 +18 -18 +74 +44 +17 +52 +65 +32 -32 -44 +57 -74 +27 -65 +68 -68 +54 -57 -54 +7 +34 +71 +22 -27 -34 -7 +21 -17 -52 -22 -21 -71 +39 +59 +5 +42 +40 +9 -5 +10 +61 +23 +64 -39 +24 -10 +43 +33 +62 +25 +11 -11 -64 +37 +51 +58 -25 -51 -37 +72 -33 -59 -9 -40 -61 -42 -23 +16 -72 -58 +19 -16 +75 +60 -...

output:

*

result:

ok correct

Test #26:

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

input:

121
+9 -9 +113 +72 -113 +41 +53 +23 -23 -53 +69 +116 -69 -72 +75 -41 -116 +43 -75 -43 +110 +7 -7 -110 +90 +120 -90 +29 +56 -56 +92 -29 +94 -94 -92 +27 -120 +21 -27 -21 +36 +55 -55 +30 -36 -30 +121 +16 -121 -16 +73 +47 -73 -47 +4 -4 +19 +104 +50 +58 +109 -109 -58 -50 +102 -19 +45 +83 +77 -104 +28 +39...

output:

*

result:

ok correct

Test #27:

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

input:

121
+97 -97 +11 -11 +112 -112 +35 -35 +55 +67 -55 +102 +121 +86 -86 -121 -102 -67 +18 +73 -73 -18 +59 +30 -30 +19 -19 -59 +62 +83 +34 -83 -34 +36 -36 -62 +116 -116 +54 +69 -69 +93 +96 -54 +74 +79 -93 -79 +119 +39 -119 +70 +9 +61 -9 +53 +25 -53 +51 -61 -96 -39 +109 +75 -70 -51 +82 +108 +58 +4 +50 -10...

output:

*

result:

ok correct

Test #28:

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

input:

474
+447 -447 +246 -246 +452 -452 +380 +384 +33 +38 -38 -380 -384 +130 +383 +352 +167 +386 -352 +244 -386 -244 +373 +162 +268 +195 +453 +126 -373 +409 +449 +207 +88 +438 +232 -409 -195 +367 +5 -126 +218 +54 +205 +238 +103 +63 +194 +193 +337 +315 +272 -232 -449 -54 +282 -103 +299 -268 +296 +395 +10 -...

output:

*

result:

ok correct

Test #29:

score: 0
Accepted
time: 1ms
memory: 4012kb

input:

474
+415 +365 -415 +326 +77 +441 +305 +17 -441 -17 -326 -365 +338 +456 -456 +158 -338 +18 -77 +332 +388 +199 -332 +387 -305 -388 +242 +245 -387 +319 -245 -319 +135 +300 +427 +268 +146 +310 +152 +299 -18 -427 -158 -199 +80 -268 -242 +397 +254 -254 +100 -100 +372 +423 +215 +27 -372 +298 -423 +163 +195...

output:

*

result:

ok correct

Test #30:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

474
+357 -357 +226 -226 +466 -466 +400 +431 -400 -431 +229 -229 +286 -286 +105 +49 +470 +267 -470 -267 +450 -105 -49 -450 +249 +325 +149 +253 +25 +188 +83 +117 +48 -83 -188 -149 -253 +90 -90 -325 +382 +282 +63 +432 -63 +381 +339 +136 +449 +425 +202 -202 -25 +280 +66 +379 -280 +463 +145 -425 +168 -14...

output:

*

result:

ok correct

Test #31:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

737
+543 +552 -552 -543 +341 -341 +456 -456 +549 -549 +423 -423 +35 -35 +101 +715 -101 -715 +430 -430 +449 -449 +559 +229 +262 -559 +573 +409 -409 +644 +353 -644 -262 +237 -237 -229 +477 -353 +149 -477 +21 +345 -149 +618 -618 +698 +643 +292 -698 -292 +377 +395 +659 +356 +166 -377 -345 -166 +220 +584...

output:

*

result:

ok correct

Test #32:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

737
+229 +89 +541 -229 +71 +303 -303 -71 -541 +522 -89 -522 +393 +26 +55 +8 -26 +429 +36 -393 +238 -36 -8 +709 -429 +589 -238 +266 +379 +328 -379 -55 -589 -709 +641 -328 +724 -266 -724 +602 +412 +199 +270 +347 +169 +191 -602 +673 +206 +659 -347 +411 +158 -206 -673 +39 +615 +695 -695 +530 -169 -39 -6...

output:

*

result:

ok correct

Test #33:

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

input:

999
+119 -119 +10 -10 +480 +652 -480 +849 +215 -652 +106 +275 -275 +179 +309 +911 +950 +973 +730 +699 +585 +453 -730 -849 +285 +76 +641 -285 +977 +41 -641 -950 -585 -179 +773 -973 -911 +954 +292 -977 +318 -106 -773 +461 -309 +948 -948 -41 +619 -699 +181 +294 -181 -453 -619 -954 +334 +116 +546 +584 +...

output:

*

result:

ok correct

Test #34:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

999
+936 -936 +284 +337 -337 +686 +556 -686 -556 +297 +258 -297 +315 -284 -315 +180 +404 +239 +273 +21 -180 +888 -888 -404 -258 +455 -21 +119 -239 +75 -75 +921 +234 -273 +41 -119 -41 +743 +574 +449 +982 +635 +844 -449 -234 +111 +275 +739 +715 +758 -275 -455 -844 -574 +238 +821 +68 -111 -982 +359 -82...

output:

*

result:

ok correct

Test #35:

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

input:

999
+32 +641 +255 -32 -641 +203 -203 +576 +605 -576 +618 -605 -618 +801 -801 -255 +217 -217 +365 +103 -103 +362 -365 -362 +910 -910 +619 +223 +450 +379 -223 -619 +948 +685 -948 +503 -379 +703 -703 +597 -685 +655 +686 +638 +10 -597 +358 +850 +433 -850 +930 -655 +929 -358 +690 +682 +725 -930 -690 -638...

output:

*

result:

ok correct

Test #36:

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

input:

4
+1 +4 +2 +3 -4 -3 -1 -2

output:

GSSG

result:

ok correct

Test #37:

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

input:

4
+1 +4 +2 +3 -4 -3 -1 -2

output:

GSSG

result:

ok correct

Test #38:

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

input:

8
+1 +4 +2 +3 -4 -3 -1 -2 +6 +8 +5 +7 -8 -7 -5 -6

output:

GSSGGGGS

result:

ok correct

Test #39:

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

input:

8
+2 +1 +3 +4 -3 -1 -4 -2 +6 +5 +7 +8 -7 -5 -8 -6

output:

GGGSGGGS

result:

ok correct

Test #40:

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

input:

996
+1 +4 +2 +3 -4 -3 -1 -2 +5 +8 +6 +7 -8 -7 -5 -6 +10 +9 +11 +12 -11 -9 -12 -10 +13 +16 +14 +15 -16 -15 -13 -14 +18 +17 +19 +20 -19 -18 -20 -17 +22 +24 +21 +23 -24 -23 -21 -22 +26 +28 +25 +27 -28 -27 -25 -26 +30 +29 +31 +32 -31 -29 -32 -30 +33 +36 +34 +35 -36 -35 -33 -34 +37 +40 +38 +39 -40 -39 -3...

output:

GSSGGSSGGGGSGSSGGSSGGGGSGGGSGGGSGSSGGSSGGSSGGGGSGSSGGSSGGSSGGGGSGGGSGGGSGSSGGGGSGGGSGGGSGGGSGSSGGSSGGSSGGGGSGGGSGSSGGSSGGGGSGSSGGSSGGSSGGGGSGSSGGGGSGGGSGSSGGGGSGGGSGSSGGSSGGGGSGGGSGSSGGGGSGSSGGGGSGGGSGSSGGGGSGGGSGSSGGSSGGGGSGSSGGSSGGSSGGGGSGGGSGSSGGGGSGGGSGSSGGGGSGGGSGSSGGSSGGGGSGGGSGSSGGGGSGGGSGGGS...

result:

ok correct

Test #41:

score: 0
Accepted
time: 1ms
memory: 3748kb

input:

996
+2 +1 +3 +4 -3 -1 -4 -2 +6 +5 +7 +8 -7 -5 -8 -6 +10 +9 +11 +12 -11 -10 -12 -9 +14 +13 +15 +16 -15 -14 -16 -13 +18 +17 +19 +20 -19 -17 -20 -18 +22 +21 +23 +24 -23 -21 -24 -22 +26 +25 +27 +28 -27 -26 -28 -25 +30 +29 +31 +32 -31 -29 -32 -30 +33 +36 +34 +35 -36 -35 -33 -34 +38 +37 +39 +40 -39 -38 -4...

output:

GGGSGGGSGSSGGSSGGGGSGGGSGSSGGGGSGSSGGSSGGGGSGSSGGGGSGGGSGSSGGSSGGSSGGGGSGGGSGSSGGSSGGGGSGGGSGGGSGGGSGSSGGSSGGSSGGSSGGGGSGSSGGSSGGSSGGSSGGSSGGGGSGGGSGSSGGGGSGGGSGGGSGSSGGSSGGGGSGGGSGSSGGSSGGGGSGSSGGSSGGSSGGSSGGSSGGSSGGSSGGSSGGGGSGSSGGSSGGSSGGSSGGSSGGSSGGSSGGGGSGSSGGGGSGGGSGSSGGGGSGGGSGSSGGGGSGSSGGGGS...

result:

ok correct

Test #42:

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

input:

1000
+2 +4 +1 +3 -4 -3 -1 -2 +5 +8 +6 +7 -8 -7 -5 -6 +10 +12 +9 +11 -12 -11 -9 -10 +13 +16 +14 +15 -16 -15 -13 -14 +17 +20 +18 +19 -20 -19 -17 -18 +22 +24 +21 +23 -24 -23 -21 -22 +26 +25 +27 +28 -27 -25 -28 -26 +30 +29 +31 +32 -31 -30 -32 -29 +34 +33 +35 +36 -35 -33 -36 -34 +37 +40 +38 +39 -40 -39 -...

output:

GGGSGSSGGGGSGSSGGSSGGGGSGGGSGSSGGGGSGSSGGSSGGGGSGGGSGSSGGGGSGSSGGSSGGSSGGGGSGGGSGSSGGSSGGGGSGSSGGSSGGGGSGGGSGGGSGSSGGGGSGGGSGGGSGGGSGSSGGSSGGGGSGSSGGGGSGGGSGSSGGGGSGGGSGGGSGSSGGSSGGGGSGSSGGSSGGGGSGGGSGSSGGSSGGGGSGSSGGSSGGSSGGSSGGSSGGSSGGSSGGSSGGGGSGSSGGGGSGGGSGSSGGGGSGGGSGGGSGSSGGSSGGGGSGGGSGSSGGGGS...

result:

ok correct

Test #43:

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

input:

1000
+1 +4 +2 +3 -4 -3 -1 -2 +6 +5 +7 +8 -7 -5 -8 -6 +10 +9 +11 +12 -11 -10 -12 -9 +13 +16 +14 +15 -16 -15 -13 -14 +18 +17 +19 +20 -19 -18 -20 -17 +21 +24 +22 +23 -24 -23 -21 -22 +25 +28 +26 +27 -28 -27 -25 -26 +30 +29 +31 +32 -31 -29 -32 -30 +34 +36 +33 +35 -36 -35 -33 -34 +38 +37 +39 +40 -39 -38 -...

output:

GSSGGGGSGSSGGSSGGSSGGSSGGSSGGGGSGGGSGSSGGGGSGGGSGGGSGSSGGSSGGGGSGGGSGSSGGGGSGSSGGGGSGSSGGSSGGSSGGSSGGSSGGGGSGGGSGSSGGGGSGSSGGSSGGGGSGGGSGSSGGGGSGGGSGGGSGSSGGSSGGGGSGGGSGSSGGSSGGSSGGSSGGGGSGSSGGGGSGGGSGSSGGSSGGSSGGGGSGSSGGGGSGSSGGGGSGSSGGGGSGSSGGSSGGGGSGSSGGGGSGGGSGGGSGGGSGSSGGGGSGSSGGSSGGSSGGSSGGSSG...

result:

ok correct

Extra Test:

score: 0
Extra Test Passed