#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME

/******************************************************************************************************************************/

const ll inf = 2e18;
const ll mod = 998244353;
const ll N = 1e5+3;

int main()
{
    auto start_time = Clock;
    FASTIO

    ll n,mxx=0;
    cin >> n;
    vll v(n), mx(n);
    rep(i,n) {
        cin >> v[i];
        chmax(mxx, v[i]);
        mx[i] = mxx;
    }
    ll sum = 0;
    rep(i,n) {
        v[i] += (i?v[i-1]:0);
        sum += v[i];
        cout << (sum+(i+1)*mx[i]) << "\n";
    }

    auto end_time = Clock;
    #ifndef TIME
        return 0;
    #endif
    cout << "\nTime elapsed: "
    << (double)duration_cast<milliseconds>(end_time-start_time).count()
    << "ms";

    return 0;
}

#include <bits/stdc++.h>
#include <climits>

using namespace std;

template<class T>
using V = vector<T>;
template<class T>
using VV = V<V<T>>;

using ld = long double;
#define ll long long
using ull = unsigned ll;
using PLL = pair<ll, ll>;
using VLL = V<ll>;
using VB = V<bool>;
using VVB = VV<bool>;
using VVLL = VV<ll>;
using Gr = VVLL;
using MLL = map<ll, ll>;
#define UMLL unordered_map<ll, ll, custom_hash>

#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

#define R &
#define CR const R

#define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i)
#define FOR(i, n) FORI(i, 0, n)
#define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i)
#define RFOR(i, n) RFORI(i, n, 0)
#define FORA(i, a) for(auto i : a)
#define FORAR(i, a) for(auto R i : a)
#define FORACR(i, a) for(auto CR i : a)
#define ALL(obj) begin(obj), end(obj)
#define Count(q) while(q--)
#define OK cerr << "OK\n";

#define mp make_pair
#define pb push_back

//#define DEBUG

template<class T>
T sqr(T x)
{
    return x * x;
}

void YES(bool g, ostream R os, bool upper = true)
{
    if(g)
        if(upper)
            os << "YES";
        else
            os << "Yes";
    else
        if(upper)
            os << "NO";
        else
            os << "No";

    os << "\n";
}

template<class T>
void show(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        os << i << " ";
    os << "\n";
}

template<class T>
void show2d(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        show(i, os);
    os << "\n";
}

constexpr ll MOD = 1e9 + 7; //998244353;
constexpr ll len = 'z' - 'a' + 1;

constexpr ll INF = 1e15, MINF = -INF;

constexpr ld PI = atanl(1.0L) * 4;
constexpr ld eps = 1e-9, EPS = 1e-9;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

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

//arr
void init() {}

void solve(istream R is, ostream R os)
{
    ll n;
    is >> n;

    string s;
    is >> s;

    char t = s[0];
    bool g = 1;

    FORA(i, s)
        g &= i == t;

    if(g)
    {
        os << "-1\n";
        return;
    }

    if(s.front() != s.back())
    {
        os << "1\n";
        return;
    }

    g = 0;
    FOR(i, n - 1)
        if(t != s[i] && t != s[i + 1])
        {
            g = 1;
        }

    if(g)
        os << "2\n";
    else
        os << "-1\n";
}

void tester(istream R is, ostream R os)
{
    auto seed = time(nullptr);
    //cerr << "seed: " << seed << "\n";
    srand(seed);
    fast
    init();
    ll q = 1;
    //is >> q;

    os << setprecision(999);
    Count(q)
        solve(is, os);
}

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    tester(cin, cout);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int x = 0, m = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') m = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * m;
}
inline void write(int x){
	if(x < 0){
		putchar('-');
		write(-x);
		return;
	}
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}
signed main(){
	int k = read(), x = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k / i; j++){
			x = x + k / (i * j);
		}
	}
	write(x);
}

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

int main() {

  string a,b;
  cin >> a;
  for( int i = a.size()-1 ; i >= 0 ; i--){
    if (a.at(i) == '6'){
      a.at(i) = '9';
    }
    else if (a.at(i) == '9'){
      a.at(i) = '6';
    }
       b += a.at(i);
  }
  cout << b << endl;
}


#include<bits/stdc++.h>
// #define maxn 100010
// #define mod 998244353
using namespace std;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
// int n;
// int A,B;
// int a[maxn]
// int ksm(int x,int y)
// {
	// int r=1;
	// while(y)
	// {
		// if(y&1) r=1ll*r*x%mod;
		// y>>=1,x=1ll*x*x%mod;
	// }
	// return r;
// }
signed main()
{
	int V=read(),T=read(),S=read(),D=read();
	if(T*V<=D&&D<=S*V) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

struct Edge{
    int to, cost;
    Edge(int t, int c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> siz; // 素集合のサイズを表す配列(1 で初期化)

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

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

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if(siz[rx] < siz[ry]) swap(rx,ry);
		siz[rx] += siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：yの根ryをxの根rxにつける
		return;
    }

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

	int size(int x){	//素集合のサイズ
		return siz[root(x)];
	}

};

int uf_num(UnionFind uf, int N){
	int res=0;
	REP(i,N) if(uf.root(i)==i) res++;
	return res;
}

const int INF=2e9+1;	//for some test case (near inf)
const ll INFLL=1e18;
const ll MOD=1e9+7;

ll MODpow(ll x, ll n, ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n >>= 1;
	}
	return res;
}

ll MODcomb(ll n, ll r, ll mod, vl fact){
	ll res=1;
	if(n>=r){
		res=fact[n]%mod;
		res=res*MODpow(fact[r], mod-2, mod)%mod;
		res=res*MODpow(fact[n-r], mod-2, mod)%mod;
	}
	return res;
}

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

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

int main(void){
	int v,t,s,d;
	cin >> v >> t >> s >>d;
	if(v*t<=d && d<=v*s) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;

const ll INF = 1001001001001001;
const int inf = 1001001001;
using P = pair<ll, ll>;

int main() {
    ll A, B;
    cin >> A >> B;
    ll C = B-A;
    for (ll i = C; i >= 1; i--) {
        ll D = B/i;
        if (i*(D-1)>= A) {
            cout << i << endl;
            return 0;
        }
    }

}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

void MAIN() {
    LL A, B;
    scanf("%lld%lld", &A, &B);

    LL ans = 1;
    for (LL i=1; i<=B; i++) {
	LL d = B/i - (A-1)/i;
	if (d >= 2) ans = i;
    }
    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#include <numeric>
#include <memory>
#include <random>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d, e) vector<vector<vector<e>>>(a, VV(b, c, d, e));
#define all(obj) (obj).begin(), (obj).end()
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> v1;
typedef std::vector<v1> v2;
typedef std::vector<v2> v3;
using namespace std;

long long floor_sum(long long n,long long m,long long a,long long b){
	long long res=0;
	if(a>=m){
		res+=n*(n-1)/2*(a/m);
		a%=m;
	}
	if(b>=m){
		res+=n*(b/m);
		b%=m;
	}

	long long y_max=(a*(n-1)+b)/m;
	if(y_max==0) return res;
	return res+y_max+floor_sum(y_max,a,m,(a*(n-1)+b)-m*y_max);
}

void solve(){
  ll x, y, p, q;
  scanf("%lld %lld %lld %lld", &x, &y, &p, &q);

  ll l = 0, r = 1000000000;
  if(floor_sum(r, p+q, 2*(x+y), x+y+q-1) == floor_sum(r, p+q, 2*(x+y), x)){
    std::cout << "infinity" << '\n';
    return;
  }

  while(r-l>1){
    ll mid = (l+r)/2;
    if(floor_sum(mid, p+q, 2*(x+y), x+y+q-1) == floor_sum(mid, p+q, 2*(x+y), x)) l = mid;
    else r = mid;
  }

  ll distsum = 2*(r-1)*(x+y) + x;
  if(distsum % (p+q) >= p) printf("%lld\n", distsum);
  else printf("%lld\n", distsum + (p - distsum % (p+q)));
}

int main(){
  int t;
  scanf("%d\n", &t);
  for(int i=0;i<t;i++) solve();
}

#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
/* * * *   * * *   	* * * */
/* *
 *
 * I love Ylva Eriksson
 *
 * */
const ll mod = 1e9 + 7;
ll add(ll a, ll b) { return a + b > mod ? a + b - mod : a + b; }
ll mult(ll a, ll b) { return a * b % mod; }
ll powmod(ll b, ll e) {
	if (e == 0) return 1;
	ll u = powmod(b, e / 2);
	u = mult(u, u);
	if (e & 1) u = mult(u, b);
	return u;
}
const int maxn = 1010;
ll f[maxn];
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	f[1] = f[0] = 1;
	for (int i = 2; i < maxn; ++i) f[i] = add(f[i - 1], f[i - 2]);
	int n, op[2][2]; cin >> n;
	char ci;
	cin >> ci; op[0][0] = ci - 'A';
	cin >> ci; op[0][1] = ci - 'A';
	cin >> ci; op[1][0] = ci - 'A';
	cin >> ci; op[1][1] = ci - 'A';
	if (n <= 3) { cout << 1 << endl; return 0; }
	if (op[0][1]) { //ABB
		if (op[1][1]) cout << 1 << endl;
		else cout << (op[1][0] == 0 ? powmod(2, n - 3) : f[n - 2]) << endl;
	} else { //AAB
		if(!op[0][0]) cout << 1 << endl;
		else cout << (op[1][0] ? powmod(2, n - 3) : f[n - 2]) << endl;
	}
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvb = vector<vb>;
using pll = pair<ll,ll>;

int main(){
    int n;
    vll x(n),y(n);
    ll s,d;
    cin >> n >> s >> d;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }
    string ans = "No";
    for (int i = 0; i < n; i++)
    {
        if (x[i] < s && y[i] > d)
        {
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

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

int main() {
    ll N,S,D;
    cin >> N >> S >> D;
    bool ans = false;
    rep(i, N) {
        ll X,Y;
        cin >> X >> Y;
        if (X < S) if (Y > D) ans = true;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(){
    long long A, B;
    scanf("%lld %lld", &A, &B);

    int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

    vector <long long> dp(1 << 20, 0);
    dp[0] = 1;

    for(long long x = A; x <= B; x++){
        int mask = 0;
        for(int i = 0; i < 20; i++)
            if(x % primes[i] == 0)mask |= 1 << i;

        for(int i = (1 << 20) - 1; i >= 0; i--)
            if((i & mask) == 0)dp[i | mask] += dp[i];
    }

    printf("%lld\n", accumulate(dp.begin(), dp.end(), 0LL));

    return 0;
}

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007//998244353//1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef  long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef ll ValType;
template<typename  T> void maxtt(T& t1, T t2) {
    t1=max(t1,t2);
}
template<typename  T> void mintt(T& t1, T t2) {
    t1=min(t1,t2);
}
#define MAX (135)

bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
const ll MOD2 = (ll)MOD * (ll)MOD;
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD){
    x+=y; if (x>=mod) x-=mod;
    if(x<0) x+=mod;
    assert(x>=0 && x<mod);
}
void et(int x=-1) {
    printf("%d\n", x); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
ll gcd1(ll x, ll y) {
    return y?gcd1(y,x%y):x;
}

int cnt[100];
int ps[20]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
ll dp[1<<20];
void fmain(int tid) {
    scanf("%lld%lld",&ln,&lm);
    int N=lm-ln+1;
    for(ll i=ln;i<=lm;i++) {
        REP(j,20) if(i%ps[j]==0) {
            cnt[i-ln+1] |= 1<<j;
        }
    }
    dp[0]=1;
    int fe=0;
    REQ(i,N) {
        if (cnt[i]==0) {
            fe++; continue;
        }
        for(int j=(1<<20)-1; j>=0; j--) if ((j&cnt[i])==cnt[i]) {
            int sm=j-cnt[i];
            dp[j]+=dp[sm];
        }
    }
    ll ans=0;
    REP(j, 1<<20) {
        ans += dp[j];
    }
    ans *= 1LL<<fe;
    printf("%lld\n", ans);
}
int main() {
    int t=1;
//    init();
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++){
        if(i)os<<" ";
        os<<v1[i];
    }
    return os;
}
template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    os<<p.first<<" "<<p.second;
    return os;
}
template<typename T> istream& operator>>(istream& is,vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++)is>>v1[i];
    return is;
}

namespace sol{

    void solve(){
        int n,m;
        int i,j,k;
        int a,b,c;
        cin>>n;
        vector<P> v1;
        for(i=0;i<2*n;i++){
            cin>>a;
            v1.push_back({a,i});
        }
        sort(v1.begin(),v1.end());
        string ss(2*n,'(');
        for(i=0;i<n;i++){
            a=v1[i].second;
            ss[a]=')';
        }
        a=-1,b=0;
        bool flag=false;
        for(i=0;i<2*n;i++){
            if(ss[i]=='(')b++;
            else b--;
            if(b<0)flag=true;
            if(b==0){
                if(flag){
                    for(j=a+1;j<=i;j++){
                        if(ss[j]=='(')ss[j]=')';
                        else ss[j]='(';
                    }
                }
                a=i;
                flag=false;
            }
        }
        cout<<ss<<endl;
    }
}

int main(){
    sol::solve();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)
#define x first
#define y second

const int N = 105,MOD = 1e9+7;
pii edges[N * N];
int deg[N];

struct Mat
{
    int c[N][N];
    Mat()
    {
        memset(c,0,sizeof c);
    }
    Mat operator*(const Mat& r) const
    {
        Mat res;
        forn(i,1,N - 1) forn(j,1,N - 1) forn(k,1,N - 1) res.c[i][j] = (res.c[i][j] + 1ll*c[i][k] * r.c[k][j] % MOD) % MOD;
        return res;
    }
    void operator*(int r)
    {
        forn(i,1,N - 1) forn(j,1,N - 1) c[i][j] = 1ll*c[i][j] * r % MOD;
    }
};

Mat qpow(Mat a,int b,int MOD)
{
    Mat res;forn(i,1,N - 1) res.c[i][i] = 1;
    while(b)
    {
        if(b & 1)   res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int qpow(int a,int b,int MOD)
{
    int res = 1;
    while(b)
    {
        if(b & 1)   res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main()
{
    // freopen("D://OJCodes//TTT//in.txt","r",stdin);
    // freopen("D://OJCodes//TTT//out.txt","w",stdout);

    int n,m,k;scanf("%d%d%d",&n,&m,&k);
    Mat f,B;forn(i,1,n)   scanf("%d",&f.c[1][i]);

    forn(i,1,m)
    {
        int u,v;scanf("%d%d",&u,&v);
        ++deg[u];++deg[v];
        edges[i] = {u,v};
    }

    int m_2fact = qpow(m * 2,MOD - 2,MOD);

    forn(i,1,m)
    {
        int u = edges[i].x,v = edges[i].y;
        B.c[u][v] = m_2fact;
        B.c[v][u] = m_2fact;
    }

    forn(i,1,n) B.c[i][i] = (2 * m - deg[i]) * 1ll * m_2fact % MOD;

    B = qpow(B,k,MOD);
    f = f * B;
    forn(i,1,n) printf("%d\n",f.c[1][i]);

    // fclose(stdin);
    // fclose(stdout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,L;
    cin >> N >> L;
    vec<int> A(N+2),B(N+2);
    for(int i=1;i<=N;i++) cin >> A[i];
    for(int i=1;i<=N;i++) cin >> B[i];
    A[N+1] = B[N+1] = L+1;
    vec<int> C(N+1),D(N+1);
    for(int i=0;i<=N;i++){
        C[i] = A[i+1]-A[i]-1;
        D[i] = B[i+1]-B[i]-1;
    }
    ll ans = 0;
    int sum = 0,r = 0;
    for(int i=0;i<=N;i++) if(D[i]){
        while(C[r]==0) r++;
        int l = r;
        while(r<=N && sum+C[r]<=D[i]){
            sum += C[r++];
            if(sum==D[i]) break;
        }
        if(sum!=D[i]){
            cout << "-1\n";
            return 0;
        }
        if(r<=i) ans += i-l;
        else if(i<=l) ans += r-i-1;
        else ans += r-l-1;
        sum = 0;
    }
    cout << ans << "\n";
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array
clock_t time_req = clock()*1.0/CLOCKS_PER_SEC;

map<int,pair<int,int>> read(int n , int L){
	vector<int> v{0};
	for(int i = 1 ; i <= n + 1; i++){
		int ai = L+1;
		if(i <= n){
			cin >> ai;
		}
		v.push_back(ai-i);
	}
	map<int,pair<int,int>> interval;
	for(int i = 0 ; i < (int)v.size() ; i++){
		if( i == 0 || v[i] != v[i-1]){
			interval[v[i]].first = i;
		}
		interval[v[i]].second = i;
	}
	return interval;
}

void test_case() {
	int n , L;
	cin >> n >> L;
	auto a = read(n,L);
	auto b = read(n,L);
	debug() << imie(a);
	debug() << imie(b);
	ll answer = 0;
	for(auto pp : b){
		int value = pp.first;
		if(!a.count(value)){
			puts("-1");
			return;
		}
		answer += max(0,a[value].first - b[value].first) + max(0,b[value].second - a[value].second);
	}
	cout<<answer<<"\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//cin >> T;
	while(T--){
		test_case();
	}
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N=105;
int n,m,k;
ll f[N][N*N*N];
ll pre[N*N*N];
int main() {
    cin>>n>>k>>m;
    const int mod=m;

    f[0][0]=1;
    int sum=0;

    for(int i=1;i<=n;i++) {
        sum+=i*k;
        for(int s=0;s<=sum;s++) {
            /*
            for(int q=0;q<=k&&i*q<=s;q++) {
                f[i][s]=(f[i-1][s-q*i]+f[i][s])%mod;
            }*/
            f[i][s]=f[i-1][s];
            if(s>=i) f[i][s]+=f[i][s-i];
            if(s>=i*(k+1)) f[i][s]-=f[i-1][s-i*(k+1)];
            f[i][s]=(f[i][s]+mod)%mod;
        }
    }

    for(int ave=1;ave<=n;ave++) {
        ll ans=0;
        int L=ave-1,R=n-ave;
        for(int j=1;j<=sum;j++) ans=(ans+f[L][j]*f[R][j])%mod;
        cout<<(ans*(k+1)+k)%mod<<"\n";
    }

    return 0;
}

/*
2
2 3
1
*/

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

int main() {
	long long k,n,m,i,j,cur;
	cin >> k >> n >> m;
	vector<long long> a(k),b(k);
	set<pair<long long,long long>> s;
	pair<long long,long long> p;
	cur=0;
	for(i=0; i<k; i++){
		cin >> a[i];
		b[i]=((a[i]*m+(n-1))/n);
		cur+=b[i];
		p.first=b[i]*n-a[i]*m; p.second=i;
		s.insert(p);
	}
	cur-=m;
	auto itr=s.begin();
	while(cur>0){
		itr=s.end(); itr--;
		p=*itr;
		s.erase(itr);
		b[p.second]--;
		p.first-=n;
		s.insert(p);
		cur--;
	}
	for(i=0; i<k; i++){
		cout << b[i] << endl;
	}

	return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int>A(N);
    vector<int>B(M);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < M; i++){
        cin >> B.at(i);
    }
    vector<int>cnt(1001);
    for(int i = 0; i < 1001; i++){
        cnt.at(i) = 0;
    }
    for(int i = 0; i < N; i++){
        cnt.at(A.at(i))++;
    }
    for(int i = 0; i < M; i++){
        cnt.at(B.at(i))++;
    }
    for(int i = 0; i < 1001; i++){
        if(cnt.at(i) == 1){
            cout << i << " ";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define rep1(i,n) for(int i = 1 ; i <= (n) ; i++)
#define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--)
#define rrep1(i,n) for(int i = (n) ; i > 0 ; i--)
#define INF 1001001001
#define MOD 1000000007
using ll = int64_t;
using P = pair<int, int>;
using PL = pair<ll,ll>;
using PD = pair<double,double>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define v(n) vector<n>
#define vv(n) vector<vector<n>>
#define vvv(n) vector<vector<vector<n>>>
#define line cout << "================================" << endl;
#define Yn(x) cout << ((x) ? "Yes" : "No") << endl;
#define yn(x) cout << ((x) ? "yes" : "no") << endl;
#define mmax(a,b) a = max(a,b)
#define mmin(a,b) a = min(a,b)
#define debug(x) cout << #x" : " << x << endl;

int main(){
    int n, m;
    cin >> n >> m;
    vi vec(1001,0);
    rep(i,n){
        int x;
        cin >> x;
        vec[x]++;
    }
    rep(i,m){
        int x;
        cin >> x;
        vec[x]++;
    }

   rep(i,vec.size()){
       if(vec[i] == 1)cout << i << " ";
   }
    cout << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  ll n; cin >> n;
  vl a;
  while(n > 0) {
    a.push_back(n % 10);
    n /= 10;
  }

  int m = sz(a);
  map<int,int> mp;
  int sum = 0;
  rep(i,m) {
    a[i] %= 3;
    mp[a[i]]++;
    sum += a[i];
  }

  if(sum % 3 == 0) cout << 0 << "\n";
  if(sum % 3 == 1) {
    if(mp[1] >= 1 && m > 1) cout << 1 << "\n";
    else if(mp[2] >= 2 && m > 2) cout << 2 << "\n";
    else cout << -1 << "\n";
  }
  if(sum % 3 == 2) {
    if(mp[2] >= 1 && m > 1) cout << 1 << "\n";
    else if(mp[1] >= 2 && m > 2) cout << 2 << "\n";
    else cout << -1 << "\n";
  }

  return 0;
}

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
ll vis[100000];
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk;
   string s;
	  cin>>s;
	  ll sum=0;
	  for(i=0;i<s.size();i++)
	  {
	  	 if((s[i]-'0')%3==1) vis[1]++,sum+=1;
	  	 else if((s[i]-'0')%3==2) vis[2]++,sum+=2;
	  	 else vis[0]++;
	  }
	  if(sum%3==1)
	  {
	  	  if(vis[1]==1&&(vis[2]||vis[0])||vis[1]>1) printf("%lld\n",(ll)1);
	  	  else if(vis[2]==2&&(vis[1]||vis[0])||vis[2]>2) printf("%lld\n",(ll)2);
	  	  else printf("-1\n");
	  }
	  else if(sum%3==2)
	  {
	  	  if(vis[2]==1&&(vis[1]||vis[0])||vis[2]>1) printf("%lld\n",(ll)1);
	  	  else if(vis[1]==2&&(vis[2]||vis[0])||vis[1]>2) printf("%lld\n",(ll)2);
	  	  else printf("-1\n");
	  }
	  else printf("0\n");

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define fillc(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 1e17
#define multi_test 0

vector<vector<ll>> v(65,vector<ll>(65,0));

void ncr()
{
	v[0][0]=1;
	for(ll i=1;i<=60;i++)
	{
		v[i][0]=1;
		//cout<<v[i][0]<<" ";
		for(ll j=1;j<=i;j++)
		{
			v[i][j]=v[i-1][j]+v[i-1][j-1];
			//cout<<v[i][j]<<" ";
		}
		//cout<<endl;
	}
}

void solve()
{
	ll a,b,k,i,j;
	cin>>a>>b>>k;
	string s;
	/*for(i=0;i<=60;i++)
	{
		for(j=0;j<=i;j++)
			cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	for(ll i=0;i<a;i++)
		s+='a';
	for(ll i=0;i<b;i++)
		s+='b';
	//cout<<s<<" ";
	for(ll i=1;i<=b;i++)
	{
		ll p=i+a,c=0;
		//c=v[a+b-p][b-i];
		while(k>c)
		{
			c=v[a+b-p][b-i];
			//cout<<c<<endl;
			if(k>c)
			{
				k-=c;
				swap(s[p-1],s[p-2]);
				p--;
			}
		}
		//cout<<a+b-p<<" "<<b-i<<" "<<c<<endl;;
	}
	cout<<s<<endl;
}

int main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ncr();
    int t=1,i;
    if (multi_test)
        cin>>t;
    for(i=1;i<=t;i++)
        solve();
}

/**
 * @author      : xnyuq
 * @created     : 24/05/2021 19:56:30 +07
 * @filename    : abc202d
 */

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef QUYNX_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const int MX = 35;
vector<vector<int64_t>> dp(MX+1, vector<int64_t>(MX+1));

string findKth(int A, int B, int64_t K) {
    if (A == 0) return string(B, 'b');
    if (B == 0) return string(A, 'a');
    if (K <= dp[A-1][B]) return "a" + findKth(A-1, B, K);
    else return "b" + findKth(A, B - 1, K - dp[A-1][B]);
}

int main() {
    ios_base::sync_with_stdio(false);
#ifndef QUYNX_DEBUG
    cin.tie(nullptr);
#endif
    int A, B;
    int64_t K;
    cin >> A >> B >> K;
    dp[0][0] = 1;
    for (int i = 0; i <= A; ++i) {
        for (int j = 0; j <= B; ++j) {
            if (i) dp[i][j] += dp[i-1][j];
            if (j) dp[i][j] += dp[i][j-1];
        }
    }
    cout << findKth(A,B,K) << "\n";
}


#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n, m, a, b;
    cin >> n >> m;
    bool ok[n][n];
    memset(ok, 0, sizeof(ok));
    rep(i, m){
        cin >> a >> b;
        a--; b--;
        ok[a][b] = ok[b][a] = true;
    }
    rep(i, n) ok[i][i] = true;
    m = 1 << n;
    bool connect[m];
    memset(connect, 0, sizeof(connect));
    connect[0] = 1;
    rep(bit, m){
        rep(i, n) if(bit >> i & 1){
            if(!connect[bit - (1 << i)]) continue;
            bool c = true;
            rep(j, n) if(bit >> j & 1){
                if(!ok[i][j]) c = false;
            }
            if(c){
                connect[bit] = true;
                break;
            }
        }
    }

    int cost[m];
    rep(i, m) cost[i] = 20;
    cost[0] = 0;
    rep(bit, m){
        if(connect[bit]) {
            cost[bit] = 1;
            continue;
        }
        int i = (bit - 1) & bit;
        for(;i>=1;i=(i-1)&bit){
            cost[bit] = min(cost[bit], cost[i] + cost[bit - i]);
        }
    }
    cout << cost[m - 1] << endl;
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <sstream>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define debug(s, param) std::cerr << s << param << std::endl;

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

const int INF = 1e9;
const ll INFL = 1e18;
const ll MOD = 1000000007;

int main() {
  ll n, k; cin >> n >> k;
  map<ll, ll> m;
  rep (i, n) {
    ll a, b; cin >> a >> b;
    m[a] += b;
  }
  ll ans = 0;
  ll current = 0;
  for (auto [village, money] : m) {
    ll cost = village - current;
    if (k >= cost) {
      ans = village;
      k -= cost;
    } else {
      ans += k;
      k = 0;
      break;
    }
    k += money;
    current = village;
  }
  ans += k;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node{long long x,y;}f[200002];
long long n,a=0,b=0,cnt=0;
bool cmp(node x,node y){return 2*x.x+x.y>2*y.x+y.y;}
int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;++i)scanf("%lld%lld",&f[i].x,&f[i].y),a+=f[i].x;
    sort(f,f+n,cmp);
    while(b<=a){b+=f[cnt].x+f[cnt].y;a-=f[cnt].x;++cnt;}
    printf("%lld",cnt);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second

//implementation mistakes:

//binary search on unsorted array
//1 to 2e5 instead of 0 to 4e5 (bounds)
//writing mnn=min(mn,value)
//writing n instead of m in bounds
//forgot to mod at every step since ai<1e18 and sum would exceed limits
//declared the using the global empty string instead of local string

//forgot to take input k
//intrepreted the question wrongly

//wrinting i instead of w[i]
//if instead of else if  -swapping two times
//printing ans without calculating it :):):)

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

   int sum=0;
   vector <int> v;

   F(i,1,n){
   	int a,b;
   	cin>>a>>b;
   	sum-=a;
   	v.pb(2*a+b);
   }
   sort(all(v));
   reverse(all(v));

   if(sum>0) out(0);
   F(i,0,n-1){
   	sum+=v[i];
   	if(sum>0) out(i+1);
   }
}


#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define mod 1000000007
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);
#define rep(i, x, y)    for (lol i = x; i <= y; i++)
#define repi(i, x, y)   for (lol i = x; i >= y; i--)
#define TC(x)           sci(x); while (x--)
#define sci(x)          lol x; cin>>x;
#define scii(x, y)      lol x, y; cin>>x>>y;
#define sciii(x, y, z)  lol x, y, z; cin>>x>>y>>z;
#define F first
#define S second
#define mp make_pair
#define pb push_back
int main(){
    Fast;
    scii(x, y);
    x = min(x, y);
    scii(z, w);
    z = min(z, w);
    cout << min(x, z)<<"\n";
}
/*##

*/

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  cout<<min(A, min(B, min(C, D)))<<endl;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

    string S;
    cin >> S;
    for(int i=0; i<S.length(); i+=2) { if(isupper(S[i])) { cout << "No"; return 0; } }
    for(int i=1; i<S.length(); i+=2) { if(islower(S[i])) { cout << "No"; return 0; } }
    cout << "Yes";

    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << n-1;
}


#include <iostream>
#include <tuple>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<std::tuple<int, int>> intervals;
  for (int i = 0; i < N; ++i) {
    int t, l, r;
    std::cin >> t >> l >> r;
    l = 2 * l + (t >= 3);
    r = 2 * r - (t % 2 == 0);
    intervals.emplace_back(l, r);
  }
  int count = 0;
  for (int i = 0; i < N; ++i) {
    const auto [li, ri] = intervals[i];
    for (int j = 0; j < i; ++j) {
      const auto [lj, rj] = intervals[j];
      count += std::max(li, lj) <= std::min(ri, rj);
    }
  }
  std::cout << count << std::endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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;
}
#define FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

    ll N;
    cin >> N;
    VD L(N), R(N);
    REP(i, N) {
        double t, l, r;
        cin >> t >> l >> r;
        if (t == 1) { r += 0.1; }
        if (t == 3) { l += 0.1, r += 0.1; }
        if (t == 4) { l += 0.1; }
        L[i] = l, R[i] = r;
    }
    ll ans = 0;
    REP(i, N) {
        FOR(t, i + 1, N) {
            if (L[i] < R[t] && L[t] < R[i]) ans++;
            // if (max(L[i], L[t]) < min(R[i], R[t])) ans++;
        }
    }

    COUT(ans);
}


#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int a, b, c;

void print()
{
    a < b ? cout << "<" : a == b ? cout << "="
                                : cout << ">";
}

int main()
{
    cin >> a >> b >> c;
    if (c%2==0)
    {
        a = abs(a);
        b = abs(b);
        print();
    }
    else
    {
        print();
    }
    return 0;
}

#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(i, j, n) for (ll i = j; i < (n); i++)
#define Repr(i, j, n) for (ll i = j; i >= (n); i--)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
template<class T> inline bool chmax(T& a, T b)
  { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b)
  { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
#define MOD 1000000007

int main(){
  int n,a,b; cin >> n >> a >> b;
  cout << n-a+b<< endl;
}


#include<bits/stdc++.h>
using namespace std;
#define _ 0
const long long maxn=1e5+5;
const long long inf=0x7fffffff;
long long n,a[maxn],minv=inf;
void dfs(long long k,long long s1,long long s2)
{
	if(k==n+1)
	{
		minv=min(minv,s1^s2);
		return ;
	}
	dfs(k+1,s1|a[k],s2);
	dfs(k+1,a[k],s1^s2);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    cin>>n;
    for(long long i=1;i<=n;i++)
    	 cin>>a[i];
    dfs(0,0,0);
    cout<<minv<<endl;
	return ~~(0^_^0);
}

/**
 *  author: MKutayBozkurt
 *  created: 01.04.2021 08:26:08
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int N; cin >> N;
  vector<long long> A(N); for (auto &x : A) cin >> x;
  long long ans = 1e18;
  for (int i = 0; i < (1 << N); i++) {
    long long ored = 0, xored = 0;
    for (int j = 0; j < N; j++) {
      int k = i & (1 << j);
      ored |= A[j];
      if (k) {
        xored ^= ored;
        ored = 0;
      }
    }
    xored ^= ored;
    ans = min(ans, xored);
  }
  cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-9
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rrep(i,r,l) for(int i=r-1;i>=l;i--)
typedef long long ll;
const int maxn=3e5+5;
int n,q,b[maxn];
struct Node{
	int l,r,val,mid;
	void update(int x){
		val^=x;
	}
}a[maxn<<2];
void push_up(int x)
{
	a[x].val=a[x<<1].val^a[x<<1|1].val;
}
void build(int x,int l,int r)
{
	a[x].l=l,a[x].r=r,a[x].mid=(l+r)>>1;
	if(l!=r){
		int mid=a[x].mid;
		build(x<<1,l,mid);
		build(x<<1|1,mid+1,r);
		push_up(x);
	}
	else a[x].val=b[l];
}
void update(int x,int pos,int val)
{
	a[x].update(val);
	int l=a[x].l,r=a[x].r;
	if(l!=r){
		int mid=a[x].mid;
		if(pos<=mid) update(x<<1,pos,val);
		else update(x<<1|1,pos,val);
	}
}
int query(int x,int l,int r)
{
	int L=a[x].l,R=a[x].r;
	if(l<=L&&R<=r) return a[x].val;
	else {
		int mid=a[x].mid,ans=0;
		if(l<=mid) ans^=query(x<<1,l,r);
		if(r>mid) ans^=query(x<<1|1,l,r);
		return ans;
	}
}
int main()
{
	cin>>n>>q;
	rep(i,1,n+1) cin>>b[i];
	build(1,1,n);
	while(q--){
		int t,x,y;
		cin>>t>>x>>y;
		if(t==1) update(1,x,y);
		else cout<<query(1,x,y)<<endl;
	}
	return 0;
}

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

int main() {
int x, y;
  cin >> x >> y;
  vector<vector<int>> cyancheck(51, vector<int>(51));
  cyancheck.at(x).at(y) = 1;
  int k = 2;
  vector<vector<int>> cyanmond(51, vector<int>(51));
    for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 50; j++) {
      cin >> cyanmond.at(i).at(j);
      if(!(j == 0)){
      if(cyanmond.at(i).at(j) == cyanmond.at(i).at(j - 1)){
        cyancheck.at(i).at(j) = k;
        cyancheck.at(i).at(j - 1) = k;
        k++;
      }
      }
      if(!(i == 0)){
      if(cyanmond.at(i).at(j) == cyanmond.at(i - 1).at(j)){
        cyancheck.at(i).at(j) = k;
        cyancheck.at(i - 1).at(j) = k;
        k++;
      }
      }

    }
  }

  if(x > 25 && y < 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) == 1)){
      cout << "U";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x - 1).at(y) = 1;
      x = x - 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){
      cout << "R";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }
    if(x <= 25 && y < 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){
      cout << "D";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x + 1).at(y) = 1;
      x = x + 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){
      cout << "R";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }

    if(x > 25 && y >= 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) = 1)){
      cout << "U";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x - 1).at(y) = 1;
      x = x - 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){
      cout << "L";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y + 1) = 1;
      y = y + 1;
    }
    }
       if(x <= 25 && y >= 25){
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){
      cout << "D";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x + 1).at(y) = 1;
      x = x + 1;}
    if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){
      cout << "L";
      cyancheck.at(x).at(y) = 1;
      cyancheck.at(x).at(y - 1) = 1;
      y = y - 1;
    }
    }

}


#include <bits/stdc++.h>

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

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

  int max_p = 3 * pow(10, 5);
  vector<int> cnts(max_p, 0);
  int cur = 0;

  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    cnts[va[i]]++;

    while (cnts[cur] > 0) {
      cur++;
    }

    ans.push_back(cur);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vS; typedef vector <vector <int>> vv; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef string S; typedef map <ll, ll> ml; typedef map <int, bool> mb; typedef vector <ld> vld; typedef vector <bool> vb; typedef map<ll, ll> mll;
#define FOR(i,N) for(int i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(int i = a; i <=b;i++)
#define dFOR(i,N) for(int i = N - 1; i>=0;i--)
#define edFOR(i,a,b) for(int i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define pb push_back
#define PI 3.14159265359
const int mod = 1e9 + 7;
int CASE = 1;
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
void solve()
{
	int n;
	cin >> n;
	mb mp;
	int k = 0;
	FOR(i, n)
	{
		int x;
		cin >> x;
		mp[x] = true;
		while (mp[k])
			k++;
		cout << k << endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int a[105];
long long E[105][105],A[105][105],B[105][105],C[105][105];
long long qpow(long long x,int n){
	long long ans=1;
	for(;n;n>>=1,x=x*x%mod)if(n&1)ans=ans*x%mod;
	return ans;
}
void mul(long long a[105][105],int n){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			C[i][j]=0;
			for(int k=1;k<=n;k++)C[i][j]=(C[i][j]+a[i][k]*a[k][j])%mod;
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=C[i][j];
}
void mul(long long a[105][105],long long b[105][105],int n){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			C[i][j]=0;
			for(int k=1;k<=n;k++)C[i][j]=(C[i][j]+a[i][k]*b[k][j])%mod;
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=C[i][j];
}
void Mqpow(int n,int k){
	for(int i=1;i<=n;i++)A[i][i]=1;
	for(;k;k>>=1,mul(E,n))if(k&1)mul(A,E,n);
}
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)E[i][i]=1;
	int I=qpow(m,mod-2),I2=qpow(2*m,mod-2);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		E[u][u]=(E[u][u]-I2+mod)%mod;
		E[v][v]=(E[v][v]-I2+mod)%mod;
		E[u][v]=(E[u][v]+I2)%mod;
		E[v][u]=(E[v][u]+I2)%mod;
	}
	Mqpow(n,k);
	for(int i=1;i<=n;i++){
		long long ans=0;
		for(int j=1;j<=n;j++)ans=(ans+A[i][j]*a[j])%mod;
		printf("%lld\n",ans);
	}
}

#include<bits/stdc++.h>
// #pragma optimize("-O3")
//  #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native")
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
//#define BIG_INF 1e18
#define vi vector<ll>
#define sz(a) ll((a).size())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1)
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// typedef tree<
// ll,
// null_type,
// less<ll>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;
typedef long long ll;
 const ll BIG_INF = 3e18;
ll mod = 1e9+7;
 ll fast_exp(ll a, ll b)
{
    if(b <= 0)
       return 1;
    else
    {
       ll res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;

    }
}

typedef long double ld;
const long long N = 1e5+1000;
const long double pi = acos(-1.0);
using cd = complex<double>;
const double PI = acos(-1);

int par[2][N] = {};
int comp[2] = {};

int find_par(int v, int mode)
{
    if(par[mode][v] == v)
        return v;
    else
        return par[mode][v] = find_par(par[mode][v],mode);
}

void union_find(int a, int b, int mode)
{
    a = find_par(a,mode);
    b = find_par(b,mode);
    if(a != b)
    {
        par[mode][a] = b;
        comp[mode]--;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    int h, w;
    cin >> h >> w;
    char a[h][w] = {};
    for(int i = 0; i<h; i++)
        for(int j = 0; j<w; j++)
        {
            cin >> a[i][j];
        }
        a[0][0] = '#';
        a[h-1][0] = '#';
        a[0][w-1] = '#';
        a[h-1][w-1] = '#';
    for(int i = 0; i<h; i++)
        par[0][i] = i;
    comp[0] = h;
    for(int i = 0; i<w; i++)
        par[1][i] = i;
    comp[1] = w;

    for(int category = 0; category < w; category++)
    {
        int prev = -1;
        for(int i = 0; i<h; i++)
        {
            if(a[i][category] == '#')
            {
                if(prev == -1)
                    prev = i;
                else
                {
                    union_find(prev,i,0);
                    prev = i;
                }
            }
        }
    }

    for(int category = 0; category < h; category++)
    {
        int prev = -1;
        for(int i = 0; i<w; i++)
        {
            if(a[category][i] == '#')
            {
                if(prev == -1)
                    prev = i;
                else
                {
                    union_find(prev,i,1);
                    prev = i;
                }
            }

        }
    }

    int ans = min(comp[0],comp[1]);
    ans--;
    cout << ans << '\n';

    // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
    return 0;

}


//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define INF 2e9
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
struct Edge{int to; ll w; Edge (int to, ll w) : to(to), w(w) {} };
typedef vector<vector<int> > Graph;
typedef vector<vector<Edge> > Graphw;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> void chmax(T& a, T b){if(a<b)a=b;}
template<class T> void chmin(T& a, T b){if(a>b)a=b;}

string s1,s2,s3,S;
map<char, int> mp;
vector<char> vec;
ll kind;
int P[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int main(){
    cin >> s1 >> s2 >> s3;
    S = s1+s2+s3;
    REP(i,S.length()){
        vec.pb(S[i]);
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    REP(i,vec.size()){
        mp[vec[i]] = 0;
    }
    kind = vec.size();

    if(kind > 10){
        cout << "UNSOLVABLE"<<endl;
        return 0;
    }

    do {
        ll n1=0,n2=0,n3=0;
        REP(i,mp.size()){
            mp[vec[i]]=P[i];
        }
        if(mp[s1[0]]==0 || mp[s2[0]]==0 ||mp[s3[0]]==0)continue;

        //n1
        REP(i,s1.length()){
            n1 = n1*10 + mp[s1[i]];
        }
        REP(i,s2.length()){
            n2 = n2*10 + mp[s2[i]];
        }
        REP(i,s3.length()){
            n3 = n3*10 + mp[s3[i]];
        }
        if(n1+n2==n3){
            cout<<n1<<endl<<n2<<endl<<n3<<endl;
            return 0;
        }

    } while(next_permutation(P, P + 10));

    cout << "UNSOLVABLE"<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> s(3);
    REP(i,3) cin >> s[i];
    string nm;
    REP(i,26){
        char c = (char)('a'+i);
        REP(j,3){
            bool f = false;
            for(char ci : s[j]){
                if(ci==c){
                    f= true;
                    break;
                }
            }
            if(f){
                nm += c;
                break;
            }
        }
    }
    int nx = nm.size();
    if(nx>10){
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    vector<char> v(10);
    REP(i,10) v[i]=(char)('0'+i);
    do {
        vector<char> vc(26);
        REP(i,nx){
            vc[(int)(nm[i]-'a')] = v[i];
        }
        bool f = false;
        REP(i,3){
            if(vc[(int)(s[i][0]-'a')]=='0'){
                f=true;
            }
        }
        if(f) continue;
        vector<string> t(3,"");
        REP(i,3){
            for(char c:s[i]){
                t[i] += vc[(int)(c-'a')];
            }
        }
        ll a,b,c;
        a = stoll(t[0]);
        b = stoll(t[1]);
        c = stoll(t[2]);
        if(a+b==c){
            REP(i,3){
                cout << t[i] << endl;
            }
            return 0;
        }
    } while( next_permutation(v.begin(), v.end()) );
    cout << "UNSOLVABLE" << endl;
    return 0;
}


#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

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

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

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<long long> fact(long long x){
    vector<long long> res;
    for(int i = 1;i*i <= x;i++){
        if (x % i == 0){
            res.push_back(i);
            res.push_back(x / i);
        }
    }

    return res;
}

bool isprime(int p){
    if (p == 1) return false;
    for(int i = 2;i < p;i++){
        if (p % i == 0){
            return false;
        }
    }
    return true;
}

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

    while(b){
        int64_t t = a/b;
        a -= t*b;
        swap(a, b);
        u -= t*v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;

    return u;
}

// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

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

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    set<int> st;
    for(int i = 0;i <= n;i++){
        st.insert(i);
    }

    int ans = n;
    vector<int> cnt(n, 0);
    for(int i = 0;i < m;i++){
        cnt[a[i]]++;
        if (cnt[a[i]] == 1) st.erase(a[i]);
    }
    ans = min(ans, *st.begin());
    for(int i = m;i < n;i++){
        cnt[a[i]]++;
        cnt[a[i - m]]--;
        if (a[i] != a[i - m]){
            if (cnt[a[i]] == 1) st.erase(a[i]);
            if (cnt[a[i - m]] == 0) st.insert(a[i - m]);
        }
        ans = min(ans, *st.begin());
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
// 数値型
using ll= long long;
using ull= unsigned long long;
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define FORB(i,I) for(auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e18
#define PI 3.141592653589
// #define MOD 1000000007 //問題による
// #define MOD (int)1e9+7 //10^9+7:合同式の法
//略記
#define FS first
#define SC second
#define PB push_back
#define Graph vector<vector<ll>>
#define Pll2 pair<ll,ll>
#define Vll vector<ll>
#define VVll vector<vector<ll>>
#define VPll2 vector<pair<ll,ll>>
#define DDD fixed<<setprecision(10)
//出力(空白区切りで昇順に)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define coutALL(x) for(auto iii=x.begin();iii!=--x.end();iii++)cout<<*iii<<" ";cout<<*--x.end()<<endl;
#define coutline cout<<"======================================================="<<endl;
#define coutlinec(x) cout<<string(55, x)<<endl;
//その他
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);
using namespace std;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))
/*..................DEFINE GLOBAL VARIABLES...................*/

/*.....................DEFINE FUNCTIONS ......................*/
#define sqr(x)  ((x) * (x)) // xの二乗値を求める
#define cub(x)  ((x) * (x) * (x)) // xの三乗値を求める
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

/*.........................MAIN...........................*/
signed main() {
    //小数の桁数の出力指定
    //cout<<fixed<<setprecision(10);
    __MAGIC__
    //
    ll N, M;
    cin >> N >> M;
    //
    ll sz = N+1;
    VVll pos(sz, Vll(1, -1));
    REP(i, N) {
        ll a; cin >> a;
        pos[a].PB(i);
    }
    //
    REP(i, sz){ pos[i].PB(N); }
    //
    REP(i, sz) {
        ll pos_size = SIZE(pos[i]);
        // coutALL(pos[i]);
        REP(j, pos_size-1) {
            if ((pos[i][j+1] - pos[i][j]) > M) {
                cout << i << endl;
                return 0;
            }
        }
    }

    //
    return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

void _case()
{
    ll n,k,i,ans=0;
    cin>>n>>k;
    k=abs(k);
    vl v;
    v.pb(1), v.pb(2);
    for(i=2;i<=2*n;i++) v.pb(min(i-1,2*n+1-i));
    for(i=2;i+k<=2*n;i++) ans+= (v[i]*v[i+k]);
    cout<<ans el;
}

main()
{
    fastio();
    _case();

}

///Thank you.

///Brainless_Loco Terminates Here!

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, MOD=998244353;

int n, k;
ll ans;

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

	cin>>n>>k;

	for (int i=max(1, k+2); i<=2*n; i++){
		if(i-k>2*n)break;
		int j=i-k;
		ans+=(ll)min((i-1), 2*n-i+1)*min((j-1), 2*n-j+1);
	}
	cout<<ans;
}


#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>to[100005];
int dp[100005];
int sz[100005];

void dfs(int v, int p = -1) {
	int csub = 0;
	dp[v] = 1;
	sz[v] = 1;
	vector<int>c;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, v);
		sz[v] += sz[e];
		int num = dp[e];
		if ((num < 0) && (0 == (sz[e] % 2))) {
			//case1
			dp[v] += num;
		}
		else if ((num >= 0) && (0 == (sz[e] % 2))) {
			//case2
			csub += num;
		}
		else {
			//case3
			c.push_back(num);
		}
	}
	sort(all(c));
	c.push_back(csub);
	rep(i, c.size()) {
		if (0 == i % 2) {
			dp[v] += c[i];
		}
		else {
			dp[v] -= c[i];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	rep(i, N - 1) {
		int p;
		cin >> p;
		p--;
		to[i + 1].push_back(p);
		to[p].push_back(i + 1);
	}
	dfs(0);
	int ans = (dp[0] + N) / 2;
	cout << ans << endl;
	return 0;
}

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

// For Policy Based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ---------------------------------------
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pll             pair<int,int>
#define vll             vector<int>
#define vpll            vector<pair<int,int>>
#define all(c)          (c).begin(), (c).end()
#define bs              binary_search
#define pqb             priority_queue<int>
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define mem(arr,x)      memset(arr,x,sizeof(arr))
#define pi              3.14159265358979323846
#define inf             2000000000000000000
#define ps(x,y)         fixed<<setprecision(y)<<x
#define test(x)         int x; cin>>x;while(x--)

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template<class A> void read(vector<A>& x) {
  for (auto &a : x)
    read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
  for (auto &a : x)
    read(a);
}

const int d4i[4] = { -1, 0, 1, 0};
const int d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void c_p_c()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
#endif
}
string int_to_string(int n) {
  ostringstream str1;
  str1 << n;
  string sar = str1.str();
  return sar;
}
int pow(int a, int b, int m)
{
  int res = 1;
  while (b > 0)
  {
    if (b % 2)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
int ncr(int  n, int k)
{ if (k == 0)
    return 1;
  if (k > n - k)
    k = n - k;
  int a = 1, b = 1, d;
  while (k)
  { a *= n; b *= k;
    d = __gcd(a, b);
    a /= d; b /= d;
    n--; k--;
  }
  return a;
}
int modinv(int k, int m)
{
  return pow(k, m - 2, m);
}
/***************************CODE BEGINS**************************************/
void solve ()
{
  int n;
  read(n);
  int A[n+2];
  for(int i=1;i<=n;i++)
    cin>>A[i];
  int ans=-inf;
  for(int i=1;i<=n;i++){
    int t=inf;
     for(int j=i;j<=n;j++){
        t=min(t,A[j]);
        int k=t*(j-i+1);
        ans=max(ans,k);
     }
  }
  cout<<ans;
}
int32_t main()
{
  c_p_c();
  // test(x)
  solve();
  // int count=1;
  // test(x){
  //   cout<<"Case #"<<count<<": ";
  //   count++;
  //   solve();
  // }
  return 0;
}


//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;

  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

  if(n != 1) res.push_back({n,1});

  return res;

}

int main(){
  ll x,y,a,b; cin >> x >> y >> a >> b;

  ll cnt = 0;

  rep(i,100000000){
    if(double(a-1)*x < b and double(a*x) < y){
      cnt++;
      x *= a;
    }
    else break;
  }

  //cout << cnt << endl;

  cnt += (y-x-1)/b;

  cout << cnt << endl;

}

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

int main() {
    ll N; cin >> N;
    int cnt = 0;
    for(ll i=1;i*(i-1)<2*N;i++){
        ll a = N-i*(i-1)/2;
        if(a%i==0) cnt++;
    }
    cout << 2*cnt << endl;
}


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

int main(void) {
    ios_base::sync_with_stdio(false);
    ll a,b,c,d; cin >> a >> b >> c >> d;
    cout << b-c << endl;
    return 0;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a,b)-min(c,d)<<endl;
}


#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
#define Repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define All(v) v.begin(),v.end()
#define Mod (ll)(1e9+7)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
const int Inf = INT_MAX / 2; const ll Infl = 1LL << 60;
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;}

int H, W;
string A[2020];
bool vis[2020][2020];
int memo[2020][2020];
int dp(int x, int y) {
    if(vis[y][x]) return memo[y][x];
    vis[y][x] = true;

    int turn = (x + y) % 2;

    if(x==W-1 && y==H-1)return memo[y][x]=0;

    if(turn==0) {
        // Takahashi
        memo[y][x]=-Inf;
        if(y<H-1)chmax(memo[y][x],dp(x,y+1)+(A[y+1][x]=='+'?1:-1));
        if(x<W-1)chmax(memo[y][x],dp(x+1,y)+(A[y][x+1]=='+'?1:-1));
        return memo[y][x];
    }
    else {
        // Aoki
        memo[y][x] = Inf;
        if(y<H-1)chmin(memo[y][x],dp(x,y+1)-(A[y+1][x]=='+'?1:-1));
        if(x<W-1)chmin(memo[y][x],dp(x+1,y)-(A[y][x+1]=='+'?1:-1));
        return memo[y][x];
    }
}

int main()
{
    cin>>H>>W;
    For(y,0,H)cin>>A[y];

    int opt=dp(0,0);

    if(0<opt)cout<<"Takahashi"<<endl;
    else if(opt==0)cout<<"Draw"<<endl;
    else cout<<"Aoki"<<endl;
    return 0;
}

#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define MOD 1000000007
#define INF 9223372036854775800
#define pi 3.14159265359

using namespace std;

int main(){

ll int H,W;
cin >> H >> W;
vector< vector< ll int > > A(H,vector< ll int > (W));
rep(i,H){
	string S;
	cin >> S;
	rep(j,W){
		if( S[j] == '+' ){
			A[i][j] = 1;
		}
		else{
			A[i][j] = -1;
		}
	}
}

if( H==1 && W==1 ){
	cout << "Draw" << endl;
	return 0;
}
vector< vector< ll int > > dp(H,vector< ll int > (W,-INF));

dp[H-1][W-1] = 0;
for( ll int i=1; i<H+W; i++ ){
	for( ll int j=0; j<=i; j++ ){
		if( j > H-1 || i-j > W-1 ){
			continue;
		}
		if( (H-1+W-1+i)%2 == 0 ){

			ll int kari1=-INF;
			ll int kari2=-INF;
			if( H-1-j+1 < H ){
				kari1 = dp[H-1-j+1][W-1-i+j] + A[H-1-j+1][W-1-i+j];
			}
			if( W-1-i+j+1 < W ){
				kari2 = dp[H-1-j][W-1-i+j+1] + A[H-1-j][W-1-i+j+1] ;
			}
			dp[H-1-j][W-1-i+j] = max( kari1, kari2 );
		}
		else{

			ll int kari1=INF;
			ll int kari2=INF;
			if( H-1-j+1 < H ){
				kari1 = dp[H-1-j+1][W-1-i+j] - A[H-1-j+1][W-1-i+j];
			}
			if( W-1-i+j+1 < W ){
				kari2 = dp[H-1-j][W-1-i+j+1] - A[H-1-j][W-1-i+j+1] ;
			}
			dp[H-1-j][W-1-i+j] = min( kari1, kari2 );
		}

	}
}

//rep(i,H){
//	rep(j,W){
//		if( dp[i][j] == -INF ){
//			cout << '!' << " " ;
//		}
//		else{
//			cout << dp[i][j] << " " ;
//		}
//	}
//	cout << endl;
//}

if( dp[0][0] == 0 ){
	cout << "Draw" << endl;
}
else if(dp[0][0] > 0 ){
	cout << "Takahashi" << endl;
}
else{
	cout << "Aoki" << endl;
}

	return 0;

}


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

signed main(){
    ll n;cin>>n;
    vector<ll>a(0),b(0);
    vector<ll>c(2*n);
    rep(i,2*n){
        cin>>c[i];
        if(i%2==0){
            a.pb(c[i]);
        }else{
            b.pb(c[i]);
        }
    }
    sort(all(a)),sort(rall(b));
    ll idx=-1;
    rep(i,n){
        if(b[i]<=a[i]){
            idx=i;
            break;
        }
    }
    string ans="";
    if(idx==-1){
        rep(i,n){
            ans+="()";
        }
    }else{
        map<ll,ll>aa;
        map<ll,ll>bb;
        rep(i,idx){
            aa[a[i]]++;
            bb[b[i]]++;
        }
        ll x=0,y=0,z=0,w=0;
        rep(i,n*2){
            if(i%2==0){
                if(y>0){
                    if(aa[c[i]]>0){
                        ans+=')';
                        aa[c[i]]--;
                        y--;
                    }else if(w>0){
                        w--;
                        ans+=')';
                    }else{
                        z++;
                        ans+='(';
                    }
                }else{
                    if(aa[c[i]]>0){
                        aa[c[i]]--;
                        ans+='(';
                        x++;
                    }else if(w>0){
                        w--;
                        ans+=')';
                    }else{
                        z++;
                        ans+='(';
                    }
                }
            }else{
                if(x>0){
                    if(bb[c[i]]>0){
                        ans+=')';
                        bb[c[i]]--;
                        x--;
                    }else if(z>0){
                        z--;
                        ans+=')';
                    }else{
                        w++;
                        ans+='(';
                    }
                }else{
                    if(bb[c[i]]>0){
                        bb[c[i]]--;
                        ans+='(';
                        y++;
                    }else if(z>0){
                        z--;
                        ans+=')';
                    }else{
                        w++;
                        ans+='(';
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*............................................................................*/
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* find_by_order(x) give iterator of the index x
   order_by_key(x) give the position where x will be placed*/
#define int long long
#define lop(i,a,b,c) for (int i=a;i<b;i+=c)
#define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c)
#define prii pair <int,int>
#define PB push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define vvii vector < vector < int > >
#define vii vector <int>
#define count_1(x) __builtin_popcount(x)
#define cn(a) scanf("%lld",&a);
#define cn_vl(arr,n) lop(i,0,n,1){scanf("%lld",arr+i);}
#define shw_vl(arr,n) lop(i,0,n,1){printf("%lld ",arr[i]);}printf("\n");
const int MAX=2e5+10;
/*......................................................................*/
void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
struct dsu
{
	int parent[MAX];int size[MAX];
	void init(){
		lop (i,1,MAX,1){parent[i]=i;size[i]=1;}
	}
	int trace(int a){
		return (a==parent[a])?a:parent[a]=trace(parent[a]);
	}
	bool connect(int a,int b){
		if ((a=trace(a))==(b=trace(b)))return false;
		if (size[b]>size[a])swap(a,b);
		parent[b]=a;size[a]+=size[b];
		return true;
	}
}ori;
struct abc{
	int u,c,d;
};
int f(int a,int b){
	int re=LLONG_MAX;
	lop (i,-1,2,1){
		int z=b+i;
		if (z<0)z=0;
		re=min(z+a/(1+z),re);
	}
	return re;
}
vector <abc> adj[MAX];const int INF=LLONG_MAX;
void dijsktra(int u,vii &dst,int n){

	dst.assign(n+1,INF);
	dst[u]=0;
	priority_queue < prii ,vector <prii> ,greater <prii>> q;
	q.push({0,u});
	while (!q.empty()){
		 int wt=q.top().F;
		 int u=q.top().S;q.pop();
		 if  (wt!=dst[u]){
		 	continue;
		 }
		 //cout<<u<<" "<<wt<<"\n";
		 for (auto v:adj[u]){
		 	int re=sqrt(v.d);
		 	int zr=dst[u];
		 	// cout<<v.u<<" "<<re<<" ";
		 	if (wt>re){
		 		re=wt;
		 	}
		 	zr=re;
		 	re=v.c+v.d/(re+1);
					 	// cout<<ren";
		 	if (re+zr<dst[v.u]){
		 		dst[v.u]=re+zr;
		 		q.push({dst[v.u],v.u});
		 	}
		 }
	}

}
void solve(){
	int n,m;cn(n)cn(m)
	lop (i,0,m,1){
		int a,b,c,d;
		cn(a)cn(b)cn(c)cn(d)
		 if (a!=b){
		 	adj[a].PB({b,c,d});
			adj[b].PB({a,c,d});
		 }
	}
	vii dst;
	dijsktra(1,dst,n);
	int z=dst[n];
	if (z==INF){
		z=-1;
	}
	cout<<z<<"\n";
}
int32_t main(){
	int t;t=1;
	// cin>>t;
	while (t--){
		auto t_1=chrono::high_resolution_clock::now();
		solve();
		auto t_2=chrono::high_resolution_clock::now();
		// cout <<". Elapsed (ms): " << chrono::duration_cast<chrono::milliseconds>(t_2 - t_1).count() << endl;
	}
	return 0;
}


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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		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);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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

	int N = getint();
	int kotae = 2e9;

	rep(i, N) {
		int a = getint();
		int p = getint();
		int x = getint();
		if (a < x && p < kotae) kotae = p;
	}

	if (kotae > 1e9) printf("-1");
	else printf("%d", kotae);

	Would you please return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using namespace std;
struct mint{
  ll x;
  mint(ll x = 0) : x((x + 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(ll 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; }
  friend istream &operator>>(istream &is, mint &a){ return is >> a.x; }
  friend ostream &operator<<(ostream &os, const mint &a){ return os << a.x; }
};
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];
  vector<mint> dpx(w), dpy(h), dpz(h + w + 1);
  mint num = 1;
  rep(i, h) rep(j, w){
    if(a[i][j] == '#'){
      dpx[j] = dpy[i] = dpz[j - i + h] = 0;
    }else{
      if(i || j) num = dpx[j] + dpy[i] + dpz[j - i + h];
      dpx[j] += num;
      dpy[i] += num;
      dpz[j - i + h] += num;
    }
  }
  cout << num << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define vt vector
#define all(x) x.begin(), x.end()
#define trav(i, x) for(auto &i : x)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back

void solve() {
    int n; scanf("%d", &n);
    vector<int> a(n), b(n);
    trav(i, a) scanf("%d", &i);
    trav(i, b) scanf("%d", &i);
    ll res=0;
    for(int i = 0; i < n; i++) {
        res += a[i]*b[i];
    }

    printf((res==0?"Yes":"No"));
}
int main() {

	int t = 1, i = 1;
	while(t--) {
		// printf("Case #%d: ", i)
		solve();
		i++;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << a*d-b*c;
  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 ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define reset(x) memset(x,0,sizeof(x))
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define PI 3.1415926535897932384626433832795
#define INF 1000000000
#define MOD 1000000007
#define MOD2 1000000009
#define EPS 1e-6
#define pb push_back
#define fi first
#define se second
#define mp make_pair

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

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    int n; cin >> n;
    vector<int> arr;
    for (int i = 1; i <= n; i++)
    {
    	int x; cin >> x;
    	arr.pb(x);
    }
    sort(all(arr));
    int total = n * (n - 1) / 2;
    for (int i = 0; i < n; i++)
    {
    	int cnt = 1, ni = i;
    	for (int j = i + 1; j < n; j++)
    	{
    		if (arr[j] == arr[i])
    		{
    			cnt++;
    			ni = j;
    		}
    		else
    		{
    			break;
    		}
    	}
    	i = ni ;
    	total -= (cnt * (cnt - 1) / 2);
    }
    cout << total;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//xd
int main(){
    long long int n;
    cin>>n;
    map<long long int,long long int> frecuencias;
    vector<int> actualnum;
    int actual_size=-1;
    while(n--)
    {
        long long int temp;
        cin>>temp;
        if(!(frecuencias.find(temp)!=frecuencias.end()))
        {
            actualnum.push_back(temp);
        }
        frecuencias[temp]++;
        actual_size++;
    }
    long long int cont=0;
    for(auto it = actualnum.begin(); it != actualnum.end(); ++it)
    {
        cont+=frecuencias[*it]*(actual_size-(frecuencias[*it]-1));
        actual_size-=frecuencias[*it];
    }
    cout<<cont<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
  fastio
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll sum = a+b+c+d;
  if(sum%2){
    cout<<"No\n";
  }
  else{
    bool done = false;
    for(ll i=0; i<(1<<4); i++){
      ll ts=0;
      if(1&i)ts+=a;
      if(2&i)ts+=b;
      if(4&i)ts+=c;
      if(8&i)ts+=d;
      if(ts == sum/2){
        done = true;
        break;
      }
    }

    if(done)cout<<"Yes\n";
    else cout<<"No\n";

  }

  return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>//fill
#include<iomanip>
#include<functional>//https://cpprefjp.github.io/reference/functional/function.html
#include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html
#include<queue>
#include<deque>
#include<cassert>
#include<stack>
#include <iterator>     // std::back_inserter
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
const double PI = acos(-1);
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n)for(ll i=0;i<(n);i++)
#define repp(x,arr) for(auto& x:arr)
#define repp2(x,y,arr) for(auto& [x,y]:arr)
#define all(a) (a.begin()),(a.end())
const ll MOD = 1e9 + 7;
const ll inf = (ll)1e18+6;

// デフォルトは整数部も含めた桁数指定
//cout <<setprecision();
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
double dl[4] = { 0,0,0.1,0.1 };
double dr[4] = { 0,-0.1,0,-0.1 };
int main() {
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<pair<double, double>>s(N), t(N);
	map<pair<double, double>,bool>m;
	rep(i, N) {
		cin >> t[i].first >> t[i].second;

	}
	rep(i, N) {
		cin >>s[i].first >> s[i].second;
		m[s[i]] = true;
	}

	if (N == 1) {
		cout << "Yes";
		return 0;
	}
	double a, b,a2,b2;
	a = s[0].first, b = s[0].second;
	a2 = s[1].first, b2 = s[1].second;
	double p1;
	p1 = atan((b2 - b) / (a2 - a));
	bool ans = false;
	//cout << "指標は" << a << " " << b << endl;
	rep(i, N) {
		double q, r,c, d;
		c = t[i].first, d = t[i].second;
		for (int j = 0; j < N; j++) {
			if(j==i)continue;
			double c2, d2,p,p2;
			c2 = t[j].first;
			d2 = t[j].second;
			c2 -= c;
			d2 -= d;
			p = p1-atan(d2 / c2);
			p2 = p + PI;
			{
				double A1, B1, x, y, x2, y2;
				A1 = t[j].first - c;
				B1 = t[j].second - d;
				x = A1 * cos(p) - B1 * sin(p);
				y = A1 * sin(p) + B1 * cos(p);
				x2 = A1 * cos(p2) - B1 * sin(p2);
				y2 = A1 * sin(p2) + B1 * cos(p2);
				x += a;
				y += b;
				x = round(x);
				y = round(y);
				x2 += a;
				y2 += b;
				x2 = round(x2);
				y2 = round(y2);
				if (x==a2&&y==b2) {
					p = p;

				}
				else if (x2 == a2 && y2 == b2) {
					p = p2;
				}
				else {
					continue;
				}

			}
			rep(k, N) {
				double A1, B1,x,y,x2,y2;
				A1 = t[k].first - c;
				B1 = t[k].second - d;
				x = A1 * cos(p) - B1 * sin(p);
				y = A1 * sin(p) + B1 * cos(p);
				//x2 = A1 * cos(p2) - B1 * sin(p2);
				y2 = A1 * sin(p2) + B1 * cos(p2);
				//cout << x << " " << y << endl;
				//cout << x2 << " " << y2 << endl;
				x += a;
				y+= b;
				x = round(x);
				y = round(y);
				if (m[{x,y}] == false) {
				//cout << "break"<<endl;
					break;
				}
				if (k == N - 1)ans = true;

			}
		}

	}
	if (ans)cout << "Yes";
	else cout << "No";
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

ll graph_bfs(V<V<ll>> &G, ll s){
    // sは始点のリスト
    const int N = G.size();
    vector<int> dist(N, -1);
    queue<int> qu;

    // initialization
    qu.push(s);
    dist[s] = 0;

    while(!qu.empty()){
        int now = qu.front();qu.pop();
        for(auto next: G[now]){
            if(dist[next] != -1) continue;
            dist[next] = dist[now] + 1;
            qu.push(next);
        }
    }

    ll res = 0;
    REP(i, N) if(dist[i] >= 0) res++;
    return res;
}

int main(){

    ll N;
    cin >> N;
    V<string> S(N);
    REP(i, N) cin >> S[i];

    V<V<ll>> G(N);
    REP(i, N){
        REP(j, N){
            if(S[i][j] == '1'){
                G[j].push_back(i);
            }
        }
    }

    ld res = 0;

    REP(i, N){
        res += (ld)1.0/(graph_bfs(G, i));
    }

    cout << res << endl;

    return 0;
}

#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,sse4.1,sse4.2,popcnt")
#include<bits/extc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int maxn = 1<<11, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> g[maxn];
int vis[maxn];
int dfs(int v) {
	vis[v] =1;
	int res = 1;
	for(auto i : g[v]) if(!vis[i]) res += dfs(i);
	return res;
}
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	char c;
	cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			cin >> c;
			if(c == '1') g[j].push_back(i);
		}
	long double ans = 0;
	for(int i = 1; i <= n; i++) {
		fill(all(vis), 0);
		ans += 1./dfs(i);
	}
	cout << fixed << setprecision(15) << ans << endl;
}