#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vl;
typedef vector<pii> vpii; typedef vector<pll> vpll;
#define FOR(n) for(int i=0;i<n;++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; }
const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f;
ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; }
int n;
ll a[212345];
ll b[212345];
ll c[212345];
signed main() {
	cin >> n;
	FOR(n)cin >> a[i];
	b[0] = a[0];
	for (int i = 1; i < n; ++i)b[i] = b[i - 1] + a[i];
	c[0] = max(0ll, b[0]);
	for (int i = 1; i < n; ++i)c[i] = max(c[i - 1], b[i]);
	/*FOR(n)cout << a[i] << " "; cout << endl;
	FOR(n)cout << b[i] << " "; cout << endl;
	FOR(n)cout << c[i] << " "; cout << endl;*/
	ll mx = 0, ans = 0;
	FOR(n) {
		mx = max(ans + c[i], mx);
		ans += b[i];
	}
	mx = max(mx, ans);
	cout << mx << endl;
	return 0;
}

//Iamskk//
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define endl '\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define countsetbits(x) __builtin_popcount(x)
#define ll long long
#define debug cout<<"I AM EXECUTING"<<endl
#define testcases int asdf; cin>>asdf; while(asdf--)
#define vi vector<int>
#define si set<int>
#define vc vector<char>
#define sc set<char>
#define vll vector<long long int>
#define vs vector<string>
#define vpp vector<pair<int,int>>
#define vppo(prs) for(auto x:prs){cout<<x.first<<" "<<x.second<<endl;}
#define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)

string sconvert(ll int n)
{
	stringstream ss;
	ss<<n;
	string str = ss.str();
	return str;
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second > b.second);
}

void  single()
{
	ll int n;
	cin>>n;
	vector<ll int> arr(n);
	ai(arr,n);
	vector<ll int> mtn(n,0);
	ll int sum=arr[0];
	mtn[0] = max(mtn[0],sum);
	For(i,1,n){
        sum+=arr[i];
        if(sum>mtn[i-1]){
        	mtn[i]=sum;
        }
        else{
        	mtn[i]=mtn[i-1];
        }
	}
	ll int answer = 0;
	sum=0;
	ll int lp = 0;
	For(i,0,n){
       sum+=arr[i];
       answer = max(answer,lp+mtn[i]);
       lp=lp+sum;
	}
	cout<<answer<<endl;
	return;
}
void multiple()
{
	testcases
    {
		single();
	}
}

int main()
{
  IOS;
 // freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  single();
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

int main() {
    char s[10];
    scanf("%s", s);
    putchar(s[1]);
    putchar(s[2]);
    putchar(s[0]);
	return 0;
}

// Problem : A - 106
// Contest : AtCoder - AtCoder Regular Contest 106
// URL : https://atcoder.jp/contests/arc106/tasks/arc106_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

long long N;
long long mypow(long long a, long long b){
	long long ret = 1;
	while(b--){
		ret *= a;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(long long i = 1; i<40; i++){
		for(long long j = 1; mypow(3, i) + mypow(5, j) <= N; j++){
			if(mypow(3, i) + mypow(5, j) == N){
				cout << i << " " << j << "\n";
				return 0;
			}
		}
	}
	cout << -1;
}


#include <cstdio>
#include <cstring>
#define int long long
const int N = 200005, M = 2*N, p = 1000000007;
int num, head[N], next[M], vet[M], len[M], n, x, y, z, ans, dis[N], cnt[2];
void add(int u, int v, int c) {
    vet[++num] = v, len[num] = c;
    next[num] = head[u];
    head[u] = num;
}
int Pow(int a, int b) {
    int an = 1;
    while(b) {
        if(b & 1) an = an * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return an;
}
void dfs(int u, int fa, int d) {
    dis[u] = d;
    for(int i = head[u]; i; i = next[i]) {
        int v = vet[i];
        if(v == fa) continue;
        dfs(v, u, d ^ len[i]);
    }
}
signed main() {
    scanf("%lld", &n);
    for(int i = 2; i <= n; i++) {
        scanf("%lld%lld%lld", &x, &y, &z);
        add(x, y, z), add(y, x, z);
    }
    dfs(1, 0, 0);
    for(int i = 0; i < 60; i++) {
        cnt[0] = cnt[1] = 0;
        for(int j = 1; j <= n; j++) cnt[(dis[j] >> i) & 1] ++;
        ans = (ans + Pow(2, i) * cnt[0] % p * cnt[1] % p) % p;
    }
    printf("%lld", ans);
    return 0;
}

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

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

using namespace std;

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

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

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

template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const { return pow(MOD-2); }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }

    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;

int N;
int X[200011];
int Y[200011];
LL W[200011];
VI G[200011];

int par[200011];
LL dp[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	LL w;
	scanf("%d%d%lld", &x, &y, &w);
	x--;
	y--;
	G[x].push_back(i);
	G[y].push_back(i);
	X[i] = x;
	Y[i] = y;
	W[i] = w;
    }

    VI que;
    que.push_back(0);
    REP (i, N) {
	int v = que[i];
	EACH (e, G[v]) {
	    int w = v ^ X[*e] ^ Y[*e];
	    if (w == par[v]) continue;

	    dp[w] = dp[v] ^ W[*e];
	    par[w] = v;
	    que.push_back(w);
	}
    }

    Mint ans = 0;
    for (int t=60; t--;) {
	LL a = 0;
	REP (i, N) if (dp[i]>>t&1) a++;
	LL b = N - a;

	ans *= 2;
	ans += a * b;
    }

    printf("%d\n", ans.geti());
}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<typename T>
std::ostream & operator<<(std::ostream & Str, vector<T> const & vec) {
    Str << "[";
    for (int i = 0; i < vec.size(); ++i) {
        if (i != 0) cout << ", ";
        cout << vec.at(i);
    }
    Str << "]";
    return Str;
}

void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    ll ans = 0;
    vector<ll> map(200000, 0);
    rep(j, N) {
        map.at(B.at(C.at(j) - 1)) += 1;
    }
    rep(i, N) {
        ans += map.at(A.at(i));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    std::scanf("%lld", &N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &B[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}

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

#define ll long long
#define vl vector<ll>
#define ml map<ll,ll>
#define sl set<ll>
#define vp vector< pair <int,int> >
#define pb push_back

#define asort sort(a,a+n)
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(),v.end())

#define F first
#define S second
#define mod 1000000007

#define mit map<ll,ll>::iterator
#define for0(j,n) for(ll i=j;i<n;i++)
#define for1(j,n) for(ll i=j;i<=n;++i)
#define MA LLONG_MAX
#define MI LLONG_MIN

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

long modInverse(long long n)
{
    return power(n, mod - 2);
}
long long fac[200001];

long long ncr(long long n, ll r)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;
    long long fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % mod;

    return (fac[n] * modInverse(fac[r]) % mod*modInverse(fac[n - r])% mod)% mod;
}
vector<ll> prime;

void sieve()
{
          vector<bool> primes(10000000000000,true);
          primes[0]=primes[1]=false;
          for(int i=2;i<10000000000000;++i)
           {
                     if(primes[i])
                      {
                                for(int j=i*i;j<10000000000000;j+=i)
                                  primes[j]=false;
                      }
           }
           for(int i=0;i<10000000000000;++i)
             if(primes[i])
             prime.pb(i);

}
sl factorization;
void trial_division3(long long n) {

    for (int d : {2, 3, 5}) {
        while (n % d == 0) {
            factorization.insert(d);
            n /= d;
        }
    }
    static array<int, 8> increments = {4, 2, 4, 2, 4, 6, 2, 6};
    int i = 0;
    for (long long d = 7; d * d <= n; d += increments[i++]) {
        while (n % d == 0) {
            factorization.insert(d);
            n /= d;
        }
        if (i == 8)
            i = 0;
    }
    if (n > 1)
        factorization.insert(n);
  }

 void solve()
  {
      ll n;string s;
    cin>>n;
 sl p;
   for(ll i=1;i*i<=n;++i)
   {
             if(n%i==0)
              {
                        p.insert(i);p.insert(n/i);
              }

   }
   for(auto it=p.begin();it!=p.end();++it)
     cout<<*it<<endl;

  }

int main()
{
    ll t=1;
     fac[0] = 1;
    for (int i = 1; i <= 200000; i++)
        fac[i] = (fac[i - 1] * i) % mod;
   // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}


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

const int MAX = 1e6;

int cnt[MAX+4];
bool isSqr[MAX+4];

using pii = pair<int,int>;

long long coprimes(int l, int r){
    //[l,r]에서 x<y인 서로소 쌍의 수
    //전체에서 k로 동시에 나눠떨어지는걸로 포함배제하면 된다
    long long result = 1LL * (r-l+1) * (r-l) / 2;
    for(int i=2;i<=r;i++)if(!isSqr[i]){
        long long tmp = r/i - (l-1)/i;
        if(cnt[i]&1) result -= tmp*(tmp-1)/2;
        else result += tmp*(tmp-1)/2;
    }
    return result;
}

int main(){
    for(int i=2;i<=MAX;i++)if(cnt[i] == 0){
        for(int j=i;j<=MAX;j+=i) cnt[j]++;
        if(1LL*i*i<=MAX) for(int j=i*i;j<=MAX;j+=i*i) isSqr[j] = 1;
    }
    int L, R;
    scanf("%d%d",&L,&R);
    long long ans = 1LL*(R-L+1)*(R-L)/2;
    ans -= coprimes(L,R);
    for(int i=max(2,L);i<=R;i++) ans -= R/i-1;
    printf("%lld\n", ans*2);
    return 0;
}

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> p(H+1,vector<int>(W+1));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      char a;
      cin>>a;
      if(a=='.'){
        p[i][j]++;
      }
    }
  }
  int Z=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(p[i][j]){
        Z+=(p[i][j+1]+p[i+1][j]);
      }
    }
  }
  cout<<Z<<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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

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

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
	string s;
	cin >> s;
	deque<char> dq;
	int dir = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'R')
		{
			dir = 1 - dir;
			continue;
		}
		if (dir == 1)
		{
			dq.push_back(s[i]);
		}
		else
		{
			dq.push_front(s[i]);
		}
	}
	vector<char> final;
	while(dq.empty() == false)
	{
		final.pb(dq.back());
		dq.pop_back();
	}
	if (dir == 1)
	{
		reverse(all(final));
	}
	stack<char> sc;
	if (sz(final) == 0)
	{
	    cout <<"";
	    return 0;
	}
	/*for (auto x : final)
	{
	    cout << x;
	}*/
	sc.push(final[0]);
	for (int i = 1; i < sz(final); i++)
	{
		if (sc.empty() == true)
		{
			sc.push(final[i]);
		}
		else
		{
			if (sc.top() != final[i])
			{
			    sc.push(final[i]);
			}
			else
			{
			    bool flag = false;
			    while(sc.empty() == false && i < sz(final) && sc.top() == final[i])
			    {
			        sc.pop(); i++; flag = true;
			    }
			    if (flag == true)
			    {
			        i--;
			    }
			}
		}
	}
	stack<char> pp;
	while(!sc.empty())
	{
	    pp.push(sc.top());
	    sc.pop();
	}
	while(!pp.empty())
	{
	    cout << pp.top(); pp.pop();
	}
}

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

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

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

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

struct T {
  int d, x, y;
  T(int d, int x, int y): d(d), x(x), y(y) {}

  bool operator < (const T &a) const {
    return d > a.d;
  }
};

signed main() {
  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  int sx, sy, gx, gy;

  vector<vector<pair<int, int>>> v(26);

  REP(i, H) REP(j, W){
    if(s[i][j] == '.' || s[i][j] == '#') continue;
    if(s[i][j] == 'S'){
      sx = i; sy = j;
    }else if(s[i][j] == 'G'){
      gx = i; gy = j;
    }else{
      v[s[i][j]-'a'].emplace_back(i, j);
    }
  }

  priority_queue<T> q;
  q.emplace(0, sx, sy);

  vector<vector<int>> dist(H, vector<int>(W, INF));
  dist[sx][sy] = 0;

  while(!q.empty()){
    auto p = q.top(); q.pop();

    int d = p.d;
    int x = p.x;
    int y = p.y;

    if(dist[x][y] != d) continue;
    if(x == gx && y == gy) break;

    REP(i, 4){
      int nx = x+dx[i];
      int ny = y+dy[i];

      if(OUT(0, nx, H) || OUT(0, ny, W)) continue;
      if(s[nx][ny] == '#') continue;

      if(chmin(dist[nx][ny], dist[x][y]+1)){
        q.emplace(dist[nx][ny], nx, ny);
      }
    }

    vector<int> A, B;
    if('a' <= s[x][y] && s[x][y] <= 'z'){
      for(auto [nx, ny] : v[s[x][y]-'a']){
        if(chmin(dist[nx][ny], dist[x][y]+1)){
          q.emplace(dist[nx][ny], nx, ny);
          A.emplace_back(nx);
          B.emplace_back(ny);
        }
      }
    }

    if(A.size() > 0){
      REP(i, A.size()){
        s[A[i]][B[i]] = '.';
      }
      s[x][y] = '.';
    }
  }

  int ans = dist[gx][gy];
  if(ans == INF) ans = -1;

  cout << ans << "\n";

  return 0;
}


#pragma GCC optimize "trapv"
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define sz(s) (int)(s.size())
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define deb(x) cout << #x << " = " << x << endl
#define endl '\n'
#define M 1000000007
const int INF = 1ll << 60;

using namespace std;

// set<pair<int, int>> st;
vector<int> v[2001];
bool vis[2001];

void dfs(int ind, int &cnt) {

	vis[ind] = 1;
	for (auto x : v[ind]) {
		if (!vis[x]) {
			// st.insert({ind, x});
			cnt++;
			dfs(x, cnt);
		}
	}
}

void solve() {
	int n, m;
	cin >> n >> m;
	int a, b;
	while (m--) {
		cin >> a >> b;
		v[a].pb(b);
	}

	int ans = n;
	for (int i = 1; i <= n; ++i) {
		memset(vis, 0, sizeof(vis));
		int cnt = 0;
		dfs(i, cnt);
		ans += cnt;
	}

	cout << ans << endl;
}

signed main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

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

#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 ld long double
#define ll long long
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
// SOME BITMASK KNOWLEDGE
// 1)x & (x - 1):sets the last one bit of x to zero
// power of two exactly when x & (x − 1) = 0.
// 2)x & -x:sets all the one bits to zero, except last one bit
// 3)x | (x - 1):inverts all the bits after the last one bit
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);

vector<ll> dp,possible;

ll memo(ll mask,ll n){
	if(dp[mask] != -1){
		return dp[mask];
	}
	ll ct = 0;
	REP(i,0,n){
        if((mask >> i) & 1) ct++;
    }
	dp[mask] = ct;
	for(ll s = mask; s > 0; s = (s - 1) & mask){
		if(possible[s]){
			dp[mask] = min(dp[mask],1 + memo((mask^s),n));
		}
    }
    return dp[mask];
}

int main()
{
	i_os;
	ll n,m;
	cin>>n>>m;
	set<ll> edges[n];
	REP(i,0,m){
		ll x,y;
		cin>>x>>y;
		x--; y--;
		edges[x].insert(y);
		edges[y].insert(x);
	}
	dp.resize((1 << n),-1);
	possible.resize((1 << n),0);
	possible[0] = 1;
	dp[0] = 0;
	REP(i,1,(1 << n)){
		vector<ll> v;
		REP(j,0,n){
			if((i >> j) & 1) v.push_back(j);
		}
		bool f = 0;
		REP(j,0,v.size()){
			REP(k,j+1,v.size()){
				auto it = edges[v[j]].find(v[k]);
				if(j != k && it == edges[v[j]].end()){
					f = 1;
					break;
				}
			}
			if(f) break;
		}
		if(f) possible[i] = 0;
		else possible[i] = 1;
	}
	cout<<memo((1 << n) - 1,n)<<endl;
	return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint h,w;cin >> h>>w;
    vector<string> s(h);
    REP(i,h){
        cin >> s[i];
    }
    vector<int> dx{1, 1, 0, 0}, dy{0, 1, 1, 0};
    lint ans = 0;
    REP(i,h-1)REP(j,w-1){
        lint cnt = 0;
        REP(k,4){
            if (s[i+dx[k]][j+dy[k]] == '#')
                cnt++;
        }
        if (cnt == 1||cnt==3){
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

#include<bits/stdc++.h>
#define re register
#define N 2001001
#define MAX 2001
using namespace std;
typedef long long ll;
typedef double db;
const ll mod=998244353;
inline void read(re ll &ret)
{
	ret=0;re char c=getchar();re bool pd=false;
	while(!isdigit(c)){pd|=c=='-';c=getchar();}
	while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c&15);c=getchar();}
	ret=pd?-ret:ret;
	return;
}
ll n,w,x[N],y[N],z[N],a[N];
signed main()
{
	read(n);
	read(w);
	for(re int i=1;i<=n;i++)
	{
		read(x[i]);
		read(y[i]);
		read(z[i]);
		a[x[i]]+=z[i];
		a[y[i]]-=z[i];
	}
	for(re int i=1;i<=200000;i++)
		a[i]+=a[i-1];
	for(re int i=0;i<=200000;i++)
	{
		if(a[i]>w)
		{
			puts("No");
			exit(0);
		}
	}
	puts("Yes");
	exit(0);
}


#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	string s;
	cin >> s;
	ll ans = 0;
	rep(i,9){
		if(s.substr(i,4)=="ZONe")ans++;
	}
	cout << ans << endl;

	return 0;
}

// Problem: C - ORXOR
// Contest: AtCoder - AtCoder Beginner Contest 197（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc197/tasks/abc197_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#define rep(i, n) for(int i = 1;i <= n;++i)
#define Rep(i, n) for(int i = n;i >= 1;--i)
#define forr(i,m,n) for(int i = m;i <= n;++i)
#define debug cout << "---------------------------\n";
#define endl '\n'
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define YES "YES"
#define NO "NO"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
const int maxn = 1e6 + 100;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;

// -------------- 板子 -----------------------------

int n;
ll a[30],ans = 1e18;

void dfs(int id,ll p) {
	// cout << id << ' ' << p << endl;
	if(id == n + 1) {
		ans = min(ans,p);
		return ;
	}
	ll cnt = 0;
	for(int i = id;i <= n;++i) {
		cnt |= a[i];
		dfs(i + 1,cnt ^ p);
	}
}

int main() {
	IO
	cin >> n;
	for(int i = 1;i <= n;++i) cin >>a[i];
	dfs(1,0);
	// ll cnt = 0;
	// for(int i = 1;i <= n;++i) {
		// cnt |= a[i];
		// dfs(i+1,cnt);
		// cout << i << " " << cnt << ' ' << ans << endl;
	// }
	cout << ans <<endl;
	return 0;
}


/*Jai Shree Ram*/
// Never Give Up
#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define mt19937                 rng(chrono::steady_clock::now().tjhe_since_epoch().count());
//shuffle(arr,arr+n,rng)
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
mii m;
pii child[200001];
int t = 1;
int BIT[200001];
void update(int i,int n,int inc)
{

  while(i<=n)
  {
    BIT[i] += inc;
    i += (i & (-i));
  }
}
int query(int i)
{
  int ans = 0;
  while(i>0)
  {
      ans += BIT[i];
      i -= (i&(-i));
  }
  return ans;
}
void updateRange(int l,int r,int inc,int n)
{
  if(l>r)
    return;
  update(l,n,inc);
  update(r+1,n,-inc);
}
class graph
{
  int V;
  list<int>* l;
public:
  graph(int V)
  {
    this->V = V;
    l = new list<int>[V+1];
  }
  void addEdge(int x,int y)
  {
    l[x].pb(y);
    l[y].pb(x);
  }
  void dfs(int src,int par)
  {
     m[src] = t;
     child[m[src]].ff = t;
      t++;
     for(int nbr:l[src])
     {
      if(nbr!=par)
      {
        dfs(nbr,src);
      }
     }
     child[m[src]].ss = t-1;
  }
};
int32_t main()
{   c_p_c();
  memset(BIT,0,sizeof(BIT));
    int n;
    cin>>n;
    graph g(n+1);
    vector<pii> edges;
    for(int i=0;i<n-1;i++)
    {
      int a,b;
      cin>>a>>b;
      g.addEdge(a,b);
      edges.pb(mp(a,b));

    }
    g.dfs(1,-1);

    w(q)
    {
      int t;
      cin>>t;
      int idx,inc;
      cin>>idx>>inc;
      idx--;
      int b = max(m[edges[idx].ff],m[edges[idx].ss]);

      if((t==1&& m[edges[idx].ss]==b)||(t==2 && m[edges[idx].ff]==b))
      {
         updateRange(1,child[b].ff-1,inc,n);
         updateRange(child[b].ss+1,n,inc,n);
      }
      else
      {
         updateRange(child[b].ff,child[b].ss,inc,n);
      }
    }
    for(int i=1;i<=n;i++)
      cout<<query(m[i])<<endl;
}

#include <bits/stdc++.h>

using namespace std;

// Templates here
template<typename T1, typename T2, typename T3>
class triple {
public:
    T1 first;
    T2 second;
    T3 third;

    triple() {
        first = 0;
        second = 0;
        third = 0;
    }
};

// Typedefs here
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set<int> si;
typedef set<ll> sl;
typedef set<pii> spii;
typedef set<pll> spll;
typedef map<string, int> mpsi;
typedef map<string, ll> mpsl;
typedef map<int, int> mpii;
typedef map<ll, ll> mpll;

// Defines here
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fora(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define forla(i, a, b) for(ll (i)=(a);(i)<(b);(i)++)
#define for0(i, b) fora((i),0,(b))
#define forl0(i, b) forla((i),0,(b))
#define rofa(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define rofla(i, a, b) for(ll (i)=(a);(i)>=(b);(i)--)
#define rof0(i, a) rofa((i),(a),0)
#define rofl0(i, a) rofla((i),(a),0)
#define forag(i, a, b, g) for(int (i)=(a);(i)<(b);(i)+=(g))
#define forlag(i, a, b, g) for(ll (i)=(a);(i)<(b);(i)+=(g))
#define for0g(i, b, g) forag((i),0,(b),(g))
#define forl0g(i, b, g) forlag((i),0,(b),(g))
#define rofag(i, a, b, g) for(int (i)=(a);(i)>=(b);(i)-=(g))
#define roflag(i, a, b, g) for(ll (i)=(a);(i)>=(b);(i)-=(g))
#define rof0g(i, a, g) rofag((i),(a),0,(g))
#define rofl0g(i, a, g) roflag((i),(a),0,(g))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define T third
#define GraphM1(g, n) int (g)[(n)][(n)]
#define GraphM2(g, n) vi (g)[(n)]

// Const variables here
const int maxn = 2e5 + 10;

// Global variables here
int n, q, a[maxn], b[maxn], par[maxn];
ll part[maxn];
GraphM2(g, maxn);
bool visited[maxn];

// Functions here
void dfs(int v, int p) {
    par[v] = p;
    visited[v] = true;

    for (auto u: g[v])
        if (!visited[u]) {
            part[u] += part[v];
            dfs(u, v);
        }

}

// Main here
int main() {
    IOS

    cin >> n;

    fora(i, 1, n) {
        cin >> a[i] >> b[i];
        g[a[i]].pb(b[i]);
        g[b[i]].pb(a[i]);
    }

    dfs(1, 0);

    cin >> q;

    for0(i, q) {
        int t, e, x, u, v;
        cin >> t >> e >> x;

        if (t == 1) {
            u = a[e];
            v = b[e];
        } else {
            v = a[e];
            u = b[e];
        }

        if (u == par[v]) {
            part[1] += x;
            part[v] -= x;
        } else
            part[u] += x;

    }

    memset(visited, 0, n + 2);

    dfs(1, 0);

    fora(i, 1, n + 1)cout << part[i] << "\n";

    return 0;
}


#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

int main() {
  IN(int, H);
  IN(int, W);
  vector<vector<char> > grid(H, vector<char>(W));
  int start_x = 0, start_y = 0;
  int goal_x = 0, goal_y = 0;
  vector<vector<pair<int, int> > > portal(26);
  REP(i, H) {
    REP(j, W) {
      IN(char, c);
      grid.at(i).at(j) = c;
      if (c == 'S') {
        start_x = i;
        start_y = j;
      } else if (c == 'G') {
        goal_x = i;
        goal_y = j;
      } else if (c != '.' && c != '#') {
        portal.at(c - 'a').emplace_back(make_pair(i, j));
      }
    }
  }

  vector<vector<int> > cost(H, vector<int>(W, INT_MAX));
  vector<bool> uncheck(26, true);
  priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > que;
  que.push(make_pair(0, make_pair(start_x, start_y)));
  cost.at(start_x).at(start_y) = 0;
  while (!que.empty()) {
    int x, y;
    int tmp_cost;
    pair<int, int> xy;
    tie(tmp_cost, xy) = que.top();
    tie(x, y) = xy;
    que.pop();
    // cout << x << ", " << y << ", " << tmp_cost << endl;
    // int tmp_cost = cost.at(x).at(y);
    if (grid.at(x).at(y) != 'S' && grid.at(x).at(y) != 'G' && grid.at(x).at(y) != '.') {
      char tmp_c = grid.at(x).at(y);
      if (uncheck.at(tmp_c - 'a')) {
        REP(i, portal.at(tmp_c - 'a').size()) {
          int tmp_x, tmp_y;
          tie(tmp_x, tmp_y) = portal.at(tmp_c - 'a').at(i);
          if (tmp_x == x && tmp_y == y) continue;
          if (cost.at(tmp_x).at(tmp_y) > tmp_cost + 1) {
            que.push(make_pair(tmp_cost + 1, make_pair(tmp_x, tmp_y)));
            cost.at(tmp_x).at(tmp_y) = tmp_cost + 1;
          }
        }
        uncheck.at(tmp_c - 'a') = false;
      }
    }

    if (x - 1 >= 0 && grid.at(x - 1).at(y) != '#') {
      if (cost.at(x - 1).at(y) > tmp_cost + 1) {
        que.push(make_pair(tmp_cost + 1, make_pair(x - 1, y)));
        cost.at(x - 1).at(y) = tmp_cost + 1;
      }
    }
    if (x + 1 < H && grid.at(x + 1).at(y) != '#') {
      if (cost.at(x + 1).at(y) > tmp_cost + 1) {
        que.push(make_pair(tmp_cost + 1, make_pair(x + 1, y)));
        cost.at(x + 1).at(y) = tmp_cost + 1;
      }
    }
    if (y - 1 >= 0 && grid.at(x).at(y - 1) != '#') {
      if (cost.at(x).at(y - 1) > tmp_cost + 1) {
        que.push(make_pair(tmp_cost + 1, make_pair(x, y - 1)));
        cost.at(x).at(y - 1) = tmp_cost + 1;
      }
    }
    if (y + 1 < W && grid.at(x).at(y + 1) != '#') {
      if (cost.at(x).at(y + 1) > tmp_cost + 1) {
        que.push(make_pair(tmp_cost + 1, make_pair(x, y + 1)));
        cost.at(x).at(y + 1) = tmp_cost + 1;
      }
    }
  }

  if (cost.at(goal_x).at(goal_y) == INT_MAX) {
    cout << "-1" << endl;
  } else {
    cout << cost.at(goal_x).at(goal_y) << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int fie[2005][2005];
vector<P> pos[29];
int dp[29][29];
int dist[2005][2005];
bool used[29];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int bfs(int v){
	memset(dist,-1,sizeof(dist));
	queue<P> que;
	for(int i=0;i<pos[v].size();i++){
		int cx=pos[v][i].first;
		int cy=pos[v][i].second;
		dist[cy][cx]=0;
		que.push(P(cx,cy));
	}
	while(que.size()){
		P p=que.front();
		que.pop();
		//printf("%d %d %d\n",p.first,p.second,dist[p.second][p.first]);
		int nu=fie[p.second][p.first];
		if(nu==27){
			return dist[p.second][p.first];
		}
		if(nu>=0 && nu<=25 && !used[nu]){
			used[nu]=true;
			for(int i=0;i<pos[nu].size();i++){
				int nx=pos[nu][i].first;
				int ny=pos[nu][i].second;
				if(dist[ny][nx]==-1){
					dist[ny][nx]=dist[p.second][p.first]+1;
					que.push(P(nx,ny));
				}
			}
		}
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(nx<0 || nx>=w || ny<0 || ny>=h)continue;
			if(fie[ny][nx]==-2)continue;
			if(dist[ny][nx]==-1){
				dist[ny][nx]=dist[p.second][p.first]+1;
				que.push(P(nx,ny));
			}
		}
	}
	return -1;
}

int main(void){
	for(int i=0;i<=27;i++){
		for(int j=0;j<=27;j++){
			dp[i][j]=11451419;
		}
		dp[i][i]=0;
	}
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		string s;
		cin >> s;
		for(int j=0;j<w;j++){
			fie[i][j]=-1;
			if(s[j]=='S'){
				fie[i][j]=26;
				pos[26].push_back(P(j,i));
			}
			if(s[j]=='G'){
				fie[i][j]=27;
			}
			if(s[j]>='a' && s[j]<='z'){
				fie[i][j]=(s[j]-'a');
				pos[(s[j]-'a')].push_back(P(j,i));
			}
			if(s[j]=='#'){
				fie[i][j]=-2;
			}
		}
	}
	printf("%d\n",bfs(26));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;}

using pint = pair<int, int>;
const int MAX = 10000;
int n;
vector<vector<int>> xyr;
bool flgs[MAX][MAX];
vector<vector<int>> res;

void paintOut(int tl_x, int tl_y, int br_x, int br_y) {
    for (int i = tl_y; i <= br_y; ++i) {
        for (int j = tl_x; j <= br_x; ++j) {
            flgs[i][j] = true;
        }
    }
}

int area(int tl_x, int tl_y, int br_x, int br_y) {
    return (br_x - tl_x + 1) * (br_y - tl_y + 1);
}

vector<int> topLeft(int sx, int sy, int r) {

    bool left_f = true, top_f = true;
    int now_row = sy, now_col = sx;

    while (left_f || top_f) {

        if (now_col == 0) left_f = false;
        if (area(now_col-1, now_row, sx, sy) > r) {
            left_f = false;
        }
        if (left_f) {
            for (int i = now_row; i <= sy; ++i) {
                if (flgs[i][now_col-1]) {
                    left_f = false;
                    break;
                }
            }
            if (left_f) now_col--;
        }

        if (now_row == 0) top_f = false;
        if (area(now_col, now_row-1, sx, sy) > r) {
            top_f = false;
        }
        if (top_f) {
            for (int i = now_col; i <= sx; ++i) {
                if (flgs[now_row-1][i]) {
                    top_f = false;
                    break;
                }
            }
            if (top_f) now_row--;
        }
    }

    bool right_f = true, bottom_f = true;
    int ty = now_row, tx = now_col;
    now_row = sy, now_col = sx;

    while (right_f || bottom_f) {

        if (now_col == MAX-1) right_f = false;
        if (area(tx, ty, now_col+1, now_row) > r) {
            right_f = false;
        }
        if (right_f) {
            for (int i = ty; i <= now_row; ++i) {
                if (flgs[i][now_col+1]) {
                    right_f = false;
                    break;
                }
            }
            if (right_f) now_col++;
        }

        if (now_row == MAX-1) bottom_f = false;
        if (area(tx, ty, now_col, now_row+1) > r) {
            bottom_f = false;
        }
        if (bottom_f) {
            for (int i = tx; i <= now_col; ++i) {
                if (flgs[now_row+1][i]) {
                    bottom_f = false;
                    break;
                }
            }
            if (bottom_f) now_row++;
        }
    }
    return {tx, ty, now_col, now_row};
}

void solve() {
    rep(i, n) flgs[xyr[i][2]][xyr[i][1]] = true;
    sort(all(xyr), [](auto& a, auto& b){return a[1] + a[2] - a[3]/8000<  b[1] + b[2] - b[3]/8000;});
    rep(i, n) {
        int x = xyr[i][1], y = xyr[i][2], r = xyr[i][3];
        vector<int> top_left = topLeft(x, y, r);
        paintOut(top_left[0], top_left[1], top_left[2], top_left[3]);
        res[xyr[i][0]] = {top_left[0], top_left[1], top_left[2] + 1, top_left[3] + 1};
    }

    rep(i, n) {
        rep(j, 4) {
            if (j) cout << " ";
            cout << res[i][j];
        }
        cout << endl;
    }
}

int main() {
    cin >> n;
    xyr.resize(n, vector<int>(4));
    rep(i, n) {
        xyr[i][0] = i;
        cin >> xyr[i][1] >> xyr[i][2] >> xyr[i][3];
    }
    res.resize(n, vector<int>(3));
    solve();
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll L, R;
ll M[2100000];
bool IsP[2010000];
ll ans = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 2; i <= 2e6; i++) {
        IsP[i] = true;
    }
    for(int i = 2; i <= 2e6; i++) {
        if(!IsP[i]) continue;
        for(int j = 2 * i; j <= 2e6; j += i) IsP[j] = false;
    }
    for(int i = 2; i <= 2e6; i++) M[i] = -1;
    for(int p = 2; p <= 2e6; p++) {
        if(!IsP[p]) continue;
        for(int i = p; i <= 2e6; i += p) {
            if(i % (p * p) == 0) {
                M[i] = 0;
            }
            else M[i] *= -1;
        }
    }
    cin >> L >> R;
    for(ll g = 2; g * 2 <= R; g++) {
        ll l = (L + g - 1) / g;
        chmax(l, 2LL);
        ll r = R / g;
        if(r < l) continue;
        ans += (r - l + 1) * (r - l + 1);
        for(ll i = 2; i <= r; i++) {
            ll num = r / i - (l - 1) / i;
            ans -= num * num * M[i];
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e3+5;
const int mod=998244353;
int n,m;
int dp[15][N];
int fac[N],invf[N];
inline int po(int x,int k){
	int ret=1;
	while(k){
		if(k&1) ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		k>>=1;
	}
	return ret;
}
inline int C(int x,int k){
	if(x<k) return 0;
	return 1ll*fac[x]*invf[k]%mod*invf[x-k]%mod;
}
int main(){
	int i,j,k;
	fac[0]=1;
	for(i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
	invf[N-1]=po(fac[N-1],mod-2);
	for(i=N-2;i>=0;i--) invf[i]=ll(i+1)*invf[i+1]%mod;
	cin>>n>>m;
	dp[0][0]=1;
	for(i=0;(1<<i)<=m;i++){
		for(j=0;j*(1<<i)<=m&&j<=n;j+=2){
			for(k=j*(1<<i);k<=m;k++)
				dp[i+1][k]=(dp[i+1][k]+1ll*dp[i][k-j*(1<<i)]*C(n,j))%mod;
		}
	}
	cout<<dp[i][m];
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+5;
int n;
char s[N],x[N];
int f[N][8];
int dp(int i,int k){
	if(i==n)	return (k==0);
	if(f[i][k]!=-1)	return f[i][k];
	int ans;
	if(x[i]=='T')	ans=dp(i+1,(k*10+s[i]-'0')%7)|dp(i+1,(k*10)%7);
	else	ans=dp(i+1,(k*10+s[i]-'0')%7)&dp(i+1,(k*10)%7);
	return f[i][k]=ans;
}
int main(){
	memset(f,-1,sizeof(f));
	scanf("%d",&n);
	scanf("%s%s",s,x);
//	cout<<s<<endl<<x<<endl;
	if(dp(0,0))	puts("Takahashi");
	else	puts("Aoki");
	return 0;
}


#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define LL long long
#define LD long double
#define pb push_back
#define F first
#define S second

const double PI=3.1415926535897932384626433;
const int KL=1e6;
const LL MOD=1e9+7;

using namespace std;

LL n,t,q,x,a[KL],k,m,y,z,sum,b[KL];
vector <pair<pair<LL,LL>,pair<LL,LL>>> vec;

int main()
{
    scl(k);scl(n);scl(m);
    for(int i=1;i<=k;i++){
        scl(a[i]);
        x=a[i]*m;
        x/=n;
        sum+=x;
        y=abs(x*n-a[i]*m);
        z=abs((x+1)*n-a[i]*m);
        vec.pb({{y,z},{i,x}});
    }
    sort(all(vec));
    reverse(all(vec));
    t=m-sum;
    for(int j=1;j<=k;j++){
        int i=j-1;
        if(j<=t){
             b[vec[i].S.F]=vec[i].S.S+1;
        }
        else {
             b[vec[i].S.F]=vec[i].S.S;
        }
    }
    for(int i=1;i<=k;i++)cout<<b[i]<<" ";cout<<endl;

    return 0;
}

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

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<cmath>
#include<map>
#include<vector>
#include<unordered_map>
#include<queue>
#include<cstring>
#include<string>
#include<bitset>

#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double>PDD;
const int INF=0x3f3f3f3f;
const int mod = 1e9+7;
long long mypow(int x,int y)
{
    long long res=1;
    for(int i=1;i<=y;i++)
        res*=x;
    return res;
}

ll gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int getlen(char s[])
{
    int res = 0;
    for(int i=1;s[i]!='\0';i++)
        res++;
    return res;
}
ll qmi(ll a,ll b)
{
    ll res = 1 ;
    while(b)
    {
        if(b&1)
            res = (res * a)%mod ;
        a = (a * a)%mod;
        b>>=1;
    }
    return res;
}

// int dx [] = {-2,-1,1,2,2,1,-1,-2};    //马路径
// int dy [] = {1,2,2,1,-1,-2,-2,-1};

// int dx [] = {-1,0,1,0};     // 上右下左
// int dy [] = {0,1,0,-1};

// int dy[] = {1,0,-1,0};    // 直角坐标
// int dx[] = {0,1,0,-1};
int n;
const int N = 4e5+10;
int qmi(int a, int k, int p)
{
    int res = 1;
    while (k)
    {
        if (k & 1) res = res * a % p;
        a =  a * a % p;
        k >>= 1;
    }
    return res;
}

int C(int a, int b, int p)
{
    if (b > a) return 0;

    int res = 1;
    for (int i = 1, j = a; i <= b; i ++, j -- )
    {
        res = (ll)res * j % p;
        res = (ll)res * qmi(i, p - 2, p) % p;
    }
    return res;
}

int lucas(int a, int b, int p)
{
    if(b==0)
        return 1;
    if (a < p && b < p) return C(a, b, p);
    return (ll)C(a % p, b % p, p) * lucas(a / p, b / p, p) % p;
}
char s[N];
char last[N];
int ans = 0;

void solve()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        int d = 0;
        char c = s[i];
        if(c=='W')
            d = 0;
        else if(c=='R')
            d = 1;
        else
            d = 2;
        ans = (ans + d*lucas(n-1,i-1,3)% 3) % 3;
    }
    if((n-1)&1)
        ans=(-ans%3+3)%3;
    char ch ;
    if(ans==0)
        ch = 'W';
    else if(ans==1)
        ch = 'R';
    else
        ch = 'B';
    cout<<ch<<endl;
}
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define int         int64_t
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll         vector<int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mi          map<int,int>
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
void solve(){
    int a,b,c; cin>>a>>b>>c;
    cout<<a+b+c-(min(a,min(b,c)));
}
signed main(){
    ios
    // #ifndef ONLINE_JUDGE
    //     freopen("input(cpp).txt", "r", stdin);
    //     freopen("output(cpp).txt", "w", stdout);
    // #endif
    int test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

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

#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 M1 1000000007
#define M2 998244353
const double pi = 3.14159265;

#define ll long long
#define lld long double

#define pb push_back
#define mp make_pair
#define vi vector<ll>

#define endl '\n'

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define collect(v, n)            \
    for (ll i = 0; i < n; i++) { \
        cin >> v[i];             \
    }
/*
__builtin_popcount(n)      // the number of ones in the int
__builtin_popcountll(n)  // the number of ones in the ll

__builtin_parity(n)  // the parity (even or odd) of the number of ones

__builtin_clz(n)  // the number of zeros at the beginning of the number

__builtin_clzll(n)  // the number of zeros at the beginning of the ll
__builtin_ctz(n)  // the number of zeros at the end of the number
*/

// template <typename T>
// #define o_set(T)
//     tree<T, null_type, less_equal<T>, rb_tree_tag,
//          tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
// MULTISET ==> less_equal
// SET ==> less

ll powM(ll x, ll y, ll m) {
    ll ans = 1, r = 1;
    x %= m;
    while (r > 0 && r <= y) {
        if (r & y) {
            ans *= x;
            ans %= m;
        }
        r <<= 1;
        x *= x;
        x %= m;
    }
    return ans;
}

int add(int a, int b) {
    a += b;
    if (a >= M2) a -= M2;
    return a;
}

int mul(int a, int b) { return a * 1ll * b % M2; }

int binpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

map<long long, long long> factorize(long long n) {
    map<long long, long long> ans;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ans[i]++;
            n /= i;
        }
    }
    if (n > 1) {
        ans[n]++;
        n = 1;
    }
    return ans;
}

ll min(ll a, ll b) {
    if (a < b) return a;
    return b;
}

ll gcd(ll x, ll y) {
    if (x == 0) return y;
    return gcd((ll)y % x, (ll)x);
}

ll modI(ll a, ll m) {
    ll m0 = m, y = 0, x = 1;
    if (m == 1) return 0;
    while (a > 1) {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0) x += m0;
    return x;
}
void amax(ll &a, ll b) { a = max(a, b); }
void amin(ll &a, ll b) { a = min(a, b); }

ll frac(ll p, ll q) {
    p = ((p + M1) % M1 + M1) % M1;
    q = ((q + M1) % M1 + M1) % M1;
    ll qinv = modI(q, M1);
    return (p * qinv) % M1;
}

void solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    vi v = {a, b, c};
    sortall(v);
    cout << v[2] + v[1] << endl;
    return;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(15);
    ll tt = 1;
    // cin >> tt;

    for (ll tc = 1; tc <= tt; tc++) {
        solve();
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
#define P 998244353
#define inv2 499122177
typedef long long ll;
const int N=1000005;
int fac[N],ifac[N],inv[N],ans,a[N],b[N],n,m,pw[N],f[N],g[N];
il int C(ct n,ct m){return n<m||m<0?0:(0ll+fac[n])*ifac[m]%P*ifac[n-m]%P;}
il int ksm(it x,it L){it ans=1;while(L) L&1?ans=(0ll+ans)*x%P,0:0,x=(0ll+x)*x%P,L>>=1;return ans;}
int main(){
	scanf("%d%d",&n,&m);it i;
	for(i=1;i<=n;++i) scanf("%d",&a[i]),b[i]=1;pw[1]=2;ct lim=(n>m?n:m);
	for(i=(fac[0]=ifac[0]=inv[0]=fac[1]=ifac[1]=inv[1]=pw[0]=1)+1;i<=lim;++i)
		fac[i]=(0ll+fac[i-1])*i%P,inv[i]=(0ll+inv[P%i])*(P-P/i)%P,ifac[i]=(0ll+ifac[i-1])*inv[i]%P,pw[i]=pw[i-1]<<1,pw[i]=(pw[i]>=P?pw[i]-P:pw[i]);
	/*for(it k=1;k<=m;++k){
		ct now=C(m,k);it tot=0;
	//	for(i=1;i<=n;++i) tot+=b[i],tot=(tot>=P?tot-P:tot),b[i]=(0ll+b[i])*a[i]%P;
		for(i=1;i<=n;++i) tot=(tot+(0ll+ksm(a[i],k))*ksm(a[i],m-k))%P;
		ans=(ans+(0ll+now)*tot)%P,printf("%d\n",ans);
	}*/
	for(it i=0;i<=m;++i)
		for(it j=1;j<=n;++j) f[i]+=b[j],f[i]=(f[i]>=P?f[i]-P:f[i]),g[i]=(g[i]+(0ll+pw[i])*b[j])%P,b[j]=(0ll+b[j])*a[j]%P;
/*	for(it i=1;i<=m;++i){
		ans=0;
		for(it j=0;j<=i;++j)
			ans=(ans+(0ll+f[j])*f[i-j]%P*inv2)%P;
		printf("%d\n",(ans-g[i]+P)%P);
	}
	*/
	for(it i=1;i<=m;++i){
		ans=0;
		for(it j=0;j<=i;++j)
			ans=(ans+(0ll+f[j])*f[i-j]%P*C(i,j))%P;
		ans=(0ll+ans-g[i]+P)*inv2%P,ans=(ans<0?ans+P:ans),printf("%d\n",ans);
	}
	return 0;
}

//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp = 0;
	int n; cin >> n;
	int m; cin >> m;
	int q; cin >> q;
	vector<pair<ll, ll>> ca;
	vector<ll> bo;
	ll w, v;
	REP(i, n){
		cin >> w >> v;
		ca.push_back(make_pair(w, v));
	}
	REP(i, m){
		cin >> w;
		bo.push_back(w);
	}
	vector<pair<ll, ll> > nc;
	vector<ll> nb;
	int l, r;
	REP(que, q){
		ans = 0;
		cin >> l >> r;
		nc.clear();
		nb.clear();
		REP(i, n) nc.push_back(ca[i]);
		nc.push_back(make_pair(0,0));
		REP(i, m) if(i < l-1 || r-1 < i) nb.push_back(bo[i]);
		sort(nb.begin(), nb.end());
		int now = -1;
		REP(i, nb.size()){
			now = n;
			REP(j, n){
				if(nb[i] >= nc[j].first && nc[now].second <= nc[j].second){
					now = j;
				}
			}
			if(now != n){
				ans += nc[now].second;
				nc[now].first = INF;
				nc[now].second = 0;
			}
		}
		cout << ans << endl;
	}

	//cout << ans << endl;
}


#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b / (1LL << i)) % 2LL == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long N;
long long A[3009], B[3009], C[3009], D[3009], E[3009];
int mask[3009];
int dp[32];

bool solve(long long border) {
	for (int i = 0; i < N; i++) {
		mask[i] = 0;
		if (A[i] >= border) mask[i] += 1;
		if (B[i] >= border) mask[i] += 2;
		if (C[i] >= border) mask[i] += 4;
		if (D[i] >= border) mask[i] += 8;
		if (E[i] >= border) mask[i] += 16;
	}
	for (int i = 0; i < 32; i++) dp[i] = (1 << 30);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 31; j >= 0; j--) dp[j | mask[i]] = min(dp[j | mask[i]], dp[j] + 1);
	}
	if (dp[31] <= 3) return true;
	return false;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];

	long long cl = 0LL, cr = 1200000000LL, cm, maxn = 0;
	for (int i = 0; i < 37; i++) {
		cm = (cl + cr) / 2LL;
		bool I = solve(cm);
		if (I == true) { maxn = max(maxn, cm); cl = cm; }
		else { cr = cm; }
	}
	cout << maxn << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <array>
#include <set>

using namespace std;

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

    vector<array<int, 5>> A(N);
    for (auto& a : A) for (int& i : a) cin >> i;

    int ok = 0, ng = 1001001001;

    auto check = [&](int x) -> bool {
        set<int> s;
        for(auto& a : A) {
            int bit = 0;
            for (int i : a) {
                bit <<= 1;
                bit |= (i >= x);
            }
            s.insert(bit);
        }
        for (int i : s) for (int j : s) for (int k : s) {
            if ((i|j|k)==31) return true;
        }
        return false;
    };

    while (abs(ng - ok) > 1) {
        int x = (ok + ng) / 2;
        if (check(x)) ok = x;
        else ng = x;
    }

    cout << ok;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mxN = 501;
const int INF = 1e9;

int a[mxN][mxN];

void solve(){
    long double x, y, r;
    cin >> x >> y >> r;
    r += 1e-14;
    ll ans = 0;
    for(int i = ceil(x - r); i <= x + r; i++){
        ans += floor(y + sqrt(r * r - (x - i) * (x - i))) - ceil(y - sqrt(r * r - (x - i) * (x - i))) + 1;
    }

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

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

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second
typedef long long ll;
using Graph = vector<vector<ll>>;

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

ll dp[2000][2000];
ll nCr(ll n, ll r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n%MOD;
       if(dp[n][r]) return dp[n][r]%MOD;
       return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD;
}

ll H(ll n, ll r) {
    return nCr(n+r-1, r)%MOD;
}

int prime[10000000];
bool is_prime[100000000 + 1];

int sieve(int n) {
    int pcnt = 0;
    for(int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }

    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++) {
        if(is_prime[i]) {
            prime[pcnt++] = i;
            for(int j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }

    return pcnt;
}

struct UnionFind {
	//自身が親であれば、その集合に属する頂点数に-1を掛けたもの
	//そうでなければ親のid
	vector<ll> r;
	UnionFind(ll N) {
		r = vector<ll>(N, -1);
	}
	ll root(ll x) {
		if (r[x] < 0) return x;
		return r[x] = root(r[x]);
	}
	bool unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (r[x] > r[y]) swap(x, y);
		r[x] += r[y];
		r[y] = x;
		return true;
	}
	ll size(ll x) {
		return -r[root(x)];
	}

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

void solve1() {
    long double x, y, r;cin >> x >> y >> r;
    ll xmin = ceil(x-r), xmax = floor(x+r);
    long double ymin, ymax;
    ll ans = 0;
    r = nextafter(r, INFINITY);
    for(ll i = xmin; i <= xmax; i++) {
        ymin = y - sqrt(r*r-(x-i)*(x-i));
        ymax = y + sqrt(r*r-(x-i)*(x-i));
        ll yi = ceil(ymin);
        ll ya = floor(ymax);

        //cout << i << " " << yi << " " << ya << endl;
        ans += ya-yi+1;
    }

    cout << ans << endl;
}

int main()
{
    solve1();
}


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

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

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
	vector<array<int, 2>> black(m);
	for(auto &[x, y] : black) cin >> x >> y;
	set<int> white;
	white.insert(n);
	sort(all(black));
	for(int i = 0; i < m;){
		int cur = black[i][0];
		vector<int> rem, ins;
		while(i < m && cur == black[i][0]){
			int l = white.count(black[i][1] - 1), r = white.count(black[i][1] + 1);
			if(l + r == 0) rem.push_back(black[i][1]);
			else ins.push_back(black[i][1]);
			++i;
		}
		for(auto j : ins) white.insert(j);
		for(auto j : rem) white.erase(j);
	}
	cout << (int)white.size() << "\n";
}

#include<bits/stdc++.h>
using namespace std;
vector< pair< int , int > > s[2003];
int q[2000006];
int main(){
	int n,m;cin>>n>>m;
	for(int i=1;i<=m;++i){
		int u,v,w;cin>>u>>v>>w;
		s[u].push_back(make_pair(v,w));
	}
	for(int i=1;i<=n;++i){
		int h=0,t=0;
		int d[2003];memset(d,0x3f3f3f3f,sizeof(d));
		bool v[2003]={0};
		for(int j=0;j<s[i].size();++j){
			d[s[i][j].first]=min(d[s[i][j].first],s[i][j].second);
			if(!v[s[i][j].first]){
			q[++t]=s[i][j].first;
			v[q[t]]=1;}
		}
		while(++h<=t){
			v[q[h]]=0;
			for(int j=0;j<s[q[h]].size();++j)
			if(d[s[q[h]][j].first]>d[q[h]]+s[q[h]][j].second){
				d[s[q[h]][j].first]=d[q[h]]+s[q[h]][j].second;
				if(!v[s[q[h]][j].first]){
					q[++t]=s[q[h]][j].first;
					v[q[t]]=1;
				}
			}
		}
		if(d[i]!=d[0])	cout<<d[i]<<endl;
		else			cout<<"-1\n";
	}
}


#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
vector<ll> ans_vec(500,0);
ll H,W,A,B;

void dfs(ll a,ll k,ll board[]){
    if(k == A){
        ans_vec[a]++;
    }
    for(ll h=0;h<H;h++){
        for(ll w=0;w<W;w++){
            if(k < a){
                if(w == W-1)
                    continue;
                if(board[h*H+w] == 1 || board[h*H+w+1] == 1)
                    continue;
                ll copy_board[500];
                rep(i,500)
                    copy_board[i] = board[i];
                copy_board[h*H+w] = 1;
                copy_board[h*H+w+1] = 1;
                dfs(a,k+1,copy_board);
            }
            else{
                if(h == H-1)
                    continue;
                if(board[h*H+w] == 1 || board[h*H+w+H] == 1)
                    continue;
                ll copy_board[500];
                rep(i,500)
                    copy_board[i] = board[i];
                copy_board[h*H+w] = 1;
                copy_board[h*H+w+H] = 1;
                dfs(a,k+1,copy_board);
            }
        }
    }
}

ll frac(ll a){
    if(a == 0)
        return 1;
    else
        return a*frac(a-1);
}

int main(){
    ll ans = 0;
    cin >> H >> W >> A >> B;
    if(H < W){
        ll tmp = W;
        W = H;
        H = tmp;
    }

    //0...縦 1...横

    for(ll a = 0; a <= A; a++){
        ll board[500];
        memset(board,0,sizeof(board));
        dfs(a,0,board);
    }
    for(ll a = 0; a <= A;a++){
        ans += ans_vec[a]/(frac(a)*frac(A-a));
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define LOCAL
#endif
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
const long infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
#define endl        '\n'
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
//#define hell        998244353
#define peak        9e18
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace Ops{
template<class y,class z> ll expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class y> ll power(ll b,y e){ll a=1;while(e!=0){if((e&1)==1){a=a*b;}b=b*b;e>>=1;}return a;}
template<class x,class z> ll inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y> x min(x a,y b){x c;if(a<=b)c=a;else c=b;return c;}
template<class x,class y> x max(x a,y b){x c;if(a>=b)c=a;else c=b;return c;}
ll mul(ll x,ll y,ll m){x%=m;y%=m;if(x==0)return 0;if(x%2==0)return (mul(x/2,y,m)*2)%m;return ((mul(x/2,y,m)*2)%m+y)%m;}
}
using namespace Ops;

namespace InOp{
template<class x>istream &operator>>(istream &in,vector<x> &v) {for(auto& i:v)in>>i;return in;}
template<class x,class y> ostream &operator<<(ostream &out,pair<x,y> &p) {out<<"("<<p.F<<","<<p.S<<")";return out;}
template<class x> ostream &operator<<(ostream &out,vector<x> &v) {out<<"Size : "<<v.size()<<endl;for(auto i:v)out<<i<<" ";out<<endl;return out;}
}
using namespace InOp;

namespace Debug{
#ifdef LOCAL
#define deb(...) printall(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void printall(const char* name, Arg1&& arg1){cerr<<name<<" : "<<arg1<<endl;}
template <typename Arg1, typename... Args>
void printall(const char* names,Arg1&& arg1,Args&&... args){const char* comma=strchr(names,',');cerr.write(names,comma-names)<<" : " <<arg1<<" | ";printall(comma+1,args...);}
#else
#define deb(...) void(0)
#endif
}
using namespace Debug;

namespace Bits{
template<class x> constexpr int onbits(x a){return __builtin_popcount(a);}
constexpr int bits(long long x){return 64-__builtin_clzll(x);}//take care of 0
constexpr int bits(int x){return 32-__builtin_clz(x);}//take care of 0
constexpr int traz(int a){return __builtin_ctz(a);}
constexpr int traz(long long a){return __builtin_ctzll(a);}
}
using namespace Bits;

namespace YesNo{
//#define CAPITAL
void yes(){
    #ifdef CAPITAL
    cout<<"YES"<<"\n";
    #else
    cout<<"Yes"<<"\n";
    #endif
}
void no(){
    #ifdef CAPITAL
    cout<<"NO"<<"\n";
    #else
    cout<<"No"<<"\n";
    #endif
}
}
using namespace YesNo;

void maester();
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(6);
    cerr<<fixed<<setprecision(6);
    ll test=1;
    //cin>>test;
    for(ll tt=1;tt<=test;tt++)
    {
        //cout<<"Case #"<<tt<<": ";
    	maester();
    }
    #ifdef LOCAL
    cerr<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}
#define N  1000005

void maester()
{
    ll i,j,k,l,r,m,n,x,y;
    cin>>n;
    vi a(n),b(n),c(n);
    cin>>a>>b>>c;
    for(i=0;i<n;i++)c[i]=b[c[i]-1];
    map<ll,ll> ma;
	for(auto i:c)ma[i]++;
	ll ans=0;
	for(auto i:a)ans+=ma[i];
	cout<<ans<<endl;
}

/*
@authors MAGNETO
@date    2021-05-24 11:33:20
*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define endl                '\n'
#define ll                  long long
#define l                   long
#define pb                  push_back
#define ppb                 pop_back
#define pf                  push_front
#define ppf                 pop_front
#define all(x)              (x).begin(),(x).end()
#define uniq(v)             (v).erase(unique(all(v)),(v).end())
#define sz(x)               (int)((x).size())
#define fr                  first
#define sc                  second
#define pii                 pair<int,int>
#define pll                 pair<long long, long long>
#define rep(i,a,b)          for(auto i=a;i<b;i++)
#define rev(i,a,b)          for(auto i=a;i>=b;i--)
#define mem1(a)             memset(a,-1,sizeof(a))
#define mem0(a)             memset(a,0,sizeof(a))
#define debug(x)            cerr << #x << " = " << x << endl;
#define debug2(x, y)        {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
#define debug3(x, y, z)     {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
#define debug4(x, y, z, w)  {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#w << " = " <<w <<"\n";}
#define ppc                 __builtin_popcount
#define ppcll               __builtin_popcountll
#define lcm(a,b)            a*b/__gcd(a,b)
//__builtin_popcount = int
//__builtin_popcountl = long int
//__builtin_popcountll = long long

//using namespace __gnu_pbds;

//template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
//__builtin_popcount = int
//__builtin_popcountl = long int
//__builtin_popcountll = long long

template<typename T >T min_ ( T a , T b ) { return a > b ? b : a ; }
template < typename T ,  typename... Ts > T min_( T first , Ts... last ){ return  min_(first, min_(last...)); }
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
  os<<"("<<t.first<<", "<<t.second<<")";
  return os;
}
template<typename T> ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "["; size_t last = v.size() - 1; for(size_t i = 0; i < v.size(); ++i) {
    out << v[i]; if (i != last) out << ", "; } out << "]"; return out;
}

void solve()
{
int n;
cin >> n;
int a[n],b[n],c[n];

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

int d[n];
memset(d, 0, sizeof d);

rep(i, 0, n){
  d[c[i]-1] += 1;
}
map<int, int>mp;

rep(i, 0, n){
  if(d[i]){
    mp[b[i]]+=d[i];
  }
}

ll ans = 0;
rep(i, 0, n){

ans +=  mp[a[i]];
}
cout << ans << endl;
}

int32_t main()
{
FAST
int T=1;
// cin>>T;
while(T--)
{
solve();
}
}


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

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

    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<int> idxs(2*n + 1);
    for (int i = 1; i <= 2*n; i++)
        idxs[i] = i;
    int flag = 0;
    while (q--) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            if (flag) {
                if (a > n)
                    a -= n;
                else
                    a += n;
                if (b > n)
                    b -= n;
                else
                    b += n;
            }
            swap(idxs[a], idxs[b]);
        }
        else {
            flag = !flag;
        }
    }
    if (!flag) {
        for (int i = 1; i <= 2*n; i++)
            cout << s[idxs[i] - 1];
    }
    else {
        for (int i = n + 1; i <= 2*n; i++)
            cout << s[idxs[i] - 1];
        for (int i = 1; i <= n; i++)
            cout << s[idxs[i] - 1];
    }

    return 0;
}

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

const int N = 1e6 + 5;

set<int> s[N];
map<pair<int,int>, int> mp;
int par[N];

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

void join(int x, int y)
{
  x = parent(x);
  y = parent(y);
  if(x == y) return;
  if(s[x].size() > s[y].size())swap(x,y);
  for(int i:s[x])
  {
    s[y].insert(i);
    mp[{y,i}] += mp[{x,i}];
  }
  par[x] = y;
}

int main()
{
  int n,q;
  cin>>n>>q;
  int a[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    mp[{i,a[i]}] = 1;
    s[i].insert(a[i]);
    par[i] = i;
  }
  while(q--)
  {
    int t,x,y;
    cin>>t>>x>>y;
    if(t == 1)join(x,y);
    else cout<<mp[{parent(x),y}]<<endl;
  }
}


#include<bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=1e3+5;
//const int mod=1e9+7;
//const int mod=998244353;
vector<PI>g2[maxm][maxm];
vector<PI>g[maxm];
int mark[maxm][maxm];
int d[maxm][maxm];
int n,m;
void bfs(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            d[i][j]=1e18;
        }
    }
    queue<PI>q;
    q.push({1,n});
    d[1][n]=0;
    mark[1][n]=1;
    while(q.size()){
        PI x=q.front();q.pop();
        for(auto y:g2[x.first][x.second]){
            if(!mark[y.first][y.second]){
                mark[y.first][y.second]=1;
                d[y.first][y.second]=d[x.first][x.second]+1;
                q.push(y);
            }
        }
    }
}
void solve(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        char c;cin>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(auto x:g[i]){
                for(auto y:g[j]){
                    if(x.second==y.second){
                        g2[i][j].push_back({x.first,y.first});
                    }
                }
            }
        }
    }
    bfs();
    int ans=1e18;
    //偶数长度路径
    for(int i=1;i<=n;i++){
        ans=min(ans,d[i][i]*2);
    }
    //奇数长度路径,枚举中间的边
    for(int i=1;i<=n;i++){
        for(auto p:g[i]){
            int j=p.first;
            ans=min(ans,d[i][j]*2+1);
        }
    }
    //
    if(ans==1e18)ans=-1;//无解
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(0);
    solve();
    return 0;
}
/*

*/

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef tuple<int,int> tpl;
typedef pair<int,int> Pair;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

struct Edge{
    int from, to, id=-1;
    int cost=1;

    Edge(int from, int to, int cost=1, int id=-1): from(from), to(to), cost(cost), id(id) {}
    Edge() {}

    friend istream &operator>>(istream  &input, Edge &e ){
        char c;
        input >> e.from >> e.to >> c;
        e.from--; e.to--; e.cost = c-'a';
        return input;
    }

    Edge rev(void){
        return Edge(to, from, cost, id);
    }
};

vector<vector<Edge>> edge(1010);
bool connect[1010][1010];
int d[1010][1010];

void Main(){
    int N,M; cin >> N >> M;
    vector<Edge> edge2[N][26];
    REP(_,M){
        Edge e; cin >> e;
        edge[e.from].emplace_back(e);
        edge[e.to].emplace_back(e.rev());

        connect[e.from][e.to] = connect[e.to][e.from] = true;

        edge2[e.from][e.cost].emplace_back(e);
        edge2[e.to][e.cost].emplace_back(e.rev());
    }

    REP(i,N)REP(j,N) d[i][j] = INF;
    int ans = INF;
    queue<Pair> q;
    q.emplace(0,N-1);
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int cost = p.first, v = p.second;
        int x = v/N, y = v%N;

        if(cost >= ans) break;

        if(!chmin(d[x][y], cost)) continue;
        if(x==y){
            chmin(ans, cost);
            break;
        }
        if(connect[x][y]){
            chmin(ans, cost+1);
            continue;
        }

        REP(i,26){
            for(auto& ex : edge2[x][i])for(auto& ey : edge2[y][i]){
                q.emplace(cost+2, ex.to*N+ey.to);
            }
        }
    }

    cout << (ans<INF ? ans : -1) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    while(t--) Main();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long s,p;
	cin>>s>>p;
	for(long long i=1;i*i<=p;++i){
		if(p%i==0){
			if((i+p/i)==s){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

#include<bits/stdc++.h>
using namespace std::chrono;
using namespace std;
#define int long long
#define loop(i, start, end) for (int i = start; i <= end; i++)
#define rloop(i, start, end) for (int i = start; i >= end; i--)
#define read(a,n) loop(i,0,n-1) cin>>a[i];
#define vi vector<int>
#define vec(x) vector<x>
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define fsp(a) fixed<<setprecision(a)
#define mem(a,with) memset(a, with, sizeof (a))
#define vmn(a) (*min_element(a.begin(),a.end()))
#define vmx(a) (*max_element(a.begin(),a.end()))
#define bs(a,key) binary_search(all(a),key)    /// return bool.
#define rotl(a,x) rotate(a.begin(),a.begin()+x,a.end());
#define rotr(a,x) rotl(a,a.size()-x);
#define nl cout<<endl
#define dbg(x) cerr << #x << " :: " << x << endl;
#define dbg2(x, y) cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define MOD 1000000007
int add(int x, int y) {int res = x + y; return (res >= MOD ? res - MOD : res);}
int mul(int x, int y) {int res = x * y; return (res >= MOD ? res % MOD : res);}
int power(int x, int y) {int res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void solve(){
    //code goes here
    int s,p;
    cin>>s>>p;
    loop(x,1,sqrt(max(s,p))){
        int y=p/x;
        if(x*y==p and x+y==s){
            cout<<"Yes";
            return;
        }
    }
    cout<<"No";
}

int32_t main()
{
auto start = chrono::high_resolution_clock::now();
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
    int t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
#ifndef ONLINE_JUDGE
     auto stop = chrono::high_resolution_clock::now();
    auto duration = chrono::duration_cast<microseconds>(stop - start);
    cout<<"\n\nExecuted In: "<<duration.count()<<" ms";
#endif
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vii;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pairNa
#define popcount __builtin_popcount
#define case cout<<"Case "<<z-t<<": ";
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,i,j,k,t=0,s=0;
    m=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>j;
        m=max(m,j);
        s+=j;
        t+=s;
        cout<<t+(i+1)*m<<endl;
    }
    cout<<endl;
}

#include <bits/stdc++.h>

template <class T>
T read() {
  T num = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  return num * f;
}

int main() {
  int x = read<int>();
  int ans = (x - x % 100 + 100) - x;
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  string C;
  cin >> C;
  if(C.at(0)==C.at(1)) {
    if(C.at(1)==C.at(2)) {
      cout << "Won" << endl;
    } else {
      cout << "Lost" << endl;
    }
  } else {
    cout << "Lost" << endl;
  }
}

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007 // 998244353
#define INFLL (1LL<<62)
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
__attribute__((constructor))
void init(){ std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout<<std::fixed<<std::setprecision(15); }
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; }
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[0]) cout << "Won" << endl;
    else cout << "Lost" << endl;
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
//x:コンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647          //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007            //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x)                                \
    for (auto i = x.begin(); i != --x.end(); i++) \
        cout << *i << " ";                        \
    cout << *--x.end() << endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
ll myfloor(ll a, ll b) { return a / b; }

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

    int N,M;
    cin >> N >> M;

    vector<pair<int, int> > a(M+1);

    REP(i,M){
        cin >> a[i].F >> a[i].S;
    }

    int K;
    cin >> K;
    vector<pair<int, int> > b(K+1);
    REP(i,K){
        cin >> b[i].F >> b[i].S;
    }

    int k2 = 1 << K;
    int ans = 0;
    REP(i,k2){
        vector<int> dist(N+1);
        REP(j,K){
            if(i&(1<<j)) dist[b[j].F]++;
            else dist[b[j].S]++;
        }
        int now = 0;
        REP(j,M){
            if(!dist[a[j].F]) continue;
            if(!dist[a[j].S]) continue;
            now++;
        }
        ans = max(ans,now);
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define repeq(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i)
#define rrep(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); --i)
#define rrepeq(i,a,b) for(int i=(int)(b); i>=(int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}

template<typename T> struct is_plural : false_type{};
template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{};
template<typename T> struct is_plural<vector<T>> : true_type{};
template<typename T> struct is_plural<complex<T>> : true_type{};
template<> struct is_plural<string> : true_type{};

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for(auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if(vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for(auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; }

bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << "\n"; return a; }

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

long long modpow(int a, long long n, int mod = MOD) { long long ret = 1; do { if(n & 1) ret = ret * a % mod; a = 1LL * a * a % mod; } while(n >>= 1); return ret; }

template<typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; }
template<typename T1, typename T2> bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) { return a.first != b.first ? a.first < b.first : a.second > b.second; }

/* -------- <templates end> -------- */

void solve() {
  int n; ll x; cin >> n >> x;
  vector<int> a(n); cin >> a;

  constexpr ll INFTY = 1LL << 60;
  ll ans = INFTY;

  for(int z=1; z<=n; ++z) {
    ll dp[n+1][z+2][z];
    fill(dp[0][0], dp[n+1][0], -INFTY);
    dp[0][0][0] = 0;
    for(int i=0; i<n; ++i) {
      for(int j=0; j<=z; ++j) {
        for(int k=0; k<z; ++k) {
          if(dp[i][j][k] == -INFTY) continue;
          chmax(dp[i+1][j][k], dp[i][j][k]);
          chmax(dp[i+1][j+1][(k + a[i]) % z], dp[i][j][k] + a[i]);
        }
      }
    }
    if(ll tmp = dp[n][z][x % z]; tmp != -INFTY) {
      chmin(ans, (x - tmp) / z);
    }
  }

  cout << ans << endl;
}

/* -------- <programs end> -------- */

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9 + 10;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
using pint = pair<ll, ll>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    map<int, int> mp;
    bool chk = 0;
    int ans = inf;
    rep(i, 0, n) {
        cin >> a[i];
        a[i] %= 200;
        if (a[i] == 0) {
            chk = 1;
            ans = i;
        }
        mp[a[i]]++;
    }
    if (chk) {
        cout << "Yes\n";
        rep(i, 0, n) {
            if (ans != i) {
                if (ans > i) {
                    cout << "2 " << i + 1 << " " << ans + 1 << "\n";
                    cout << "1 " << i + 1 << "\n";
                    return 0;
                } else {
                    cout << "2 " << ans + 1 << " " << i + 1 << "\n";
                    cout << "1 " << i + 1 << "\n";
                    return 0;
                }
            }
        }
    }
    for (auto p : mp) {
        if (p.second > 1) {
            chk = 1;
            ans = p.first;
            break;
        }
    }
    if (chk) {
        cout << "Yes\n";
        int c = 0;
        rep(i, 0, n) {
            if (ans == a[i]) {
                cout << "1 " << i + 1 << "\n";
                c++;
                if (c == 2) return 0;
            }
        }
    }
    for (ll bit = 1; bit < (1 << n); bit++) {
        vector<int> vec;
        if (__builtin_popcount(bit) == 1) continue;
        ll sum = 0;
        rep(i, 0, n) {
            if (bit & (1 << i)) {
                vec.push_back(i);
                sum += a[i];
            }
        }
        sum %= 200;
        mp[sum]++;
        if (mp[sum] == 2) {
            chk = 1;
            ans = sum;
            break;
        }
    }
    if (chk) {
        cout << "Yes\n";
        int cnt = 0;
        for (ll bit = 1; bit < (1 << n); bit++) {
            vector<int> vec;
            ll sum = 0;
            rep(i, 0, n) {
                if (bit & (1 << i)) {
                    vec.push_back(i);
                    sum += a[i];
                }
            }
            sum %= 200;
            if (sum == ans) {
                cout << __builtin_popcount(bit) << " ";
                for (auto i : vec) cout << i + 1 << " ";
                cout << "\n";
                cnt++;
                if (cnt == 2) return 0;
            }
        }
    } else {
        cout << "No\n";
    }
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define INF 1 << 30

// bool solve1(string S) {
//     sort(S.begin(), S.end());
//     for (int i = 8; i <= 999992; i += 8) {
//         auto T = to_string(i);
//         sort(T.begin(), T.end());
//         if (S == T) {
//             return true;
//         }
//     }
//     return false;
// }

bool solve2(string s) {
    if (s.size() == 1) return s == "8";
    if (s.size() == 2) {
        if (stoi(s) % 8 == 0) return 1;
        swap(s[0], s[1]);
        return stoi(s) % 8 == 0;
    }
    vector<int> cnt(10);
    for (char x : s) cnt[x - '0']++;
    for (int i = 112; i < 1000; i += 8) {
        auto c = cnt;
        for (char x : to_string(i)) c[x - '0']--;
        if (all_of(c.begin(), c.end(), [](int x) { return x >= 0; })) return 1;
    }
    return 0;
}

int main() {
    string s; cin >> s;
    bool ans = solve2(s);
    cout << (ans?"Yes":"No") << endl;
}


#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define ndl '\n'
void solve()
{
   ll n;cin>>n;
   cout<<ceil((-1+sqrtl(1+8*n))/2)<<ndl;
}
int main()
{
    auto starttime = high_resolution_clock::now();
    flash
    solve();
    auto endtime = high_resolution_clock::now();
    double duration = duration_cast<microseconds>(endtime - starttime).count();
    duration/=1000000;
    cerr<<"Time Taken : "<<fixed<<setprecision(6)<<duration<<" secs"<<'\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
	int cur, n, i;
	cin >> n ;
	cur = 0;
  	i = 1 ;
  	while(i<=n){
      cur += i ;
      if(cur>=n) break ;
    	++i ;}
	cout << i ;
	return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
// #define ll long long
#define mod 1000000007
// #define mod 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;

// int mod;
int power(int x, int y)
{
    int res = 1LL;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int  n)
{
    return power(n,mod-2)%mod;
}

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

}
int sq(int n){
    return n*n;
}

const int N=2e5+10;

vector<int> a[1000005];
int p[1000005];
void solve(){

    int mx=0;
    int i,j,k;
    int l,r;
    cin>>l>>r;

    if(l==1)
        l++;

    if(l>r)
    {   cout<<"0\n";
        return;
    }

    for(i=2;i<=1e6;i++)
    {   for(j=2*i;j<=1e6;j+=i)
        {   a[j].pb(i);
            mx=max(mx,(int)a[j].size());
        }
        p[i]=i;
        if(a[i].size())
            p[i]=a[i][0];

    }

    int cnt=0,coprime=0;
    for(i=l;i<=r;i++)
    {
        if(a[i].size()){
            int lo=0,hi=a[i].size();
            while(lo<hi){
                int mid=(lo+hi)/2;
                if(a[i][mid]>=l)
                    hi=mid;
                else lo=mid+1;
            }
            int val=a[i].size()-lo;
            cnt+=val;
        }

        vector<int> pf;

        int cur=i;
        while(cur>1){
            int cp=p[cur];
            pf.pb(cp);
            while(cur%cp==0)
                cur/=cp;
        }
        int sz=pf.size();

        int total=0;
        for(j=1;j<(1<<sz);j++)
        {
            int prod=1;
            int bc=__builtin_popcount(j);
            int coprime_cnt=0;
            for(k=0;k<sz;k++)
                if(j&(1<<k))
                    prod*=pf[k];

            coprime_cnt=i/prod-(l-1)/prod;

            if(bc%2==0)
                coprime_cnt*=-1;
            total+=coprime_cnt;
        }
        coprime+=i-l+1-total;
    }
    cnt+=coprime;
    cnt*=2;

    int len=r-l+1;

    cnt+=len;
    cout<<len*len-cnt<<"\n";

}
int32_t main(){
   fast
    int t=1;
    int tc=0;
    // cin>>t;

    while(t--)
    {
        tc++;
        // cout<<"Case #"<<tc<<": "
        solve();
    }
}

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vec vector
using namespace std;

const int MX = 1e6 + 1;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	int l, r;
	cin >> l >> r;
	vec<int> lpf(MX);
	for (int i=2; i<MX; i++) {
		if (lpf[i] > 0) continue;
		for (int j=i; j<MX; j+=i) lpf[j] = i;
	}
	ll res = 0;
	for (int i=2; i<=r; i++) {
		int x = i, prm = 0;
		bool poss = 1;
		while (x > 1) {
			int y = lpf[x], cnt = 0;
			while (x%y == 0) {
				x /= y;
				cnt++;
			}
			if (cnt > 1) {
				poss = 0;
				break;
			}
			prm++;
		}
		if (poss) {
			ll c = r/i - (l-1)/i;
			if (prm&1) res += c*(c-1) / 2;
			else res -= c*(c-1) / 2;
		}
	}
//	cout << 2*res << '\n';
	for (int i=max(2, l); i<=r; i++) res -= r/i-1;
	cout << 2*res << '\n';
}


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

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

  int tc;
  cin >> tc;

  while (tc--) {
    int n;
    cin >> n;

    set<int> s;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;

      if (s.find(a) != s.end()) s.erase(a);
      else s.insert(a);
    }

    if (n&1) cout << "Second\n";
    else if (s.size()) cout << "First\n";
    else cout << "Second\n";
  }
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

void solve(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	if(n%2==0){
		map<int,int> f;
		rep(i,n) ++f[a[i]];
		bool ok=true;
		for(auto p:f) if(p.second%2==1) ok=false;
		puts(!ok?"First":"Second");
	}
	else{
		puts("Second");
	}
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}