結果

問題 No.201 yukicoderじゃんけん
コンテスト
ユーザー zeta
提出日時 2026-03-05 09:11:29
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 36,749 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,078 ms
コンパイル使用メモリ 329,712 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-05 09:12:32
合計ジャッジ時間 5,824 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#line 1 "No_201_yukicoder\u3058\u3083\u3093\u3051\u3093.cpp"
#define YRSD
#line 2 "YRS/all.hpp"

#line 2 "YRS/aa/head.hpp"

#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <bit>
#include <chrono>
#include <functional>
#include <iomanip>
#include <utility>
#include <type_traits>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <limits>
#include <ranges>
#include <concepts>

#define TE template <typename T>
#define TES template <typename T, typename ...S>
#define Z auto
#define ep emplace_back
#define eb emplace
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

#define ov(a, b, c, d, e, ...) e
#define FO1(a) for (int _ = 0; _ < (a); ++_)
#define FO2(i, a) for (int i = 0; i < (a); ++i)
#define FO3(i, a, b) for (int i = (a); i < (b); ++i)
#define FO4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define FOR(...) ov(__VA_ARGS__, FO4, FO3, FO2, FO1)(__VA_ARGS__)
#define FF1(a) for (int _ = (a) - 1; _ >= 0; --_)
#define FF2(i, a) for (int i = (a) - 1; i >= 0; --i)
#define FF3(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define FF4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define FOR_R(...) ov(__VA_ARGS__, FF4, FF3, FF2, FF1)(__VA_ARGS__)
#define FOR_subset(t, s) for (int t = (s); t > -1; t = (t == 0 ? -1 : (t - 1) & s))

#define sort ranges::sort

using namespace std;

TE using vc = vector<T>;
TE using vvc = vc<vc<T>>;
TE using T1 = tuple<T>;
TE using T2 = tuple<T, T>;
TE using T3 = tuple<T, T, T>;
TE using T4 = tuple<T, T, T, T>;
TE using max_heap = priority_queue<T>;
TE using min_heap = priority_queue<T, vc<T>, greater<T>>;
using u8 = unsigned char; using uint = unsigned int; using ll = long long;      using ull = unsigned long long;
using ld = long double;   using i128 = __int128;     using u128 = __uint128_t;  using f128 = __float128;
using u16 = uint16_t;
using PII = pair<int, int>;   using PLL = pair<ll, ll>;

#ifdef YRSD
constexpr bool dbg = 1;
#else
constexpr bool dbg = 0;
#endif
#line 2 "YRS/IO/IO.hpp"

istream &operator>>(istream &I, i128 &x) {
  static string s;
  I >> s;
  int f = s[0] == '-';
  x = 0;
  const int N = (int)s.size();
  FOR(i, f, N) x = x * 10 + s[i] - '0';
  if (f) x = -x;
  return I;
}
ostream &operator<<(ostream &O, i128 x) {
  static string s;
  s.clear();
  bool f = x < 0;
  if (f) x = -x;
  while (x) s += '0' + x % 10, x /= 10;
  if (s.empty()) s += '0';
  if (f) s += '-';
  reverse(all(s));
  return O << s;
}
istream &operator>>(istream &I, f128 &x) {
  static string s;
  I >> s, x = stold(s);
  return I;
}
ostream &operator<<(ostream &O, const f128 x) { return O << ld(x); }
template <typename... S>
istream &operator>>(istream &I, tuple<S...> &t) {
  return apply([&I](Z &...s) { ((I >> s), ...); }, t), I;
}
template <typename T, typename U>
istream &operator>>(istream &I, pair<T, U> &x) {
  return I >> x.fi >> x.se;
}
template <typename T, typename U>
ostream &operator<<(ostream &O, const pair<T, U> &x) {
  return O << x.fi << ' ' << x.se;
}
TE requires requires(T &c) { begin(c); end(c); } and 
                          (not is_same_v<decay_t<T>, string>)
istream &operator>>(istream &I, T &c) {
  for (Z &e : c) I >> e;
  return I;
}
TE requires requires(const T &c) { begin(c); end(c); } and 
  (not is_same_v<decay_t<T>, const char*>) and 
  (not is_same_v<decay_t<T>, string>) and 
  (not is_array_v<remove_reference_t<T>> or 
   not is_same_v<remove_extent_t<remove_reference_t<T>>, char>)
ostream &operator<<(ostream &O, const T &a) {
  if (a.empty()) return O;
  Z i = a.begin();
  O << *i++;
  for (; i != a.end(); ++i) O << ' ' << *i;
  return O;
}
void IN() {}
TE void IN(T &x, Z &...s) { cin >> x, IN(s...); }
void print() { cout << '\n'; }
TES void print(T &&x, S &&...y) {
  cout << x;
  if constexpr (sizeof...(S)) cout << ' ';
  print(forward<S>(y)...);
}
void put() {}
TES void put(T &&x, S &&...y) {
  cout << x;
  put(forward<S>(y)...);
}

#define INT(...)  int    __VA_ARGS__; IN(__VA_ARGS__)
#define UINT(...) uint   __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...)   ll     __VA_ARGS__; IN(__VA_ARGS__)
#define ULL(...)  ull    __VA_ARGS__; IN(__VA_ARGS__)
#define I128(...) i128   __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...)  string __VA_ARGS__; IN(__VA_ARGS__)
#define CH(...)   char   __VA_ARGS__; IN(__VA_ARGS__)
#define REAL(...) re     __VA_ARGS__; IN(__VA_ARGS__)
#define VEC(T, a, n) vc<T> a(n); IN(a)

void YES(bool o = 1) { print(o ? "YES" : "NO"); }
void Yes(bool o = 1) { print(o ? "Yes" : "No"); }
void yes(bool o = 1) { print(o ? "yes" : "no"); }
void NO(bool o = 1) { YES(not o); }
void No(bool o = 1) { Yes(not o); }
void no(bool o = 1) { yes(not o); }
void ALICE(bool o = 1) { print(o ? "ALICE" : "BOB"); }
void Alice(bool o = 1) { print(o ? "Alice" : "Bob"); }
void alice(bool o = 1) { print(o ? "alice" : "bob"); }
void BOB(bool o = 1) { ALICE(not o); }
void Bob(bool o = 1) { Alice(not o); }
void bob(bool o = 1) { alice(not o); }
void POSSIBLE(bool o = 1) { print(o ? "POSSIBLE" : "IMPOSSIBLE"); }
void Possible(bool o = 1) { print(o ? "Possible" : "Impossible"); }
void possible(bool o = 1) { print(o ? "possible" : "impossible"); }
void IMPOSSIBLE(bool o = 1) { POSSIBLE(not o); }
void Impossible(bool o = 1) { Possible(not o); }
void impossible(bool o = 1) { possible(not o); }
void TAK(bool o = 1) { print(o ? "TAK" : "NIE"); }
void NIE(bool o = 1) { TAK(not o); }
#line 5 "YRS/all.hpp"

#if (__cplusplus >= 202002L)
#include <numbers>
constexpr ld pi = numbers::pi_v<ld>;
#endif
TE constexpr T inf = numeric_limits<T>::max();
template <> constexpr i128 inf<i128> = i128(inf<ll>) * 2'000'000'000'000'000'000;
template <typename T, typename U>
constexpr pair<T, U> inf<pair<T, U>> = {inf<T>, inf<U>};

TE constexpr static inline int pc(T x) { return popcount(make_unsigned_t<T>(x)); }
constexpr static inline ll len(const Z &a) { return a.size(); }

void reverse(Z &a) { reverse(all(a)); }

void unique(Z &a) {
  sort(a);
  a.erase(unique(all(a)), a.end());
}
TE vc<int> inverse(const vc<T> &a) {
  int N = len(a);
  vc<int> b(N, -1);
  FOR(i, N) if (a[i] != -1) b[a[i]] = i;
  return b;
}

Z QMAX(const Z &a) { return *max_element(all(a)); }
Z QMIN(const Z &a) { return *min_element(all(a)); }
TE Z QMAX(T l, T r) { return *max_element(l, r); }
TE Z QMIN(T l, T r) { return *min_element(l, r); }
constexpr bool chmax(Z &a, const Z &b) { return (a < b ? a = b, 1 : 0); }
constexpr bool chmin(Z &a, const Z &b) { return (a > b ? a = b, 1 : 0); }

vc<int> argsort(const Z &a) {
  vc<int> I(len(a));
  iota(all(I), 0);
  sort(I, [&](int i, int k) { return a[i] < a[k] or (a[i] == a[k] and i < k); });
  return I;
}
TE vc<T> rearrange(const vc<T> &a, const vc<int> &I) {
  int N = len(I);
  vc<T> b(N);
  FOR(i, N) b[i] = a[I[i]];
  return b;
}
template <int of = 1, typename T> 
vc<T> pre_sum(const vc<T> &a) {
  int N = len(a);
  vc<T> c(N + 1);
  FOR(i, N) c[i + 1] = c[i] + a[i];
  if (of == 0) c.erase(c.begin());
  return c;
}

TE constexpr static int topbit(T x) {
  if (x == 0) return - 1;
  if constexpr (sizeof(T) <= 4) return 31 - __builtin_clz(x);
  else return 63 - __builtin_clzll(x);
}
TE constexpr static int lowbit(T x) {
  if (x == 0) return -1;
  if constexpr (sizeof(T) <= 4) return __builtin_ctz(x);
  else return __builtin_ctzll(x);
}

TE constexpr T floor(T x, T y) { return x / y - (x % y and (x ^ y) < 0); }
TE constexpr T ceil(T x, T y) { return floor(x + y - 1, y); }
TE constexpr T bmod(T x, T y) { return x - floor(x, y) * y; }
TE constexpr pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return pair{q, x - q * y};
}
template <typename T = ll>
T SUM(const Z &v) {
  return accumulate(all(v), T(0));
}
int lb(const Z &a, Z x) { return lower_bound(all(a), x) - a.begin(); }
TE int lb(T l, T r, Z x) { return lower_bound(l, r, x) - l; }
int ub(const Z &a, Z x) { return upper_bound(all(a), x) - a.begin(); }
TE int ub(T l, T r, Z x) { return upper_bound(l, r, x) - l; }

template <bool ck = 1>
ll bina(Z f, ll l, ll r) {
  if constexpr (ck) assert(f(l));
  while (abs(l - r) > 1) {
    ll x = (r + l) >> 1;
    (f(x) ? l : r) = x;
  }
  return l;
}
TE T bina_real(Z f, T l, T r, int c = 100) {
  while (c--) {
    T x = (l + r) / 2;
    (f(x) ? l : r) = x;
  }
  return (l + r) / 2;
}

Z pop(Z &s) {
  if constexpr (requires { s.pop_back(); }) {
    Z x = s.back();
    return s.pop_back(), x;
  } else if constexpr (requires { s.top(); }) {
    Z x = s.top();
    return s.pop(), x;
  } else {
    Z x = s.front();
    return s.pop(), x;
  }
}
void setp(int x) { cout << fixed << setprecision(x); }

TE inline void sh(vc<T> &a, int N, T b = {}) {
  a.resize(N, b);
}
#line 1 "YRS/debug.hpp"
#ifdef YRSD
void DBG() { cerr << "]" << endl; }
TES void DBG(T &&x, S &&...y) {
  cerr << x;
  if constexpr (sizeof...(S)) cerr << ", ";
  DBG(forward<S>(y)...);
}
#define debug(...) cerr << "[" << __LINE__ << "]: [" #__VA_ARGS__ "] = [", DBG(__VA_ARGS__)
void ERR() { cerr << endl; }
TES void ERR(T &&x, S &&...y) {
  cerr << x;
  if constexpr (sizeof...(S)) cerr << ", ";
  ERR(forward<S>(y)...);
}
#define err(...) cerr << "[" << __LINE__ << "]: ", ERR(__VA_ARGS__)
#define asser assert
#else
#define debug(...) void(0721)
#define err(...)   void(0721)
#endif
#line 2 "YRS/nt/bigint/big.hpp"

#line 2 "YRS/poly/c/bs.hpp"

#line 2 "YRS/poly/c/fps_t.hpp"

#line 2 "YRS/mod/mint_t.hpp"

#define c constexpr
template <int mod>
struct mint_t {
  using T = mint_t;
  static c uint m = mod;
  uint x;

  c inline uint val() const { return x; }

  c mint_t() : x(0) {}
  c mint_t(uint x) : x(x % m) {}
  c mint_t(ull x) : x(x % m) {}
  c mint_t(u128 x) : x(x % m) {}
  c mint_t(int x) : x((x %= mod) < 0 ? x + mod : x) {}
  c mint_t(ll x) : x((x %= mod) < 0 ? x + mod : x) {}
  c mint_t(i128 x) : x((x %= mod) < 0 ? x + mod : x) {}

  c T &operator+=(T p) {
    if ((x += p.x) >= m) x -= m;
    return *this;
  }
  c T &operator-=(T p) {
    if ((x += m - p.x) >= m) x -= m;
    return *this;
  }
  c T operator+(T p) const { return T(*this) += p; }
  c T operator-(T p) const { return T(*this) -= p; }

  c T &operator*=(T p) {
    x = ull(x) * p.x % m;
    return *this;
  }
  c T operator*(T p) const { return T(*this) *= p; }

  c T &operator/=(T p) { return *this *= p.inv(); }
  c T operator/(T p) const { return T(*this) /= p; }

  c T operator-() const { return T::gen(x ? mod - x : 0); }

  c T inv() const {
    int a = x, b = mod, x = 1, y = 0;
    while (b > 0) {
      int t = a / b;
      swap(a -= t * b, b);
      swap(x -= t * y, y);
    }
    return T(x);
  }

  c T pow(ll k) const {
    if (k < 0) return inv().pow(-k);
    T s(1), a(x);
    for (; k; k >>= 1, a *= a)
      if (k & 1) s *= a;
    return s;
  }

  c bool operator<(T p) const { return x < p.x; }
  c bool operator==(T p) const { return x == p.x; }
  c bool operator!=(T p) const { return x != p.x; }

  static c T gen(uint x) {
    T s;
    s.x = x;
    return s;
  }

  friend istream &operator>>(istream &cin, T &p) {
    ll t;
    cin >> t;
    p = t;
    return cin;
  }
  
  friend ostream &operator<<(ostream &cout, T p) { return cout << p.x; }

  static c int get_mod() { return mod; }

  static c PII ntt_info() {
    if (mod == 167772161) return {25, 17};
    if (mod == 469762049) return {26, 30};
    if (mod == 754974721) return {24, 362};
    if (mod == 998244353) return {23, 31};
    if (mod == 120586241) return {20, 74066978};
    if (mod == 880803841) return {23, 211};
    if (mod == 943718401) return {22, 663003469};
    if (mod == 1004535809) return {21, 582313106};
    if (mod == 1012924417) return {21, 368093570};
    return {-1, -1};
  }
  
  static c bool can_ntt() { return ntt_info().fi != -1; }
};
#undef c

using M99 = mint_t<998244353>;
using M17 = mint_t<1000000007>;

#ifdef FIO
template <int mod>
void rd(mint_t<mod> &x) {
  LL(y);
  x = y;
}
template <int mod>
void wt(mint_t<mod> x) {
  wt(x.x);
}
#endif
#line 4 "YRS/poly/c/fps_t.hpp"

// 动态模数需要在 设置模数后 进行构造
TE struct fps_t {
  using fps = vc<T>;
  using cf = const fps &;
  static inline const uint p = T::get_mod(), t = T::ntt_info().fi,
                           r = T::ntt_info().se;
  static inline const ull M = ull(p) * p;
  // 需要动态模数反复set mod的啥比题到底是谁在出
  // static inline uint p = T::get_mod(), t = T::ntt_info().fi,
  //                    r = T::ntt_info().se;
  // static inline ull M = ull(p) * p;
  // static void reset() {
  //   p = T::get_mod();
  //   tie(t, r) = T::ntt_info();
  //   M = ull(p) * p;
  // }

  fps fa{1, 1}, ifa{1, 1}, in{0, 1};
  T inv(int);
  T fac(int);
  T ifac(int);
  T C(int, int);
  
  static constexpr int p0 = 167'772'161, p1 = 469'762'049, p2 = 754'974'721;
  using f0 = fps_t<mint_t<p0>>;
  using f1 = fps_t<mint_t<p1>>;
  using f2 = fps_t<mint_t<p2>>;

  static void sh(fps &, int);
  static int count_terms(cf);

  static T eval(cf, T);

  T crt(ull, ull, ull);
  u128 crt_128(ull, ull, ull);

  static void ntr(T *, T *, T *, T *, T *, T *);
  static void ntt(fps &, bool);
  static void trans_ntt(fps &, bool);
  static void ntt_db(fps &f, bool = 0);

  fps conv_naive(cf, cf);
  fps conv_kara(cf, cf);
  static fps conv_ntt(fps, fps);
  fps conv_mtt(cf, cf);
  fps conv(cf, cf);
  vc<int> conv_for_big(const vc<int> &, const vc<int> &);

  static fps sq_ntt(fps);
  fps sq_mtt(cf);
  fps sq(cf);

  fps diff(cf);
  fps inte(cf);
  T inte(cf, T, T);

  fps mid_prod(cf, cf);

  fps inv_sp(cf);
  fps inv_ntt(cf);
  fps inv_mtt(cf);
  fps inv(cf);

  fps div_sp(fps, fps);
  fps div_ntt(cf, cf);
  fps div_mtt(fps, fps);
  fps div_dense(cf, cf);
  fps div(cf, cf);

  fps log_sp(cf);
  fps log_dense(cf);
  fps log(cf);

  fps exp_sp(cf);
  fps exp_ntt(cf);
  fps exp_mtt(cf);
  fps exp_dense(cf);
  fps exp(cf);

  fps pw_sp(cf, T);
  fps pw_dense(cf, T);
  fps pw(cf, T);
  fps pow(cf, ll);

  fps sqr_sp(cf);
  fps sqr_ntt(cf);
  fps sqr_dense(cf);
  fps sqr(cf);
  fps sqrt(cf);

  fps conv_all(const vc<fps> &);
  fps conv_all(fps);

  fps eval_geo(fps, T, T, int);
  fps inte_geo(fps, T, T);
  struct subprod_t;
  subprod_t subprod(cf);
  fps eval_ntt(fps, fps);
  fps eval(fps, fps);
  fps inte(fps, fps);

  fps shift(fps, T);

  T lag(cf, T);
  fps lag(cf, T, int);
  T lag(cf, cf, T);

  fps pow_proj_ntt(fps, fps, int);
  fps pow_proj(fps, fps, int);

  fps comp_slow(cf, cf);
  fps comp_ntt(fps, fps);
  fps comp_mtt(fps, fps);
  fps comp(fps, fps);
  fps comp_inv(fps);

  pair<fps, fps> divmod(fps, cf);
  fps modpow(cf, ll, cf);

  fps prod_of_f_rk_x(fps, T, int);
  fps prod_of_one_minus_xn(const vc<int> &, int);
  fps prod_of_inv_one_minus_xn(const vc<int> &, int);
  fps prod_of_one_plus_xn(const vc<int> &a, int);
  fps prod_of_inv_one_plus_xn(const vc<int> &a, int);

  pair<fps, fps> sum_of_rationals(vc<pair<fps, fps>>);
  pair<fps, fps> sum_of_rationals_sp(cf, cf);
  fps sum_of_exp_bx(cf, cf, int);
  fps sum_of_pow(cf, int);
  fps sum_of_pow(ll, ll, int);
  fps sum_of_pow(cf, cf, int);
  fps sum_of_binomail(fps, T, T);

  fps subset_sum(const vc<int> &, int k);
  fps subset_sum_lm(const vc<int> &, int k);

  T coef_of_rationals_ntt(fps, fps, ll);
  T coef_of_rationals_mtt(fps, fps, ll);
  T coef_of_rationals(fps, fps, ll);

  fps find_line(cf);
  T line_inte(cf a, ll N);

  template <int>
  struct fac_t;
  template <int lg = 10>
  fac_t<lg> fac_large();

  fps p_to_ffp(cf);
  fps ffp_to_p(cf);
  fps ffp_conv_ntt(fps, fps);
  fps ffp_conv_mtt(fps, fps);
  fps ffp_conv(cf, cf);

  fps sin(cf);
  fps cos(cf);
  fps asin(cf);
  fps atan(cf);

  fps comp_f_ex(cf);
  fps comp_f_1_minus_ex(cf);
  fps comp_f_ex_minus_1(cf);
  fps comp_f_a_plus_bx(cf, T, T);
  fps comp_f_aplusbx_div_cplusdx_fake(cf, T, T, T, T);
  fps comp_f_aplusbx_div_cplusdx(cf, T, T, T, T);
  fps comp_f_x_plus_1_divx(cf);

  struct conv_t;
  conv_t online_conv();
  struct exp_t;
  exp_t online_exp();
  struct log_t;
  log_t online_log();
  struct inv_t;
  inv_t online_inv();
  struct div_t;
  div_t online_div();
  struct pow_t;
  pow_t online_pow(T);

  fps presum(cf, T);

  fps sinh(int);
  fps exp_x(int);
  fps exp_invx(int);
  fps E_S(int);
  fps E(int);
  fps E_n(int, int);
  fps E_odd(int);
  fps E_noempty(int);
  fps C_R(int);

  fps bell(int);
  fps derange(int);
  fps bernoulli(int);
  fps partition(int);

  fps count_label_dag(int);
  fps count_label_dag_con(int);
  fps count_label_undir(int);
  fps count_label_undir_con(int);
  fps count_label_unicycle(int);
  fps count_label_bipartite(int, bool);
  fps count_label_bcc_v(int);
  T count_label_bcc_v_N(int);
  fps count_label_bcc_e(int);
  T count_label_bcc_e_N(int);
  T count_label_tournament(int);
  fps count_label_scc(int);
  fps count_label_euler_undir(int);
  fps count_label_tree(int);
  fps count_unlabel_tree(int);
};
#line 4 "YRS/poly/c/bs.hpp"

TE Z fps_t<T>::inv(int n) -> T {
  assert(0 <= n);
  while (len(in) <= n) {
    int k = len(in), q = (p + k - 1) / k, r = k * q - p;
    in.ep(in[r] * T(q));
  }
  return in[n];
}

TE Z fps_t<T>::fac(int n) -> T {
  if (n >= p) return 0;
  while (len(fa) <= n) {
    int k = len(fa);
    fa.ep(fa[k - 1] * T(k));
  }
  return fa[n];
}

TE Z fps_t<T>::ifac(int n) -> T {
  if (n < 0) return T(0);
  while (len(ifa) <= n) ifa.ep(ifa.back() * inv(len(ifa)));
  return ifa[n];
}

TE Z fps_t<T>::C(int n, int k) -> T {
  assert(n >= 0);
  if (k < 0 or n < k) return 0;
  return fac(n) * ifac(k) * ifac(n - k);
}

TE Z fps_t<T>::sh(fps &a, int N) -> void { a.resize(N); }

// 非0项数量
TE Z fps_t<T>::count_terms(cf f) -> int {
  int s = 0, N = len(f);
  FOR(i, N) s += f[i].val() != 0;
  return s;
}

TE Z fps_t<T>::eval(cf f, T x) -> T {
  T s = 0, c = 1;
  int N = len(f);
  FOR(i, N) s += f[i] * c, c *= x;
  return s;
}

TE Z fps_t<T>::crt(ull a, ull b, ull c) -> T {
  constexpr ull x = 104'391'568, xx = 190'329'765;
  ull t = (b - a + p1) * x % p1, s = a + t * p0;
  t = (c - s % p2 + p2) * xx % p2;
  return T(s) + T(t) * T(ull(p0) * p1);
}

TE Z fps_t<T>::ntr(T *w, T *iw, T *r, T *ir, T *b, T *ib) -> void {
  w[t] = fps_t<T>::r, iw[t] = w[t].inv();
  FOR_R(i, t) w[i] = w[i + 1] * w[i + 1], iw[i] = iw[i + 1] * iw[i + 1];
  T s = 1, c = 1;
#define f(a, g) FOR(i, t - g + 1) a[i] = w[i + g] * s, s *= iw[i + g], i##a[i] = iw[i + g] * c, c *= w[i + g]
  f(r, 2);
  s = c = 1;
  f(b, 3);
#undef f
}


TE Z fps_t<T>::ntt(fps &a, bool in) -> void {
  assert(T::can_ntt());
  const uint m = p;
  static T w[30], iw[30], r[30], ir[30], b[30], ib[30];
  static bool ok = 0;
  if (ok == 0) ok = 1, ntr(w, iw, r, ir, b, ib);

#define f(k) a[i + of + k * p]
#define g(k) ull(f(k).val())
#define tp topbit(~s & -~s)
  int N = len(a), n = topbit(N);
  if (not in) {
    int sz = 0;
    while (sz < n) {
      if (n - sz == 1) {
        int p = 1 << (n - sz - 1);
        T c = 1;
        FOR(s, 1 << sz) {
          int of = s << (n - sz);
          FOR(i, p) {
            T l = f(0), w = f(1) * c;
            f(0) = l + w, f(1) = l - w;
          }
          c *= r[tp];
        }
        ++sz;
      } else {
        int p = 1 << (n - sz - 2);
        T c = 1, in = w[2];
        FOR(s, 1 << sz) {
          T rr = c * c, R = rr * c;
          int of = s << (n - sz);
          FOR(i, p) {
            ull x = g(0), y = g(1) * c.val(), e = g(2) * rr.val(),
                r = g(3) * R.val(), t = (y + M - r) % m * in.val();
            f(0) = x + y + e + r;
            f(1) = x + e + M + M - y - r;
            f(2) = x + M - e + t;
            f(3) = x + M + M - e - t;
          }
          c *= b[tp];
        }
        sz += 2;
      }
    }
  } else {
    T c = T(N).inv();
    FOR(i, N) a[i] *= c;
    int sz = n;
    while (sz) {
      if (sz == 1) {
        int p = 1 << (n - sz);
        T c = 1;
        FOR(s, 1 << (sz - 1)) {
          int of = s << (n - sz + 1);
          FOR(i, p) {
            ull l = g(0), r = g(1);
            f(0) = l + r, f(1) = (m + l - r) * c.val();
          }
          c *= ir[tp];
        }
        --sz;
      } else {
        int p = 1 << (n - sz);
        T c = 1, in = iw[2];
        FOR(s, 1 << (sz - 2)) {
          T rr = c * c, R = rr * c;
          int of = s << (n - sz + 2);
          FOR(i, p) {
            ull x = g(0), y = g(1), e = g(2), r = g(3),
                t = (m + e - r) * in.val() % m;
            f(0) = x + y + e + r;
            f(1) = (x + m - y + t) * c.val();
            f(2) = (x + y + m + m - e - r) * rr.val();
            f(3) = (x + m + m - y - t) * R.val();
          }
          c *= ib[tp];
        }
        sz -= 2;
      }
    }
  }
}
#undef f
#undef g
#undef tp

TE Z fps_t<T>::conv_naive(cf a, cf b) -> fps {
  int N = len(a), M = len(b), sz = N + M - 1;
  if (not N or not M) return {};
  if (N > M) return conv_naive(b, a);
  fps c(sz);
  FOR(i, N) FOR(k, M) c[i + k] += a[i] * b[k];
  return c;
}  

TE Z fps_t<T>::conv_kara(cf f, cf g) -> fps {
  constexpr int lm = 30;
  if (min(len(f), len(g)) <= lm) return conv_naive(f, g);
  int N = max(len(f), len(g)), M = ceil(N, 2);
  fps f1, f2, g1, g2;
  if (len(f) < M) f1 = f;
  if (len(f) >= M) f1 = {f.begin(), f.begin() + M};
  if (len(f) >= M) f2 = {f.begin() + M, f.end()};
  if (len(g) < M) g1 = g;
  if (len(g) >= M) g1 = {g.begin(), g.begin() + M};
  if (len(g) >= M) g2 = {g.begin() + M, g.end()};
  fps a = conv_kara(f1, g1);
  fps b = conv_kara(f2, g2);
  FOR(i, len(f2)) f1[i] += f2[i];
  FOR(i, len(g2)) g1[i] += g2[i];
  fps c = conv_kara(f1, g1);
  fps F(len(f) + len(g) - 1);
  FOR(i, len(a)) F[i] += a[i], c[i] -= a[i];
  FOR(i, len(b)) F[2 * M + i] += b[i], c[i] -= b[i];
  if (c.back() == T(0)) c.pop_back();
  FOR(i, len(c)) if (c[i] != T(0)) F[M + i] += c[i];
  return F;
}

TE Z fps_t<T>::conv_ntt(fps a, fps b) -> fps {
  assert(T::can_ntt());
  int N = len(a), M = len(b), sz = 1;
  if (min(N, M) == 0) return {};
  while (sz < N + M - 1) sz <<= 1;
  sh(a, sz), sh(b, sz);
  ntt(a, 0);
  ntt(b, 0);
  FOR(i, sz) a[i] *= b[i];
  ntt(a, 1);
  sh(a, N + M - 1);
  return a;
}

TE Z fps_t<T>::conv_mtt(cf a, cf b) -> fps {
  int N = len(a), M = len(b);
  if (not N or not M) return {};
  f0::fps a0(N), b0(M);
  f1::fps a1(N), b1(M);
  f2::fps a2(N), b2(M);
  FOR(i, N) a0[i] = a[i].val(), a1[i] = a[i].val(), a2[i] = a[i].val();
  FOR(i, M) b0[i] = b[i].val(), b1[i] = b[i].val(), b2[i] = b[i].val();
  Z c0 = f0::conv_ntt(a0, b0);
  Z c1 = f1::conv_ntt(a1, b1);
  Z c2 = f2::conv_ntt(a2, b2);
  fps c(len(c0));
  FOR(i, N + M - 1) c[i] = crt(c0[i].val(), c1[i].val(), c2[i].val());
  return c;
}

TE Z fps_t<T>::conv(cf a, cf b) -> fps {
  int N = len(a), M = len(b);
  if (min(N, M) == 0) return {};
  if (T::can_ntt()) {
    if (min(N, M) <= 50) return conv_kara(a, b);
    return conv_ntt(a, b);
  }
  if (min(N, M) <= 200) return conv_kara(a, b);
  return conv_mtt(a, b);
}

TE Z fps_t<T>::sq_ntt(fps a) -> fps {
  assert(T::can_ntt());
  int N = len(a), sz = 1;
  if (N == 0) return {};
  while (sz < N + N - 1) sz <<= 1;
  sh(a, sz);
  ntt(a, 0);
  FOR(i, sz) a[i] *= a[i];
  ntt(a, 1);
  sh(a, N + N - 1);
  return a;
}

TE Z fps_t<T>::sq_mtt(cf a) -> fps {
  int N = len(a);
  if (N == 0) return {};
  f0::fps a0(N);
  f1::fps a1(N);
  f2::fps a2(N);
  FOR(i, N) a0[i] = a[i].val(), a1[i] = a[i].val(), a2[i] = a[i].val();
  Z c0 = f0::sq_ntt(a0);
  Z c1 = f1::sq_ntt(a1);
  Z c2 = f2::sq_ntt(a2);
  fps c(len(c0));
  FOR(i, N + N - 1) c[i] = crt(c0[i].val(), c1[i].val(), c2[i].val());
  return c;
}

TE Z fps_t<T>::sq(cf a) -> fps {
  int N = len(a);
  if (T::can_ntt()) {
    if (N <= 50) return conv_naive(a, a);
    return sq_ntt(a);
  }
  if (N <= 150) return conv_kara(a, a);
  return sq_mtt(a);
}

// 微分
TE Z fps_t<T>::diff(cf f) -> fps {
  int N = len(f);
  if (N <= 1) return {};
  fps g(N - 1);
  FOR(i, N - 1) g[i] = f[i + 1] * T(i + 1);
  return g;
}

// 积分
TE Z fps_t<T>::inte(cf f) -> fps {
  int N = len(f);
  fps g(N + 1);
  FOR(i, 1, N + 1) g[i] = f[i - 1] * inv(i);
  return g;
}

// 定积分
TE Z fps_t<T>::inte(cf f, T l, T r) -> T {
  T s = 0, L = 1, R = 1;
  int N = len(f);
  FOR(i, N) {
    L *= l, R *= r;
    s += inv(i + 1) * f[i] * (L - R);
  }
  return s;
}
#line 4 "YRS/nt/bigint/big.hpp"

TE Z fps_t<T>::crt_128(ull a, ull b, ull c) -> u128 {
  constexpr ull x = 104'391'568, xx = 190'329'765;
  ull t = (b - a + p1) * x % p1, s = a + t * p0;
  t = (c - s % p2 + p2) * xx % p2;
  return s + u128(t) * p0 * p1;
}

TE Z fps_t<T>::conv_for_big(const vc<int> &a, const vc<int> &b) -> vc<int> {
  f0::fps a0(all(a)), b0(all(b));
  f1::fps a1(all(a)), b1(all(b));
  f2::fps a2(all(a)), b2(all(b));
  Z c0 = f0::conv_ntt(a0, b0);
  Z c1 = f1::conv_ntt(a1, b1);
  Z c2 = f2::conv_ntt(a2, b2);
  vc<int> c(len(c0));
  u128 x = 0;
  static constexpr int M = 1000000000;
  int N = len(a) + len(b) - 1;
  FOR(i, N) {
    x += crt_128(c0[i].val(), c1[i].val(), c2[i].val());
    c[i] = x % M, x /= M;
  }
  while (x) c.ep(x % M), x /= M;
  return c;
}

// https://www.luogu.com.cn/problem/P2152 高精度gcd

struct bigint {
  static constexpr int TEN[]
        {1,      10,      100,      1000,      10000,
         100000, 1000000, 10000000, 100000000, 1000000000};
  static constexpr int n = 9, M = TEN[n];
  using T = bigint;

  int op;
  vc<int> a;

  bigint() : op(0), a() {}
  bigint(int op, const vc<int> &a) : op(op), a(a) {}
  bigint(ll x) {
    if (x == 0) { op = 0; return; }
    op = 1;
    if (x < 0) op = -1, x = -x;
    while (x) a.ep(x % M), x /= M;
  }
  bigint(string s) {
    if (s[0] == '0') { op = 0; return; }
    op = 1;
    if (s[0] == '-') op = -1, s.erase(s.begin());
    reverse(s);
    int N = len(s), m = ceil(N, n);
    a.assign(m, 0);
    FOR(i, N) a[i / n] += TEN[i % n] * (s[i] - '0');
  }

  void from_str(string s) {
    a.clear();
    if (s[0] == '0') { op = 0; return; }
    op = 1;
    if (s[0] == '-') op = -1, s.erase(s.begin());
    reverse(s);
    int N = len(s), m = ceil(N, n);
    a.assign(m, 0);
    FOR(i, N) a[i / n] += TEN[i % n] * (s[i] - '0');
  }

  bool operator<(const T &p) const {
    if (op != p.op) return op < p.op;
    if (op == 0) return 0;
    if (op == 1) return less(a, p.a);
    else return less(p.a, a);
  }
  bool operator>(const T &p) const { return p < *this; }
  bool operator<=(const T &p) const { return not(*this > p); }
  bool operator>=(const T &p) const { return not(*this < p); }
  bool operator==(const T &p) const { return op == p.op and a == p.a; }
  bool operator!=(const T &p) const { return op != p.op or a != p.a; }

  T operator-() const {
    T p = *this;
    return p.op = -op, p;
  }

  T operator+() const { return *this; }

  T &operator+=(const T &p) {
    if (op == 0) return *this = p;
    if (p.op == 0) return *this;
    if (op == p.op) return a = sum(a, p.a), *this;
    if (less(a, p.a)) return a = sub(p.a, a), op = -op, *this;
    a = sub(a, p.a);
    if (is_zero(a)) op = 0;
    return *this;
  }

  T &operator-=(const T &p) {
    if (p.op == 0) return *this;
    if (op == 0) return *this = -p;
    if (op != p.op) return a = sum(a, p.a), *this;
    if (less(a, p.a)) return a = sub(p.a, a), op = -op, *this;
    a = sub(a, p.a);
    if (is_zero(a)) op = 0;
    return *this;
  }

  T &operator*=(const T &p) {
    op *= p.op;
    if (not op) a.clear();
    else a = mul(a, p.a);
    return *this;
  }
  
  T &operator/=(const T &p) { return *this = divmod(p).fi; }
  T &operator%=(const T &p) { return *this = divmod(p).se; }

  T operator+(const T &p) const { return T(*this) += p; }
  T operator-(const T &p) const { return T(*this) -= p; }
  T operator*(const T &p) const { return T(*this) *= p; }
  T operator/(const T &p) const { return T(*this) /= p; }
  T operator%(const T &p) const { return T(*this) %= p; }

  pair<T, T> divmod(const T &p) const {
    assert(p.op != 0);
    if (op == 0) return {T(), T()};
    Z res = divmod_newton(a, p.a);
    int op1 = op * p.op, op2 = op;
    if (is_zero(res.fi)) op1 = 0;
    if (is_zero(res.se)) op2 = 0;
    return {{op1, res.fi}, {op2, res.se}};
  }

  T pow(ll k) const { return pow(*this, k); }

  static T pow(T a, ll k) {
    if (k == 0) return 1;
    T p = pow(a, k >> 1), s = p * p;
    return (k & 1) ? s * a : s;
  }

  string to_string() const {
    if (not op) return "0";
    string s = to_string(a);
    if (op == -1) s += '-';
    return reverse(s), s;
  }

  string to_binary_string() const {
    assert(op != -1);
    vc<uint> A(all(a));
    string s;
    while (1) {
      while (not A.empty() and A.back() == uint(0)) pop(A);
      if (A.empty()) break;
      ull r = 0;
      int N = len(A);
      FOR_R(i, N) {
        r = r * M + A[i];
        A[i] = r >> 32;
        r &= uint(-1);
      }
      FOR(i, 32) s += '0' + (r >> i & 1);
    }
    while (not s.empty() and s.back() == '0') pop(s);
    if (s.empty()) s += '0';
    return reverse(s), s;
  }

  ll to_ll() const {
    if (op == 0) return 0;
    ll x = to_ll(a);
    return op == -1 ? -x : x;
  }

  i128 to_i128() const {
    if (op == 0) return 0;
    i128 x = to_i128(a);
    return op == -1 ? -x : x;
  }

  friend ostream &operator<<(ostream &cout, const T &b) {
    return cout << b.to_string();
  }

  friend istream &operator>>(istream &cin, T &b) {
    static string s;
    cin >> s;
    b.from_str(s);
    return cin;
  }

  bool is_zero() const { return op == 0; }
  bool is_one() const { return op == 1 and len(a) == 1 and a[0] == 1; }
  bool is_odd() const { return op != 0 and (a[0] & 1); }
  bool is_even() const { return not is_odd(); }

  T div2() const {
    T r = *this;
    int N = len(a);
    for (int i = N; i--; r.a[i] >>= 1)
      if ((r.a[i] & 1) and i) r.a[i - 1] += M;
    sh(r.a);
    if (r.a.empty()) r.op = 0;
    return r;
  }

  T gcd(const T &x) const {
    T a = this->abs(), b = x.abs();
    if (a < b) swap(a, b);
    if (b.is_zero()) return a;
    int t = 0;
    while (a.is_even() and b.is_even()) a = a.div2(), b = b.div2(), ++t;
    while (b > 0) {
      if (a.is_even()) a = a.div2();
      else if (b.is_even()) b = b.div2();
      else a -= b;
      if (a < b) swap(a, b);
    }
    while (t--) a += a;
    return a;
  }

  T lcm(const T &x) const { return *this / gcd(x) * x; }

  T abs() const {
    if (op == 0) return 0;
    if (op < 0) return -(*this);
    return *this;
  }

  using vec = vc<int>;
  using PVV = pair<vec, vec>;

  static vc<int> mul(const vec &a, const vec &b) {
    int N = len(a), m = len(b), t = min(N, m);
    if (t == 0) return {};
    if (t <= 500) {
      vec c(N + m - 1);
      u128 x = 0;
      FOR(k, N + m - 1) {
        int s = max(0, k + 1 - m), t = min(k, N - 1);
        FOR(i, s, t + 1) x += ull(a[i]) * b[k - i];
        c[k] = x % M;
        x /= M;
      }
      while (x > 0) c.ep(x % M), x /= M;
      return c;
    }
    static fps_t<mint_t<M>> X;
    return X.conv_for_big(a, b);
  }

  static bool is_zero(const vec &a) { return a.empty(); }
  static bool is_one(const vec &a) { return len(a) == 1 and a[0] == 1; }
  static bool eq(const vec &a, const vec &b) { return a == b; }
  static bool less(const vec &a, const vec &b) {
    if (len(a) != len(b)) return len(a) < len(b);
    int N = len(a);
    FOR_R(i, N) if (a[i] != b[i]) return a[i] < b[i];
    return 0;
  }
  static bool greater(const vec &a, const vec &b) { return less(b, a); }
  static bool less_eq(const vec &a, const vec &b) { return not greater(a, b); }
  static bool greater_eq(const vec &a, const vec &b) { return not less(a, b); }

  static void sh(vec &a) {
    while (not a.empty() and a.back() == 0) pop(a);
  }

  static vec to_vec(ll x) {
    vec s;
    while (x) s.ep(x % M), x /= M;
    return s;
  }

  static ll to_ll(const vec &a) {
    ll s = 0;
    int N = len(a);
    FOR_R(i, N) s = s * M + a[i];
    return s;
  }

  static i128 to_i128(const vec &a) {
    i128 s = 0;
    int N = len(a);
    FOR_R(i, N) s = s * M + a[i];
    return s;
  }

  static string to_string(const vec &a) {
    string s;
    for (int x : a) FOR(n) s += '0' + x % 10, x /= 10;
    while (s.back() == '0') pop(s);
    return s;
  }

  static vec sum(const vec &a, const vec &b) {
    vec c(a);
    c.resize(max(len(a), len(b)) + 1);
    int N = len(b);
    FOR(i, N) c[i] += b[i];
    N = len(c) - 1;
    FOR(i, N) if (c[i] >= M) c[i] -= M, ++c[i + 1];
    return sh(c), c;
  }

  static vec sub(const vec &a, const vec &b) {
    vec c(a);
    int N = len(b);
    FOR(i, N) c[i] -= b[i];
    N = len(a) - 1;
    FOR(i, N) if (c[i] < 0) c[i] += M, --c[i + 1];
    return sh(c), c;
  }

  // 0 <= A < 1e18, 1 <= B > 1e9
  static PVV divmod_ll_int(const vec &a, const vec &b) {
    assert(0 <= len(a) and len(a) <= 2);
    assert(len(b) == 1);
    ll x = to_ll(a);
    int y = b[0];
    return {to_vec(x / y), to_vec(x % y)};
  }
  // 0 <= A < 1e18, 1 <= B < 1e18
  static PVV divmod_ll_ll(const vec &a, const vec &b) {
    assert(0 <= len(a) and len(a) <= 2);
    assert(1 <= len(b) and len(b) <= 2);
    ll x = to_ll(a), y = to_ll(b);
    return {to_vec(x / y), to_vec(x % y)};
  }
  // 1 <= B < 1e9
  static PVV divmod_1e9(const vec &a, const vec &b) {
    assert(len(b) == 1);
    if (len(a) <= 2) return divmod_ll_int(a, b);
    int N = len(a);
    vec s(N);
    ll d = 0;
    int bb = b[0];
    FOR_R(i, N) {
      d = d * M + a[i];
      assert(d <= 1ll * M * bb);
      int q = d / bb, r = d % bb;
      s[i] = q, d = r;
    }
    return sh(s), pair{s, d ? vec{int(d)} : vec{}};
  }
  // 0 <= A, 1 <= B
  static PVV divmod_naive(const vec &a, const vec &b) {
    assert(not is_zero(b));
    if (len(b) == 1) return divmod_1e9(a, b);
    if (max(len(a), len(b)) <= 2) return divmod_ll_ll(a, b);
    if (less(a, b)) return {{}, a};
    // B >= 1e9, A >= B
    int norm = M / (b.back() + 1);
    vec x = mul(a, {norm}), y = mul(b, {norm});
    int yb = y.back();
    vec s(len(x) - len(y) + 1);
    vec r(x.end() - len(y), x.end());
    int N = len(s);
    FOR_R(i, N) {
      if (len(r) < len(y));
      else if (len(r) == len(y)) {
        if (less_eq(y, r)) s[i] = 1, r = sub(r, y);
      } else {
        assert(len(y) + 1 == len(r));
        ll rb = 1ll * r.back() * M + r.end()[-2];
        int q = rb / yb;
        vec yq = mul(y, {q});
        while (less(r, yq)) --q, yq = sub(yq, y);
        r = sub(r, yq);
        while (less_eq(y, r)) ++q, r = sub(r, y);
        s[i] = q;
      }
      if (i) r.insert(r.begin(), x[i - 1]);
    }
    sh(s), sh(r);
    Z [ss, rr] = divmod_1e9(r, {norm});
    assert(is_zero(rr));
    return {s, ss};
  };

  // 1 / a を 絶対誤差 B^{-deg} で求める
  static vec keis_inv(const vec &a, int deg) {
    assert(not a.empty() and M / 2 <= a.back() and a.back() < M);
    int k = deg, N = len(a);
    while (k > 64) k = (k + 1) >> 1;
    vec b(N + k + 1);
    b.back() = 1;
    b = divmod_naive(b, a).fi;
    while (k < deg) {
      vec s = mul(b, b);
      s.insert(s.begin(), 0);
      int d = min(N, k * 2 + 1);
      vec t{a.end() - d, a.end()}, v = mul(s, t);
      v.erase(v.begin(), v.begin() + d);
      vec w(k + 1), ww = sum(b, b);
      copy(all(ww), back_inserter(w));
      b = sub(w, v);
      b.erase(b.begin());
      k <<= 1;
    }
    return b.erase(b.begin(), b.begin() + k - deg), b;
  }

  static PVV divmod_newton(const vec &a, const vec &b) {
    assert(not is_zero(b));
    if (len(b) <= 64) return divmod_naive(a, b);
    if (len(a) - len(b) <= 64) return divmod_naive(a, b);
    int norm = M / (b.back() + 1);
    vec x = mul(a, {norm}), y = mul(b, {norm});
    int N = len(x), m = len(y);
    int deg = N - m + 2;
    vec z = keis_inv(y, deg), q = mul(x, z);
    q.erase(q.begin(), q.begin() + m + deg);
    vec yq = mul(y, q);
    while (less(x, yq)) q = sub(q, {1}), yq = sub(yq, y);
    vec r = sub(x, yq);
    while (less_eq(y, r)) q = sum(q, {1}), r = sub(r, y);
    sh(q), sh(r);
    Z [qq, rr] = divmod_1e9(r, {norm});
    assert(is_zero(rr));
    return {std::move(q), std::move(qq)};
  }
};

bigint abs(const bigint &x) { return x.abs(); }
bigint gcd(const bigint &a, const bigint &b) { return a.gcd(b); }
bigint lcm(const bigint &a, const bigint &b) { return a.lcm(b); }

#ifdef FIO
void rd(bigint &x) {
  static string s;
  rd(s);
  x.from_str(s);
}
void wt(const bigint &x) {
  wt(x.to_string());
}
#endif
#line 5 "No_201_yukicoder\u3058\u3083\u3093\u3051\u3093.cpp"

void Yorisou() {
  string s, t, c;
  bigint a, b;
  IN(s, a, c, t, b, c);
  if (a == b) print(-1);
  else print(a > b ? s : t);
}
constexpr int tests = 0, fl = 0, DB = 10;
#line 1 "YRS/aa/main.hpp"
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  if (fl) cerr.tie(0);
  if (tests and not fl) IN(T);
  for (int i = 0; i < T or fl; ++i) {
    Yorisou();
    if (fl and i % DB == 0) cerr << "Case: " << i << '\n';
  }
  return 0;
}
#line 15 "No_201_yukicoder\u3058\u3083\u3093\u3051\u3093.cpp"
0