#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=1;i<=(n);++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define RI(x) scanf("%d",&x)
#define RII(x,y) scanf("%d%d",&x,&y)
int n;
char con[105][105];
vector<int> R[105];
int up[105];
bool vis[105];
inline void dfs(int u,int rt){
	++up[rt];vis[u]=1;
	for (int i=0;i<R[u].size();++i) if (!vis[R[u][i]]) dfs(R[u][i],rt);
}
double ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n) cin>>con[i]+1;
	REP(i,n) REP(j,n) if (con[i][j]=='1') R[j].pb(i);
	REP(i,n){
		memset(vis,0,sizeof(vis));
		dfs(i,i);//--up[i];
		//cerr<<i<<' '<<up[i]<<endl;
		ans+=double(1.0)/up[i];
	}
	printf("%0.10lf",ans);

	return 0;
}

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

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

char cn[1200010];
char *ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
char tc[200002], *di = tc + 100000, *di2 = tc + 200000;
const char d[2] = "0";

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

	rep(i, 100000) tc[i] = '0';
	rep(i, 100000) di[i] = '1';
	di2[0] = '0';
	di2[1] = '\n';
	fread(cn, 1, 1200010, stdin);
	int T = getint();
	//while ((ct = *ci++) >= '0') T = T * 10 + ct - '0';

	rep(t, T) {
		int N = getint();
		//while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
		fwrite(di - N, 1, N, stdout);
		fwrite(di2 - N, 1, N + 2, stdout);
		ci += 6 * N + 3;
	}

	Would you please return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define lowbit(x) ((x) & -(x))

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

constexpr double eps = 1e-8;
constexpr int NINF = 0xc0c0c0c0;
constexpr int INF = 0x3f3f3f3f;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 3e5 + 5;

int n, a[N], bit[N], ans[N], l[N], r[N];

void add(int k, int v) {
    for (; k <= n; k += lowbit(k)) bit[k] += v;
}

ll sum(int k) {
    ll ans = 0;
    for (; k; k -= lowbit(k)) ans += bit[k];
    return ans;
}

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

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i]++;
    ll res = 0;
    for (int i = n; i; i--) {
        int x = sum(a[i]);
        res += x;
        r[i] = x;
        add(a[i], 1);
    }
    for (int i = 0; i <= n; i++) bit[i] = 0;
    for (int i = 1; i <= n; i++) {
        int x = sum(a[i]);
        l[i] = x;
        add(a[i], 1);
    }
    for (int i = 1; i <= n; i++) {
        cout << res << '\n';
        // res = res - (a[i] - 1) + (n - a[i]);
        res = res - r[i] + (n - i - r[i]) - l[i] + (i - 1 - l[i]);
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

bool invalid(vector<double> &i){
	if(i[0] > i[1])
		return true;
	return false;
}

bool inter(vector<double> &i1, vector<double> &i2){
	if(invalid(i1) || invalid(i2))
		return false;
	double nw_s = max(i1[0], i2[0]);
	double nw_e = min(i1[1], i2[1]);
	return (nw_s <= nw_e);
}

void solve()
{
	int n;
	cin >> n;
	vector<vector<double> > interv;
	F(int,i, 0, n - 1, 1){
		double t, st, end;
		cin >> t >> st >> end;
		if(t == 1){

		}else if(t == 2){
			end -= 0.2;
		}else if(t == 3){
			st += 0.2;
		}else{
			end -= 0.2;
			st += 0.2;
		}
		// deb(st);deb(end);next_line;
		interv.push_back(vector<double>{st, end});
	}
	int ans = 0;
	F(int, i, 0, n - 1, 1){
		F(int, j, i + 1, n - 1, 1){
			ans += inter(interv[i], interv[j]);
		}
	}
	cout << ans << '\n';
}

signed main()
{
	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);
		// freopen("Debug.txt", "w", stderr);
	#else
	#endif
	// cout << fixed << setprecision(10);
	int _t = 1;
	// cin>>_t;
	F(int, i, 1, _t, 1){
		// cout << "Case #" << i << ": ";
		solve();
	}
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;

vector<string> f(int n){
    if(n == 1)  return vector<string>{"AB"};
    vector<string> ans = f(n - 1);
    int sz = ans.size();
	for(int t = 0; t < sz; ++t){
        ans[t] = ans[t] + ans[t];
        string s = ans[t];
        int siz = s.size();
        for(int i = siz / 2; i < siz; ++i)  s[i] = "AB"[s[i] == 'A'];
        ans.emplace_back(s);
    }
    string s(1 << (n - 1), 'A'),  ss(1 << (n - 1), 'B');
    ans.emplace_back(s + ss);
    return ans;
}

int n;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
    cin >> n;
    vector<string> s = f(n);
    cout << s.size() << "\n";
    for(auto &v : s)  cout << v << "\n";
    return 0;
}

#include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
//using vec = vector<ll>;
//using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

using vec = vector<bool>;
using mat = vector<vec>;
mat solve(int n){
    mat res((1<<n) - 1, vec(1<<n, false));
    rep(i, (1<<(n - 1))) res[0][i] = true;
    if(n == 1){
        return res;
    }else{
        auto lastres = solve(n - 1);
        reps(i, 1, (1<<n) - 1){
            vec &now = res[i], &last = lastres[(i-1)/2];
            rep(j, (1<<(n-1))) now[j] = last[j];
            if(i&1){
                reps(j, (1<<(n-1)), 1<<n) now[j] = last[j - (1<<(n-1))];
            }else{
                reps(j, (1<<(n-1)), 1<<n) now[j] = !last[j - (1<<(n-1))];
            }
        }
        return res;
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N;
    K = (1<<N) - 1;
    cout<<K<<endl;
    auto res = solve(N);
    rep(i, K){
        rep(j, 1<<N) cout<<(res[i][j] ? 'A' : 'B');
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=3000005,INF=1<<30;

ll dp[MAX][4],sum[MAX][4];

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;ll K;cin>>N>>K;
    K--;

    dp[0][0]=1;
    sum[0][0]=1;

    for(int i=1;i<=3*N;i++){
        for(int j=1;j<=3;j++){
            dp[i][j]+=sum[i-1][j-1];
            if(i-(N+1)>=0) dp[i][j]-=sum[i-(N+1)][j-1];
        }
        for(int j=0;j<=3;j++){
            sum[i][j]=dp[i][j]+sum[i-1][j];
        }
    }

    for(ll s=3;s<=3*N;s++){
        //cout<<dp[s][3]<<endl;
        if(K>=dp[s][3]) K-=dp[s][3];
        else{
            for(ll i=1;i<=N;i++){
                ll rem=s-i;
                if(rem<2||rem>2*N) continue;
                ll can=N-abs(N+1-rem);
                if(K>=can) K-=can;
                else{
                    for(ll j=1;j<=N;j++){
                        ll k=s-i-j;
                        if(1<=k&&k<=N){
                            if(K==0){
                                cout<<i<<" "<<j<<" "<<k<<endl;
                                return 0;
                            }
                            K--;
                        }
                    }
                }
            }
        }
    }
}

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
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; }

void solve(){
    ll N,K;
    cin >> N >> K;
    ll cur = K;
    ll sum = -1;
    ll mid = (N*3 + 3) / 2;
    rep(n,3,N*3+1){
        ll idx, val;
        if(n <= mid){
            idx = n - 2;
            val = idx * (idx+1) / 2;
            if(n > N+2){
                ll j = n - (N+2);
                ll pena = 3 * j * (j+1) / 2;
                val -= pena;
            }
        }else{
            if((N*3+3) % 2 == 0){
                ll diff = n - mid;
                ll m = mid - diff;
                idx = m-2;
                val = idx * (idx+1) / 2;
                if(m > N+2){
                    ll j = m - (N+2);
                    ll pena = 3 * j * (j+1) / 2;
                    val -= pena;
                }
            }else{
                ll diff = n - mid;
                ll m = (mid+1) - diff;
                idx = m-2;
                val = idx * (idx+1) / 2;
                // print("m",n,m);
                if(m > N+2){
                    ll j = m - (N+2);
                    ll pena = 3 * j * (j+1) / 2;
                    val -= pena;
                }
            }
        }

        // print(n ,val);
        if(cur <= val){
            sum = n;
            break;
        }else{
            cur -= val;
        }
    }
    // print(sum, cur);
    rep(n,1,sum-1){
        ll nokori = sum - n;
        if(nokori > 2 * N) continue;
        ll start = nokori - N;
        if(start <= 1) start = 1;
        ll num = min(N, nokori-1) - start + 1;
        if(cur <= num){
            ll second_val = start + cur-1;
            print(n, second_val, sum-n-second_val);
            return;

        }else{
            cur -= num;
        }
    }
    // typedef struct{ll x,y,z;} P;
    // vector<P> v;
    // map<ll,ll> mp;
    // rep(i,0,N){
    //     rep(j,0,N){
    //         rep(k,0,N){
    //             v.push_back({i+1, j+1, k+1});
    //             mp[i+j+k+3]++;
    //         }
    //     }
    // }

    // sort(v.begin(), v.end(), [](P p1, P p2){
    //     if(p1.x+p1.y+p1.z == p2.x+p2.y+p2.z){
    //         if(p1.x == p2.x){
    //             return p1.y < p2.y;
    //         }
    //         return p1.x < p2.x;

    //     }
    //     return p1.x+p1.y+p1.z < p2.x+p2.y+p2.z;
    // });

    // // for(auto &e: v) print(e.x,e.y,e.z);
    // for(auto &e: mp){
    //     ll n = e.first - 2;
    //     // print(e.first, e.second, n*(n+1)/2, n*(n+1)/2 - e.second);
    // }

}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

vector<ll> enum_div(ll n){//yakusu
	vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i){
			if(n%i == 0){
				ret.push_back(i);
				if(i*i!=n)ret.push_back(n/i);
			}
	}
	return ret;
}

int main(){

	ll N;
	cin >> N;
	auto ans = enum_div(N);
	SORT(ans);
	for(auto x:ans){
		cout << x << endl;
	}

}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

int main(){
    ll N;
    cin >> N;
    set<ll> ans;
    ll bk=sqrt(N);
    for(ll i=1;i<=bk;i++){
        if(N%i == 0){
            ans.insert(i);
            if(N%(N/i)==0)ans.insert(N/i);
        }
    }
    for(ll i:ans)cout << i << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR(i,a,b) for(i= a ; i < b ; ++i)
#define rep(i,n) FOR(i,0,n)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define INF INT_MAX
#define pb push_back
#define tc int t;cin>>t;while(t--)
#define mod (int)(1e9 + 7)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define endl "\n"
#define si set<int>
#define lld unsigned long long int
void factors(ll x) {
    vector <ll> result;
    ll i = 1;
    while(i*i <= x) {
        if(x % i == 0) {
            result.push_back(i);
            if(x/i != i) {
                result.push_back(x/i);
            }
        }
        i++;
    }
    sort(result.begin(),result.end());
        for(ll i=0; i<result.size(); i++) {
            cout << result[i] <<endl;
        }
        //cout << endl;
}
int main()
{
    fastio;
    ll n;
    cin>>n;
    factors(n);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int n;
cin>>n;
vector<long int> t(0);
int f=2;
for (long int i = 1; i <= sqrt(n); i++)
{
   if (n%i==0)
   {
       t.push_back(i);
       if(i!=n/i){
           t.push_back(n/i);
       }
   }
   }
sort(t.begin(), t.end());

/*while (f<=n)
{
    if(n%f==0){
        n=n/f;
        t.push_back(f);

    }
    else
    {
        f++;
    }

}

*/

for (int i = 0; i < t.size(); i++)
{
cout<<t[i]<<endl;
}

}


//@Author: KeinYukiyoshi

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD   = 1000000007;
// const int MOD    = 998244353;
const int INF    = 10000000000007; // 1e13 + 7
const int INF2    = LLONG_MAX; // 9.2e18
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
template<class T> T chmod(T &a, T mod=MOD) {a =  a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;};
int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

class ALongCommonSubsequence {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int t;
    cin >> t;
    rep(_, t) {
      int N;
      string S1, S2, S3;
      cin >> N >> S1 >> S2 >> S3;
      cout << string(N, '0') + string(N, '1') + '0' << endl;
    }
  }
};

signed main() {
  ALongCommonSubsequence solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

void solve(){
    int n;
    cin>>n;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    for(int i=0;i<n;i++) cout<<"0";
    for(int i=0;i<n;i++) cout<<"1";
    cout<<"0";
    cout<<"\n";
}

int main(){
    ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            cout<<fixed;
            cout<<setprecision(10);
    //        freopen("timber_input.txt", "r", stdin);
    //        freopen("timber_output.txt", "w", stdout);
            int t=1;
            cin>>t;
            for(int i=1;i<=t;i++){
            //    cout<<"Case #"<<i<<": ";
                solve();
    }
    return 0;
}


#ifdef GCC_VERSION
#include<bits/stdc++.h>
#endif

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <tuple>
#include <algorithm>
#include <functional>
#include <deque>
#include <queue>
#include <cstring>
#include <chrono>
#include <numeric>

#ifdef _DEBUG
#define DEBUG_INPUT
#endif

#ifdef DEBUG_INPUT
#include "../__common/Helper.h"
#endif

using ll = long long int;
using ld = long double;

static const ll INF = 6'000'000'000'000'000'000; // -INF for min value

template<typename T> using Vec = std::vector<T>;
template<typename T> using VecVec = std::vector<std::vector<T>>;

#define fe(e,cont) for(auto& e : cont) // others loop types by snippets
#define all(v) std::begin(v),std::end(v)

// only for md-arrays
template<class T> void unsafe_clear(T& val) { auto sz = sizeof(val); std::memset(&val, 0, sz); }
template<class T1, class T2> bool isMemEqual(const T1& v1, const T2& v2) { static_assert(sizeof(v1) == sizeof(v2)); return std::memcmp(&v1, &v2, sizeof(v1)) == 0; }

ll ipow(ll v, ll p) { ll res = 1; while (p--) { res *= v; } return res; }
ll div_ceil(ll a, ll b) { ll res = a / b; if (res * b != a) res++; return res; }

class Timer { // Sometimes measurement is required...
    using sc = std::chrono::steady_clock;  sc::time_point start;
public:
    Timer() :start(sc::now()) {}
    ll elapsedMs() { return std::chrono::duration_cast<std::chrono::milliseconds>(sc::now() - start).count(); }
};

extern const char* INPUT_DATA;

#ifdef DEBUG_INPUT
static Helper helper(INPUT_DATA);
#endif

template<class T>
T __get() {
#ifdef DEBUG_INPUT
    return helper.get<T>();
#else
    T val; std::cin >> val; return val;
#endif
}

ll get() { return __get<ll>(); }
std::tuple<ll, ll> get2() { return { get(), get() }; } std::tuple<ll, ll, ll, ll, ll> get5() { return { get(), get(), get(), get(), get() }; }
std::tuple<ll, ll, ll> get3() { return { get(), get(), get() }; } std::tuple<ll, ll, ll, ll> get4() { return { get(), get(), get(), get() }; }
std::string gets() { return __get<std::string>(); }

template<class T> void print(const T& val) { std::cout << val << " "; }
template<class T, class ... Types> void print(const T& var, const Types&...var2) { print(var); print(var2...); }
void endl() { std::cout << "\n"; }

void onetime(); void prepare() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);  std::cout.tie(nullptr); onetime(); }
void task(); void tcase() { ll t = get(); while (t--) task(); }

int main() {
    Timer timer; prepare();
    //tcase();
    task();
#ifdef DEBUG_INPUT
    while (helper.hasInput()) task();
    //print("Execution time:", timer.elapsedMs());
#endif
    return 0;
}

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

void onetime()
{
}

const char* INPUT_DATA = R"(
2 2 1

)";

void task()
{
    auto [a, b, c] = get3();
    bool win;
    if (c == 0)
    {
        win = a > b;
    }
    else
    {
        win = a >= b;
    }

        print(win ?"Takahashi":"Aoki");

}

#include <iostream>
using namespace std;

int main(){
	int A, B, C;
	cin >> A;
	cin >> B;
	cin >> C;
	if (A == 0 && B > 0) cout << "Aoki";
	if (B == 0 && A > 0) cout << "Takahashi";
	if (A == 0 && B == 0){
		if (C == 0){
			cout << "Aoki";
		}
		else cout << "Takahashi";
	}
	while (A > 0 && B > 0){
		if (C == 0){
			A--;
			if (A == 0){
				cout << "Aoki";
				break;
			}
			B--;
			if (B == 0){
				cout << "Takahashi";
				break;
			}
		}
		else{
			B--;
			if (B == 0){
				cout << "Takahashi";
				break;
			}
			A--;
			if (A == 0){
				cout << "Aoki";
				break;
			}
		}
	}
	return 0;
}


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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll,ll>
#define pii pair<int ,int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define forn(i,s,e) for(int i = s; i < (e); ++i)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILEIO                          \
freopen("./input.txt", "r", stdin); \
freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                   \
for (                                                                   \
auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                               \
debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T> T ABS(const T &x) {return x>0? x:-x;}
ll gcd(ll n1, ll n2) {return n2==0? ABS(n1) : gcd(n2,n1%n2);}
ll lcm(ll n1, ll n2) {return n1==0 && n2==0? 0 : ABS(n1*n2)/gcd(n1,n2);}
ll ceil2(ll a, ll b) {return (a + b - 1) / b;}

// int dx[4] = {1,-1,0,0};
// int dy[4] = {0,0,1,-1};

int main()
{
FASTIO
#ifdef LOCAL
FILEIO
#endif
    int n,m;
    cin >> n >> m;
    vector<unsigned> to(n);

    while(m--){
        int a,b;
        cin >> a >> b;
        --a,--b;
        to[a] |= 1 << b;
        to[b] |= 1 << a;
    }

    vector<unsigned> cs(3);
    ll res = 0;
    auto dfs = [&](auto &&self, int curr) -> void {
        if(curr == n){
            ++res;
            return;
        }
        if(to[curr] == 0){
            self(self,curr+1);
        }
        else{
            forn(i,0,3){
                cs[i] += 1 << curr;
                if((to[curr] & cs[i]) == 0) self(self, curr+1);
                cs[i] -= 1 << curr;
            }
        }
    };
    dfs(dfs,0);
    for(auto j : to) if(!j) res *= 3;
    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;

    vector<vi> G(N);
    rep(i,M){
        int a,b; cin>>a>>b; a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    vector<bool> seen(N);
    auto dfs = [&](auto &dfs, vi &vec, int v)->void{
        seen[v] = true;
        vec.pb(v);
        for(auto u:G[v]){
            if (seen[u]) continue;
            dfs(dfs,vec,u);
        }
    };

    ll ans=1;
    rep(v,N)if(!seen[v]){
        vi vec;
        dfs(dfs,vec,v);
        int sz = vec.size();

        ll sum=0;
        vi color(N,-1);
        auto dfs2 = [&](auto &dfs, int idx)->void{
            if (idx==sz){
                sum+=3;
                return;
            }
            const int &v = vec[idx];
            if (idx==0){
                color[v]=0;
                dfs(dfs,idx+1);
                color[v]=-1;
                return;
            }
            int mask=0b111;
            for(auto u:G[v]){
                if (color[u]==-1) continue;
                mask &= ~(1<<color[u]);
            }
            rep(i,3)if(mask>>i&1){
                color[v]=i;
                dfs(dfs,idx+1);
                color[v]=-1;
            }
        };
        dfs2(dfs2,0);
        ans*=sum;
    }
    cout<<ans<<"\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll mod = 1e9+7;
const ll INF = 1e18;
const ll MAXN = 40;

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

    ll ans = 1LL;
    while (b) {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll modinv(ll n) {
    return binpow(n, mod - 2);
}

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++) spf[i] = i;
    for (ll i=4; i<MAXN; i+=2) spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++) {
        if (spf[i] == i) {
            for (ll j=i*i; j<MAXN; j+=i) {
                if (spf[j]==j) spf[j] = i;
            }
        }
    }
}

vector<ll> getFactorization(ll x)
{
    vector<ll> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}

void solve() {
    ll n; cin>>n;
    ll ans = 1;
    map<ll,ll> mt;
    sieve();
    for(ll i =2; i<=n; i++) {
        map<ll,ll> temp;
        vector<ll> v = getFactorization(i);
        for(ll x : v) {
            temp[x]++;
        }
        for(auto it = temp.begin(); it!=temp.end(); it++) {
            mt[it->fi] = max(mt[it->fi],it->se);
        }
    }

    for(auto it = mt.begin(); it!=mt.end(); it++) {
        ans *= poww(it->fi,it->se);
    }
    ans++;
    cout<<ans;
}

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

    //ll no_of_test_cases; cin>>no_of_test_cases;
    ll no_of_test_cases = 1;
    for(ll i=1; i<=no_of_test_cases; i++) {
        solve();
    }
    return 0;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

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

  Int n;
  cin>>n;
  auto as=read(n);
  auto bs=read(n);

  Int ans=0;
  for(Int a:as) ans+=a;

  priority_queue<Int> pq[2];
  for(Int i=0;i<n;i++)
    pq[i&1].emplace(bs[i]-as[i]);

  while(!pq[0].empty()){
    Int res=pq[0].top()+pq[1].top();
    pq[0].pop();pq[1].pop();
    if(res>0) ans+=res;
    else break;
  }

  cout<<ans<<newl;
  return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mymod(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

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

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

void solve()
{
	ll n,k;
  cin>>n>>k;
  ll ans=0;
  for(ll i=2;i<=2*n;++i){
    ll y=i-k;
    if(y<2||y>n*2)continue;
    ans+=(min(n,i-1)-max(1LL,i-n)+1)*(min(n,y-1)-max(1LL,y-n)+1);
  }
  cout<<ans;
}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128_t LL;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

ll get(int x, int n) {
    if (x <= 1) {
        return 0;
    }
    else if (x <= n + 1) {
        return x - 1;
    }
    else {
        return n - (x - n) + 1;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n, k;
    cin >> n >> k;
    if (k < 0) {
        k = -k;
    }
    ll ans = 0;
    for (int i = 2; i <= 2 * n; i++) {
        ans += get(i, n) * get(i - k, n);
    }
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include<bits/stdc++.h>
#define Woody
#define int long long
#define rep(n) for(int i=0;i<n;i++)
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#ifdef Woody
#define quick ios::sync_with_stdio(0);cin.tie(0);
#else
#define quick
#endif
#define INF INT64_MAX
#define PI 3.14159265
using namespace std;
const double eps=1e-3;
typedef pair<double,double> p;
bool ok(int n,vector<p> v1,vector<p> v2){
//	cout<<"OK\n";

	sort(v2.begin(),v2.end());
/*	rep(n){
		printf("%.5lf %.5lf\n",v1[i].F,v1[i].S);
	}//cout<<"\n";
	rep(n){
		printf("%.5lf %.5lf\n",v2[i].F,v2[i].S);
	}cout<<"\n";*/
	double disx=v1[0].F-v2[0].F;
	double disy=v1[0].S-v2[0].S;
	for(int i=1;i<n;i++){
		double dx=v1[i].F-v2[i].F;
		double dy=v1[i].S-v2[i].S;
		if(abs(disx-dx)>eps||abs(disy-dy)>eps) return false;
	}

	return true;
}
bool solve(){
	int n;
	cin>>n;
	vector<p> v1(n);
	vector<p> v2(n);
	rep(n){
		cin>>v2[i].F>>v2[i].S;
	}
	rep(n){
		cin>>v1[i].F>>v1[i].S;
	}
	sort(v1.begin(),v1.end());
	vector<p> v3(n);
	for(double d=0;d<=360;d+=0.0005){
		double s=sin(d*PI/180.0);
		double c=cos(d*PI/180.0);
		rep(n){
			double x=v2[i].F;
			double y=v2[i].S;
			v3[i].F=x*c+y*(-1)*s;
			v3[i].S=x*s+y*c;
		}
		if(ok(n,v1,v3)) return true;
	}
	return false;
}
signed main(){
	quick
	bool f=solve();
	if(f) cout<<"Yes\n";
	else cout<<"No\n";

}

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

template < typename Iterator >
void dump(Iterator fst, Iterator lst, string const dm = " ")
{ auto it=fst; for ( it!=lst && cout<<to_string(*it++); it!=lst; ) cout << dm << to_string(*it++);
  cout << endl; }

template < typename T >
void dump( T const & v, string const delim = " ")
{ dump(begin(v), end(v), delim); }

ll N;
typedef pair<ll, ll> pll;
vector<ll> A, B;
void solve(void);

int main()
{
  cin >> N;
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  solve();
}

void solve(void)
{
  ll sa = 0;
  vector<ll> aa;
  REP(i, N) {
    sa += A[i];
    aa.push_back(2*A[i]+B[i]);
  }

  ll ans = 0;
  ll d = sa;
  //cout << sa << endl;
  sort(aa.begin(), aa.end(), [](auto const& l, auto const& r){ return l > r; });
  for (auto a : aa) {
    //cout << "a = " << a << endl;
    if (d<0) break;
    d -= a;
    ans++;
  }
  cout << ans << endl;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A + B) / 2<<"\n";
	cout << (A - B) / 2;
	return 0;
}

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;
  cout << (A+B)/2 << " " << A - (A+B)/2 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pairI2;
typedef pair<LL, LL> pairLL2;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define shig_for(i, a, b) for(int i = (a); i < (b); ++i)
#define shig_rep(i, n) shig_for(i, 0, n)
#define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define shig_repB(bit,n) shig_forB(bit,0,n)
#define CINLL(a) LL (a); cin >> (a)
#define CINI2(a, b) int a, b; cin >> (a) >> (b)
#define CINLL2(a, b) LL a, b; cin >> (a) >> (b)
#define tmp int temp = 0
#define str string s

struct Rect{
  int rightIdx;
  int leftIdx;
  int height;
};

LL maxHistogramRect(VI &histogram)
{
  LL maxArea = 0;
  int histogramSize = histogram.size();
  stack<Rect> weightStack;
  for (int i = 0; i < histogramSize; i++){
    Rect newRect;
    newRect.height = histogram[i];
    //空なのは最初だけ、それ以降は空でないことが保証できる
    if (weightStack.empty()){
        newRect.leftIdx = i;
        weightStack.push(newRect);
        maxArea = 1 * newRect.height;
    }else{//取り出されたものは戻されることはなく、一方通行だからO(n)
        int lastLeftIdx = i;
        while (!weightStack.empty() && weightStack.top().height > histogram[i]){
        weightStack.top().rightIdx = i - 1;
        int area = (weightStack.top().rightIdx - weightStack.top().leftIdx + 1) * weightStack.top().height;
        if(maxArea < area)maxArea = area;
        lastLeftIdx = weightStack.top().leftIdx;
        weightStack.pop();
        }
        Rect newRect;
        newRect.height = histogram[i];
        newRect.leftIdx = lastLeftIdx;
        weightStack.push(newRect);
    }
  }
  //weightStackに残ったものについての面積を計算する
  while (!weightStack.empty()){
    weightStack.top().rightIdx = histogramSize - 1;
    int area = (weightStack.top().rightIdx - weightStack.top().leftIdx + 1) * weightStack.top().height;
    if(maxArea < area)maxArea = area;
    weightStack.pop();
  }
  return maxArea;
}

int main(){

    LL N;
    cin >> N;
    VI A(N);
    shig_rep(i, N)cin >> A[i];

    LL ans = maxHistogramRect(A);

    cout << ans << endl;
    //for(string& s : S) cin >> s;
    //cout << "Atcoder " << N << endl;
    //cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define cauto const auto
# define int long long
# define float long double
# define fi first
# define se second
# define mkp make_pair
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define contains(x,key) ((x).find(key) != (x).end())
# define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x)))
# define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x)))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using mii = map<int, int>;
using mci = map<char, int>;
using msi = map<string, int>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
constexpr float PI = 3.1415926535897932385;
constexpr int Flag(int n) { return 1LL << n; }
template<class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T> istream& operator>>(istream& is, vector<vector<T>>& v) { for(auto& x : v) for (auto& y : x) is >> y; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vector<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ cout << p.fi << " " << p.se; return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);}
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; drop(args...);}
template<class T> inline void Unique(T& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T> inline constexpr bool chmax(T &a, T b) { return a < b && (a = b, true); }
template<class T> inline constexpr bool chmin(T &a, T b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
const char* YesNo(bool b) { return b ? "Yes" : "No"; }
const char* YESNO(bool b) { return b ? "YES" : "NO"; }
const char* yesno(bool b) { return b ? "yes" : "no"; }
const char* yn(bool b) { return YesNo(b); }
# endif  // ngng628_library

int32_t main() {
   int n;
   cin >> n;
   vi a(n);
   cin >> a;
   int ans = 0;
   rep (l, n) {
      int mn = INF;
      repr (r, l, n) {
         chmin(mn, a[r]);
         int ln = r - l + 1;
         chmax(ans, mn*ln);
      }
   }
   print(ans);
}


#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 200001

using namespace std;

long long MOD = 1000000007;

struct unionSet{
    int parent[MAX_N];
    int size[MAX_N];
    vector<map<int,int>> dict=vector<map<int,int>>(MAX_N,map<int,int>());

    unionSet(int num){
        for(int i=0; i<num; i++){
            size[i]=1;
            parent[i]=i;
        }
    }

    //find root of x
    int find(int x){
        if (x==parent[x]){
            return x;
        }else{
            return parent[x]=find(parent[x]);
        }
    }

    //check if roots of x and y are same
    bool same(int x, int y){
        return (find(x)==find(y));
    }

    // unite sets of x and y
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y)return;

        if(size[x]>size[y]){
            for(auto kv:dict[y]){
                int k=kv.first;
                int v=kv.second;

                if(dict[x].count(k)>0){
                    dict[x][k]+=v;
                }else{
                    dict[x][k]=v;
                }
            }

            parent[y]=x;
            size[x]+=size[y];
        }else{
            for(auto kv:dict[x]){
                int k=kv.first;
                int v=kv.second;

                if(dict[y].count(k)>0){
                    dict[y][k]+=v;
                }else{
                    dict[y][k]=v;
                }
            }

            parent[x]=y;
            size[y]+=size[x];
        }
    }
};

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N, Q;
    cin >> N >> Q;

    unionSet us(N);

    vector<int> cls(N,0);
    for(int i=0; i<N; i++){
        cin >> cls[i];
        cls[i]--;
        us.dict[i][cls[i]]=1;
    }

    for(int i=0; i<Q; i++){
        int c,x,y;
        cin >> c >> x >> y;
        x--;y--;

        x=us.find(x);
        if(c==1){
            us.unite(x,y);
        }else if(us.dict[x].find(y)!=us.dict[x].end()){
            cout << us.dict[x][y] << '\n';
        }else{
            cout << "0\n";
        }
    }

    /*
    for(int i=0; i<N; i++){
        cout << us.size[i] << ' ';
    }
    */
}

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

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
//constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(9e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

struct UnionFind {
    vector<ll> par,size;

    UnionFind(ll N) : par(N) { //最初はすべてが根であるとして初期化
        size.resize(N,1);
        for(ll i=0;i<N;i++) par[i] = i;
    }

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

    void unite(ll x, ll y){ //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return; //同じ木にあるときはそのまま
        if(size[rx]>size[ry]){
            par[ry]=rx;
            size[rx] += size[ry];
        }else{
            par[rx] = ry;
            size[ry] += size[rx];
        }
        return;
    }

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

    ll treesize(ll x){return size[root(x)];}
};

int main() {
    ll n,m,t,x,y,q,k,ans=0;
    cin>>n>>q;
    vll c(n);
    vector<map<ll, ll>> mp(n);
    UnionFind uf(n);
    rep(i,n){
        cin>>c[i];
        c[i]--;
        mp[i][c[i]] = 1;
    }
    rep(i,q){
        cin>>t>>x>>y;
        if(t==1){
            x--;y--;
            if(uf.same(x,y)) continue;
            x=uf.root(x);
            y=uf.root(y);
            uf.unite(x,y);
            if(y==uf.root(x)) swap(x,y);
            for(auto e:mp[y]){
                mp[x][e.first] += e.second;
            }
        }else{
            pt(mp[uf.root(x-1)][y-1]);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+4;
int vis[N];
int a[N],pos[N],ans[N],cnt;

int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]),pos[a[i]]=i;
    for(int i=1;i<=n;++i){
        for(int j=pos[i];j>i;--j){
            if(vis[j-1]) {puts("-1");return 0;}
            vis[j-1]=1;
            ans[++cnt]=j-1;
            swap(a[j],a[j-1]);
            pos[a[j]]=j;
            pos[a[j-1]]=j-1;
        }
    }
    for(int i=1;i<n;++i){
        if(vis[i]!=1) {puts("-1");return 0;}
    }
    for(int i=1;i<=cnt;++i) cout<<ans[i]<<endl;
}

#include<bits/stdc++.h>

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};
///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction
///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll bigmod(ll a,ll b)
{
    if(b==0)return 1;
    ll x=bigmod(a,b/2)%mod;
    x=(x*x)%mod;
    if(b%2)x=(x*a)%mod;
    return x;
}

ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
        ...ENDING OF TEMPLATE...
*/

ll arr[2*mx],brr[2*mx];
ll ck[2*mx];

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    /** Use "long double"(%Lf) instead of double for precision safety*/
    ll tst,a,b,c,k,n,m,res=0,ans=0,t=0;
    sl(n);
    for(ll i=1;i<=n;i++)
    {
        sl(arr[i]);
        brr[arr[i]]=i;
    }
    vl v;
    res=1;
    for(ll i=1;i<=n;i++)
    {
        while(brr[i]!=i)
        {
//            cout<<brr[i]<<endl;
            a=brr[i]-1;
            if(ck[a])
            {
                res=0;
                break;
            }
//            b=arr[]
            v.pb(a);
            ck[a]=1;
            swap(arr[a],arr[a+1]);
            brr[arr[a+1]]=a+1;
            brr[arr[a]]=a;
            if(sz(v)>n-1)
            {
                res=0;
                break;
            }
        }
        if(res==0)
            break;
//        for(ll i=1;i<=n;i++)
//        {
//            cout<<arr[i]<<" ";
//        }
//        cout<<endl;
    }

//    cout<<"size "<<sz(v)<<endl;
    if(sz(v)!=n-1)
    {
        cout<<-1<<endl;
        return 0;
    }

    for(ll i=1;i<=n;i++)
    {
        if(arr[i]!=i)
        {
            res=0;
            break;
        }
    }

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

    for(auto i:v)
    {
        cout<<i<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}

template<class T> bool umax(T& a, const T& b) {
	return a<b?a=b, 1:0;
}

template<class ForwardIterator> void read(ForwardIterator first,
		ForwardIterator last) {
	while (first != last) {
		cin >> (*first);
		++first;
	}
}

template<class T> void read(vector<T> &v) {
	read(v.begin(),v.end());
}

template<class ForwardIterator> void print(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T> void print(vector<T> &v, string sep = " ", string end = "\n") {
	print(v.begin(),v.end(),sep,end);
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

template<typename T>
vector<int> argsort(const vector<T> &v, function<bool(T,T)> cmp) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    sort(indices.begin(), indices.end(),[&v,&cmp](int left, int right) -> bool {return cmp(v[left],v[right]);});
    return indices;
}

template<typename T>
vector<int> argsort(const vector<T> &v) {
    return argsort<T>(v, less<T>());
}

template<typename T, typename T2>
vector<int> argsort(const vector<T> &v, function<T2(T)> key) {
	vector<T2> v2(v.size());
	for(int i = 0; i < SZ(v); i++) v2[i]=key(v[i]);
    return argsort<T2>(v2);
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo <= hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

bool solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	read(v);
	sort(v.begin(),v.end());
	for (int i = 0; i < n; i++) {
		if (v[i] != i+1) {
			return false;
		}
	}
	return true;
}

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

	cout << (solve() ? "Yes" : "No") << "\n";

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

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

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

  ll ans = 1;
  REP(i, 2, n){
    ans = lcm(ans, (ll)i);
  }

  ans++;
  cout << ans << endl;

  return 0;
}


//叫んで 藻掻もがいて 瞼まぶたを腫らしても
#include <bits/stdc++.h>

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e6 + 10;
const ll mod = 1e9+7;

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m;
int x[maxn] , y[maxn];
vector < int > v , vc;
priority_queue < pii > pq;

int X(int x){
	return lower_bound(v.begin() , v.end() , x) - v.begin();
}

int Y(int x){
	return lower_bound(vc.begin() , vc.end() , x) - vc.begin();
}

set < int > ans;
set < pii > kil;
set < int > pos[maxn] , zap[maxn];

int32_t main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> m;
	for(int i = 1 ; i <= m ; i ++)
		cin >> x[i] >> y[i] , v.pb(x[i]) , vc.pb(y[i]) , vc.pb(y[i] - 1) , vc.pb(y[i] + 1);
	vc.pb(n);
	vc.pb(n+1);
	vc.pb(n-1);
	v.pb(0);
	sort(v.begin() , v.end());
	v.resize(unique(v.begin() , v.end()) - v.begin());
	for(int i = 1 ; i <= m ; i ++)
		x[i] = X(x[i]);
	sort(vc.begin() , vc.end());
	vc.resize(unique(vc.begin() , vc.end()) - vc.begin());
	for(int i = 1 ; i <= m ; i ++)
		y[i] = Y(y[i]);
	for(int i = 1 ; i <= m ; i ++)
		kil.insert({x[i] , y[i]}) , pos[y[i]].insert(x[i]) , zap[y[i]].insert(x[i]);
	// x -> satr / y -> sootoon
	pq.push({-X(0) , Y(n)});
	while(!pq.empty()){
		auto [cx , cy] = pq.top();
		pq.pop();
		cx = -cx;
		while(kil.size() and (*kil.begin()).first <= cx){
			pos[(*kil.begin()).second].erase((*kil.begin()).first);
			if(zap[(*kil.begin()).second].count((*kil.begin()).first))zap[(*kil.begin()).second].erase((*kil.begin()).first);
			kil.erase((*kil.begin()));
		}
		int lim = maxn;
		if(pos[cy].empty())ans.insert(cy);
		else lim = *pos[cy].begin();
		while(zap[cy - 1].size() and *zap[cy-1].begin() <= lim){
			int nx = *zap[cy - 1].begin();
			pq.push(pii(-nx , cy - 1));
			zap[cy - 1].erase(nx);
		}
		while(zap[cy + 1].size() and *zap[cy+1].begin() <= lim){
			int nx = *zap[cy + 1].begin();
			pq.push(pii(-nx , cy + 1));
			zap[cy + 1].erase(nx);
		}
	}
	cout << ans.size();
	return(0);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const lld INF = 1e18;
struct MCMF{
	struct Edge{
		int to,r;
		lld c,cost;
		Edge() : Edge(0,0,0,0){
		}
		Edge(int a,lld b,int c,lld d) : to(a),c(b),r(c),cost(d){
		}
	};
	vector<vector<Edge> > adj;
	vector<pi> par;
	int N,S,E;
	MCMF(int n,int s,int e){
		this->N = n;
		this->S = s;
		this->E = e;
		adj.resize(n);
		par.resize(n);
	}
	void push_edge(int a,int b ,lld c,lld d){
		adj[a].push_back({b,c,sz(adj[b]),d});
		adj[b].push_back({a,0,sz(adj[a])-1,-d});
	}
	bool SPFA(){
		vector<int> inq;
		vector<lld> dst;
		inq.resize(N+5,0);
		dst.resize(N+5,INF);
		inq[S] = 1;
		dst[S] = 0;
		queue<int> q;
		q.push(S);
		while(!q.empty()){
			int x = q.front();q.pop();
			inq[x] = 0;
			for(int i=0;i<sz(adj[x]);i++){
				auto& e = adj[x][i];
				if(e.c<=0) continue;
				if(dst[x]<INF&&dst[e.to]>dst[x]+e.cost){
					dst[e.to] = dst[x] + e.cost;
					par[e.to] = mk(x,i);
					if(inq[e.to]==0){
						inq[e.to] = 1;
						q.push(e.to);
					}
				}
			}
		}
		return dst[E] != INF;
	}
	pl flow(){
		lld work = 0;
		lld money = 0;
		while(SPFA()){
			lld vv = 0;
			lld f = INF;
			for(int i = E;i!=S;i=par[i].x){
				auto& e = adj[par[i].x][par[i].y];
				f = min(f,e.c);
				vv += e.cost;
			}
			work += f;
			money += f*vv;
			for(int i = E;i!=S;i=par[i].x){
				auto& e = adj[par[i].x][par[i].y];
				e.c -= f;
				adj[e.to][e.r].c += f;
			}
		}
		return mk(work,money);
	}
};
const int MAX = 55;
int W[MAX],V[MAX],X[MAX];
void solve(int tc){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	for(int e=1;e<=n;e++) scanf("%d%d",&W[e],&V[e]);
	for(int e=1;e<=m;e++) scanf("%d",&X[e]);
	while(q--){
		int l,r;
		scanf("%d%d",&l,&r);
		lld ans = 0;
		for(int t=1;t<=m;t++){
			int st = 0,ed = n + m + 2;
			MCMF gh(n+m+3,st,ed);
			gh.push_edge(st,1,t,0);
			for(int e=1;e<=m;e++){
				if(e>=l&&e<=r){
					continue;
				}
				gh.push_edge(1,e+1,1,0);
				for(int p=1;p<=n;p++){
					if(X[e]>=W[p]){
						gh.push_edge(e+1,m+1+p,1,-V[p]);
					}
				}
			}
			for(int p=1;p<=n;p++) gh.push_edge(m+1+p,ed,1,0);
			pl now = gh.flow();
			ans = max(ans,-now.y);
		}
		printf("%lld\n",ans);
	}
}

int main(void){
	/*
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/
	int tc = 1;
	/*
		cin >> tc;
	*/
	for(int test_number=1;test_number<=tc;test_number++){
		solve(test_number);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_map>
#include<queue>
#include<deque>
#include<cmath>
#include<bitset>
#include<iomanip>
#include<stack>
#include<map>
#include<tuple>
#define ll long long

using namespace std;

bool ck(int n){
    int x = n;
    while (x > 0){
        if (x % 8 == 7) return false;
        x /= 8;
    }
    x = n;
    while (x > 0){
        if (x % 10 == 7) return false;
        x /= 10;
    }
    return true;
}

int main(){
	int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (ck(i)) ans++;
    }
    cout << ans;
}

#include<iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  n %= 100;
  n = 100-n;
  cout << n << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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

mt19937_64 rnd(time(NULL));

i64 mod_pow(i64 x, i64 y, i64 mod){
	i64 res = 1;
	while(y > 0){
		if(y & 1) res = res * x % mod;
		x = x*x %mod;
		y >>= 1;
	}
	return res;
}

int h,w;
string s[2020];
int a[2020][2020];
bool used[2020][2020];
void solve(){
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> s[i];
	}
	i64 l = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.') l++;
		}
	}

	for(int i = 0; i < h; i++) fill(a[i],a[i]+w,-1);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#') continue;
			if(used[i][j]) continue;
			int c = j;
			while(s[i][j] == '.' && j < w) j++;
			for(int k = c; k < j; k++){
				a[i][k] += j-c;
			}
		}
	}
	for(int i = 0; i < h; i++) fill(used[i],used[i]+w, 0);
	for(int j = 0; j < w; j++){
		for(int i = 0; i < h; i++){
			if(s[i][j] == '#') continue;
			if(used[i][j]) continue;
			int c = i;
			while(s[i][j] == '.' && i < h) i++;
			for(int k = c; k < i; k++){
				a[k][j] += i-c;
			}
		}
	}

	i64 cnt = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#') continue;
			cnt += (mod_pow(2,a[i][j],INF)-1)*mod_pow(2,l-a[i][j],INF);
			cnt %= INF;
		}
	}
	cout << cnt << endl;
}

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

	return 0;
}

#include <cctype>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

char buf[2010][2010];
int ct[2010][2010];
bool used[2][2010][2010];

int main(void) {
  int h, w;
  scanf("%d%d", &h, &w);
  int empty = 0;
  REP(i, h) {
    scanf("%s", buf[i]);
    REP(j, w) {
      if(buf[i][j] == '.') {
        ++empty;
      }
    }
  }
  REP(i, h) {
    REP(j, w) {
      if(buf[i][j] != '.') {
        continue;
      }
      if(!used[0][i][j]) {
        int c = 0;
        for(int ii = i; ii < h && buf[ii][j] == '.'; ++ii) {
          ++c;
        }
        for(int ii = i; ii < h && buf[ii][j] == '.'; ++ii) {
          ct[ii][j] += c;
          used[0][ii][j] = true;
        }
      }
      if(!used[1][i][j]) {
        int c = 0;
        for(int jj = j; jj < w && buf[i][jj] == '.'; ++jj) {
          ++c;
        }
        for(int jj = j; jj < w && buf[i][jj] == '.'; ++jj) {
          ct[i][jj] += c;
          used[1][i][jj] = true;
        }
      }
    }
  }

  mint res = empty * POW(2, empty);
  REP(i, h) {
    REP(j, w) {
      if(buf[i][j] == '#') {
        continue;
      }
      // cerr << ct[i][j] << " ";
      // cerr << POW(2, empty-ct[i][j]+1) << " ";
      res -= POW(2, empty-ct[i][j]+1);
    }
    // cerr << endl;
  }
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

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

signed main() {
  init();
  ll X, Y, A, B;
  cin >> X >> Y >> A >> B;

  if (A >= B) {
    ll c = (Y - X) / B;
    if (c != 0 and (Y - X) % B == 0) c--;
    COUT(c);
    return 0;
  }

  ll ans = 0;
  while (1) {
    ll next1 = X * A;
    ll next2 = X + B;
    if ((ld)X >= (ld)Y / (ld)A) break;
    if (next1 >= Y) break;
    if (next1 >= next2) break;
    X = next1;
    ans++;
  }

  if (Y - X > B) {
    ll count = (Y - X) / B;
    if (count != 0 and (Y - X) % B == 0) count--;
    ans += count;
  }
  ANS;
  return 0;
}

#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
	ll x, y, a, b;
	ll ans = 0;
	cin >> x >> y >> a >> b;
	while ((x + b >= x * a) && a * x < y && (double)a * x <= 2e18) {
		x *= a;
		ans++;
	}
	ans += ((y - x - 1) / b);
	cout << ans << endl;

	return 0;
}


# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vvi = vec<vi>;
using db = deque<bool>;
using ddb = deque<db>;
using vs = vec<string>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); }
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); }
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); }
template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
# endif  // ngng628_library

int32_t main() {
   string s;
   cin >> s;
   for (char c : s) {
      if (c == '.') break;
      cout << c;
   }
   cout << "\n";
}

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

int main()
{
    long long int N;
    cin >> N;
    string str = to_string(N);
    int size = str.size();
    if (size % 2 == 0)
    {
        int num1 = atoi(str.substr(0, size / 2).c_str());
        int num2 = atoi(str.substr(size / 2, size / 2).c_str());
        int count = 0;
        if (num1 > num2) count = num1 - 1;
        else count = num1;

        cout << count << endl;
    }
    else
    {
        int count = 0;
        if (size == 1) count = 0;
        else if (size == 3) count = 9;
        else if (size == 5) count = 99;
        else if (size == 7) count = 999;
        else if (size == 9) count = 9999;
        else if (size == 11) count = 99999;
        else if (size == 13) count = 999999;
        cout << count << endl;
    }
}


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

int main(void)
{
    char S, T;

    cin >> S >> T;

    if(S =='Y') {
        T = toupper(T);
    }
    else {
    }

    cout << T << endl;
    return 0;

}

/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {

	char s, t;
	cin>>s;
	cin>>t;
	if (s == 'Y') {
		if (t == 'a') cout<<"A"<<endl;
		else if (t == 'b') cout<<"B"<<endl;
		else cout<<"C"<<endl;
	}
	else {
		if (t == 'a') cout<<"a"<<endl;
		else if (t == 'b') cout<<"b"<<endl;
		else cout<<"c"<<endl;
	}

	return 0;
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

vector<string> solve(int n) {
  if (n == 1) {
    vector<string> ret;
    ret.push_back("AB");
    return ret;
  }
  vector<string> ret;
  string c = "";
  for (int i = 0; i < (1 << (n - 1)); i++)
    c.push_back('A');
  for (int i = 0; i < (1 << (n - 1)); i++)
    c.push_back('B');
  ret.push_back(c);
  vector<string> lo = solve(n - 1);
  trav(x, lo) {
    ret.push_back(x + x);
    string y = x;
    trav(c, y)
      if (c == 'A')
        c = 'B';
      else
        c = 'A';
    ret.push_back(x + y);
  }
  return ret;
}

int main() {
  FIO
  int n; read(n);
  vector<string> ans = solve(n);
  print(sz(ans));
  trav(x, ans)
    print(x);
  return 0;
}

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

vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};

const int INF = 1000000000;
const ll INFLL = 100000000000000000;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
    ll n; cin >> n;
    if(n == 0){
        cout << "Yes" << endl;
        return 0;
    }
    while(n % 10 == 0){
        n /= 10;
    }

    string s_n = to_string(n);
    string r_n = to_string(n);
    reverse(r_n.begin(), r_n.end());
    if(s_n == r_n){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 3000000000000001 // 3e15
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fill(a, n, x) for(int i = 0; i < n; i++) a[i] = x;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 10000110;
const ll M = log2(N) + 1;

struct point
{
    ll x, y;
};

template<typename T>
T fast_exp(T x,T n)
{
    if(n == 0) return 1;
    T ans = 1;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         ans = ans * ans % mod;
    }
    else ans = fast_exp(x, n - 1) * x % mod;
    return ans;
}

void update(ll BIT[], ll i, ll x, ll n)
{
    if(i <= 0) return;
    for(; i <= n; i += i & (-i))
        BIT[i] += x;
}

ll query(ll BIT[], ll l, ll r)
{
    l--;
    ll sum = 0;
    while(r > 0)
    {
        sum += BIT[r];
        r = r & (r - 1);
    }
    while(l > 0)
    {
        sum -= BIT[l];
        l = l & (l - 1);
    }
    return sum;
}

ll fact[2], infact[2];
void work()
{
    fact[0] = fact[1] = infact[0] = infact[1] = 1;
    for(ll i = 2; i < N; i++)
    {
        fact[i] = fact[i - 1] * i % mod;
        infact[i] = fast_exp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    if(r > n || r < 0) return 0;
    return fact[n] * infact[n - r] % mod * infact[r] % mod;
}

int main()
{
    fast;
    int _ = 1, test = 0;
   // cin >> _;
    while(_--)
    {
        test++;
        ll n, m, x = 0, y = 0, ans = 0, k = 0;
        cin >> n;
        ll a[n + 1];
        for(int i = 1; i <= n; i++) a[i] = 2;
        a[1] = 1;
        for(int i = 2; i <= n; i++)
        {
            x = a[i];
            for(int j = i + i; j <= n; j += i)
            {
                a[j] = x + 1;
            }
        }
        for(int i = 1; i <= n; i++) cout << a[i] << " ";
        //cout << ans << "\n";
    }
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll n;
  cin >> n;
  vector<int> v;
  while (n) {
    v.push_back(n % 10);
    n /= 10;
  }
  reverse(v.begin(), v.end());
  int m = v.size();
  int ans = 1e9;
  for (int bit = 1; bit < (1 << m); ++bit) {
    ll sum = 0;
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
      if (bit >> i & 1) {
        cnt++;
        sum *= 10;
        sum += v[i];
      }
    }
    if (sum % 3 == 0) {
      ans = min(ans, m - cnt);
    }
  }
  cout << (ans == 1e9 ? -1 : ans) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	string base = "atcoder";
	while(t--){
		string s;
		cin >> s;
		int at = 0, n = s.size();
		while(at < base.size() && at < n && base[at] == s[at]) at++;
		if((at < base.size() && at < n && base[at] < s[at]) || (at == base.size() && at < n)) cout << 0 << '\n';
		else if(at == 1){
			int ans = 1<<30;
			while(at < n && s[at] == 'a') at++;
			if(at == n) ans = -1;
			else {
				if(s[at] > 't') ans = at - 1;
				else ans = at;
			}
			cout << ans << '\n';
		} else {
			assert(at > 1);
			cout << 1 << '\n';
		}
	}
	return 0;
}

#include <iostream>
#include <string>

int main() {
  const std::string atcoder = "atcoder";
  int T;
  std::cin >> T;
  for (int t = 0; t < T; ++t) {
    std::string S;
    std::cin >> S;
    if (S > atcoder) {
      std::cout << 0 << std::endl;
      continue;
    }
    int index = -1;
    for (std::size_t i = 0; i < S.size(); ++i) {
      if (S[i] > 'a') {
        index = i;
        break;
      }
    }
    if (index <= 0) {
      std::cout << index << std::endl;
      continue;
    }
    for (int count = 1, i = index - 1; i >= 0; --i, ++count) {
      std::swap(S[i], S[i + 1]);
      if (S > atcoder) {
        std::cout << count << std::endl;
        break;
      }
    }
  }
  return 0;
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
  long long N,Sum,Ans,count;
  cin >> N;
  int A[N];
  count =1;
  Sum =0;
  Ans =0;

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

  for(int j=0;j<N;j++){
    if(A[j]==A[j+1]){
      count++;
    }else{
      Sum += count*count;
      count=1;
    }
  }
  Ans = (N*N-Sum)/2;
  cout << Ans;
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define PI 3.14159265
#define sqr(x) ((x)*(x))
#define vi vector<int>
#define vll vector<long long>
#define vull vector<unsigned long long>
#define all(v) ((v).begin()), ((v).end())
#define rev(v) ((v).rbegin()), ((v).rend())
#define rep(i, st, en) for(int i = st; i < en; i++)
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long int ulli;

//int prefix[MAX];
//ll sieve_size;
//bitset<10000010>bs;
//vll p;
//void sieve(ll upperbound) {
//    sieve_size = upperbound + 1;
//    bs.set();
//    bs[0] = bs[1] = false;
//    for (ll i = 2; i < sieve_size; i++) {
//        if (bs[i]) {
//            for (ll j = i * i; j < sieve_size; j += i) bs[j] = false;
//            p.push_back(i);
//        }
//    }
//    prefix[0] = prefix[1] = 0;
//    for (int p = 2; p <= MAX; p++) {
//        prefix[p] = prefix[p - 1];
//        if (bs[p])
//            prefix[p]++;
//    }
//}

bool isPrime(ll n) {
    // Corner cases
    if (n <= 1) return false;
    if (n <= 3) return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

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

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

template<typename T>
void takeInput(vector<T>& v)
{
    for (auto& value: v)
        cin >> value;
}

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

    int n;
    cin >> n;
    vi v(n);
    takeInput(v);
    int mx = INT_MIN;
    rep(i, 0, n){
        int x = v[i];
        rep(j, i, n){
            x = min(x, v[j]);
            mx = max(mx, x*(j-i+1));
        }
    }

    cout << mx;

    return 0;
}


#include<iostream>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  cout<<(a+b)/2<<" "<<a-(a+b)/2;
}

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

int main(){
    int a,b; cin>>a>>b;
    for(int i=-100; i<=100; ++i){
        for(int j=-100; j<=100; ++j){
            if(i+j==a && i-j==b){
                cout << i <<" "<< j << endl;
                return 0;
            }
        }
    }

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cassert>
#include <cctype>
#include <string>
#include <sstream>
#include <bitset>
#include <list>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define LT(x) (x<<1)
#define RT(x) (x<<1|1)
#define MID(x, y) (x + y) >> 1
typedef vector<ll> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const ll mod = 1000000007;
const ll LINF = 1e16 + 10;
const int MAXN = 2e5 + 24;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

char vec[MAXN];

int main() {
#ifdef kirito
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // kirito
	int n, s;
	while (~scanf("%d %d", &n, &s)) {
		scanf("%s", &vec);
		for (int i = 0; i < n; i++) {
			if (vec[i] == 'x') {
				s--;
				s = max(s, 0);
			}
			else {
				s++;
			}
		}
		printf("%d\n", s);
	}
	return 0;
}

//F - Valid payments
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>

#define ll long long
#define cl(x, y) memset((x), (y), sizeof(x))
#define rep(i, a, b) for(ll i = a; i <= b; i++)
#define per(i, a, b) for(ll i = a; i >= b; i--)
#define de(x) cerr << #x << " = " << x << " "
#define inc_mod(x, y) x = ((x - y) % mod + mod) % mod
#define add_mod(x, y) x = (x + y) % mod
#define add(x, y) x += y
#define inc(x, y) x -= y
#define Lowbit(x) (x & (-x))
#define inf 0x3f3f3f3f3f3f3f3f
#define mod 998244353
#define rson (x << 1 | 1)
#define lson (x << 1)
using namespace std;
const ll maxn = 100;

ll total, limit, ans;
ll num[maxn];
map<ll, ll> cube;

inline void File() {
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
}

signed main() {
    // file();
    ios::sync_with_stdio(false);
    cin >> total >> limit;
    rep(i, 1, total) { cin >> num[i]; }
    cube[limit] = 1;
    rep(i, 1, total-1) {
        ll x = num[i+1] / num[i];
        map<ll, ll> temp;
        map<ll, ll>::iterator iter;
        for(iter = cube.begin(); iter != cube.end(); iter++) {
            if((*iter).first % x) { temp[(*iter).first / x + 1] += (*iter).second; }
            temp[(*iter).first / x] += (*iter).second;
        }
        swap(cube, temp);
    }
    map<ll, ll>::iterator iter;
    for(iter = cube.begin(); iter != cube.end(); iter++)
        ans += (*iter).second;
    cout << ans << endl;
    // fclose(stdin);
    // fclose(stdout);
    // system("pause");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i=0; i<N; ++i) cin >> P[i];

    for (int i=0; i<N; ++i) --P[i];
    vector<int> idx(N);
    for (int i=0; i<N; ++i) idx[P[i]] = i;
    vector<int> ans;
    int cur = 0;
    auto sorted = [&P](int s, int t) -> bool {
        for (int i=s; i<t; ++i) {
            if (P[i] != i + 1) return false;
        }
        return true;
    };
    while (cur < N-1) {
        int id = idx[cur];
        if (id == cur) {
            cout << -1 << '\n';
            return;
        } else if (id == cur + 1) {
            ans.push_back(cur);
            ++idx[P[id-1]];
            swap(P[id-1], P[id]);
            cur = id;
        } else {
            if (!sorted(cur, id-1)) {
                cout << -1 << '\n';
                return;
            }
            for (int i=id-1; i>=cur; --i) ans.push_back(i);
            ++idx[P[id-1]];
            swap(P[id-1], P[id]);
            cur = id;
        }
    }
    if ((int)ans.size() != N-1) cout << -1 << '\n';
    else for (int x : ans) cout << x + 1 << '\n';
}

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

    solve();

    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (200006)
ll n;
vector<pi> v;
int main() {
	FAST
	cin>>n;
	ll mx = -1;
	FOR(i,1,n) {
		ll a; cin>>a;
		if(mx > i && a >= i) {
			cout<<"-1\n";
			return 0;
		}
		if(a > i) {
			v.eb(i, a);
		}
		mx = max(mx, a);
	}
	reverse(all(v));
	vector<ll> o;
	for(auto i:v) {
		FOR(j,i.f,i.s-1) {
			o.eb(j);
		}
	}
	if(o.size()!=n-1) {
		cout<<"-1\n";
		return 0;
	}
	for(auto i:o) cout<<i<<'\n';
	return 0;
}


#pragma GCC optimize("O3")
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

// using mint = modint998244353;
// ostream& operator<<(ostream& out, mint m){
//   out << m.val();
//   return out;
// }

const int P = 998244353;
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += P;
}
int mul(int a,int b){
  return a * b % P;
}
int n;
int res = 0;
vector<vector<int>> dp;
vector<int> t;
void add(int x){
  int pom = t[x];
  int a = SZ(dp);
  int b = SZ(dp[0]);
  vector<vector<int>> dp2(a + 1,vector<int>(b + pom));
  R(i,a)R(j,b){
    add(dp2[i + 1][j + pom], mul(dp[i][j], i + 1));
    if(j <= pom){
      add(dp2[a - i][pom - j], mul(dp[i][j], a - i));
    }else{
      add(dp2[i][j - pom], mul(dp[i][j], a - i));
    }
  }
//   debug(dp,pom,dp2);
  swap(dp,dp2);
}
void licz(int po,int ko){
  if(po + 1 == ko){
    debug(po,dp);
    R(i,SZ(dp)){
      R(j,min(SZ(dp[0]), t[po])){
        sub(res, dp[i][j]);
      }
    }
    debug(po,t[po],res);
    return;
  }
  int m = (po + ko) / 2;
  auto pam = dp;
  for(int i = po; i < m; i++)add(i);
  licz(m,ko);
  swap(dp,pam);
  for(int i = m; i < ko; i++)add(i);
  licz(po,m);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  t.resize(n);
  res = 1;
  R(i,n){
    cin >> t[i];
    res = mul(res, i + 1);
  }
  debug(res);
  dp.resize(1,vector<int>(1,1));
  licz(0,n);
  cout << res << "\n";
}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, m, k;
vector<int> to[100];
typedef vector<int> vec;
typedef vector<vec> mat;

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % MOD;
        x = static_cast<long>(x) * x % MOD;
        y >>= 1;
    }
    return ans;
}

mat mul(mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++) {
        for (int k = 0; k < B.size(); k++) {
            for (int j = 0; j < B[0].size(); j++) {
                C[i][j] = (C[i][j] + scll(A[i][k]) * B[k][j] % MOD) % MOD;
            }
        }
    }
    return C;
}

mat pow(mat A, long n) {
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++) {
        B[i][i] = 1;
    }
    while (n > 0) {
        if (n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main() {
    ci3(n, m, k);
    mat a(n, vec(1));
    rep(i, n) ci(a[i][0]);
    rep(i, m) {
        int x, y;
        ci2(x, y);
        to[x - 1].epb(y - 1);
        to[y - 1].epb(x - 1);
    }
    mat PRO(n, vec(n));
    rep(i, n) {
        rep(j, n) PRO[i][j] = 0;
        for (auto &j: to[i]) PRO[i][j] = 1;
        PRO[i][i] = (2 * m - to[i].size()) % MOD;
    }
    mat POPRO = pow(PRO, k);
    mat ans = mul(POPRO, a);
    int pp = po(po(2 * m, MOD - 2), k);
    rep(i, n) co(scll(ans[i][0]) * pp % MOD);
    return 0;
}