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

using namespace std;
using namespace chrono;

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

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

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

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

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

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

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

int main()
{
    auto start_time = Clock;
    FASTIO

    ll n,m;
    cin >> n >> m;
    vector<string> s(n);
    vector<vll> mp(n+m+1);
    rep(i,n) {
        cin >> s[i];
        rep(j,m) {
            ll x = i+j;
            if(s[i][j] == 'R') mp[x].pb(1);
            else if(s[i][j] == 'B') mp[x].pb(-1);
            else mp[x].pb(0);
        }
    }
    ll ans = 1, ok = 1;
    rep(i,n+m+1) {
        ll R,B,D;
        R = B = D = 0;
        for(auto j: mp[i]) {
            if(j==1) ++R;
            else if(j==0) ++D;
            else ++B;
        }
        // if(i==2) trace(R,B,D);
        if(R>0 && B>0) ok = 0;
        else if(D>0 && R==0 && B==0) {ans *= 2;ans %= mod;}
    }

    if(!ok) ans = 0;
    cout << ans << "\n";

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

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 998244353;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int H,W; cin >> H >> W;
    vector<string> S(H);
    REP(i,H) cin >> S[i];
    int cnt = 0;

    REP(j,W) {
        set<char> st;
        for(int i = 0,k = j; i < H &&  k >= 0; i++,k--) {
                st.insert(S[i][k]);
        }
        if(st.count('R') && st.count('B')) {
            cout << 0 << endl;
            return 0;
        } if(st.size() == 1 && st.count('.')) cnt++;
    }

    REP(i,H) {
        if(i == 0) continue;
        set<char> st;
        for(int k = i,j = W-1; k < H && j >= 0; k++,j--) {
            st.insert(S[k][j]);
        }
        if(st.count('R') && st.count('B')) {
            cout << 0 << endl;
            return 0;
        } if(st.size() == 1 && st.count('.')) cnt++;
    }
    cout << modpow(2LL,cnt,MOD) << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 1000000000000000000
#define INT_MINI -9000000000000000000

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

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

char arr[1005][1005];

int main()
{
	fio;
	ll t,n,i,j,k,x,l,r,b,h,y,m,a,c,d;
	cin>>a>>b>>c>>d;
	double val=d*1.0/a;
	if(val>=b&&val<=c)
	{
		cout<<"No";
	}
	else
	cout<<"Yes";

}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits>
#include <string>

using namespace std;

int main() {
  int V, T, S, D;
  cin >> V >> T >> S >> D;

  cout << ((V * T > D || (V * T + (V * (S - T)) <  D)) ? "Yes" : "No") << endl;

  return 0;
}


/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10, mod = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % mod;
}

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

int main() {
	fast_cin();
	int n; cin >> n;
	char caa, cab, cba, cbb;
	cin >> caa >> cab >> cba >> cbb;
	if (cab == 'B') {
		cab ^= 'A' ^ 'B';
		cba ^= 'A' ^ 'B';
		tie(caa, cbb) = make_pair(cbb ^ 'A' ^ 'B', caa ^ 'A' ^ 'B');
	}
	if (caa == 'A') {
		cout << 1 << '\n';
	} else {
		if (cba == 'A') {
			int m = n - 2, a = 1, b = 1;
			while (m--) {
				tie(a, b) = make_pair(b, add(a, b));
			}
			cout << a << '\n';
		} else {
			int p2 = 1;
			for (int i = 0; i < n - 3; ++i) {
				p2 = mul(p2, 2);
			}
			cout << p2 << '\n';
		}
	}
}

#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (c == 0) {
		if (a > b) cout << "Takahashi" << endl;
		else cout << "Aoki" << endl;
	}
	else {
		if (b > a) cout << "Aoki" << endl;
		else cout << "Takahashi" << endl;
	}
	system("Pause");
}


//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647;
use io;
int n,m,a[N],f[N],T;
char an[666][666];
void ck(int k,int x,int y,int b)
{
	if(k==0)
		an[x][y]='A'+b;
	else
	{
		ck(k-1,x,y,b);
		ck(k-1,x+(1<<(k-1)),y,b);
		ck(k-1,x,y+(1<<(k-1)),b);
		ck(k-1,x+(1<<(k-1)),y+(1<<(k-1)),b^1);
	}
}
int main()
{
	int i,j,a1,a2;
	_(n);
	ck(n,0,0,0);
	_pn((1<<n)-1);
	fo(i,(1<<n)-1)
		puts(an[i]);
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  if (n == 1) {
    cout << "Yes\n";
    return 0;
  }
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];
  for (int i = n - 1; i >= 0; --i) {
    a[i] -= a.front();
    b[i] -= b.front();
  }
  int dist1 = a[1] * a[1] + b[1] * b[1];
  set<pair<int, int>> s;
  REP(i, n) s.emplace(a[i], b[i]);
  vector<int> c(n), d(n);
  REP(i, n) cin >> c[i] >> d[i];
  REP(r, n) {
    vector<int> x(n), y(n);
    REP(i, n) {
      x[i] = c[i] - c[r];
      y[i] = d[i] - d[r];
    }
    REP(i, n) {
      if (i == r || x[i] * x[i] + y[i] * y[i] != dist1) continue;
      double theta = atan2(b[1], a[1]) - atan2(y[i], x[i]), co = cos(theta), si = sin(theta);
      bool is_valid = true;
      REP(j, n) {
        double nx = x[j] * co - y[j] * si, ny = x[j] * si + y[j] * co;
        if (abs(round(nx) - nx) > EPS
            || abs(round(ny) - ny) > EPS
            || s.count({static_cast<int>(round(nx)), static_cast<int>(round(ny))}) == 0) {
          is_valid = false;
          break;
        }
      }
      if (is_valid) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}


#include <bits/stdc++.h>
# define INF32 2147483647
# define INF64 9223372036854775807
# define rep(i,l,n) for(int i=l,i##_end=n;i<i##_end;++i)
# define rrep(i,n,l) for(int i=((int)(n)-1),i##_end=l;i>=i##_end;--i)
# define erep(i,n) for(auto &i : n)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    // 1. input
    string S;
    cin>>S;

    // 2.
    bool ans = true;
    rep(i,0,S.size()){
        if( (i%2 == 0 && isupper(S[i])) || (i%2 == 1 && !isupper(S[i])) ) {
            ans = false;
            break;
        }
    }

    // 3. output
    cout << (ans?"Yes":"No") << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=0;
    for(int i=0;i<s.length();i++)
    {
        if( (i%2==0) )
        {
            if(s[i]>= 'a' && s[i]<= 'z') flag=1;
            else {flag=0; break;}

        }
        else if(i%2==1)
        {
            if(s[i]>= 'A' && s[i]<= 'Z') flag=1;
             else {flag=0; break;}
        }
    }
    if(flag==1) cout<<"Yes\n";
    else cout<<"No\n";

}


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

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

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

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

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll dig(ll n) {//桁数
    ll res = 0;
    while(n > 0) {
        res ++;
        n /= 10;
    }
    return res;
}
vector<bool> seen;
void dfs(vvll &G, ll v){
    seen[v]=true;
    for(auto next:G[v]){
        if(seen[next]) continue;
        dfs(G,next);
    }
}

int main() {
    ll n,m,x,ans=1;
    cin>>n>>m;
    vll A(n);
    vll X(m+1,1);
    rep(i,n){
        if(i==0){
            A[0]=m;
            continue;
        }
        ll sum=0;
        rep(j,m){
            A[i]+=mod+A[i-1]+modpow(m,i,mod)-X[j];
            A[i]%=mod;
            X[j]=(m-j-1)*X[j]+modpow(m,i,mod);
            X[j]%=mod;
        }
    }
    cout<<A[n-1]%mod<<endl;
}

#include<bits/stdc++.h>
using namespace std;
long long f[5001][5001];
const int mod=998244353;

int main()
{

    int n,m;
    cin>>n>>m;
    for (int i=0;i<=m;i++){
            f[i][0]=1;
        for (int j=1;j<=n;j++){
            f[i][j]=f[i][j-1]*1ll*i%mod;
        }
    }
    long long res=1ll*n*f[m][n]%mod;
    for (int i=1;i<=m;i++){
        for (int len=2;len<=n;len++){
            int pos=n-len+1;
            int in=f[m-i][len-2];
            int out=f[m][n-len];
            res=(res+mod-pos*1ll*in%mod*1ll*out)%mod;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

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

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int n;
    cin>>n;
    if(n&1) cout << "Black";
    else cout << "White";
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    // cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}

#include<iostream>
using namespace std;

int main(void)
{
    int n; cin>>n;
    if(n&1) puts("Black");
    else puts("White");
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

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

#define MAXN 200005
typedef long long ll;
typedef unsigned long long ull;

ull Max = 0x3f3f3f3f3f3f3f3f;

ull dist[MAXN];
typedef struct
{
    ull to;
    ull t, k;
} Node;
vector<Node> vec[MAXN];
ull N, M, X, Y;

void min_len2()
{
    using Pair = pair<ull, ull>;

    for (ull i = 1; i <= N; i++)
        dist[i] = Max;
    dist[X] = 0;

    priority_queue<Pair, vector<Pair>, greater<Pair>> q; // 小根堆
    q.push(Pair(0, X));

    while (!q.empty())
    {
        auto top = q.top();
        auto tick = top.first;
        auto node = top.second;

        if (node == Y && tick != 0)
            return;

        q.pop();

        for (auto &x : vec[node])
        {
            ull d = tick + (x.k - tick % x.k) % x.k + x.t; // dist + wait + travel time
            if (d < dist[x.to])
            {
                dist[x.to] = d;
                q.push(Pair(dist[x.to], x.to));
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M >> X >> Y;

    for (ull i = 0; i < M; i++)
    {
        ull a, b, t, k;
        cin >> a >> b >> t >> k;
        vec[a].push_back({b, t, k});
        vec[b].push_back({a, t, k});
    }
    min_len2();

    if (dist[Y] >= Max)
        cout << "-1" << endl;
    else
        cout << dist[Y] << endl;

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<a*d-b*c<<endl;
	return 0;
 }

//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d %d %d",&n,&m,&k,&t);
	printf("%d\n",n*t-m*k);
	return 0;
}


// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 998244353;
int board[1010][1010]; // マスの色(0: 色なし, 1: 赤, 2: 青).
int cnt[1010][3];      // 出現回数(0: 色なし, 1: 赤, 2: 青).

int main(){

    // 1. 入力情報.
    int H, W;
    scanf("%d %d", &H, &W);
    rep(i, H){
        char c[505];
        scanf("%s", c);
        rep(j, W){
            if(c[j] == 'R') board[i][j] = 1;
            if(c[j] == 'B') board[i][j] = 2;
        }
    }

    // 2. 右上から左下に向かって, マスの色を確認.
    rep(k, H + W - 1){
        rep(i, H + W - 1){
            int j = k - i;
            if(j >= 0) cnt[k][board[i][j]]++;
            else       break;
        }
    }
    // rep(i, H + W - 1) printf("n=%d r=%d b=%d\n", cnt[i][0], cnt[i][1], cnt[i][2]);

    // 3. 色なしのみをカウント.
    // -> 赤, 青が混在している場合は, 着色不可能と判定.
    // -> 開始地点, 終了地点も, '.' となる場合があるので, 注意.
    LL ans = 1;
    int noColor = 0;
    rep(i, H + W - 1){
        if(cnt[i][1] && cnt[i][2])   ans = 0;
        if(!cnt[i][1] && !cnt[i][2]) noColor++;
    }

    // 4. 塗り方の総数は？
    rep(i, noColor) ans <<= 1, ans %= MOD;

    // 5. 出力.
    printf("%lld\n", ans);
    return 0;

}

#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
const int mod=998244353;
int n,m,i,j,s=1;
char c[505][505];
int main(){
	cin>>n>>m;
	rep(i,n)rep(j,m)cin>>c[i][j];
	for(i=1+1;i<=n+m;i++){
		bool b=0,r=0;
		rep(j,n){
			int k=i-j;
			if(1<=k&&k<=m){
				if(c[j][k]=='B')b=1;
				if(c[j][k]=='R')r=1;
			}
		}
		s=1ll*s*(2-b-r)%mod;
	}
	cout<<s<<endl;
	return 0;
}


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

#define ll long long int
#define ull unsigned long long int

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

void solve() {

}

int main() {

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

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

	ll t = 1;
	// cin >> t;
	while (t--) {
		int a, b, c;
		cin >> a >> b >> c;

		if (a > b || (a == b && c == 1)) {
			cout << "Takahashi" << endl;
		} else if (a < b || (a == b && c == 0)) {
			cout << "Aoki" << endl;
		}
	}
}

// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif

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

    ll n,w,i,x,y,p,m = -100;
    ll idx[2*MAX];
    for(i=0;i<=200005;++i){
        idx[i] = 0;
    }
    cin>>n>>w;
    for(i=0;i<n;++i){
        cin>>x>>y>>p;
        idx[x] += p;
        idx[y] -= p;
        m = max(m,y);
    }
    for(i=1;i<=m;++i){
        idx[i] += idx[i-1];
    }
    for(i=0;i<=m;++i){
        if(idx[i] > w){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


/*
设dp[i][j]为当前算到tak拿了i个物品，它的和为j的方案数。
*/
#include<cstdio>
const long long mod=998244353;
long long n,w[110],sum,dp[110][10010],power[110],ans;
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;++i)	scanf("%lld",&w[i]);
	dp[0][0]=1;
	power[0]=1;
	for(long long i=1;i<=n;++i)
	{
		power[i]=(power[i-1]*i)%mod;
		for(long long j=i-1;j>=0;--j)
		{
			for(long long k=0;k<=sum;++k)	dp[j+1][k+w[i]]=(dp[j+1][k+w[i]]+dp[j][k])%mod;
		}
		sum+=w[i];
	}
	if(sum%2==0)
	{
		for(long long i=1;i<=n;++i)	ans=(ans+((power[i]*power[n-i])%mod)*dp[i][sum/2])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
const int N = 105, P = 998244353;
int n, a[N], sum = 0, f[N][N * N], g[N][N * N], fac[N]; // 1：当前权值；2：<0次数
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]), sum += a[i];
	if (sum & 1) { puts("0"); return 0; }
	fac[1] = 1;
	for (int i = 2; i <= n; i++)
		fac[i] = 1ll * fac[i - 1] * i % P;
	f[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		memset(g, 0, sizeof g);
		for (int j = 0; j <= i; j++)
			for (int k = 0; k <= i * 100; k++) {
				g[j][k] = f[j][k];
				if (j && k >= a[i]) g[j][k] = (g[j][k] + f[j - 1][k - a[i]]) % P;
			}
		memcpy(f, g, sizeof g);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = (ans + 1ll * fac[i] * fac[n - i] % P * g[i][sum / 2]) % P;
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F(w,x,y) for(ll w=x; w<y; w++)
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

void play()
{
    ll n,a;
    cin>>n;
    vector <ll> pref(n+1);
    pref[0]=0;
    vector <ll> maxi(n+1,0);
    maxi[0]=0;
    F(i,1,n+1)
    {
        cin>>a;
        pref[i]=pref[i-1]+a;
        maxi[i]=max(maxi[i-1],a);
    }
    ll sum=0;
    F(i,1,n+1)
    {
        sum+=pref[i];
        cout<<sum+(maxi[i]*i)<<endl;
    }
}

int main()
{
    //freopen("milkvisits.in","r",stdin);
    //freopen("milkvisits.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //pre();
    ll t;
    t=1;
    //cin>>t;
    F(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        play();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
int n,a[200010];
long long sum[200010],ma;
void solve() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+sum[i];
	for(int i=1;i<=n;i++) {
		ma=max(ma,(long long)a[i]);
		printf("%lld\n",sum[i]+1ll*ma*i);
	}
}
int main() {
	int t=1;//scanf("%d",&t);
	while(t--) solve();
}


#include<bits/stdc++.h>
#define MAXN 50+10
#define MAXM 2500+10

using namespace std;

const int n = 50;

int si,sj;
string Fs = "RDLU";

int Fx[10] = {0,1,0,-1};
int Fy[10] = {1,0,-1,0};

int Soc[MAXM];
bool vis[MAXM];

int t[MAXN][MAXN];
int p[MAXN][MAXN];
string Move,s;

int Now = 0;
int Ans = 0;

const int Time_Limit =  (int) (1.9 * CLOCKS_PER_SEC);

void DFS(int x,int y)
{
	if(Now > Ans)
	{
		Move = s;
		Ans = Now;
	}
	if((int)clock() >  Time_Limit)
	{
		cout << Move;
		exit(0);
	}

	vis[t[x][y]] = true;
	Now += Soc[t[x][y]];

	for(int i=0;i<4;i++)
	{
		int nx = x + Fx[i];
		int ny = y + Fy[i];
		if(nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
		if(vis[t[nx][ny]]) continue;
		s += Fs[i];
		DFS(nx,ny);
		s.pop_back();
	}
	vis[t[x][y]] = false;
	Now -= Soc[t[x][y]];
}

int main()
{
	scanf("%d%d",&si,&sj);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&t[i][j]);

	 for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			scanf("%d",&p[i][j]);
			Soc[t[i][j]] += p[i][j];
		}

	DFS(si,sj);

	cout << Move;
	//cout << Ans;
}

#include<bits/stdc++.h>
using namespace std;
int n,t,a[102],ans;
set<int> q;
void Dfs1(int dep,int sum){
	if(sum>t)
		return;
	if(dep==(n>>1)+1){
		q.insert(sum);
		return;
	}
	Dfs1(dep+1,sum),
	Dfs1(dep+1,sum+a[dep]);
}
void Dfs2(int dep,int sum){
	if(sum>t)
		return;
	if(dep==n+1){
		set<int>::iterator i=q.upper_bound(t-sum);
		--i;
		ans=max(ans,sum+(*i));
		return;
	}
	Dfs2(dep+1,sum),
	Dfs2(dep+1,sum+a[dep]);
}
int main(){
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	Dfs1(1,0);
	Dfs2((n>>1)+1,0);
	printf("%d\n",ans);
}


// D - RGB Coloring 2
// sample code
// reference: https://atcoder.jp/contests/abc199/submissions/22053625
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)

vec<vi> G;
vi IX; //彩色順を記録。違う連結成分なら同じ index もある

ll dfs(int now, vi&v){
	ll res = 0;
	for(int to:G[now]) if(v[to] == v[now]) return res; // 隣接色かぶり
	res = 1;
	for(int to:G[now]){ // 隣接点
		if(IX[to] == -1) IX[to] = IX[now] + 1; // 未訪問->彩色順を採番
		if(IX[to] != IX[now] + 1) continue; // 彩色順どおりでない->訪問済み
		ll tmp = 0;
		rep(i, 2){
			v[to] = (v[now] + i+1) % 3; // 隣接点を彩色
			tmp += dfs(to, v); // 隣接点へ
		}
		v[to] = -1; // 無色に戻す
		res *= tmp;
		if (tmp == 0) break;
		// tmp == 0 の時、早期に return してるので
		// IX が振り切れていない事に注意
	}
 	return res;
}

int main(){
	int n, m; cin>>n>> m;
	G.resize(n);
	rep(i, m){
		int a, b; cin>>a>>b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	IX.resize(n, -1);
	vi v(20, -1); // 彩色された点
	ll ans = 1;
	rep(i, n){
		if(IX[i] != -1) continue; // 採番済み->訪問済み
		IX[i] = v[i] = 0; // 開始点の訪問済み＆彩色
		ans *= dfs(i, v) * 3;
	}
	cout<< ans <<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, L;
    cin >> N >> L;
    vector<ll> A(N+3), B(N+2);
    for (ll i = 0; i < N; i++) {
        cin >> A[i+1];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i+1];
    }
    A[0] = 0; A[N+1] = L+1; A[N+2] = L+3; B[N+1] = L+3;

    vector<ll> J(N+2);
    ll tmpj = 0;
    for (int i = 1; i <= N; i++) {
        while(tmpj <= N+1){
            if(B[i] == A[tmpj] - (tmpj - i)){
                J[i] = tmpj;
                break;
            }
            tmpj++;
        }
    }
    if(tmpj == N+2){
        printf("%d\n", -1);
        return 0;
    }
    J[N+1] = N+3;

    ll ans = 0;
    J[0] = -1;
    for (ll i = 1; i <= N; i++) {
        if(J[i] == J[i-1]) continue;
        ll mi, ma; mi = min(i, J[i]); ma = max(i, J[i]);
        ll tmpi = i;
        while(J[tmpi] == J[i]){
            mi = min(mi, tmpi);
            ma = max(ma, tmpi);
            tmpi++;
        }
        ans += ma - mi;
        // printf("%lld %lld %lld\n", J[i], mi, ma);
        ll tmp = 0;
        tmpi = J[i] - 1;
        while(tmpi >= mi && A[tmpi] + 1 == A[tmpi+1]){
            tmp++;
            tmpi--;
        }
        tmpi = J[i] + 1;
        while(tmpi <= ma && A[tmpi-1] + 1 == A[tmpi]){
            tmp++;
            tmpi++;
        }
        // for (int j = mi; j < ma+1; j++) {
        //     if(j == J[i]) continue;
        //     if(A[j] == B[j]){
        //         tmp++;
        //     }
        // }
        ans -= tmp;
    }

    // for (int i = 1; i <= N; i++) {
    //     printf("%lld\n", J[i]);
    // }
    printf("%lld\n", ans);

}


// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int cas;
  cin >> cas;
  while (cas--) {
    int n;
    cin >> n;
    vector<int> a(n), pos(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      --a[i];
      pos[a[i]] = i;
    }
    if (n == 2) {
      if (a[0] == 0) {
        cout << 0 << '\n';
        cout << '\n';
      } else {
        cout << 1 << '\n';
        cout << 1 << '\n';
      }
      continue;
    }
    vector<int> ret;
    auto add =
      [&](int x) {
        ret.push_back(x);
        swap(pos[a[x]], pos[a[x + 1]]);
        swap(a[x], a[x + 1]);
      };
    int k = 0;
    for (int i = n - 1; i >= 0; --i) {
      trace(a, pos, ret, i);
      if (i == 2) {
        while (a[0] != 0 || a[1] != 1 || a[2] != 2) {
          add(k);
          k ^= 1;
        }
        break;
      }
      if (pos[i] == i) continue;
      while (pos[i] % 2 != k) {
        add(k);
        k ^= 1;
      }
      int j = pos[i];
      for (int t = j; t < i; ++t) {
        add(t);
        k ^= 1;
      }
    }
    cout << SZ(ret) << '\n';
    for (int i = 0; i < SZ(ret); ++i) {
      cout << ret[i] + 1 << " \n"[i + 1 == SZ(ret)];
    }
    if (SZ(ret) == 0) cout << '\n';
  }

  return 0;
}

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

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

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

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

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

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

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

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

signed main() {
  init();
  ll N;
  string S;
  cin >> N >> S;
  if (S[0] != S[N - 1]) {
    COUT(1);
    return 0;
  }

  bool ok = false;
  char c = S[0];
  rep2(i, 1, N - 1) {
    if (S[i] != c and S[i + 1] != c) ok = true;
  }

  if (ok) {
    COUT(2);
  } else {
    COUT(-1);
  }

  return 0;
}


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

#define ll long long

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)

#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second

#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>

#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
// constexpr ll mod = 998244353;
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    ll vs = v.size(), vs0 = v[0].size();
    rep(i, vs) {
        rep(j, vs0) {
            if (v[i][j] != INF)
                cout << v[i][j];
            else
                cout << -1;

            if (j != vs0 - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

void make_prime(vector<ll> &ret, ll n) {
    ll x = n;
    for (ll i = 2; i * i <= x; i++) {
        while (n % i == 0) {
            n /= i;
            ret.push_back(i);
        }
    }
    if (n != 1) {
        ret.push_back(n);
    }

    return;
}

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

    ll N;
    cin >> N;
    vll a(N);
    rep(i, N) cin >> a[i];

    vll ans;
    rep(i, N - 1) {
        if (a[i] < a[i + 1]) continue;

        ll see = i + 1;
        while ((see != 0 && a[see] < a[see - 1])) {
            ans.push_back(see - 1);
            swap(a[see], a[see - 1]);
            if (ans.size() >= N) {
                cout << -1 << "\n";
                return 0;
            }
            see--;
            if (see == 0) break;
        }
    }
    // pt_vll(ans);

    if (ans.size() != N - 1) {
        cout << -1 << "\n";
        return 0;
    }
    vector<bool> used(N - 1);
    rep(i, N - 1) {
        if (!used[i])
            used[i] = true;
        else {
            cout << -1 << "\n";
        }
    }

    rep(i, N - 1) { cout << ans[i] + 1 << "\n"; }
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int h, w, a, b;
long long dp[1 << 16][9];
bool ok[16];
void solution() {
  cin >> h >> w >> a >> b;
  int mx = h * w;
  for (int i = 0; i < mx; i ++) {
    if ((i + 1) % w == 0) ok[i] = false;
    else ok[i] = true;
  }
  dp[0][0] = 1;
  for (int msk = 0; msk < (1 << mx); msk ++) {
    int fbit;
    for (int i = 0; i < mx; i ++) if (!(msk >> i & 1)) {
      fbit = i;
      break;
    }
    for (int alr = 0; alr <= a; alr ++) {
      dp[msk ^ (1 << fbit)][alr] += dp[msk][alr];
      if (alr < a) {
        if (ok[fbit] && !(msk >> (fbit + 1) & 1))
          dp[msk ^ (1 << fbit) ^ (1 << (fbit + 1))][alr + 1] += dp[msk][alr];
        if (fbit < mx - w && !(msk >> (fbit + w) & 1)) {
          dp[msk ^ (1 << fbit) ^ (1 << (fbit + w))][alr + 1] += dp[msk][alr];
        }
      }
    }
  }
  cout << dp[(1 << mx) - 1][a];
}
signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1;
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  // cin >> tc;
  while (tc --) { solution(); cout << "\n"; }
}


// Jai Shree Ram

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

int solve(){
 		int k,n,m; cin >> k >> n >> m;

 		vector<int>a(k+1);
 		rep(i,1,k+1){
 			cin >> a[i];
 		}
 		pii p;
 		auto func = [&](int x){
 			int l = 0;
 			int r = 0;
 			for(int i = 1; i <= k; i++){
 				// |bn - am| <= x
 				// [(am-x)/(n),(am+x)(n)]
 				int mx = (a[i]*m + x)/n;
 				int mn = (a[i]*m - x)/n;
 				if(mn*n < a[i]*m - x)mn++;
 				maxs(mn,0LL);
 				r += mx;
 				l += mn;
 			}
 			p = {l,r};
 			return m <= r and m >= l;
 		};
 		int L = 0,R = 1e18;
 		int ans = 0;
 		while(L <= R){
 			int M = (L + R)/2;
 			if(func(M)){
 				ans = M;
 				R = M-1;
 			}
 			else{
 				L = M+1;
 			}
 		}
 		func(ans);
 		int l = p.x;
 		int r = p.y;
 		vector<int>b(k+1);
 		int sum = m;
 		for(int i = 1; i <= k; i++){
 			int mx = (a[i]*m + ans)/n;
			int mn = (a[i]*m - ans)/n;
			if(mn*n < a[i]*m - ans)mn++;
			l -= mn;
			r -= mx;
			// find y in [mn,mx] such that  y >= 0 and m - y >= l and m - y <= r
			//y <= m - l and y >= m - r
			//cout << l << " " << r << endl;
			b[i] = max(max(0LL,sum-r),mn);
			sum -= b[i];
			cout << b[i] << " ";
 		}
 		cout << endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++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; }
using ll = long long;
using pii = pair<int, int>;

using C = complex<double>;
const double gs = 0.000001;

int main(){
    int n;
    cin >> n;
    vector<double> lx(n), ly(n), rx(n), ry(n);
    rep(i,n) cin >> lx[i] >> ly[i];
    rep(i,n) cin >> rx[i] >> ry[i];
    double ljx, ljy, rjx, rjy;
    ljx = ljy = rjx = rjy = 0;
    rep(i,n){
        ljx += lx[i];
        ljy += ly[i];
        rjx += rx[i];
        rjy += ry[i];
    }
    ljx /= n; ljy /= n; rjx /= n; rjy /= n;
    rep(i,n){
        lx[i] -= ljx;
        ly[i] -= ljy;
        rx[i] -= rjx;
        ry[i] -= rjy;
    }
    string ans = "No";
    rep(i,n){
        rep(j,n){
            double llen = sqrt(lx[i]*lx[i] + ly[i]*ly[i]);
            double rlen = sqrt(rx[j]*rx[j] + ry[j]*ry[j]);
            if(abs(rlen-llen) >= gs) continue;
            double lshi = atan2(ly[i], lx[i]);
            double rshi = atan2(ry[j], rx[j]);
            double shi = lshi - rshi;
            bool allMitukata = true;
            rep(j2, n){
                C tani(cos(shi), sin(shi));
                C r(rx[j2], ry[j2]);
                r = r*tani;
                double rx2 = r.real(); // kaitenn
                double ry2 = r.imag();
                bool mitukata = false;
                rep(i2, n){
                    if(abs(lx[i2]-rx2)>=gs || abs(ly[i2]-ry2)>=gs) continue;
                    mitukata = true;
                }
                if(!mitukata) allMitukata = false;
            }
            if(allMitukata) ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define all(c) c.begin(),c.end()
#define deb(x) cout<<"[ "<<#x<<" = "<<x<<"] "
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define f first
#define s second

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

const long long INF=1e18;
const int32_t mod=1e9+7;

const int N=5e5+5;

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

void solve(){

     ll r,x,y;
     cin>>r>>x>>y;

     ll dist = x*x + y*y;

     if(dist < r*r)
     {
         puts("2");
         return;
     }

     ll ng = 1e6 , ok = 0;

     while((ng - ok) > 1){

         ll mid = (ng + ok)/2ll;
         ll u = mid * r;

         if(1ll*u*u >= dist)
         ng = mid;
         else
         ok = mid;

     }

     cout<<ng<<endl;
     return;

}

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

    int  t=1;

    //cin>>t;

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

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	double R, X, Y;

	cin >> R >> X >> Y;

	double dist = sqrt(pow(X, 2) + pow(Y, 2));

	double ans = dist / R;

	if (ans < 1.0) {
		ans = 2;
	}

	cout << ceil(ans) << endl;

	return 0;
}


#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define it(x,b)  for(auto &x:b)
#define NUM 1000000007
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define endl "\n"
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2)%NUM;
    if (b % 2)
        return (((res * res)%NUM)* a)%NUM;
    else
        return (res * res)%NUM;
}
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};//unordered_map<pair<long long, long long>, bool, hash_pair> um;
long long fact(long long n)
{
    long long res = 1;
    for (long long i = 2; i <= n; i++)
        res = (res * i)%NUM;
    return (res)%NUM;
}
bool isPrime(long long n) {
    if (n == 1)return false;
    if (n == 2)return true;
    for (long long i = 2; i * i <= n; i++)
        if (n % i == 0)return false;
    return true;
}
ll ceil(ll a, ll b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return ((a/b)+1);
    }
}
ll min(ll a,ll b)
{
    if(a>b)
    {
        return b;
    }
    return a;
}
ll max(ll a, ll b)
{
    if(a>b)
        return a;
    return b;
}
long long dif(long long a,long long b)
{
    if(a>b)
        return a-b;
    return b-a;
}
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
    long long k=gcd(a,b);
    return (a*b)/k;
}
void read(ll arr[],long long n)
{
    for(long long i=0;i<n;i++)
    {
        cin>>arr[i];
    }
}
void addedge(vector<vector<long long>>&v,long long p1,long long p2) {
    v[p1].push_back({p2});
    v[p2].push_back({p1});
}
bool mycmp(pair<long long ,float>p1,pair<long long ,float>p2)
{
    return p1.first<p2.first;
}
void print(ll arr[],ll n)
{
    for (long long i = 0; i < n; ++i) {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
bool mycmp2(pair<long long ,pair<long long ,long long >>&p1,pair<long long ,pair<long long ,long long >>&p2)
{
    if(p1.second.first==p2.second.first)
    {
        return p1.first>p2.first;
    }
    else
    {
        return p1.second.first<p2.second.first;
    }
}
vector<long long >prime;
void sieveOferatosthenes(long long  MAX)
{
    bool pri[MAX + 1];
    memset(pri, true, sizeof(pri));
    pri[1] = false;

    for (long long  p = 2; p * p <= MAX; p++) {

        // If prime[p] is not changed, then it is a prime
        if (pri[p]) {

            // Set all multiples of p to non-prime
            for (long long  i = p * 2; i <= MAX; i += p)
                pri[i] = false;
        }
    }
    for(long long  i=1;i<=MAX;i++)
    {
        if(pri[i])
        {
            prime.push_back(i);
        }
    }
}
bool mycmp3(pair<long long,long long>&p1,pair<long long,long long>&p2)
{
    if(p1.first==p2.first)
    {
        return p1.second<p2.second;
    }
    return p1.first<p2.first;
}
#define tr first
#define fa second
void solve()
{
    int n;cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        v.push_back(s);
    }
    pair<ll,ll>p[n+1];
    p[0].tr=1;p[0].fa=1;
    for(int i=1;i<=n;i++)
    {
        if(v[i-1]=="AND")
        {
            p[i].tr=p[i-1].tr;
            p[i].fa=p[i-1].tr+2*(p[i-1].fa);
        }
        else
        {
            p[i].fa=p[i-1].fa;
            p[i].tr=p[i-1].fa+2*(p[i-1].tr);
        }
    }
    cout<<p[n].first<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    //cin>>t;
    // WE WILL WIN.
    while(t--)
    {
        solve();
    }
}

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define ll long long
#define MAX 1000005
#define MOD 1000000007
#define EXP 1e-8
#define lowbit(x) (x&-x)
// const int INF = 0x1fffffffffffffff;
const int INF = INT_MAX;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

void dfs(int u, unordered_map<int, int> &cls, vector<vector<int>> &adjl, vector<int> &visited, vector<int> &color, unordered_map<int, int> &no) {
    for (auto &v : adjl[u]) {
        if (visited[v]) continue;
        visited[v] = 1;
        if (cls[color[v]] > 0) no[v] = 1;
        cls[color[v]]++;
        dfs(v, cls, adjl, visited, color, no);
        cls[color[v]]--;
    }
}
int main () {
    ll n, m, x, y;
    ll a, b; ll t, k;
    cin >> n;
    vector<int> color(n+1, -1);
    for (int i = 0; i < n; ++i) cin >> color[i];

    vector<vector<int>> adjl(n+1, vector<int> (0));

    m = n-1;
    for (ll i = 0; i < m; ++i) {
        cin >> a >> b; a--, b--;
        adjl[a].push_back(b);
        adjl[b].push_back(a);
    }

    typedef pair<int, set<int>> dist;
    auto cmp = [](const dist &a, const dist &b) {return a.second > b.second;};
    queue<dist> q;
    vector<dist> dists(n+1);
    vector<int> visited(n+1, 0);

    unordered_map<int, int> pre;
    unordered_map<int, int> no;
    for (ll i = 0; i <= n; ++i)
        dists[i] = make_pair(i, set<int> {});
    x = 0;
    dists[x] = make_pair(x, set<int> {});
    q.push(dists[x]);
    visited[x] = 1;

    unordered_map<int, int> color_cnt;
    color_cnt[color[0]] = 1;
    dfs(0, color_cnt, adjl, visited, color, no);

    for (int i = 0; i < n; ++i) {
        if (no[i] == 1) continue;
        else cout << i+1<<endl;
        // int flag = 1, start_color = color[i], u = i;
        // while (pre.count(u)) {
        //     u = pre[u];
        //     // cout << i << ' ' << u << ' ' << color[u] << ' ' << color[i] <<endl;
        //     if (color[u] == start_color) {
        //         flag = 0; break;
        //     }
        // }
        // if (flag) cout << i+1 <<endl;
    }
    return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")

#include <bits/stdc++.h>

using namespace std ;

const int MAX = 100 + 10 ;

int Sub(int x , int y , int mod)
{
	x -= y ;
	if(x < 0)
		x += mod ;
	return x ;
}

int arr[MAX] ;
int n ;
long long x ;
int dp[2][MAX][MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>x ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	long long ans = 4e18 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		for(int k = 0 ; k < i ; ++k)
		{
			for(int x = 0 ; x <= i ; ++x)
				dp[0][k][x] = dp[1][k][x] = -2e9 ;
		}
		dp[0][0][0] = 0 ;
		for(int j = 1 ; j <= n ; ++j)
		{
			bool now = j & 1 ;
			bool prv = !now ;
			for(int k = 0 ; k < i ; ++k)
			{
				dp[now][k][0] = dp[prv][k][0] ;
				for(int x = 1 ; x <= i ; ++x)
				{
					dp[now][k][x] = max(dp[prv][k][x] , dp[prv][Sub(k , arr[j] % i , i)][x-1] + arr[j]) ;
				}
			}
		}
		if(dp[n&1][x%i][i] >= 0)
			ans = min(ans , (x - dp[n&1][x%i][i]) / (i * 1ll)) ;
	}
	return cout<<ans<<"\n" , 0 ;
}

#include <bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
vector<long long> fact, fact_inv, inv;
void init_nCk(int n){
    fact.resize(n+54);
    fact_inv.resize(n+54);
    inv.resize(n+54);
    fact[0]=fact[1]=fact_inv[0]=fact_inv[1]=inv[1]=1;
    for(int i=2;i<n+54;i++){
        fact[i]=(fact[i-1]*i)%MOD;
        inv[i]=MOD-(inv[MOD%i]*(MOD/i))%MOD;
        fact_inv[i]=(fact_inv[i-1]*inv[i])%MOD;
    }
}
int nCk(int n,int k){
    return fact[n]*((fact_inv[k]*fact_inv[n-k])%MOD)%MOD;
}
int main(){
  #define int long long
  int N,K;
  cin>>N>>K;
  vector<int> A(N),a(N),b(N,1),vec(K+1);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    a.at(i)=2*A.at(i);
  }
  for(int i=0;i<=K;i++){
    int sum=0;
    for(int j=0;j<N;j++){
      sum+=b.at(j);
      sum%=MOD;
      b.at(j)*=A.at(j);
      b.at(j)%=MOD;
    }
    vec.at(i)=sum;
  }
  init_nCk(250);
  for(int i=1;i<=K;i++){//X
    int sum=0;
    for(int j=0;j<=i;j++){//k
      sum+=(((nCk(i,j)*vec.at(j))%MOD)*vec.at(i-j))%MOD;
      sum%=MOD;
    }
    for(int j=0;j<N;j++){
      sum-=a.at(j)-MOD;
      a.at(j)*=2*A.at(j);
      sum%=MOD;
      a.at(j)%=MOD;
    }
    if(sum%2==0){cout<<sum/2<<endl;}
    else{cout<<(sum+MOD)/2<<endl;}
  }
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const int maxn = 1e6 + 5;

int n;
int a[maxn];

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

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

    int g = a[0];
    for (int i=0; i<n; i++) {
	g = __gcd(g, a[i]);
    }

    cout<<g<<endl;

    return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define sz(x) ((int)(x).size())
#define mp make_pair
#define full(a) a.begin(), a.end()
#define pii pair<int, int>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 3e5 + 5;

// printf("%.2f\n", value); digits after decimal
// 'a' - 97
// 'A' - 65

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
    int n; cin >> n;
    map<int, int> mmp;
    for (int i = 0; i < n; i++)
    {
        int a; cin >> a;
        mmp[a]++;
    }
    while (sz(mmp) > 1)
    {
        pii p = *mmp.rbegin();
        int X = p.first, c = p.second;
        p = *mmp.begin();
        int x = p.first;
        mmp.erase(prev(mmp.end()));
        mmp[X - x] += c;
    }
    cout << mmp.begin() -> first;
    return 0;
}


#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")

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

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

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

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

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

void solve() {
	int n, m; cin >> n >> m;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	vector<vector<int>> G(n);
	rep(i, m) {
		int x, y; cin >> x >> y; x--; y--;
		G[x].push_back(y);
	}
	vector<ll> dp(n);
	rep(i, n)dp[i] = INF;
	ll ans = -INF;
	rep(i, n) {
		ans = max(ans, a[i] - dp[i]);
		dp[i] = min(dp[i], a[i]);
		for (int to : G[i])dp[to] = min(dp[to], dp[i]);
	}
	cout << ans << "\n";
}

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

#include<bits/stdc++.h>

using namespace std;

#define int                  long long
#define mod                  1000000007
#define ps(x, y)             fixed << setprecision(y) << x
#define w(x)                 int x; cin >> x; while(x --)
#define mk(arr, n, type)     type *arr = new type[n];
#define gcd(x, y)            __gcd(x, y)
#define len(x)               int(x.size())
#define PI                   3.1415926535897932384626433832795
#define for0(i, n)           for (int i = 0; i < (int)(n); i ++) //0 based indexing
#define for1(i, n)           for (int i = 1; i <= (int)(n); i ++) // 1 based indexing
#define forc(i, l, r)        for (int i = (int)(l); i <= (int)(r); ++i) // l to r inclusive
#define forr0(i, n)          for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n)          for (int i = (int)(n); i >= 1; --i) // reverse 1 base
//short hand for usual tokens
#define pb                   push_back
#define fi                   first
#define se                   second
// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x)               (x).begin(), (x).end() //Forward traversal
#define rall(x)              (x).rbegin, (x).rend() //reverse traversal
// shorthand for common types
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
//static_cast<new_type>(expression)
//swap(a,b)
//sort(a, a + n) sort(all(x))
void solve(){
    int n; cin >> n;
    vector<pair<int, int>> arr1;
    for0(i, n){
        int a, b;
        cin >> a >> b;
        arr1.pb({a, b});
    }
    bool l = false;
    for(int i = 0; i < n; i ++){
        for(int j = i + 1; j < n; j ++){
            for(int k = j + 1; k < n; k ++){
                int a = arr1[i].first, b = arr1[i].second;
                int c = arr1[j].first, d = arr1[j].second;
                int e = arr1[k].first, f = arr1[k].second;
                if((a * (d - f) + c * (f - b) + e * (b - d)) == 0){
                    cout << "Yes" ;
                    l = true;
                    break;
                }
            }
            if(l) break;
        }
        if(l) break;
    }
    if(!l) cout << "No";
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(x) (memset(x,0,sizeof(x)))
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

// head
 int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int __=1;
    //cin>>__;
    while(__--)
    {
        int n;
        cin>>n;
        int a,c,s;
                int num=1e9+5;
        rep(i,0,n)
        {
            cin>>a>>c>>s;
            if(a<s)
                num=min(c,num);
        }
        if(num>1e9)
            cout<<"-1";
        else
        cout<<num<<endl;
    }

}

#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
typedef long long ll;
#define int long long
#define endl "\n"
#define forp(i, x, t) for (int i = x; i < t; i++)
#define forn(i, t) for (int i = t; i >= 0; i--)
#define deb(x) cout << #x << " = " << x << endl
const int mod = 1e9 + 7;

using namespace std;

void solve(){

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

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

    int n;
    cin>>n;
    int time = 0;
    int ans = INT32_MAX;
    while (n--){
        int a,p,x;
        cin>>a>>p>>x;
        time += a;
        x -= a;
        if (x > 0){
            ans = min(ans, p);
        }

    }
    if (ans == INT32_MAX) cout << -1;
    else cout<<ans;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(m == 0)
	{
		for(int i=1; i<=n; ++i)
			printf("%d %d\n",2*i-1,2*i);
		return 0;
	}
	if(m<0 || m>=n-1) return printf("-1"), 0;

	int cur = 1;
	for(int i=1; i<=m+1; ++i)
		printf("%d %d\n",cur+1,cur+2),
		cur += 2;
	printf("1 %d\n",cur+1);
	++cur;

	n -= m+2;
	while(n--)
		printf("%d %d\n",cur+1,cur+2),
		cur += 2;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <numeric> //gcd,lcm c++17
#include <tuple>
#include <iomanip> //setprecision
#include <unordered_map>
#include <chrono>
//#define _GLIBCXX_DEBUG
using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T>
using vv = vc<vc<T>>;
template <typename T>
using PQ = priority_queue<T, vc<T>, greater<T>>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
//typedef __uint128_t Int;
using vi = vc<int>;
using vl = vc<ll>;
using vd = vc<double>;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
#define sz(x) (int)(x).size()
template <class T1, class T2, class Pred = std::less<T2>>
struct sort_pair_second
{
    //sort_pair_second<ll,ll,greater<ll>>()
    bool operator()(const std::pair<T1, T2> &left, const std::pair<T1, T2> &right)
    {
        Pred p;
        return p(left.second, right.second);
    }
};
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
int MOD = 1e9 + 7;
double EPS = 1e-9;
int INF = 2000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
int rdx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int rdy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vl A, B;
int N, M;
vi G[200000];
bool visited[200000] = {};
ll sum1, sum2;

void dfs(int v)
{
    visited[v] = true;
    sum1 += A[v];
    sum2 += B[v];
    for (auto x : G[v])
    {
        if (visited[x])
            continue;
        dfs(x);
    }
}

int main()
{
    cin >> N >> M;
    A.resize(N);
    B.resize(N);
    FOR(i, 0, N)
        cin >> A[i];
    FOR(i, 0, N)
        cin >> B[i];
    FOR(i, 0, M)
    {
        int c, d;
        cin >> c >> d;
        c--, d--;
        G[c].push_back(d);
        G[d].push_back(c);
    }
    FOR(i, 0, N)
    {
        if (visited[i])
            continue;
        sum1 = 0, sum2 = 0;
        dfs(i);
        if (sum1 != sum2)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, q;
int t[4*MAXN];
int a[MAXN];
void build(int v, int tl, int tr){
    if(tl == tr){
        t[v] = a[tl];
    }else{
        int tm = (tl + tr) / 2;
        build(2*v, tl, tm);
        build(2*v + 1, tm + 1, tr);
        t[v] = (t[2*v] ^ t[2*v + 1]);
    }
}

void upd(int v, int tl, int tr, int pos){
    if(tl == tr){
        t[v] = a[tl];
    }else{
        int tm = (tl + tr) / 2;
        if(pos <= tm)
            upd(2*v, tl, tm, pos);
        else
            upd(2*v + 1, tm + 1, tr, pos);
        t[v] = (t[2*v] ^ t[2*v + 1]);
    }
}

int gt(int v, int tl, int tr, int l, int r){
    if(l > r) return 0;
    if(tl == l && tr == r){
        return t[v];
    }else
    {
        int tm = (tl + tr) / 2;
        return (gt(2*v, tl, tm, l, min(tm, r)) ^ gt(2*v + 1, tm + 1, tr, max(tm + 1, l), r));
    }
}

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

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>q;

    for(int i = 0; i < n; i++)
        cin>>a[i];

    build(1, 0, n - 1);

    while(q--){
        int t;
        cin>>t;
        if(t == 1){
            int x, y;
            cin>>x>>y;
            x--;
            a[x] ^= y;
            upd(1, 0, n - 1, x);
        }else{
            int l, r;
            cin>>l>>r;
            cout<<gt(1, 0, n - 1, l - 1, r - 1)<<endl;
        }
    }

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>

/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>

/********define********/
const int MAX = 510000;
const int MOD = 1000000007;

#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)

#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf  INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()

typedef long long int ll;
typedef pair<long long, long long> P;

/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];

ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;

string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>N;cin>>M;

	vector<string>v(M);

	vector<pair<long long, string> > p(M);
	//sort(p.begin(), p.end());
	//sort(p.begin(), p.end(),greater<pair<long long,long long> >());

	rep(j,M){
		cin>>v[j];
	}
	rep(i,M){
		p[i].fi=v[i].size();
		p[i].se=v[i];
	}
	sort(p.begin(), p.end());
	ll check;
	check=0;
	ll i;
	i=0;
	ll flg;
	while(check<N*N && i<M){

		if(check%N!=0){
			if(p[i-1].se[p[i-1].se.size()-1]==p[i].se[0]){
				rep(j,p[i].se.size()-1){
					p[i].se[j]=p[i].se[j+1];
				}
				p[i].se.resize(p[i].se.size()-1);
			}
		}

		if(check%N+p[i].se.size()<=N){
			cout<<p[i].se;
			check+=p[i].se.size();
			if(check%N==0){
				cout<<"\n";
			}
		}
		else{
			while(check%N!=0){
				cout<<".";
				check++;
			}
			cout<<"\n";
		}
		i++;
	}
	re 0;
}


#include <ctime>
#include <deque>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, std::string> origin, std::pair<int64_t, std::string> another){return origin.first > another.first;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true;}return false;}
std::vector<std::string> list;

int main()
{
    //std::vector< std::pair< int64_t, int64_t > > list;
    std::vector< std::string > str_list;
    std::string str1;
    std::string str2;
    int64_t n,k,l,a,b,c;
    std::cin>> a;
    std::cin>> b;
    std::cin>> c;

    if( pow( a, 2 ) + pow( b, 2 ) < pow( c, 2 ) )
    {
        std::cout<< "Yes";
    }
    else
    {
        std::cout<< "No";
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

template <typename F>
class
#if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
  [[nodiscard]]
#endif  // defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard)
FixPoint final : private F
{
public:
  template <typename G>
  explicit constexpr FixPoint(G&& g) noexcept
    : F{std::forward<G>(g)}
  {}

  template <typename... Args>
  constexpr decltype(auto)
  operator()(Args&&... args) const
#if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  noexcept(noexcept(F::operator()(std::declval<FixPoint>(), std::declval<Args>()...)))
#endif  // !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 9
  {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};  // class FixPoint

#if defined(__cpp_deduction_guides)
template <typename F>
FixPoint(F&&)
  -> FixPoint<std::decay_t<F>>;
#endif  // defined(__cpp_deduction_guides)

namespace
{
  template <typename F>
#if !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  #  if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
__attribute__((warn_unused_result))
#  elif defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_Check_return_)
_Check_return_
#  endif  // defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#endif  // !defined(__has_cpp_attribute) || !__has_cpp_attribute(nodiscard)
  inline constexpr decltype(auto)
  makeFixPoint(F&& f) noexcept
  {
    return FixPoint<std::decay_t<F>>{std::forward<std::decay_t<F>>(f)};
  }
}  // namespace

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

	int64 A, B, W;
	cin >> A >> B >> W;
	W *= 1000;
	int64 rmin = INF, rmax = 0;
	REP(i, 1000100) {
	  if (i * A + i * (B - A) >= W && i * A <= W) {
	    chmin(rmin, i);
	  }
	  if (i * B - i * (B - A) <= W && W <= i * B) {
	    chmax(rmax, i);
	  }
	}
	if (rmin == INF) {
	  cout << "UNSATISFIABLE" << endl;
	} else {
	  cout << rmin << " " << rmax << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

using V = vector<int>;
using Q = queue<int>;
using Graph = vector<vector<int>>;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl
#define err(x) cerr<<(x)<<endl
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define YesNo(x) cout<<(x?"Yes":"No")<<endl
#define YESNO(x) cout<<(x?"YES":"NO")<<endl
#define yesno(x) cout<<(x?"yes":"no")<<endl
#define yay(x) cout<<(x?"yay":":(")<<endl

#define deg(_rad) (((_rad)/2/M_PI)*360)
#define rad(_deg) (((_deg)/360)*2*M_PI)
#define mid(min, max) ((min + max) / 2)

bool isComp(const char& c1, const char& c2) {
  if (c1 == 'A') return c2 == 'T';
  if (c1 == 'T') return c2 == 'A';
  if (c1 == 'C') return c2 == 'G';
  if (c1 == 'G') return c2 == 'C';
  return false;
}

int main() {
  in(n);
  V a(n);
  rep(i, n)
    cin >> a[i];

  int max_num = 2;
  int max_gcd = 0;

  for(int i = 2; i <= 1000; i++) {
    int warikireta = 0;
    rep(j, a.size()) {
      if (a[j] % i == 0) ++warikireta;
    }
    if (warikireta > max_gcd) {
      max_gcd = warikireta;
      max_num = i;
    }
  }
  out(max_num);
  return 0;
}

#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 ll 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);
    ll test=1;
    //cin>>test;
    for(ll tt=1;tt<=test;tt++)
    {
        //cout<<"Case #"<<tt<<": ";
        maester();
    }
    #ifdef LOCAL
    cout<<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 v(n);
    cin>>v;
    ll ans=2,maxi=-1;
    for(i=2;i<=1000;i++)
    {
        ll ansi=0;
        for(auto j:v)if(j%i==0)ansi++;
        if(ansi>maxi)
        {
            maxi=ansi;
            ans=i;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b != 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}
ll POW(ll a, ll n){ ll res = 1; while(n > 0){ if(n & 1){ res = res * a; } a *= a; n >>= 1; } return res; }
using P = pair<ll, ll>;

// 0 false, 1 true
// string number to int : -48 or - '0'
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization
// DONT FORGET TO INTIALIZE
// The type of GRID is CHAR. DONT USE STRING
// If the result in local and judge is different, USE CODETEST!!
// (a * b)over flow?   if(a > INF / b){ /* overflow */}

struct UnionFind
{
    vector<long long> d;
    UnionFind(long long n = 0) : d(n, -1)
    {
    }

    //root : -size, not root: root
    long long root(long long x){
        if(d[x] < 0){
            return x;
        }
        return d[x] = root(d[x]);
    }

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

    long long size(long long x){
        return -d[root(x)];
    }

    bool issame(long long a, long long b){
        return root(a) == root(b);
    }
};

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> a(n);
    for(long long i = 0; i < n; i ++){
        cin >> a[i];
    }

    ll ans = INF;
    for(ll bit = 0; bit < (1<<(n-1)); bit++){
        UnionFind uf(n);
        vector<ll> tmp;
        //cout << "{ ";
        for(ll i = 0; i < (n-1); i++){

            if((bit>>i) & 1){
                tmp.push_back(i);
                //cout << i << " ";
            }
        }
        //cout << " }" << endl;

        for(ll i = 0; i < tmp.size(); i++){
            uf.unite(tmp[i], tmp[i]+1);
        }

        //cout << "uf ";
        vector<ll> res(n);
        for(ll i = 0; i < n; i++){
            ll x = uf.root(i);
            res[x] = res[x] | a[i];
            //cout << uf.root(i) << " ";

        }

        ll now = 0;
        rep(i, n){
            now = now ^ res[i];
        }

        //cout << "now = " << now << endl;
        ans = min(ans, now);

    }

    cout << ans << endl;

}

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

const int maxN = 20; int n;
lli a[maxN];

lli solve(int i = 0, lli currOr = 0, lli currXor = 0)
{
  if (i == n) return currXor ^ currOr;

  currOr |= a[i];
  lli ans = min(
    solve(i + 1, 0, currXor ^ currOr),
    solve(i + 1, currOr, currXor)
  );

  return ans;
}

int main()
{
  while (~scanf("%d", &n))
  {
    for (int i = 0; i < n; i++)
      scanf("%lld", &a[i]);

    lli ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}


#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    ll a, b;
    read(a,b);
    ll x = (a + b) / 2;
    ll y = ( a - b) /2 ;
    cout << x << " " << y << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)/2<<" "<<(a-b)/2<<'\n';
}

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


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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        const int N = 100009;

        void solve(){
            cin >> str;
            if(str.size() < 4){
                n = stoi(str);
                if(n%8 == 0){
                    cout << "Yes\n";
                    return;
                }
                if(str.size() == 2){
                    string newOne = str;
                    newOne[0] = str[1];
                    newOne[1] = str[0];
                    n = stoi(newOne);
                    if(n%8 == 0){
                        cout << "Yes\n";
                        return;
                    }
                }
            }

            map<char,int> mp;
            for(char ch : str){
                mp[ch]++;
            }

            for(int i=104; i < 1000; i+= 8){
                string str = to_string(i);
                map<char, int> curr;
                for(char ch : str) curr[ch]++;
                bool flag = true;
                for(auto it : curr){
                    char ch = it.first;
                    int amount = it.second;
                    int amount2 = mp[ch];
                    if(amount > amount2) flag = false;
                }
                if(flag){
                    cout << "Yes\n";
                    return;
                }
            }
            cout << "No\n";

        }

        int main(){
            ios_base::sync_with_stdio(false);

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

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

#define debug(x) cout << #x << ": " << (x) << endl;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> iip;

string s;
int cnt[10] = {0};

bool check(int last_digit) {
    // debug(last_digit);

    if (!cnt[last_digit]) return false;

    --cnt[last_digit];

    int i;
    if (last_digit == 8) i = 0;
    else if (last_digit == 6) i = 1;
    else if (last_digit == 4) i = 2;
    else if (last_digit == 2) i = 3;

    for (; i < 100; i += 4) {
        if (s.length() > 2 && i < 10) continue;

        vector<int> v(cnt, cnt + 10);

        bool f = true;
        string s = to_string(i);
        // debug(s);
        for (auto c : s) {
            // if (c == '0') continue;

            if (!v[c - '0']) {
                f = false;
                break;
            }

            --v[c - '0'];
        }

        if (f) return true;
    }

    ++cnt[last_digit];
    return false;
}

void solve() {
    // string s;
    cin >> s;

    if (s == "8") {
        cout << "Yes\n";
        return;
    }

    for (auto c : s) {
        ++cnt[c - '0'];
    }

    if (check(8) || check(6) || check(4) || check(2)) cout << "Yes\n";
    else cout << "No\n";
}

int main() {
    // For fast I/O
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    return 0;
}


#include "bits/stdc++.h" //custom precompiled stdc++.h header :)
using namespace std;

#define ll                  long long int
#define Print(x)            cout << x << endl
#define PrintAns(x)         cout << x << endl; return
#define PrintPrec(x, y)     cout << fixed << setprecision(y) << x << endl;
#ifdef SUBLIME
#define deb(x)              cout << #x << ": " << x << endl;
#define deb2(x, y)          cout << #x << ": " << x << ", " << #y << ": " << y <<endl
#else
#define deb(x)              //luKaS iS No0b
#define deb2(x, y)          //XD
#endif
#define cint(x)             int x; cin >> x
#define cll(x)              ll x; cin >> x
#define cstring(x)          string x; cin >> x
#define pb                  push_back
#define mp                  make_pair

typedef vector<int>         vi;
typedef vector<ll>          vll;
typedef vector<string>      vs;

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//    cint(n);
//    vi vec(n);
//    for(int i = 0; i < n; i++){
//        cin >> vec[i];
//    }

void test_case() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> b >> a;
        ans += a * (a + 1) / 2 - b * (b + 1) / 2 + b;
    }
    Print(ans);
}

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

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

    long long t = 1;
    ///cin >> t;
    while (t--)
    {
        test_case();
    }

    return 0;
}

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

int main()
{
   ll n,i;
   cin>>n;
   ll A[n];
   ll S=0;
   for(i=0;i<n;i++)
   {
       cin>>A[i];
       S+=A[i];
   }
   sort(A,A+n);
   ll prev=0,ans=0;
   for(i=0;i<n;i++)
   {
       ll p1,p2;
       prev+=A[i];
       p1=(i+1)*A[i]-prev;
       p2=(S-prev)-(n-i-1)*A[i];
       ans+=(p1+p2);
   }
   ans/=2;
   cout<<ans;
}


#include <iostream>
using namespace std;
#define STRMAX 101

int main()
{
    int V, T, S, D;
    char str[STRMAX];
    cin >> V >> T >> S >> D;
    int x_T = V * T;
    int x_S = V * S;
    if(D >= x_T && D <= x_S) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int ans = n*1.08;
    if(206>ans){
        cout << "Yay!" << endl;
    }
    else if(206 == ans){
        cout << "so-so" << endl;
    }
    else{
        cout << ":(" << endl;
    }
}


#include <bits/stdc++.h>
#define rei register int
using namespace std;
const int maxn = 1010;
int h,w;
string s[maxn];
queue<int>q;
int vish[maxn],visw[maxn],cnth = 2,cntw = 2;
void updateh(int x){
	for(rei i = 0;i < w;++i) if(s[x][i] == '#') {
		if(visw[i + 1] == 0){
			visw[i + 1] = 1; q.push(i + 1); ++cntw;
		}
	}
} void updatew(int x){
	--x; for(rei i = 1;i <= h;++i) if(s[i][x] == '#'){
		if(vish[i] == 0){
			vish[i] = 1; q.push(i); ++cnth;
		}
	}
} void bfsh(int x){
	q.push(x); vish[x] = 1;
	while(!q.empty()){
		int x = q.front(); q.pop(); if(vish[x]) updateh(x);
		if(visw[x]) updatew(x);
	}
} void bfsw(int x){
	q.push(x); visw[x] = 1;
	while(!q.empty()){
		int x = q.front(); q.pop(); if(vish[x]) updateh(x);
		if(visw[x]) updatew(x);
	}
} void work(){
	vish[1] = vish[h] = visw[1] = visw[w] = 1;
	updateh(1),updateh(h),updatew(1),updatew(w);
	while(!q.empty()){
		int x = q.front(); q.pop(); if(vish[x]) updateh(x);
		if(visw[x]) updatew(x);
	}
}
int main(){
	ios::sync_with_stdio(false); cin >> h >> w;
	for(rei i = 1;i <= h;++i){
		cin >> s[i] ;
	} int ans = 99999,cnt = 0;
	work(); for(rei i = 1;i <= h;++i) if(!vish[i]) bfsh(i),++cnt; ans = cnt; cnt = 0;
	memset(vish,0,sizeof(vish)),memset(visw,0,sizeof(visw));  work(); for(rei i = 1;i <= w;++i)
	if(!visw[i]) bfsw(i),++cnt ; ans = min(ans,cnt); cout << ans ;
	return 0;
}

#include<bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2")
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define req(i,a,b) for(int i=(a);i>=(b);--i)
#define rep_(i,a,b) for(int i=(a);i<(b).size();++i)
#define F(a) rep(a,1,n)
#define M(a,b) memset(a,b,sizeof a)
#define DC int T;cin>>T;while(T--)
#define ll long long
#define Z(a,b) sort(a+1,a+b+1)
using namespace std;
const unsigned _mod=998244353;
const unsigned mod=1e9+7;
const ll infi=0x3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
void rd(auto &x){x=0;int f=1;char ch=getchar();while(ch<48||ch>57){if(ch==45)f=-1;ch=getchar();}while(ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();x*=f;}
ll ksm(ll x,ll y=mod-2,ll m=mod){ll ret=1;while(y){if(y&1)ret=ret*x%m;y>>=1ll;x=x*x%m;}return ret;}
ll qpow(ll x,ll y){ll ret=1;while(y){if(y&1ll)ret=ret*x;y>>=1ll;x=x*x;}return ret;}
/*
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
    [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
*/
int h,w,fa[2010],s,t;
char c;
unordered_map<int,bool> mp;
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void merge(int x,int y){fa[find(x)]=find(y);}
int main()
{
    cin>>h>>w;
    rep(i,1,h+w) fa[i]=i;
    merge(1,h+1),merge(1,h+w),merge(h,h+1),merge(h,h+w);
    rep(i,1,h) rep(j,1,w) cin>>c,c=='#'&&(merge(i,h+j),1);
    rep(i,1,h) s+=!mp[find(i)],mp[find(i)]=1;
	mp.clear();
	rep(i,h+1,h+w) t+=!mp[find(i)],mp[find(i)]=1;
	cout<<min(s,t)-1<<'\n';
    return 0;
}