#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
ll tr[N << 1];
struct Node {
	int num, idx;
	bool operator<(const Node& a) {
		return num < a.num;
	}
};
Node a[N];
int n, b[N];
inline int lowbit(int x) { return x & -x; }
void add(int idx, int val) {
	while (idx <= 2 * n) tr[idx] += val, idx += lowbit(idx);
	return;
}
int getsum(int idx) {
	int cnt = 0;
	while (idx) cnt += tr[idx], idx -= lowbit(idx);
	return cnt;
}
ll res;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].num;
		a[i].idx = i;
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; ++i) {
		add(a[i].idx, 1);
		b[a[i].num] = i - getsum(a[i].idx);
		res += b[a[i].num];
	}
	sort(a + 1, a + 1 + n, [](Node& c, Node& d){
		return c.idx < d.idx;
		});
	for (int i = 1; i <= n; ++i) {
		cout << res << endl;
		res =res -  a[i].num ;
		res = res +  n - a[i].num - 1ll;
	}
	return 0;
}

#pragma comment(linker, "/STACK:512000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

#define int li
//const int mod = 1000000007;

void solve(__attribute__((unused)) bool read) {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  vector<vector<pair<int, int>>> res(2);
  for (int i = 0; i < n; ++i) {
    res[i & 1].push_back({a[i], b[i]});
  }
  for (auto& vec : res) {
    sort(all(vec), [&](const pair<int, int>& q, const pair<int, int>& w) {
      return q.first - q.second < w.first - w.second;
    });
  }
  int cur_ans = ans;
  for (int i = 0; i < res[0].size(); ++i) {
    for (int j = 0; j < 2; ++j) {
      cur_ans -= res[j][i].first;
      cur_ans += res[j][i].second;
    }
    relax_max(ans, cur_ans);
  }

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


/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1e9 + 7
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a/b<<endl;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <iomanip>
#include <math.h>
#include <cmath>
using namespace std;
typedef long long int ll;
typedef unsigned long long lls;

int main()
{

    //129a
    /*int n;
    cin >> n;

    int contP(0);
    int contImp(0);
    int num;

    for(int i = 0; i < n; i++)
    {
        cin >> num;
        if(num % 2 == 0)
        {
            contP++;
        }
        else
        {
            contImp++;
        }
    }

    //RES

    int res(0);

    if(/*contImp > 2 &&// contImp % 2)
    {
        res += contImp;
    }
    else
    {
        res += contP;
    }

    cout << res;*/

    //ATCODER 182

    int a, b;
    cin >> b >> a;

    cout <<  ((2*b) + 100) - a;

    return 0;
}


#include<bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define MP make_pair
#define PB emplace_back
using namespace std;
const int SIZE = 1 << 20;
int a[SIZE];
int b[SIZE];
int A[40];
int T;
void dfs(int x,int bound, int v, int d[], int &num) {
    if(v > T) { return; }
    if(x == bound) {
        d[num++] = v;
        return;
    }
    dfs(x + 1, bound, v, d, num);
    dfs(x + 1, bound, v + A[x], d, num);
}
void solve() {
    int N;
    scanf("%d%d", &N, &T);
    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    int a_num = 0;
    dfs(0, N/2, 0, a, a_num);
    int b_num = 0;
    dfs(N/2, N, 0, b, b_num);
    sort(a, a + a_num);
    sort(b, b + b_num);
    int ptr = b_num - 1;
    int ma = 0;
    for(int i = 0; i < a_num; i++) {
        while(ptr >= 0 && a[i] + b[ptr] > T) {
            ptr--;
        }
        if(ptr < 0) { break; }
        ma = max(ma, a[i] + b[ptr]);
    }
    printf("%d\n", ma);
}
int main() {
    solve();
    return 0;
}

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 10/24/20 20:53:04
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,m; cin>>n>>m;
  if (m < 0 or (m != 0 and m >= n-1)) {
    cout << -1 << endl;
  } else {

    if (m == 0) {
      vector<pair<int,int>> LR;
      int k = 1;
      for (int i = 0; i < n; i++) {
        LR.emplace_back(k, k+1);
        k += 2;
      }
      for (auto [l,r] : LR)
        cout << l << " " << r << endl;
    } else {
      vector<pair<int,int>> LR;
      int k = 1;
      for (int i = 0; i < n-m-2; i++) {
        LR.emplace_back(k, k+1);
        k += 2;
      }
      LR.emplace_back(k, k+1+2*(m+1));
      k++;
      for (int i = 0; i < m+1; i++, k+=2)
        LR.emplace_back(k, k+1);

      for (auto [l,r] : LR)
        cout << l << " " << r << endl;
    }

  }

  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod = 1e9 + 7;
int add(int a, int b) {
    return (a + b) % mod;
}
int mul(int a, int b) {
    ll ans = a * 1ll * b;
    return ans % mod;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> grid(h, vector<bool>(w, false));
    int cnt = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                grid[i][j] = true;
                cnt++;
            }
        }
    }
    int res = 0;
    vector<int> pow(cnt + 1);
    pow[0] = 1;
    for (int i = 1; i <= cnt; i++) {
        pow[i] = add(pow[i - 1], pow[i - 1]);
    }
    vector<vector<pair<int, int>>> gridn(h, vector<pair<int, int>>(w, make_pair(0, 0)));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j]) {
                if (gridn[i][j].first == 0) {
                    int temp = 1;
                    for (int k = j + 1; k < w; k++) {
                        if (!grid[i][k]) {
                            break;
                        }
                        temp++;
                    }
                    //cout << "asd" << temp << endl;
                    for (int k = j; k < w; k++) {
                        if (!grid[i][k]) {
                            break;
                        }
                        gridn[i][k].first = temp;
                    }
                }
                if (gridn[i][j].second == 0) {
                    int temp = 1;
                    for (int k = i + 1; k < h; k++) {
                        if (!grid[k][j]) {
                            break;
                        }
                        temp++;
                    }
                    //cout << "asdf" << temp << endl;
                    for (int k = i; k < h; k++) {
                        if (!grid[k][j]) {
                            break;
                        }
                        gridn[k][j].second = temp;
                    }
                }
                int temp = gridn[i][j].first + gridn[i][j].second - 1;
                //cout << temp << i << j << endl;
                res = add(res, mul(pow[cnt - temp], pow[temp] - 1));
            }
        }
    }
    cout << res << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>
#include <algorithm>
using namespace std;

string rus;
int point = 0;

void move(vector<vector<int>> &mdata, vector<vector<int>> &pdata, vector<int> cdata,int x,int y,int p,int dir, string sdata,int c){
	if (point < p) {
		rus = sdata;
		point = p;
	}
	if (x > 50 || y > 50 || x <= 0 || y <= 0) {
		return;
	}
	if (cdata.at(mdata.at(y).at(x)) == 0) {
		return;
	}
	cdata.at(mdata.at(y).at(x)) = 0;
	p = p + pdata.at(y).at(x);

	if (dir == 1)
		sdata += 'D';
	else if (dir == 2)
		sdata += 'U';
	else if (dir == 3)
		sdata += 'R';
	else if (dir == 4)
		sdata += 'L';

	map<int, int> hp;
	int cnt = 0;
	if(cdata.at(mdata.at(y + 1).at(x)) != 0)
		hp[pdata.at(y + 1).at(x)] = 1;
	if (cdata.at(mdata.at(y - 1).at(x)) != 0)
		hp[pdata.at(y - 1).at(x)] = 2;
	if (cdata.at(mdata.at(y).at(x + 1)) != 0)
		hp[pdata.at(y).at(x + 1)] = 3;
	if (cdata.at(mdata.at(y).at(x - 1)) != 0)
		hp[pdata.at(y).at(x - 1)] = 4;

	for (auto i = hp.rbegin();i != hp.rend();i++) {
		if (i->second == 1) {
			move(mdata, pdata, cdata, x, y + 1, p, 1, sdata,c+1);
		}
		else if (i->second == 2) {
			move(mdata, pdata, cdata, x, y - 1, p, 2, sdata,c+1);
		}
		else if (i->second == 3) {
			move(mdata, pdata, cdata, x + 1, y, p, 3, sdata,c+1);
		}
		else {
			move(mdata, pdata, cdata, x - 1, y, p, 4, sdata,c+1);
		}

		//cout << i->second << endl;
		cnt++;
		if ((cnt == 1 && c > 15) ||(cnt == 2 && c > 10)) break;
	}
}

int main(void) {
	int sx, sy;
	string sdata;

	cin >> sy >> sx;

	vector<int> cdata(52 * 52, 0);
	vector<vector<int>> mdata(52, vector<int>(52));
	vector<vector<int>> pdata(52, vector<int>(52));
	for (int i = 1;i <= 50;i++) {
		for (int j = 1;j <= 50;j++) {
			cin >> mdata.at(i).at(j);
			cdata.at(mdata.at(i).at(j)) = 1;
		}
	}
	for (int i = 1;i <= 50;i++) {
		for (int j = 1;j <= 50;j++) {
			cin >> pdata.at(i).at(j);
		}
	}
	move(mdata,pdata, cdata, sx+1, sy+1,pdata.at(sy+1).at(sx+1),0,sdata,0);

	cout << rus << endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
#define pb push_back
#define ms(a, b); memset(a, b, sizeof(a));
#define all(x) x.begin(), x.end()
#define endl "\n"
#define ins insert
#define bck back
#define lb lower_bound
#define ub upper_bound
#define popcount(x)  __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define clz(x) __builtin_clz(x)
const int inf = 0x3f3f3f3f, mod = 1e9+7, mx = 2e5+10, LOGN = 21;
const ll infll = 0x3f3f3f3f3f3f3f3f;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	vector<pair<int, string>> a(n);
	for(int i=0; i < n; i++)cin >> a[i].second >> a[i].first;
	sort(all(a));
	cout << a[n-2].second << "\n";
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  map<int,string> mount{};
  vector<int> vec;
  rep(i,n) {
    string s;
    int x;
    cin>>s>>x;
    mount[x]=s;
    vec.push_back(x);
  }
  sort(vec.begin(),vec.end(),greater<int>());
  cout<<mount[vec[1]]<<endl;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;
ll Fib[89];

int main(){
  Fib[0]=Fib[1]=1;
  for(int i=2;i<89;i++)Fib[i]=Fib[i-1]+Fib[i-2];

  ll n;cin>>n;
  vector<int> A;
  for(int i=88;i>=0;i--){
    if(n>=Fib[i]){
      A.push_back(i);
      n-=Fib[i];
    }
  }
  reverse(ALL(A));
  vector<int> ans;
  int now=0;
  for(int i=0;i<88&&now<A.size();i++){
    if(A[now]==i){
      ans.push_back(1+(i&1));
      now++;
    }
    ans.push_back(3+(i&1));
  }
  reverse(ALL(ans));
  cout<<ans.size()<<endl;
  for(int p:ans)cout<<p<<endl;
}

#include<bits/stdc++.h>
using namespace std;
const double SQUP=0.618033992;
const double SQLO=0.618033982;

bool Deal(long long x,long long y,int dep)
{
	if(dep>129)return false;
	if(x<5 && y<5)
	{
		int tot=dep+x+y+1;
		if(tot>129)return false;
		printf("%d\n",tot);
		for(int i=1;i<=x;i++)puts("1");
		for(int i=1;i<=y;i++)puts("2");
		return true;
	}
//	printf("%lld %lld %d %.10lf\n",x,y,dep,1.0*x/y);
	if(rand()%25==0)
	{
		bool ret=Deal(x,y-1,dep+1);
		if(ret)puts("2");
		return ret;
	}
	if(rand()%25==0)
	{
		bool ret=Deal(x-1,y,dep+1);
		if(ret)puts("1");
		return ret;
	}
	if(x>y)
	{
//		if(y>x*SQUP && rand()%6)Deal(x,y-1,dep+1);
//		else if(x<200 && y<200 && x%y<y/16)Deal(x,y-1,dep+1);
//		else
		bool ret=Deal(x-y,y,dep+1);
		if(ret)puts("3");
		return ret;
	}
	else
	{
//		if(x>y*SQUP && rand()%6)Deal(x-1,y,dep+1);
//		else if(x<200 && y<200 && y%x<x/16)Deal(x-1,y,dep+1);
//		else
		bool ret=Deal(x,y-x,dep+1);
		if(ret)puts("4");
		return ret;
	}
}

int main()
{
	long long tar;scanf("%lld",&tar);
	long long x=tar*(sqrt(5)-1)/2,y=tar-x;
	while(!Deal(x,y,0));
	puts("3");
	return 0;
}


#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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

template<class T, class S> inline bool exist(std::set<T> &s, const S &e){
    return (s.find(e) != s.end());
}

struct edge{
    int to;
    long long C, D;
    edge(int To, long long c, long long d): to(To), C(c), D(d){}
};

void dijkstra(int s, std::vector<std::vector<edge>> &G, std::vector<long long> &d, std::vector<int> &prv){
    //pair<int, int> first: 距離　second: 頂点
    std::priority_queue<std::pair<long long, int>,
                        std::vector<std::pair<long long, int>>,
                        std::greater<std::pair<long long, int>>> que;
    int V{int(G.size())};
    d.resize(V, LINF+3);
    prv.resize(V, NIL);
    d[s] = 0;
    que.emplace(0, s);

    while(!que.empty()){
        std::pair<long long, int> p{que.top()}; que.pop();
        int v{p.second};
        if(d[v] < p.first) continue;
        for(edge &e: G[v]){
            long long TT{(long long)(std::sqrt((long double)(e.D)) - 1)};
            long long mn{LINF+8};
            for(int i{-300}; i <= 300; ++i){
                long long t{TT + i};
                if(t < d[v]) t = d[v];
                chmin(mn, t + e.C + e.D/(t + 1));
            }
            if(d[e.to] > mn){
                d[e.to] = mn;
                prv[e.to] = v;
                que.emplace(d[e.to], e.to);
            }
        }
    }
}

int main(){
    int N, M; std::cin >> N >> M;
    std::vector<std::vector<edge>> G(N);
    {
        int A, B; long long C, D;
        for(int i{0}; i < M; ++i){
            std::cin >> A >> B >> C >> D;
            G[A-1].emplace_back(B-1, C, D);
            G[B-1].emplace_back(A-1, C, D);
        }
    }
    std::vector<long long> d;
    std::vector<int> p;
    dijkstra(0, G, d, p);
    std::cout << (d[N-1] <= LINF ? d[N-1]: -1LL) << std::endl;
    return 0;
}

#include <bits/stdc++.h>
typedef long long int   LL;
typedef long double     LD;
#define nl              '\n'
#define ff              first
#define ss              second
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define FOR(i,a)        for(int i=0;i<a;i++)
//#pragma                 GCC optimize("Ofast,no-stack-protector")
//#pragma                 GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma                 GCC optimize("unroll-loops")
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define sss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

//--------------------------code starts here---------------------------------------
const int maxn=2e5+5;

vector<LL> adj[maxn];
set<LL> st;
vector<pll> v;
int n;

LL dp[maxn][2];

LL calc(LL x,LL y)
{
    /*if(x<0 && y<0)
    {
        return abs(fabs(x)-fabs(y));
    }

    if(x<0 && y>=0)
    {
        return fabs(x)+y;
    }
    if(x>0 && y>0)
        return abs(y-x);*/

    return abs(x-y);
}
LL lowest=100000000000000;
LL fun(int pos,int flag)
{
    if(pos==n)
    {
        if(flag==0)
        {
            return abs(lowest-v[pos-1].ff);
        }
        else
        {
            return abs(lowest-v[pos-1].ss);
        }
    }

    if(dp[pos][flag]!=-1)
        return dp[pos][flag];

    LL res=10000000000000000;
    if(flag==0)
    {
        LL dist=calc(v[pos-1].ff,v[pos].ff);
        dist+=calc(v[pos].ff,v[pos].ss);
        res=min(res,dist+fun(pos+1,1));

        dist=calc(v[pos-1].ff,v[pos].ss);
        dist+=calc(v[pos].ff,v[pos].ss);
        res=min(res,dist+fun(pos+1,0));
    }
    else
    {
        LL dist=calc(v[pos-1].ss,v[pos].ff);
        dist+=calc(v[pos].ff,v[pos].ss);
        res=min(res,dist+fun(pos+1,1));

        dist=calc(v[pos-1].ss,v[pos].ss);
        dist+=calc(v[pos].ff,v[pos].ss);
        res=min(res,dist+fun(pos+1,0));
    }

    return dp[pos][flag]=res;
}

void solve(int test)
{
    si(n);
    FOR(i,n)
    {
        LL x,y;
        sll(x,y);
        adj[y].pb(x);
        st.insert(y);
    }

    v.pb({0,0});

    for(auto i:st)
    {
        sort(adj[i].begin(),adj[i].end());
        LL frst=adj[i][0];
        LL lst=adj[i][adj[i].size()-1];
        v.pb({frst,lst});

        lowest=min(lowest,frst);
        lowest=min(lowest,lst);
    }

    for(int i=0;i<v.size();i++)
    {
        v[i].ff+=lowest;
        v[i].ss+=lowest;
    }

    n=v.size();

    mem(dp,-1);
    LL res=fun(1,0);
    printf("%lld\n",res);

}

int main()
{
	int test=1;
    //si(test);
    Rep(i,1,test)
    {
        solve(test);
    }

	return 0;
}


#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
#include <stdio.h>
int main(void) {
    ll n,i,c=0,d=0,ma,min;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        c+=abs(a[i]);
        d+=a[i]*a[i];
    }
    ma=*max_element(a,a+n);
    min=*min_element(a,a+n);
    cout<<c<<"\n"<< fixed << setprecision(15) << sqrt(d)<<"\n"<<max(ma,-1*min);

	return 0;
}

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

#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define pb          push_back
#define all(v)      v.begin(),v.end()
#define ya          cout<<"YES"<<endl;
#define no          cout<<"NO"<<endl;
#define ff          first
#define sc          second
#define inf         999999999
#define pi          3.14159265359
#define printv(v)   for(auto x:v)cout<<x<<' ';cout<<endl;
#define takev(v)    for(auto &x:v)cin>>x;
inline  int         random(int a=1,int b=10)
{
    return a+rand()%(b-a+1);
}
typedef long long ll;
inline ll           lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
//#define see(x)  cout<<endl<<#x<<" : "<<(x)<<endl;
#define see(args...) \
{ \
    string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);\
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr<< *it << " = " << a <<",\n"[++it==istream_iterator<string>()];
    err(it, args...);
}

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int N=2e5+9,mod=998244353;

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

    ll n,i,j,k,ans=0,tot=0,ta=0,ao=0,win=0;
    string s,t;
    cin>>k;
    cin>>s>>t;
    vector<ll>ft(11),fa(11),have(11,k);

    for(int i=0;i<4;i++)ft[s[i]-'0']++,have[s[i]-'0']--;
    for(int i=0;i<4;i++)fa[t[i]-'0']++,have[t[i]-'0']--;

    for(i=1;i<=9;i++)
    {
        ta += i*pow(10,ft[i]);
        ao += i*pow(10,fa[i]);
    }

    tot = k*9 - 8;
    tot *= tot-1;

    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            ft[i]++;
            fa[j]++;

            ll taka = ta - i*pow(10,ft[i]-1);
            taka += i*pow(10,ft[i]);

            ll aoki = ao - j*pow(10,fa[j]-1);
            aoki += j*pow(10,fa[j]);

            ft[i]--;
            fa[j]--;

            if(taka > aoki)
            {
                if(i==j)
                win += have[i]*(have[j]-1);
                else
                win += (have[i]*have[j]);
            }

        }
    }

    printf("%.10lf\n",win/(tot*1.0));

    return 0;
}


//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	int n,q;
	cin>>n>>q;
	vl A(n);
	take(A,0,n);
	sort(all(A));
	while(q--)
	{
		ll k;
		cin>>k;
		ll low = 0, high = 2e18;
		ll ans=-1;
		while(low<=high)
		{
			ll mid = low + (high-low)/2;
			int smol = 0;
			int l = 0, h = n-1;
			while(l<=h)
			{
				int m = l + (h-l)/2;
				if(A[m]<=mid)
				{
					smol = m+1;
					l = m+1;
				}
				else h = m-1;
			}
			if(mid - smol >=k)
			{
				ans = mid;
				high = mid-1;
			}
			else low = mid+1;
		}
		cout<<ans<<endl;
	}
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[100010],n,q;
signed main(){
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		a[i]-=i;
	}
	while(q--){
		int k;
		cin>>k;
		int rk=lower_bound(a+1,a+n+1,k)-a-1;
		if(rk==n+1){
			cout<<k+n<<endl;
		}else{
			cout<<k+rk<<endl;
		}
	}
}


// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;

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

#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353

void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
	F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef arwaeystoamneg
	if (sz(s))
	{
		freopen((s + ".in").c_str(), "r", stdin);
		if (s != "test1")
			freopen((s + ".out").c_str(), "w", stdout);
	}
#endif
}

template<int MOD, int RT> struct mint {
	static const int mod = MOD;
	static constexpr mint rt() { return RT; } // primitive root for FFT
	int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
	mint() { v = 0; }
	mint(ll _v) {
		v = int((-MOD < _v&& _v < MOD) ? _v : _v % MOD);
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mint& a, const mint& b) {
		return a.v == b.v;
	}
	friend bool operator!=(const mint& a, const mint& b) {
		return !(a == b);
	}
	friend bool operator<(const mint& a, const mint& b) {
		return a.v < b.v;
	}

	mint& operator+=(const mint& m) {
		if ((v += m.v) >= MOD) v -= MOD;
		return *this;
	}
	mint& operator-=(const mint& m) {
		if ((v -= m.v) < 0) v += MOD;
		return *this;
	}
	mint& operator*=(const mint& m) {
		v = int((ll)v * m.v % MOD); return *this;
	}
	mint& operator/=(const mint& m) { return (*this) *= inv(m); }
	friend mint power(mint a, ll p) {// MAKE SURE YOU ARE USING THE CORRECT VERSION OF POW!!!!!!!!
		mint ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	friend mint inv(const mint& a) {
		assert(a.v != 0);
		return power(a, MOD - 2);
	}

	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }
	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

typedef mint<inf, 5> mi; // 5 is primitive root for both common mods
const int MAX = 1111111;
int n, m, k;
mi fac[2 * MAX];
mi choose(int x, int y)
{
	if (y == -1)return 0;
	return fac[x] * inv(fac[y]) * inv(fac[x - y]);
}
int main()
{
	setIO("test1");
	cin >> n >> m >> k;
	if (m + k < n)
	{
		cout << 0 << endl;
		return 0;
	}
	fac[0] = 1;
	F0R(i, 2 * MAX - 1)
	{
		fac[i + 1] = fac[i] * (i + 1);
	}
	cout << (int)(choose(n + m, n) - choose(n + m, n - k - 1)) << endl;
}

#include<iostream>
#include<string>
#include<iomanip>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<vector>
#include<limits.h>
#include<math.h>
#include<array>
#include<map>
#include<cstring>
#include<stack>
#include<numeric>
using ll = long long;
constexpr int MOD = 1e9+7;

int power(int x,int y){
	int res = 1;
	while(y > 0){
		if(y%2){
			res = (res * 1LL * x)%MOD;
		}
		x = (x * 1LL * x)%MOD;
		y /= 2;
	}
	return res;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n,m,k;
	std::cin >> n >> m >> k;
	if(n > m+k){
		std::cout << "0\n";
	}
	else{
		std::vector<int> fact(n+m+1);
		fact[0] = 1;
		for(int i = 1; i <= n+m;++i){
			fact[i] = (fact[i-1] * 1LL * i)%MOD;
		}
		int temp = (fact[n] * 1LL * fact[m])%MOD;
		int ans = (fact[n+m] * 1LL * power(temp,MOD-2))%MOD;
		if(k+1 <= n){
			temp = (fact[n-k-1] * 1LL * fact[m+k+1])%MOD;
			temp = (fact[n+m] * 1LL * power(temp,MOD-2))%MOD;
			ans = ((ans - temp)%MOD + MOD)%MOD;
		}
		std::cout << ans << '\n';
	}
}


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

const int maxn = 1e6 + 13;

int e[20];
bool dp[maxn];
int dp2[maxn];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		e[u] |= 1 << v;
		e[v] |= 1 << u;
	}

	dp[0] = 1;
	for (int mask = 1; mask < (1 << n); ++mask) {
		for (int i = 0; i < n; ++i) {
			if (mask >> i & 1)
				if(((mask & ~(1 << i)) & e[i]) == (mask & ~(1 << i)))
					dp[mask] |= dp[mask & ~(1 << i)];
 		}
	}
	for (int mask = 1; mask < (1 << n); ++mask) {
		if (dp[mask]) {
			dp2[mask] = 1;
			continue;
		}
		int cnt = 0;
		for (int i = 0; i < n; ++i)cnt += mask >> i & 1;
		dp2[mask] = cnt;
		for (int s = mask; s; s = (s - 1) & mask) {
			dp2[mask] = min(dp2[mask], dp2[s] + dp2[~s & mask]);
 		}
	}
	cout << dp2[(1 << n) - 1] << "\n";
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=998244353;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll binom(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  ll res=1;
  for(ll i=0;i<k;i++) res=res*(n-i)%MOD;
  res=res*ifac[k]%MOD;
  return res;
}

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

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

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

  setComb();

  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  vector<ll> sum(K+1,0);
  vector<ll> num(N,1);
  for(int k=1;k<=K;k++){
    rep(i,N){
      mul(num[i],A[i]);
      add(sum[k],num[i]);
    }
  }

  vector<ll> dp(K+1,0);
  for(int k=1;k<=K;k++){
    add(dp[k],(N)*sum[k]%MOD);
    add(dp[k],(N)*sum[k]%MOD);

    for(int x=1;x<k;x++){
      ll res=sum[x];
      mul(res,sum[k-x]);
      mul(res,comb(k,x));
      add(dp[k],res);
    }
  }

  vector<ll> ans=dp;
  rep(i,N) num[i]=1;
  for(int k=1;k<=K;k++){
    rep(i,N){
      mul(num[i],(A[i]+A[i])%MOD);
      add(ans[k],MOD-num[i]);
    }
    mul(ans[k],inv[2]);
  }

  rep(i,K) cout<<ans[i+1]<<"\n";

  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1500005;
int n,m;
int a[N];
int queue[N];
int book[N];
int l,r=0;

int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<m;i++)
		queue[r++]=a[i],book[a[i]]++;
	int ans=9999999;
	for(int i=0;i<N;i++)
		if(book[i]==0)
		{
			ans=i;
			break;
		}
	while(r<n)
	{
		int temp=queue[l++];
		book[temp]--;
		queue[r]=a[r];
		book[a[r]]++;
		if(book[temp]==0&&ans>temp)
			ans=temp;
		r++;

		//cout<<ans<<endl;
	}
	cout<<ans<<endl;

}

/*
	I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
/*----typedefs--------*/
typedef long long ll;typedef long double ld;typedef complex<ld> cd;
typedef pair<int, int> pi;typedef pair<ll, ll> pl;typedef pair<ld, ld> pd;
typedef vector<int> vi;typedef vector<pi> vpi;typedef vector<ll> vl;typedef vector<ld> vd;typedef vector<pl> vpl;
typedef vector<cd> vcd;typedef vector<vi> vvi;
typedef map<int, int> mi;typedef map<ll, ll> ml;typedef map<int, vi> mivi;typedef map<int, pi> mipi;
typedef set<int> si;typedef set<ll> sl;typedef set<pair<int, int>> spi;
typedef queue<int> qi;typedef queue<pi> qpi;
/*-----in and out--------*/
#define sc(a) cin >> a
#define pf(a) cout << a << endl
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*-----traversals--------*/
#define trav(it, a) for(auto &it : a)
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
/*--- bit-stuff ----*/
#define GET_SET_BITS(a) (__builtin_popcount(a))
#define GET_SET_BITSLL(a) ( __builtin_popcountll(a))
#define GET_TRAIL_ZERO(a) (__builtin_ctz(a))
#define GET_LEAD_ZERO(a) (__builtin_clz(a))
#define GET_PARITY(a) (__builtin_parity(a))
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/*------ single or multiple testcase-----*/
#define ssolve solve();
#define msolve int t;sc(t);while(t--) {solve();}
#define mcsolve int t;sc(t);for(int tt = 1;tt <= t;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 5;
const int MAX = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
void solve() {
	int n, k;
	int a[8][8];

	scanf("%d%d", &n, &k);
	F0R(i, n) {
		F0R(j, n) {
			scanf("%d", &a[i][j]);
		}
	}

	int cnt = 0, s = 0;
	int b[8] = {0, 1, 2, 3, 4, 5, 6, 7};
	while(b[0] == 0) {
		s = 0;
		for(int i = 0;i + 1 < n;i++) {
			s += a[b[i]][b[i + 1]];
		}

		s += a[b[n - 1]][b[0]];
		if(s == k) {
			cnt++;
		}

		next_permutation(b, b + n);
	}

	printf("%d\n", cnt);
}

int main() {
	ssolve
	return 0;
}


#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;

}
void printv(vector<ll>a){
    rep(i,a.size()){
        if(i==a.size()-1){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll A,B;
    cin>>A>>B;
    vl ans;
    if(A > B){
        ll sum=0;
        rep2(i,A){
            ans.pb(i);
            sum+=i;
        }
        rep2(i,B-1){
            ans.pb(-i);
            sum-=i;
        }

        ans.pb(-sum);
    }else{
        ll sum=0;
        rep2(i,B){
            ans.pb(-i);
            sum-=i;
        }
        rep2(i,A-1){
            ans.pb(i);
            sum+=i;
        }

        ans.pb(-sum);
    }

    printv(ans);
    return 0;

}


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

int main() {
	int N; cin >> N;
	multiset<string> st;
	for (string s; cin >> s;) {
		st.insert(s);
	}

	for (const string &s: st) {
		if (st.count('!' + s)) {
			cout << s << '\n';
			return 0;
		}
	}
	cout << "satisfiable\n";
}

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#include <map>
#include <vector>
#include <cstdio>
#include <climits>
#define white 0
#define gray 1
#define black 2
#define LIMIT (1<<30)
#define MOD 1000000007
//#define MOD 998244353
#define ll long long
using namespace std;

//const ll INF = LLONG_MAX;
//cout << fixed << setprecision(10) << ans << endl;
//pair<ll, ll> vec[4] = {make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0), make_pair(0, -1)};

int main(){
    int n;
    cin >> n;
    cout << n - 1 << endl;
}


// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#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 int long long int

#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
#define Graph vector<vi>
#define Graphw vector<vector<pair<int,int>>>
#define sz(x) (int)x.size()
#define pr pair<int,int>

#define display(v) for(int i =0;i<(int)v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
#define read(a) for(int i = 0;i<(int)a.size();++i)cin>>a[i]
#define show(x) cout << #x << " is " << x << "\n";
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
// typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
#define show_arr(a) cout << #a << "\n"; display(a) ; cout << "\n";
inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }
inline int sum_till(int n) { return mul(mul(n, n + 1), (MOD + 1) / 2); }
const int nax = 300*1000 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define ook order_of_key
//#define fbo find_by_order
//   order_of_key(x) -> number of elements less than x.
// * find_by_order(x) -> gives the element at index x (0 - indexing)

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

int sumXOR(vi arr)
{
    int sum = 0;
    for (int i = 0; i < 61; i++)
    {
        //  Count of zeros and ones
        int zc = 0, oc = 0;

        // Individual sum at each bit position
        int idsum = 0;
        for (int j = 0; j < sz(arr); j++)
        {
            if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;
        }

        // calculating individual bit sum
        idsum = mul(oc , mul(zc , (1LL<<i)));

        // final sum
        sum  = add(sum , idsum);
    }
    return sum;
}

int n;
Graphw G;
vi val;

void dfs(int st , int par = -1 , int cur = 0LL){
    val[st] = cur;
    //cout << st << '\n';
    for(pr to : G[st]){
        if(to.ff != par){
            dfs(to.ff , st , cur^to.ss);
        }
    }
}

void test_case(){
    cin>>n;
    val = vi(n + 1 , 0);
     G = Graphw(n + 1);
    for(int i = 0;i < n - 1 ; ++i){
        int u   ,v , w; cin>>u>>v>>w;
        G[u].pb({v , w});
        G[v].pb({u , w});
    }
    //cout << "Hi";
    dfs(1);
    vi arr;
    for(int i = 1; i <= n ; ++i){
        arr.pb(val[i]);
    }
    cout << sumXOR(arr);
}

// Химаншу
// check overflow
// special case n == 1
// 🍪🍪🍪

// Code Created BY LEO_VALDEZ
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define sarr(x) (int)(sizeof(x)/sizeof(x[0]))
#define mp make_pair
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define p2(x) (1ll<<x)
#define pob pop_back
#define f first
#define s second
#define in pair<int, int>
#define INF 1000000000000000
#define MX (int)2e5+5
const int mod = 1e9 + 7;// make this 98953... if reqd
vector<in> Adj[MX];
int dp[MX];
void DFS(int u, int p, int val)
{
	dp[u] = val;
	for(in vw : Adj[u])
	{
		int v = vw.f;
		int w = vw.s;
		if(v==p)
			continue;
		DFS(v, u, val^w);
	}
	return;
}
signed main()
{
	int n;
	cin >> n;
	int m = n-1;
	while(m--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		Adj[a].pb({b, c});
		Adj[b].pb({a, c});
	}
	DFS(0, -1, 0);
	vector<int> a(60, 0);
	vector<int> b(60, 0);
	for(int i = 0; i < 60; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if((dp[j]>>i)&1)
				a[i]++;
			else
				b[i]++;
		}
	}
	int ans = 0;
	for(int i = 0; i < 60; i++)
	{
		int po = (1ll<<i)%mod;
		int other = (a[i]*b[i])%mod;
		ans+=((po*other)%mod);
		ans%=mod;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    lli a,b;cin>>a>>b;
    lli sum=0;
    flli(i,1,a)
    {
    	lli var=500500+i;
    	cout<<var<<" ";
    	sum+=var;
    }
    flli(i,1,b-1)
    {
    	cout<<-i<<" ";
    	sum-=i;
    }
    cout<<-sum;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    ll n, m;
    cin >> n >> m;
    ll a, b;
    vvll g(n);
    REP(i, m) {
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll k;
    cin >> k;
    vll c(k);
    REP(j, k) {
        cin >> c[j];
        c[j]--;
    }
    auto BFS = [&](int s){
        vll cost(n, INF);
        cost[s] = 0;
        queue<int> q;
        q.push(s);
        while(q.size()){
            int x = q.front();
            q.pop();
            for(int y : g[x]) if(chmin(cost[y], cost[x] + 1)) q.push(y);
        }
        for(int i = 0; i < k; i++) cost[i] = cost[c[i]];
        cost.resize(k);
        return cost;
    };

    vvll d(k);
    REP(i, k) d[i] = BFS(c[i]);

    vvll dp(k, vll(1 << k, INF));
    REP(i, k) dp[i][0] = 0;
    for(int bit = 1; bit < (1 << k); bit++){
        REP(j, k) if(bit >> j & 1) {
            REP(x, k){
                ll cost = dp[j][bit - (1 << j)] + d[j][x];
                if (bit == ((1 << k) - 1)) chmin(dp[x][bit], dp[j][bit - (1 << j)]);
                chmin(dp[x][bit], cost);
            }
        }
    }

    ll ans = INF;
    REP(i, k) chmin(ans, dp[i][(1 << k) - 1]);

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


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//AtCoder以外ではコメントアウトを忘れずに！
//#include <atcoder/all>
//using namespace atcoder;
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
//**AC Libraryリスト**//
//pow_mod, inv_mod, floor_sum, convolution, convolution_ll, modint//
//fenwicktree, segtree, lazysegtree, string//
ll i, j, k, l; ll N, M, K, H, W, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vector<vtll> path;
//***********//
inline long long mod2(long long a, long long m) {
	return (a % m + m) % m;
}

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

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
	long long p, q;
	long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
	if ((b2 - b1) % d != 0) return make_pair(0, -1);
	long long m = m1 * (m2 / d); // lcm of (m1, m2)
	long long tmp = (b2 - b1) / d * p % (m2 / d);
	long long r = mod2(b1 + m1 * tmp, m);
	return make_pair(r, m);
}
int main() {
	ll T;
	cin >> T;
	for (l = 0; l < T; l++) {
		ll X, Y, P, Q;
		cin >> X >> Y >> P >> Q;
		ll ans = INF;
		for (i = 0; i < Y; i++) {
			for (j = 0; j < Q; j++) {
				ll m1 = X * 2 + Y * 2;
				ll b1 = X + i;
				ll m2 = P + Q;
				ll b2 = P + j;
				pll Ans = ChineseRem(b1, m1, b2, m2);
				//debug(b1,m1, b2,m2, Ans.first,Ans.second);
				if (Ans.second != -1) {
					chmin(ans, Ans.first);
				}
			}
		}
		//debug(1000000000999999999 - ans);
		if (ans == INF) cout << "infinity" << endl;
		else cout << ans << endl;
		//debug(ChineseRem(3, 2, 5, 3).first);
	}
}

#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli __int128
#define ldouble long double
using namespace std;

/*
(2x + 2y)n + x <= t < (2x + 2y)n + x + y
  range = y (max 500)
(p + q)n + p <= t < (p + q)(n + 1)
  range = q (max 500)

try all combinations of mod (500^2)

t - (2x + 2y)n - x == remY
t - (2x + 2y)n = remY + x
t = remY + x + (2x + 2y)n1

t - (p + q)n - p == remQ
t - (p + q)n = remQ + p
t = remQ + p + (p + q)n2

remQ + p + (p + q)n2 = remY + x + (2x + 2y)n1
(p + q)n2 - (2x + 2y)n1 = remY + x - remQ - p

*/

lli read() {
    lli x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
void print(lli x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

lli abslol(lli num)
{
  return num < 0 ? -num : num;
}

lli gcd(lli a, lli b, lli& x, lli& y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  lli x1, y1;
  lli d = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

bool find_any_solution(lli a, lli b, lli c, lli &x0, lli &y0, lli &g)
{
  g = gcd(abslol(a), abslol(b), x0, y0);
  if (c % g) {
    return false;
  }

  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 = -x0;
  if (b < 0) y0 = -y0;
  return true;
}

const lli inf = LONG_LONG_MAX;
lli x, y, p, q;

lli findMinSolution(lli remY, lli remQ)
{
  // t - (2x + 2y)n - x == remY
  // t - (2x + 2y)n = remY + x
  // t = remY + x + (2x + 2y)x0

  // t - (p + q)n - p == remQ
  // t - (p + q)n = remQ + p
  // t = remQ + p + (p + q)y0

  // remQ + p + (p + q)y0 = remY + x + (2x + 2y)x0
  // -(2x + 2y)x0 + (p + q)y0 = remY + x - remQ - p
  lli x0, y0, g;
  lli a = -(2*x + 2*y), b = p + q, c = remY + x - remQ - p;
  if (find_any_solution(a, b, c, x0, y0, g))
  {
    lli t1 = remY + x + (2*x + 2*y)*x0, t2 = remQ + p + (p + q)*y0;
    bool isNegative = a / g < 0;

    // lli lo = 0, hi = 1e18;
    // while (lo < hi)
    // {
    //   lli mid = (lo + hi + 1) >> 1;
    //   if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q))
    //     hi = mid - 1;
    //   else
    //     lo = mid;
    // }
    // lli maxHi = lo;

    // lo = -1e18, hi = 0;
    // while (lo < hi)
    // {
    //   lli mid = (lo + hi) >> 1;
    //   if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q))
    //     lo = mid + 1;
    //   else
    //     hi = mid;
    // }
    // lli minLo = lo;

    lli lo = -1e18, hi = 1e18;
    while (lo < hi)
    {
      lli mid = (lo + hi + isNegative) >> 1;
      lli e = remQ + p + (p + q)*(y0 + mid*(a / g));

      // DEBUG printf("\t\t%lld %lld\n", mid, e);
      if (isNegative)
      {
        if (e >= 0) lo = mid;
        else hi = mid - 1;
      }
      else
      {
        if (e >= 0) hi = mid;
        else lo = mid + 1;
      }
    }

    x0 -= lo * b / g;
    y0 += lo * a / g;

    // DEBUG printf("\t%lld %lld - %lld %lld | %lld %lld\n", remY, remQ, t1, t2, 0LL, b / g);
    return remQ + p + (p + q)*y0;
  }
  else
    return inf;
}

int main()
{
  int t; scanf("%d", &t);
  for (int tt = 1; tt <= t; tt++)
  {
    // scanf("%lld %lld %lld %lld", &x, &y, &p, &q);
    x = read();
    y = read();
    p = read();
    q = read();
    lli ans = inf;
    for (int i = 0; i < y; i++)
      for (int j = 0; j < q; j++)
        ans = min(ans, findMinSolution(i, j));

    if (ans == inf) printf("infinity\n");
    else
    {
      print(ans);
      printf("\n");
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   //半分全列挙
           int n;
           ll x;
           cin>>n>>x;
           vll w(n);
           rep(i,0,n)cin>>w[i];
           vll cnt_l,cnt_r;
           int l=n/2;
           int r=n-l;

           for(int bid=0;bid<(1<<l);bid++){
             ll sum=0;
             rep(i,0,l){
               if(bid & (1<<i))sum+=w[i];
             }
             cnt_l.pb(sum);
           }

           for(int bid=0;bid<(1<<r);bid++){
            ll sum=0;
             rep(i,0,r){
              if(bid & (1<<i))sum+=w[l+i];
             }
             cnt_r.pb(-sum);
           }
           sort(all(cnt_r));
           sort(all(cnt_l));
           ll ans=0;
           for(auto v:cnt_l){
               ll t=v;
             ll p=*lower_bound(cnt_r.begin(), cnt_r.end(), t-x);
             if(t-p>x)continue;
             chmax(ans,t-p);
           }
           cout<<ans<<endl;
}

//伟大的导师，伟大的领袖，伟大的统帅，伟大的舵手
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
char __buf[1<<20],*__p1,*__p2;
//#define getchar() (__p1==__p2?(__p2=__buf+fread(__p1=__buf,1,1<<20,stdin),__p1==__p2?EOF:*__p1++):*__p1++)
int read() {
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
const int maxn = 110, mod = 998244353;
int n,f[maxn][maxn*maxn],s,w[maxn],ans,pw[maxn];
signed main() {
	n=read(),f[0][0]=1;
	pw[0]=1;for(int i=1;i<=n;i++) pw[i]=1ll*pw[i-1]*i%mod;
	for(int i=1;i<=n;i++) s+=(w[i]=read());
	if(s&1) return cout<<0<<'\n',0;s/=2;
	for(int i=1;i<=n;i++)
		for(int j=i;j;j--)
			for(int k=s;k>=w[i];k--) f[j][k]=(f[j][k]+f[j-1][k-w[i]])%mod;
	for(int i=1;i<=n;i++) ans=(ans+1ll*pw[i]*pw[n-i]%mod*f[i][s])%mod;
	cout<<ans<<'\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
set<multiset<int>> s[111];
int dp[6333][6333];
int dfs(int n, int k) {
	if (!k) return 1;
	if (!n) return 0;
	n = min(n,k);
	int &ans = dp[n][k];
	if (~ans) return ans;
	return ans = (dfs(n-1,k)+dfs(2*n,k-n))%P;
}

int main() {
	memset(dp,-1,sizeof dp);
	int n, k;
	scanf("%d%d", &k, &n);
	printf("%d\n", dfs(n,k-n));
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

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

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

    ll rui[n], ruipow[n];
    ll a[n];
    rep(i, n){
        cin >> a[i];

        if(i){
            rui[i] = a[i] + rui[i-1];
            ruipow[i] = a[i]*a[i] + ruipow[i-1];
        }
        else {
            rui[i] = a[i];
            ruipow[i] = a[i] * a[i];
        }
    }

    ll ans = 0;
    rep1(i, n-1){
        ll c1 = i * a[i] * a[i];
        ll c2 = 2 * a[i] * rui[i-1];
        ll c3 = ruipow[i-1];

        // cout << rui[n-1] -  rui[i] << ", " << c3 << endl;

        ans += c1 - c2 + c3;
    }

    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1005;
char a[N][N];
int n,m;
vector<int>g[N*2];
bool vis[N*2];
void add(int u,int v){
        g[u].push_back(v);
        g[v].push_back(u);
}
void dfs(int u){
        vis[u]=1;
        for(auto v:g[u])if(!vis[v])dfs(v);
}
int main(){
        cin>>n>>m;
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
        add(1,n),add(1,n+1),add(1,n+m);
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]=='#')add(i,n+j);
        int ans=0;
        for(int i=1;i<=n;i++)if(!vis[i])dfs(i),ans++;
        ans--;
        memset(vis,0,sizeof(vis));
        int now=0;
        for(int i=n+1;i<=n+m;i++)if(!vis[i])dfs(i),now++;
        now--;
        cout<<min(ans,now)<<endl;
        return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 1000 + 5;
char grid[MAX][MAX], grid_cpy[MAX][MAX];
bool line_unblocked[MAX], column_unblocked[MAX];
int n, m;

void unblock(int x, int y);

void unblock_line(int x) {
    if (line_unblocked[x]) return;
    line_unblocked[x] = true;
    fori (i, 1, m + 1) {
        if (grid[x][i] == '#') unblock(x, i);
    }
}

void unblock_column(int y) {
    if (column_unblocked[y]) return;
    column_unblocked[y] = true;
    fori (i, 1, n + 1) {
        if (grid[i][y] == '#') unblock(i, y);
    }
}

void unblock(int x, int y) {
    unblock_line(x);
    unblock_column(y);
}

void solve() {
    cin >> n >> m;
    fori (i, 1, n + 1) fori (j, 1, m + 1) cin >> grid[i][j];

    grid[1][1] = grid[1][m] = grid[n][1] = grid[n][m] = '#';
    memcpy(grid_cpy, grid, sizeof(char) * MAX * MAX);

    int line_cost = 0;
    unblock(1, 1);
    fori (i, 1, n + 1) {
        if (!line_unblocked[i]) {
            grid[i][1] = '#';
            line_cost++;
            unblock(i, 1);
        }
    }

    memcpy(grid, grid_cpy, sizeof(char) * MAX * MAX);
    memset(line_unblocked, false, sizeof line_unblocked);
    memset(column_unblocked, false, sizeof column_unblocked);

    int column_cost = 0;
    unblock(1, 1);
    fori (i, 1, m + 1) {
        if (!column_unblocked[i]) {
            grid[1][i] = '#';
            column_cost++;
            unblock(1, i);
        }
    }

    cout << min(line_cost, column_cost) << endl;
}

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


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

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;

using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;

#define pb push_back
#define mp make_pair
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" <<endl;

inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

struct node {
    int col;
    vi ns;
};

vector<node> t;
unordered_set<int> seen; // seen colors
set<int> ans;

void dfs(int x, int parent)
{
    //debug(x);
    int c = t[x].col;
    bool is_new = seen.count(c) == 0;
    if (is_new) ans.emplace(x);
    seen.emplace(c);
    for (auto y: t[x].ns) {
        if (y != parent) dfs(y, x);
    }
    if (is_new)//
    seen.erase(c);
}

int main()
{
    int n = in_int();

    t.reserve(n);
    seen.reserve(n);

    rep(i, n) {
        int cc = in_int();
        t[i].col = cc;
    }

    rep(i, n-1) {
        int x = in_int()-1;
        int y = in_int()-1;
        t[x].ns.pb(y);
        t[y].ns.pb(x);
    }

    dfs(0, -1);

    for (auto it: ans) cout << it+1 << endl;

    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; }
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

const int INF = (1<<30)-1;
const long long LINF = 1LL<<60;
const double EPS = 1e-9;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int dx[8] = {-1,0,1,0,1,-1,1,-1};
const int dy[8] = {0,1,0,-1,1,-1,-1,1};

//-------------------------- Libraries --------------------------//

//--------------------------- Solver ----------------------------//

using Graph = vector<vector<int>>;

int N;
vector<int> C;
Graph g;
vector<int> ans;

void dfs(int v, int p, multiset<int> &se) {
    if (!se.count(C[v])) ans.push_back(v+1);
    se.insert(C[v]);
    for (auto &&u : g[v]) {
        if (u == p) continue;
        dfs(u, v, se);
    }
    se.erase(se.find(C[v]));
}

void solve() {
    cin >> N;
    C.resize(N);
    for (int i = 0; i < N; i++) cin >> C[i];
    g.resize(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    multiset<int> se;
    dfs(0, -1, se);
    sort(ans.begin(), ans.end());
    print(ans);
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 123;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	int ans = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans += max(0, x - 10);
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  998244353;
//const ll maxn = 1000000000;
//const ll mod = 1000000007;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
template <typename T>
void chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
  }
}
template <typename T>
void chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
  }
}

int main() {
    ll n;
    cin>>n;
    ll ans=0;
    vll a(n);
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(a[i]>10)ans+=a[i]-10;
    }
    cout<<ans<<endl;

}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdexcept>
#include<math.h>
using namespace std;

using ll=long long ;

#define rep(i,n)  for(int i=0;i<(n);i++)
#define f first
#define sc second

int fact(int n){
if(n==0){
     return 1;
 }else{
     return n*fact(n-1);
 }
}

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

template<class T>void chmin(T& a,T b){
    if(a>b){
        a=b;
    }
}

template<class T>void chmax(T& a,T b){
    if(a<b){
        a=b;
    }
}
int gcd(int x, int y) {
     if(x % y == 0) {
        return y;
     } else {
        return gcd(y, x % y);
     }
}

ll f(ll x,ll c,ll d){
    return x-x/c-x/d+x/(c/(gcd(c,d))*d);
}

string to_oct(int n){
    string s;
    while(n){
     s = std::to_string(n%8) + s;
     n /= 8;
    }
return s;
}

using namespace std;
int main(){
   ll n,m;
   cin>>n>>m;

   ll a[n];
   set<ll> d;
   rep(i,n+1)d.insert(i);

   ll mex=n;
   map<ll,int> mp;

   rep(i,n)cin>>a[i];

   rep(i,m){
       mp[a[i]]++;
       d.erase(a[i]);
   }

   mex=*begin(d);
   int j=0;

   for(int i=m; i<=n-1;i++){
       mp[a[i]]++;
       d.erase(a[i]);
       mp[a[j]]--;
       if(mp[a[j]]==0)d.insert(a[j]);
       mex=min<ll>(mex,*begin(d));
       j++;

   }

   cout << mex << endl;

}

// Problem: E - Mex Min
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_e
// Memory Limit: 1024 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// krishrawat

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define pb insert
#define eb emplace_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define show(x) cerr << #x << " is " << x << "\n"
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pp;
typedef vector<pp> vp;
typedef map<ll, ll> ii;
typedef set<ll> sl;
typedef multiset<ll> msl;
typedef set<pair<ll, ll>> sp;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 1;
ll mod_mul(ll x, ll y) { return ((x % MOD) * (y % MOD)) % MOD; }
ll mod_add(ll x, ll y) { return ((x % MOD) + (y % MOD)) % MOD; }

// main code
void solve() {
  ll n, m;
  cin >> n >> m;
  vl v(n);
  for (auto &i : v) cin >> i;
  sl s;
  for (int i = 0; i <= m; i++) s.pb(i);
  ll ans = 1e18;
  ii mp;
  for (int i = 0; i < m; i++) {
    auto it = s.find(v[i]);
    mp[v[i]]++;
    if (it != s.end()) s.erase(it);
  }
  auto it = s.lower_bound(0);
  ans = *it;
  for (int i = m; i < n; i++) {
    mp[v[i - m]]--;
    if (v[i - m] < m && !mp[v[i - m]]) s.pb(v[i - m]);
    it = s.find(v[i]);
    mp[v[i]]++;
    if (it != s.end()) s.erase(it);
    auto it = s.lower_bound(0);
    ans = min(ans, *it);
  }
  cout << ans << "\n";
}

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


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
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(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long S, long long P){
  for(ll i=1;i*i <= P; ++i){
    if(P%i==0){
      if(S==i+P/i){
        cout<<YES<<endl;
        return;
      }
    }
  }
  cout<<NO<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long S;
    scanf("%lld",&S);
    long long P;
    scanf("%lld",&P);
    solve(S, P);
    return 0;
}

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll i = 0LL; (i) < (ll)(n); (i)++)
#define rrep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rrrep(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
ll ri2[ohara], le2[ohara];

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

  cin >> n >> m;
  rep(i, n)cin >> a[i];
  rep(i, m)cin >> b[i];
  sort(a, a + n);
  rep(i, n){
          le2[i + 1] = a[i + 1] - a[i];
          i++;
  }
  rrrep(i, n - 1, 0){
          ri2[i - 1] = a[i] - a[i - 1];
          i--;
  }
  //p(i,n)Cout(le2[i]);
  rrep(i, 1, n)le2[i] += le2[i - 1];
  rrrep(i, n - 1, 0)ri2[i] += ri2[i + 1];

  ans = LINF;
  rep(i, m){
        ll le = 0, ri = n - 1, mid;
        ll idx_ = n;
        while(ri - le > 1){
                mid = (le + ri) / 2;
                if(b[i] < a[mid])ri = mid;
                else le = mid;
        }
        rrep(j, le, ri + 1){
                if(b[i] < a[j]){
                        idx_ = j;
                        break;
                }
        }
        if(idx_ % 2 == 1)idx_--;
        cnt = 0;
        if(idx_ >= 1)cnt = le2[idx_ - 1];
        cnt += ri2[idx_ + 1];
        cnt += abs(b[i] - a[idx_]);
        //Cout(cnt);
        ans = min(ans, cnt);
  }
  Cout(ans);
  return 0;
}


#define ll long long
#define lld double
#define M 202
#define f first
#define s second
#define pi 3.141592653589793238
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define N 100002
#define Endl endl
#define maxx(a,b,c,d) max(max(a,b),max(d,c))
#define minn(a,b,c,d) min(min(a,b),min(d,c))
#define pb push_back
#define mod 1000000007
#define pp 31
#define ss(v) sort(v.begin(),v.end())
#define sr(v) sort(v.begin(),v.end(),greater<pll>())
#define rin(A, B, C) (((A)<=(B))&&((B)<=(C)))
#include <bits/stdc++.h>
using namespace std;
ll power(ll a, ll b)
{
	if(!b)return 1LL;
	ll aa=power(a,b/2);
	if(b%2)return aa*aa%mod*a%mod;
	return aa*aa%mod;
}
ll im(ll a)
{
	return power(a,mod-2);
}
// ll ncr(ll n,ll r)
// {
// 	return f[n]*im(f[r])%mod*im(f[n-r])%mod;
// }
bool check(ll n)
{
	ll m=n;
	while(n)
	{
		if(n%10!=0 && m%(n%10)!=0)
		{
			return false;
		}
		n/=10;
	}
	return true;
}
pll ol(ll a, ll b, ll c, ll d)
{
	a=max(a,c);
	b=min(b,d);
	return {a,b};
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// freopen("output.txt", "w", stdout);
	// freopen("input.txt", "r", stdin);
    ll a,b;
	cin>>a>>b;
	ll ans1=0,ans2=0;
	while(a)
	{
		ans1+=a%10;
		a/=10;
	}
	while(b)
	{
		ans2+=b%10;
		b/=10;
	}
	cout<<max(ans1,ans2)<<endl;

	return 0;
}

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

using namespace std;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
constexpr int MOD = 998244353;
using mint = ModInt< MOD >;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());

  mint ans = 0;
  mint sum = 0, base = 1;
  for(int i = 0; i < n; i++){
    sum += base * a[i];
    base *= 2;
  }

  mint inv2 = mint(2).inverse();

  for(int i = 0; i < n; i++){
    ans += mint(a[i]) * a[i];
    sum -= a[i];
    sum *= inv2;
    ans += sum * a[i];
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
const int INF = (int)1e9;
const ll INFL = (ll)1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
int dx[]={0, 0, -1, 1};
int dy[]={1, -1, 0, 0};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (c % 2 == 0)
	{
		a = abs(a);
		b = abs(b);
	}
	if (a > b)
		cout << '>' << endl;
	else if (a < b)
		cout << '<' << endl;
	else
		cout << '=' << endl;
	return 0;
}

/*WELCOME TO AYUSH RANJAN CODE'S*/

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl "\n"
#define IOS std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define loop(i,a,b) for(int i=(a);i<(b);i++)
#define rloop(i,a,b) for(int i=(a);i>(b);i--)
#define ft first
#define sd second

using namespace std;

const ll mod = 1e9+7;
const ll INF = 1e18;
const ll MAX = 1e6+1;

bool check_prime(ll n)
{
    ll i;
    if(n<=1)
    {
        return false;
    }
    if(n==2)
    {
        return true;
    }
    if(n%2==0)
    {
        return false;
    }
    ll sn=sqrt(n);
    for(i=3;i<=sn;i++){
        if(n%i==0)
        {
            return false;
        }
    }
    return true;
}
vector<bool> seive(ll n)
{
    ll i,j;
    vector<bool> prime(n+1);
    for(i=0;i<=n;i++)
    {
        prime[i]=true;
    }
    prime[0]=false;
    prime[1]=false;
    ll sn=sqrt(n);
    for(i=2;i<=sn;i++)
    {
        if(prime[i])
        {
            for(j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }

    }
    return prime;
}
ll GCD(ll a,ll b)
{
    if(b==0)
    {
        return a;
    }
    return GCD(b,a%b);
}
vector<ll> primeFactors(ll n)
{
    vector<ll> v;
    while (n%2 == 0)
    {
        v.push_back(2);
        n = n/2;

    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            v.push_back(i);
            n = n/i;
        }
    }
    v.push_back(n);
    return v;
    }
}
ll factorial[1000001];
void fact()
{
    factorial[0]=1;
    for(int i = 1; i <= 1000000; i++)
        factorial[i] = factorial[i - 1] * i % mod;
}
ll power(ll x, unsigned ll y, unsigned ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, mod) % mod;
    p = (p * p) % mod;
    return (y%2 == 0)? p : (x * p) % mod;
}
ll inverse(ll a)
{
    return power(a, mod-2, mod);
}
long long binomial_coefficient(ll n, ll k)
{
    return factorial[n] * inverse(factorial[k]) % mod * inverse(factorial[n - k]) % mod;
}
void solve()
{
    ll i,j,k,n,m,d,l,r,y,x,z,b,c,s;
    cin>>n>>s>>d;
    ll a[n][2];
    for(i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1];
    }
    ll ans=0;
    for(i=0;i<n;i++){
        if(a[i][0]<s&&a[i][1]>d){
            cout<<"Yes";

            return;
        }

    }
    cout<<"No";
    return;
}

int main()
{
   // IOS;
    int t;
    t=1;//cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> results;
string res, a, b, c;
vector<bool> used(10, 0);

bool found = 0;

long long getNum(string a)
{
    long long num = 0;
    for(int i = 0; i < a.size(); ++i)
    {
        // find where it is in res;
        num = num * 10 + results[res.find(a[i])];
    }
    return num;
}

void dp(int depth)
{
    if(found) return;
    else if(depth == results.size())
    {
        // try and check
        long long d = getNum(a), e = getNum(b), f = getNum(c);
        if(d + e == f && d > 0 && e > 0 && f > 0)
        {
            found = 1;
            cout << d << endl << e << endl << f << endl;
        }
        return;
    }
    for(int i = 0; i < 10; ++i)
    {

        if(!used[i] && (i != 0 || (res[depth] != a[0] && res[depth] != b[0]  && res[depth] != c[0])))
        {
            results[depth] = i;
            used[i] = 1;
            dp(depth + 1);
            used[i] = 0;
        }
    }
}

int main()
{
    cin >> a >> b >> c;
    res = a + b + c;
    sort(res.begin(), res.end());
    res.resize(distance(res.begin(), unique(res.begin(), res.end())));
    if(res.size() > 10)
    {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    results = vector<int>(res.size());
    // dp results
    dp(0);
    if(!found)
        cout << "UNSOLVABLE" << endl;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m,q,usx=0,usy=200001;
long long getint()
{
	char ch;do	{ch=getchar();}while (ch!='-'&&(ch<'0'||ch>'9'));
	long long ans=0,f=0;if (ch=='-') f=1; else ans=ch-'0';
	while (isdigit(ch=getchar())) ans=ans*10+ch-'0';
	if (f) ans*=-1;
	return ans;
}
long long tr[200001];
bool vis[200001];
int lowbit(int x)
{
	return x&-x;
}
void add(int x)
{
	while(x<=n)
	{
		tr[x]+=1;
		x+=lowbit(x);
	}
	return ;
}
long long query(int x)
{
	long long ans=0;
	while(x)
	{
		ans+=tr[x];
		x-=lowbit(x);
	}
	return ans;
}
struct Q
{
	int x,y;
	void in()
	{
		x=n-getint()+1;
		y=getint();
		if(x==n)usy=usy<y? usy:y;
		if(y==1)usx=usx>x? usx:x;
	}
}nod[600011];
bool cmp(const Q& x,const Q& y)
{
	return x.y==y.y? x.x<y.x:x.y<y.y;
}
int main()
{
	n=getint();m=getint();q=getint();
	for(int i=1;i<=q;i++)
	  nod[i].in();
	for(int i=1;i<usx;i++)
	{
		nod[++q].x=i;
		nod[q].y=1;
	}
	for(int i=usy+1;i<=m;i++)
	{
		nod[++q].x=n;
		nod[q].y=i;
	}
	sort(nod+1,nod+q+1,cmp);
	long long ans=0;
	for(int i=1;i<=q;i++)
	{
		if(!vis[nod[i].x])
		{
			vis[nod[i].x]=true;
			add(nod[i].x);
		}
		if(nod[i].y!=nod[i+1].y)
		  ans+=query(nod[i].x);
	}
	cout<<n*m-ans;
 }


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};

int A[55][55];
const ll mod = 998244353;
int main() {
  int n,m;
  cin >> n >> m;
  rep(i,n) rep(j,n)cin >> A[i][j];
  UnionFind R(n),C(n);

  rep(i,n){
    rep(j,n){
      bool ok1 = true, ok2 = true;
      rep(k,n){
        ok1&=(A[i][k]+A[j][k]<=m);
        ok2&=(A[k][i]+A[k][j]<=m);
      }
      if(ok1)R.unite(i,j);
      if(ok2)C.unite(i,j);
    }
  }
  ll a = 1,b = 1;
  for(auto v:R.data){
    if(v<0){
      ll x = -v,tmp = 1;
      while(x>=1){
        tmp*=x;
        tmp%=mod;
        x--;
      }
      a*=tmp;
      a%=mod;
    }
  }
  for(auto v:C.data){
    if(v<0){
      ll x = -v,tmp = 1;
      while(x>=1){
        tmp*=x;
        tmp%=mod;
        x--;
      }
      b*=tmp;
      b%=mod;
    }
  }
  ll ans = (a*b)%mod;
  cout<<ans<<endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

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

template <class Tuple, std::size_t... Is>
void tuple_out(std::ostream& os, const Tuple& tp, std::index_sequence<Is...>) {
    ((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ')';
}

template <class... Args>
std::ostream& operator<<(std::ostream& os, const std::tuple<Args...>& tp) {
    tuple_out(os, tp, std::index_sequence_for<Args...>{});
    return os;
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
    int n = 0;
    for(auto e : vec)   os << (n++ ? ", " : "(") << e;
    return os << (n ? ")" : "{}");
}

template <class T, class Compare>
std::ostream& operator<<(std::ostream& os, const std::set<T, Compare>& st) {
    int n = 0;
    for(auto e : st)    os << (n++ ? ", " : "(") << e;
    return os << (n ? ")" : "{}");
}

template<class T, class U, class Compare>
std::ostream& operator<<(std::ostream& os, const std::map<T, U, Compare>& mp) {
    int n = 0;
    for(auto e : mp)    os << (n++ ? ", " : "(") << e;
    return os << (n ? ")" : "{}");
}

#ifdef LOCAL
#define debug(...) std::cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

void debug_out() { std::cout << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
    std::cout << head;
    if(sizeof...(Tail) != 0)    std::cout << ", ";
    debug_out(std::forward<Tail>(tail)...);
}

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, T;
    cin >> N >> T;
    vector<ll> A(N);
    for(int i = 0; i < N; ++i)  cin >> A[i];
    vector<ll> dat(1, 0LL);
    int M = N / 2;
    for(int mask = 0; mask < 1 << M; ++mask){
        ll sum = 0;
        for(int i = 0; i < M; ++i){
            if(mask >> i & 1)   sum += A[i];
        }
        // cout << sum << ' ';
        if(sum <= T)    dat.emplace_back(sum);
    }
    // cout << '\n';
    sort(dat.begin(), dat.end());
    dat.erase(unique(dat.begin(), dat.end()), dat.end());
    // for(auto x : dat)   cout << x << ' ';
    // cout << '\n';
    ll ans = 0;
    //cout << N - M << '\n';
    for(int mask = 0; mask < (1 << (N - M)); ++mask){
        //cout << mask << ' ';
        ll sum = 0;
        for(int i = 0; i < N - M; ++i){
            //if(mask >> i & 1)   cout << i << '\n';
            if(mask >> i & 1)   sum += A[M + i];
        }
        //cout << sum << ' ';
        if(sum > T) continue;
        auto it = upper_bound(dat.begin(), dat.end(), T - sum);
        it = prev(it);
        chmax(ans, sum + *it);
    }
    //cout << '\n';
    cout << ans << endl;
}


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

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

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

const ll INF = 1LL << 60;

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

const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    int K;
    cin >> K;
    vector<int> C(K), D(K);
    REP(i, K) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << K); bit++) {
        vector<int> cnt(N);
        REP(i, K) {
            if (bit & (1 << i))
                cnt[C[i]]++;
            else
                cnt[D[i]]++;
        }
        int s = 0;
        REP(i, M) {
            if (cnt[A[i]] >= 1 && cnt[B[i]] >= 1)
                s++;
        }
        chmax(ans, s);
    }
    cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <limits.h>
#include <stdio.h>
using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    int a[m], b[m];
    std::vector<int> v;
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
    }
    int k;
    cin >> k;
    int c[k], d[k];

    for(int i=0; i<k; i++){
        cin >> c[i] >> d[i];
    }

    long long int ans = 0;
    for(long long int i=0; i<pow(2.0, k); i++){
        std::map<int, int> mp;
        std::bitset<16> bs(i);
        for(long long int j=0; j<k; j++){
            if(bs[j]==0){
                mp[c[j]]++;
            }else{
                mp[d[j]]++;
            }
        }
        long long int cnt = 0;
        for(long long int j=0; j<m; j++){
            if(mp[a[j]]>0 && mp[b[j]]>0){
                cnt++;
            }
        }
        if(ans < cnt) ans = cnt;
    }
    cout << ans << endl;

    return 0;
}


#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

void solveD() {
    int N;
    cin >> N;
    vll a(N);
    rep(i, N) cin >> a[i];

    if (N % 2 == 1) {
        cout << "Second" << endl;
        return;
    }
    map<ll, int> num;
    rep(i, N) {
        num[a[i]]++;
    }
    for(auto n : num){
        if (n.second  %2 != 0) {
            cout << "First" << endl;
            return;
        }
    }
    cout << "Second" << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin >> T;
    rep(t, T) {
        solveD();
    }
    /*ll ans = 0;
    cout << ans << endl;*/
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#define LL long long
#define LD long double
#define MAXN 100005
#define MAXM
#define P
#define INF 0x3f3f3f3f
using namespace std;

int t, n, a[MAXN];

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(int i=1; i<=n; ++i) scanf("%d", &a[i]);
        if(n%2) printf("Second\n");
        else
        {
            int tag=0;
            sort(a+1, a+n+1);
            for(int i=1, cnt=0; i<=n; ++i)
            {
                if(a[i]!=a[i-1] && cnt%2) tag=1;
                cnt++;
            }
            if(tag) printf("First\n");
            else printf("Second\n");
        }
    }
    return 0;
}