#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("inline")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #define DEBUG

#ifdef DEBUG
#pragma region
#endif

using namespace std;
#define LL long long
#define PII pair<int, int>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define newl '\n'
#ifdef DEBUG
#define debug(...) cerr << '[', _debug(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9;

template <typename T>
void _debug(T a) {
  cerr << a << ']' << endl;
}

template <typename T, typename... Args>
void _debug(T a, Args... args) {
  cerr << a << ", ";
  _debug(args...);
}

#ifdef DEBUG
#pragma endregion
#endif

string s;
int a[10];

void solve() {
  cin >> s;
  for (char c : s) {
    ++a[c - '0'];
  }
  if (s == "8") {
    cout << "Yes";
    return;
  }
  for (int i = 12; i < 100; i += 4) {
    int ten = i / 10, digit = i % 10;
    if (a[ten] >= 1) {
      --a[ten];
      if (a[digit] >= 1) {
        debug(ten, digit);
        --a[digit];

        if (s.size() == 2) {
          cout << "Yes";
          return;
        } else {
          if (i % 8 == 0) {
            if (a[2] >= 1 || a[4] >= 1 || a[6] >= 1 || a[8] >= 1) {
              cout << "Yes";
              return;
            }
          } else {
            if (a[1] >= 1 || a[3] >= 1 || a[5] >= 1 || a[7] >= 1 || a[9] >= 1) {
              cout << "Yes";
              return;
            }
          }
        }

        ++a[digit];
      }
      ++a[ten];
    }
  }
  cout << "No";
}

int main() {
  // freopen("live.in", "r", stdin);
  // freopen("live.out", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // cout << fixed << setprecision(7);
  // int n;
  // cin >> n;
  // rep(i, n)
  //     //
  solve();
  cout << flush;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

#define MX 200002
int dp[MX];
void solve()
{
int n;
cin>>n;
if(n<0)
    cout<<0<<endl;
else
    cout<<n<<endl;

}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
while(t--)
{
solve();
}
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
  cin>>x;
  cout<<max(0,x);
return 0;}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
#define readFast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fin cin
#define ll long long
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define output(x) ((int)x && cout << "YES\n") || cout << "NO\n";
#define ld long double
using namespace std;

#ifdef LOCAL
#define read() ifstream fin("date.in.txt")
#else
#define read() readFast
#endif // LOCAL

const int N = 3e5 + 5;
const ll MOD = 998244353;
long double n;

int main() {
    read();
    fin >> n;

    long double act = 0;
    for (double i = 1; i < n; ++i) {
        act += n / i;
    }
    cout << setprecision(6) << fixed << act;

    return 0;
}  /*stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
~Benq~*/

// Problem: D - Journey
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const int max_n = 1e5 + 9;
const int mod = 1e9 + 7;
const int inf = 1e9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	int n;
	cin >> n;

	long double dp[n+1];
	dp[n] = 0;
	for(int i = n-1 ; i >= 1 ; i--) {
		dp[i] = dp[i+1] + (1.0*n)/(n-i);
	}

	cout << fixed << setprecision(11) << dp[1] << "\n";
}
signed main(){
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ; i++){
		solve();
	}
}


/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Camels and Bridge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 8;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;

/* typedef */

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

/* global variables */

int wis[MAX_N], ps[MAX_N], cls[MAX_N];
int vs[MAX_M], mls[MAX_M + 1];
pii vls[MAX_M];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) scanf("%d", wis + i);
  sort(wis, wis + n);

  for (int i = 0; i < m; i++)
    scanf("%d%d", &vls[i].second, &vls[i].first);
  sort(vls, vls + m);

  if (wis[0] > vls[0].first) { puts("-1"); return 0; }

  for (int i = 0; i < m; i++) vs[i] = vls[i].first;

  mls[0] = 0;
  for (int i = 0; i < m; i++) mls[i + 1] = max(mls[i], vls[i].second);

  for (int i = 0; i < n; i++) ps[i] = i;

  ll minl = LINF;
  do {
    cls[0] = 0;
    for (int i = 1; i < n; i++) {
      int wsum = wis[ps[i]];
      ll lsum = 0;
      cls[i] = 0;
      for (int j = i - 1; j >= 0; j--) {
	wsum += wis[ps[j]];
	int k = lower_bound(vs, vs + m, wsum) - vs;
	if (mls[k] > lsum + cls[i]) cls[i] = mls[k] - lsum;
	lsum += cls[j];
      }
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) sum += cls[i];
    if (minl > sum) minl = sum;
  } while (next_permutation(ps, ps + n));

  printf("%lld\n", minl);
  return 0;
}

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

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >>t;
	while(t--){
		int n,q,x=0,y;
		cin>>n>>q;
		int a[n],b[n];
		for(int i=0;i<n;i++){
			cin >>a[i];
			b[i]=a[i]-x-1;
			x=a[i];
		}
		for(int i=1;i<n;i++)
			b[i]=b[i]+b[i-1];
		while(q--){
			int l=0,r=2e18,m;
			cin>>x;
			while(l<=r){
				m=(l+r)/2;
				if(m-(lower_bound(a,a+n,m)-a)>=x+1)
				r=m-1;
				else
				l=m+1;
			}
			cout<<r<<endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll n;
gr g;

pll rec(ll u) { // ret (what takes Taker, odd/even)
    ll ret = 1, cnt = 1;
    vector<vll> o,e;
    for(auto v: g[u]) {
        auto [val, sz] = rec(v);
        if(sz&1) o.pb({2*val-sz, val,sz-val});
        else e.pb({2*val-sz, val,sz-val});
        cnt += sz;
    }
    sort(all(o));
    F(o.size()) ret += o[i][1+(i&1)];
    F(e.size()) if(e[i][0]<=0) {
        ret += e[i][1];
    } else {
        ret += e[i][1+(o.size()&1)];
    }
    return {ret, cnt};
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    g = gr(n);
    F(n-1) {
        ll x; cin >> x; x--;
        g[x].pb(i+1);
    }
    cout << rec(0).x << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
vector<pll> RG;
vector<pll> GB;
vector<pll> RB;
/*

*/
ll A[200010];
char C[200010];
vector<pll> P(0);
ll N, r, g, b, dog;
ll ans = oo;
bool used[200010] = {};

void dfs(ll depth, ll pre, ll score)
{
  if (r%2 == 0 && g%2 == 0 && b%2 == 0){
    chmin(ans, score);
    return ;
  }
  if (depth == 2) return ;
  ll k, s;
  rep(i, 3){
    if (i==pre) continue;
    if (i==0){//okになるid探す
      ll sz = RG.size();
      bool ok = false;
      rep(j, sz){
        k=RG[j].second;
        s=RG[j].first;
        if (used[k] || used[k+1]) continue;
        else{
          ok = true;
          break;
        }
      }
      if (!ok) continue;
      r--, g--;
    }
    if (i==1){//okになるid探す
      ll sz = GB.size();
      bool ok = false;
      rep(j, sz){
        k=GB[j].second;
        s=GB[j].first;
        if (used[k] || used[k+1]) continue;
        else{
          ok = true;
          break;
        }
      }
      if (!ok) continue;
      g--, b--;
    }
    if (i==2){//okになるid探す
      ll sz = RB.size();
      bool ok = false;
      rep(j, sz){
        k=RB[j].second;
        s=RB[j].first;
        if (used[k] || used[k+1]) continue;
        else{
          ok = true;
          break;
        }
      }
      if (!ok) continue;
      r--, b--;
    }
    used[k] = true;
    used[k+1] = true;
    dfs(depth+1, i, score + s);
    // 復元
    if (i==0) r++, g++;
    if (i==1) g++, b++;
    if (i==2) r++, b++;
    used[k] = false;
    used[k+1] = false;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cin >> N;
  dog = N*2;
  rep(i, dog){
    ll a;
    char c;
    cin >> a >> c;
    A[i] = a;
    C[i] = c;
    if (c == 'R') r++;
    if (c == 'G') g++;
    if (c == 'B') b++;
    P.push_back({a, c});
  }
  if (r%2 == 0 && g%2 == 0 && b%2 == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  sort(all(P));
  rep(i, dog-1){
    ll pr=0, pg=0, pb=0;
    if (P[i].second == P[i+1].second) continue;
    if (P[i].second == 'R') pr++;
    if (P[i].second == 'G') pg++;
    if (P[i].second == 'B') pb++;
    if (P[i+1].second == 'R') pr++;
    if (P[i+1].second == 'G') pg++;
    if (P[i+1].second == 'B') pb++;
    ll dif = P[i+1].first - P[i].first;
    if (pr && pg) RG.push_back({dif, i});
    if (pg && pb) GB.push_back({dif, i});
    if (pr && pb) RB.push_back({dif, i});
  }
  sort(all(RG));
  sort(all(GB));
  sort(all(RB));
  dfs(0, -1, 0);
  cout << ans << endl;
}


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

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int k;
    string s,t;
    cin>>k>>s>>t;
    vector<int>cnt(10),cs(10),ct(10);
    rep(i,4){
        cnt[s[i]-'0']++;
        cnt[t[i]-'0']++;
        cs[s[i]-'0']++;
        ct[t[i]-'0']++;
    }
    double ans=0.0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            double prob=1.0;
            cnt[i]++;
            if(cnt[i]<=k){
                prob*=1.0*(k-cnt[i]+1)/(9*k-8);
                cnt[j]++;
                if(cnt[j]<=k){
                    prob*=1.0*(k-cnt[j]+1)/(9*k-9);
                    cs[i]++,ct[j]++;
                    int ss=0,st=0;
                    for(int l=1;l<=9;l++){
                        ss+=l*pow(10,cs[l]);
                        st+=l*pow(10,ct[l]);
                    }
                    if(ss>st)ans+=prob;
                    cs[i]--,ct[j]--;
                }
                cnt[j]--;
            }
            cnt[i]--;
        }
    }
    printf("%.12lf\n",ans);
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	int X, Y, Z;
	cin >> X >> Y >> Z;

	cout << (Y * Z % X == 0 ? Y * Z / X - 1 : Y * Z / X) << endl;
}


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

int main()
{
	int n, m;
	cin >> n >> m;

	if (m == 0)
	{
		cout << 1 << endl;
		return 0;
	}

	vector<int> a(m);
	rep(i, m) cin >> a[i];
	sort(a.begin(), a.end());
	vector<int> d(m+1);
	int mn = 1e9 + 5;
	rep(i, m)
	{
		if (i == 0) d[0] = a[0] - 1;
		else d[i] = a[i] - a[i - 1] - 1;
		if(d[i] != 0) mn = min(mn, d[i]);
	}
    d[m] = n - a.back();

	int ans = 0;
	rep(i, m+1)
	{
		if (d[i] == 0) continue;
		ans += (d[i] + mn - 1) / mn;
	}
	cout << ans << endl;
	return 0;
}

/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())

int cnt[4][5005];

signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	string s;
	cin>>s;

	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			cnt[0][i]=0;
			cnt[1][i]=0;
			cnt[2][i]=0;
			cnt[3][i]=0;
		}
		cnt[0][i]=cnt[0][i-1];
		cnt[1][i]=cnt[1][i-1];
		cnt[2][i]=cnt[2][i-1];
		cnt[3][i]=cnt[3][i-1];
		if(s[i]=='A')
			cnt[0][i]++;
		else if(s[i]=='G')
			cnt[1][i]++;
		else if(s[i]=='C')
		    cnt[2][i]++;
		else
			cnt[3][i]++;
	}
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(cnt[0][j]-cnt[0][i-1]\
			==cnt[3][j]-cnt[3][i-1]&&\
			cnt[1][j]-cnt[1][i-1]\
			==cnt[2][j]-cnt[2][i-1])
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define ls n << 1
#define rs n << 1 | 1
#define PB push_back
#define MP make_pair
#define LD double
#define int long long
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
const int N = 500;
const int M = 300;
const int mod = 1e9 + 7;
const LL inf = 1e18;
// 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 getchar nc
inline int read() {
    int s = 0;
    register bool neg = 0;
    register char c = getchar();
    for (; c < '0' || c > '9'; c = getchar())
        neg |= (c == '-');
    for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar())
        ;
    s = (neg ? -s : s);
    return s;
}

int a;

inline int calc(int n) {
    int res = 0;
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            while (n % i == 0) n /= i, res++;
        }
    }
    if (n != 1) res++;
    return res;
}

signed main() {
    // freopen("in1.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    a = read();
    for (int i = 1; i <= a; i++) {
        printf("%lld ", calc(i) + 1);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#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 rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<char> s(n);
    vector<int> A(n+1), T(n+1), G(n+1), C(n+1);
    rep(i,n) cin >> s[i];
    rep(i, 1, n+1) {
        A[i] += A[i-1]; T[i] += T[i-1]; G[i] += G[i-1]; C[i] += C[i-1];
        if(s[i-1] == 'A') A[i]++;
        else if(s[i-1] == 'T') T[i]++;
        else if(s[i-1] == 'G') G[i]++;
        else C[i]++;
    }
    ll ans = 0;
    rep(i, n) rep(j, i+1, n) {
        if((j-i)%2 == 0) continue;
        int a = A[j+1]-A[i];
        int t = T[j+1]-T[i];
        int g = G[j+1]-G[i];
        int c = C[j+1]-C[i];
        if(a == t && g == c) ans++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
    int n;
    cin>>n;
    n*=2;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    vector<pair<int,int>> ai;
    unordered_map<int,vector<int>> mp;
    unordered_map<int,int> cnt;
    for(int i=0;i<n;i++){
        mp[b[i]].push_back(i);
    }
    for(int i=0;i<n;i++){
        ai.push_back(make_pair(a[i],mp[a[i]][cnt[a[i]]]));
        cnt[a[i]]++;
    }
    string ans(n,' ');
    int khaali=n,open=0;
    int right[n];
    // for(int i=0;i<n;i++){
    //     cout<<ai[i].first<<' '<<ai[i].second<<'\n';
    // }
    for(int i=n-1;i>=0;i--){
        // cout<<i<<' '<<khaali<<'\n';
        if(ai[i].second<(n/2)){
            if(khaali<n){
                ans[i]='(';
                ans[khaali]=')';
                khaali=right[khaali];
            }
            else{
                ans[i]=')';
                open++;
            }
        }
        else{
            if(open>0){
                ans[i]='(';
                open--;
            }
            else{
                right[i]=khaali;
                khaali=i;
            }
        }
    }
    // assert(open==0);
    cout<<ans<<'\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i=a; i<b; ++i)
#define FORR(i, a, b) for(int i=a; i>b; --i)
#define all(x) (x).begin(), (x).end()
#define printCon(con) for(const auto &x: con) cout<<x<<" "
#define MOD 1000000007

// operator overloading

template<typename T>
istream& operator>>(istream &istream, vector<T>& a)
{
	for (auto &it : a)
		istream >> it;
	return istream;
}

template<typename T>
ostream& operator<<(ostream &stream, vector<T>& v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

// Mathematical functions

int GCD(int a, int b) {
	if(b==0) return a;
	return GCD(b, a%b);
}

// #####START YOUR CODE HERE#####

void solve(int tc) {

	int n; cin>>n;
	int range = 0, arr[n];
	for(int i=0; i<n; ++i) {
		cin>>arr[i]; range += arr[i];
	}

	int sum = range/2;

	bool dp[n+1][sum+1];

	for(int i=0; i<=n; ++i) dp[i][0] = true;
	for(int j=1; j<=sum; ++j) dp[0][j] = false;

	for(int i=1; i<=n; ++i) {
		for(int j=1; j<=sum; ++j) {
			if(j - arr[i-1] >= 0) dp[i][j] = dp[i-1][j] || dp[i-1][j-arr[i-1]];
			else dp[i][j] = dp[i-1][j];
		}
	}

	int ans;

	for(int j=sum; j>=0; --j) {
		if(dp[n][j]) {
			ans = j; break;
		}
	}

	cout<<range-ans;

}

int main() {

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t = 1;
	// cin>>t;

	FOR(i, 1, t+1) {
		solve(i);
	}

	return 0;
}


#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

#ifdef LOCAL
#define log(val) std::cerr << std::setw(3) << __LINE__ << "| " << #val << " = " << (val) << std::endl
#define dbg(proc) proc
#else
#define log(val) 0
#define dbg(proc) 0
#endif

template <typename T>
std::ostream& operator<<(std::ostream& os,const std::vector<T>& v){os << "{";if(!v.empty()){os << v[0];for(std::size_t i=1;i<v.size();++i){os << ", " << v[i];}}return os << "}";}

using ll = std::int64_t;
using P = std::tuple<ll,int>;

int N, Q;
int a[200100], t[200100];
P p[200100];
ll res[200100];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> a[i] >> t[i];
    }

    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int x;
        std::cin >> x;

        p[i] = std::make_tuple(x, i);
    }

    std::sort(p, p + Q);

    // [0, l) 内はすべて同じ値 vl を取る
    // (r, N-1] 内はすべて同じ値 vr を取る
    // [l, r] には一様に acc が加えられている
    int l = 0, r = Q - 1;
    constexpr ll INF = 1001001001;
    ll vl = -INF, vr = INF, acc = 0;

    for(int i=0;i<N;++i){
        if(t[i] == 1){
            vl += a[i];
            acc += a[i];
            vr += a[i];
        }else if(t[i] == 2){
            while(l < Q && fst(p[l]) + acc <= a[i]){
                l += 1;
            }

            vl = std::max<ll>(vl, a[i]);
            vr = std::max<ll>(vr, a[i]);
        }else{
            while(r >= 0 && fst(p[r]) + acc >= a[i]){
                r -= 1;
            }

            vl = std::min<ll>(vl, a[i]);
            vr = std::min<ll>(vr, a[i]);
        }
    }

    for(int i=0;i<l;++i){
        res[snd(p[i])] = vl;
    }

    for(int i=l;i<=r;++i){
        res[snd(p[i])] = fst(p[i]) + acc;
    }

    for(int i=r+1;i<Q;++i){
        res[snd(p[i])] = vr;
    }

    for(int i=0;i<Q;++i){
        std::cout << res[i] << std::endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=20000010;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll>a(n),t(n);
    rep(i,n)cin>>a[i]>>t[i];
    ll su=inf,ma=inf;
    ll de=-inf,mi=-inf;
    ll now=0;
    rep(i,n){
        if(t[i]==1){
            now+=a[i];
            ma+=a[i];
            mi+=a[i];
        }
        if(t[i]==2){
            if(mi>a[i])continue;
            if(ma<=a[i]){
                de=inf;
                su=-inf;
                ma=a[i],mi=a[i];
                continue;
            }
            de=a[i]-now;
            mi=a[i];
        }
        if(t[i]==3){
            if(ma<a[i])continue;
            if(mi>=a[i]){
                de=inf;
                su=-inf;
                ma=a[i],mi=a[i];
                continue;
            }
            su=a[i]-now;
            ma=a[i];
        }
        //cout<<de<<' '<<su<<' '<<mi<<' '<<ma<<endl;
    }
    ll q;cin>>q;
    rep(i,q){
        ll x;cin>>x;
        if(su<=de){
            cout<<ma<<endl;
        }else{
            if(x>=su){
                cout<<ma<<endl;
            }else if(x<=de){
                cout<<mi<<endl;
            }else{
                cout<<x+now<<endl;
            }
        }
    }
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    char s, t;
    cin >> s >> t;

    if(s == 'Y') {
        char c = toupper(t);
        out(c);
    }
    else {
        out(t);
    }

    re0;
}

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

#define fi first
#define se second
#define rep(i,a,b) for(int i = (a) ; i<(b) ; ++i)
#define ar array
#define ll long long
#define pb push_back
#define sz(v) (int)(v).size()
#define endl '\n'
#define dbg(x) cerr << #x << " = " << x << endl

const int N = int(2e5) + 99;
const int INF = int(1e9) + 99;
const int mxN = 1000005;
const int MOD = 998244353;
const int MASK = 4;

ll binpow(ll a, ll p, ll m) {
	a%=m;
	ll ans = 1;
	while(p>0) {
		if(p&1) ans *= a, ans%m;
		p>>=1;
		a*=a;
		a%=m;
	}
	return ans;
}
int h,w;
string s[1000];

bool valid(int x, int y) {
	return min(x,y) >=0 && x<h && y<w;
}

bool isvalidr(int x, int y) {
	int i=x,j=y;
	while(valid(i+1,j-1)) {
		++i,--j;
		if(s[i][j]=='B') return false;
	}
	i=x,j=y;
	while(valid(i-1,j+1)) {
		--i,++j;
		if(s[i][j]=='B') return false;
	}
	return true;
}

bool isvalid(int x, int y) {
	int i=x,j=y;
	while(valid(i+1,j-1)) {
		++i,--j;
		if(s[i][j]!='.') return false;
	}
	i=x,j=y;
	while(valid(i-1,j+1)) {
		--i,++j;
		if(s[i][j]!='.') return false;
	}
	return true;
}

bool vis[2000] = {false};

void solve() {
	cin>>h>>w;
	rep(i,0,h) cin>>s[i];
	ll ans = 1;
	set<char> st[h+w-1];
	rep(i,0,h) rep(j,0,w) {
		if(s[i][j]!='.') st[i+j].insert(s[i][j]);
	}
	rep(i,0,h+w-1) if(sz(st[i])==2) ans=0;else ans *= (st[i].empty())?2:1,ans%=MOD;
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--) {
		solve();
	}
}


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

const int inf = 1e18, mxn = 2e5;

// Global

void solve() {
   int n;
   cin >> n;
   vector<pair<int, string>> v(n);
   for (auto &i : v) {
      cin >> i.second >> i.first;
   }
   sort(v.begin(), v.end(), greater<>());
   cout << v[1].second << '\n';
}

signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   //   int t;
   //   cin >> t;
   //   while (t--)
   solve();
   return 0;
}

#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
const int N=1000005;
int h[N],nxt[N],adj[N],u,v,t,a[N],n,dep[N],fa[N],mn[N][20],path[N],dfn[N],cnp,ans[N];
/*
il int MIN(ct p,ct q){return dep[p]<dep[q]?p:q;}
il void lca(it u,it v){
	u=dfn[u],v=dfn[v],u>v?std::swap(u,v),0:0;
	ct k=LG[v-u+1];
	lc=MIN(mn[u][k],mn[v-(1<<k)+1][k]);
}
il int D(ct u,ct v){lca(u,v);return dep[u]+dep[v]-dep[lc]-dep[lc];}
il void ck(){
//	for(it i=1;i<=n;++i) printf("%d ",a[i]);puts("");
	for(it i=1;i<=n;++i)
		for(it j=i+1;j<=n;++j)
			if(D(i,j)>std::abs(a[i]-a[j])) return;
	for(it i=1;i<=n;++i) printf("%d ",a[i]);puts("");
	//exit(0);
}
il void Dfs(ct x){
	if(x>n) return ck();
	for(it i=1;i<=9;++i) a[x]=i,Dfs(x+1);
}
il void dfs(ct x){
	path[++cnp]=x,dep[x]=dep[fa[x]]+1,dfn[x]=cnp;
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa[x])
			fa[j]=x,dfs(j),path[++cnp]=x;
}
il void Pre(){
	LG[0]=-1;for(it i=1;i<=cnp;++i) mn[i][0]=path[i],LG[i]=LG[i>>1]+1;LG[0]=0;
	for(it j=1;j<=20;++j)
		for(it i=1;i+(1<<j)<=cnp;++i)
			mn[i][j]=MIN(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
}*/
int mxd,id;
int son[N];
bool flag[N];
il void dfs(ct x){
	path[++cnp]=x,dep[x]=dep[fa[x]]+1,dfn[x]=cnp;
	for(it i=h[x],j;i;i=nxt[i])
		if(((j=adj[i])^fa[x])&&(j^son[x]))
			fa[j]=x,dfs(j);
	if(son[x]) fa[son[x]]=x,dfs(son[x]);
	path[++cnp]=x;
}
il void predfs(ct x){
	flag[x]=(x==id);
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa[x]){
			fa[j]=x,predfs(j);
			if(flag[j]) son[x]=j,flag[x]=1;
		}
}
il void DFS(ct x,ct fa,ct dep){
	if(dep>mxd) mxd=dep,id=x;
	for(it i=h[x],j;i;i=nxt[i])
		if((j=adj[i])^fa)
			DFS(j,x,dep+1);
}
il void add(){nxt[++t]=h[u],h[u]=t,adj[t]=v,nxt[++t]=h[v],h[v]=t,adj[t]=u;}
int main(){
	scanf("%d",&n);it i;
	for(i=1;i<n;++i) scanf("%d%d",&u,&v),add();
	DFS(1,0,0),mxd=0,i=id,id=0,DFS(i,0,0),std::swap(i,id),predfs(i),dfs(i);
	for(i=cnp;i;--i) ans[path[i]]=i;
	for(i=1;i<=n;++i) printf("%d ",ans[i]);
	//dfs(1),Pre();
	//for(it i=1;i<=n;++i) for(it j=i+1;j<=n;++j) printf("i=%d j=%d D(i,j)=%d\n",i,j,D(i,j));
	//Dfs(1);
	//for(it i=1;i<=cnp;++i) printf("%d ",path[i]);puts("");
	return 0;
}


#include <bits/stdc++.h>
//#include <bits/extc++.h>
//#include <immintrin.h>

using namespace std;

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &i : a)
        in >> i;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto &i : a) {
        out << i << " ";
    }
    return out;
}

template<typename T, typename D>
istream &operator>>(istream &in, pair<T, D> &a) {
    in >> a.first >> a.second;
    return in;
}

template<typename T, typename D>
ostream &operator<<(ostream &out, const pair<T, D> &a) {
    out << a.first << " " << a.second;
    return out;
}

struct LogOutput {
    template<typename T>
    LogOutput &operator<<(const T &x) {
#ifdef DIVAN
        cout << x;
#endif
        return *this;
    }
} dout, fout;

typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
typedef complex<double> cd;

#define nl '\n'
#define elif else if
#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) >= 0 ? ((x) % m) : ((((x) % m) + m) % m))
#define minq(x, y) x = min((x), (y))
#define maxq(x, y) x = max(x, (y))
#define forn(i, n) for (int i = 0; i < (n); ++i)

#define vpi vector <pair <int, int, int>>
#define vi vector<int>
#define pi pair <int, int>
#define ti tuple <int, int, int>

const ll INFL = 9187201950435737471;
const ll nINFL = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const long double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

inline void IO() {
#ifdef DIVAN
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#else
    //    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
}

#define int ll

const int MOD = 998244353;

const int MAXN = 100 + 15;
const int MAXE = 1e4 + 15;

int dp[MAXN][MAXE];
int ndp[MAXN][MAXE];

void Add(int &a, int b) {
    a = (a + b) % MOD;
}

int Factorial(int x) {
    if (x == 0) {
        return 1;
    }
    return (Factorial(x - 1) * x) % MOD;
}

void Solve() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int need = 0;
    for (auto u : a) {
        need += u;
    }
    if (need & 1ll) {
        cout << "0";
        return;
    }
    need >>= 1ll;
    dp[0][0] = 1;
    for (auto u : a) {
        memcpy(ndp, dp, sizeof(dp));
        forn(i, MAXN) {
            forn(j, MAXE) {
                if (dp[i][j]) {
                    Add(ndp[i + 1][j + u], dp[i][j]);
                }
            }
        }
        memcpy(dp, ndp, sizeof(dp));
    }
    int sum = 0;
    forn(i, MAXN) {
        if (dp[i][need] != 0) {
            Add(sum, (dp[i][need] * ((Factorial(i) * Factorial(n - i)) % MOD)) % MOD);
        }
    }
    cout << sum;
}

signed main() {
    auto startTime = chrono::high_resolution_clock::now();
    IO();
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        Solve();
    }
    auto endTime = chrono::high_resolution_clock::now();
    chrono::duration<long double> duration = endTime - startTime;
    cout << setprecision(6) << fixed;
    fout << '\n' << "Time: " << duration.count();
    return 0;
}

#include <cctype>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <ios>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
#include <list>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, char> origin,std::pair<int64_t, int64_t> another) {return origin.first < another.first; }
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true; } return false; }

int main()
{
    int64_t q,k,n,s,h,w,d,e,x;
    std::cin>> n;

    std::string str;
    std::vector< int64_t > list( n );
    int64_t dp[2][n+1];
    k = 1;

    for( int i = 0; i < n; i++ )
    {
        std::cin>> str;

        if( str == "AND" )
        {
            list[i] = 1;
        }
        else
        {
            list[i] = 0;
        }
    }

    dp[0][0] = 1;//False
    dp[1][0] = 1;//True

    for( int i = 0; i < n; i++ )
    {
        if( list[i] == 1 )//And
        {
            dp[0][i+1] = dp[0][i] * 2 + dp[1][i];
            dp[1][i+1] = dp[1][i];
        }
        else
        {
            dp[0][i+1] = dp[0][i];
            dp[1][i+1] = dp[1][i] * 2 + dp[0][i];
        }
    }

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


#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <cmath>

typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)
#define pub push_back
#define pob pop_back
using namespace std;
int gcd(int a,int b){int r;while((r=a%b)!=0){a=b;b=r;}return b;}//最大公約数
int lcm(int a,int b){return (a*b)/gcd(a,b);}//最小公倍数
using P=pair<int,int>;
typedef struct time{
    int score;
    string col;
} tm_t;

int main() {
    ll i,n;
    cin>>n;
    if(n==2){
        cout<<'3'<<endl;
        return 0;
    }
    ll ans=1;
    if(n<=12){
        for(i=2;i<=n;i++){
            ans*=i;
        }
        cout<<ans+1<<endl;
        return 0;
    }else{
        cout<<(ll)4*4*5*5*7*3*9*11*13*17*19*23*29+1<<endl;
        return 0;
    }
}

#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<long long> A(n);

    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    long long sum = 0;
    long long pre = 0;
    long long res = 0;
    long long mx = 0;
    for (int i = 0; i < n; ++i) {
        mx = max(mx, A[i]);
        res = mx * (i + 1);
        pre += A[i];
        sum += pre;
        res += sum;
        cout << res << '\n';
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int x=floor(1.08*n);
	if(x==206) cout<<"so-so"<<endl;
	else if(x<206) cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
	return 0;
}

#include <bits/stdc++.h>
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define even(x) (x % 2 == 0 ? true : false)
#define odd(x) (x % 2 ? true : false)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;
//const int mod = 1000000007;
//vector<vector<int>> dp(m, vector<int>(n));

void	solve()
{
	double n;
	cin >> n;

	n *= 1.08;
	int x = (int)n;
	if (x < 206) puts("Yay!");
	else if (x == 206) puts("so-so");
	else puts(":(");
}

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

	solve();
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

ll a[100],b[100];

int main()
{
    ll n,x,i,j;
    scanf("%lld%lld",&n,&x);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(i=n-1;i>=0;i--)
    {
        b[i]=x/a[i];
        x%=a[i];
    }
    ll ci=1,k=0,h;
    for(i=0;i<n;i++)
    {
        h=ci;
        if((b[i]+1)*a[i]!=a[i+1])
            ci+=k;
        if(b[i]!=0)
            k+=h;
    }
    printf("%lld\n",ci);
    return 0;
}

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

int main() {
	int N;
	long long X;
	cin >> N >> X;
	vector<long long>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<vector<long long>> dp(N + 1, vector<long long>(2, 0));
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 2; ++j) {
			long long d = (X / A[i] + j);
			if (i != N - 1) {
				d %= (A[i + 1] / A[i]);
			}
			if (0 == d) {
				dp[i + 1][j] += dp[i][j];
			}
			else {
				dp[i + 1][0] += dp[i][j];
				dp[i + 1][1] += dp[i][j];
			}
		}
	}
	cout << dp[N][0] << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int t;
	cin>>t;

	while(t--){
		long long n;
		cin>>n;

		if(n%4==0) cout<<"Even"<<endl;
		else if(n%2==0) cout<<"Same"<<endl;
		else cout<<"Odd"<<endl;
	}
}//I refer to other commentaries.

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<vector<vector<int> > > vvvi;
typedef vector<vector<int> > vvi;
int main(){
  int n;
  cin>>n;
  cout<<1;
  for(int i =2; i<=n; i++){
    int tmp = i;
    int ans = 0;
    while(tmp>0){
      tmp /=2;
      ans++;
    }
    cout<<" "<<ans;
  }
}


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

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

  int n; LL k; cin >> n >> k;

  LL dp[4][3000005] = {0};

  dp[0][0] = 1;

  #if 0
  // A slower way of calculating dp[i][j] is:
  // Will give TLE: https://atcoder.jp/contests/abc200/submissions/22497898

  for (int i = 0; i < 3; i ++) {
    // O(N^2)
    for (int j = 0; j <= 3 * n; j ++) {
      for (int k = 1; k <= n; k ++) {
        dp[i + 1][j + k] += dp[i][j];
      }
    }
  }

  // first of all, we know dp[i][j] > 0 if j <= i * n;
  // next, dp[i][j] will be added to dp[i+1][j+1:j+n+1)
  // so we can basically use dp[i+1][j] as a prefix to dp[i+1][j+1]
  #else

  for (int i = 0; i < 3; i ++) {
    // O(N)
    for (int j = 0; j <= i * n; j ++) {
      dp[i+1][j+1] += dp[i][j];
      dp[i+1][j+n+1] -= dp[i][j]; // remove from accumulation.
    }
    // accumulate / prefix sum
    for (int j = 1; j <= (i + 1) * n; j ++)
      dp[i+1][j] += dp[i+1][j-1];
  }

  #endif
  // we accumulate the counts of sums until we reach k.
  // sum_{i=3}^{x} dp[3][i] <= k. we want to find x.
  int x;
  for (int i = 3; i <= 3 * n; i ++) {
    if (k <= dp[3][i]) { x = i; break; }
    else { k -= dp[3][i]; }
  }

  // finally, we can iterate the beauty of the cake
  for (int i = 1; i <= n; i ++) {
    // i is the beauty.
    // the maximum of the taste we can get is
    // x (the sum) - i (beauty) - n (pop).
    // the minimum is
    // x - i - 1.
    // we should constrain them between [1, n].
    int jmi = max(1, x - i - n), jma = min(n, x - i - 1);

    if (jmi > jma) continue; // in this case i is too small.
    if (k > (jma - jmi + 1)) {
      k -= (jma - jmi + 1); // these are the choices available for taste.
      continue;
    }

    int y = jmi + k - 1;
    int z = x - i - y;
    cout << i << ' ' << y << ' ' << z << '\n';
    return 0;
  }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

ll n, m, k;
vector<ll> a;
set<ll> st;

int cnt = 1600;

double calcerr(double x){
	vector<double> dp(n + m + 1, 0);

	double tmp = m;
	double mm = (double) m;
	for(int i = n-1; i >= 0; i--){
		if(st.count(i) == 1){
			dp[i] = x;
		}else{
			dp[i] = 1.0 / mm * tmp;
		}

		tmp += dp[i]+1;
		tmp -= dp[i+m]+1;
	}

	return abs(dp[0] - x);
}

double sanbun(){
	double l = 0.0, r = 1e100;
	rep(i, cnt){
		double m1 = (2.0 * l + r) / 3.0, m2 = (l + 2.0 * r) / 3.0;
		double e1 = calcerr(m1), e2 = calcerr(m2);
		if(e1 > e2){
			l = m1;
		}else{
			r = m2;
		}
	}

	assert((r - l) < 1e-3);
	return l;
}

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

	cin >> n >> m >> k;

	a.resize(k);
	rep(i, k) cin >> a[i];

	int cont = 0;
	int mx_cont = 0;
	rep(i, k){
		if(i == 0) cont++;
		else if(a[i] > a[i-1] + 1){
			cont = 1;
		}else{
			cont++;
		}
		chmax(mx_cont, cont);
	}

	if(mx_cont >= m){
		cout << -1 << endl;
		exit(0);
	}

	rep(i, k) st.insert(a[i]);
	cout << fixed << setprecision(10) << sanbun() << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int count=0;
	for(int i=0;i<9;i++){
		if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e'){
			count++;
			i=i+3;
		}
	}
	cout<<count<<endl;
	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"

#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)
#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int mod = 1e9+7;
const int mod2 = 998244353;
const long long inf = 1e18;
const long double PI = 3.141592653589793;

template<typename... T>
void in(T&... args) {((cin>>args), ...);}

template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}

template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}

int nxt(){int x;cin>>x;return x;}

int add(int a,int b,int mod=mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}

int mul(int a,int b,int mod=mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}

struct customCompare {
    bool operator () (int x, int y) {
        return x>y;
    }
};

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

const int N = 2e5;
int codejam = 0, testcases = 0;

void solve() {
    string s; cin >> s;
    int n = s.length();
    int cnt = 0;
    rep (i,3, n) {
        if (s.substr(i-3, 4) == "ZONe") {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    #ifndef ONLINE_JUDGE
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
    #endif

    int t = 1;
    if (testcases)
        cin >> t;
    for (int tc = 1; tc <= t; ++tc) {
        if (codejam)
            cout << "Case #" << tc << ": ";
        solve();
    }

    // printclock;
    return 0;
}


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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll n;

    cin >> n;

    if(n%2==0)
    {
        cout << "White" << endl;
    }
    else
    {
        cout << "Black" << endl;
    }

    return 0;
}

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

#define ff                          first
#define ss                          second
#define int                         long long
#define pb                          push_back
#define mp                          make_pair
#define pii                         pair<int,int>
#define vi                          vector<int>
#define omii                        map<int,int>
#define umii                        unordered_map<int,int>
#define pqi                         priority_queue<int>
#define pqd                         priority_queue<int,vi,greater<int> >
#define setbits(x)                  __builtin_popcountll(x)
#define zrobits(x)                  __builtin_ctzll(x)
#define mod                         1000000007
#define inf                         1e18
#define ps(x,y)                     fixed<<setprecision(y)<<x
#define mk(arr,n,type)              type *arr=new type[n];
#define tc(t)                       int t; cin>>t; while(t--)
#define fl(n)                       for(int i=0; i<n; i++)
#define twodvect(m,n, intit)        vector<vector<int>> v(m, vector<int>(n,0))
mt19937                             rng(chrono::steady_clock::now().time_since_epoch().count());

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_c();

    int n;
    cin>>n;
    if(n%2==0)
        cout<<"White"<<"\n";
    else cout<<"Black"<<"\n";

    return 0;
}


#include <iostream>
#include <algorithm>

constexpr int N = 105;

int n;
long long x;
int a[N];
int f[N][N];

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n >> x;
    for (int i = 1; i <= n; ++i) std::cin >> a[i];
    long long ans = 1e18;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j)
            for (int k = 0; k < i; ++k)
                f[j][k] = -1;
        f[0][0] = 0;
        for (int pos = 1; pos <= n; ++pos)
            for (int j = i; j; --j)
                for (int k = 0; k < i; ++k)
                    if (~f[j - 1][k])
                        f[j][(k + a[pos]) % i] = std::max(f[j][(k + a[pos]) % i], f[j - 1][k] + a[pos]);
        if (~f[i][x % i]) ans = std::min(ans, (x - f[i][x % i]) / i);
    }
    std::cout << ans << '\n';
    return 0;
}

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

//#include <atcoder/all>
// using namespace atcoder;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, y) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), y))
#define Upper_bound(v, y) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), y))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

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;
}

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, x;
  cin >> n >> x;

  vvvll dp(n + 1, vvll(n + 1, vll(n + 1, -1)));
  repLRE(i, 1, n) dp[0][i][0] = 0;
  rep(_, n) {
    ll a;
    cin >> a;
    vvvll ndp = dp;
    rep(i, n) repLRE(j, 1, n) rep(k, j) {
      if (dp[i][j][k] != -1) {
        ll ni = i + 1;
        ll nk = (dp[i][j][k] + a) % j;
        chmax(ndp[ni][j][nk], dp[i][j][k] + a);
      }
    }
    swap(ndp, dp);
  }

  ll ans = x;
  repLRE(i, 1, n) rep(k, i) {
    ll v = x - dp[i][i][k];
    if (dp[i][i][k] != -1 && v % i == 0) {
      ll tmp = v/i;
      chmin(ans, tmp);
    }
  }

  cout << ans << endl;

  return 0;
}


/**
 *    author:  pankaj_m05
 *    created: 02.01.2021 17:42:10
**/
#include<bits/stdc++.h>

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  map<string, bool> mp1, mp2;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp1[s] = true;
    if (s[0] != '!') {
      mp2[s] = true;
    }
  }
  for (auto& it : mp2) {
    string t1 = it.first, t2 = "!" + it.first;
    if (mp1[t1] && mp1[t2]) {
      cout << t1;
      return 0;
    }
  }
  cout << "satisfiable";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];

//using Graph = vector<vector<int>>;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

//Union-Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%MOD;
    }
    return res;
}

bool ok(int v, int b) {
    while (v) {
        if (v % b == 7) return false;
        v /= b;
    }
    return true;
}

int main() {
   int n;
   cin >> n;
   string s[n];
   set <string> ans1,ans2;
   rep (i,n) {
       cin >> s[i];
       if (s[i][0] != '!') ans1.insert(s[i]);
       else ans2.insert(s[i]);
   }
    int d = ans2.size();
    string ans = "satisfiable";
   for (auto x:ans1) {
       string s = "!";
       s += x;
       ans2.insert(s);
       if (d == ans2.size()){
           ans = x ;
           break;
       }
       else {
           d = ans2.size();
           continue;
       }
   }
   cout << ans << endl;
}


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

vector<long long> primes, X;
long long dp[73][(1<<20)];

int isPrime(int n)
{
    for (int i=2; i*i<=n; i++)
        if (n % i == 0)
            return 0;

    return 1;
}

long long solve(int n, int mask)
{
    if (n < 0)
        return 1;

    if (dp[n][mask] != -1)
        return dp[n][mask];

    int canTake = 1;
    int newMask = mask;
    long long ans = solve(n-1, mask);

    for (int i=0; i<primes.size(); i++)
    {
        if (X[n] % primes[i] == 0)
        {
            if (mask & (1 << i))
                canTake = 0;

            newMask |= (1 << i);
        }
    }

    if (canTake)
        ans += solve(n-1, newMask);

    return dp[n][mask ] = ans;
}

int main()
{
    for (int i=2; i<=71; i++)
        if (isPrime(i))
            primes.push_back(i);

    long long a, b;
    cin >> a >> b;

    while (a <= b)
        X.push_back(a++);

    memset(dp, -1, sizeof(dp));

    cout << solve(X.size() - 1, 0) << "\n";
    return 0;
}

#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define rep2(i, a, b) for (int i = a; i < b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)

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

const int MAXN = 2e5 + 5;

void solve() {
    int n, res = 0;
    cin >> n;
    rep (i, 1, n) {
        int x;
        cin >> x;
        res += max(x - 10, 0);
    }
    cout << res << '\n';
}
signed main(int argc, char *argv[]) {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int cas = 1;
    // cin >> cas;
    while (cas--) solve();
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}


#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, P> State;

int closed[17][1<<17];

int main(){
  int n;
  cin >> n;
  ll t[17][3];
  for (int i = 0; i < n; i++) {
    cin >> t[i][0] >> t[i][1] >> t[i][2];
  }
  memset(closed, -1, sizeof(closed));
  closed[0][0] = 0;
  priority_queue< State, vector<State>, greater<State> > open;
  open.push(State(0, P(0, 0)));
  while (!open.empty()) {
    State st = open.top(); open.pop();
    ll cost = st.first;
    int pos = st.second.first;
    int used = st.second.second;
    if (pos == 0 && used == (1 << n) - 1) {
      cout << cost << endl;
      break;
    }
    if (closed[pos][used] != -1 && closed[pos][used] < cost) {
      continue;
    }
    for (int nextPos = 0; nextPos < n; nextPos++) {
      if (nextPos == pos) {
        continue;
      }
      int nextUsed = used | (1 << nextPos);
      ll nextCost = cost + abs(t[nextPos][0] - t[pos][0]) + abs(t[nextPos][1] - t[pos][1]) + max(0LL, t[nextPos][2] - t[pos][2]);
      if (closed[nextPos][nextUsed] == -1 || closed[nextPos][nextUsed] > nextCost) {
        open.push(State(nextCost, P(nextPos, nextUsed)));
        closed[nextPos][nextUsed] = nextCost;
      }
    }
  }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll mod=1e9 +7;
ll dp[17][(1<<17)],n;

ll cost(pair<pair<ll,ll>,ll> &p1,pair<pair<ll,ll>,ll> &p2)
{
    return max((ll)0,p2.second-p1.second)+abs(p1.first.first-p2.first.first)+abs(p1.first.second-p2.first.second);
}

ll solve(vector<pair<pair<ll,ll>,ll> > v,ll idx,ll mask)
{
    if(mask== (1<<n)-1)
    {
        return cost(v[idx],v[0]);
    }
    if(dp[idx][mask]!=-1) return dp[idx][mask];
    dp[idx][mask]=1e9;
    for(int i=0;i<n;i++)
    {
        if(mask&(1<<i)) {}
        else
        {
            dp[idx][mask]=min(dp[idx][mask],cost(v[idx],v[i])+solve(v,i,mask|(1<<idx)));
        }
    }
    // cout<<idx<<" "<<mask<<" "<<dp[idx][mask]<<endl;
    return dp[idx][mask];
}

int main()
{
    cin>>n;
    vector<pair<pair<ll,ll>,ll> > v(n);
    for(int i=0;i<n;i++)
        cin>>v[i].first.first>>v[i].first.second>>v[i].second;
    memset(dp,-1,sizeof dp);
    cout<<solve(v,0,0);
}


/**
*    author:  Dooloper
*    created: 26.10.2020 13:52:11
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i<n;i++)
typedef pair<int,int> P;
#define Mod 998244353

int main() {
   ll h,w,ans=1;
   cin >> h >> w;
   vector <vector <char>> s(h,vector <char>(w));

   rep(i,h){
     rep(j,w){
       cin >> s.at(i).at(j);
     }
   }

   rep(i,h+w){
       ll j=(i<h?i:h-1),k=i-j,co=0;
       char tmp='o';
     //cout << j << k << endl;
       while(j>=0 && k<w){
         //cout <<i<< j << k << endl;
           if((tmp=='R' && s.at(j).at(k)=='B') || (tmp=='B' && s.at(j).at(k)=='R')){
               cout << 0 << endl;
               return 0;
           }
           //cout << 222 << endl;
         //cout << j << k << endl;
            if(s.at(j).at(k)=='.'){
            co++;
            }else if(s.at(j).at(k)=='R'){
            tmp='R';
            }else {
            tmp='B';
            }
           j--;
           k++;
         //cout << 333 << endl;
       }

       if(co!=0 && tmp=='o')
       ans=(ans*2)%Mod;

   }
  cout << ans << endl;

}

#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	int h,w,i,j;
	long long ans = 1,mod=998244353;
	vector<vector<int>> board;
	cin >> h >> w;
	board.assign(h, vector<int>(w,0));
	for(i=0;i<h;i++) {
		string s;
		cin >> s;
		for(j=0;j<w;j++) {
			if(s[j] == 'R') board[i][j] = 1;
			else if (s[j] == 'B') board[i][j] = 2;
			else board[i][j] = 0;
		}
	}
	for(i=0;i<h+w-1;i++) {
		//long long tmp=0;
		int color = 0;
		//bool isupdate = false;
		for(j=0;j<=i;j++) {
			if(i-j >= w) continue;
			if(j >= h) break;
//cout << j << " " << i-j << endl;
			if(board[j][i-j]>0){
				if(color==0) {
					color = board[j][i-j];
				} else {
					if(color != board[j][i-j]){
						color = -1;
						break;
					}
				}
			}
		}
		if(color == -1){
			ans = 0;
			break;
		}
		if(color==0){
			ans *= 2;
			ans %= mod;
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	printf("%d\n", (1 << n) - 1);
	for (int i = 1; i < 1 << n; i++) {
		std::string res;
		for (int j = 0; j < 1 << n; j++) {
			if (__builtin_popcount(i & j) & 1) res.push_back('A');
			else res.push_back('B');
		}
		std::cout << res << std::endl;
	}

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  int max_a = *max_element(a.begin(), a.end());
  int min_b = *min_element(b.begin(), b.end());
  int ans;
  if (max_a > min_b)  ans = 0;
  else ans = min_b - max_a + 1;

  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#include <set>
#include <stack>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;
constexpr int mo2 = 998244353;
vector<pair<int,int>> d = {{-1,0},{0,-1},{1,0},{0,1}};
int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int h,w,x,y;
    cin>>h>>w>>y>>x;
    x--;y--;
    vector<string> f(h);
    for(auto & a :f)cin>>a;
    int count = 0;
    for(auto [dy,dx] : d){
        int toy = y + dy;
        int tox = x + dx;
        while(true){
            if(toy >= h or toy < 0 or tox >= w or tox < 0 or f[toy][tox] == '#')break;
            count++;
            toy += dy;
            tox += dx;
        }

    }
    count++;
    cout << count << endl;
    return 0;

}

//Making love with his ego Ziggy sucked up into his mind
#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define ff first
#define ss second
#define ter(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<ll,ll> ii;
const int N=2e6;
int val[N],col[N];
int n,m;
char s[40];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",s);
		int pw=1;
		int here=0;
		for(int j=m-1;j>=0;j--){
			if(s[j]=='1')
				here|=pw;
			pw<<=1;
		}
		val[i]=here;
	}
	col[0]=1;
	int w=1;
	for(int i=1;i<n;i++){
		if((__builtin_popcount(val[0]^val[i]))%2==0)
			val[i]=1,w++;
	}
	int b=n-w;
	//ter(b);
	//ter(w);
	cout<<1LL*w*b<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
/* * * *   * * *   	* * * */
/* *
 *
 * Too many mind, no mind.
 *
 * */
bool isPrime(ll n) {
	for (ll i = 2; i * i <= n; ++i) if (n % i == 0) return 0;
	return 1;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	vector <ll> primes;
	for (ll i = 2; i <= 50; ++i) if (isPrime(i)) primes.push_back(i);
	int n; cin >> n;
	vector <ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	ll ans = LLONG_MAX;
	for (int mask = 0; mask < (1 << (int)primes.size()); ++mask) {
		int can = 0; ll cur = 1;
		for (int i = 0; i < primes.size(); ++i) if (mask >> i & 1) cur *= primes[i];
		for (int i = 0; i < n; ++i) {
			for (int bit = 0; bit < primes.size(); ++bit) if (mask >> bit & 1) {
				if (a[i] % primes[bit] == 0) {
					can++;
					break;
				}
			}
		}
		if (can == n) ans = min(ans, cur);
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++){
      cin>>vec.at(i).at(j);
    }
  }
  int min=0;
  int64_t ans=1000000000;
  for(int i=0; i<N; i++){
    min=vec.at(i).at(0);
    if(vec.at(i).at(2)-min>0&&ans>=vec.at(i).at(1))
      ans=vec.at(i).at(1);
  }
  if(ans!=1000000000)
    cout<<ans<<endl;
  else
    cout<<"-1"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int rev = 1;
  int a, b; scanf("%d%d", &a, &b);
  if (a < b) swap(a, b), rev = -1;
  int cur = 0;
  for (int i = 1; i <= a; ++i) printf("%d ", i * rev), cur += i * rev;
  for (int i = 1; i < b; ++i) printf("%d ", -i * rev), cur -= i * rev;
  printf("%d\n", -cur);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	int ans=2*a+100-b;
	cout<<ans;
}


#include<iostream>
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int d;
  if(n>=m) d=n-m;
  else d=m-n;
  if(d>=3) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define DEC(x) fixed<<setprecision(x)
#define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);
const long long INF=2e18;

template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;}
template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;}

ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll modinv(ll a,ll m)
{
    return power(a,m-2,m);
}

// #define _NCR_

int TLE_TERROR()
{
 	ll a,b;
 	cin>>a>>b;
 	ll n=abs(a-b);
 	if(n<3)
 		cout<<"Yes"<<endl;
 	else
 		cout<<"No"<<endl;

 	return 0;
}

int main()
{
    FAST
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll int TESTS=1;
    // cin>>TESTS;
    #ifdef _NCR_
        initialvalues();
    #endif
    while(TESTS--)
        TLE_TERROR();
    return 0;
}


//int max = 2 147 483 647 (2^31-1)
//ll max = 9 223 372 036 854 775 807 (2^63-1)
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

//Fast input and output
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

int main(){
  int n;
  cin >> n;
  vector<pi>a(n);
  forn(i,n){
    int x,y;
    cin >> x >> y;
    a[i]=mp(x,y);
  }
  int ans=0;
  forn(i,n){
    for(int j=i+1;j<n;j++){
      if(i==j){
        continue;
      }
      pi p=a[i],q=a[j];
      if(p.f>q.f){
        swap(p,q);
      }
      int k = q.f-p.f;
      if(q.s<=p.s+k and q.s>=p.s-k){
        ans++;
      }
    }
  }
  cout << ans;
}

/* Clearink */

#include <cstdio>
#include <cstdlib>
#include <assert.h>

const int MAXN = 200;
int n, match[MAXN + 5];
bool f[MAXN + 5], vis[MAXN + 5];

inline bool check ( const int l, const int r ) {
	int stp = r - l + 1 >> 1; // i -> i + stp.
	for ( int i = l, j; ( j = i + stp ) <= r; ++ i ) {
		bool acci = 1 <= match[i] && match[i] <= n << 1;
		bool accj = 1 <= match[j] && match[j] <= n << 1;
		if ( match[i] == -1 || ( acci  && match[i] ^ j )
		|| match[j] == ( n << 1 | 1 ) || ( accj && match[j] ^ i )
		|| ( !acci && !accj && match[i] && match[j] ) ) {
			return false;
		}
	}
	return true;
}

int main () {
	scanf ( "%d", &n );
	for ( int i = 1, a, b; i <= n; ++ i ) {
		scanf ( "%d %d", &a, &b );
		if ( ~a && ~b && a >= b ) return puts ( "No" ), 0;
		if ( ~a && ~b ) match[a] = b, match[b] = a;
		else if ( ~a ) match[a] = n << 1 | 1;
		else if ( ~b ) match[b] = -1;
		if ( ~a ) {
			if ( vis[a] ) return puts ( "No" ), 0;
			vis[a] = true;
		}
		if ( ~b ) {
			if ( vis[b] ) return puts ( "No" ), 0;
			vis[b] = true;
		}
	}
	f[0] = true;
	for ( int i = 2; i <= n << 1; i += 2 ) {
		for ( int j = 0; j < i && !f[i]; j += 2 ) {
			f[i] = f[j] && check ( j + 1, i );
		}
	}
	puts ( f[n << 1] ? "Yes" : "No" );
	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int MAXN = 2e5 + 100;
const int MOD = 1E9 + 7;
int n;
char c[MAXN];

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

template <class T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

LL qpow(LL a, LL b, LL MOD) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % MOD;
        b >>= 1, base = base * base % MOD;
    }
    return ans;
}

void solve(int testNum) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        if (c[i] == '0') {
            if (i + 1 <= n && c[i + 1] != '1') {
                cout << 0;
                return;
            }
            if (i + 2 <= n && c[i + 2] != '1') {
                cout << 0;
                return;
            }
            if (i + 3 <= n && c[i + 3] != '0') {
                cout << 0;
                return;
            }
        } else {
            if (i + 1 <= n) {
                if (c[i + 1] == '0') {
                    if (i + 2 <= n && c[i + 2] != '1') {
                        cout << 0;
                        return;
                    }
                    if (i + 3 <= n && c[i + 3] != '1') {
                        cout << 0;
                        return;
                    }
                } else {
                    if (i + 2 <= n && c[i + 2] != '0') {
                        cout << 0;
                        return;
                    }
                    if (i + 3 <= n && c[i + 3] != '1') {
                        cout << 0;
                        return;
                    }
                }
            }
        }
    }
    if (n == 1) {
        if (c[1] == '1')
            cout << 2ll * (LL)pow(10ll, 10);
        else
            cout << (LL)pow(10ll, 10);
        return;
    }
    if (c[1] == '1' && c[2] == '1')
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - (n - 1)) / 3.0);
    else if (c[1] == '1' && c[2] == '0')
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - 1 - (n - 1)) / 3.0);
    else
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - 2 - (n - 1)) / 3.0);
}

signed main() {
    // freopen("1.in", "r", stdin);
    int testCase = 1;
    // read(testCase);
    // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // cin >> testCase;
    for (int i = 1; i <= testCase; i++) solve(i);
    return 0;
}


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

int main() {
  long long n;	cin >> n;

  int b = log(n) / log(2);
  long long abc = 100100101101110;
  for(;b >= 0; b--){
    long long B = pow(2, b);
    long long a = n/B;
    long long c = n - a*B;
    long long tmpabc = a + b + c;
    if(abc > tmpabc){
      abc = tmpabc;
    }
  }

  cout << abc << endl;
  return 0;
}

//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

void solve(){
    llint n;
    cin >> n;
    llint a=0,b=0,c=0;
    llint x=1;
    llint ans=inf;
    if(n==1)ans=1;
    while(n>1){
        if(n%2==1){
            n-=1;
            c+=x;
        }
        n/=2;
        b+=1;
        x*=2;
        if(ans>n+b+c){
            ans=n+b+c;
        }
    }

    //printf("%ld %ld %ld\n",a,b,c);
    cout << ans << endl;
}

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


#include <bits/stdc++.h>

#define x first
#define y second
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<double, double> PDD;

const int INF = 0x3f3f3f3f;
// const double INF = 1e20;
const double PI = acos(-1);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

void quick_read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

void solve() {
    map<char, int> mp;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    for (char c : s1) mp[c]++;
    for (char c : s2) mp[c]++;
    for (char c : s3) mp[c]++;
    if (mp.size() > 10) {
        cout << "UNSOLVABLE" << endl;
        return;
    }
    vector<int> p(10);
    iota(p.begin(), p.end(), 0);
    do {
        string n1, n2, n3;
        int cnt = 0;
        for (auto& it : mp) it.y = p[cnt++];
        for (char c : s1) n1.push_back(mp[c] + '0');
        for (char c : s2) n2.push_back(mp[c] + '0');
        for (char c : s3) n3.push_back(mp[c] + '0');
        LL a = stoll(n1), b = stoll(n2), c = stoll(n3);
        if (n1[0] != '0' && n2[0] != '0' && n3[0] != '0' && a + b == c) {
            cout << a << endl << b << endl << c << endl;
            return;
        }
    } while (next_permutation(p.begin(), p.end()));
    cout << "UNSOLVABLE" << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<int(n); i++)
#define print(x) cout << (x) << endl

int main() {
    int n,k,m; cin >> n >> k >> m;
    vector<int> a(n-1);
    rep(i,n-1) cin >> a[i];
    auto asum = accumulate(a.begin(), a.end(),0);
    int ans = -1;
    rep(i,k+1) {
        if ((asum+i)/n >= m) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
using pairint = pair<int, int>;

template <typename T>
struct SegmentTree{
    SegmentTree(unsigned int n, function<T(T, T)> AssociativeFunction, T ZeroElement=0){
        length = 1;
        fn = AssociativeFunction;
        z = ZeroElement;
        while(length < n*2){
            length <<= 1;
        }
        Nodes.assign(length, z);
    }
    void assign(unsigned int index, T value){
        unsigned int initindex = (length>>1) + index;
        Nodes[initindex] = value;
        for(unsigned int i=initindex>>1; i>0; i>>=1){
            Nodes[i] = fn(Nodes[i*2], Nodes[i*2+1]);
        }
    }
    T element(unsigned int index){
        return Nodes[(length>>1) + index];
    }
    T query(unsigned int lindex, unsigned int rindex){
        int l = (length>>1) + lindex;
        int r = (length>>1) + rindex;
        T res = z;
        while(l <= r){
            if(r==l){
                if(res==z){
                    res = Nodes[l];
                }else res = fn(res, Nodes[l]);
                break;
            }
            if(l%2==1){
                if(res==z){
                    res = Nodes[l];
                }else res = fn(res, Nodes[l]);
                l += 2;
            }
            if(r%2==0){
                if(res==z){
                    res = Nodes[r];
                }else res = fn(res, Nodes[r]);
                r -= 2;
            }
            l>>=1;
            r>>=1;
        }
        return res;
    }

private:
    T z;
    unsigned int length;
    vector<T> Nodes;
    function<T(T, T)> fn;
};

int main(void){
    int H, W, M, Xbuf, Ybuf;
    long long res = 0;
    vector<int> leftmost, uppermost;
    vector<vector<int>> Obstructions;
    cin >> H >> W >> M;
    leftmost.assign(H, W);
    uppermost.assign(W, H);
    Obstructions.assign(W, {});
    for(int i=0; i<M; i++){
        cin >> Xbuf >> Ybuf;
        Xbuf--;
        Ybuf--;
        leftmost[Xbuf] = min(leftmost[Xbuf], Ybuf);
        uppermost[Ybuf] = min(uppermost[Ybuf], Xbuf);
        Obstructions[Ybuf].push_back(Xbuf);
    }
    for(int i=0; i<uppermost[0]; i++)res += leftmost[i];
    SegmentTree<int> st(H, plus<int>());
    for(int i=uppermost[0]; i<H; i++)st.assign(i, 1);
    for(int i=0; i<leftmost[0]; i++){
        for(int obstruction: Obstructions[i])st.assign(obstruction, 1);
        res += st.query(0, uppermost[i]-1);
    }
    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
template <class T1, class T2>
bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; }
template <class T1, class T2>
bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) { cout << head << ' '; co(forward<Tail>(tail)...); }
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); }
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t LINF = 1000000000000000001;
constexpr int64_t MOD = 1000000007;
constexpr int64_t MOD_N = 998244353;
constexpr long double EPS = 1e-11;
const double PI = acos(-1);

template <typename T>
struct BIT {
    int64_t N;
    vector<T> data;

    BIT(int64_t n) {
        init(n);
    }

    const T &operator[](const int64_t i) const {
        return at(i);
    }

    T at(int64_t k) { return sum(k + 1) - sum(k); }

    void init(int64_t n) {
        N = 1;
        while (N < n) N <<= 1;
        data.assign(N + 1, 0);
    }

    void build(vector<T> v) {
        init(N);
        for (int i = 0; i < v.size(); ++i) {
            add(i, v[i]);
        }
    }

    // v[k] += w
    void add(int64_t k, T w) {
        for (int64_t x = k + 1; x <= N; x += x & -x) {
            data[x] += w;
        }
    }

    // v[k] = x
    void update(int64_t k, T x) {
        add(k, x - at(k));
    }

    // v[0] + ... + v[k - 1]
    T sum(int64_t k) {
        T res = 0;
        for (int64_t x = k; x > 0; x -= x & -x) {
            res += data[x];
        }
        return res;
    }

    // v[a] + ... + v[b - 1]
    T sum(int64_t a, int64_t b) { return sum(b) - sum(a); }

    T lower_bound(T k) {
        int64_t l = 0, r = N;
        while (r - l > 1) {
            int64_t m = (l + r) / 2;
            if (sum(m) >= k) r = m;
            else l = m;
        }
        return r;
    }
};

int main(void) {
    ll h, w;
    cin >> h >> w;
    ll m;
    cin >> m;
    VecP ps(m);
    rep(i, m) cin >> ps[i].first >> ps[i].second;
    sort(all(ps));

    Vec my(h + 1, w + 1);
    rep(i, m) chmin(my[ps[i].first], ps[i].second);
    repn(i, h) {
        if (my[i - 1] == 1) my[i] = 1;
    }

    BIT<ll> bit(w + 1);
    set<ll> st;

    if (my[1] <= w) {
        REPN(i, my[1], w) {
            bit.add(i, 1);
            st.insert(i);
        }
    }
    ce(st.size());

    ll ans = 0;
    ll pos = 0;
    repn(i, h) {
        while (pos < m && ps[pos].first == i) {
            if (st.find(ps[pos].second) == st.end()) {
                bit.add(ps[pos].second, 1);
                st.insert(ps[pos].second);
            }
            ++pos;
        }
        ans += bit.sum(my[i], w + 1);
    }
    co(h * w - ans);

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fastio            ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ifs               freopen("aa.in","r",stdin);
#define ofs               freopen("aa.out","w",stdout);
#define iof               ifs ofs
#define ll                long long
#define ld                long double
#define da(x,i)           cout << #x << "[" << i << "]=" << x[i] << "\n";
#define da2(x,i,y,j)      cout << #x << "[" << i << "]=" << x[i] << " ! " << #y << "[" << j << "]=" << y[j] << "\n";
#define d2a(x,i,j)        cout << #x << "[" << i << "][" << j << "]=" << x[i][j] << "\n";
#define db(x)             cout << #x << "=" << (x) << "\n";
#define db2(x,y)          cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << "\n";
#define db3(x,y,z)        cout << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define db4(w,x,y,z)      cout << #w << "=" << (w) << " ! " << #x << "=" << (x) << " ! " << #y << "=" << (y) << " ! " << #z << "=" << (z) << "\n";
#define inf               LLONG_MAX
#define fr                first
#define sc                second
#define all(a)            a.begin(),a.end()

const ll M=998244353,N=1e6+7;;
vector<ll> p(N,-1),g[N],f=p;
ll n,i,j,k,A,z;

void join(ll a,ll b)
{
    if(a==b)
        return;
    ll sa,sb;
    sa=(ll)g[a].size();
    sb=(ll)g[b].size();
    if(sa<sb)
        swap(a,b);
    for(ll i : g[b]){
        p[i]=a;
        g[a].push_back(i);
    }
    g[b]={};
}

ll bmod(ll n=j)
{
    if(n==0)
        return 1;
    if(n==1)
        return 2;
    if(n%2)
        return (2*bmod(n-1))%M;
    ll R=bmod(n/2);
    return (((R%M)*(R%M))%M+2*M)%M;
}

int main()
{
    cin>>n;
    for(i=1; i<=n; i++){
        g[i]={i};
        p[i]=i;
    }
    for(i=1,k=0; i<=n; i++){
        cin>>j;
        join(p[j],p[i]);
    }
    for(i=1,j=0; i<=n; i++){
        z=(ll)g[i].size();
        if(z)
            j++;
    }
    A=bmod();
    A=(A+3*M)%M;
    cout<< A-1 <<"\n";
}

#include<iostream>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<iomanip>
#include<fstream>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
using namespace std;
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
//string::npos

const double pi = 3.141592653589;
const int maxn = 200002;
const int maxm = 26;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
typedef long long ll;

ll ksm(int a, int k){
    ll res = 1;
    while(k){
        if(k&1) res = (ll)res*a%mod;
        a = (ll)a*a%mod;
        k >>= 1;
    }
    return res;
}
int nxt[maxn];
int vis[maxn];
int ans, p, ring, n;

void solve(){
    for(int i = 1; i <= n; ++i){
        if(vis[i]) continue;
        p = i;
        ++ring;
        while(vis[p] == 0){
            vis[p] = ring;
            p = nxt[p];
            if(vis[p] == ring) ++ans;
        }
    }
}

int main(){
    sync;

    cin >> n;
    ring = 1;
    for(int i = 1; i <= n; ++i){
        cin >> nxt[i];
        if(nxt[i] == i){
            vis[i] = ring++;
            ans++;
        }
    }
    solve();
    cout << ksm(2, ans)-1 << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 300000+10;

int a[maxn], prefix[maxn];

int f(){
    int n;
    cin >> n;
    fo(i, 1, n) cin >> a[i];
    fo(i, 1, n) prefix[i] = a[i] + prefix[i - 1];
    int ans = 0, curr = 0, val = -MOD;
    fo(i, 1, n){
        val = max(val, prefix[i]);
        ans = max(ans, curr + val);
        curr += prefix[i];
    }
    return ans;
}

int32_t main(){
    fast_io;
    int t = 1;
    // cin>>t;
    while(t--){
        show(f());

        // f();

        // if(f()){
        //  cout<<"YES"<<endl;
        // }
        // else cout<<"NO"<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];
    ll ans = 0;
    ll s= 0, b = 0;
    ll max_b = 0;
    rep(i,n){
      // フェーズごとの累積和
      b += A[i];
      // これまでの累積和の最大
      max_b = max(max_b, b);
      // 最終的な座標からそれまでの累積和の最大
      ans = max(ans, s + max_b);
      // 各フェーズの最終的な座標
      s += b;
    }
    cout << ans << endl;
    return 0;
}


// Problem: E - Akari
// Contest: AtCoder - AtCoder Beginner Contest 182
// URL: https://atcoder.jp/contests/abc182/tasks/abc182_e
// Memory Limit: 1024 MB
// Time Limit: 2500 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define x first
#define y second

const int N = 1600;
pii blimit[N][N][4];
bool bubl[N][N],wall[N][N];
int main()
{
	int h,w,n,m;scanf("%d%d%d%d",&h,&w,&n,&m);
	forn(i,1,n)
	{
		int x,y;scanf("%d%d",&x,&y);
		bubl[x][y] = 1;
	}
	forn(i,1,m)
	{
		int x,y;scanf("%d%d",&x,&y);
		wall[x][y] = 1;
	}
	pii cur = {0,0};
	//left -> right
	forn(i,1,h)
	{
		cur = {0,0};
		forn(j,1,w)
		{
			if(bubl[i][j])	cur.x = i,cur.y = j;
			if(wall[i][j])	cur.x = 0,cur.y = 0;
			blimit[i][j][0] = cur;
		}
	}
	//right -> left
	forn(i,1,h)
	{
		cur = {0,0};
		for(int j = w;j >= 1;--j)
		{
			if(bubl[i][j])	cur.x = i,cur.y = j;
			if(wall[i][j])	cur.x = 0,cur.y = 0;
			blimit[i][j][1] = cur;
		}
	}
	//up -> down
	forn(j,1,w)
	{
		cur = {0,0};
		forn(i,1,h)
		{
			if(bubl[i][j])	cur.x = i,cur.y = j;
			if(wall[i][j])	cur.x = 0,cur.y = 0;
			blimit[i][j][2] = cur;
		}
	}
	// down -> up
	forn(j,1,w)
	{
		cur = {0,0};
		for(int i = h;i >= 1;--i)
		{
			if(bubl[i][j])	cur.x = i,cur.y = j;
			if(wall[i][j])	cur.x = 0,cur.y = 0;
			blimit[i][j][3] = cur;
		}
	}
	// forn(i,1,h)	forn(j,1,w)
	// {
		// printf("#%d %d\n",i,j);
		// forn(k,0,3)	printf("%d %d %d\n",k,blimit[i][j][k].x,blimit[i][j][k].y);
	// }
	int res = 0;
	forn(i,1,h)	forn(j,1,w)
	{
		int ok = 0;
		forn(k,0,3)	if(blimit[i][j][k].x)	ok = 1;
		// if(ok)	cout << i << " " << j << endl;
		res += ok;
	}
	printf("%d",res);
    return 0;
}

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

int main() {
  int h, w, n, m;
  cin >> h >> w >> n >> m;
  int map[h][w] = {};
  int a, b, c, d, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    map[a - 1][b - 1] = -1;
    ans++;
  }
  for (int i = 0; i < m; i++) {
    cin >> c >> d;
    map[c - 1][d - 1] = -2;
  }

  bool light;
  int x, y;
  queue<int> q;

  for (int i = 0; i < h; i++) {
    light = false;
    q = queue<int>();
    for (int j = 0; j < w; j++) {
      if (map[i][j] == 0) {
        if (light) {
          map[i][j] = 1;
          ans++;
        } else {
          q.push(i);
          q.push(j);
        }
      } else if (map[i][j] == -1) {
        while (!q.empty()) {
          x = q.front();
          q.pop();
          y = q.front();
          q.pop();
          map[x][y] = 1;
          ans++;
        }
        light = true;
      } else if (map[i][j] == -2) {
        light = false;
        q = queue<int>();
      }
    }
  }

  for (int j = 0; j < w; j++) {
    light = false;
    q = queue<int>();
    for (int i = 0; i < h; i++) {
      if (map[i][j] == 0) {
        if (light) {
          map[i][j] = 1;
          ans++;
        } else {
          q.push(i);
          q.push(j);
        }
      } else if (map[i][j] == -1) {
        while (!q.empty()) {
          x = q.front();
          q.pop();
          y = q.front();
          q.pop();
          map[x][y] = 1;
          ans++;
        }
        light = true;
      } else if (map[i][j] == -2) {
        light = false;
        q = queue<int>();
      }
    }
  }
   cout << ans;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    int ans = 0;
    for (int i=0; i<n; i++) cin >> x[i] >> y[i];
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (i==j) continue;
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            if (-dx <= dy && dy <= dx) ans++;
        }
    }
    cout << ans << endl;
}

#include <vector>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a=0;
  vector<double> X(N,0);
  vector<double> Y(N,0);
  for (int i=0; i<N; i++){
    cin >> X[i] >> Y[i];
  }
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++){
      for (int k=j+1; k<N; k++){
        if (X[i]==X[j] && X[i]==X[k]){
          a=1;
        }
        else {
          double d1=(Y[j]-Y[i])/(X[j]-X[i]);
          double d2=(Y[k]-Y[i])/(X[k]-X[i]);
          if (d1==d2){
            a=1;
            break;
          }
        }
      }
      if (a==1){
        break;
      }
    }
    if (a==1){
        break;
    }
  }
  if (a==0){
    cout << "No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define int long long
template<typename T>
void dbg_a(T *a,int l,int r){cout<<" {";for(int i = l;i<r;i++) cout<<a[i]<<", ";cout<<a[r]<<"}"<<endl;}
typedef long long ll;
template<typename T = int>
inline T read(){
    T f = 1,r = 0;
    char c = getchar();
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()

//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);

const int N = 2e5 + 10,M = 2*N + 10,INF = 0x3f3f3f3f;
const int mod = 998244353;
int h[N],ne[M],e[M],idx;
void add(int a,int b){
    e[++idx] = b;ne[idx] = h[a];h[a] = idx;
}
int exgcd(int a,int b,int &x,int &y){
    int d = a;
    if(b){ d = exgcd(b, a%b, y, x);y -= (a/b)*x;}
    else{x = 1;y = 0;}
    return d;
}
int inv(int a,int mo){
    int x,y;
    int d = exgcd(a,mo,x,y);
    return d == 1 ? (x + mo)%mo : -1;//-1表示不存在，并对逆元调整
}
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
bool merge(int a1,int m1,int a2,int m2,int &A,int &mo){
    int c = (a2 - a1),d = gcd(m1,m2);
    if(c % d) return 0;//gcd(m1,m2)|(a2 - a1)时才有解
    c = (c%m2 + m2)%m2;//将c变为[0,m2)之间的数
    c /= d;m1 /= d;m2 /= d;//两边除以d
    c = c*inv(m1,m2) % m2;//将m1/d 移到右边
    mo = m1*m2*d;// mo = m1 * m2 /d
    A = (c*m1%mo*d%mo + a1)%mo;
    return 1;
}
int EXCRT(int n,int a[],int mo[]){
    int a1 = a[1],m1 = mo[1],A,Mo;
    for(int i = 2;i<=n;i++){
        if(!merge(a1,m1,a[i],mo[i],A,Mo)) return -1;//不合法
        a1 = A;m1 = Mo;
    }
    return (a1 + m1)%m1;
}
int n;
void solve(){
    int x,y,p,q;
    cin>>x>>y>>p>>q;
    int a[3] = {},mo[3] = {};
    int ans = 3e18;
    For(i,x,x+y-1){
        For(j,p,p+q-1){
            a[1] = i,mo[1] = 2*(x+y);
            a[2] = j,mo[2] = p + q;
            int res = EXCRT(2,a,mo);
            if(res == -1) continue;
            ans = min(res,ans);
        }
    }
    if(ans == 3e18)cout<<"infinity"<<"\n";
    else cout<<ans<<"\n";
}
signed main(){
    int T = 1;
    T = read();
    while(T--) solve();
    system("pause");
    return 0;
}

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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// BEGIN CUT
ll modpow(ll x, ll y, ll m) {
    ll a = 1, p = x;
    while (y > 0) {
        if (y % 2 == 0) {
            p = (p * p) % m;
            y /= 2;
        } else {
            a = (a * p) % m;
            y--;
        }
    }
    return a;
}
// END CUT

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;
}

int main() {
    int T;
    cin >> T;
    while (T) {
        T--;
        ll X, Y, P, Q;
        cin >> X >> Y >> P >> Q;
        ll ans = INF;
        for (ll k1 = X; k1 < X + Y; k1++) {
            for (ll k2 = P; k2 < P + Q; k2++) {
                ll x, y;
                ll g = extgcd(2 * X + 2 * Y, P + Q, x, y);
                if (abs(k2 - k1) % g != 0)
                    continue;
                x *= (k2 - k1) / g;
                ll b = (P + Q) / g;
                if (x >= 0) {
                    x %= b;
                } else {
                    ll k = (abs(x) + b - 1) / b;
                    x += k * b;
                }
                ans = min(ans, (2 * X + 2 * Y) * x + k1);
            }
        }
        if (ans == INF)
            cout << "infinity" << endl;
        else
            cout << ans << endl;
    }
}