//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = 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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    int n;cin>>n;
    string s; cin>>s;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }

    ll ans=r*b*g;
    ll sub=0;
    rep(i,n)for(int j=i; j<n; j++){
        if(s[i]==s[j])continue;
        int k = j*2 - i;
        if(k>=n || s[j]==s[k] || s[k]==s[i])continue;
        sub++;
    }

    cout<<ans - sub<<endl;
    return 0;

}

#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  ll s[200010];
  s[0]=0;
  rep(i,n){
    ll a;
    cin >> a;
    s[i+1]=s[i]+a;
  }

  ll ans=1e18;
  for(int i=2;i<n-1;i++){
    ll *l,*r;
    ll gap;
    l=lower_bound(s+1,s+i+1,s[i]/2+1);
    r=lower_bound(s+i+1,s+n+1,(s[n]+s[i])/2+1);
    rep(j,2){
      rep(k,2){
        gap=max({*l,s[i]-*l,*r-s[i],s[n]-*r})-min({*l,s[i]-*l,*r-s[i],s[n]-*r});
        ans=min(ans,gap);
        l--;
      }
      l+=2;
      r--;
    }
  }
  cout << ans << endl;
}


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

int	main()
{
	int	N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>>	cnt_vec(N + 1, vector<int>(N + 1, 0));
	int	L, R;
	for (int i = 0; i < M; ++i) {
		cin >> L >> R;
		cnt_vec.at(L).at(R) += 1;
	}
	vector<vector<int>>	cumsum(N + 1, vector<int>(N + 1, 0));
	for (int i = N; i > 0; --i) {
		for (int j = 1; j <= N; ++j) {
			cumsum.at(i).at(j) = cnt_vec.at(i).at(j);
			cumsum.at(i).at(j) += cumsum.at(i).at(j - 1);
			if (i < N) {
				cumsum.at(i).at(j) += cumsum.at(i + 1).at(j);
				cumsum.at(i).at(j) -= cumsum.at(i + 1).at(j - 1);
			}
		}
	}
	int	p, q;
	for (int i = 0; i < Q; ++i) {
		cin >> p >> q;
		cout << cumsum.at(p).at(q)  << endl;
	}
}


#include <iostream>
#include <climits>
using namespace std;
#define	int long long
const int INF=1e18;
const int MAX_V=2000;
int v,g[MAX_V][MAX_V],r;
void warshall(){
  for(int k=0;k<v;k++)
    for(int i=0;i<v;i++)
      for(int j=0;j<v;j++) g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
}
signed main(){
  int e;
  cin>>v>>e;
  for(int i=0;i<v;i++) for(int j=0;j<v;j++) g[i][j]=i==j?0:INF;
  for(int i=0,a,b,c;i<e&&cin>>a>>b>>c;i++) g[a][b]=c;
  warshall();
  //for(int i=0;i<v;i++) for(int j=0;j<v;j++) if(INF/2<g[i][j]&&g[i][j]<INF) r++;
  for(int i=0;i<v;i++) if(g[i][i]) r++;
  if(r){
    cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
  }
  for(int i=0;i<v;i++){
    for(int j=0;j<v;j++){
      if(j) cout<<" ";
      if(g[i][j]>=INF/2) cout<<"INF";
      else cout<<g[i][j];
    }
    cout<<endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string s,t;
  cin>>s>>t;
  ll count = 0;
  t.pb('1');
  for (ll i = n; i > 0; i--){
    string a = s.substr(n - i);
    string b = t;
    b.erase(b.begin() + i,b.begin()+n+1);
    if (a == b)
    {
      count = i;
      break;
    }
  }
  print(2 * n - count);
}


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

#define V_MAX 10040
int N,E;
int INF = INT_MAX/4;

struct edge {
    int to,cap,rev;
    edge(int _to, int _cap, int _rev) {to = _to; cap=_cap; rev=_rev;}
};

vector<edge> G[V_MAX];
bool used[V_MAX];

void add_edge(int from, int to, int cap){
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
}

int dfs(int v, int t, int f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap>0){
            int d = dfs(e.to, t, min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used,0,sizeof(used));
        int f = dfs(s,t,INF);
        if(f==0) return flow;
        flow += f;
    }
}

int main(){

    cin>>N;

    int s, t;
    s = 2 * N;
    t = s + 1;

    vector<pair<int,int>> r(N);
    for(int i=0; i<N; i++){
     cin >> r[i].first >> r[i].second;
     add_edge(s, i, 1);
    }

    vector<pair<int,int>> b(N);
    for(int i=0; i<N; i++){
      cin >> b[i].first >> b[i].second;
      add_edge(N+i, t, 1);
    }

    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        if (r[i].first < b[j].first && r[i].second < b[j].second){
          add_edge(i, N+j, 1);
        }
      }
    }

    cout << max_flow(s, t) << endl;
    return 0;
}

#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int pri[N]; bool vis[N];
void init (int n)
{
	for (int i=2; ; i++)
	{
		if (!vis[i]) pri[++pri[0]]=i;
		if (pri[0]==n) break;
		for (int j=1; j<=pri[0]; j++)
		{
			int p=pri[j],k=i*p;
			if (k> 10000) break;
			vis[k]=1;
			if (i%p==0) break;
		}
	}
}
LL lcm (LL x,LL y) { return (!x||!y)?(x+y):(x/__gcd (x,y)*y); }
int n; LL a[1010][1010];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n); init (1000);
	if (n==2) return puts("4 7\n23 10"),0;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++) if ((i+j+1)&1)
			a[i][j]=pri[(i+j)/2]*pri[n+(i-j)/2+(n+1)/2];
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++) if (!a[i][j])
			a[i][j]=lcm (lcm (a[i-1][j],a[i][j-1]),lcm (a[i+1][j],a[i][j+1]))+1;
	for (int i=1; i<=n; i++,putchar('\n'))
		for (int j=1; j<=n; j++,putchar(' '))
			print(a[i][j]);

    return 0;
}


// darksta5's template v2.0

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

class DisjointSet
{
private:
  int _sz, _numSets;
  vector<int> _par, _setSz, _rank;

public:
  DisjointSet(int sz)
  {
    _sz = sz;
    _numSets = sz;
    _setSz.assign(sz, 1);
    _rank.assign(sz, 0);
    _par.assign(sz, 0);
    for (int i = 0; i < sz; i++)
    {
      _par[i] = i;
    }
  }

  int sz()
  {
    return _sz;
  }

  int numSets()
  {
    return _numSets;
  }

  int setSz(int i)
  {
    return _setSz[find(i)];
  }

  int find(int i)
  {
    int x = i;
    while (x != _par[x])
    {
      x = _par[x];
    }

    return _par[i] = x;
  }

  bool isSame(int i, int j)
  {
    return find(i) == find(j);
  }

  void uni(int i, int j)
  {
    if (!isSame(i, j))
    {
      _numSets--;
      int x = find(i);
      int y = find(j);
      if (_rank[x] < _rank[y])
      {
        _par[x] = y;
        _setSz[y] += _setSz[x];
      }
      else
      {
        _par[y] = x;
        _setSz[x] += _setSz[y];
        if (_rank[x] == _rank[y])
        {
          _rank[x]++;
        }
      }
    }
  }
};

ll make_key(int x, int y)
{
  return (ll)x * 200050LL + (ll)y;
}

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

  int n, r1, r2;
  cin >> n >> r1 >> r2;
  DisjointSet ds1(n), ds2(n);

  for (int i = 0; i < r1; i++)
  {
    int x, y;
    cin >> x >> y;
    ds1.uni(x - 1, y - 1);
  }

  for (int i = 0; i < r2; i++)
  {
    int x, y;
    cin >> x >> y;
    ds2.uni(x - 1, y - 1);
  }

  unordered_map<ll, int> cnt;
  for (int i = 0; i < n; i++)
  {
    ll key = make_key(ds1.find(i), ds2.find(i));
    cnt[key]++;
  }

  for (int i = 0; i < n; i++)
  {
    ll key = make_key(ds1.find(i), ds2.find(i));
    if (i < n - 1)
    {
      cout << cnt[key] << " ";
    }
    else
    {
      cout << cnt[key] << endl;
    }
  }
}

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

/*int main(){
  int n, m;
  cin >> n >> m;
  vi vec(n);
  vi num(n);
  rep(i,m){
    int si, ci;
    cin >> si >> ci;
    si -= 1;
    if (vec.at(si) != ci) num.at(si)++;
    vec.at(si) = ci;
  }
  if (num.at(0) != 1 ){
    cout << -1 << endl;
    return 0;
  }
  REP(i,1,n){
    if (num.at(i) > 1){
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i,n){
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}*/

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  rep(i,m) cin >> p.at(i).first >> p.at(i).second;
  rep(i,1000){
    vi d(1, i%10);
    int nx = i / 10;
    while (nx){
      d.push_back(nx%10);
      nx /= 10;
    }
    if ((int)d.size() != n) continue;
    reverse(d.begin(), d.end());
    bool ok = true;
    rep(i,m){
      if (d[p.at(i).first-1] != p.at(i).second) ok = false;
    }
    if (ok){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n, q;
	while (cin >> n >> q, n, q) {
		int mem[110] = {};
		int maxv = -1;
		for (int i = 0; i < n; i++){
			int m; cin >> m;
			for (int j = 0; j < m; j++) {
				int d; cin >> d;
				mem[d]++;
				maxv = max(maxv, d);
			}
		}
		int ans = 0, num = -1;
		for (int i = 0; i <= maxv; i++) {
			if (ans == 0) {
				if (mem[i] >= q) { ans = i; num = mem[i]; }
			}
			else if (mem[i] > num) { ans = i; num = mem[i]; }
		}
		cout << ans << endl;
	}
}

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main (int argc, char *argv[]) {
	int N;
	cin >> N;
	cin.ignore();
	for(int i = 0; i < N; ++i) {
		string str;
		int out_count = 0, base[3] = {0, 0, 0}, point = 0;
		while (true) {
			getline(cin,str);
			if (str == "OUT") out_count++;
			else if (str == "HIT") {
				if (base[2] == 1) {
					point++;
					base[2] = 0;
				}
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
			else if (str == "HOMERUN") {
				point += 1 + count(base,base+3,1);
				memset(base, 0, sizeof base);
			}
			if (out_count == 3) break;
		}
		cout << point << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, r; cin >> n >> r;
  n = min(n, 10);
  cout << r + 100 * (10-n) << endl;
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

void abc_150a();

void abc_151a();

void abc_152a();

void abc_154a();

void abc_156a();

int main()
{
  //abc_150a();
  //abc_151a();
  //abc_152a();
  //abc_154a();
  abc_156a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}

void abc_151a()
{
  char C;
  cin >> C;

  cout << (char)((int)C + 1) << "\n";
}

void abc_152a()
{
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes\n";
  else cout << "No\n";
}

void abc_154a()
{
  string S, T;
  cin >> S >> T;
  int a, b;
  cin >> a >> b;
  string U;
  cin >> U;

  if (S == U) cout << a - 1 << " " << b << "\n";
  else cout << a << " " << b - 1 << "\n";

}

void abc_156a()
{
  int N, R;
  cin >> N >> R;

  if (N >= 10) cout << R << "\n";
  else cout << R + 100 * (10 - N) << "\n";
}


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

int main() {
    uint N; cin >> N;
    vector<int> A(N, 0);
    for (auto &a: A) cin >> a;

    int cnt = 0;
    bool exist = false;
    while (!exist) {
        for (size_t i=0; i<A.size(); ++i) {
            if (A[i] % 2 != 0) {
                exist = true;
                break;
            }
            A[i] /= 2;
        }
        if (!exist) ++cnt;
    }
    cout << cnt << endl;
}

/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

int me(int val) {
	for(int i=1;;i<<=1) {
		if(i&val)return log2(i);
	}
	return log2(val);
}

void solve(int test_case) {//227
	int n;
	cin>>n;
	int mi = 64;
	REP(i,1,n) {
		int val;
		cin>>val;
		mi=min(mi,me(val));
	}
	cout<<mi;
}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}


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

//#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 80 + 1;
const int SIZ = 2 * 6400 + 1;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "1";

int a[siz][siz];
bool f[siz][siz][SIZ];

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int m, n;
    cin >> m >> n;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            int x;
            cin >> x;

            a[i][j] = abs(a[i][j] - x);
        }
    }

    f[1][1][a[1][1]] = true;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 0; k < SIZ; k++) {
                if (f[i][j][k] == true) {
                    if (i < m) {
                        f[i + 1][j][abs(k - a[i + 1][j])] = true;
                        f[i + 1][j][k + a[i + 1][j]] = true;
                    }

                    if (j < n) {
                        f[i][j + 1][abs(k - a[i][j + 1])] = true;
                        f[i][j + 1][k + a[i][j + 1]] = true;
                    }
                }
            }
        }
    }

    for (int k = 0; k < SIZ; k++) {
        if (f[m][n][k] == true) {
            return cout << k << "\n", 0;
        }
    }

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}

#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
bool dp[6410][20000];
int abs(int x,int y){
    if(x>=y) return x-y;
    else return y-x;
}
int main(){
    int h,w;
    cin >> h >> w;
    vector<int> a(h*w), b(h*w);
    rp(i,h*w) cin >> a[i];
    rp(i,h*w) cin >> b[i];
    rp(i,6410){
        rp(j,20000) dp[i][j]=false;
    }
    int m=0;
    rp(i,h*w) m=max(m,abs(a[i],b[i]));
    dp[0][abs(a[0],b[0])]=true;
    for(int i=1; i<h*w; i++){
        int dif=abs(a[i],b[i]);
        if(i%w){
            for(int k=0; k<=(h+w)*m;k++){
                if(dp[i-1][k]){
                    dp[i][abs(k,dif)]=true;
                    if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
                }
            }
        }
        if(i>=w){
            for(int k=0; k<=(h+w)*m;k++){
                if(dp[i-w][k]){
                    dp[i][abs(k,dif)]=true;
                    if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
                }
            }
        }
    }
    int ans;
    int c=0;
    while(1){
        if(dp[h*w-1][c]){
            ans=c;
            break;
        }
        c++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
	int waseda[10];
	int keo[10];
	for(int i = 0; i < 10; i++){
		cin >> waseda[i];
	}
	for(int i = 0; i < 10; i++){
		cin >> keo[i];
	}
	sort(waseda,waseda+10,greater<int>());
	sort(keo,keo+10,greater<int>());

	int sumW=0;
	int sumK=0;
	for(int i = 0; i < 3; i++){
		sumW += waseda[i];
		sumK += keo[i];
	}
	cout << sumW << " " << sumK << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define rep(x, n)          for (int x = 0; x < n; x++)
#define REP(x, a, b)       for (int x = a; x <= b; x++)
#define all(container)     (container).begin(), container.end()
#define rall(container)    (container).begin(), container.end()
#define sz(container)      (int) (container).size()

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

#ifdef LOCAL_DEFINE
    #include "DEBUG.hpp"
#else
    #define debug(...) 0
#endif
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(void) {
    int n,m;
    scanf("%d%d",&n,&m);
    if(m&1){
        int end=2*m+1;
        REP(i,m+1,3*m/2+1)
            printf("%d %d\n",i,end-i+m+1);
        end=m;
        REP(i,1,m/2)
            printf("%d %d\n",i,end-i+1);
    }else{
        int end=2*m+1;
        REP(i,m+2,3*m/2+1)
            printf("%d %d\n",i,end-i+m+2);
        end=m+1;
        REP(i,1,m/2)
            printf("%d %d\n",i,end-i+1);
    }
    return 0;
}


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

int main(void){
   int N;
   cin>>N;
   vector<char> S(N);
   for(int i=0;i<N;i++){
      cin>>S[i];
   }
   int ans=0;
   vector<int> E(N+1);
   vector<int> W(N+1);
   E[0]=0;
   W[0]=0;
   for(int i=0;i<N;i++){
      if(S[i]=='E'){
         E[i+1]=E[i]+1;
      }else{
         E[i+1]=E[i];
      }
      if(S[i]=='W'){
         W[i+1]=W[i]+1;
      }else{
         W[i+1]=W[i];
      }
   }
   ans=N;
   for(int i=0;i<N;i++){
      int result=W[i+1]+E[N]-E[i]-1;
      ans=min(result,ans);
   }
   cout<<ans<<endl;
   return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}

    ll N; cin>>N;
    ll cnt=0,ans=INF;
    string s; cin>>s;

    //EEEEEEEEEEEEEEEEE
    rep(i,sz(s)){
        if(s[i]=='W') cnt++;
    }
    ans=cnt;

    rrep(i,sz(s)){
        if(s[i]=='W') cnt--;
        else cnt++;
        chmin(ans,cnt);
    }

    cout<<ans<<endl;
}


/*                                  /   \                                                                   (Hello)//JSM//*/
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<bits/stdc++.h>
#include<cstring>
#include<map>
#include<cmath>
#include<set>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())
#define all(v )  v.begin(), v.end()
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char>
#define vll vector< pair<ll,ll> >
#define mps map<string ,ll>
#define mpc map<char ,ll>
#define mpl map<ll, ll>
#define pr pair<ll,ll>
#define tpl tuple<ll,ll,ll>
ll containsDigit(ll number, ll digit){while (number != 0){int curr_digit = number % 10;if (curr_digit == digit) return 1;number /= 10;}return 0;}
ll soltn(ll x, ll n) {if(x>=0) return x%n;    else return n+x%n;}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}
ll coda(ll n,ll d){ll count=0;while(n!=0){if(n%10==d)count++;n/=10;}return count;}
ll mdls(ll x){return max(x,-x);}
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x%MOD*x%MOD)%MOD;if(p%2==0) return x;else return (x*n)%MOD;}
ll isSubstr(string s1, string s2) {   ll M = s1.length();    ll N = s2.length();  for (ll i = 0; i <= N - M; i++) { ll j; for (j = 0; j < M; j++) if (s2[i + j] != s1[j])  break;         if (j == M) return i;   } return -1; }
//s2>s1;if(not) rtrn -1;

ll maxSubArraySum(ll a[], ll size)
{
   ll max_so_far = a[0];
   ll curr_max = a[0];

   for (ll i = 1; i < size; i++)
   {
        curr_max = max(a[i], curr_max+a[i]);
        max_so_far = max(max_so_far, curr_max);
   }
   return max_so_far;
}

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
	  ll tt=1;

//	   cin>>tt;
	      while(tt--)
{

/*
3 2 3*/
ll n,j,i;
ll a[3];
fo(i,3)
cin>>a[i];
sort(a,a+3);
cout<<a[0]+a[1];
ee;

}
return 0;
}

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

int main(){
  int A;
  int B;
  int C;
  cin >> A;
  cin >> B;
  cin>> C;
  vector <int> seged_vector;
  seged_vector.push_back(A+B);
  seged_vector.push_back(A+C);
  seged_vector.push_back(B+A);
  seged_vector.push_back(B+C);
  seged_vector.push_back(C+A);
  seged_vector.push_back(C+B);
  int seged=seged_vector[0];
  for(int i=1;i<seged_vector.size();i++){
    if(seged>seged_vector[i]){
      seged=seged_vector[i];
    }
  }
  cout << seged;
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

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

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << '\n';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    ll n,m; cin >> n >> m;
    vector<vector<ll>> graph(n);
    vector<ll> ans(n, INF), in(n, 0);

    rep(i,n - 1 + m) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        // graph[b].emplace_back(a);
        in[b]++;
    }
    ll root;
    rep(i,n)if(in[i] == 0){
        root = i;
        ans[root] = 0;
    }
    // print(in);
    queue<Pll> que;
    que.push(Pll(root, 0));
    while(!que.empty()){
        Pll t = que.front();que.pop();
        for(auto to : graph[t.first]){
            if(in[to] == 1){
                ans[to] = t.first + 1;
                que.push(Pll(to, t.second + 1));
            }
            in[to]--;
        }
    }

    print(ans);
}

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class Graph {
public:
    int N;
    vector<vector<int>> G;
    vector<bool> visit;
    vector<int> cir;
    vector<int> exist;

    Graph(int N) : N(N) {
        G.resize(N);
        visit.resize(N, false);
        exist.resize(N, -1);
    }

    void add_edge(int s, int t){
        G[s].push_back(t);
    }

    bool dfs(int n, int s){
        if(n == s && visit[n]){
            return true;
        }
        if(visit[n]){
            return false;
        }

        visit[n] = true;
        for(int i = 0; i < (int)G[n].size(); i++){
            int nx = G[n][i];
            if(dfs(nx, s)){
                cir.push_back(n);
                return true;
            }
        }

        return false;
    }

    void solve(){
        //0 ~ N-1について自身に戻れるかdfsをN回
        bool found = false; //閉路があるか

        for(int i = 0; i < N; i++){
            fill(visit.begin(), visit.end(), false);
            if(dfs(i, i)){
                found = true;
                break;
            }
        }

        if(!found){
            cout << -1 << endl;
            return;
        }

        reverse(cir.begin(), cir.end());

        while(true){
            //debug
            /*
            cout << "cir = ";
            for(int val : cir){
                cout << val + 1 << " ";
            }
            cout << endl;
            */

            //閉路上の点かどうかを示すexist更新
            fill(exist.begin(), exist.end(), -1);
            for(int i = 0; i < (int)cir.size(); i++){
                exist[cir[i]] = i;
            }

            cir.push_back(cir[0]);

            bool check = false;
            for(int i = 0; i < (int)cir.size() - 1; i++){
                int n = cir[i];
                for(int j = 0; j < (int)G[n].size(); j++){
                    int nx = G[n][j];
                    if(exist[nx] >= 0 && nx != cir[i + 1]){
                        //閉路作り直し
                        check = true;

                        vector<int> tmp;
                        if(exist[n] < exist[nx]){
                            for(int k = 0; k < (int)cir.size() - 1; k++){
                                if(k <= exist[n] || exist[nx] <= k) tmp.push_back(cir[k]);
                            }
                        } else {
                            //cout << "hoge" << endl;
                            for(int k = exist[nx]; k <= exist[n]; k++){
                                tmp.push_back(cir[k]);
                            }
                        }

                        cir = tmp;
                        break;
                    }
                }

                if(check) break;
            }

            if(!check) break;
        }

        cout << cir.size() - 1 << endl;
        for(int i = 0; i < (int)cir.size() - 1; i++){
            cout << cir[i] + 1 << endl;
        }

        return;
    }
};

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

    Graph gr = Graph(N);

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        gr.add_edge(a - 1, b - 1);
    }

    gr.solve();
    return 0;
}


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

void printChess(int chess[]){
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			if(j == chess[i])
				cout<<"Q";
			else
				cout<<".";
		}
		cout<<endl;
	}
}

bool isBlank(int chess[], int &r){
	for(int i=0;i<8;i++){
		if(chess[i] == 100){
			r = i;
			return true;
		}
	}
	return false;
}

bool setQ(int chess[], int r, int c){
	for(int i=0;i<8;i++){
		if(chess[i] == c)
			return false;
		if(i+chess[i] == r+c)
			return false;
		if(i-chess[i] == r-c)
			return false;
	}
	return true;
}

void solve(int chess[]){
	int r;
	if(isBlank(chess, r)){
		for(int c=0;c<8;c++){
			if(setQ(chess, r, c)){
				chess[r] = c;
				solve(chess);
				chess[r] = 100;
			}
		}
	}else{
		printChess(chess);
	}
}

int main(){
	int k, r, c, chess[8];

	for(int i=0;i<8;i++)
		chess[i] = 100;

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

	solve(chess);

	return 0;
}

// Phttps://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
const ll tl= 1'000'000'007;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
ll n=8;
vvl bd(n,vl(n,0));
vvl memo(n); //-1,0,1
vector<pair<ll,ll>>A;

void queen_dfs(int cnt, int p,vvl bd, vvl old_memo){
    bd[cnt][p]=1;
    if(cnt==n-1){
        int f=1;
        each(x,A){
            if(!bd[x.first][x.second]) f=0;
        }
        if(f){
            REP(i,n){
                REP(j,n){
                    cout << ((bd[i][j])?"Q":".");
                }out();
            }
        }
        return;
    }
    //memo 更新
    vvl new_memo(n);
    REP(j,n){
        REP(t,old_memo[j].size()){
            ll x= j+old_memo[j][t];
            if(0<=x && x<n) new_memo[x].pb(old_memo[j][t]);
        }
    }
    // bd
    REP(i,n){
        if(!new_memo[i].size()){
            vvl n_memo= new_memo;
            n_memo[i].pb(-1);
            n_memo[i].pb(0);
            n_memo[i].pb(1);
            queen_dfs(cnt+1, i, bd, n_memo);
        }
    }
}
int main(){
    init();
    inl(k);
    A.resize(k);
    REP(i,k){
        inl(r,c);
        A[i]= {r,c};
    }

    REP(i,n){
        vvl memo(8);
        memo[i].pb(-1);
        memo[i].pb(0);
        memo[i].pb(1);
        queen_dfs(0,i,bd,memo);
    }
}


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

int main(){
  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i, n) a.at(i) = l + i;
  sort(ALL(a), [](const auto &l1, const auto &l2){
    return abs(l1) < abs(l2);
  });
  int ans = 0;
  rep2(i, 1, n) ans += a.at(i);
  cout << ans << endl;
  return 0;
}

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n,l;
    cin >> n >> l;
    int a[n];
    for(int i=0;i<n;i++){
        a[i] = l+i;
    }
    int c=1;
    if(a[0]<0) c=0;
    int m = abs(a[0]);
    for(int i=0;i<n;i++){
        if(m>abs(a[i])){
            if(a[i]>=0){
                c=1;
            }else{
                c=0;
            }
            m = abs(a[i]);
        }
    }

    int sum =0;
    for(int i=0;i<n;i++){
        sum += a[i];
    }
    if(c){
        cout << sum-m << endl;
    }else{
        cout << sum+m << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N=305;
#define fi first
#define se second
typedef pair<int,int>P;
priority_queue<P>que;
int n,m,b[N],vi[N],cnt[N],a[N][N];
bool check(int mid){
	while(!que.empty())	que.pop();
	for(int i=1;i<=m;i++)	b[i]=0;
	for(int i=1;i<=n;i++)	++b[a[i][cnt[i]=1]];
	for(int i=1;i<=m;i++)	vi[i]=0,que.push(P(b[i],i));
	while(!que.empty()){
		P x=que.top();	que.pop();
		if(vi[x.se])	continue;
		if(x.fi<=mid)	return true;

		vi[x.se]=1;
		for(int i=1;i<=n;i++){
			if(a[i][cnt[i]]!=x.se)	continue;
			while(vi[a[i][cnt[i]]]&&cnt[i]<=m)	++cnt[i];
			if(cnt[i]>m)	return false;
			que.push(P(++b[a[i][cnt[i]]],a[i][cnt[i]]));
		}
	}
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid))	r=mid;
		else	l=++mid;
	}
	printf("%d\n",l);
	return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
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 main() {
  int N, M; cin >> N >> M;

  vector<queue<int>> A(N, queue<int>());
  rep(i, N) rep(j, M) {
    int a; cin >> a;
    A[i].push(a);
  }

  set<int> used;
  int ans = N;
  rep(i, M) {
    map<int, int> count;
    rep(j, N) {
      while (!A[j].empty() && used.find(A[j].front()) != used.end())
        A[j].pop();
      ++count[A[j].front()];
    }
    int max_count = 0, max_num;
    for (const auto& e : count) {
      int num = e.first, count = e.second;
      if (chmax(max_count, count))
        max_num = num;
    }
    chmin(ans, max_count);
    used.insert(max_num);
  }
  cout << ans << endl;

  return 0;
}


// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++)
  for (int j = 0; j <= n - i; j++) {
    int k = n - i - j;
    if (10000 * i + 5000 * j + 1000 * k == y) {
      cout << i << ' ' << j << ' ' << k << '\n';
      return;
    }
  }
  cout << "-1 -1 -1" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++)
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n, y;
ll count(ll mon){
    ll cnt = y / mon;
    y %= mon;
    return cnt;
}

int main() {
    cin >> n >> y;
    vector<ll> a(3, 0);
    a[2] = count(10000);
    a[1] = count(5000);
    a[0] = count(1000);
    ll d = n - (a[0]+a[1]+a[2]);
    if (d<0){
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }
    ll val = min(a[2], d/9);
    a[0] += val*10;
    a[2] -= val;
    d -= val*9;
    val = min(a[1], d/4);
    a[0] += val*5;
    a[1] -= val;
    d -= val*4;
    val = min(a[2], d);
    a[1] += val*2;
    a[2] -= val;
    d -= val;
    if (d!=0){
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }
    cout << a[2] << " " << a[1] << " " << a[0] << endl;
    //printf("%.12f", ans);
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int sum = 0;
    int mini = 101;
    for (int i = 0; i < 4; ++i) {
        int s;
        cin >> s;
        sum += s;
        mini = min(s, mini);
    }
    int s1, s2;
    cin >> s1 >> s2;
    cout << sum - mini + max(s1, s2) << '\n';
}

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n){
    cin >> a[i];
  }
  int k=1000000;
  int ans=0;
  rep(i,n){
    k=min(k,a[i]);
    if(k==a[i]){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;

const int mod = 1000000007  ;
const int inf = 100005;
const int N = 3e5, M = N;
ll i,j,n,m,idx,cnt;
char d[31][31];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};

void solve() {
 ll n;
 cin>>n;

 vl vec(61);
 ll ans = 0,x;
 cin>>x;
 fo(i,0,61) {
    if(x & (1LL<<i)) vec[i]++;
 }
 ll k;
 fo(i,1,n) {
    cin>>x;
    fo(j,0,61) {
        if(x & (1LL<<j)) {
            k = i - vec[j];
            ans = (ans%mod + ((1LL<<j)%mod * k%mod)%mod)%mod;
            vec[j]++;
        }
        else {
            k = vec[j];
            ans = (ans%mod + ((1LL<<j)%mod * k%mod)%mod)%mod;
        }
    }

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

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

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

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
void solve() {
	int n;
	cin >> n;
	map<int,set<int> > L, R, U, D;
	map<int, set<int> > L2, R2, U2, D2;
	map<int, set<int> > L3, R3, U3, D3;
	rep(i, 0, n) {
		int x, y;
		char dir;
		cin >> x >> y >> dir;
		if (dir == 'U') {
			U[x].insert(y);
			U2[x + y].insert(y);
			U3[x - y].insert(y);
		}
		if (dir == 'D') {
			D[x].insert(y);
			D2[x + y].insert(y);
			D3[x - y].insert(y);
		}
		if (dir == 'L') {
			L[y].insert(x);
			L2[x + y].insert(y);
			L3[x - y].insert(y);
		}
		if (dir == 'R') {
			R[y].insert(x);
			R2[x + y].insert(y);
			R3[x - y].insert(y);
		}
	}
	int dis = INT_MAX, dis2 = INT_MAX;
	for (auto m : U) {
		set<int> up = m.second;
		set<int> down = D[m.first];
		for (auto y : up) {
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis = min(dis, (*it) - y);
			}
		}
	}
	for (auto m : R) {
		set<int> right = m.second;
		set<int> left = L[m.first];
		for (auto x : right) {
			auto it = left.lower_bound(x);
			if (it == left.end()) {
				break;
			}
			else {
				dis = min(dis, (*it) - x);
			}
		}
	}
	for (auto m : L2) {
		int sum = m.first;
		set<int> left = m.second;
		for (auto y : left) {
			set<int> down = D2[sum];
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : R3) {
		int diff = m.first;
		set<int> right = m.second;
		for (auto y : right) {
			set<int> down = D3[diff];
			auto it = down.lower_bound(y);
			if (it == down.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : U2) {
		int sum = m.first;
		set<int> up = m.second;
		for (auto y : up) {
			set<int> right = R2[sum];
			auto it = right.upper_bound(y);
			if (it == right.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	for (auto m : U3) {
		int diff = m.first;
		set<int> up = m.second;
		for (auto y : up) {
			set<int> left = L3[diff];
			auto it = left.upper_bound(y);
			if (it == left.end()) {
				break;
			}
			else {
				dis2 = min(dis2, (*it) - y);
			}
		}
	}
	if (dis == INT_MAX && dis2 == INT_MAX) {
		cout << "SAFE" << endl;
	}
	else {
		int ans = INT_MAX;
		if (dis != INT_MAX) {
			ans = min(ans, dis * 5);
		}
		if (dis2 != INT_MAX) {
			ans = min(ans, dis2 * 10);
		}
		cout << ans << endl;
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}


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

int main()
{
    int N, K, x;
    cin >> N;
    cin >> K;
    x = 1;
    for (int i = 0; i < N; ++i)
    {
        if (x * 2 < x + K)
        {
            x = x * 2;
        }
        else
        {
            x = x + K;
        }
    }
    cout << x << endl;
}

//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N;
	cin >> N;
	string s;
	cin >> s;
	ll ans = 0;
	rep(bits,0,1<<N) {
		string zeros;
		string ones;
		rrep(i,N,0) {
			if (bits & (1 << i)) {
				ones.push_back(s[i]);
			} else {
				zeros.push_back(s[i]);
			}
		}
		/*
		if (bits == 1) {
			cout << "zeros:" << zeros << endl;
			cout << "ones:" << ones << endl;
		}
		*/
		auto dp = make_vec_nd(0, 1+zeros.size(), 1+ones.size());
		dp[0][0] = 1;
		rep(n,1,N+1) {
			rep(z,0,min((ll)zeros.size(),n)+1) {
				ll o = n - z;
				if (o > ones.size()) {
					continue;
				}
				if (z >= 1 && s[2*N-n] == zeros[zeros.size()-z]) {
					dp[z][o] += dp[z-1][o];
				}
				if (o >= 1 && s[2*N-n] == ones[ones.size()-o]) {
					dp[z][o] += dp[z][o-1];
				}
				// cout << z << "," << o << ":" << dp[z][o] << endl;
			}
		}
		ans += dp[zeros.size()][ones.size()];
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll unsigned long long
#define MOD 1000000007
using namespace std;
ll a[2000005];
ll S[2000005];
ll add(ll a,ll b){
	return (a%MOD+b%MOD)%MOD;
}
ll mul(ll a,ll b){
	return (a%MOD*b%MOD)%MOD;
}
int main(){
	int n ;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	S[1] = a[1];
	for(int i=2;i<=n;i++){
		S[i] = add(S[i-1],a[i]);
	}
	ll ans = 0;
	for(int i=1;i<=n-1;i++){
		// 注意大整数取模的时候需要先加上MOd防止暴毙。
		ans = add(ans,mul(a[i],(S[n]-S[i]+MOD)%MOD))%MOD;
	}
	cout<<ans;
//
//	ull n,sum = 0;
//    cin >> n;
//    for(int i = 1;i <= n;i++) cin >> arr[i];
//    for(int i = 1;i <= n;i++) ans[i] = (arr[i]+ans[i-1]);
//    for(int i = 1;i <= n;i++) sum = ((sum + arr[i]*((ans[n]-ans[i])%mod))%mod)%mod;
//    cout << sum << endl;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;
int main()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    ll s1 = 0, s2 = 0;
    for (int i=0; i<n; i++) {
        cin>>a[i];
        s1 += a[i];
        s2 += (a[i] * a[i]);
        s1 %= mod;
        s2 %= mod;
    }
    ll res = (s1 * s1 - s2);
    res %= mod;
    while (res < 0) res += mod;
    ll ans;
    if (res % 2) ans = (res + mod) / 2;
    else ans = res / 2;

    cout << ans << '\n';
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int x,y,ans=0; cin>>x>>y;
    if(x<=3) ans+=(4-x)*100000;
    if(y<=3) ans+=(4-y)*100000;
    if(x==1 && y==1) ans+=400000;
    cout<<ans<<endl;
}

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

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


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

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

    int x,y;
    ll cnt=0;
    cin >> x >> y;
    if(x>=0 && y>=0){
        if(x>y){
            x=0-x;
            ++cnt;
            while(1){
                if(abs(x)==abs(y)) break;
                ++x; ++cnt;
            }
            if(y!=0) ++cnt;
        }else{
            while(1){
                if(x==y) break;
                ++x; ++cnt;
            }
        }
    }else if(x<0 && y<0){
        if(abs(x)>=abs(y)){
            while(1){
                if(x==y) break;
                ++x; ++cnt;
            }
        }else{
            x=0-x;
            ++cnt;
            while(1){
                if(abs(x)==abs(y)) break;
                ++x; ++cnt;
            }
            ++cnt;
        }
    }else if(x<0 && y>=0){
        if(abs(x)<=abs(y)){
            x=0-x;
            ++cnt;
        }
        while(1){
            if(abs(x)==abs(y)) break;
            ++x; ++cnt;
        }
        if(x!=y) ++cnt;
    }else if(x>=0 && y<0){
        if(abs(x)<abs(y)){
            while(1){
                if(abs(x)==abs(y)) break;
                ++x; ++cnt;
            }
            ++cnt;
        }else{
            x=0-x;
            ++cnt;
            while(1){
                if(x==y) break;
                ++x; ++cnt;
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;

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

    if(a == 0){
        if(b < 0) cout << abs(b) + 1 << endl;
        else cout << abs(b) << endl;
    }else if(b == 0){
        if(a < 0) cout << abs(a) << endl;
        else cout << abs(a) + 1 << endl;
    }else if(0 < a && 0 < b){
        if(a < b){
            cout << b - a << endl;
        }else{
            cout << abs(b - a) + 2 << endl;
        }
    }else if(a < 0 && b < 0){
        if(abs(a) < abs(b)){
            cout << abs(b) - abs(a) + 2 << endl;
        }else{
            cout << abs(a) - abs(b) << endl;
        }
    }else if(a < 0 && 0 < b){
        if(abs(a) < b){
            cout << b - abs(a) + 1 << endl;
        }else{
            cout << abs(a) - b + 1 << endl;
        }
    }else if(0 < a && b < 0){
        if(a < abs(b)){
            cout << abs(b) - a + 1 << endl;
        }else{
            cout << a - abs(b) + 1 << endl;
        }
    }

    return 0;
}


#include <iostream>
using namespace std;
static const int MAX = 101;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim()
{
    int u, mincost;
    int d[MAX], p[MAX], color[MAX];
     for(int i=0; i<MAX; i++)
     {
         color[i] = WHITE;
         d[i] = INFTY;
         p[i] = -1;
     }
     d[0] = 0;
     while(1)
     {
         mincost = INFTY;
         for(int i=0; i<n; i++)
         {
             if(color[i] != BLACK && d[i] < mincost)
             {
                 mincost = d[i];
                 u = i;
             }
         }
         if(mincost == INFTY)
                break;
         color[u] = BLACK;
         for(int v=0; v<n; v++)
         {
             if(color[v] != BLACK && M[u][v] != -1)
             {
                 if(M[u][v] < d[v])
                 {
                     d[v] = M[u][v];
                     p[v] = u;
                     color[v] = GRAY;
                 }
             }
         }
     }
     int sum = 0;
     for(int i=0; i<n; i++)
     {
         if(p[i] != -1)
            sum += M[i][p[i]];
     }
     return sum;
}
int main()
{
     cin >> n;
     int e;
     for(int i=0; i<n; i++)
     {
         for(int j=0; j<n; j++)
         {
             cin >> e;
             if(e == -1)
                M[i][j] = INFTY;
             else
                M[i][j] = e;
         }
     }
     cout << prim() << endl;
     return 0;
}

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

int p[100];
pair<int, int> a[10000];

int root( int m ) {
	if ( p[m] != m )
		p[m] = root( p[m] );
	return p[m];
}

void unit( int x, int y ) {
	p[root( y )] = root( x );
}

bool same( int x, int y ) {
	return root( x ) == root( y );
}

int main() {
	int n, ai, pn, ans;
	cin >> n;
	for ( int i = 0; i < n * n; i++ ) {
		cin >> ai;
		if ( ai == -1 || i % n <= i / n )
			ai = 2001;
		a[i] = make_pair( ai, i );
	}
	sort( a, a + ( n * n ) );
	pn = 0;
	ans = 0;
	for ( int i = 0; i < n; i++ )
		p[i] = i;
	for ( int i = 0; i < n * n; i++ ) {
		if ( ! same( a[i].second % n, a[i].second / n ) ) {
			ans += a[i].first;
			pn++;
			unit( a[i].second % n, a[i].second / n );
			if ( pn >= n - 1 ) break;
		}
	}
	cout << ans << endl;
}


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

using namespace std;

#define ll long long

const ll mod  = 1e9 + 7;
const ll INF = 1e14;

void solve(){

    int n; cin >> n;
    string s; cin >> s;

    if(s.length() <= n) cout << s;
    else cout << s.substr(0, n) << "...";

}

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

    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();
    //}

	return 0;
}

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
    cout << a << endl;
    exit(0);
}

void Main()
{
    ll n; cin >> n;
    str ans;
    while(n)
    {
        n--;
        ans.pb((char)(n % 26 + 'a'));
        n /= 26;
    }
    reverse(all(ans));
    fin(ans);
}

//前処理
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10); //高精度少数表示
    Main();
    return 0;
}


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

struct node
{
    ll x;
    ll y;
};
node a[5007];
int n;

bool cmp(node p,node q)
{
    if (p.x+p.y==q.x+q.y) return p.y<q.y;
    return p.x+p.y<q.x+q.y;
}
int main(){
    ios::sync_with_stdio(false);
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    scanf("%lld%lld",&a[i].x,&a[i].y);

    priority_queue<int>q;
  //  n=n+1;
  //  a[n].x=1e9+10;
  //  a[n].y=1e9+10;
    sort(a+1,a+n+1,cmp);

    ll tmp=0;

    ll t=0;
    int ans=0;
    for (int i=1;i<=n;i++)
    {
       // cout<<ans<<" "<<a[i].x<<a[]
        if (tmp<=a[i].x)
        {
            tmp+=a[i].y;
            q.push(a[i].y);
            ans++;
        }
        else
        {
            if (a[i].y<q.top())
            {
                tmp-=q.top();
                q.pop();
                tmp+=a[i].y;
                q.push(a[i].y);
            }
        }

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

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 5010;
const ll INF = 1e18;
ll dp[N][N];

int main() {
    int n;
    cin >> n;
    vector<PL> a(n);
    REP(i,n){
        cin >> a[i].first >> a[i].second;
        a[i].first += a[i].second;
    }
    sort(ALL(a));
    VL h(n), p(n);
    REP(i,n){
        h[i] = a[i].first - a[i].second;
        p[i] = a[i].second;

        // cout << h[i] << " " << p[i] << endl;
    }

    REP(i,n+1) REP(j,n+1) dp[i][j] = INF;

    dp[0][0] = 0;
    REP(i,n) REP(j,n){
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        if (dp[i][j] <= h[i]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p[i]);
    }

    int ans = 0;
    REP(i,n+1) if (dp[n][i] < INF) ans = i;
    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n; cin >> n; cout << n / 3;

}

#include <bits/stdc++.h>

using namespace std;

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; 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; }

const long long INF = 1LL << 60;
#define PI 3.14159265359

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

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

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

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int collatz(int n){
    int a=n;
    if(a%2 == 0)a/=2;
    else a = a*3+1;
    return a;
}

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

    if(R<1200)cout << "ABC" << endl;
    else if (R>=1200 && R<2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;

}


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

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;

    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

vector<int> enum_prime(int n){   // containing n
    vector<int> res;
    if (n <= 1) return res;
    vector<bool> p(n + 1);
    fill(p.begin() + 2, p.end(), true);
    for(int i = 2; i <= n; i++){
        if(p[i]){
            res.push_back(i);
            for(int j = i * 2; j <= n; j += i) p[j] = false;
        }
    }
    return res;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> prime = enum_prime(100000);
    Combination com(150000);
    ll ans = 1;
    for(int p : prime){
        int k = 0;
        while(m % p == 0){
            m /= p;
            k++;
        }
        ans = ans * com.com(n + k - 1, k) % MOD;
    }
    if(m > 1) ans = ans * n % MOD;
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    if(A > B) {
        ans += A;
        A--;
    }
    else{
        ans += B;
        B--;
    }

    ans += max(A, B);
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
//template
int black[2005][2005],ver[2005][2005],wid[2005][2005];
//main
signed main(){
  int N,M,Q;cin>>N>>M>>Q;
  std::vector<string> s(N+1);
  for(int i=0;i<N;i++)cin>>s[i];
  s[N]=(string(M,'#'));
  for(int i=0;i<=N;i++)s[i]+="#";
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(s[i][j]=='1')black[i+1][j+1]++;
      if(s[i][j]=='1'&&s[i][j+1]=='1')ver[i+1][j+1]++;
      if(s[i][j]=='1'&&s[i+1][j]=='1')wid[i+1][j+1]++;
    }
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      black[i][j+1]+=black[i][j];
      ver[i][j+1]+=ver[i][j];
      wid[i][j+1]+=wid[i][j];
    }
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      black[i+1][j]+=black[i][j];
      ver[i+1][j]+=ver[i][j];
      wid[i+1][j]+=wid[i][j];
    }
  }
  std::vector<int> ans(Q);
  for(int i=0;i<Q;i++){
    int x1,x2,y1,y2;cin>>x1>>y1>>x2>>y2;
    int B=black[x2][y2]+black[x1-1][y1-1]-black[x2][y1-1]-black[x1-1][y2];
    int E1=ver[x2][y2-1]+ver[x1-1][y1-1]-ver[x2][y1-1]-ver[x1-1][y2-1];
    int E2=wid[x2-1][y2]+wid[x1-1][y1-1]-wid[x2-1][y1-1]-wid[x1-1][y2];
    ans[i]=B-E1-E2;
  }
  for(int i=0;i<Q;i++)cout<<ans[i]<<endl;
}
/*
解説AC
連結成分の個数は森なら頂点の個数と辺の数から数えられるというもの
森じゃなくても各連結成分の頂点の数と辺の数に何かしら関係があれば使えるテクだね
数えやすい成分に言い換えてしまうテクニック
あとそもそも今回の問題の設定を閉路がないとしか思わなかったけど閉路がない＝木（森）を忘れていた
*/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

const int N=2005;
int n,m,q,a[N][N],s[N][N],sx[N][N],sy[N][N];

void doit(){
	int x,y,xx,yy;
	read(x);read(y);read(xx);read(yy);
	int n=s[xx][yy]-s[xx][y-1]-s[x-1][yy]+s[x-1][y-1];
	int m=(sx[xx][yy-1]-sx[xx][y-1]-sx[x-1][yy-1]+sx[x-1][y-1])+(sy[xx-1][yy]-sy[x-1][yy]-sy[xx-1][y-1]+sy[x-1][y-1]);
	write(n-m);puts("");
}

signed main(){
	read(n);read(m);read(q);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) scanf("%1d",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
			sx[i][j]=sx[i-1][j]+sx[i][j-1]-sx[i-1][j-1]+(a[i][j]+a[i][j+1]==2);
			sy[i][j]=sy[i-1][j]+sy[i][j-1]-sy[i-1][j-1]+(a[i][j]+a[i+1][j]==2);
		}
	while(q--) doit();
}


#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
int main() {
    ll A, B;
    cin >> A >> B;
    string str;
    cin >> str;

    bool isOk = true;
    REP(i, str.size()) {
        if (i == A) {
            isOk &= str[i] == '-';
        } else {
            isOk &= str[i] != '-';
        }
        if (!isOk) break;
    }
    PR(isOk ? "Yes" : "No");
    return 0;
}

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

int main() {
    int A, B; cin >> A >> B;
    vector<char> S(A + B + 1);
    for (int i = 0; i < A + B + 1; i++) {
        cin >> S.at(i);
    }

    string ans = "Yes";
    if (S.at(A) != '-') ans = "No";
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '-' && i != A) ans = "No";
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 3;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE EVAL({cout << -1 << '\n'; exit(0);})
//------------------------------------------------------------------------------------------------------

LL K;

int main() {
    cin >> K;
    LL x = K % 50;
    LL m = (K-x)/50 + 49;
    cout << 50 << '\n';
    REP(i, 50-x) cout << (m-x) << ' ';
    REP(i, x) cout << (m+51-x) << ' ';
    cout << '\n';
}

#include <iostream>
#include <vector>

using namespace std;

int simulate(vector<long long int> A){
  int N = A.size(), ret = 0;
  while(1){
    int t = 0;
    for(int i = 0; i < N; ++i){
      if(A[i] > A[t]) t = i;
    }
    if(A[t] < N) break;
    for(int i = 0; i < N; ++i){
      if(i != t) ++A[i];
      else A[i] -= N;
    }
    ++ret;
  }
  return ret;
}

int main(){
  long long int K, M = 1e16 + 1e3 + 1;
  cin >> K;
  vector<long long int> A(50);
  for(long long int i = 0; i < 50; ++i) A[i] = i + K/50;
  K %= 50;
  for(int i = 0; i < K; ++i) ++A[49-i];
  //cout << simulate(A) << endl;
  cout << 50 << endl;
  cout << A[0];
  for(int i = 1; i < 50; ++i) cout << " " << A[i];
  cout << endl;
  return 0;
}


#include "bits/stdc++.h"
#define ll long long
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll c[4];
double dp[301][301][301];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a, c[a]++;
    dp[0][0][0] = 0;
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= n; j++)
        {
            for (ll k = 0; k <= n; k++)
            {
                double z = n - (i + j + k), val = 1;
                if (z == n)
                    continue;
                if (i + j + k > n)
                    continue;
                if (i > 0)
                    val += (1.0 * i / n) * dp[i - 1][j + 1][k];
                if (j > 0)
                    val += (1.0 * j / n) * dp[i][j - 1][k + 1];
                if (k > 0)
                    val += (1.0 * k / n) * dp[i][j][k - 1];
                if (z > 0)
                    val /= (1.0 - 1.0 * z / n);
                dp[i][j][k] = val;
            }
        }
    }

    cout << setprecision(9) << fixed << dp[c[3]][c[2]][c[1]];
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

//dp
vector<vector<vector<double>>> table;

double dp(ll i,ll j,ll k){
  //cout<<i<<" "<<j<<" "<<k<<endl;
  if(i==0&&j==0&&k==0) return 0;
  if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k);

  table.at(i).at(j).at(k)=0;
  if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N;
  if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N;
  if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N;
  table.at(i).at(j).at(k)+=1;

  return table.at(i).at(j).at(k)/=(double)(i+j+k)/N;
}

int main()
{
  cin>>N;
  vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;}

  //dp
  table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));

  cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl;
  /*
  rep(i,2) {
    if(i!=0) cout<<" ";
    cout<<table.at(0).at(0).at(i);
  }
  cout<<fixed<<setprecision(15)<<endl;
  */

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
pii p[100005];
int x[100005], y[100005];
int r[100005];
int root(int a){
    return r[a] == a?a:(r[a]=root(r[a]));
}
void merge(int a, int b){
    a = root(a), b = root(b);
    if(a != b) r[a] = b;
}
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &x[i], &y[i]);
        p[i] = pii(x[i], i);
        r[i] = i;
    }
    sort(p+1, p+1+n);
    vector<pipii> edges;
    for(int i=2;i<=n;i++) edges.eb(pipii(p[i].fi-p[i-1].fi, pii(p[i].se, p[i-1].se)));
    sort(all(edges));
    for(int i=1;i<=n;i++) p[i] = pii(y[i], i);
    sort(p+1, p+1+n);
    for(int i=2;i<=n;i++) edges.eb(pipii(p[i].fi-p[i-1].fi, pii(p[i].se, p[i-1].se)));
    sort(all(edges));
    int ans = 0;
    for(int i=0;i<sz(edges);i++){
        if(root(edges[i].se.fi) != root(edges[i].se.se)){
            merge(edges[i].se.fi, edges[i].se.se);
            ans += edges[i].fi;
        }
    }
    printf("%d\n", ans);
}

#include <iostream>
#include <vector>
#include <functional>
using namespace std;
const int INF = 1001001001;

template<class M, class L> struct LazyPropagationSegmentTree
{
	int n;
	int size;
	vector<M> data;
	vector<L> lazy;
	const function<M(M, M)> f_m;
	const M e_m;
	const function<L(L, L)> f_l;
	const L e_l;
	const function<M(M, L)> f;

	LazyPropagationSegmentTree(int n, function<M(M, M)> f_m, M e_m, function<L(L, L)> f_l, L e_l, function<M(M, L)> f) : n(n), f_m(f_m), e_m(e_m), f_l(f_l), e_l(e_l), f(f) {
		size = 1;
		while (size < n) size <<= 1;
		data.assign(size * 2, e_m);
		lazy.assign(size * 2, e_l);
	}

	void init(const vector<M> &init_vals) {
		data.assign(size * 2, e_m);
		for (int i = 0; i < init_vals.size(); i++) data[size+i] = init_vals[i];
		for (int i = size-1; i > 0; i--) data[i] = f_m(data[2*i], data[2*i+1]);
	}

	void eval(int k) {
		if (lazy[k] == e_l) return;
		if (k < size) {
			lazy[2*k] = f_l(lazy[2*k], lazy[k]);
			lazy[2*k + 1] = f_l(lazy[2*k + 1], lazy[k]);
		}
		data[k] = f(data[k], lazy[k]);
		lazy[k] = e_l;
	}

	void update(int l, int r, L l_prop) {
		update_aux(l, r, l_prop, 1, 0, size);
	}

	void update_aux(int l, int r, L l_prop, int k, int k_l, int k_r) {
		eval(k);
		if (r <= k_l || k_r <= l) return;
		else if (l <= k_l && k_r <= r) {
			lazy[k] = f_l(lazy[k], l_prop);
			eval(k);
		} else {
			update_aux(l, r, l_prop, 2*k, k_l, (k_l + k_r) / 2);
			update_aux(l, r, l_prop, 2*k + 1, (k_l + k_r) / 2, k_r);
			data[k] = f_m(data[2*k], data[2*k + 1]);
		}
	}

	M query(int l, int r) {
		return query_aux(l, r, 1, 0, size);
	}

	M query_aux(int l, int r, int k, int k_l, int k_r) {
		eval(k);
		if (r <= k_l || k_r <= l) return e_m;
		else if (l <= k_l && k_r <= r) return data[k];
		else {
			M vl = query_aux(l, r, k*2, k_l, (k_l + k_r) / 2);
			M vr = query_aux(l, r, k*2 + 1, (k_l + k_r) / 2, k_r);
			return f_m(vl, vr);
		}
	}

	void eval_all() {
		for (int i = 1; i < 2*size; i++) eval(i);
	}

	M val(int idx) {
		return data[size + idx];
	}

	vector<M> val_vec() {
		vector<M> res(n);
		for (int i = 0; i < n; i++) res[i] = data[size+i];
		return res;
	}
};

int main() {
	int h, w;
	cin >> h >> w;
	struct M
	{
		int val, idx, l;
	};
	using L = int;
	M e_m = {-INF, INF, -1};
	L e_l = -INF-1;
	auto f_m = [&](M m1, M m2) -> M {
		if (m1.idx - m1.val < m2.idx - m2.val) return m1;
		else return {m2.val, m2.idx, m1.l};
	};
	auto f_l = [&](L l1, L l2) -> L {
		if (l2 == e_l) return l1;
		return l2;
	};
	auto f = [&](M m, L l) -> M {
		if (l == e_l) return m;
		return {l, m.l, m.l};
	};
	LazyPropagationSegmentTree<M, L> st(w, f_m, e_m, f_l, e_l, f);
	vector<M> init_vals(w);
	for (int i = 0; i < w; i++) {
		init_vals[i] = {i, i, i};
	}
	st.init(init_vals);
	for (int i = 1; i <= h; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		int val;
		if (a == 0) val = -INF;
		else val = st.query(a-1, a).val;
		st.update(a, b, val);
		M q = st.query(0, w);
		int ans = i + q.idx - q.val;
		if (q.val == -INF) ans = -1;
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll Rev(ll x) {
	return bin_pow(x, MOD - 2);
}
ll W;

const int LOG = 20;
const int N = 1 << 20;
ll w[N];
int rev[N];

void initFFT() {
	for (ll x = 2;; x++) {
		ll y = x;
		for (int i = 1; i < LOG; i++)
			y = mult(y, y);
		if (y == MOD - 1) {
			W = x;
			break;
		}
	}
	w[0] = 1;
	for (int i = 1; i < N; i++)
		w[i] = mult(w[i - 1], W);
	rev[0] = 0;
	for (int mask = 1; mask < N; mask++) {
		int k = 0;
		while(((mask >> k) & 1) == 0) k++;
		rev[mask] = rev[mask ^ (1 << k)] ^ (1 << (LOG - 1 - k));
	}
}

ll F[2][N];
void FFT(ll *A) {
	for (int i = 0; i < N; i++)
		F[0][rev[i]] = A[i];
	int t = 0, nt = 1;
	for (int lvl = 0; lvl < LOG; lvl++) {
		int len = 1 << lvl;
		for (int st = 0; st < N; st += (len << 1))
			for (int i = 0; i < len; i++) {
				ll ad = mult(F[t][st + len + i], w[i << (LOG - 1 - lvl)]);
				F[nt][st + i] = add(F[t][st + i], ad);
				F[nt][st + len + i] = sub(F[t][st + i], ad);
			}
		swap(t, nt);
	}
	for (int i = 0; i < N; i++)
		A[i] = F[t][i];
}

ll f[N], rf[N];
ll a[N];

ll getC(int n, int k) {
	if (k < 0 || k > n) return 0;
	return mult(f[n], mult(rf[k], rf[n - k]));
}

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

	initFFT();

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	rf[N - 1] = Rev(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = mult(rf[i], i);

	for (int k = 0; k < N / 2; k++) {
		a[k] = mult(f[2 * k], mult(rf[k], rf[k]));
	}
	FFT(a);
	for (int i = 0; i < N; i++)
		a[i] = mult(a[i], a[i]);
	FFT(a);
	reverse(a + 1, a + N);
	ll rN = Rev(N);
	for (int i = 0; i < N; i++) {
		a[i] = mult(a[i], rN);
		a[i] = mult(a[i], mult(rf[2 * i], mult(f[i], f[i])));
		a[i] = sub(a[i], 1);
		a[i] = mult(a[i], (MOD + 1) / 2);
		a[i] += i;
	}

	int n, m;
	scanf("%d%d", &n, &m);
	if (n < m) swap(n, m);
	if (n == m) {
		printf("%lld\n", a[n]);
		return 0;
	}

	ll ans = 0;

	for (int k = 0; k <= m; k++) {
		int L = n - m + k - 1;
		ll p = getC(L + k, k);
		if (k > 0)
			p = sub(p, getC(L + k, k - 1));
		p = mult(p, getC(2 * (m - k), m - k));
		ans = add(ans, mult(p, add(L + 1, a[m - k])));
	}
	ans = mult(ans, mult(rf[n + m], mult(f[n], f[m])));
	printf("%lld\n", ans);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=1e6+11,mo=998244353;
int fpow(int a,int b){
	int r=1;
	for(;b;b>>=1,a=1ll*a*a%mo)
		if(b&1)r=1ll*r*a%mo;
	return r;
}
int inv(int x){return fpow(x,mo-2);}
int jc[N+1],jcv[N+1];
int C(int a,int b){
	return a<b?0:1ll*jc[a]*jcv[b]%mo*jcv[a-b]%mo;
}
int n,m;
int main(){
#ifdef flukehn
	freopen("c.in","r",stdin);
#endif
	ios::sync_with_stdio(0);
	jc[0]=1;
	rep(i,1,N)jc[i]=1ll*jc[i-1]*i%mo;
	jcv[N]=inv(jc[N]);
	per(i,1,N)jcv[i-1]=1ll*jcv[i]*i%mo;
	cin>>n>>m;
	if(n<m)swap(n,m);
	int ans=0;
	rep(i,1,m){
		ans=(ans+1ll*C(2*i,i)*C(n+m-2*i,n-i))%mo;
	}
	ans=1ll*ans*inv(C(n+m,n))%mo;
	ans=1ll*ans*inv(2)%mo;
	printf("%d\n",(ans+n)%mo);
}


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

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

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

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

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N;
    int64_t D, A[200000];
    cin >> N >> D;
    for(int i=0; i<N; i++) cin >> A[i];

    typedef pair<int64_t, int> P;
    const int64_t INF = 1e18;
    const P INFP = {INF, 0};
    Segtree<P> stL(N, [](P a, P b){ return min(a, b);}, INFP);
    Segtree<P> stR(N, [](P a, P b){ return min(a, b);}, INFP);

    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int i, int j){ return A[i] < A[j];});
    vector<vector<int64_t>> edges;

    for(int i : order){
        auto p = stL.between(0, i);
        if(p != INFP){
            int64_t cost = p.first + A[i] - (N-i)*D;
            edges.push_back({cost, i, p.second});
        }
        p = stR.between(i, N-1);
        if(p != INFP){
            int64_t cost = p.first + A[i] - i*D;
            edges.push_back({cost, i, p.second});
        }
        stL.update(i, {A[i] + (N-i)*D, i});
        stR.update(i, {A[i] + i*D, i});
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    int64_t ans = 0;
    for(auto& e : edges){
        if(!uf.same(e[1], e[2])){
            uf.unite(e[1], e[2]);
            ans += e[0];
        }
    }

    cout << ans << endl;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
#define LP pair<LL, LL>
const LL inf = 1e17;
struct segtree {
	int n = 1;
	vector<LP> node;//cost, place
	void init(int N) {
		node.clear();
		while (N > n) n *= 2;
		node.resize(n * 2, { inf, inf });
	}

	void update(int k, LL x, int a) {

		k += n - 1;
		node[k] = { x, a };
		while (k > 0) {
			k = (k - 1) / 2;
			int l = k * 2 + 1;
			int r = k * 2 + 2;
			if (node[l].first < node[r].first) node[k] = node[l];
			else node[k] = node[r];
		}
	}

	LP mini(int a, int b, int k = 0, int l = 0, int r = -1) {

		if (r < 0) r = n;
		if (b <= l || r <= a) return { inf, inf };
		if (a <= l && r <= b) return node[k];
		LP ln = mini(a, b, k * 2 + 1, l, (l + r) / 2);
		LP rn = mini(a, b, k * 2 + 2, (l + r) / 2, r);
		if (ln.first < rn.first) return ln;
		else return rn;
	}
};

struct edge {
	LL to;
	LL cost;
	bool operator<(const edge &e1) const {
		return e1.cost < cost;
	}
};

int N;
int idx[200010];
LL D;
bool used[200010];
vector<LL> A;
vector<LP> B;
vector<edge> G[200010];

LL prim() {
	priority_queue<edge> pq;
	pq.push(edge{ 0, 0 });
	LL total = 0;
	while (!pq.empty()) {
		edge e = pq.top();
		pq.pop();
		if (!used[e.to]) {
			used[e.to] = true;
			total += e.cost;
			for (auto u : G[e.to]) {
				if (!used[u.to]) pq.push(u);
			}
		}
	}
	return total;
}

void build() {
	segtree seg;
	seg.init(N);

	for (int i = 0; i < N; i++) {
		seg.update(idx[i], A[i] + D * (N - i - 1), idx[i]);
		if (i != 0) {
			LP lp = seg.mini(0, idx[i]);
			if (lp.first == inf) continue;

			lp.first -= D * (N - i - 1) - A[i];
			G[B[lp.second].second].push_back(edge{ i, lp.first });
			G[i].push_back(edge{ B[lp.second].second, lp.first });
		}
	}

	seg.init(N);
	for (int i = N - 1; i >= 0; i--) {
		seg.update(idx[i], A[i] + D * i, idx[i]);
		if (i != N - 1) {
			LP lp = seg.mini(0, idx[i]);
			if (lp.first == inf) continue;

			lp.first -= D * i - A[i];
			G[B[lp.second].second].push_back(edge{ i, lp.first });
			G[i].push_back(edge{ B[lp.second].second, lp.first });
		}
	}
}

void init() {
	cin >> N >> D;
	for (int i = 0; i < N; i++) {
		LP tmp;
		cin >> tmp.first;
		tmp.second = i;
		A.push_back(tmp.first);
		B.push_back(tmp);
	}
	sort(B.begin(), B.end());

	for (int i = 0; i < N; i++) {
		idx[B[i].second] = i;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	build();
	cout << prim() << endl;
	return 0;
}


#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = a; i < b+1; i++) {
    int ii = i;
    vector<int> vec(5);
    rep(j, 5) {
      vec.at(j) = (ii % 10);
      ii /= 10;
    }
    if (vec.at(0) == vec.at(4)) {
      if (vec.at(1) == vec.at(3)) {
        count++;
      }
    }
  }
  cout << count << endl;
}

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n,m;
Vi a;
int mj[9];
vector<string> dp;
string calc(ll nu){
    if(!dp[nu].empty())return dp[nu];
    string ans,tmp;
    if(nu==0){
        ans.clear();
        return ans;
    }
    rep(i,9){
        if(mj[i]!=0){
            if(nu-i>=0){
                if(calc(nu-i).empty() && (nu-i)!=0)continue;
                tmp.assign(calc(nu-i));
                tmp += to_string(mj[i]);
                //cout<<"tmp"<<tmp<<endl;;
                if(ans.size()<tmp.size())ans = tmp;
                if(ans.size()== tmp.size() && ans < tmp)ans = tmp;
                tmp.clear();
            }
        }
    }
    dp[nu]=ans;
    return ans;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m; a.resize(m);
    dp.resize(n+2);
    rep(i,m)cin>>a[i];
    sort(all(a));
    rep(i,9)mj[i]=0;
    rep(i,m){
        switch (a[i]){
            case 1: mj[2]=1;
                break;
            case 2: mj[5]=2;
                break;
            case 3: mj[5]=3;
                break;
            case 4: mj[4]=4;
                break;
            case 5: mj[5]=5;
                break;
            case 6: mj[6]=6;
                break;
            case 7: mj[3]=7;
                break;
            case 8: mj[7]=8;
                break;
            case 9: mj[6]=9;
                break;
        }
    }
    print(calc(n));
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t,o;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
typedef double dob;
/*
0:
1:0
2:00
3:1
4:10
5:100
6:11
*/
const int N=300010,P=1000000007;
int n,g[7],f[7],h[7];
char s[N];
void add(int &x,int y){x=(x+y)%P;}
void tran(int k){
	memset(g,0,sizeof(g));
	memset(h,0,sizeof(h));
	add(g[1],f[0]);
	add(g[2],f[1]);
	add(g[1],f[2]);
	add(g[4],f[3]);
	add(g[5],f[4]);
	add(g[4],f[5]);
	add(g[6],f[6]);

	add(h[3],f[0]);
	add(h[0],f[1]);
	add(h[1],f[2]);
	add(h[6],f[3]);
	add(h[3],f[4]);
	add(h[4],f[5]);
	add(h[6],f[6]);
	if (k==0) swap(f,g); else
	if (k==1) swap(f,h); else{
		rep(i,0,6) add(g[i],h[i]);
		swap(f,g);
	}
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	f[0]=1;
	rep(i,1,n) tran(s[i]=='?'?2:s[i]-'0');
	LL ans=f[6]+f[3];
	ans=(ans%P+P)%P;
	printf("%lld\n",ans);
	return 0;
}


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

//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 1e3+5;
const ll mod = 1e9+7;

ll n, mt;
bool cycle = 0;
ll in[SZ][SZ];
vector <ll> adj[SZ*SZ];
ll vis[SZ*SZ];
ll ind[SZ*SZ];

void dfs(ll u) {
    if(vis[u] == 2 || cycle) return;
    if(vis[u] == 1) {
        cycle = 1;
        return;
    }

    vis[u] = 1;
    for(auto v: adj[u]) {
        dfs(v);
    }
    vis[u] = 2;
}

int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin1(n);
    mt = ((n *(n-1)) / 2);

    for1(i, n) fora(j, i+1, n) in[i][j] = in[j][i] = ++c;

    for1(i, n) {
        cin1(p);
        p = in[i][p];

        fora(j, 2, n-1) {
            cin1(x);
            x = in[i][x];
            adj[p].pb(x);
            ind[x]++;
            p = x;
        }
    }

    for1(i, mt) {
        if(!vis[i]) dfs(i);
    }

    if(cycle) {
        cotminus;
        return 0;
    }

    vector <ll> now;
    for1(i, mt) if(ind[i] == 0) now.pb(i);

    while(1) {
        ans++;
        vector <ll> tmp;

        for(auto u: now) {
            for(auto v: adj[u]) {
                ind[v]--;
                if(ind[v] == 0) tmp.pb(v);
            }
        }

        if(tmp.empty()) break;

        now = tmp;
    }

    cot1(ans);

    return 0;
}

#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}

};
vector<ll> TopologicalSort(ConnectNodeInfo& connect){
	int N=connect.size();
	stack<ll> vertex;
	vector<ll> input(N),sorted;
	REP(i,N){
		for(auto& x:connect[i]) input[x.first]++;
	}
	REP(i,N){
		if(input[i]==0) vertex.push(i);
	}
	while(!vertex.empty()){
		auto v=vertex.top();vertex.pop();
		sorted.push_back(v);
		for(auto& x:connect[v]){
			input[x.first]--;
			if(!input[x.first]) vertex.push(x.first);
		}
	}
	if(sorted.size()!=N) sorted.clear();
	return sorted;
}

ll CalcLongestPathOnDAG(ConnectNodeInfo& connect,vector<ll>& DAG){
	int N=connect.size();
	vll dist(N,-1);
	ll maxD=0;
	REP(i,N){
		if(dist[DAG[i]]<0) dist[DAG[i]] = 0;
		for(auto& x:connect[DAG[i]]){
			dist[x.first] = max(dist[x.first],dist[DAG[i]]+x.second);
			maxD = max(maxD,dist[x.first]);
		}
	}
	return maxD;
}

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

	int N=in();
	vvll L(N,vll(N,-1));
	int index=0;
	REP(i,N){
		FOR(j,i+1,N){
			L[i][j] = index++;
			L[j][i] = L[i][j];
		}
	}
	ConnectNodeInfo connect(index);
	REP(i,N){
		ll s=in()-1;
		REP(j,N-2){
			ll t=in()-1;
			connect.AddDirectionalConnection(L[i][s],L[i][t],1);
			s = t;
		}
	}
	auto DAG = TopologicalSort(connect);
	if(DAG.empty()){
		out(-1);
		return 0;
	}

	ll maxD = CalcLongestPathOnDAG(connect,DAG);
	out(maxD+1);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

char mp[2222][2222];
bool ng[2222][2222];
int high[2222][2222];

int seica(ll h,ll w){
	ll ret = 0;
	REP(i,h){
		stack<pair<ll,ll>> st;
		REP(j,w){
			ll tmp = j;
			while(!st.empty() && st.top().FI > high[i][j]){
				auto now = st.top();
				st.pop();
				ret = max(ret,(j - now.SE) * now.FI);
				tmp = min(tmp,now.SE);
				//cout << i << " " << j << " " << now.FI << " " << now.SE << " " << (j - now.SE) * now.FI << endl;
			}
			if(st.empty() || st.top().FI < high[i][j])st.push(MP(high[i][j],tmp));
			if(st.empty() || st.top().FI < i + 1)st.push(MP(i + 1,j));
		}
		while(!st.empty()){
			auto now = st.top();
			st.pop();
			ret = max(ret, (w - now.SE) * now.FI);
			//cout << i << " " << w << " " << now.FI << " " << now.SE << " " << (w - now.SE) * now.FI << endl;
		}
	}
	return ret;
}

int main(){

	int h,w;cin >> h >> w;
	REP(i,h){
		REP(j,w){
			cin >> mp[i][j];
		}
	}

	REP(i,h-1){
		REP(j,w-1){
			int y = i + 1;
			int x = j + 1;
			int cou = 0;
			if(mp[y][x] == '#')cou++;
			if(mp[y][x-1] == '#')cou++;
			if(mp[y-1][x] == '#')cou++;
			if(mp[y-1][x-1] == '#')cou++;
			if(cou % 2)ng[y][x] = true;
		}
	}

	REP(i,h){
		REP(j,w){
			if(i == 0)high[i][j] = 1;
			else {
				if(ng[i][j])high[i][j] = 1;
				else high[i][j] = high[i-1][j] + 1;
			}
		}
	}

	cout << seica(h,w) << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
int g[2020][2020],h[2020][2020];
ii dp[2020][2020];
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			char c;
			cin >> c;
			g[i][j] = (c == '#');
		}
	}
	for(int i=0;i<n-1;i++) {
		for(int j=0;j<m-1;j++) {
			h[i][j] = 1-((g[i][j] + g[i+1][j] + g[i][j+1] + g[i+1][j+1])%2);
		}
	}
	int ma = max(n,m);
	for(int i=0;i<n;i++) {
		for(int j=0;j<m-1;j++) {
			if(h[i][j]) {
				if(i > 0) {
					h[i][j] = max(h[i-1][j]+1,2);
				} else {
					h[i][j] = 2;
				}
			}
		}
		stack<int> st;
		int v,mc = 0;
		int id = 0;
		while(id < m-1) {
			if(st.empty() || h[i][st.top()] <= h[i][id]) {
				st.push(id++);
			} else {
				v = h[i][st.top()];
				st.pop();
				mc = v*(id+1);
				if(!st.empty()) {
					mc = v*(id-st.top());
				}
				ma = max(ma,mc);
			}
		}
		while(!st.empty()) {
			v = h[i][st.top()];st.pop();
			mc = v*(id+1);
			if(!st.empty()) {
				mc = v*(id-st.top());
			}
			ma = max(ma,mc);
		}
	}
	cout << ma << '\n';
}