#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
  if(a) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
void Yes(int a){
  if(a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint998244353 mint;

ll inf=1001001001001001001;

ll gcd(ll a,ll b){
  if(b==0) return a;
  return gcd(b,a%b);
}

int main(){
  string S;
  cin>>S;
  string T;
  rep(i,S.size()){
    if(S[i]=='6') T+='9';
    else if(S[i]=='9') T+='6';
    else T+=S[i];
  }
  reverse(all(T));
  cout<<T<<endl;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007ll
#define md 998244353ll
#define e1 1e-9
#define v vector< long long >
#define vv vector< vector< long long > >
#define p pair < long long,long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define all(x) x.begin() , x.end()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define bb(i,a,b) for(ll i=a;i>=0;i--)
#define test \
    ll tt{0}; \
    cin>>tt; \
    while(tt--)
using namespace std;
bool prime(ll n) {
    if (n < 2)return false;
    for (ll x = 2; x * x <= n; x++) {
        if (n % x == 0)return false;
    }
    return true;
}
vector<ll> Seiveprime(ll n)
{
    vector<bool> isPrime(n, true);
    for (int i = 2; i * i < n; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * i; j < n; j += i)
                isPrime[j] = false;
        }
    }
    vector<ll> prime;
    prime.push_back(2);
    for (int i = 3; i < n; i += 2)
        if (isPrime[i])
            prime.push_back(i);
    return prime;
}
vector<ll> factors(ll n) {
    vector<ll> f;
    for (ll x = 2; x*x <= n; x++) {
        while (n%x == 0) {
            f.pb(x);
            n /= x;
        }
    }
    if (n > 1) f.pb(n);
    return f;
}
vp pri_fact(ll n) {
    v x = factors(n);
    vp y;
    y.eb(x[0], 1);

    for (ull i = 1; i < x.size(); i++) {
        if (x[i] == x[i - 1]) {
            y.back().second++;
        } else {
            y.eb(x[i], 1);
        }
    }

    return y;
}
tuple<int,int,int> gcd(int a, int b) {
    if (b == 0) {
        return {1,0,a};
    } else {
        int x,y,g;
        tie(x,y,g) = gcd(b,a%b);
        return {y,x-(a/b)*y,g};
    }
}
ll mult(ll x,ll y,ll m) {
    return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
    if (n == 0)return 1;
    if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
    return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
    ll i = 0;

    while (x / (1 << i) != 1)
        i++;
    return i;
}
ll add(ll x,ll y)
{
    x+=y;
    if(x>=md)return x-md;
    return x;
}
ll digitno(ll n){
    ll x{0};
    while(n>0){
        x++;
        n/=10;
    }
    return x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    bitset<100005ll> bit,bit1;
    bit[0]=1;

    ll n{0},sum{0};
    cin>>n;

    v t(n);
    f(i,0,n){
        cin>>t[i];
        sum+=t[i];
        bit= bit | (bit<<t[i]);
    }

    ll mn=INT_MAX;
    ll ans{0};
    f(i,1,100005){
        if(bit[i]){
            if(abs(sum-2*i)<mn)
            {
                mn=abs(sum-2*i);
                ans=i;
            }
        }
    }
    ans=max(ans,sum-ans);

    cout<<ans;

    return 0;
}


// abc193_e
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(2e18)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

// 拡張 Euclid の互除法
// ax + by = gcd(a, b) となる (x, y) を求め、d = gcd(a, b) を返す
ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; } else{ x = 1; y = 0; } return d; }

// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) { p = 1; q = 0; return a; }
    long long d = extGcd(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
    long long p, q;
    long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
    if ((b2 - b1) % d != 0) return make_pair(0, -1);
    long long m = m1 * (m2/d); // lcm of (m1, m2)
    long long tmp = (b2 - b1) / d * p % (m2/d);
    long long r = mod(b1 + m1 * tmp, m);
    return make_pair(r, m);
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int T;
    cin >> T;
    while (T--){
        ll X, Y, P, Q;
        cin >> X >> Y >> P >> Q;

        ll ans = -1;

        REP(j, Q){
            int i = 0;
            ll n1 = 2*X + 2*Y;
            ll b1 = X + i;
            ll n2 = P + Q;
            ll b2 = P + j;

            auto res = ChineseRem(b1, n1, b2, n2);
            if (res.second == -1){
                continue;
            }
            ll tmp = res.first;
            ans = ans == -1 ? tmp : min(ans, tmp);
        }

        REP(i, Y) {
            int j = 0;
            ll n1 = 2*X + 2*Y;
            ll b1 = X + i;
            ll n2 = P + Q;
            ll b2 = P + j;

            auto res = ChineseRem(b1, n1, b2, n2);
            if (res.second == -1){
                continue;
            }
            ll tmp = res.first;
            ans = ans == -1 ? tmp : min(ans, tmp);
        }

        if (ans == -1){
            print("infinity");
        }  else {
            print(ans);
        }
    }

    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#define hh "\n"
#define fi first
#define se second
#define inf 2147483647
#define llf 9223372036854775807
#define For(i,a) for(auto &i:a)
#define mapa(a,b) make_pair(a,b)
#define tty template <typename T>
#define mm(a,b) memset(a,b, sizeof(a));
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define cf int t;cin>>t;while (t--) solve();
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
tty T gcd (T a, T b) {while (b ^= a ^= b ^= a %= b);  return a;}
inline char nc() {static char buf[1000000], *p1 = buf, *p2 = buf;return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;}
//#define nc getchar
tty inline void read(T &sum) {char ch = nc();T tf = 0;sum = 0;while((ch < '0' || ch > '9') && (ch != '-')) ch = nc();tf = ((ch == '-') && (ch = nc()));while(ch >= '0' && ch <= '9') sum = sum * 10+ (ch - 48), ch = nc();(tf) && (sum = -sum);}
tty inline void write(T x){char F[200];T tmp=x>0?x:-x ;if(x<0)putchar('-') ;T cnt=0 ;while(tmp>0){F[cnt++]=tmp%10+'0';tmp/=10;}while(cnt>0)putchar(F[--cnt]) ;}
tty inline T ksc(T x, T y, T mod){return ( x * y - (ll) ( (long double) x / mod*y )*mod + mod ) % mod;}
tty inline T exgcd(T a, T b, T &x, T &y) {if (!b) {x = 1,y=0;return a;}T d = exgcd(b, a % b, x, y);T t = x;x=y;y=t-(a/b)*y;return d;}

tty inline void rmqmin(T f[][20],T n){for (int i = 1; i <= n; i++)cin >> f[i][0];for (int j = 1; j <= 20; j++)for (int i = 1; i <= n; i++)if (i + (1 << j) - 1 <= n)f[i][j] = min(f[i][j - 1], f[i + (1 << (j-1))][j - 1]);}
tty inline T zymin(T f[][20],T z,T y){int x=int (log(y-z+1)/log(2));return min(f[z][x],f[y-(1<<x)+1][x]);}
tty inline void rmqmax(T f[][20], T n, int i1) {for (int i = 1; i <= n; i++)cin >> f[i][0];for (int j = 1; j <= 20; j++)for (int i = 1; i <= n; i++)if (i + (1 << j) - 1 <= n)f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);}
tty inline T zymax(T f[][20],T z,T y){int x=int (log(y-z+1)/log(2));return max(f[z][x],f[y-(1<<x)+1][x]);}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ll excrt(ll n , ll ai[] , ll bi[])
{
    ll x,y;
    ll M=bi[1] , ans=ai[1];
    for(int i=2;i<=n;i++)
    {
        ll a=M , b=bi[i] , c=(ai[i]-ans%b+b)%b;
        ll gcd=exgcd(a,b,x,y) , bg=b/gcd;
        if(c%gcd != 0) return -1;
        x = ksc(x,c/gcd,bg);
        ans += x * M;
        M *= bg;
        ans=(ans%M+M)%M;
    }
    return (ans%M+M)%M;
}
ll a[5],b[5];
void solve()
{
    ll x , y , p , q; cin >> x >> y >> p >> q;
    ll ans = llf;
    for (int i = x ; i < x + y ; i++){
        for (int j = p ; j < p + q ; j++){
            a[1] = i , b[1] = 2 * (x + y);
            a[2] = j , b[2] = p + q;
            ll res = excrt(2 , a , b);
            if (res == -1) continue;
            ans = min(ans , res);
        }
    }
    if (ans == llf) cout<<"infinity"<<endl;
    else cout<<ans<<endl;
}
int main()
{
    IOS;cf
    return 0;
}


#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

#ifdef __GNUC__
#define popcount __builtin_popcountll
#else
constexpr int popcount(ll x)
{
  x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
  x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
  x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f);
  x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff);
  x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
  return (int)((x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff));
}
#endif

struct Cst {
  int x, y, z;
  bool operator<(const Cst& v) const {
    return x < v.x;
  }
};

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M; cin >> N >> M;
  v(Cst) cs(M);
  vv(Cst) ds(N + 1);
  F0R(i, M) {
    cin >> cs[i].x >> cs[i].y >> cs[i].z;
    ds[cs[i].x].push_back(cs[i]);
  }
  vl dp(1 << N);  // 既に並べた数が 集合i のときの場合の数
  dp[0] = 1;
  FOR(b, 1, 1 << N) {
    F0R(i, N) {
      if ((b >> i) & 1) {
        dp[b] += dp[b ^ (1 << i)];
      }
    }
    int pc = popcount(b);
    for (auto [x, y, z] : ds[pc]) {
      int a = b & ((1 << y) - 1);
      if (popcount(a) > z) {
        dp[b] = 0;
        break;
      }
    }
  }
  cout << dp[(1 << N) - 1] << newl;
}
#endif

#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
const int mod = 1e9 + 7;
const ll INF = 3e18;
const double EPSILON = 1e-9;
const int N = 200005;
struct ST{
    int pos, qt, val;
};
bool valid[1<<19];
int n, m;
ll dp[1<<19];
ll solve(int msk){
    if(msk == (1<<n)-1)
        return 1;
    if(dp[msk] != -1)
        return dp[msk];
    ll ans = 0;
    for(int j = 0; j < n; j++){
        if(!(msk&(1<<j)) and valid[msk+(1<<j)]){
            ans += solve(msk+(1<<j));
        }
    }
    return dp[msk] = ans;
}
int main(){
    fastio;
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    ST v[m];
    for(int i = 0; i < m; i++){
        cin >> v[i].pos >> v[i].val >> v[i].qt;
    }
    for(int msk = 0; msk < (1<<n); msk++){
        int x = __builtin_popcount(msk);
        vi sum(n+1);
        for(int i = 0; i < n; i++){
            if(msk&(1<<i)){
                sum[i+1]++;
            }
            sum[i+1] += sum[i];
        }
        bool flag = true;
        for(int j = 0; j < m; j++){
            if(v[j].pos < x)continue;
            if(sum[v[j].val] > v[j].qt)
                flag = false;
        }
        valid[msk] = flag;
    }
    cout << solve(0) << "\n";
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

int main(void){
    int a,b;
    scanf("%d%d", &a, &b);
    if(b%a==0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
       return 0;

}

#include<bits/stdc++.h>
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
using namespace std;
typedef long long LL ;
LL S,P;
int main() {
	scanf("%lld%lld",&S,&P);
	LL TMP;
	for(LL i=1;i*i<=P;++i) if(P%i == 0) {
		TMP = P/i;
		if(TMP + i == S) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

// A+B = S;
// A*B = P;
// A = S-B
// (S-B)*B = P
// P + (B-S) * B = 0
// B^2 - S*B + P = 0;
// delta = S^2-4*P


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define pr pair<int,int>
#define N 100005
#define mod 1000000007
#define INF 2147483647
using namespace std;
int main() {
	IOS;
    int n;
    string t;
    cin>>n>>t;
    if(n==1){
        if(t=="1"){
            cout<<20000000000;
        }
        else cout<<10000000000;
        return 0;
    }
    bool los=0;
    int cnt1=0,cnt0=0;
    bool hs0=0;
    for(int i=0;i<n;i++){
        if(t[i]=='0'){
            if(hs0&&cnt1!=2)los=1;
            hs0=1;
            cnt1=0;
            cnt0++;
        }
        else cnt1++,cnt0=0;
        if(cnt1>2||cnt0>1)los=1;
        if(los)break;
    }
    if(los)cout<<0;
    else{
        ll len=10000000000;
        ll ans=n;
        if(t[0]=='0'){
            ans=(2+n)/3+((n+2)%3!=0);

        }
        else if(t[1]=='0'){
            ans=(1+n)/3+((n+1)%3!=0);
        }
        else{
            ans=n/3+(n%3!=0);
        }
        cout<<len-ans+1;
    }
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#define eprintf(...) 42
#endif

int main() {
  int n; string t; cin >> n >> t;
  if(n == 1) {
    if(t[0] == '0') cout <<  (ll)1e10 << endl;
    else cout <<  2 * (ll)1e10 << endl;
    return 0;
  }

  if(n==2) {
    if(t=="11") cout <<  (ll)1e10 << endl;
    if(t=="10") cout <<  (ll)1e10 << endl;
    if(t=="01") cout <<  (ll)(1e10)-1 << endl;
    if(t=="00") cout << 0 << endl;
    return 0;
  }

  auto ttt = t.substr(0,3);
  if(!(ttt=="110" || ttt =="101" || ttt=="011")) {
    cout << 0 << endl;
    return 0;
  }
  for(int i=0; i<n-3; i++) {
    if(t[i] != t[i+3]) {
      cout << 0 << endl;
      return 0;
    }
  }

  int zero = 0;
  for(auto c:t) zero += (c=='0');
  cerr << zero << endl;
  ll ans = (ll)1e10 - zero;
  if(t.back() == '0') ans++;
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define endl '\n'

void fast_io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}
ll gcd(ll a , ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

void dfs(vi g[], int vis[], int src, int a[]) {
	vis[src] = 1;
	for (int v : g[src]) {
		if (!vis[v]) {
			dfs(g, vis, v, a);
		}
	}
}
int cnt;
void dfs2(vi g[], int vis[], int src, int a[], int n) {
	vis[src] = 1;
	if (cnt >= (n - 1)) return;

	for (int v : g[src]) {
		if (!vis[v]) {
			cout << src  + 1 << " ";
			cout << v + 1 << endl;
			cnt++;
			dfs2(g, vis, v, a, n);
		}
	}
}
void bfs(vi g[], ll n, int dis[], int p[]) {
	int visi[n + 1];
	for (int i = 1; i <= n; i++) visi[i] = 0;
	queue<int> q;
	q.push(1); visi[1] = 1;
	p[1] = -1;
	while (!q.empty()) {
		int top = q.front(); q.pop();
		for (int v : g[top]) {
			if (!visi[v]) {
				q.push(v);
				visi[v] = 1;
				dis[v] = dis[top] + 1;
				p[v] = top;
			}
		}
	}
}
// bool vis[100010];
// int subtreesize[100010];
// vi adjacency_list[100010];
pair<ll, int> subtree_size_dfs(vi adjacency_list[], int node, bool vis[], int subtreesize[] ) {
	vis[node] = true;
	int cur = 1;
	ll mex = 0;
	for (int child : adjacency_list[node]) {
		if (!vis[child]) {
			// p[child] = node;
			auto tmp = subtree_size_dfs(adjacency_list, child, vis, subtreesize);
			mex = max(mex, tmp.first);
			cur += tmp.second;
		}
	}
	subtreesize[node] = cur;
	return {cur + mex, cur};

}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int max_r = 2000;
const int max_c = 2000;
int bfs_grid(char grid[][max_c], int n, int m, int sx, int sy, vpii al[], int desx, int desy) {
	bool vis[n][m];
	int dis[n][m];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			vis[i][j] = false;
			dis[i][j] = -1;
		}
	}
	int visc[26] = {0};
	for (int i = 0; i < 26; i++) {
		visc[i] = false;
	}
	queue<pii> q;
	q.push({sx, sy});
	vis[sx][sy] = true;
	dis[sx][sy] = 0;
	while (!q.empty()) {
		pii top = q.front(); q.pop();
		int nx = top.ff;
		int ny = top.ss;
		for (int i = 0; i < 4; i++) {
			int tx = top.ff + dx[i];
			int ty = top.ss + dy[i];

			if (tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && grid[tx][ty] != '#') {
				vis[tx][ty] = true;
				q.push({tx, ty});
				dis[tx][ty] = dis[top.ff][top.ss] + 1;
			}

		}
		if (grid[nx][ny] >= 'a' && grid[nx][ny] <= 'z' && !visc[grid[nx][ny] - 'a']) {
			int num = grid[nx][ny] - 'a';
			visc[num] = 1;
			for (int i = 0; i < (int)al[num].size(); i++) {
				int tx = al[num][i].ff;
				int ty = al[num][i].ss;
				if (tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && grid[tx][ty] != '#') {
					vis[tx][ty] = true;
					q.push({tx, ty});
					dis[tx][ty] = dis[nx][ny] + 1;
				}

			}
		}
	}
	return dis[desx][desy];

}
int main()
{
	fast_io();
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	while (t--)
	{
		char grid[max_r][max_c];
		int n, m; cin >> n >> m;
		int sx, sy, desx, desy;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cin >> grid[i][j];
				if (grid[i][j] == 'S') {
					sx = i; sy = j;
				}
				if (grid[i][j] == 'G') {
					desx = i; desy = j;
				}
			}
		}

		vpii al[26];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (grid[i][j] >= 'a' && grid[i][j] <= 'z') {
					int num = grid[i][j] - 'a';
					al[num].pb({i, j});
				}
			}
		}
		cout << bfs_grid(grid, n, m, sx, sy, al, desx, desy) << endl;

	}

}

#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

vector<P> warps[30];

ll warp_points[2010][2010];

ll maze[2010][2010];

vector<P> get_warp(ll y, ll x) {
  ll wid = warp_points[y][x];

  return warps[wid];

  // auto point1 = warps[wid][0];
  // auto point2 = warps[wid][1];

  // if (point1.first == y && point1.second == x) {
  //   return point2;
  // } else {
  //   return point1;
  // }
}

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll H, W;
  scanf("%lld %lld", &H, &W);

  fill(maze[0], maze[2005], -1);

  ll sy, sx, gy, gx;

  // インデックス1開始なので注意
  reps(y, H) {
    string line;
    cin >> line;

    reps(x, line.size()) {
      char ch = line[x - 1];
      if (ch == '#') {
        maze[y][x] = -1;
      } else if (ch == '.') {
        maze[y][x] = INF;
      } else if (ch == 'S') {
        sy = y;
        sx = x;
        maze[y][x] = 0;
      } else if (ch == 'G') {
        gy = y;
        gx = x;
        maze[y][x] = INF;
      } else {
        // ワープ
        ll wid = ch - 'a' + 1;
        warps[wid].emplace_back(mp(y, x));
        warp_points[y][x] = wid;

        maze[y][x] = INF;
      }
    }
  }

  //--------------------------------------------------

  deque<l_l> que;
  que.emplace_back(mp(sy, sx));
  maze[sy][sx] = 0;

  for (;;) {
    if (que.empty()) {
      break;
    }
    auto pos = que.front();
    que.pop_front();
    ll y = pos.first;
    ll x = pos.second;

    // cout << "y:" << (y) << ",x:" << (x) << endl;

    ll c = maze[y][x];

    for (auto e : {mp(y - 1, x), mp(y, x - 1), mp(y + 1, x), mp(y, x + 1)}) {
      if (maze[e.first][e.second] == -1) {
        continue;
      }
      if (maze[e.first][e.second] <= c + 1) {
        continue;
      }
      maze[e.first][e.second] = c + 1;
      que.emplace_back(make_pair(e.first, e.second));
    }

    if (warp_points[y][x]) {
      ll wid = warp_points[y][x];

      auto warp_list = get_warp(y, x);

      rep(i, warp_list.size()) {
        auto next = warp_list[i];

        warp_points[next.first][next.second] = 0;

        if (maze[next.first][next.second] > c + 1) {
          // cout << "WARP!:"
          //      << "next.first:" << (next.first) << ",next.second:" << (next.second) << endl;
          maze[next.first][next.second] = c + 1;
          que.emplace_front(make_pair(next.first, next.second));
        }

        warp_points[next.first][next.second] = 0;
      }
    }
  }

  ll ans = maze[gy][gx];

  if (ans == INF) {
    cout << (-1) << endl;
    return 0;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define MP make_pair
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)
#define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)

typedef long long LL;
typedef pair<int, int> pii;

int ret;
string s;

void dfs(int pos, int cnt, int cur)
{
    if (pos == 10) {
        if (cnt == 4) ret += cur;
        return ;
    }

    if (s[pos] == 'x') {
        dfs(pos + 1, cnt, cur);
        return ;
    }
    int st = s[pos] == 'o' ? 1 : 0;
    for (int i = st; i + cnt <= 4; ++ i) {
        int ncur = cur;
        for (int j = cnt + 1; j <= cnt + i; j ++) ncur *= j;
        for (int j = 1; j <= i; j ++) ncur /= j;
        dfs(pos + 1, cnt + i, ncur);
    }
}

int main()
{
    cin >> s;
    dfs(0, 0, 1);
    printf("%d\n", ret);
    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=998244353;

ll dp[102][102][10004];

int main(){FIN;
	ll n; cin>>n;
	vector<ll> a(n);
	fore(i,0,n)cin>>a[i];
	for(ll x=n;x>=0;x--){
		for(ll y=x;y>=0;y--){
			fore(z,0,10004){
				ll &res=dp[x][y][z];
				if(x==n){
					if(z==0)res=1;
					else res=0;
				}else{
					res=dp[x+1][y+1][z+a[x]]*(y+1);
					if(a[x]<=z){
						res=(res+dp[x+1][y][z-a[x]]*(x+1-y))%MOD;
					}else{
						res=(res+dp[x+1][x-y+1][a[x]-z]*(x+1-y))%MOD;
					}
				}
			}
		}
	}
	cout<<dp[0][0][0]<<"\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
	return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(it); } // element that doesn't exist from (multi)set

void solve()
{
    int n; cin>>n;
    ll sum=0;
    int a[n],b[n];
    FOR(i,0,n) cin>>a[i];
    FOR(i,0,n) cin>>b[i];
    FOR(i,0,n) sum += a[i]*b[i];
    if(sum==0) cout<<"Yes";
    else cout<<"No";
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);

    int ct=1;
    // cin>>ct;
    while(ct--)
    {
        solve();
    }

}

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#include <cassert>
#include <fstream>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
using namespace std;
#define y first
#define x second
constexpr bool istest = false;
constexpr int n = 50;
ifstream file;
ofstream out;
void input_setup(){
	if(istest){
		cout << "write the in file number\n";
		string s;
		cin >> s;
		file.open("C:/Users/souta/downloads/ahc/tools/in/" + s + ".txt");
		if(file.fail()){
			cout << "the file was not found\n";
			return;
		}
		cin.rdbuf(file.rdbuf());
	}
}
//答えるときのやつ
string ans = "";
void output(){
	if(istest){
		out.open("C:/users/souta/downloads/ahc/tools/out.txt");
		if(out.fail()){
			cout << "the file was not found\n";
			return;
		}
		cout.rdbuf(out.rdbuf());
	}
	cout << ans << "\n";
}
pii st_pos;
vvi tiles(n, vi(n)), point(n, vi(n));
void inputs(){
	//start position
	cin >> st_pos.y >> st_pos.x;
	//tiles
	rep(i, n) rep(j, n) cin >> tiles[i][j];
	//points
	rep(i, n) rep(j, n) cin >> point[i][j];
}

//過去に同じ番号のタイルを通ったことがあるのかを確認する
bool checkVisited(const int &Y, const int &X, const vector<pii> &logs){
	int col = tiles[Y][X];
	for(auto a : logs){
		if(col == tiles[a.y][a.x]) return true;
	}
	return false;
}
//とりあえずBFSで探索してみる
int dy[] = {-1,1,0,0};
int dx[] = {0,0,-1,1};
char dir[] = {'U', 'D', 'L', 'R'};
void bfs(){
	priority_queue<pair<pii, int>> que;
	vvi checked(n, vi(n, -1));
	checked[st_pos.y][st_pos.x] = point[st_pos.y][st_pos.x];
	vector<vector<vector<pii>>> logs(n, vector<vector<pii>>(n));

	logs[st_pos.y][st_pos.x].push_back(make_pair(st_pos.y, st_pos.x));
	que.push(make_pair(st_pos, point[st_pos.y][st_pos.x]));

	while(!que.empty()){
		pii pos; int score;
		tie(pos, score) = que.top();
		que.pop();
		if(checked[pos.y][pos.x] > score) continue;
		rep(i, 4){
			int Y = pos.y + dy[i];
			int X = pos.x + dx[i];
			if(Y >= n || X >= n || Y < 0 || X < 0) continue;
			if(checkVisited(Y, X, logs[pos.y][pos.x])) continue;

			int v = score + point[Y][X];
			if(checked[Y][X] == -1 || checked[Y][X] <= v){
				que.push(make_pair(make_pair(Y, X), v));
				checked[Y][X] = v;
				logs[Y][X] = logs[pos.y][pos.x];
				logs[Y][X].push_back(make_pair(Y, X));
			}
		}
	}
	int mx = 0;
	pii bestpos = st_pos;
	rep(i, n) rep(j, n){
		if(mx < checked[i][j]){
			bestpos = make_pair(i, j);
			mx = checked[i][j];
		}
	}

	vector<pii> track = logs[bestpos.y][bestpos.x];
	pii last = st_pos;
	for(auto a : track){
		rep(i, 4){
			if(last.y + dy[i] == a.y && last.x + dx[i] == a.x){
				ans += dir[i];
				break;
			}
		}
		last = a;
	}
}
int main(){
	input_setup();
	inputs();

	bfs();

	output();
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) { cerr << head; dump(); }
template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

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

int main()
{
  int a,b,c; cin>>a>>b>>c;

  vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101)));

  for (int i=99; i>=0; i--) {
    for (int j=99; j>=0; j--) {
      for (int k=99; k>=0; k--) {
        if (i == 0 && j == 0 && k == 0) continue;
        dp[i][j][k] += dp[i+1][j][k]*((double)i/(i+j+k));
        dp[i][j][k] += dp[i][j+1][k]*((double)j/(i+j+k));
        dp[i][j][k] += dp[i][j][k+1]*((double)k/(i+j+k));
        dp[i][j][k] += 1;
      }
    }
  }
  printf("%.10lf\n", dp[a][b][c]);

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef stack<ll> stll;
typedef pair<ll,ll> pll;
typedef vector<vll> vvll;
typedef vector<bool> vb;

#define FOR(i,s,e) for(ll i=s;i<e;i++)
#define mp make_pair
#define pb push_back
#define fi first
#define sec second
#define in insert
#define sz size
#define ln length
#define vec vector
#define all(v) v.begin(),v.end()
#define allg(v) v.begin(),v.end(),greater<ll>()
#define nl() cout << "\n"
#define mst(a) memset(a,-1,sizeof(a))
#define endl "\n"
#define debug(z) cout << #z << "=" << z << endl
#define MAX ll(1e9+7)

void solve();

double dp[101][101][101];

double calcu(ll a,ll b,ll c){
    if(a==100 || b==100 || c==100)
        return 0;
    if(dp[a][b][c])
        return dp[a][b][c];
    double ans=0;
    ans+=(calcu(a+1,b,c)+1)*a/(a+b+c);
    ans+=(calcu(a,b+1,c)+1)*b/(a+b+c);
    ans+=(calcu(a,b,c+1)+1)*c/(a+b+c);
    return dp[a][b][c]=ans;
}

void solve(){
    ll a[3];
    FOR(i,0,3){
        cin >> a[i];
    }
    printf("%.9f",calcu(a[0],a[1],a[2]));
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }

void Main(){
    int n; cin >> n;
    n = (1<<n);
    cout << n-1 << endl;
    rep3(i, 1, n-1){
        rep(j, n){
            int tmp = __builtin_popcount(i&j);
            cout << (tmp&1 ? 'B' : 'A');
        }
        cout << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int Maxx=1000001,Maxn=2001,INF=0x3f3f3f3f,Mod=1e9+7;
inline int read()
{
	int res=0,bj=0;char ch=getchar();
	while(ch<'0'||ch>'9')bj|=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
	return bj?-res:res;
}
void print(int x)
{
	if(x>9)print(x/10);
	putchar(x%10^48);
}
inline void printnum(int x,char ch)
{
	if(x<0)putchar('-'),x=-x;
	print(x),putchar(ch);
}
char S[1005],P[10]="atcoder";
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int T=read()+1,n;
	while(--T){
		scanf("%s",S),n=strlen(S);
		int ans=1e9,p=0;
		for(int i=0;i<8;++i)
		if(S[i]!=P[i]){
			if(S[i]>P[i])ans=0;
			i=8;
		}
		for(int i=0,x;i<min(7,n);++i){
			x=n;
			for(int j=i;j<n;++j)
			if(S[j]>P[i])x=j,j=n;
			if(x<n)ans=min(ans,p+x-i);
			x=n;
			for(int j=i;j<n;++j)
			if(S[j]>=P[i])x=j,j=n;
			if(x==n)break;
			p+=x-i;for(int j=x;j>i;--j)swap(S[j],S[j-1]);
		}
		cout<<(ans==1e9?-1:ans)<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	int n;
	cin>>n;
	VII dp(2,vector<ll>(n+1));
	dp[0][0] = dp[1][0] = 1;
	for(int i=1;i<=n;i++){
		string s;
		cin>>s;
		if(s == "AND"){
			dp[1][i] += dp[1][i-1];
			dp[0][i] += dp[1][i-1] + 2*dp[0][i-1];
		}else{
			dp[1][i]+=2*dp[1][i-1]+dp[0][i-1];
			dp[0][i]+=dp[0][i-1];

		}

	}
	cout<<dp[1][n];
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int SZ = 400000;
class UF {
public:
	ll P[SZ + 1];
	UF() : P() {
		rep1(i, SZ) P[i] = -(1 << 20);
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	void unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) {
			P[a]--;
			return;
		}
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
	}
} uf;
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint();
	rep(i, N) {
		int a = getint(), b = getint();
		uf.unite(a, b);
	}
	int kotae = 0;
	rep1(i, 400000) {
		ll a = -uf.P[i];
		if (a > 0) {
			kotae += (a >> 20) - 1;
			kotae += bool(a & ((1 << 20) - 1));
		}
	}
	printf("%d", kotae);

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

struct Ad{ll x, y, r, num;};
struct Recang{
    ll x1, y1, x2, y2;
    ll size(){
        return abs(x2-x1)*abs(y2-y1);
    }
};

mt19937 mt(123);
const int MAX=9999;
int n;

bool overlap(Recang a, Recang b){
    return max(a.x1,b.x1)<min(a.x2,b.x2)&&max(a.y1,b.y1)<min(a.y2,b.y2);
}

bool check(vector<Recang> ans, Recang a, int k){
    REP(i,n){
        if(i==k)
            continue;
        if(overlap(a,ans[i]))
            return 1;
    }
    return 0;
}

bool extension(vector<Recang>& ans, int i, vector<ll> weight){
    Recang& tmpr=ans[i];
    vector<bool> used(4,0);
    vector<int> perm;
    REP(i,4){
        ll sum=0;
        REP(j,4){
            if(!used[j])
                sum+=weight[j];
        }
        ll r;
        if(sum==0)
            r=-1;
        else
            r=mt()%sum;
        REP(j,4){
            if(used[j])
                continue;
            r-=weight[j];
            if(r<0){
                perm.push_back(j);
                used[j]=1;
                break;
            }
        }
    }
    REP(j,4){
        if(perm[j]==0){
            tmpr.x2++;
            if(tmpr.x2>MAX||check(ans,tmpr,i))
                tmpr.x2--;
            else
                return 1;
        }
        else if(perm[j]==1){
            tmpr.y2++;
            if(tmpr.y2>MAX||check(ans,tmpr,i))
                tmpr.y2--;
            else
                return 1;
        }
        else if(perm[j]==2){
            tmpr.x1--;
            if(tmpr.x1<0||check(ans,tmpr,i))
                tmpr.x1++;
            else
                return 1;
        }
        else{
            tmpr.y1--;
            if(tmpr.y1<0||check(ans,tmpr,i))
                tmpr.y1++;
            else
                return 1;
        }
    }
    return 0;
}

void solve(){
    cin >> n;
    vector<Ad> ads(n);
    int x, y, r;
    REP(i,n){
        cin >> x >> y >> r;
        ads[i]=Ad{x,y,r,i};
    }
    vector<vector<ll>> weight(n,vector<ll>(4,0));
    REP(i,n)REP(j,i){
        if(ads[i].x<ads[j].x){
            weight[i][0]+=ads[j].r;
            weight[j][2]+=ads[i].r;
        }
        else{
            weight[i][2]+=ads[j].r;
            weight[j][0]+=ads[i].r;
        }
        if(ads[i].y<ads[j].y){
            weight[i][1]+=ads[j].r;
            weight[j][3]+=ads[i].r;
        }
        else{
            weight[i][3]+=ads[j].r;
            weight[j][1]+=ads[i].r;
        }
    }
    REP(i,n){
        ll sum=0;
        REP(j,4)
            sum+=weight[i][j];
        REP(j,4)
            weight[i][j]=sum-weight[i][j];
    }
    vector<Recang> ans(n);
    REP(i,n){
        Ad ad=ads[i];
        ans[i]={ad.x,ad.y,ad.x+1,ad.y+1};
    }
    priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> que;
    REP(i,n) que.push({(double)1/ads[i].r,i});
    while(!que.empty()){
        int i=que.top().second;
        que.pop();
        if(extension(ans,i,weight[i])){
            if(ans[i].size()<ads[i].r)
                que.push({(double)ans[i].size()/ads[i].r,i});
        }
    }
    REP(i,n){
        Recang tmpr=ans[i];
        cout << tmpr.x1 << " ";
        cout << tmpr.y1 << " ";
        cout << tmpr.x2 << " ";
        cout << tmpr.y2 << endl;
    }
}

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

#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template <class T>
void CVEC(const T &v) {
	int c = v.size() - 1;
	for (int i = 0; i < c; i++) cout << v[i] << ' ';
	if (c > -1) cout << v[c];
	cout << '\n';
}

#pragma endregion header

int XMAX = 10000;
int YMAX = 10000;

struct Rectangle{
	int a, b, c, d;
};

struct Point{
	int id, x, y, r;
	bool operator<( const Point& right ) const {
        return x == right.x ? y < right.y : x < right.x;
    }
};

void COUT(Rectangle	x){
	cout << x.a << " " << x.b << " " << x.c << " " << x.d << endl;
}

int n;
set<P> occupied;
vector<int> area(n, 0);

signed main(){
    cin >> n;
	vector<Point> Ps;
	map<int, Rectangle> ans;
	rep(i,n){
		int x, y, r; cin >> x >> y >> r;
		Ps.push_back({i, x, y, r});
	}
	sort(ALL(Ps));
	/*
	rep(i,n){
		int a = Ps[i].x;//x
		int b = Ps[i].y;//y
		int r = Ps[i].r;
		cout << a << " " << b << " " << r << endl;
	}
	*/
	rep(i,n){
		int x = Ps[i].x;
		int y = Ps[i].y;
		int id = Ps[i].id;
		if(i == 0) ans[id] = {0, 0, x+1, y+1};
		else if(i == n-1) ans[id] = {x, y, XMAX, YMAX};
		else ans[id] = {x, y, x+2, y+2};
	}
	rep(i,n){
		COUT(ans[i]);
	}
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int A,B;
  cin>>A>>B;
  if(B < 2*A + 100)
  {
    cout<<2*A + 100 - B<<"\n";
  }
  else
  {
    cout<<0<<"\n";
  }
}

#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vvv(t) vector<vector<vector<t>>>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll A, B;
    cin >> A >> B;
    ll res = 2 * A + 100 - B;
    cout << res <<endl;

}

int main(){
    Main();
}


#include<bits/stdc++.h>
using namespace std;
int Large_digit(int a,int b){
    int sum1=0,sum2=0;
   while(a!=0){
    int r=a%10;
    sum1+=r;
    a/=10;
   }
   while(b!=0){
    int p=b%10;
    sum2+=p;
    b/=10;
   }
   return max(sum1,sum2);
}
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<Large_digit(a,b)<<endl;
}

#include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef  long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define fastttt ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define p_q priority_queue
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define vii vector <pair<ll,ll>>
#define pii pair<ll,ll>
#define vi vector <ll>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll fact[250005],fact_inv[250005];

ll power(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
}

void pre(){
    fact[0]=1;
    fact_inv[0]=1;
    for(int i=1;i<250005;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        fact_inv[i]=power(fact[i],mod-2);
    }
}
ll ncr(ll n,ll r){
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
    //return x;
}
ll mod_inverse(ll x){
    return power(x,mod-2);
}

bool sortbysec(const pair<ll,ll> &a,
              const pair<ll,ll> &b)
{
    return (a.second < b.second);
}

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
#define nx 100005

//before dp think greedy
/***************************code begins here*****************************/

class solver{
	public:

	ll f(ll x)
	{
		ll s=0;
		while(x!=0)
		{
			s+=x%10;
			x=x/10;
		}
		return s;
	}

	void solve()
	{
		ll a,b;cin>>a>>b;
		cout<<max(f(a),f(b));
	}
};

int main(){
	fastttt
	//	cout<<fixed<<setprecision(10);

	int test=1,c=1;
	//pre();
	//cin>>test;
	while(test--){
		//cout<<"Case #"<<c<<": ";c++;
		solver o;
		o.solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    vector<string> S(3);
    rep(i,3) cin >> S[i];

    map<char,bool> used;
    rep(i,3) rep(j,S[i].size()) used[S[i][j]] = true;

    if (used.size()>10) Cout("UNSOLVABLE");

    vector<ll> num(10);
    rep(i,10) num[i] = i;

    do {
        map<char,ll> id;
        ll index = 0;
        for (auto p : used) {
            id[p.first] = num[index];
            index++;
        }

        vector<ll> N(3);
        bool NG = false;
        rep(i,3) {
            if (id[S[i][0]]==0) NG = true;
            rep(j,S[i].size()) N[i] = N[i]*10 + id[S[i][j]];
        }
        if (NG) continue;
        if (N[0]+N[1]==N[2]) {
            rep(i,3) cout << N[i] << endl;
            return 0;
        }
    } while (next_permutation(all(num)));

    Cout("UNSOLVABLE");
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (m); i < (int)(n); i++)
using ll = long long;

ll solve(ll b, ll c) {
    if (b == 0) return 1 + c / 2 + (c - 1) / 2;
    ll ret = 2;
    if (b > 0) ret += (c - 1) / 2 + (c - 2) / 2;
    else ret += c / 2 + (c - 1) / 2;

    if (b < 0) {
        b *= -1;
        c--;
    }
    ll l = max(-b + 1, b - c / 2);
    ll r = min(b, (c - 1) / 2 - b + 1);
    if (l <= r) ret += 2 * b - 1;
    else ret += (b - l) + (b + r - 1);
    return ret;
}

int main() {
    // input
    ll B, C;
    cin >> B >> C;

    //solve
    ll ans = solve(B, C);
    cout << ans << endl;
}


//红太阳zhouakngyang txdy!
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read()
{
	int sum=0,nega=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
	while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
	return sum*nega;
}
int n,L=500001,R=500000,flag,top;
char a[500009],ans[1000009],res[1000009];
char out[1000009];
int main()
{
	scanf("%s",a+1);n=strlen(a+1);
	for(int i=1;i<=n;i++)
	{
		if(a[i]=='R')flag^=1;
		else
		{
			if(flag)L--,res[L]=a[i];
			else R++,res[R]=a[i];
		}
	}
	if(!flag)
		for(int i=1;i<=R-L+1;i++)ans[i]=res[i+L-1];
	else
		for(int i=1;i<=R-L+1;i++)ans[i]=res[R+1-i];
	for(int i=1;i<=R-L+1;i++)
	{
		out[++top]=ans[i];
		while(top!=0&&out[top]==out[top-1])top-=2;
	}
	for(int i=1;i<=top;i++)putchar(out[i]);
	return 0;

}

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  deque<char> t;
  bool f = 1;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'R'){
      f = !f;
    }else if(t.empty()){
      t.push_back(s.at(i));
    }else if(f){
       if(s.at(i) != t.back()){
         t.push_back(s.at(i));
       }else{
         t.pop_back();
       }
    }else if(!f){
       if(s.at(i) != t.front()){
         t.push_front(s.at(i));
       }else{
         t.pop_front();
       }
    }
  }
  if(!f){
    for(int i = t.size() - 1; i >= 0; i--){
      cout << t.at(i);
    }
  }else{
    for(int i = 0; i < t.size(); i++){
      cout << t.at(i);
    }
  }
}


#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
double a,b;
cin>>a>>b;
cout<<100*(1-(b/a));
return 0;
}

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;
using Graph = vector<vector<int>>;

int main(){
    ll n, k;   cin >> n >> k;
    ll ans = 0;
    k = abs(k);
    for(int i=k+2; i<=2*n; i++){
        ll tmp;
        if(i > n + 1) tmp = 2*n - i + 1;
        else    tmp = i - 1;
        if(i - k > n + 1) tmp *= (2*n - (i - k) + 1);
        else    tmp *= (i - k - 1);
        ans += tmp;
    }
    print(ans);
}


#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n, m; cin >> n >> m;
    unordered_set<int> a, b;

    int curr;
    for (int i = 0; i < n; ++i) {
        cin >> curr;
        a.insert(curr);
    }
    for (int i = 0; i < m; ++i) {
        cin >> curr;
        b.insert(curr);
    }
    set<int> ans;
    for (int num : a) {
        if (b.find(num) == b.end()) {
            ans.insert(num);
        }
    }
    for (int num : b) {
        if (a.find(num) == a.end()) {
            ans.insert(num);
        }
    }
    for (int num : ans) {
        cout << num << ' ';
    }
    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

#include<bits/stdc++.h>
#define RT register
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
using namespace std;

template<typename T>
inline void read(T &x){
    x=0; bool f=0;char ch=getchar();
    while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    x=f?-x:x;
}
template<typename T>
inline void print(T x){
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
const int N=1004;
int a[N],b[N];
int n,m;
int main(){
    read(n),read(m);
    for(int i=1;i<=n;i++) read(a[i]);
    for(int i=1;i<=m;i++) read(b[i]);
    a[n+1]=b[m+1]=100000;
    for(int i=1,j=1;i<=n||j<=m;){
        if(a[i]<b[j]){
            print(a[i]),putchar(' ');i++;
        }
        else if(a[i]==b[j]){
            i++,j++;
        }
        else{
            print(b[j]),putchar(' ');j++;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int maxk = 20;
char s[maxn];
ll f[maxn][maxk];
int n, k;
inline int c(char ch) { return isdigit(ch) ? ch - '0' : ch - 'A' + 10;}
ll calc(int pos, int state, bool flag)
{
	if((!flag && state) || pos == n) return f[pos][__builtin_popcount(state)];
	ll ret = 0;
	int end = flag ? c(s[pos]) : 15;
	for(int i = 0; i <= end; ++i)
	{
		int nxtstate = (!state && !i) ? 0 : state | (1 << i);
		ret = (ret + calc(pos + 1, nxtstate, flag && (i == end))) % mod;
	}
	return ret;
}
int main()
{
	scanf("%s%d", s, &k);
	n = strlen(s);
	f[n][k] = 1;
	for(int i = n - 1; ~i; --i)
		for(int j = 0; j <= k; ++j)
			f[i][j] = (f[i + 1][j] * j % mod + f[i + 1][j + 1] * (16 - j) % mod) % mod;
	printf("%lld\n", calc(0, 0, 1));
	return 0;
}

#pragma GCC optimize(2)
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define Buff ios::sync_with_stdio(false)
#define rush() int Case = 0; int T; cin >> T;  while(T--)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define reps(i, a, b) for(int i = a; b; i ++)
#define clc(a, b) memset(a, b, sizeof(a))
#define Buff ios::sync_with_stdio(false)
#define readl(a) scanf("%lld", &a)
#define readd(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define reads(a) scanf("%s", a)
#define read(a) scanf("%d", &a)
#define lowbit(n) (n&(-n))
#define pb push_back
#define lson rt<<1
#define rson rt<<1|1
#define ls lson, l, mid
#define rs rson, mid+1, r
#define y second
#define x first
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>PII;
const double eps = 1e-6;
const int INF = 1e9 + 7;
const int N = 2007;
const int M = 1e6 + 7;
const ll mod = 1e9 + 7;
ll dp[N][N];
ll sum[4][N][N];
char a[N][N];
signed main()
{
    Buff;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> a[i][j];
    dp[1][1] = sum[1][1][1] = sum[2][1][1] = sum[3][1][1] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(a[i][j] == '#' || (i == j && j == 1))
                continue;
            else
            {
                dp[i][j] = (sum[1][i - 1][j] + sum[2][i][j - 1] + sum[3][i - 1][j - 1]) % mod;
                sum[1][i][j] = (sum[1][i - 1][j] + dp[i][j]) % mod;
                sum[2][i][j] = (sum[2][i][j - 1] + dp[i][j]) % mod;
                sum[3][i][j] = (sum[3][i - 1][j - 1] + dp[i][j]) % mod;
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<int> subtree_size, score;

void dfs(vector<vector<int>> &g, int v){
	int sum = 0;
	vector<int> vec;
	for(auto nv : g[v]){
		dfs(g, nv);
		subtree_size[v] += subtree_size[nv];
		if(subtree_size[nv]%2 == 1) vec.push_back(-score[nv]);
		else if(score[nv] < 0) score[v] -= -score[nv];
		else sum += -score[nv];
	}
	sort(vec.rbegin(), vec.rend());
	vec.push_back(sum);
	rep(i,vec.size()){
		if(i%2 == 1) score[v] += vec[i];
		else score[v] -= vec[i];
	}
}

void solve(){
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	subtree_size.assign(n, 1);
	score.assign(n, 1);
	rep(i,n-1){
		int p;
		cin >> p;
		--p;
		g[p].push_back(i+1);
	}
	dfs(g, 0);
	int ans = (n + score[0]) / 2;
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>

const int MAXN = 100005;

std::vector<int> Adj[MAXN];

std::pair<int, int> dfs(int u) {
  std::pair<int, int> ret = {1, 1};
  std::vector<int> choices[2];

  for(int j : Adj[u]) {
    std::pair<int, int> next = dfs(j);
    ret.second ^= next.second;
    choices[next.second].push_back(next.first);
  }

  int odd = choices[1].size();
  for(int i = 0; i < choices[0].size(); i++) {
    if(choices[0][i] < 0)
      ret.first += choices[0][i];
    else
      ret.first += (1 - 2*(odd%2))*choices[0][i];
  }

  std::sort(choices[1].begin(), choices[1].end());
  for(int i = 0; i < choices[1].size(); i++)
    ret.first += (1 - 2*(i%2))*choices[1][i];

  return ret;
}

signed main() {
  int n;
  std::cin >> n;

  for(int i = 1; i < n; i++) {
    int p;
    std::cin >> p;
    p--;
    Adj[p].push_back(i);
  }

  std::cout << (dfs(0).first + n)/2 << std::endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using ml = map<ll, ll>;
using vl = vector<ll>;
using vp = vector<pl>;
using vvl = vector<vl>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define fore(i_in,a) for (auto& i_in: a)
#define forp(x,y,a) for(auto& [x, y]: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define CEIL(a, b) (a+b-1)/b;
#define offset_FLOOR(a, b) (a-1)/b;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<(int)v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }

ll n, ans;
string s;

int main() {
    fio(); cin>>n;
    vvl dp(n+1, vl(2, 0));
    dp[0][0]=1;dp[0][1]=1;
    rep(i,n) {
        cin>>s;
        if (s=="OR") {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][0] + 2 * dp[i][1];
        }
        else {
            dp[i+1][0] = 2 * dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][1];
        }
    }
    print(dp[n][1]);
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#include<queue>
#include<deque>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
inline int read(){
	int x=0;
	bool f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	if(f){
		return -x;
	}
	return x;
}
inline uint readu(){
	uint x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x;
}
void fp(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
char a[500005],t[1000005],tt[500005];
bool b[1000005];
int main(){
    //fp();
    int i,len,zz=500000,zz1=499999,fz=1,zz2=1;
	scanf("%s",a+1);
	len=strlen(a+1);
	for(i=1;i<=len;i++){
		if(a[i]=='R'){
			fz^=1;
		}
		else{
			if(fz){
				t[++zz1]=a[i];
			}
			else{
				t[--zz]=a[i];
			}
		}
	}
	if(!fz){
		for(i=zz1;i>=zz;i--){
		if(tt[zz2]==t[i]){
			zz2--;
		}
		else{
			tt[++zz2]=t[i];
		}
	}
	for(i=2;i<=zz2;i++){
		printf("%c",tt[i]);
	}
	return 0;
	}
	for(i=zz;i<=zz1;i++){
		if(tt[zz2]==t[i]){
			zz2--;
		}
		else{
			tt[++zz2]=t[i];
		}
	}
	for(i=2;i<=zz2;i++){
		printf("%c",tt[i]);
    }
    return 0;
}


// Problem: A - ABC Preparation
// Contest: AtCoder - AtCoder Beginner Contest 185
// URL: https://atcoder.jp/contests/abc185/tasks/abc185_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;

struct splitmix64_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;

template <typename K, typename Hash = splitmix64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(min(a, b), min(c, d));
	return 0;
}

#include<iostream>
using namespace std;

int main(){

    int V, T, S, D;

    cin >> V >> T >> S >> D;

    if(D / V >= T && S >= ((D + (V-1))/ V)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <time.h>
#include <queue>
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define forr(i,a,n) for(ll i=a;i<n;i++)
#define ford(i,a,n) for(ll i=n-1;i>=a;i--)
#define all(v) v.begin(),v.end()
#define testc  ll ts;\
               cin>>ts;\
               while(ts--)
#define arn ll n;\
            cin>>n;\
            ll a[n];\
            forr(i,0,n)cin>>a[i];\

#define arr(a,n) ll a[n];\
                 forr(i,0,n)cin>>a[i];\

#define sss <<" "<<
#define nnn <<"\n"
#define nl cout<<"\n";
#define prtitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)cout<<*itr<<" ";
#define fitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)
using namespace std;
ll M=1e9+7;
ll cdiv(ll a,ll b){
    return (a%b==0)?a/b:a/b+1;
}
ll myMod(ll a, ll b){
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll ModPow(ll a,ll b,ll M)
{
    if(M==1)return 0;
    a%=M;
    ll ans=1,t=1;
    while(t>0&&t<=b)
    {
        if(t&b)
        {
            ans*=a;
            ans%=M;
        }
        t<<=1;
        a*=a;
        a%=M;
    }
    return ans;
}

ll Pow(ll a,ll b)
{
    if(M==1)return 0;
    ll ans=1,t=1;
    while(t>0&&t<=b)
    {
        if(t&b)
        {
            ans*=a;
        }
        t<<=1;
        a*=a;
    }
    return ans;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int countSetBits(int n)
{
    int count = 0;
    while (n > 0)
    {
        count++;
        n &= (n-1);
    }
    return count;
}

// Function that return count of
// flipped number
int FlippedCount(int a, int b)
{
    // Return count of set bits in
    // a XOR b
    return countSetBits(a^b);
}

struct Point{
    int x,y;
};

bool isPrime(ll n){
    if (n <= 1)
        return false;
    for (ll i = 2; i*i <= n; i++)
        if (n % i == 0)
            return false;
    return true;
}
ll modInverse(ll n, ll p)
{
    return ModPow(n, p - 2, p);
}

ll nCrModP(ll n, ll r, ll p)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;

    ll fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p
            * modInverse(fac[n - r], p) % p)
           % p;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

       ll n;
       cin>>n;
       ll a[n],b[n];
       forr(i,0,n)cin>>a[i];
       forr(i,0,n)cin>>b[i];
       ll mxa=-1,mxp=-1;
       forr(i,0,n){
           mxa=max(a[i],mxa);
           mxp=max(mxp,b[i]*mxa);
           cout<<mxp nnn;
       }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main()
{

    int n;cin>>n;
    ll arr[n+3],arr1[n+3];
    for(int i=0;i<n;i++)cin>>arr[i];
    for(int j=0;j<n;j++)cin>>arr1[j];
    ll prev=-1,mx=0;
    for(int i=0;i<n;i++)
    {
        mx=max(mx,arr[i]);
        ll k=(arr[i]*arr1[i]);
        prev=max(prev,k);
        if(i>0)
        {
           prev=max(mx*arr1[i],prev);
        }
        cout<<prev<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define all(v) v.begin(),v.end()
#define  mat vector<vector<ll>>
#define el cout<<'\n';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double slope( pair<ll,ll>&a,pair<ll,ll>&b){
     return ((double)(b.ss-a.ss))/((double)(b.ff-a.ff));

}
void solve(){

     ll n ;
     cin>>n;
    //  map<string,int>mp;
    //  string ans="satisfiable";
    //  fr(i,0,n){
    //      string s;
    //      cin>>s;
    //      if(s[0]=='!' && mp.count(s.substr(1)))
    //      ans=s.substr(1);
    //      else if(mp.count("!"+s))
    //      ans=s;
    //     mp[s]++;

    //  }
    //  cout<<ans;
    vector<pair<ll,ll>>v(n);
    fr(i,0,n)
    cin>>v[i].ff>>v[i].ss;
    ll ans=0;
    fr(i,0,n){
        for(int j=i+1;j<n;j++){
                double slp=slope(v[i],v[j]);
                if(slp<=1 && slp>=-1)
                ans++;
        }
    }
     cout<<ans;
}

int main(){
 boost
 ll t=1;
// cin>>t;

    while(t--){
      solve();
   el
        }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,L,R) for(int i=L;i<R;i++)
using namespace std;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<vector<int>> Graph;
typedef vector<string> Grid;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}

//#define DEBUG

//declaration area

//struct area

//function area

//main area
int main(){
    int h, m;
    cin >> h >> m;
    cout << (m%h==0 ? "Yes":"No") << endl;
}
/*

*/

#include <bits/stdc++.h>
using namespace std;
int m,h;
int main()
{
    cin>>m>>h;
    if(h%m==0) cout<<"Yes";
    else cout<<"No";
}


#include<bits/stdc++.h>
// using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
// using namespace atcoder;
#endif
#define int long long

#pragma region header

#pragma region alias

using lint = long long;
using ll = long long;
using P = std::pair<int,int>;
template<class T> using prique = std::priority_queue<T,std::vector<T>,std::greater<T>>;

#pragma endregion

#pragma region macros

#define rep(i, n) for(int i = 0;i<(int)(n);i++)
#define REP(i, m, n) for(int i = (m);i<(int)(n);i++)
#define drep(i, n) for(int i = (n)-1;i>=0;i--)
#define DREP(i, m, n) for(int i = (m)-1;i>=(int)(n);i--)
#define all(v) (v).begin(),(v).end()
#define reall(v) (v).rbegin(),(v).rend()

template<class T, class U>
bool chmax(T& a,const U b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T, class U>
bool chmin(T& a,const U b) {
    if(a>b) {
        a = b;
        return true;
    }
    return false;
}

std::map<int,int> prime_div(int n) {
    std::map<int,int> mp;
    if(~n&1) while(~n&1) n>>=1,mp[2]++;
    for(int i = 3;i<=std::sqrt(n);i+=2) {
        if(n%i==0) {
            while(n%i==0) {
                n/=i;
                mp[i]++;
            }
        }
    }
    if(n!=1) mp[n]++;
    return mp;
}

#pragma endregion

#pragma region constant

constexpr long long inf = 1LL << 61;
constexpr int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
constexpr int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
constexpr long long mod = 1e9+7;
constexpr long long MOD = 998244353;

#pragma endregion

#pragma region inout

template<class T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) {
    for(int i = 0; i < (int)(v.size()); i++) {
        stream << v[i];
        if(i != (int)(v.size()) - 1) stream << ' ';
    }
    return stream;
}

template<typename Itr>
inline void print(const Itr& begin, const Itr& end, bool endline = true, const char* BEGIN = "{", const char* mid = ", ", const char* END = "}") {
    if(begin == end) return;
    std::cout << BEGIN << *begin;
    for(Itr itr = begin+1; itr < end; itr++) std::cout << mid << *itr;
    std::cout << END;
    if(endline) std::endl(std::cout);
    return;
}

template<class T>
std::istream& operator>>(std::istream& stream, std::vector<T>& v) {
    for(T& p:v) stream >> p;
    return stream;
}

template<typename Itr>
inline void input(Itr begin, Itr end) {
    for(Itr& itr = begin; itr < end; itr++) std::cin >> *itr;
    return;
}

template<class T, class U>
std::ostream& operator<<(std::ostream& stream, const std::pair<T,U>& pair) {
    return stream << pair.first << ' ' << pair.second;
}

template<class T, class U>
inline void print(const std::pair<T,U>& pair,const bool endline = true, const char* begin = "(", const char* mid = ", ", const char* end = ")") {
    std::cout << begin << pair.first << mid << pair.second << end;
    if(endline) std::endl(std::cout);
    else std::cout << ' ';
    return;
}

template<class T, class U>
std::istream& operator>>(std::istream& stream, std::pair<T,U>& pair) {
    return stream >> pair.first >> pair.second;
}

template<class T, class U>
inline void input(std::pair<T,U>& pair, const bool first = true, const bool second = true) {
    if(first) std::cin >> pair.first;
    if(second) std::cin >> pair.second;
}

#pragma endregion

#pragma region DEBUG

#ifdef _DEBUG
#define debug(x) do{std::cout << #x << ": ";view(x);}while(0);
#else
#define debug(x)
#endif

template<class T> inline void view(const T& x) {
    std::cout << x << std::endl;
}

template<class T> inline void view(const std::vector<T>& v) {
    print(all(v));
}

#pragma endregion

#pragma endregion

signed main() {
    int n;
    std::cin >> n;
    long double ans = 0;
    for(int i = n-1;i>=1;i--) ans+=(double)n/i;
    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
    return 0;
}

#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e7+7;

const int N=1e5+10;
double dp[N];
bool vis[N];
ll n;

double go(ll pos){
    if(pos==n) return 0;
    if(vis[pos])
        return dp[pos];
    vis[pos]=true;
    ll ans=0;
    dp[pos] = (double)((double)1 + (double)pos/n*go(pos+1)) / ((double)pos/n);
    return dp[pos];
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    cin>>n;
    cout<<fixed<<setprecision(10);
    cout<<go(1);

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll h,w;
vector<vector<char>> t(2010,vector<char>(2010));
int roty[2]={1,0},rotx[2]={0,1};

int main(void){
    cin>>h>>w;
    rep(i,h)rep(j,w){
        cin>>t[i][j];
    }
    vector<vector<ll>> d(h,vector<ll>(w,0));
    for(int y=h-1;y>=0;y--){
        for(int x=w-1;x>=0;x--){
            ll tot=-1e9;
            if(y==h-1&&x==w-1){
                d[y][x]=0;
                continue;
            }
            rep(k,2){
                ll ny=y+roty[k],nx=x+rotx[k];
                if(ny<0||ny>=h||nx<0||nx>=w)continue;
                ll buf=(t[ny][nx]=='+')? 1:-1;
                buf-=d[ny][nx];
                chmax(tot,buf);
            }
            d[y][x]=tot;
        }
    }
    ll res=d[0][0];
    if(res>0)cout<<"Takahashi"<<endl;
    else if(res==0)cout<<"Draw"<<endl;
    else cout<<"Aoki"<<endl;
}

#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

string x;
ull m;

bool solve(ull mid){
    ull curr = 0;
    ull pow = 1;
    RREP(i, SZ(x)){
        if (pow > m) return 0;
        curr += (ull)((ull)x[i] - '0') * pow;
        if (curr > m) return 0;
        pow = pow * mid;
    }
    return 1;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
    cin >> x >> m;
    if (SZ(x) == 1){
        if (stoll(x) > m){
            cout << 0 << endl;
        }
        else cout << 1 << endl;
        return 0;
    }
    int d = 0;
    REP(i, SZ(x)){
        d = max(d, (int)x[i] - '0');
    }
    ull lo = d + 1, hi = 10e18, mid, ans = d;
    while (lo <= hi){
        mid = (lo + hi) / 2;
        if (solve(mid)){
            lo = mid + 1;
            ans = max(ans, mid);
        }
        else hi = mid - 1;
    }
    cout << ans - d << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;
}


#include<bits/stdc++.h>
//#include <atcoder/all>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
//using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
//using mint = modint998244353;

const ll ZER = 0;
const ll MOD =  998244353 ;

// UnionFind木(サイズ持ち)
class UnionFind {
    public :

        vector<int> par;

        UnionFind(int N){
            par = vector<int>(N, -1);
        }

        int parent(int x){
            return par[x];
        }

        int root(int x){
            if(par[x] < 0)return x;
            return par[x] = root(par[x]);
        }

        int size(int x){
            return -par[root(x)];
        }

        void merge(int x, int y){
            int rx = root(x);
            int ry = root(y);
            if(rx == ry)return;

            if(size(rx) < size(ry))swap(rx, ry);

            par[rx] += par[ry];
            par[ry] = rx;

            return;
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, K;
    cin >> n >> K;
    vector<ll> fac(1001, 1);
    REP(i, 2, 1000){
        fac[i] = fac[i - 1] * i;
        fac[i] %= MOD;
    }
    vector<vector<int>> a(n, vector<int>(n));
    rep(i, n)rep(j, n)cin >> a[i][j];
    UnionFind uf1(n), uf2(n);;
    rep(i, n){
        REP(j, i + 1, n - 1){
            bool f = true;
            rep(k, n){
                if(a[i][k] + a[j][k] > K)f = false;
            }
            if(f)uf1.merge(i, j);
        }
    }
    rep(i, n){
        REP(j, i + 1, n - 1){
            bool f = true;
            rep(k, n){
                if(a[k][i] + a[k][j] > K)f = false;
            }
            if(f)uf2.merge(i, j);
        }
    }
    ll tate = 1;
    vector<bool> se1(n, false);
    rep(i, n){
        if(se1[uf1.root(i)])continue;
        tate *= fac[uf1.size(i)];
        tate %= MOD;
        se1[uf1.root(i)] = true;
    }
    ll yoko = 1;
    vector<bool> se2(n, false);
    rep(i, n){
        if(se2[uf2.root(i)])continue;
        yoko *= fac[uf2.size(i)];
        yoko %= MOD;
        se2[uf2.root(i)] = true;
    }
    ll res = tate * yoko % MOD;
    cout << res << endl;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353;
const int N = 55;
int n, k, a[N][N], fac[N], far[N], s1[N], s2[N], flag[N];
ll ans = 1;
int find1(int x) {
	return far[x] == x ? x : far[x] = find1(far[x]);
}
int find2(int x) {
	return fac[x] == x ? x : fac[x] = find2(fac[x]);
}
int main() {
	cin>>n>>k;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) cin>>a[i][j];
	for (int i = 1; i <= n; i++) far[i] = fac[i] = i, s1[i] = s2[i] = 1;
	for (int r1 = 1; r1 <= n; r1++)
		for (int r2 = r1 + 1; r2 <= n; r2++) {
			bool flag = true;
			for (int j = 1; j <= n; j++)
				if (a[r1][j] + a[r2][j] > k) flag = false;
			if (flag)
				if (find1(r1) != find1(r2)) s1[find1(r2)] += s1[find1(r1)], far[find1(r1)] = find1(r2);
		}
	for (int c1 = 1; c1 <= n; c1++)
		for (int c2 = c1 + 1; c2 <= n; c2++) {
			bool flag = true;
			for (int i = 1; i <= n; i++)
				if (a[i][c1] + a[i][c2] > k) flag = false;
			if (flag)
				if (find2(c1) != find2(c2)) s2[find2(c2)] += s2[find2(c1)], fac[find2(c1)] = find2(c2);
		}
	for (int i = 1; i <= n; i++)
		if (!flag[find1(i)]) {
			flag[find1(i)] = 1;
			for (int j = 2; j <= s1[find1(i)]; j++)
				ans = ans * j % mod;
		}
	for (int i = 1; i <= n; i++) flag[i] = 0;
	for (int i = 1; i <= n; i++)
		if (!flag[find2(i)]) {
			flag[find2(i)] = 1;
			for (int j = 1; j <= s2[find2(i)]; j++)
				ans = ans * j % mod;
		}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define MOD 1000000007
// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int N;
vector<vector<int>> es;
vector<int> A,B;
vector<int> depth;
vector<ll> dp;

void DepthDFS(int a, int d) {
  depth[a]=d;
  for (int  next : es[a]) {
    if(depth[next]==-1) {
      DepthDFS(next,d+1);
    }
  }
}
void ImosDFS(int a, long now) {
  now += dp[a];
  dp[a] = now;
  for (int  next : es[a]) {
    if(depth[next] > depth[a]) {
      ImosDFS(next,now);
    }
  }
}
int main(void) {
  cin >> N;
  es.resize(N);
  A.resize(N);
  B.resize(N);
  depth.resize(N,-1);
  dp.resize(N,0);

  rep(i,N-1) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    es[A[i]].push_back(B[i]);
    es[B[i]].push_back(A[i]);
  }
  DepthDFS(0,0);

  int Q;
  cin >> Q;
  rep(i,Q) {
    int t,e,x;
    cin >> t >> e >> x;
    e--;

    int va,vb;
    if (t==1) {
      va = A[e];
      vb = B[e];
    } else {
      va = B[e];
      vb = A[e];
    }

    if(depth[va] < depth[vb]) {
      dp[0] += x;
      dp[vb] -= x;
    } else {
      dp[va] += x;
    }
  }
  ImosDFS(0,0);
  rep(i,N) {
    cout << dp[i] << endl;
  }
}

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 2e5;
vector<int> adj[MAXN];
int par[MAXN];
int nbSommets;
int id[MAXN];
bool onPath[MAXN];
int cnt;

int getFurthest(int source) {
  vector<int> dis(nbSommets, -1);
  dis[source] = 0;
  queue<int> q;
  q.push(source);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : adj[u])
      if (dis[v] == -1) {
        dis[v] = dis[u] + 1;
        par[v] = u;
        q.push(v);
      }
  }
  int sol = 0;
  for (int i(0); i < nbSommets; ++i)
    if (dis[i] > dis[sol])
      sol = i;
  return sol;
}

void dfs(int u, int p) {
  id[u] = ++cnt;
  for (auto v : adj[u])
    if (v != p and !onPath[v])
      dfs(v, u);
  for (auto v : adj[u])
    if (v != p and onPath[v])
      dfs(v, u);
  ++cnt;
}

signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> nbSommets;
  for (int i = 0; i < nbSommets - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int s = getFurthest(0);
  int t = getFurthest(s);
  while (1) {
    onPath[t] = true;
    if (t == s)
      break;
    t = par[t];
  }
  dfs(s, s);
  for (int i = 0; i < nbSommets; ++i) {
    cout << id[i] << ' ';
  }
  cout << endl;
}


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main(void) {
  int x;
  cin >> x;
  int ans = x >= 0 ? x : 0;
  cout << ans << endl;
}

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define  ff      first
#define  ss      second
#define  pb      push_back
#define  ll      long long
#define  MX      100005
#define  inf     INT_MAX
#define  mod     1000000007
#define  endl    "\n"

#define  W(t)            while(t--)
#define  gcd(a,b)        __gcd(a,b)
#define  lcm(a,b)        (a*b)/gcd(a,b)
#define  all(v)          v.begin(),v.end()
#define  clr(a,x)        memset(a,x,sizeof(a))
#define  rep(i,a,b)      for(i = a; i <= b; i++)
#define  irep(i,b,a)     for(i = b; i >= a; i--)
#define  IOS             ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;

int main()
{
   IOS
   ll n,x;
   string s;

   cin >> x;
   cout << (x < 0?0:x);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
    int n; read(n);
    vi a(n), b(n);
    rep(i, n) read(a[i], b[i]);
    int ans = INF;
    rep(i, n) repa(j, i + 1, n) chkmin(ans, max(a[i], b[j])), chkmin(ans, max(a[j], b[i]));
    rep(i, n) chkmin(ans, a[i] + b[i]);
    println(ans);
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;
}

#include<iostream>
using namespace std;
//n是电量上线，m是到咖啡馆的次数，t是归家时间，power是当前电量，a、b分别是进入、离开咖啡馆的次数
int n,m,t;
int power;
int a[1005],b[1005];
int main()
{
	cin>>n>>m>>t;
	//设定初始变量
	power=n;
	for(int i=1;i<=m;i++)//因为M是1000，最小，一定是用来用的
		{
		//读入a，b
		cin>>a[i]>>b[i];
		//求出上一次离开后花了多少电
		int temp1=a[i]-b[i-1];
		power=power-temp1;
		if(power<=0)
			{
			cout<<"No";
			return 0;
			}
		//然后加上充进去的电量
		int temp2=b[i]-a[i];
		power=min(power+temp2,n);
		}
	//加上归家路上耗费的电量
	int tmp=t-b[m];
	power=power-tmp;
	if(power<=0)
		{
		cout<<"No";
		return 0;
		}
	//如果没有在途中被“0”拦截，就不会有“0”
	cout<<"Yes"<<endl;
	return 0;
}


/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
/* 重ならないように置く　でかい四角を縦線か横線で区切ったとき、2つの四角形にぶつからずに区切れるか? */
/* 1つのパターンで沢山区切れるので単純にやると重複が沢山出るが、
 * 片方の四角形を基準に線を引いてそれで考えればよい */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>

const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD(n)   n=n%MOD;if(n < 0){n += MOD;}

int main()
{
	ll N;
	std::cin >> N;
	std::vector<ll> A(N, 0);

	ll ans = 0;
	ll zahyo = 0;

	ll all_mv = 0;
	ll max_point = 0;
	rep(i, N)
	{
		ll pre_all_mv = all_mv;
		ll now = 0;
		std::cin >> now;

		// 一番動いた位置
		ll max = zahyo + max_point;
		ans = std::max(ans, max);

		all_mv += now;
		if(all_mv > max_point)
		{
			max_point = all_mv;
		}

		// 最後の位置
		zahyo += pre_all_mv;
		zahyo += now;

		ans = std::max(ans, zahyo);
	}

	std::cout << ans;

	return 0;
}

#include<bits/stdc++.h>
#include<iomanip>
/*
#include<atcoder/all>
using namespace atcoder;
*/
using namespace std;
#define REP(i,n) for(int i = 0;i < n;i++)
#define RNG(i,s,n) for(int i = s;i <= n;i++)
#define _RNG(i,e,s) for(int i = e;i >= s;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dup(x,y) (x + y - 1) / (y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define lb(x,key) lower_bound(all(x) , (key))
#define ub(x,key) upper_bound(all(x) , (key))
#define _size(v) int((v).size())
#define prt(x) cout << x << '\n'
#define re return
#define re0 return 0
#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type,vector<type>,greater<type>>

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
  cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
  return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
  cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
  return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
  for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
  cin >> p.first >> p.second; return in;
}

#define F first
#define S second
/********************************************************************************/
/* BE CAREFUL : OVERFLOW / MIN&MAX OF THE CONSTRAINTS / INDEX LABELING!! */

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);

  int n;cin >> n;
  vl a(n);cin >> a;
  vl add(n),addmax(n);
  REP(i,n){
    if(i==0){
      add[i] = a[i];
      addmax[i] = a[i];
    }else{
      add[i] = add[i-1] + a[i];
      if(add[i] > addmax[i-1]){
        addmax[i] = add[i];
      }else{
        addmax[i] = addmax[i-1];
      }
    }
  }

  ll max_pos = 0;
  ll cur = 0;
  REP(i,n){
    chmax(max_pos,cur + addmax[i]);
    cur += add[i];
  }
  cout << max_pos << '\n';

  return 0;
}