#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N;
ll A[200000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    vector<ll> sum(N,0);
    vector<ll> t(N,0);
    rep(i,N) sum[i]=A[i];
    rep(i,N-1) sum[i+1]+=sum[i];
    //rep(i,N) cout<<sum[i]<<' ';cout<<endl;
    rep(i,N) t[i]=sum[i];
    rep(i,N-1) sum[i+1]=max(sum[i+1],sum[i]);

    rep(i,N-1) t[i+1]+=t[i];
    //rep(i,N) cout<<sum[i]<<' ';cout<<endl;

    ll ans=0;
    rep(i,N-1){
        ans=max(ans,t[i]+sum[i+1]);
    }
    ans=max(ans,t[0]);

    // ll maxi=-INF;
    // ll idx=0;
    // rep(i,N){
    //     if(t[i]>maxi){
    //         maxi=t[i];
    //         idx=i;
    //     }
    // }

    cout<<ans<<endl;

    return 0;
}

#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

    set<char> chars;
    REP(i, 3){
        for(auto c: s[i]) chars.insert(c);
    }
    if(chars.size() > 10){
        cout << "UNSOLVABLE" << endl;
        return 0;
    }

    vector<int> nums(10);
    iota(nums.begin(), nums.end(), 0);
    vector<int> nums_orig(nums);

    vector<ll> ans = {-1, -1, -1};

    do{
        next_permutation(nums.begin(), nums.end());
        map<char, int> assoc;
        int i = 0;
        for(auto c: chars){
            assoc[c] = nums[i];
            i++;
        }
        vector<string> new_str(s);
        vector<ll> new_num(3);
        REP(i, 3){
            REP(j, new_str[i].size()){
                new_str[i][j] = assoc[new_str[i][j]] + '0';
            }
            new_num[i] = stoll(new_str[i]);
        }
        if(
            (new_str[0][0] == '0')
         || (new_str[1][0] == '0')
         || (new_str[2][0] == '0')) continue;

        if(new_num[0] + new_num[1] == new_num[2]){
            ans = new_num;
            break;
        }

    } while(nums != nums_orig);

    if(ans[0] != -1){
        for(auto t: ans) cout << t << endl;
    }
    else{
        cout << "UNSOLVABLE" << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <stack>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define ls rt<<1
#define rs rt<<1|1
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define Inf 0x3f3f3f3f
#define debug(a) cout<<#a<<"="<<a<<"\n"
using namespace std;
inline void ckmin(int& a,int b){if(a>b) a=b;}
inline void ckmax(int& a,int b){if(a<b) a=b;}
const int mod=998244353;
const int maxn=2e5+5;
vector<int>g[maxn];
int n,k;
int d[maxn],ans[maxn],num[maxn];
vector<pii>qu[maxn];
void dfs(int x,int fa){
	d[x]=d[fa]+1;
	for(pii i:qu[x]){
		ans[i.se]=-num[i.fi];
	}
	++num[d[x]];
	for(int i:g[x]){
		dfs(i,x);
	}
	for(pii i:qu[x]){
		ans[i.se]+=num[i.fi];
	}
}
int main()
{
	scanf("%d",&n);
	for(int x,i=2;i<=n;i++){
		scanf("%d",&x);
		g[x].push_back(i);
	}
	d[0]=-1;
	int q,u,c;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d",&u,&c);
		qu[u].push_back({c,i});
	}
	dfs(1,0);
	for(int i=1;i<=q;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


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

int main() {
	// your code goes here
	ll a,b,c;cin>>a>>b>>c;
	if(a==b)cout<<c;
	else if(b==c)cout<<a;
	else if(a==c)cout<<b;
	else if(a==b&&b==c)cout<<a;
	else cout<<"0";
	return 0;
}

//  “Alhamdulillah for Everything”

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

//---------DEFINES------------
#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      sline(s)         getline(cin,s);
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a*b)/gcd(a,b))
#define      all(sob)         sob.begin(),sob.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,b,n)       for(ll i = b;i <= n; i++)
#define      rev(i,b,n)       for(ll i = b;i >= n; i--)
#define      setp(x)          cout<<fixed<<setprecision(x)
#define      watch(x)         cout<<(#x)<<" = "<<(x)<<'\n'
#define      TEST_CASE(t)     for(ll zz=1;zz<=t;zz++)
#define      PRINT_CASE       cout<<"Case "<<zz<<": ";
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      ActioN           ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

//-------CONSTANTS------------
const        ll               mod = 1e9+7;
const        ll               mxn = 1e5+7;
const        ll               inf = 1e18;

//------MOD-FUNCTIONS---------
inline      void              normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline       ll               modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline       ll               modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline       ll               modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline       ll               modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline       ll               modInverse(ll a) { return modPow(a, mod - 2); }
inline       ll               modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

int  main()
{
    //Light_Camera:)
    ActioN;
    ll i,j,k,a,b,c,d,n,m,t,u,v,w,x,y,z;
    vector<ll>vec(3);
    for(i=0;i<3;i++)
    {
        cin>>vec[i];
    }
    sort(all(vec));
    a=vec[0];
    b=vec[1];
    c=vec[2];
    if(a==b)
    {
        cout<<c<<endl;
    }
    else if(b==c)
    {
        cout<<a<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair

#define sz(x) (int)x.size()
#define PI    3.14159265359

const long long INF=1e18;

bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; }

int factorial[10000001]={0};

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

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

void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
    factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}

int nCr(int n, int r)
{
    if(r < 0 || r > n){
        return 0;
    }
    int temp = factorial[n];
    temp *= (powerFunction(factorial[r], MOD-2)%MOD);
    temp %= MOD;
    temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
    temp %= MOD;
    return temp;
}

map<int,int> dp;

int find(int x ,int y )
{
    if(x >= y)
        return x - y;

    if(dp.find(y) != dp.end())
        return dp[y];

    if(y % 2 == 0 )
    {
        int a = find(x , y/2 ) + 1;
        dp[y] = min(y - x , a);
        return dp[y];
    }
    else
    {
        int a = find( x , (y+1)/2 ) + 2;
        int b = find(x , (y-1)/2) + 2;
        dp[y] =  min(min(a,b) , y - x );
        return dp[y];
    }
}

signed main()
{
    int x,y;
    cin>>x>>y;
    cout<< find(x,y)<<endl;
}

#include<cstdio>
#include<cctype>
#include<algorithm>
#define LL long long
using namespace std;

template <class I>
inline void read(I &z)
{
    z=0;
    char c=getchar();int base=1;
    while (!isdigit(c) && c!='-') c=getchar();
    if (c=='-') c=getchar(),base=-1;
    while (isdigit(c)) z=z*10+c-'0',c=getchar();
    z*=base;
}

int x,y,z,n,ans=2147483647;

int main(int argc, char const *argv[])
{
    read(n);
    for (int i=1;i<=n;++i)
    {
        read(x),read(y),read(z);
        if (x<z) ans=min(ans,y);
    }
    if (ans==2147483647) printf("-1"); else printf("%d",ans);
    return 0;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define rf0(i,n) for(i=n-1;i>=0;i--)
#define f2(i,n) for(i=1;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fab(i,a,b) for(i=a;i<=b;i++)
#define shr  ll t;cin>>t; while(t--)
#define fi first
#define sc second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define dev(a) for(auto it:a)cout<<it<<" "
#define prec(nm,prc) cout<<fixed<<setprecision(nm)<<prc<<" "
#define print(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#pragma GCC optimization ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define nl cout<<"\n"
#define ye cout<<"Yes\n"
#define yee cout<<"YES\n"
#define no cout<<"No\n"
#define noo cout<<"NO\n"
#define ln length()
#define ms(cnt,r) memset(cnt, r, sizeof(cnt))
using namespace std;
bool comp(pll &a,pll &b)
{
    return (a.sc<b.sc);
}
ll power(ll n,ll p)
{
	if(p==0)
	return 1;
	else
	{
		ll ans=power(n,p/2)%mod;
		ans=(ans*ans)%mod;
		if(p%2==0)
		return ans;
		else
		return ans=(ans*n)%mod;
	}
}
bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

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

    return true;
}
    /********************HAR HAR MAHADEV***********JAI BAJRANG BALI************************/
  int main()
 {
  	FAST;
  	/* ifstream cin;
    cin.open("input.txt");
    ofstream cout;
    cout.open("output.txt");
                      */
  	//shr
  	  {
  	  	ll i,j,n,a,b,c,d,m,sum=0,ans=0,cnt=0,r=0,e=0;
  	  	string str,s1,om,s;
  	     unordered_map<ll,ll>mp,mp1;
  	     set<ll>st;
  	     cin>>n>>a>>b;

  	     f0(i,n)
  	     {
  	        cin>>r>>e;
  	        if(r<a&&e>b)cnt=1;
  	     }
  	    if(cnt)ye;
  	    else no;

  	  }
   	return 0;
  }

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(ll i=a;i<n;i+=x)
#define forD(i,a,n,x) for(ll i=n-1;i>=a;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

int main()
{
    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);
    ll n,s,d;
    cin>>n>>s>>d;

    ll tdamage=0;

    while(n--)
    {
    	ll x,y;
    	cin>>x>>y;

    	if(x<s && y>d)tdamage|=1;
    }

    if(tdamage)cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;
const int query = 1000;
const int grid_size = 30;
const int grid_total = grid_size * grid_size;
const int initial_length = 5000;

string path_ex(int si, int sj, int ti, int tj){
	int di = ti - si, dj = tj - sj;
	string s;
	if(di >= 0) rep(k,di) s.push_back('D');
	else rep(k,-di) s.push_back('U');
	if(dj >= 0) rep(k,dj) s.push_back('R');
	else rep(k,-dj) s.push_back('L');
	return s;
}

vector<vector<int>> G;
int cost[grid_total][grid_total];

string dijkstra(int st, int ed){
   int N = G.size();
   vector<int> dist(N, INF), par(N, -1);
   dist[st] = 0;
   priority_queue<P,vector<P>,greater<P>> q;
   q.push({dist[st], st});
   while(!q.empty()){
	   P p = q.top(); q.pop();
	   int d = p.first, n = p.second;
	   if(dist[n] < d) continue;
	   for(auto v : G[n]){
		   int c = cost[n][v];
		   if(dist[v] <= d + c) continue;
		   dist[v] = d + c;
		   q.push({dist[v], v});
		   par[v] = n;
	   }
   }
   string path;
   int now = ed;
   while(now != st){
	   char c;
	   if(par[now] + 1 == now) c = 'R';
	   else if(par[now] - 1 == now) c = 'L';
	   else if(par[now] + grid_size == now) c = 'D';
	   else c = 'U';
	   path.push_back(c);
	   now = par[now];
   }
   reverse(path.begin(), path.end());
   return path;
}

int main(){
	//FILE *outputfile;
	//outputfile = freopen("test.txt", "w", stdout);

	G.resize(grid_total);
	rep(i,grid_size){
		rep(j,grid_size) cost[i][j] = INF;
	}
	rep(i,grid_size){
		rep(j,grid_size-1){
			int l = i * grid_size + j, r = i * grid_size + j + 1;
			assert(l < grid_total and r < grid_total);
			G[l].emplace_back(r);
			G[r].emplace_back(l);
			cost[l][r] = initial_length, cost[r][l] = initial_length;
		}
	}
	rep(j,grid_size){
		rep(i,grid_size-1){
			int u = i * grid_size + j, d = (i + 1) * grid_size + j;
			assert(u < grid_total and d < grid_total);
			G[u].emplace_back(d);
			G[d].emplace_back(u);
			cost[u][d] = initial_length, cost[d][u] = initial_length;
		}
	}
	rep(q,query){
		int si, sj, ti, tj;
		cin >> si >> sj >> ti >> tj;
		int st = si * grid_size + sj, ed = ti * grid_size + tj;
		assert(st < grid_total and ed < grid_total);
		string path = dijkstra(st, ed);
		cout << path << endl;
		int dist_result;
		cin >> dist_result;
		int now = st, pre = -1;
		int path_size = path.size();
		rep(k,path_size){
			pre = now;
			if(path[k] == 'R') now++;
			else if(path[k] == 'L') now--;
			else if(path[k] == 'D') now += grid_size;
			else now -= grid_size;
			int now_length = cost[pre][now];
			int ave_length = dist_result / path_size;
			cost[pre][now] = (now_length * (query - q - 1) + ave_length * (q + 1)) / query;
		}
	}

	return 0;
}


#pragma GCC optimize("O3")

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

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

	string s;
	cin >> s;
	string res = "";
	for(char c : s){
		if(c == '.') break;
		else res +=c;
	}
	cout << res;

	return 0;
}

#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  cout << 100-(n%100) << "\n";
  return 0;
}


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

#define ll long long
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define pi pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>

ll mod = 1e9+7;
const int IMAX = 2000500;
const int V = 2100;
const ll LMAX = 99999999999999999;
const ll p = 1000000000;
int R[] = {-1,0,1,0};
int C[] = {0,1,0,-1};

void solve(int test)
{
    string s,s1;
    cin>>s;

    int n = s.length(),cnt=0;
    for(int i=0;i<=n-4;i++)
    {
        s1 = s.substr(i,4);

        if(s1 == "ZONe")
            cnt++;
    }

    cout<<cnt<<"\n";
}

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

    int t;
    // cin>>t;
    t = 1;
    // preprocess();
    for(int i=1;i<=t;i++)
        solve(i);
}

/////////////////////////////////// UNION - FIND ////////////////////////
/*void initialize()
{
    for(int i=0;i<MAXM;i++)
    {
        root[i] = i;
        size[i] = 1;
    }
}

int find(int a)
{
    while(a!=root[a])
    {
        root[a] = root[root[a]];
        a = root[a];
    }

    return a;
}

void merge(int a,int b)
{
    int roota = find(a);
    int rootb = find(b);
    if(size[roota] < size[rootb])
    {
        size[rootb] += size[roota];
        root[roota] = root[rootb];
    }
    else
    {
        size[roota] += size[rootb];
        root[rootb] = root[roota];
    }
}*/

#include <bits/stdc++.h>
using namespace std;
long long n, ans;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
long long lo=0, hi=1500000007;
while (lo<hi){
	long long mid=(lo+hi+1)/2;
	long long cur = mid*(mid+1)/2;
	if (cur <= (n+1)) lo=mid;
	else hi=mid-1;
}
cout << (n-lo+1);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 100005
LL A[M],sum[M],K;
int main(){
	int n,q;
	cin>>n>>q;
	A[0]=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&A[i]);
		sum[i]=sum[i-1]+A[i]-A[i-1]-1;
	}
	sum[n+1]=2e18-A[n];
	cout<<endl;
	while(q--){
		scanf("%lld",&K);
		int L=1,R=n+1,res;
		while(L<=R){
			int mid=(L+R)>>1;
			if(sum[mid]>=K){
				R=mid-1;res=mid;
			}else L=mid+1;
		}
		printf("%lld\n",A[res-1]+K-sum[res-1]);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vt vector
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))

// 🚩
// 20210306 21:02:45~
//
int main()
{
    ll A, B;
    cin >> A >> B;
    ll C = A + B;
    ll ans = 0;
    if (C >= 15 && B >= 8)
    {
        ans = 1;
    }
    else if (C >= 10 && B >= 3)
    {
        ans = 2;
    }
    else if (C >= 3)
    {
        ans = 3;
    }
    else
    {
        ans = 4;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" "
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    v a(n);in(a,n);
    int g=0;
    f(i,n)
        g=__gcd(g,a[i]);
    cout<<g<<endl;
    return 0;
}

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

        using namespace std;
        typedef long long ll;
        typedef unsigned long long ull;
        # define M_PI  3.14159265358979323846

        const int M=1e9+7;
        long long mod(long long x){
            return ((x%M + M)%M);
        }
        long long add(long long a, long long b){
            return mod(mod(a)+mod(b));
        }
        long long mul(long long a, long long b){
            return mod(mod(a)*mod(b));
        }

        ll modPow(ll a, ll b){
            if(b==0)
                return 1LL;
            if(b==1)
                return a%M;
            ll res=1;
            while(b){
                if(b%2==1)
                    res=mul(res,a);
                a=mul(a,a);
                b=b/2;
            }
            return res;
        }

        ll lcm(ll a, ll b){
            ll ans=(a*b)/(ll)(__gcd(a,b));
            return ans;
        }

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


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    map<string, bool> mp;
    string ans = "satisfiable";
    while(N--) {
        string s;
        cin >> s;
        if(ans != "satisfiable") continue;
        bool exist = (s[0] == '!' ? true : false);
        if(exist) s.erase(s.begin());
        if(mp.count(s) && mp[s] != exist) ans = s;
        mp[s] = exist;
    }
    cout << ans << '\n';

    return 0;
}

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

#define FAST cin.tie(nullptr)->sync_with_stdio(false);
#define PRECISE cout << fixed << setprecision(19);
#define ONE int tc = 1;
#define GO for (int i = 0; i < tc; ++i) { solve(); }

using vi = vector<int>;

#define all(x) (x).begin(), (x).end()

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))

void solve() {
    int n; cin >> n;
    vi a(n), b(n);
    ice(i, 0, n) {
        cin >> a[i];
    }
    ice(i, 0, n) {
        cin >> b[i];
    }
    cout << max(0, *min_element(all(b)) - *max_element(all(a)) + 1);
}

int main() {
    FAST PRECISE ONE GO
}


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

//solve関数。falseなら7が入っている。trueなら7が入っていない。
bool solve7(int n){
    while(n!=0){
        if(n%8==7){
            return false;
        }
        //ケタを下ろしていく(1の桁以外を調べる)
        n /= 8;
    }
    return true;
}

bool solve10(int n){
    while(n!=0){
        if(n%10==7){
            return false;
        }
        //ケタを下ろしていく(1の桁以外を調べる)
        n /= 10;
    }
    return true;
}

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

    int cnt = 0;

    for( int i=1 ; i<=n ; i++ ){
        //どっちの基準でも7が入っていなかったら、true。
        //数字をカウントする
        if( solve7(i) && solve10(i) ){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=3.14159265358979323846;
//using namespace atcoder;

string toeight(ll a){
    string ret = "";
    while(a>0){
        ll r = a % 8;
        ret = ret + char(r +'0');
        a /= 8;
    }
    return ret;
}

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    REP(i,1,N+1){
        string S = to_string(i);
        string T = toeight(i);
        rep(j,S.size()){
            if(S[j] == '7') goto gt;
        }
        rep(j,T.size()){
            if(T[j] == '7') goto gt;
        }
        ans++;
        gt:
        continue;
    }

    cout << ans << endl;
}


//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<ctime>
//#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>;
using vc = vector<char>;
using vvc = vector<vc>;

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

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

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

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

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

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

};

int main(){
  ll n; cin >> n;
  vvl cost(n,vl(n));

  vl x(n); vl y(n); vl z(n);
  rep(i,n) cin >> x[i] >> y[i] >> z[i];

  rep(i,n){
    rep(j,n){
      //各都市から各都市へのコストを計算
      cost[i][j] = abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0LL,z[j] - z[i]);
    }
  }

  ll inf = 1e18;
  vvl dp((1<<n),vl(n,inf)); //dp[訪れた都市の集合][最後に訪れた都市]

  dp[1][0] = 0; //最初は都市1(0-indexedでは0)にいるのでコスト0

  for(ll i=1; i < (1<<n); i++){ //都市の集合のループ
    if(i % 2 == 0) continue; //都市1には行ったことがあるので，必ず奇数になる

    for(ll j=1; j < n; j++){ //これから向かう都市のループ
      if(i & (1<<j)) continue; //訪れたことのある都市に向かおうとしていたらcontinue

      for(ll k=0; k < n; k++){ //最後に来た都市のループ
        if(!(i&(1<<k))) continue; //まだ訪れていない都市からやってこようとしたらcontinue

        //もともとの行き方よりも,訪れた都市集合がi,最後に来た都市kの状態で,
        //これから都市jに向かった方がコストがかからない場合，更新

        if(dp[i|(1<<j)][j] > dp[i][k] + cost[k][j]){
          dp[i|(1<<j)][j] = dp[i][k] + cost[k][j];
        }
      }
    }
  }

  ll ans = 1e18;

  rep(i,n){
    //全ての都市を回った状態で，都市1に戻ってくる
    ans = min(dp[(1<<n)-1][i] + cost[i][0],ans);
  }

  cout << ans << endl;

}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	vector<int> l(n + 1, mod);
	vector<int> r(n + 1, -mod);
	rep(i, n) {
		int x, c; cin >> x >> c;
		l[c] = min(l[c], x);
		r[c] = max(r[c], x);
	}
	vector<LP> dp;
	dp.push_back({ 0,0 });
	rep1(c, n) {
		if (l[c] == mod)continue;
		ll lval = INF, rval = INF;
		for (LP p : dp) {
			ll loc = p.first;
			ll val = p.second;
			lval = min(lval, val + abs(r[c] - loc) + r[c] - l[c]);
			rval = min(rval, val + abs(l[c] - loc) + r[c] - l[c]);
		}
		dp.clear();
		dp.push_back({ l[c],lval });
		dp.push_back({ r[c],rval });
	}
	ll ans = INF;
	for (LP p : dp) {
		ll loc = p.first;
		ll val = p.second;
		ans = min(ans, abs(loc) + val);
	}
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
		solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (int)1e9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
//
#define FOR(i, a, b, in) for (int i=a ; i<(b) ; i+=in)
#define RFOR(i, a, b, in) for (int i=a-1 ; i>=(b) ; i-=in)
#define REP(i, a, b) FOR(i, a, b, 1)
#define RREP(i, a, b) RFOR(i, a, b, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define all(cont) cont.begin(), cont.end()

void solve () {
	int ans = 1e9;
	bool ok = 0;
	int n;
	cin >> n;
	REP (i, 0, n) {
		int a, p, x;
		cin >> a >> p >>x;
		if (a < x) {
			ans = min(ans, p);
			ok = true;
		}
	}
	if (!ok) ans = -1;

	cout << ans << "\n";
}

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

	return 0;
}
//$ sudo g++ -o name name.cpp
//$ ./name


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

// template {{{
#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
// constexpr i32 mod   = 998244353;

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  i64 n = input(), k = input();

  auto dp = make_vector(3, 4 * n, 0ll);
  range(a, 1, n + 1) dp[0][a] = 1;
  range(i, 0, 2) {
    range(a, 1, dp[i].size() - n - 1) {
      dp[i + 1][a + 1] += dp[i][a];
      dp[i + 1][a + n + 1] -= dp[i][a];
    }

    range(b, 1, dp[i].size()) dp[i + 1][b] += dp[i + 1][b - 1];
  }

  i64 s = 3;
  while (s < 3 * n) {
    // i64 p = (s - 1) * (s - 2) / 2;
    i64 p = dp[2][s];
    // debug(p);
    if (k <= p) break;
    k -= p;
    s++;
  }

  i64 a = 1;
  while (a < n) {
    i64 d = s - a;
    i64 l = d - n;
    i64 r = n;
    i64 p = max(r - l + 1, i64(0));
    p = dp[1][d];

    if (k <= p) break;
    k -= p;
    a++;
  }

  range(b, 1, s - a + 1) {
    int c = (s - a) - b;
    if (c > n) continue;
    k--;
    if (k) continue;

    cout << a << " " << b << " " << c << endl;
    return;
  }
}

signed main() {
  solve();
}

#include<bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define put(i) cout<<i<<endl
#define rep(i,s,n) for(long long i=s;i<(long long)(n);i++)
using namespace std;
using ll = long long;

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

    if(a*a + b*b < c*c) put("Yes");
    else put("No");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI a(n), b(n), c(n), d(n);
    REP(i,n) cin >> a[i] >> b[i], a[i]*=n, b[i]*=n;
    REP(i,n) cin >> c[i] >> d[i], c[i]*=n, d[i]*=n;
    if(n==1){
        cout << "Yes" << endl;
        return 0;
    }
    double csx=0, csy=0, ctx=0, cty=0;
    REP(i,n){
        csx+=a[i];
        csy+=b[i];
        ctx+=c[i];
        cty+=d[i];
    }
    csx/=n, csy/=n, ctx/=n, cty/=n;
    REP(i,n){
        a[i]-=csx;
        b[i]-=csy;
        c[i]-=ctx;
        d[i]-=cty;
    }
    if(a[0]==0&&b[0]==0){
        swap(a[0],a[1]);
        swap(b[0],b[1]);
    }
    REP(i,n){
        if(c[i]==0&&d[i]==0)
            continue;
        double ang=atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool ok=1;
        REP(j,n){
            double x=a[j]*cos(ang)-b[j]*sin(ang);
            double y=a[j]*sin(ang)+b[j]*cos(ang);
            bool f=0;
            REP(k,n){
                if(abs(x-c[k])<=1e-6&&abs(y-d[k])<=1e-6)
                    f=1;
            }
            if(!f){
                ok=0;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long int_;
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 200005;
const int Mod = 998244353;
vector<int> v[MaxN];
map<int,int> mp;
int c[MaxN]; // BIT

int main(){
	int n = readint();
	for(int i=1,t=0; i<=n; ++i){
		int &x = mp[readint()+i];
		if(!x) x = ++ t; // new id
		v[x].push_back(i);
	}
	for(int i=1; i<=n; ++i){
		int len = v[i].size();
		rep(j,0,len-1-j)
			swap(v[i][j],v[i][len-1-j]);
	}
	int_ ans = 0;
	for(int i=1; i<=n; ++i){
		int &x = mp[readint()+i];
		if(!x || v[x].empty()){
			puts("-1"); return 0;
		}
		int id = n+1-v[x].back();
		v[x].pop_back(); // match
		for(int j=id; j; j-=(j&-j))
			ans += c[j]; // inversion
		for(int j=id; j<=n; j+=(j&-j))
			++ c[j]; // count
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

template<typename T, long long MOD_VALUE>
class ModInt {
    static constexpr long long MOD = MOD_VALUE;
private:
    T value_;
public:
    ModInt() {}
    ModInt(const T& value) {if (value >= 0) {value_ = value % MOD;} else {T k = (MOD - 1 - value) / MOD; value_ = (value + k * MOD) % MOD;}}
    ModInt& operator+=(const ModInt& x)  {value_ += x.value_; if (value_ >= MOD) value_ -= MOD; return *this;}
    friend ModInt& operator+=(const T& x, const ModInt& y) {ModInt res(x); res.value_ += x.value_; if (res.value_ >= MOD) res.value_ -= MOD; return res;}
    ModInt& operator-=(const ModInt& x) {if (value_ < x.value_) value_ += MOD; value_ -= x.value_; return *this;}
    friend ModInt& operator-=(const T& x, const ModInt& y) {ModInt res(x); if (res.value_ < y.value_) res.value_ += MOD; res.value_ -= y.value_; return res;}
    ModInt& operator*=(const ModInt& x) {value_ = (value_ * x.value_) % MOD; return *this;}
    friend ModInt& operator*=(const T& x, const ModInt& y) {ModInt res(x); res.value_ = (res.value_ * y.value_) % MOD; return res;}
    const ModInt operator+(const ModInt& x) const {return ModInt(*this) += x;}
    friend const ModInt operator+(const T& x, const ModInt& y) {return ModInt(x) += y;}
    const ModInt operator-(const ModInt& x) const {return ModInt(*this) -= x;}
    friend const ModInt operator-(const T& x, const ModInt& y) {return ModInt(x) -= y;}
    const ModInt operator*(const ModInt& x) const {return ModInt(*this) *= x;}
    friend const ModInt operator*(const T& x, const ModInt& y) {return ModInt(x) *= y;}
    static ModInt modpow(ModInt x, long long y) {ModInt z = 1; while (y > 0) {if (y & 1) {z *= x;}x *= x; y /= 2;} return z;}
    ModInt& operator/=(const ModInt& x) {return *this *= modpow(x, MOD - 2);}
    const ModInt operator/(const ModInt& x) const {return ModInt(*this) /= x;}
    friend const ModInt operator/(const T& x, const ModInt& y) {return ModInt(x) /= y;}
    ModInt operator++(int) {ModInt tmp(*this); value_ = (value_ + 1 == MOD ? 0 : value_ + 1); return tmp;}
    ModInt operator--(int) {ModInt tmp(*this); value_ = (value_ - 1 < 0 ? MOD - 1 : value_ - 1); return tmp;}
    friend istream& operator>>(istream& stream, ModInt& x) {stream >> x.value_; x.value_ %= MOD; return stream;}
    friend ostream& operator<<(ostream& stream, const ModInt& x) {stream << x.value_; return stream;}
};

using mint = ModInt<ll, 1000000007>;

void solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    mint K = max(N - A - B + 1, 0LL);
    mint cnt = K * (K + 1);  // 片方が接しない通り数
    mint ans = cnt * mint(N - A + 1) * mint(N - B + 1) * 2;
    ans -= cnt * cnt;
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    rep(_, 0, T) {
        solve();
    }
    return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

const ll mod=1000000007;

inline ll C(ll x){return (x*(x+1ll)/2ll)%mod;}
inline ll Mul(ll a,ll b){return (a%mod*b%mod)%mod;}

int main()
{
	int T=read();
	while(T--)
	{
		ll n=read(),a=read(),b=read(),ans=0;
		if(a+b>n) {puts("0"); continue;}
		ans=Mul(4,C(n-a-b+1));
		ans=Mul(ans,Mul(n-a+1,n-b+1));
		ll res=Mul(C(n-a-b+1),C(n-a-b+1)); res=Mul(4,res);
		ans=(ans-res+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

vector< pair<int, pair<int,int> > > edges;
map<pair<int, int>, int> mp;
int par[N], sz[N];
int n, m;
vector<pair<int, int> > adj[N];
int ans[N];

struct DSU{
    void init()
    {
        f(i, N) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void merge(int x, int y) {
        int u = find(x);
        int v = find(y);
        if (sz[u] <= sz[v])
        {
            par[u] = par[v];
            sz[v] += sz[u];
        }
        else
        {
            par[v] = par[u];
            sz[u] += sz[v];
        }
    }
};

ll kruskal()
{
    ll ret = 0ll;
    DSU dsu;
    dsu.init();
    for(auto it : edges)
    {
        int w = it.first, u = it.second.first, v = it.second.second;
        int par_u = dsu.find(u), par_v = dsu.find(v);
        if(par_u == par_v) continue;
        adj[u].pb({v, mp[{u, v}]});
        adj[v].pb({u, mp[{u, v}]});
        dsu.merge(u,v);
    }
    return ret;
}

void dfs(int src = 0, int par = -1) {
	for(auto it: adj[src]) {
		int v = it.first, c = it.second;
		if (v == par) continue;
		if (c == ans[src]) ans[v] = (c + 1) % n;
		else ans[v] = c;
		dfs(v, src);
	}
}

void solve() {
	cin>>n>>m;
	f(i, m) {
		int u, v, c;
		cin>>u>>v>>c;
		u--, v--, c--;
		if(mp.find({u, v}) != mp.end()) continue;
		edges.push_back({i, {u, v}});
		mp[{u, v}] = c;
		mp[{v, u}] = c;
	}
	kruskal();
	ans[0] = 0;
	dfs();
	f(i, n) cout<<ans[i] + 1<<"\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<vector>
#define For(i,A,B) for(i=(A);i<=(B);++i)
#define pb push_back
using namespace std;
const int N=100050;
int G[N],to[N*2],w[N*2],nxt[N*2],sz,f[N],a[N];
inline void adde(int u,int v,int c){
	to[++sz]=v;w[sz]=c;nxt[sz]=G[u];G[u]=sz;
	to[++sz]=u;w[sz]=c;nxt[sz]=G[v];G[v]=sz;
}
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
void dfs(int u,int fa,int c){
	int i,v;
	vector<int> t;
	if(c>0)a[u]=c;
	else if(c<0)t.pb(-c);
	for(i=G[u];i;i=nxt[i])if((v=to[i])!=fa){
		dfs(v,u,w[i]==c?-c:w[i]);
		t.pb(w[i]);
	}
	if(c<=0){
		sort(t.begin(),t.end());
		t.erase(unique(t.begin(),t.end()),t.end());
		For(i,0,t.size()-1)if(t[i]!=i+1){
			a[u]=i+1;
			break;
		}
		if(!a[u])a[u]=t.size()+1;
	}
}
int main(){
	int n,m,i,u,v,c,x,y;
	scanf("%d%d",&n,&m);
	For(i,1,n)f[i]=i;
	while(m--){
		scanf("%d%d%d",&u,&v,&c);
		if((x=gf(u))!=(y=gf(v))){
			adde(u,v,c);
			f[x]=y;
		}
	}
	dfs(1,0,0);
	For(i,1,n)printf("%d\n",a[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back

int main(){

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    int ans=0;

    if (a==c and b==d){
        ans=0;
    }

    else if ((a+b)==(c+d) or (a-b)==(c-d) or (abs(a-c)+abs(b-d))<=3){
        ans=1;

    }

    else if ((a+b+c+d)%2==0){
        ans=2;
    }

    else {
        bool flag=false;

        for (int i=-2;i<=2;i++){
            for (int j=-2;j<=2;j++){
                int x=a+i;
                int y=b+j;
                if ((x+y)==(c+d) or (x-y)==(c-d) or (abs(x-c)+abs(y-d))<=3){
                    flag=true;
                }
            }
        }

        int x=a-3;
        int y=b;
        if ((x+y)==(c+d) or (x-y)==(c-d) or (abs(x-c)+abs(y-d))<=3){
            flag=true;
        }
        x=a+3;
        if ((x+y)==(c+d) or (x-y)==(c-d) or (abs(x-c)+abs(y-d))<=3){
            flag=true;
        }
        x=a;
        y=b-3;
        if ((x+y)==(c+d) or (x-y)==(c-d) or (abs(x-c)+abs(y-d))<=3){
            flag=true;
        }
        y=b+3;
        if ((x+y)==(c+d) or (x-y)==(c-d) or (abs(x-c)+abs(y-d))<=3){
            flag=true;
        }

        if (flag){
            ans=2;
        }
        else {
            ans=3;
        }

    }

    cout<<ans<<endl;

}

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

int main(void){
    int r1, c1, r2, c2;
    cin >> r1 >> c1;
    cin >> r2 >> c2;
    if((r1==r2)&&(c1==c2)){
        cout << 0 << endl;
    }else if((r1+c1 == r2+c2)||(r1-c1 == r2-c2)){
        cout << 1 << endl;
    }else if(abs(r1-r2)+abs(c1-c2)<=3){
        cout << 1 << endl;
    }else if((r1+c1)%2 == (r2+c2)%2){
        cout << 2 << endl;
    }else if(min(abs(r1+c1-r2-c2), abs(r1-c1-r2+c2))<=3){
        cout << 2 << endl;
    }else if(abs(r1-r2)+abs(c1-c2)<=6){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vp =vector<pair<ll,ll>>;
using vvp =vector<vp>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define sz(x) (ll)(x).size()
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){

  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

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

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

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

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

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

//cout<<""<<endl;
// ./a.out
// g++ 201110.cpp

//  ll N;cin>>N;
int main(){
  ll a,b,c,d   ;
  cin >>a>>b>>c>>d  ;
  ll x=max((a-c),(a-d));
  ll y=max((b-c),(b-d))  ;

  cout<<max(x,y)   <<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=b-c;
    cout<<ans;
}


#include <bits/stdc++.h>

const int N = 200000;

std::vector<int>G[N + 5];
void adde(int u, int v) {
	G[u].push_back(v), G[v].push_back(u);
}

int n, k, d, t;

int a[N + 5], b[N + 5];
void dfs1(int x, int f) {
	a[x] = b[x] = -1;

	int p = -1, q = 0;
	for(auto to : G[x]) if( to != f ) {
		dfs1(to, x);
		p = std::max(p, a[to] - 1);
		q = std::max(q, b[to] + 1);
	}
	if( p >= q ) q = -1;
	if( q == d ) p = d, q = -1, t++;

	a[x] = p, b[x] = q;
}

bool check(int _d) {
	d = _d, t = 0, dfs1(1, 0);
	if( b[1] != -1 ) t++;
	return t <= k;
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i=1,u,v;i<n;i++) scanf("%d%d", &u, &v), adde(u, v);

	int l = 1, r = n - 1;
	while( l < r ) {
		int m = (l + r) >> 1;
		if( check(m) ) r = m;
		else l = m + 1;
	}
	printf("%d\n", l);
}

#include<bits/stdc++.h>
#define fgx cerr<<"-----------------------"<<endl
#define LL long long
#define DB double
#define pb push_back
using namespace std;
inline int read(){
	int nm=0,fh=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') fh=-1;
	for(;isdigit(c);c=getchar()) nm=nm*10+c-'0';
	return nm*fh;
}
#define M 200020
#define pii pair<int,int>
#define mp make_pair
#define ds second
int n,K,ans,tot,to[M<<1],nt[M<<1],fs[M],dep[M],fa[M][21],lim;
bool vis[M]; priority_queue<pii >que;
inline void link(int u,int v){to[++tot]=v,nt[tot]=fs[u],fs[u]=tot;}
inline int Jump(int u,int k){for(int i=20;~i;i--) if(k&(1<<i)) u=fa[u][i]; return u;}
inline void dfs(int u,int last=0){
	dep[u]=dep[last]+1,fa[u][0]=last;
	for(int i=1;i<=20;i++) fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfs(to[i],u);
}
inline void dfst(int u,int dep,int last=0){
	if(dep>lim) return; vis[u]=true;
	for(int i=fs[u];i;i=nt[i]) if(to[i]^last) dfst(to[i],dep+1,u);
}
inline bool Jud(int td){
	lim=td;
	for(int i=1;i<=n;i++) que.push(mp(dep[i],i)),vis[i]=false;
	int ret=0;
	while(!que.empty()){
		if(ret>=K) return 0;
		int u=que.top().ds,pos; que.pop();
		if(vis[u]) continue;
		if(dep[u]<=td) pos=1; else pos=Jump(u,td);
		dfst(pos,0),ret++;
		while(!que.empty()&&vis[que.top().ds]) que.pop();
	} return ret<=K;
}
int main(){
	n=read(),ans=n; K=read();
	for(int i=1;i<n;i++){int u=read(),v=read(); link(u,v),link(v,u);}
	dfs(1);
	for(int k=20;~k;k--){int td=ans-(1<<k); if(td>=0&&Jud(td)) ans=td;}
	printf("%d\n",ans);
	return 0;
}


/*

    P_r_A_d_Y ☹

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

#define int     long long int
#define endl    "\n"
#define mod     1000000007
#define inf     1e18
#define pb      push_back
#define all(x)  x.begin(),x.end()
#define arr_max(x)  *max_element(x.begin(),x.end())
#define arr_min(x)  *min_element(x.begin(),x.end())
#define pii         pair<int,int>
#define ff          first
#define ss          second
#define vec         vector<int>

const int N = 200005;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

bool cmp(vector<int>a , vector<int>b) {
    return a[0] < b[0];
}
int poww(int x, int n)
{
    if (n == 0 ) return 1 ;
    int u = poww(x, n / 2);
    u = (u * u) ;
    if (n % 2 == 1)u = (u * x) ;
    return u;
}

//(x**n)%m
int mod_pow(int x, int n, int m)
{
    if (n == 0 ) return 1 % m;
    int u = mod_pow(x, n / 2, m);
    u = (u * u) % m;
    if (n % 2 == 1)u = (u * x) % m;
    return u;
}
int query(int l, int r)
{
    int x;
    cout << "? " << l << " " << r << endl;
    cout.flush();
    cin >> x;
    cout.flush();

    return x;
}

int xd[4] = {1, 0, -1, 0};
int yd[4] = {0, -1, 0, 1};
int ceil(int a, int d)
{
    return (a % d ? a / d + 1 : a / d);
}

int32_t main()
{
    fastIO;

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

    int test;
    test = 1;
    //cin >> test;
    int ert = 1;
    while (test--)
    {

        int n; cin >> n;

        int d = 0;
        int dup = n;
        while (dup > 0)
        {
            d++;
            dup /= 10;
        }

        int ans = 0;
        for (int i = 4; i < d; i++)
        {
            int g = (i - 1) / 3;
            ans += g * (9 * poww(10, i - 1));
        }

        int f = (d - 1) / 3;
        ans += f * (n - poww(10, d - 1) + 1);
        cout << ans << endl;

    }

    return 0;
}

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

using ll=long long;
ll mod=1000000007;

int main(){
    ll N,ans=0,K=1000;
    cin >> N;
    while(N-K+1>=0){
        ans+=N-K+1;
        K*=1000;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

int main(){
    int n;
    cin >> n;
    ll res1 = 0;
    ll res2 = 0;
    ll res3 = 0;
    for (int i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        res1 += abs(x);
        res2 += x * x;
        chmax(res3, abs(x));
    }

    cout << res1 << endl;
    cout << fixed << setprecision(10) << sqrt(res2) << endl;
    cout << res3 << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> lr;
  int ans = 0;
  rep(i, n) {
    int t, l, r;
    cin >> t >> l >> r;
    for(auto [pt, pl, pr] : lr) {
      if(pr < l || r < pl) continue;
      if(pr == l) {
        if((pt == 1 || pt == 3) && (t == 1 || t == 2)) {
        } else {
          continue;
        }
      }
      if(r == pl) {
        if((pt == 1 || pt == 2) && (t == 1 || t == 3)) {
        } else {
          continue;
        }
      }
      ans++;
    }
    lr.push_back({t, l, r});
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
	long long a, b, c, d;
	//long long n, x, y;
	long long ans = 0;
	double n = 0;
	cin >> a >> b >> c >> d;
	if (b >= d*c) {
	    ans = -1;
	} else {
	   // n = 0;
	   // x = 0;
	   // y = 0;
	   // while (a + x > d*y) {
	   //     x += b;
	   //     y += c;
	   //     n++;
	   // }
	   n = (double)a/(double)(c*d - b);
	   ans = (long long)n;
	   if (n - ans != 0) {
	       ans++;
	   }
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define REP(i, L, R) for (int i = L; i < (R); ++i)
#define SZ(x) (int)x.size()

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

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

// O(log max(a,b))
template <typename T = int>
T gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  return gcd<T>(b, a % b);
}

// Finds gcd(a,b) and x, y s.t. ax + by = gcd(a,b).
template <typename T = int>
T ext_gcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = ext_gcd<T>(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    // b = 0 then gcd(a,b) = a = a*1 + b*0
    x = 1;
    y = 0;
  }

  return d;
}

// Finds x s.t. ax = 1 (mod m) given (a,m)=1.
// (a,m)=1=ax+my.
template <typename T = int>
T mod_inverse(T a, T m) {
  T x, y;
  ext_gcd<T>(a, m, x, y);
  return (m + x % m) % m;
}

// Computes C(n,k) % m.
template <typename T = int>
T comb(T n, T k, T m) {
  if (n < k || k < 0 || n < 0) return 0;
  T ret = 1;
  for (T i = 0; i < k; ++i) {
    ret = ret * (n - i) % m;
    ret = ret * mod_inverse<T>(i + 1, m) % m;
  }

  return ret;
}

// Solves for x in ax = b (mod m). The solution when exists is of the form x
// (mod n). Returns false if no solution exists, in which case x and n are
// undefined.
template <typename T = int>
bool solve_lineq(T a, T b, T m, T &x, T &n) {
  T d = gcd<T>(a, m);
  if (b % d != 0) {
    return false;
  }

  // ax - b = tm -> a/d x - b/d = t m/d -> a' x = b' (mod m') with (a',m') = 1.
  // The solution is x = inverse(a') b' (mod m').
  a /= d;
  b /= d;
  m /= d;
  x = mod_inverse(a, m) * b % m;
  n = m;

  return true;
}

// Solves a linear system: A_i x = B_i (mod M_i) for i=1,...n (n >= 1).
// Returns a pair (b, m) means x=b(mod m) is the solution. The pair (0, -1)
// means no solution existed.
template <typename T = int>
pair<T, T> solve_linsys(const vector<T> &A, const vector<T> &B,
                        const vector<T> &M) {
  // Consider the first equation x = 0 (mod 1).
  T x = 0, m = 1;

  for (int i = 0; i < A.size(); ++i) {
    // x = b (mod m) -> x = b+tm
    // A[i] x = B[i] (mod M[i]) -> (A[i]*m) * t = (B[i]-A[i]*b) (mod M[i])
    T a = A[i] * m;
    T b = B[i] - A[i] * x;
    T d = gcd(M[i], a);
    if (b % d != 0) {
      // no solution
      return make_pair(0, -1);
    }
    T t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
    x = x + m * t;
    m *= M[i] / d;
  }
  return make_pair((x + m) % m, m);
}

void solve() {
  int t;
  cin >> t;
  REP(ti, 0, t) {
    ll X, Y, P, Q;
    cin >> X >> Y >> P >> Q;

    ll ans = -1;
    REP(q, 0, Q) {
      REP(y, 0, Y) {
        // solve: x = P+q (mod P+Q) and x = X+y (mod 2X+2Y)
        pl sol = solve_linsys<ll>(vector<ll>{1, 1}, vector<ll>{P + q, X + y},
                                  vector<ll>{P + Q, 2 * X + 2 * Y});
        if (sol.second != -1) {
          if (ans == -1) {
            ans = sol.first;
          } else {
            ans = min(ans, sol.first);
          }
        }
      }
    }

    if (ans == -1) {
      cout << "infinity";
    } else {
      cout << ans;
    }
    cout << endl;
  }
}

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


#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ll h,w,n,m;cin>>h>>w>>n>>m;
    ll vis[h][w],dp[h][w],ans=0,a,b;
    for(ll i=0;i<h;i++)for(ll j=0;j<w;j++)vis[i][j]=0;
    for(ll i=0;i<n;i++)cin>>a>>b,vis[a-1][b-1]=1;
    for(ll i=0;i<m;i++)cin>>a>>b,vis[a-1][b-1]=2;
    ll flg;
    // for(ll i=0;i<h;i++)
    for(ll i=0;i<h;i++){
        flg=1;
        for(ll j=0;j<w;j++){
            dp[i][j]=0;
            if(vis[i][j]==1)flg=0;
            else if(vis[i][j]==2)flg=1;
            if(!flg)
            dp[i][j]=1;
        }
    }

    for(ll i=0;i<h;i++){
        flg=1;
        for(ll j=w-1;j>=0;j--){
            if(vis[i][j]==1)flg=0;
            else if(vis[i][j]==2)flg=1;
            if(!flg)
            dp[i][j]=1;
        }
    }

    for(ll j=0;j<w;j++){
        flg=1;
        for(ll i=0;i<h;i++){
            if(vis[i][j]==1)flg=0;
            else if(vis[i][j]==2)flg=1;
            if(!flg)
            dp[i][j]=1;
        }
    }

    for(ll j=0;j<w;j++){
        flg=1;
        for(ll i=h-1;i>=0;i--){
                if(vis[i][j]==1)flg=0;
                else if(vis[i][j]==2)flg=1;
                if(!flg)
                dp[i][j]=1;
        }
    }
    for(ll i=0;i<h;i++)for(ll j=0;j<w;j++)if(dp[i][j])ans++;
    cout<<ans<<endl;
}

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

//---------------- 定数 ----------------

// [X_MIN, X_MAX], [Y_MIN, Y_MAX]
#define X_MIN 0
#define X_MAX 29
#define Y_MIN 0
#define Y_MAX 29

#define QUERY 1000

// -------- util function --------

int rand_int(){
	static unsigned long long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long long t = (x^(x << 11));
	x=y; y=z; z=w;
	return (w=(w^(w>>19))^(t^(t>>8)));
}

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

// 座標(y, x)を扱うクラス
struct Point{
	int x, y;

	//Point(int y, int x): x(x), y(y);
};

struct Query{
	Point start, end;
	string ans;

	// クエリを開始する処理
	void init(){
		cin >> start.y >> start.x >> end.y >> end.x;
	}

	// クエリの答えを出力する処理
	void submit(){
		int point;
		cout << ans << endl;
		cin >> point;
		return;
	}

	void solve(){
		Point now = start;

		while(now.y != end.y || now.x != end.x){
			int flag = -1;
			if(now.y == end.y) flag = 1;
			if(now.x == end.x) flag = 0;
			if(flag == -1) flag = rand_int() % 2;

			if(flag == 0){
				if(now.y < end.y){
					ans.push_back('D');
					now.y++;
				}else{
					ans.push_back('U');
					now.y--;
				}
			}else{
				if(now.x < end.x){
					ans.push_back('R');
					now.x++;
				}else{
					ans.push_back('L');
					now.x--;
				}
			}
		}
	}
};

int main(){
	for(int q = 0;q < QUERY;q++){
		Query query;
		query.init();
		query.solve();
		query.submit();
	}
	return 0;
}


#include <bits/stdc++.h>
namespace IO {
  #define iL (1 << 20)
  char ibuf[iL], *iS = ibuf + iL, *iT = ibuf + iL;
  #define gc() ((iS == iT) ? (iT = (iS = ibuf) + fread(ibuf, 1, iL, stdin), iS == iT ? EOF : *iS ++) : *iS ++)
  template<class T> inline void read(T &x) {
    x = 0;int f = 0;char ch = gc();
    for (; !isdigit(ch); f |= ch == '-', ch = gc());
    for (; isdigit(ch); x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc());
    x = (f == 1 ? ~ x + 1 : x);
  }
  char Out[iL], *iter = Out;
  #define flush() fwrite(Out, 1, iter - Out, stdout), iter = Out
  template<class T> inline void write(T x, char ch = '\n') {
    T l, c[35];
    if (x < 0) *iter ++ = '-', x = ~ x + 1;
    for (l = 0; !l || x; c[l] = x % 10, l++, x /= 10);
    for (; l; -- l, *iter ++ = c[l] + '0');*iter ++ = ch;
    flush();
  }
}
using namespace IO;
#define N 200005
#define ll long long
#define MOD 998244353
#define DEBUG
using namespace std;

int n, fa[N];

int Find(int x) {
	return (fa[x] == x) ? x : fa[x] = Find(fa[x]);
}

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
	read(n);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1, f; i <= n; i++) {
		read(f);
		int a = Find(i), b = Find(f);
		if (a != b) fa[a] = b;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (fa[i] == i) ans = (ans + 1) % MOD;
	}
//	write(((ans - 1) * ans % MOD + 1) % MOD);
	write((Qpow(2, ans) % MOD - 1) % MOD);
  return 0;
}

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

void check(long long &a, vector<int> &v, vector<int> &c, int i, int &lc){
  if(c.at(i) == lc){
    a++;
    return;
  }
  if(c.at(i) != -1){
    return;
  }
  c.at(i) = lc;
  check(a, v, c, v.at(i), lc);
}

int main(){
  int N;
  long long a = 0;
  cin >> N;
  vector<int> v(N);
  rep(i, N){
    cin >> v.at(i);
    v.at(i)--;
  }
  vector<int> c(N, -1);
  for(int i = 0; i < N; i++){
    if(c.at(i) == -1){
      check(a, v, c, i, i);
    }
  }
  long long ans = 1;
  rep(i, a){
    ans *= 2;
    ans %= 998244353;
  }
  cout << ans - 1 << endl;
}


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

// clang-format off
#define forn(i, x, y) for (int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define all(v) v.begin(), v.end()
// clang-format on

using VI = vector<int>;

template <int n>
class UF
{
public:
    vector<int> par, rank, cnt;
    UF()
    {
        par = rank = vector<int>(n, 0);
        cnt = vector<int>(n, 1);
        forn(i, 0, n) par[i] = i;
    }
    void reset()
    {
        forn(i, 0, n) rank[i] = 0, cnt[i] = 1, par[i] = i;
    }
    int operator[](int x) { return (par[x] == x) ? (x) : (par[x] = operator[](par[x])); }
    int count(int x) { return cnt[operator[](x)]; }
    int operator()(int x, int y)
    {
        if ((x = operator[](x)) == (y = operator[](y)))
            return x;
        cnt[y] = cnt[x] = cnt[x] + cnt[y];
        if (rank[x] > rank[y])
            return par[x] = y;
        rank[x] += rank[x] == rank[y];
        return par[y] = x;
    }
};

int N;
int X[100], Y[100];

struct edge
{
    int u, v;
    double w;
};

int main()
{
    IOS;
    cin >> N;
    forn(i, 0, N) cin >> X[i] >> Y[i];

    vector<edge> edges;
    forn(i, 0, N)
    {
        edges.push_back({i, 100, 100.0 - Y[i]});
        edges.push_back({i, 101, Y[i] + 100.0});
        forn(j, 0, N)
            edges.push_back({i, j, hypot(X[i] - X[j], Y[i] - Y[j])});
    }
    sort(all(edges), [](edge a, edge b) {
        return a.w < b.w;
    });

    UF<102> uf;
    int n = edges.size();
    double res = 0.0;
    forn(i, 0, n)
    {
        edge &e = edges[i];
        uf(e.u, e.v);
        if (uf[100] == uf[101])
        {
            res = e.w / 2;
            break;
        }
    }

    cout << fixed << setprecision(10) << res << endl;

    return 0;
}

#pragma GCC optimize("-Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef pair<ll, p64> tp;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
// #define mint modint998244353

ll mpow(ll a, ll b)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2);
    t1 *= t1;
    t1 %= MOD;
    if (b % 2)
        t1 *= a;
    t1 %= MOD;
    return t1;
}

ll mpow(ll a, ll b, ll p)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2, p);
    t1 *= t1;
    t1 %= p;
    if (b % 2)
        t1 *= a;
    t1 %= p;
    return t1;
}

ll modinverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll range(ll l, ll r)
{
    return l + mt() % (r - l + 1);
}

ll rev(ll v)
{
    return mpow(v, MOD - 2);
}

ll nc2(ll n)
{
    return (n * (n - 1)) / 2;
}

ll ceil(ll p, ll q)
{
    return (p + q - 1) / q;
}

void solve()
{
    int k, n, m;
    cin >> k >> n >> m;
    v64 arr(k + 1);
    v64 ans(k + 1, 0);
    for (int i = 1; i <= k; i++)
    {
        cin >> arr[i];
        ans[i] = arr[i] * m / n;
    }
    m = m % n;
    // v64 f(k + 1);
    // v64 c(k + 1);
    vp64 temp(k + 1);
    ll sum = 0;
    for (int i = 1; i <= k; i++)
    {
        // f[i] = arr[i] * m / n;
        // c[i] = f[i] + 1;
        temp[i] = {(arr[i] * m) % n,
                   i};
        sum += temp[i].fi;
    }
    int cnt = sum / n;
    sort(temp.begin() + 1, temp.end(), greater<p64>());
    for (int i = 1; i <= cnt; i++)
    {
        ans[temp[i].se]++;
    }
    for (int i = 1; i <= k; i++)
    {
        cout << ans[i] << " ";
    }
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    // mint a = 3;
    // cout << (1 - a).val() << endl;
    forn(i, t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

template <class T>
class Matrix {
 public:
  int h, w;
  V<V<T>> data;
  Matrix(int h_, int w_ = 0, T v = 0) {
    h = h_;
    w = (w != 0) ? w_ : h;
    data.resize(h);
    rep(i, h) data[i].resize(w, v);
  }
  Matrix(const V<V<T>>& data_)
      : h(data_.size()), w(data_[0].size), data(data_) {}
  Matrix(initializer_list<initializer_list<T>> list) {
    data.resize(list.size());
    int cnt = 0;
    for (auto row : list) data[cnt++] = V<T>(row);
    h = data.size(), w = data[0].size();
  }
  Matrix(const Matrix& a) : h(a.h), w(a.w), data(a.data) {}
  Matrix& operator=(const Matrix& a) {
    h = a.h, w = a.w, data = a.data;
    return *this;
  }
  V<T>& operator[](int n) { return data[n]; }
  Matrix& operator*=(Matrix& a) {
    V<V<T>> res(w, V<T>(a.w));
    rep(i, w) rep(j, a.w) {
      rep(k, w) res[i][j] += data[i][k] * a[k][j];
    }
    swap(data, res);
    h = w, w = a.w;
    return *this;
  }
  Matrix operator*(Matrix& a) { return Matrix(*this) *= a; }
  Matrix& operator+=(Matrix& a) {
    rep(i, h) rep(j, w) data[i][j] += a[i][j];
    return *this;
  }
  string str() {
    ostringstream oss;
    rep(i, h) {
      rep(j, w) oss << data[i][j] << " ";
      if (i != h - 1) oss << "\n";
    }
    return oss.str();
  }
};

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

  V<P> xy(n);
  rep(i, n) cin >> xy[i].first >> xy[i].second;

  V<Matrix<ll>> ops;
  Matrix<ll> now = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
  ops.push_back(now);
  Matrix<ll> clk = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}};
  Matrix<ll> clw = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}};

  cin >> m;
  rep(i, m) {
    int op;
    ll p;
    cin >> op;
    if (op > 2) cin >> p;

    if (op == 1) {
      now = clk * now;
    } else if (op == 2) {
      now = clw * now;
    } else if (op == 3) {
      Matrix<ll> f = {{-1, 0, 2 * p}, {0, 1, 0}, {0, 0, 1}};
      now = f * now;
    } else if (op == 4) {
      Matrix<ll> f = {{1, 0, 0}, {0, -1, 2 * p}, {0, 0, 1}};
      now = f * now;
    }
    ops.push_back(now);
  }

  int Q;
  cin >> Q;
  rep(i, Q) {
    int a, b;
    cin >> a >> b;
    b--;
    Matrix<ll> pos = {{xy[b].first}, {xy[b].second}, {1}};
    auto ans = ops[a] * pos;
    ll x = ans[0][0], y = ans[1][0];
    printf("%ld %ld\n", x, y);
  }
}

#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define pb   push_back
#define mp   make_pair
#define ff   first
#define ss   second
#define pop  pop_back
#define	mii  map<int,int>
#define in(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define out(a,n) for(int i=0;i<n;i++)   cout<<a[i]<<" ";cout<<endl;
#define test int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define endl "\n"
#define MOD 1000000007
using namespace std;

int power(int x, int y)
{
    float temp;
    if(y == 0) return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0) return temp * temp;
    else
    {
        if(y > 0) return x * temp * temp;
        else return (temp * temp) / x;
    }
}

signed main()
{
    fast
    int x,y,a,b;
    cin>>x>>y>>a>>b;
    if(a>=b || x>=b) cout<<(y-x-1)/b<<endl;
    else
    {
        int s=log((b)/x)/(log(a));
        int c=x*power(a,s);
        // cout<<s<<" "<<c<<endl;
        if(c>=y)
        {
            int r=(log(y/x)/log(a));
            if(x*power(a,r)==y) cout<<r-1<<endl;
        }
        else if(c+((y-c)/b)*b==y) cout<<s+(y-c)/b-1<<endl;
        else cout<<s+(y-c)/b<<endl;
    }
}


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

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

    long long MOD = 998244353;
    vector<vector<long long>> C(N+1, vector<long long>(N+1));
    for (int i=0; i<=N; i++)
    {
        C[i][0] = 1;
        for (int j=1; j<i; j++)
            C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD;
        C[i][i] = 1;
    }

    //for (int i=0; i<=N; i++)
    //{
    //    for (int j=0; j<=i; j++)
    //        cout<<" "<<C[i][j];
    //    cout<<endl;
    //}

    vector<long long> T(N+1);
    T[0] = 1;
    for (int i=0; i<16; i++)
    {
        vector<long long> P(N+1);
        P.swap(T);
        for (int j=0; j<=N; j++)
            for (int k=0; k<=N; k+=2)
                if (j%2==(M>>i&1))
                    (T[(j>>1)+(k>>1)] += C[N][k]*P[j]%MOD) %= MOD;
    }
    cout<<T[0]<<endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

long long const mod = 1000000007;
struct mint{
	long long val;
	mint(long long val = 0): val(val % mod) {}
	mint& operator += (const mint n){
		val += n.val;
		if(val >= mod) val -= mod;
		return *this;
	}
	mint& operator -= (const mint n){
		val -= n.val;
		if(val < 0) val += mod;
		return *this;
	}
	mint& operator *= (const mint n){
		val *= n.val;
		val %= mod;
		if(val < 0) val += mod;
		return *this;
	}
	mint operator + (const mint n) const{
		mint res(*this);
		return res += n;
	}
	mint operator - (const mint n) const{
		mint res(*this);
		return res -= n;
	}
	mint operator * (const mint n) const{
		mint res(*this);
		return res *= n;
	}
	mint pow(long long n) const{
		if(n == 0) return 1;
		mint m = pow(n >> 1);
		m *= m;
		if(n & 1) m *= *this;
		return m;
	}
	// mint division for prime mod
	mint inv() const{
		return pow(mod - 2);
	}
	mint& operator /= (const mint n){
		return (*this) *= n.inv();
	}
	mint operator / (const mint n) const{
		mint res(*this);
		return res /= n;
	}
};

template<typename T>
struct matrix{
	int row, column;
	vector<vector<T>> mat;

	matrix(int r = 0, int c = 0, T val = 0) : row(r), column(c) {
		mat = vector<vector<T>>(r, vector<T>(c, val));
	}
	vector<T>& operator [] (const int num) {
		return mat[num];
	}
	matrix& operator += (const matrix A) {
		assert(row == A.row && column == A.column);
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < column; j++) {
				mat[i][j] += A.mat[i][j];
			}
		}
		return *this;
	}
	matrix& operator -= (const matrix A) {
		assert(row == A.row && column == A.column);
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < column; j++) {
				mat[i][j] -= A.mat[i][j];
			}
		}
		return *this;
	}
	matrix& operator *= (const matrix A) {
		assert(column == A.row);
		matrix B(row, A.column);
		for(int i = 0; i < row; i++) {
			for(int k = 0; k < column; k++) {
				for(int j = 0; j < A.column; j++) {
					B.mat[i][j] += mat[i][k] * A.mat[k][j];
				}
			}
		}
		return *this = B;
	}
	matrix& operator *= (long long k) {
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < column; j++) {
				mat[i][j] *= k;
			}
		}
		return *this;
	}
	matrix operator + (const matrix A) const {
		assert(row == A.row && column == A.column);
		matrix B = *this;
		return B += A;
	}
	matrix operator - (const matrix A) const {
		assert(row == A.row && column == A.column);
		matrix B = *this;
		return B -= A;
	}
	matrix operator * (const matrix A) const {
		assert(column == A.row);
		matrix B = *this;
		return B *= A;
	}
	matrix operator * (long long k) const {
		matrix B = *this;
		return B *= k;
	}
	vector<T> operator * (const vector<int> A) const {
		int vector_size = A.size();
		assert(column == vector_size);
		vector<T> B(row);
		for(int i = 0; i < row; i++) {
			for(int j = 0; j < column; j++) {
				B[i] += mat[i][j] * A[j];
			}
		}
		return B;
	}
	matrix pow(long long n) const {
		assert(row == column);
		if(n == 0){
			matrix E(row, column);
			for(int i = 0; i < row; i++) {
				E.mat[i][i] = 1;
			}
			return E;
		}
		matrix A = pow(n >> 1);
		A *= A;
		if(n & 1) A *= *this;
		return A;
	}
};

int main(){
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	vv G(N);
	rep(i,M){
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[x].emplace_back(y);
		G[y].emplace_back(x);
	}
	matrix<mint> mat(N, N), F(N, N);
	rep(i,N){
		int s = G[i].size();
		mint coef = M * 2 - s, tot = M * 2;
		coef *= tot.inv();
		mat[i][i] = coef;
		for(auto j : G[i]) mat[i][j] = tot.inv();
	}
	F = mat.pow(K);
	vector<mint> ans = F * A;
	rep(i,N) cout << ans[i].val << endl;

	return 0;
}


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

const int MOD = 1e9+7;

template<uint_fast64_t Modulus = MOD>
struct Modint {
  using u64 = uint_fast64_t;
  u64 a;

  constexpr Modint(const u64 x = 0) noexcept : a(x % Modulus) {}

  constexpr Modint operator+(const Modint rhs) const noexcept {
    return Modint(*this) += rhs;
  }
  constexpr Modint operator-(const Modint rhs) const noexcept {
    return Modint(*this) -= rhs;
  }
  constexpr Modint operator*(const Modint rhs) const noexcept {
    return Modint(*this) *= rhs;
  }
  constexpr Modint operator/(const Modint rhs) const noexcept {
    return Modint(*this) /= rhs;
  }

  constexpr Modint &operator+=(const Modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) a -= Modulus;
    return *this;
  }
  constexpr Modint &operator-=(const Modint rhs) noexcept {
    if (a < rhs.a) a += Modulus;
    a -= rhs.a;
    return *this;
  }
  constexpr Modint &operator*=(const Modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr Modint &operator/=(Modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp & 1) *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }

  Modint pow(u64 t) const {
    if (!t) return 1;
    Modint x = pow(t>>1);
    x *= x;
    if (t&1) x *= *this;
    return x;
  }

  explicit operator bool() const {
    return a;
  }

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

using mint = Modint<>;

void solve() {
  int h, w; cin >> h >> w;
  vector<string> g(h);
  for(auto &s : g) cin >> s;

  vector<vector<bool>> b(h, vector<bool>(w, false));
  int sum = 0;
  for(int i=0; i<h; ++i) {
    for(int j=0; j<w; ++j) {
      if(g[i][j] == '.') {
        ++sum;
      } else {
        b[i][j] = true;
      }
    }
  }

  vector<vector<int>> cnt(h, vector<int>(w, -1));
  for(int i=0; i<h; ++i) {
    int prev = 0;
    for(int j=0; j<=w; ++j) {
      if(j == w || b[i][j]) {
        for(int k=prev; k<j; ++k) {
          cnt[i][k] += j - prev;
        }
        prev = j+1;
      }
    }
  }
  for(int j=0; j<w; ++j) {
    int prev = 0;
    for(int i=0; i<=h; ++i) {
      if(i == h || b[i][j]) {
        for(int k=prev; k<i; ++k) {
          cnt[k][j] += i - prev;
        }
        prev = i+1;
      }
    }
  }

  vector<mint> two(sum+1);
  two[0] = 1;
  for(int i=0; i<sum; ++i) {
    two[i+1] = two[i] * 2;
  }

  mint ans = two[sum] * sum;
  for(int i=0; i<h; ++i) {
    for(int j=0; j<w; ++j) {
      if(cnt[i][j] > 0) {
        ans -= two[sum - cnt[i][j]];
      }
    }
  }
  cout << ans << endl;
}

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

#include<bits/stdc++.h>
typedef int64_t i64;
typedef long double f128;
using namespace std;

template<typename T>
void scan(T& n)
{
  cin>>n;
  return;
}

void scan()
{
  return;
}

template<typename T,class... Args>
void scan(T& n,Args&... args)
{
  scan(n);
  scan(args...);
  return;
}

template<typename T>
void scan_array(T start,T end)
{
  T now=start;
  for(;now!=end;++now)
  {
    scan(*now);
  }
  return;
}

template<typename T>
void print(T n)
{
  cout<<n;
  return;
}

template<typename T>
void println(T n)
{
  print(n);
  print('\n');
  return;
}

template<typename T,class... Args>
void println(T n,Args... args)
{
  print(n);
  print(' ');
  println(args...);
  return;
}

template<typename T>
void print_array(T start,T end)
{
  T now=start;
  print(*now);
  ++now;
  for(;now!=end;++now)
  {
    print(' ');
    print(*now);
  }
  print('\n');
  return;
}

i64 pow_mod(i64 a,i64 n,i64 mod)
{
  i64 res=1,now=a;
  while(n)
  {
    if(n&1)
    {
      res=res*now%mod;
    }
    now=now*now%mod;
    n>>=1;
  }
  return res;
}

i64 inv_mod(i64 a,i64 mod)
{
  return pow_mod(a,mod-2,mod);
}

int main()
{
  i64 constexpr mod=1000000007;
  i64 H,W;
  scan(H,W);
  vector<string> S(H);
  scan_array(S.begin(),S.end());
  i64 K=0;
  for(i64 i=0;i<H;++i)
  {
    for(i64 j=0;j<W;++j)
    {
      if(S[i][j]=='.')
      {
        K+=1;
      }
    }
  }
  vector<vector<i64>> sum1(H,vector<i64> (W)),sum2(H,vector<i64> (W));
  for(int i=0;i<H;++i)
  {
    int start=-1,len=0;
    for(int j=0;j<W;++j)
    {
      if(S[i][j]=='#')
      {
        if(start==-1)
        {
          continue;
        }
        for(int k=start;k<j;++k)
        {
          sum1[i][k]=len;
        }
        start=-1;
        len=0;
        continue;
      }
      if(start==-1)
      {
        start=j;
      }
      len+=1;
    }
    if(start==-1)
    {
      continue;
    }
    for(int k=start;k<W;++k)
    {
      sum1[i][k]=len;
    }
  }
  for(int j=0;j<W;++j)
  {
    int start=-1,len=0;
    for(int i=0;i<H;++i)
    {
      if(S[i][j]=='#')
      {
        if(start==-1)
        {
          continue;
        }
        for(int k=start;k<i;++k)
        {
          sum2[k][j]=len;
        }
        start=-1;
        len=0;
        continue;
      }
      if(start==-1)
      {
        start=i;
      }
      len+=1;
    }
    if(start==-1)
    {
      continue;
    }
    for(int k=start;k<H;++k)
    {
      sum2[k][j]=len;
    }
  }
  vector<vector<i64>> vec(H,vector<i64> (W));
  for(int i=0;i<H;++i)
  {
    for(int j=0;j<W;++j)
    {
      vec[i][j]=K-(sum1[i][j]+sum2[i][j]-1);
    }
  }
  i64 sum=0;
  for(int i=0;i<H;++i)
  {
    for(int j=0;j<W;++j)
    {
      if(vec[i][j]==K+1)
      {
        continue;
      }
      sum+=pow_mod(2,vec[i][j],mod);
    }
  }
  sum%=mod;
  i64 ans=pow_mod(2,K,mod)*K%mod-sum;
  ans=(ans%mod+mod)%mod;
  println(ans);
}


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

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

#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define all(c) (c).begin(),(c).end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

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

int main(){
    fast
    ll h,w,n,m;
    cin>>h>>w>>n>>m;

    vi br[w+1],bc[h+1],dr[w+1],dc[h+1];

    map<pii,ll> mp;

    FOR0(i,n){
        ll x,y;
        cin>>x>>y;
        mp[{x,y}]=1;
        br[y].pb(x);
        bc[x].pb(y);
    }

    FOR0(i,m){
        ll x,y;
        cin>>x>>y;
        mp[{x,y}]=-1;
        dr[y].pb(x);
        dc[x].pb(y);
    }

    FOR0(i,h+1){
        sort(all(bc[i]));
        sort(all(dc[i]));
    }

    FOR0(i,w+1){
        sort(all(br[i]));
        sort(all(dr[i]));
    }

    ll ans=n;

    for(ll i=1;i<=h;i++){
        for(ll j=1;j<=w;j++){
            if(mp[{i,j}] !=0){
                continue;
            }

            auto it1=lower_bound(all(bc[i]),j);
            auto it2=lower_bound(all(dc[i]),j);

            ll d1=0,d2=w+1;
            if(it2 != dc[i].end()){
                d2 = *it2;
            }
            if(it2 != dc[i].begin()){
                it2--;
                d1 = *it2;
            }

            ll b1=-1,b2=-1;
            if(it1 != bc[i].end()){
                b2 = *it1;
            }
            if(it1 != bc[i].begin()){
                it1--;
                b1 = *it1;
            }

            if(b1>d1 && b1<d2){
                ans++;
                continue;
            }
            if(b2>d1 && b2<d2){
                ans++;
                continue;
            }

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

            it1=lower_bound(all(br[j]),i);
            it2=lower_bound(all(dr[j]),i);

            d1=0,d2=h+1;
            if(it2 != dr[j].end()){
                d2 = *it2;
            }
            if(it2 != dr[j].begin()){
                it2--;
                d1 = *it2;
            }

            b1=-1,b2=-1;
            if(it1 != br[j].end()){
                b2 = *it1;
            }
            if(it1 != br[j].begin()){
                it1--;
                b1 = *it1;
            }

            if(b1>d1 && b1<d2){
                ans++;
                continue;
            }
            if(b2>d1 && b2<d2){
                ans++;
                continue;
            }

        }
    }

    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vr vector
#define endl "\n"
#define all(x) x.begin(),x.end()

template<class T> void read(vr<T> &arr)
{
	for (auto &x : arr)
		cin >> x;
}

template<class T> void read(T &x)
{
	cin >> x;
}

template<class T> void write(vr<T> &arr)
{
	for (auto x : arr)
		cout << x << " ";
	cout << endl;
}

template<class T> void write(vr<vr<T>> &arr)
{
	for (auto &x : arr)
	{
		for (auto &y : x)
			cout << y << " ";
		cout << endl;
	}
}

template<class T> void write(T &x)
{
	cout << x;
}

void solve() {
				cout<<setprecision(9);
				cout<<fixed;
				int a,b,c,d;
				cin>>a>>b>>c>>d;
				b = -b;
				if(a == c)
				{
								cout<<a;
								return;
				}
				double slop = 1.0 * (d - b) / (c - a);
				double newX = (slop * a - b) / slop;
				cout<<newX;
}

int32_t main() {
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
//	cin>>t;
	while (t--)
	{
		solve();
	}
	return  0;
}


#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long n;
        cin>>n;
        int count=0;
        while(n%2==0)
        {
            n/=2;
            count++;
        }
        if(count==0)
        {
            cout<<"Odd"<<endl;
        }
        else if(count==1)
        {
            cout<<"Same"<<endl;
        }
        else
        {
            cout<<"Even"<<endl;
        }
    }
}


// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    set<string> st;
    rep(i, N){
        char c[22];
        scanf("%s", c);
        string s(c);
        st.insert(s);
    }

    // 2. 不満な文字列があるか？
    string ans = "satisfiable";
    for(auto &p : st){
        if(p[0] != '!'){
            string q = '!' + p;
            if(st.count(q)){
                ans = p;
                break;
            }
        }
    }

    // 3. 出力.
    printf("%s\n", ans.c_str());
    return 0;

}

#include<iostream>
#include<map>
using namespace std;
const int MAXN=2e5+10;
int n;
string a[MAXN];
map<string,int> mp;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];

		if(a[i][0]=='!') {
			a[i]=a[i].substr(1,a[i].length()-1);
			if(mp[a[i]]==0) mp[a[i]]=2;
			else if(mp[a[i]]==1) {
				cout<<a[i]<<endl;
				return 0;
			}
		}

		else {
			if(mp[a[i]]==0) mp[a[i]]=1;
			else if(mp[a[i]]==2) {
				cout<<a[i]<<endl;
				return 0;
			}

		}
	}
	cout<<"satisfiable\n";
	return 0;
}


#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define endl '\n'
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll n;
    cin>>n;
    Vec a(n);
    Vec b(n);
    cin>>a>>b;
    Vec v(n);
    ll ans = 0;
    rep(i,n){
        ans += a[i];
        v[i] = b[i]-a[i];
    }
    dbg(ans);
    dbg(v);
    Vec x;
    Vec y;
    rep(i,n){
        if(i%2==0){
            x.pb(v[i]);
        }else{
            y.pb(v[i]);
        }
    }

    sort(rALL(x));
    sort(rALL(y));
    dbg(x)
    dbg(y)
    ll now = ans;
    rep(i,n/2){
        now += x[i] + y[i];
        chmax(ans,now);
    }
    out(ans);
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ll T;
//    cin>>T;
//    while(T--)
    solve();
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

   ll n;
   cin>>n;

   ll sum = 0;

   ll arr[n], arr1[n];
   rep(n)
        cin>>arr[i];
   rep(n)
        cin>>arr1[i];
   rep(n)
        sum+=arr[i];
   set<pii,greater<pii>> s1,s2;
   rep(n)
        if(i%2 == 0)
            s2.insert(mp(arr1[i]-arr[i],i));
        else s1.insert(mp(arr1[i]-arr[i],i));
   while(s1.size()>0 && (*s1.begin()).ff + (*s2.begin()).ff > 0)
   {
       auto curr = *s1.begin();
       auto curr1 = *s2.begin();
       s1.erase(s1.begin());
       s2.erase(s2.begin());

       sum+=(curr.ff+curr1.ff);
   }
   cout<<sum;

  return 0;

}