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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

template<typename T>
struct SegmentTree {
	typedef function<T(T,T)> F;
    typedef function<T(T,T)> G;
    int n;
    F f;
    G g;
    T e;

    vector<T> val;

    SegmentTree(vector<T> a, F f_, G g_, T e):
        f(f_), g(g_), e(e){
            int sz = a.size();
            n = 1;

            while (n < sz) n <<= 1;
            val.resize(2 * n - 1, e);
            for (int i = 0; i < sz; i++) val[i + n - 1] = a[i];
            for (int i = n - 2; i >= 0; i--) val[i] = f(val[i * 2 + 1], val[i * 2 + 2]);
        }

        SegmentTree() {}

        void update(int pos, T v) {
            // 0-indexed
            int k = pos + n - 1;
            val[k] = g(val[k], v);
            while (k > 0) {
                k = (k - 1) / 2;
                val[k] = f(val[k * 2 + 1], val[k * 2 + 2]);
            }
        }

        T get(int pos) {
            // 0-indexed
            int k = pos + n - 1;
            return val[k];
        }

        T query(int a, int b, int k = 0, int l = 0, int r = -1) {
            // 0-indexed
            // [a,b)に対してquery
            if (r < 0) r = n;
            if (r <= a || b <= l) return e;
            if (a <= l && r <= b) return val[k];
            T lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return f(lv, rv);
        }
};

int main(void){
    auto f = [](P a, P b){
        return max(a,b);
    };
    auto g = [](P a, P b){
        return P(a.first+b.first, a.second);
    };

    int N,M; cin >> N >> M;
    VVI A(N,VI(M)); REP(i,N)REP(j,M) cin >> A[i][j];
    REP(i,N) REVERSE(A[i]);

    int l=0, r=N, n=(l+r)/2;
    while(r-l>1){
        VVI B(A);
        int s = 1000;
        set<int> removed;
        while(s > n){
            vector<P> a(M);
            REP(i,M){
                a[i].first = 0;
                a[i].second = i;
            }
            SegmentTree<P> st(a, f, g, P(0,0));
            REP(i,N){
                if(B[i].size()) st.update(B[i].back()-1, P(1,0));
            }
            P mx = st.query(0,M);
            s = mx.first;
            if(s > n){
                removed.insert(mx.second);
                REP(i,N){
                    while(B[i].size() && removed.count(B[i].back()-1)) B[i].pop_back();
                }
            }
        }
        if(s == 0) l = n;
        else r = n;
        n = (l+r)/2;
    }
    int ans = r;
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<vector<int64_t>> a(n, vector<int64_t>(m));
    for (auto i : irange(0L, n)) {
        for (auto j : irange(0L, m)) {
            cin >> a[i][m - j - 1];
            --a[i][m - j - 1];
        }
    }

    int64_t ans = n;
    vector<bool> available(m, true);
    for (auto _ : irange(0L, m)) {
        vector<int64_t> c(m);

        for (const auto& b :
             a | transformed([](const auto& aa) { return aa.back(); })) {
            ++c[b];
        }

        auto b = max_element(c.begin(), c.end()) - c.begin();
        available[b] = false;
        ans = min(ans, c[b]);

        for (auto&& aa : a) {
            while (!aa.empty() && !available[aa.back()]) {
                aa.pop_back();
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    int k;
    string ss;
    cin>>k>>s;
    if(s.length()>k){
        for(int i=0; i<k; i++){
            ss += s[i];
        }
        ss+="...";
    }
    else {
        ss =s;
    }
    cout<<ss;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

    int k;
    string s, t = "...";
    cin >> k >> s;
    if(s.size() <= k)
        cout << s << '\n';
    else {
        for (int i = 0; i < k; ++i) {
            cout << s[i];

        }
        cout << t;
    }

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n;
	cin>>n;
	int a[17];
	int x[17][17];
	int y[17][17];
	rep(i,n){
		cin>>a[i];
		rep(j,a[i]){
			cin>>x[i][j]>>y[i][j];
		}
	}
	int ans=0;
	rep(bit,1<<n){
		int shoujiki[17];
		rep(i,n){
			if(bit&(1<<i)) shoujiki[i]=1;
			else shoujiki[i]=0;
		}
		int to[17][17];
		int ok=1;
		rep(i,n){
			if(shoujiki[i]){
				rep(j,a[i]){
					if(y[i][j]){
						if(shoujiki[x[i][j]-1]==0) ok=0;
					}else{
						if(shoujiki[x[i][j]-1]==1) ok=0;
					}

				}
			}
		}
		if(ok){
			int cnt=0;
			rep(i,n){
				if(shoujiki[i]==1) cnt++;
			}
			chmax(ans,cnt);
		}
	}

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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <queue>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define MAXN 200005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 - '0' + c;
	c = getchar();
    }
    res = res * f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N,M,I,P,Q;
struct node {
    int next,to;
}E[MAXN * 2];
int head[MAXN],sumE,col[MAXN];
bool vis[MAXN];
void dfs(int u) {
    vis[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    dfs(v);
	}
    }
}
bool paint(int u) {
    if(!col[u]) col[u] = 2;
    for(int i = head[u] ; i; i = E[i].next) {
	int v = E[i].to;
	if(!col[v]) {col[v] = col[u] ^ 1;if(!paint(v)) return false;}
	else if(col[v] == col[u]) return false;
    }
    return true;
}
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Solve() {
    read(N);read(M);
    int u,v;
    for(int i = 1 ; i <= M ; ++i) {
	read(u);read(v);
	add(u,v);add(v,u);
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(!head[i]) ++I;
	else if(!vis[i]){
	    dfs(i);
	    if(paint(i)) ++Q;
	    else ++P;
	}
    }
    int64 ans = 1LL * I * I + 2LL * I * (N - I);
    ans += 1LL * P * P + 2LL * P * Q + 2LL * Q * Q;
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  ll a;
  cin >> a;
  ll ans = 999;
  while(a>99){
    ans = min(ans,abs(753-a%1000));
    a /= 10;
  }
  cout << ans;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s;
  cin >> s;
  int n = s.size();

  int mn = 754;
  for(int i=0; i<n-2; ++i){
    string str = s.substr(i,3);
    int num = stoi(str);
    int res = abs(num-753);
    mn = min(mn, res);
  }
  cout << mn;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int cnt = 0;
  while (1) {
    rep(i, n) {
      if (a[i] % 2 != 0) {
        cout << cnt << endl;
        return 0;
      }
      a[i] *= 0.5;
    }
    cnt++;
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200, MAXINT=2147483647;
int a[N], t, n, mi=MAXINT;
int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        if (a[i]%2) {
            cout << 0; return 0;
        } else {
            int tp=0;
            while (!(a[i]%2)) {
                a[i]/=2; tp++;
            }
            if (tp<mi) mi=tp;
        }
    }

    cout << mi;
}


#include <bits/stdc++.h>

using std::max;

const int N=15,Inf=1e9+10;

int n,m,map[N][N],f[N][1<<N],M[N][1<<N],sum[1<<N];

void Init() {
	scanf("%d%d",&n,&m);
	int a,b,c;
	for (int i=1;i<=m;++i) {
		scanf("%d%d%d",&a,&b,&c);
		a--; b--;
		map[a][b]=map[b][a]=c;
	}
}

int summ;
bool vis[N];
void Dfs(int x,int s) {
	if (vis[x]) return ;
	vis[x]=1;
	for (int i=0;i<n;++i) if ((1<<i)&s && map[x][i]) {
		summ+=map[x][i];
		Dfs(i,s);
	}
}

void Solve() {
	int Max=1<<n;
	for (int s=0;s<Max;++s) {
		summ=0;
		for (int i=0;i<n;++i) vis[i]=0;
		for (int i=0;i<n;++i) if ((1<<i)&s) Dfs(i,s);
		sum[s]=summ>>1;
	}

	summ=0;
	for (int i=0;i<n;++i)
		for (int j=i;j<n;++j) summ+=map[i][j];
	for (int i=0;i<n;++i)
		for (int s=0;s<Max;++s) f[i][s]=-Inf,M[i][s]=-Inf;
	M[0][1]=0;
	for (int s=0;s<Max;++s) if (s&1) {
		f[0][s]=sum[s];
		for (int t=0;t<n;++t)
			if (map[t][0]) M[t][s]=max(M[t][s],f[0][s]+map[t][0]);
	}
	for (int s=0;s<Max;++s) {
		for (int i=0;i<n;++i) if ((1<<i)&s) {
			for (int p=s;p;p=(p-1)&s) if (!((1<<i)&p)) {
				f[i][s]=max(f[i][s],M[i][p]+sum[s^p]);
			}
			for (int t=0;t<n;++t) if (map[t][i]) M[t][s]=max(M[t][s],f[i][s]+map[t][i]);
		}
	}

	printf("%d\n",summ-f[n-1][Max-1]);
}

int main() {
	Init();
	Solve();
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<vector<ll>> g;
vector<ll> dp; // -1 .. no paint, 0 .. red, 1 .. blue

// c .. 0 or 1
bool dfs(int v, int c) {
  if (dp[v] >= 0) {
    return dp[v] == c;
  }
  // Here, dp[v] == -1
  dp[v] = c;
  int nc = c^1; // next color
  for (auto nv : g[v]) {
    if (!dfs(nv, nc)) { return false; }
  }
  return true;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, m;
  cin >> n >> m;
  g.resize(n);
  dp.assign(n, -1);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    --a; --b; //0-indexed
    g[a].push_back(b);
    g[b].push_back(a);
  }

  if (dfs(0, 0)) { // g is bipartite grah
    ll red = 0;
    rep(i, n) {
      if (dp[i] == 0) { ++red; }
    }
    ll blue = n-red;
    cout << red*blue - m << endl;
  } else {
    cout << n*(n-1)/2 - m << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin >> h >> w;
    int a[h][w],b[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> b[i][j];
        }
    }
    const int vmax=12800;
    bool c[h][w][2*vmax]={false};
    c[0][0][a[0][0]-b[0][0]+vmax]=true;
    c[0][0][b[0][0]-a[0][0]+vmax]=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<2*vmax;k++){
                if(!c[i][j][k]){
                    continue;
                }
                if(i<h-1){
                    c[i+1][j][k+a[i+1][j]-b[i+1][j]]=true;
                    c[i+1][j][k+b[i+1][j]-a[i+1][j]]=true;
                }
                if(j<w-1){
                    c[i][j+1][k+a[i][j+1]-b[i][j+1]]=true;
                    c[i][j+1][k+b[i][j+1]-a[i][j+1]]=true;
                }
            }
        }
    }
    int ans=inf;
    for(int i=0;i<2*vmax;i++){
        if(c[h-1][w-1][i]){
            chmin(ans,abs(i-vmax));
        }
    }
    cout << ans << endl;
}


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

#define LL long long
const int N = 1e6 + 5, mod = 1e9 + 7;
bool A[N], B[N];
int n, m, x;
LL ans = 1, r, c, tc, tr;

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

    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(A[x]) {return cout << 0, 0;}
        A[x] = 1;
    }

    for(int i = 0; i < m; i++) {
        cin >> x;
        if(B[x]) {return cout << 0, 0;}
        B[x] = 1;
    }

    for(int i = n * m; i > 0; i--) {
        tc = c, tr = r;
        if(A[i]) {tr = 1, r++;}
        if(B[i]) {tc = 1, c++;}
        if(A[i] || B[i]) {ans *= (tc * tr) % mod;}
        else ans *= (tc * tr - (n * m - i)) % mod;
        ans %= mod;
    }
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define LL long long
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; }

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,(int)(v.size()-1)) os << v[i] << " ";
    os << v[v.size()-1];
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 1e6+5;
const int maxh = 1e3+3;
const int mod = 1e9+7;
int cnt = 0;

int A[maxh];
int B[maxh];
int N,M;

int mult(LL a,LL b){
    return (a*b)%mod;
}

int main()
{
    cin >> N >> M;
    _rep(i,1,N) cin >> A[i];
    A[N+1] = -1;
    _rep(i,1,M) cin >> B[i];
    B[M+1] = -1;

    LL ans = 1;
    int pa = 1,pb = 1;
    sort(A+1,A+N+1,greater<int>());
    sort(B+1,B+M+1,greater<int>());

    for(int i = M*N;i >= 1;i--){
        if(A[pa] == i && B[pb] == i){
            pa++;pb++;
        }
        else if(A[pa] == i){
            ans = mult(ans,pb-1);
            pa++;
        }
        else if(B[pb] == i){
            ans = mult(ans,pa-1);
            pb++;
        }
        else{
            LL used = M*N - i;
            LL rest = (pa-1)*(pb-1);
            //cout << pa <<" "<< pb << endl;
            if(rest - used <= 0){ans = 0;break;}
            ans = mult(ans,rest-used);
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  ll N, M;
  vector<int> color;
  vector<vector<int> > G;

  void init() {
    cin >> N >> M;
    color.resize(N);
    G.resize(N);
    int a, b;
    rep(i, M) {
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }

  bool dfs(int u, int c) {
    color[u] = c;
    for(const auto& v : G[u]) {
      if(color[u] == color[v]) return false;
      if(color[v] == 0 && !dfs(v, -c)) return false;
    }
    return true;
  }

  void solve() {
    fill(ALL(color), 0);
    if(dfs(0, 1)) {
      ll b = 0;
      ll w = 0;
      for(const auto& c : color) {
        if(c == 1) b++;
        else w++;
      }
      cout << b*w - M << "\n";
    } else {
      cout << N*(N-1)/2 - M << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

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

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n * 2);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        uf.unionSet(a, b + n);
        uf.unionSet(a + n, b);
    }
    long long all = 0;
    if (uf.findSet(0, n)) {
        all = 1LL * n * (n - 1) / 2;
    } else {
        for (int i = 0; i < n; i++) all += uf.findSet(0, i);
        all *= n - all;
    }
    cout << all - m << endl;
    return 0;
}


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

int main() {
    int64_t N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<int64_t> A(N);
    for(auto &e : A) cin >> e;
    sort(A.begin(), A.end());
    rep(i, N) A[i] += M;
    vector<int64_t> cum(N + 1);
    rep(i, N) cum[i + 1] = cum[i] + A[i];
    int y = N - P;
    auto OK = [&](int x) -> bool {
        if(A[x] + M < A[y]) return false;
        int64_t S = cum[y + 1] - cum[x + 1];
        int64_t D = A[x] * (y - x);
        return S - D <= M * (N - V);
    };
    int l = -1, r = y;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        OK(mid) ? r = mid : l = mid;
    }
    cout << N - r << '\n';
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,a[N],b[N],match[N];
char s[N],t[N];
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	if (!strcmp(s+1,t+1)) return puts("0"),0;
	for (int p=n,q=n;p;p--){
		while (t[p]==t[p-1]) p--;
		while (q&&(q>p||s[q]!=t[p])) q--;
		if (!q) return puts("-1"),0;
		match[p]=q;
	}
	for (int i=1;i<=n;i++)
		if (match[i]) m++,a[m]=match[i],b[m]=i;
	a[m+1]=b[m+1]=n+1;
	int ans=0,Max=0;
	for (int i=1;i<=m;i++)
		for (int j=a[i];j<a[i+1]-1;j++)
			if (s[j]!=s[j+1]) ans=1;
	for (int i=1;i<=m;i++){
		int l=0,r=m+1-i;
		while (l<r){
			int mid=(l+r)>>1;
			if (a[i+mid]-mid>=b[i]) r=mid;else l=mid+1;
		}
		Max=max(Max,l);
	}
	printf("%d\n",ans+Max);
	return 0;
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<climits>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    unordered_map<int,int>ump1,ump2;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i+=2){
        ump1[v[i]]++;
    }
    for(int i=1;i<n;i+=2){
        ump2[v[i]]++;
    }
    int max1=0;
    int max2=0;
    int index1=0;
    int index2=0;
    for(auto it=ump1.begin();it!=ump1.end();it++){
        if(max1<=it->second){
            max2=max1;
            index2=index1;
            max1=it->second;
            index1=it->first;
        }
        else
        if(max2<it->second){
            max2=it->second;
            index2=it->first;
        }
    }
    int m1=0;
    int m2=0;
    int mindex1=0;
    int mindex2=0;
    for(auto it=ump2.begin();it!=ump2.end();it++){
        if(m1<=it->second){
            m2=m1;
            mindex2=mindex1;
            m1=it->second;
            mindex1=it->first;
        }
        else
        if(m2<it->second){
            m2=it->second;
            mindex2=it->first;
        }
    }
    int result=0;
    if(index1==mindex1){
        int f1=max1+m2;
        int f2=max2+m1;
        int result1=(v.size()-f1);
        int result2=(v.size()-f2);
        result=min(result1,result2);
    }
    else
    {
        result=(v.size()-m1-max1);
    }
    cout<<result;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    long long n,sum=0,he=0;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        he+=abs(a[i]);
        if(a[i]<0) sum++;
        a[i]=abs(a[i]);
    }
    sort(a,a+n);
    if(sum%2==0) cout<<he<<endl;
    else cout<<he-a[0]*2<<endl;
    return 0;
}


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

int main(){
	vector<int> v(1001);
	int cnt=0;
	for(int i=1; i<1002; i++){
		if(i%3==0) cnt++;
		v[i]=cnt;
	}
	int n; cin>>n;
	cout<<v[n]<<endl;
}

#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {

		int R;
		cin >> R;
		cout << R / 3 << endl;

}


#include<stdio.h>

//this file is not a C file but a C++ file

int main(void){
    int stnum;//the number of the student
    int pm, pe, pj;//ある生徒の点数
    char grade;//成績
    while(1) {
        scanf(" %d", &stnum);
        if(stnum == 0) {
            break;
        }
        for(int i = stnum - 1;i >= 0;i -= 1) {
            scanf(" %d %d %d", &pm, &pe, &pj);
            if((pm == 100 || pe == 100 || pj == 100) ||
               (pm + pe) / 2 >= 90                   ||
               (pm + pe + pj) / 3 >= 80) {
                grade = 'A';
            }else if((pm + pe + pj) / 3 >= 70 ||
                     (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80))){
                grade = 'B';
            }else{
                grade = 'C';
            }
            printf("%c\n", grade);
        }
    }
    return 0;
}

#include <iostream>

using namespace std;

void res(int, int, int);

int main()
{
    int n, pm, pe, pj;

    while (cin >> n, n) {
	for (int i = 0; i < n; i++) {
	    cin >> pm >> pe >> pj;
	    res(pm, pe, pj);
	}
    }
    return 0;
}

void res(int pm, int pe, int pj)
{
    double ave, meave;

    ave = (double)(pm + pe + pj) / 3;
    meave = (double)(pm + pe) / 2;

    if (pm == 100 || pe == 100 || pj == 100 || meave >= 90 || ave >= 80) {
	cout << 'A' << endl;
    } else if (ave >= 70 || ( ave >= 50 && ( pm >= 80 || pe >= 80))) {
	cout << 'B' << endl;
    } else {
        cout << 'C' << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  double N;
  cin>>N;
  vector<double>a(N);
  double sum=0;
  for(int i=0;i<N;i++){
    cin>>a[i];
    sum+=a[i];
  }
  double m=sum/N;
  double dis=9999999;
  for(int i=0;i<N;i++){
    if(dis>abs(a[i]-m)){dis=abs(a[i]-m);}
  }
  for(int i=0;i<N;i++){
    if(abs(a[i]-m)==dis){cout<<i<<endl;return 0;}
  }
  return 0;
}

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

using ll=long long;

int main() {
  int N; cin >>N;
  vector<int> a(N);
  rep(i,0,N) {
    cin >>a[i];
  }
  int b=accumulate(a.begin(),a.end(),0);
  int ans=0;
  int c=INT_MAX;
  rep(i,0,N) {
    int d=abs(N*a[i]-b);
    if (d<c) {
      c=d;
      ans=i;
    }
  }
  cout <<ans <<endl;
  return 0;
}


// ALPC-B.cpp

#include <iostream>
#include <atcoder/fenwicktree.hpp>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
int main()
{
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    ll a;
    rep(i, n) {
        cin >> a;
        fw.add(i, a); // fwに値をセット
    }
    ll q0, q1, q2;
    rep(i, q) {
        cin >> q0 >> q1 >> q2;
        if (q0 == 0) {
            fw.add(q1, q2); // fwの値を更新
        }
        if (q0 == 1) {
            cout << fw.sum(q1, q2) << endl; // fwで区間和を求める
        }
    }
}

#include <iostream>
#include <vector>
#include <functional>

template<typename T> struct segment_tree {
private :
	int N;
	std::vector<T> value;
public :
	const std::function<T(T, T)> op;
	const T id;

	segment_tree(const std::vector<T>& a, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int n = a.size(), m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
		for (int i = 0; i < n; i++) value[N + i] = a[i];
		for (int i = N - 1; i > 0; i--) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	segment_tree(const int& n, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
	}

	inline const int& size()const{return N;}

	void point_update(int i, const std::function<T(T, T)>& f, const T& t) {
		i += N;
		value[i] = f(value[i], t);
		while (i /= 2) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	T range_fold(const int& L, const int& R, const int& i = 1, const int& l = 0, int r = -1) {
		if (r == -1) r = N;
		if (L <= l && r <= R) return value[i];
		if (r <= L || R <= l) return id;
		return op(
			range_fold(L, R, i * 2, l, (l + r) / 2),
			range_fold(L, R, i * 2 + 1, (l + r) / 2, r)
		);
	}

	inline const T& operator[](const int& i)const{return value[N + i];}
};

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<long long> a(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];

	segment_tree<long long> sg(a, [](long long a, long long b){return a + b;}, 0);
	while (q--) {
		int op;
		std::cin >> op;
		if (op == 0) {
			int p; long long x;
			std::cin >> p >> x;
			sg.point_update(p, [](long long a, long long b){return a + b;}, x);
		} else {
			int l, r;
			std::cin >> l >> r;
			std::cout << sg.range_fold(l, r) << '\n';
		}
	}

	return 0;
}


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

int a, b, k;

int main() {
  cin >> a >> b >> k;
  for (int i = 0; i < k; ++i) {
    a /= 2;
    b += a;
    swap(a, b);
  }
  if (k & 1) swap(a, b);
  cout << a << " " << b << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    double n,m,d;
    cin>>n>>m>>d;
    double ans=(d*2+(n-(d*2))*2)/(n*n);
    ans*=(m-1);
    if(d==0) ans/=2;
    cout<<fixed<<setprecision(10)<<ans<<endl;

}


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

int main() {
  string s;
  cin >> s;
  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
}

#include<iostream>

using namespace std;

int main() {
  int x,m,n;
	while(cin >> x){
	  n=0;
	  m = 600/x;
	  for(int i = 1;i<m;i++){
	    n += x*x*x*i*i;
	  }

	  cout << n << endl;
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    cout << (n-2)*180 << endl;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];

  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

ll t[400008];
void build(vector<ll>& a, int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v*2, tl, tm);
        build(a, v*2+1, tm+1, tr);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}

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

void update(int v, int tl, int tr, int pos, ll new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2] ,t[v*2+1]);
    }
}

int main() {

int a;
cin>>a;
cout<<a+a*a+a*a*a;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBERS(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

ll Earliest(ll N, ll K, vector<ll> Xs)
{
    vector<ll> ret(N-K+1);
    for(ll i=0;i<N-K+1;i++)
    {
        if(Xs[i+K-1]<=0)
        {
            ret[i] = abs(Xs[i]);
        }
        else if(Xs[i]<=0)
        {
            ret[i] = abs(Xs[i]-Xs[i+K-1]) + min(abs(Xs[i]),Xs[i+K-1]);
        }
        else
        {
            ret[i] = Xs[i+K-1];
        }
    }
    return *min_element(ALL(ret));
}

int main()
{
    ll N,K;
    cin >> N >> K;

    vector<ll> Xs(N);
    ALLIN1_NUMBERS(Xs);

    OUT0(Earliest(N,K,Xs));

    return 0;
}

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, m; cin >> n >> m;
	bool ans = false;
	for (ll i = 0; i < n+1; i++) {
		for (ll j = 0; j < n+1; j++) {
			if (i + j <= n) {
				if (i * 1000 + j * 5000 + (n - i - j) * 10000 == m) {
					cout << n - i - j << " " << j << " " << i << endl;
					ans = true;
					break;
				}
			}
		}
		if (ans) break;
	}
	if (ans == false) {
		cout << -1 << " " << -1 << " " << -1 << endl;
	}
}


#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

using s64 = int64_t;

constexpr s64 INF = 1'010'000'000'000'000'000LL;

template<typename T, typename U>
bool chmin(T& xmin, const U& x)
{
    if(x < xmin) {
        xmin = x;
        return true;
    }
    else {
        return false;
    }
}

#define FOR(i, start, end) for(s64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

s64 N;
s64 M;
vector<vector<s64>> G;

void print_g() {
    REP(i, N) {
        REP(j, N) {
            s64 c = G[i][j];
            if(c == INF)
                cout << "INF";
            else
                cout << c;
            cout << (j==N-1 ? '\n' : ' ');
        }
    }
}

void floyd() {
    REP(k, N) {
        REP(i, N) {
            if(G[i][k] == INF) continue;
            REP(j, N) {
                if(G[k][j] == INF) continue;
                chmin(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
}

void solve() {
    floyd();

    REP(i, N) {
        if(G[i][i] < 0) {
            cout << "NEGATIVE CYCLE\n";
            return;
        }
    }

    print_g();
}

int main() {
    cin >> N;
    G.assign(N, vector<s64>(N, INF));
    REP(i, N) { G[i][i] = 0; }

    cin >> M;
    REP(_, M) {
        s64 a, b, c; cin >> a >> b >> c;
        G[a][b] = c;
    }

    solve();

    return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
const ll INF = 10000000000000;
int E,V;
vector<vector<ll> > d;
vector<vector<bool> > is_pass;
int warshall(){
  REP(k,V){
    REP(i,V){
      REP(j,V){
	if(is_pass[k][j]&&is_pass[i][k]){
	  d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
	  is_pass[i][j] = true;}
      }
    }
  }
  REP(i,V){
    if(d[i][i] < 0){
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  REP(i,V){
    REP(j,V){
      if(d[i][j]!=INF)
	cout << d[i][j];
      else
	cout << "INF";
      if(j<V-1)cout << " ";
    }
    cout << "\n";
  }
  return 0;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> V >> E;
  d.resize(V,vector<ll>(V,INF));
  is_pass.resize(V,vector<bool>(V,false));
  REP(i,E){
    int s,t;
    cin >> s >> t;
    cin >> d[s][t];
    is_pass[s][t] = true;
  }
  REP(i,V)d[i][i] = 0;
  warshall();

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;

int main()
{
    FAST
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数

template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/
//cout << std::fixed << std::setprecision(12) <<<< endl;

int main() {
	ll A,B;
	cin>>A>>B;
	cout<<(A*B)<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc045_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string A, B, C;
  cin >> A >> B >> C;

  int a = 0, b = -1, c = -1;
  char next = 'a';
  while (true) {
    if (next == 'a') {
      a++;
      if (a == A.size()) {
        cout << "A" << endl;
        return 0;
      }
      next = A[a];
    } else if (next == 'b') {
      b++;
      if (b == B.size()) {
        cout << "B" << endl;
        return 0;
      }
      next = B[b];
    } else {
      c++;
      if (c == C.size()) {
        cout << "C" << endl;
        return 0;
      }
      next = C[c];
    }
  }
}

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

int main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int tmp = 0;
    int num[3] = {0,0,0};
    while(num[tmp] < s[tmp].size()){
        num[tmp]++;
        tmp = s[tmp][num[tmp] - 1] - 'a';
    }
    cout << char('A' + tmp) << endl;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int as[3];
int main(){

  cin>>N;
  for(int i=0;i<N;i++)cin>>as[i];
  int maxV=0;
  for(int i=0;i<N;i++)maxV=max(maxV,as[i]);
  vector<int> v;
  for(int j=1;j<=maxV;j++){
    bool ok=true;
    for(int i=0;i<N;i++){
      if(as[i]%j!=0){
        ok=false;
        break;
      }
    }
    if(ok)v.push_back(j);
  }
  for(int i=0;i<(int)v.size();i++)
    cout<<v[i]<<endl;

  return 0;
}

#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define  MAX 100
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)

int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
int field[12][12];
char s[12];

void dfs(int x,int y){
	field[y][x] = 0;

	for(int i = 0;i < 4;i++){

		int nx = x + dx[i];
		int ny = y + dy[i];

		if(nx < 0 || ny < 0 || nx >= 12 || ny >= 12){

			continue;

		}else if(field[ny][nx] == 1){
			dfs(nx,ny);
		}
	}

}

void setfield(char S[],int y){
	rep(i,12){
		if(S[i] == '1'){
			field[y][i] = 1;
		}else{
			field[y][i] = 0;
		}
	}
}

int countisland(){
	int count = 0;
	rep(y,12){
		rep(x,12){
			if(field[y][x] == 1){
				count++;
				dfs(x,y);
			}
		}
	}
	return count;
}

int main(){

	while(true){
		if(scanf("%s",s) == EOF) break;
		setfield(s,0);
		FOR(i,1,12){
			scanf("%s",s);
			setfield(s,i);
		}
		cout << countisland() << endl;
	}

	return 0;
}


//ツ単ツ渉δづ可嘉ーツつッツづ篠つ「ツつ「ツつセツつッツつセツつェ, ツ板?湘」ツ額ツつェintツづ可偲サツづ慊づァツづ按つ「ツ嘉つ能ツ青ォツつェツつ?づゥツづ個づ?陳債暗督つオツづ按つッツづェツづ篠づ按づァツづ按つ「
//ツ姪「ツ妥ィツ閉カツづ可渉堕つゥツづェツづ?つ「ツづゥツ「100ツ鳴?* 10ツ鳴慊」ツづ個湘ーツ個渉づ?づ? intツづ可偲サツづ慊づァツづ按つ「
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

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

int main(){
  int n;
  ll sum[4002], num[4002];

  while(cin >> n, n){
    //ツ催?渉? ツ全ツ暗オツ板?湘」ツづ?
    fill(sum, sum + 4002, 0);

    //ツ全ツ暗オツづ慊つセツ禿シツ療債つウツづェツづ?つ「ツづ按つ「
    fill(num, num + 4002, -1);

    //ツ渉?氾板づ可湘ョツ陛アツづーツ禿シツ療?
    for(int i = 0; i < n; i++){
      ll m, a, b;
      cin >> m >> a >> b;

      //ツ板?湘」ツづーツ堕ォツつオツつアツづ?
      sum[m] += a * b;

      //ツ渉可づ淞づ?禿シツ療債つウツづェツつスツ偲青暗オツ氾板債?づ按づァツづ? ツ可スツ氾板姪堋づ可禿シツ療債つウツづェツつスツつゥツ記ツ可ッツつオツづ?つィツつュ
      if(num[m] == -1){
        num[m] = i;
      }
    }

    //ツ板?湘」ツつェ100ツ鳴慊暗按湘」ツづ個人ツづーツ療アツ仰督つキツづゥ
    //ツつアツづ個づ?つォ, ツ可スツ氾板姪堋づ可禿シツ療債つウツづェツつスツ人ツづ?つ?づゥツつゥツづ?つ「ツつ、ツ湘ョツ陛アツづ?暗ェツ渉渉づ英ush
    vector<P> ans;

    for(int i = 0; i < 4002; i++){
      if(1000000 <= sum[i]){
        ans.push_back(P(num[i], i));
      }
    }

    //ツ禿シツ療債渉?づ可陛?づ堕妥鳴つヲ
    sort(ans.begin(), ans.end());

    //ツ督堋つヲツ出ツ療?
    for(int i = 0; i < ans.size(); i++){
      cout << ans[i].second << endl;
    }

    //1ツ人ツづ?該ツ督鳴偲陳つェツつ「ツづ按つッツづェツづ晒A
    if(ans.size() == 0){
      cout << "NA\n";
    }
  }
}

#include <iostream>
#include <vector>
#include <utility>
#include <map>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, long long> > members;
        for (int i = 0; i < n; i++) {
            pair<int, long long> member;
            int id;
            long long cost, count;
            cin >> id >> cost >> count;
            bool exist = false;
            for (int i = 0; i < members.size(); i++) {
                if (members[i].first == id) {
                    members[i].second += cost * count;
                    exist = true;
                }
            }
            if (!exist) {
                member.first = id;
                member.second = cost * count;
                members.push_back(member);
            }
        }
        bool exist = false;
        for (vector< pair<int, long long> >::iterator m_i = members.begin();
                m_i != members.end(); m_i++) {
            if (m_i->second >= 1000000) {
                cout << m_i->first << endl;
                exist = true;
            }
        }
        if (!exist) {
            cout << "NA" << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{while(1)
{
	int  n=0;
	scanf("%d",&n);
	if(n==0){break;}
	int c=0,m[11]={0};
	for(int i=0;i<n;i++)
	{
		scanf("%d",&c);
		for(int j=0;j<11;j++)
		{
			if(c==j){m[j]++;break;}
		}
	}
	for(int i=0;i<10;i++)
	{
		if(m[i]==0){printf("-");}
		else
		{
		for(m[i]=m[i];m[i]>0;m[i]--)
		{
			printf("*");
		}
}
		printf("\n");
	}
}
	return 0;
}

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

int main(){
	int a[128];
	a[0]=a[1]=1;
	for(int i=1 ; i<32 ; i++){
		a[i]=a[i-1];
		if(i>1) a[i]+=a[i-2];
		if(i>2) a[i]+=a[i-3];
	}
	int n;
	while(cin>> n){
		if(n!=0){
		int day = (a[n]-a[n]%10)/10 + 1;
		int year =(day - day %365 )/365 + 1;
		cout<<year<<endl;
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vl a(6);
  rep(i, 6) cin >> a[i];
  cout << (a[4]-a[0]<=a[5] ? "Yay!" : ":(") << newl;
  return 0;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++

int main() {
  vi A(5);
  int k;
  rep(i,5)cin>>A[i];
  cin >> k ;
  string ans = "Yay!";
  rep(i,5) rep(j,5) {
    if (i >= j) continue;
    if (A[j] - A[i] > k) ans = ":(";
  }
  cout << ans << endl;
  return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

void visit(
    const Graph &g, size_t v, size_t u, set<size_t> &artpoint,
    vector<size_t> &num, vector<size_t> &low, int &time
) {
    low[v] = num[v] = ++time;
    for (const Edge &e: g[v]) {
        size_t w=e.dst;
        if (!num[w]) {
            visit(g, w, v, artpoint, num, low, time);
            low[v] = min(low[v], low[w]);

            if (num[v]==1? num[w]!=2 : low[w]>=num[v])
                artpoint.insert(v);

        } else {
            low[v] = min(low[v], num[w]);
        }
    }
}

set<size_t> get_artpoint(const Graph &g) {
    const size_t V=g.size();

    vector<size_t> low(V), num(V);
    set<size_t> artpoint;
    for (size_t u=0; u<V; ++u) if (!num[u]) {
        int time=0;
        visit(g, u, -1, artpoint, num, low, time);
    }

    return artpoint;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        scanf("%zu %zu", &s, &t);

        join(g, s, t);
    }

    set<size_t> artpoint=get_artpoint(g);

    for (size_t v: artpoint)
        printf("%zu\n", v);

    return 0;
}

// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

const int MAXN = 100010;

int n;
vector<int> g[100010];

int zeit, dis[MAXN], fin[MAXN], low[MAXN], par[MAXN], dep[MAXN];
int kodat[MAXN], koptr[MAXN + 1];
void dfsInfo(int u,int oy,int d){
	dis[u] = low[u] = zeit++; par[u] = oy; dep[u] = d;
	int v;
	rep(i,sz(g[u])) if((v = g[u][i]) != oy){
		if(!~dis[v]){
			dfsInfo(v, u, d + 1);
			low[u] = min(low[u], low[v]);
		} else {
			low[u] = min(low[u], dis[v]);
		}
	}
	fin[u] = zeit++;
}

void dfsInfos(){
	memset(dis, ~0, n*4); zeit = 0;
	rep(u,n) if(!~dis[u]) dfsInfo(u, -1, 0);
	rep(u,n){
		int &j = koptr[u + 1] = koptr[u];
		rep(i,sz(g[u])) if(u == par[g[u][i]]) kodat[j++] = g[u][i];
	}
}

bool produce(int u,int v){
	return (dis[u] <= dis[v] && fin[u] >= fin[v]);
}

int related(int u,int v){
	int s = koptr[u], e = koptr[u+1], h;
	while(s+1 < e){
		h = (s + e) >> 1;
		(dis[kodat[h]] <= dis[v]) ? s = h : e = h;
	}
	return kodat[s];
}

bool isBridge(int u,int v){
	if(dis[u] > dis[v]) swap(u, v);
	return (u == par[v] && dis[v] <= low[v]);
}

int Count[MAXN];

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

	int m;
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep(i,n)sort(g[i].begin(),g[i].end());
	dfsInfos();
	Count[0] = -1;
	rep(i,n)rep2(j,koptr[i],koptr[i+1]){
		Count[i] += dis[i] <= low[kodat[j]];
	}
	rep(i,n){
		if(Count[i] > 0)cout<<i<<endl;
	}
	//rep(i,n)cout<<Count[i]<<" ";cout<<endl;
}


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

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

  if (a <= 8 && b <= 8)
    cout << "Yay!" << '\n';
  else
    cout << ":(" << '\n';

  return 0;
}

#include <iostream>

using namespace std;

int main() {
    int A;
    int B;
    cin >> A;
    cin >> B;
    int eatA = 0;
    int eatB = 0;
    for (int i = 0; i < 16; i++) {
        if (i % 2 == 0) {
            eatA++;
        } else {
            eatB++;
        }
    }
    if (eatA >= A && eatB >= B) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}


#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;
const int N = 1e6 + 10, P = 998244353;
int n, m, ans, inv[N], fac[N];
int qp (int a, int b) { int c = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P; return c; }
int main () {
	scanf("%d%d", &n, &m); if (n < m) n ^= m ^= n ^= m;
	inv[0] = inv[1] = 1; for (int i = 2; i <= n + m; ++i) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
	fac[0] = 1; for (int i = 1; i <= n + m; ++i) fac[i] = 1ll * fac[i - 1] * i % P, inv[i] = 1ll * inv[i] * inv[i - 1] % P;
	for (int i = 1; i <= m; ++i) ans = (1ll * fac[i << 1] * inv[i] % P * inv[i] % P * fac[n + m - (i << 1)] % P * inv[n - i] % P * inv[m - i] + ans) % P;
	return printf("%d\n", (1ll * ans * qp(1ll * fac[n + m] * inv[n] % P * inv[m] % P * 2 % P, P - 2) + n) % P), 0;
}


#include <stdio.h>

int
main(void)
{
	char line[80];
	int d;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &d) == 1) {
			int s = 0;
			for (int i = 1; d*i <= 600 - d; i++) {
				s += (d*i)*(d*i) * d;
			}
			printf("%d\n", s);
		}
	}

	return 0;
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string str;
	while(cin>>str){
		vector<int> Vec;
		for(int i=0; i < str.size();i++){
			if(str[i] == 'I'){
				Vec.push_back(1);
			}else if(str[i] == 'V'){
				Vec.push_back(5);
			}else if(str[i] == 'X'){
				Vec.push_back(10);
			}else if(str[i] == 'L'){
				Vec.push_back(50);
			}else if(str[i] == 'C'){
				Vec.push_back(100);
			}else if(str[i] == 'D'){
				Vec.push_back(500);
			}else if(str[i] == 'M'){
				Vec.push_back(1000);
			}
		}

		int sum=0;
		bool flag = false;
		for(int i=0;i<Vec.size()-1;i++){
			// 右側に大きな数が続くとき
			if( Vec[i] < Vec[i+1] ){
				sum += Vec[i+1] - Vec[i];
				// iを一つ進める
				i++;
				flag = true;
			}else{  // 右側に同じ又は小さな数
				sum += Vec[i];
				flag = false;
			}
		}
		// 最後まで足せていない場合は、最後だけ足す
		if( !flag ){
			sum += Vec[ Vec.size()-1 ];
		}

		cout<<sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
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++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);

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

    int h,w,a,b;
    cin >> h >> w >> a >> b;
    rep(i,h) {
        rep(j,w) {
            bool flag=(i<b)^(j<a);
            if (flag) cout << '0';
            else cout << '1';
        }
        cout << endl;
    }

    return 0;
}

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

int main()
{
    string weeks[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

    struct tm  t;
    t.tm_year  = 2004 - 1900;
    t.tm_hour  = 0;
    t.tm_min   = 0;
    t.tm_sec   = 0;
    t.tm_isdst = 0;

    for (int month, day; cin >> month >> day && (month || day);) {
        t.tm_mon   = month - 1;
        t.tm_mday  = day;
        mktime(&t);
        cout << weeks[t.tm_wday] << endl;
    }

    return 0;
}


///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=998244353;
const int M=100005;
inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
int k,zero=0,one=0,cur=0;
string s;
vector< vector< vector<int> > >dp;
int cnt[306];
int solve(int pos,int has,int op)
{
    if(op>k)return 0;
    if(pos==cur)return 1;
    int &ret=dp[pos][has][op];
    if(ret!=(-1))return ret;
    ret=0;
    for(int i=0;i<=cnt[pos];i++)
    {
        ret=ad(ret,solve(pos+1,has+i,op+i));
    }
    for(int i=1;i<=has;i++)
    {
         ret=ad(ret,solve(pos+1,has-i,op));
    }
    return ret;
}
 main()

{
    fast
    cin>>s>>k;
    for(auto ch:s)
    {
        if(ch=='0')zero++;
        else one++;
    }
    dp.resize(zero+3);
    for(auto &x:dp)
    {
        x.resize(one+2);
        for(auto &y:x)
        {
            y.resize(one+2,-1);
        }
    }
    while(s.size())
    {
        if(s.back()=='0')cur++;
        else cnt[cur]++;
        s.pop_back();
    }
    cout<<solve(0,0,0)<<endl;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define fill(x, k) memset(x, k, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y , true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y , true) : false; }
struct __init { __init()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cout.precision(16); cout << fixed;
	srand(time(0) ^ ui(ul(new char)));
}};
static __init __init__;
/* default code ends here */
const ll mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, m;
ll a[maxn], b[maxn];
int main()
{
	cin >> n >> m;
	enum(i, 1, n)
		cin >> a[i];
	enum(i, 1, m)
		cin >> b[i];
	ll s1 = 0, s2 = 0;
	enum(i, 1, n - 1)
		s1 = (s1 + (a[i + 1] - a[i]) * i % mod * (n - i)) % mod;
	enum(i, 1, m - 1)
		s2 = (s2 + (b[i + 1] - b[i]) * i % mod * (m - i)) % mod;
	cout << s1 * s2 % mod << '\n';
	return 0;
}


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

static const int NIL = -1;

struct Vertex {
    vector<int> link;
    int parent = NIL;
    int ord;
    int lowlink;
    bool is_visit = false;
};

class ArticulationPoint {
private:
    int n;
    vector<Vertex> graph;
    int timer = 1;

public:
    ArticulationPoint() {}

    ArticulationPoint(int n)
    {
        this->n = n;
        graph.resize(n);
        int edge;
        cin >> edge;
        int s, t;
        for (int e = 0; e < edge; e++)
        {
            cin >> s >> t;
            graph[s].link.push_back(t);
            graph[t].link.push_back(s);
        }
    }

    void dfs(int current)
    {
        graph[current].is_visit = true;
        graph[current].ord = graph[current].lowlink = timer;
        timer++;

        for(int next : graph[current].link)
        {
            if(!graph[next].is_visit)
            {
                graph[next].parent = current;
                dfs(next);
                graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3.
            }
            else if(next != graph[current].parent)
            {
                // １回の移動で行くことのできる訪問済みの頂点は，Backedgeを除けば自分の親しかいない
                // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき
                graph[current].lowlink = min(graph[current].lowlink, graph[next].ord);
            }

        }
    }

    void articulation_point()
    {
        set<int> art_point;
        int root = 0;

        dfs(root);

        int root_child_num = 0;
        for(int u = 0; u < n; u++)
        {
            int p = graph[u].parent;
            if(p == NIL) continue;
            if(p == root)
            {
                root_child_num++;
                if(root_child_num >= 2)
                    art_point.insert(root);
            }
            else if(graph[p].ord <= graph[u].lowlink)
            {
                art_point.insert(p);
            }
        }

        for(int x : art_point)
            cout << x << endl;
    }
};

int main()
{
    int n;
    cin >> n;
    ArticulationPoint articulationPoint(n);
    articulationPoint.articulation_point();
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vvi g(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); g[v].push_back(u);
	}
	int timer = 0;
	vi stTime(n, INF), enTime(n, INF);
	vi low(n);
	vi ans(n);
	function<void(int, int)> dfs = [&] (int u, int p) {
		stTime[u] = timer++;
		low[u] = stTime[u];
		int jai = 0;
		for (int v : g[u]) {
			if (v == p) continue;
			if (stTime[v] >= INF) {
				// tree edge
				dfs(v, u);
				low[u] = min(low[u], low[v]);
				if (low[v] >= stTime[u] && p != -1) ans[u] = 1;
				jai++;
			} else if (enTime[v] >= INF) {
				// back edge
				low[u] = min(low[u], stTime[v]);
			}
		}
		enTime[u] = timer;
		if (p == -1 && jai > 1) ans[u] = 1;
	};
	dfs(0, -1);
	for (int i = 0; i < n; i++) if (ans[i]) cout << i << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

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

// vim: fdm=marker


#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  V<int> a;
  map<int, int> count;
  cin >> n;
  a.resize(n);
  rep(i, n) {
    cin >> a[i];

    count[a[i]] = 0;
  }

  // Count
  rep(i, n) {
    count[a[i]]++;
  }
  // Aggregate
  int ans = 0;
  for(auto it = count.begin(); it != count.end(); it++) {
    if(it->second % 2 == 1) {
      ans++;
    }
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    set<ll> s;
    rep(i, n) {
        ll a; cin >> a;
        if(s.count(a)) s.erase(a);
        else s.insert(a);
    }
    cout << s.size() << endl;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>n;
    if(n<=111) cout<<111;
    else if(n<=222) cout<<222;
else    if(n<=333) cout<<333;
    else if(n<=444) cout<<444;
 else   if(n<=555) cout<<555;
   else if(n<=666) cout<<666;
  else  if(n<=777) cout<<777;
   else if(n<=888) cout<<888;
   else if(n<=999) cout<<999;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    cout<<(n+110)/111*111<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int pts[101] = {};
    int n;
    cin >> n;

    int const rn = n * ( n - 1 ) / 2;
    for( int i=0; i<rn; ++i ) {
        int ca, cb, pa, pb;
        cin >> ca >> cb >> pa >> pb;
        if ( pa > pb ) {
            pts[ca-1] += 3;
        } else if ( pb > pa ) {
            pts[cb-1] += 3;
        } else if ( pa == pb ){
            pts[ca-1] += 1;
            pts[cb-1] += 1;
        }
    }

    int rank[101] = {};
    int last = -1, rk=0, tr = 1;
    for( int i=0; i<n; ++i ) {
        int mm = 0, r = -1;
        for( int j=0; j<n; ++j ) {
            if ( pts[j] > mm ) {
                mm = pts[j];
                r = j;
            }
        }
        if ( mm == last ) {
            ++tr;
        } else {
            rk += tr > 0 ? tr : 1;
            tr = 1;
        }
        rank[r] = rk;
        last = mm;
        pts[r] = -1;
    }

    for( int i=0; i<n; ++i ) {
        cout << rank[i] << endl;
    }
}

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

int main()
{
    int n,i, m,c1=0,c2=0;
    cin >> n;
    set <int> winner;
    set <int>::iterator it1;
    multiset <int> loser;
    multiset <int>::iterator it2;
    for(i=0; i<n; i++)
    {
        cin >> m;
        winner.insert(m);
        loser.insert(m);
    }
    it1=winner.begin();
    it2=loser.begin();

    for(i=0; it1!=winner.end(); i++)
    {
        if(*it1==*it2)
        {
            c1 = c1+1;

            it2++;
        }
        else
        {
            it1++;
            c2 = c2 + (c1&1);

            c1 = 0;
        }
    }
    cout << c2 + (c1&1);

}


#include <iostream>
using namespace std;
int main(){
  int n,p,data[50],i,d,result;
  while(1){
    cin >> n >> p;
    d=p;
    if(n==0&&p==0) break;
    for(i=0;i<n;i++) data[i]=0;
    i=0;
    while(1){
      if(p>0){
	p--;
        data[i]++;
	if(data[i]==d){
	  result=i;
	  break;
	}
      }else if(p==0){
        p=data[i];
        data[i]=0;
      }
      if(i+1==n) i=0;
      else i++;
    }
    cout << result << endl;
  }
  return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll n, m;
vector<ll> G[N], R[N];
ll id[N], ans[N], root;
ll M[N];
vector<ll> T;
void DFS(ll v) {
	M[v] = 1;
	for (auto u : G[v])
		if (!M[u])
			DFS(u);
	T.pb(v);
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; i ++) {
		ll v, u;
		cin >> v >> u;
		G[v].pb(u);
		R[u].pb(v);
	}
	for (int i = 1; i <= n; i ++) {
		if (R[i].size()) continue;
		DFS(i);
	}
	reverse(all(T));
	root = T[0];
	for (int i = 0; i < n; i ++) {
		id[T[i]] = i;
	}
	for (int i = 1; i <= n; i ++) {
		ll pos = -1, v = 0;
		for (auto u : R[i]) {
			if (id[u] > pos) {
				pos = id[u];
				v = u;
			}
		}
		ans[i] = v;
	}
	for (int i = 1; i <= n; i ++) {
		cout << ans[i] <<  '\n';
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main(){
  int N, M, A[1024], c[1024];
  scanf("%d%d", &N, &M);
  memset(c, 0, sizeof(c));

  rep(i, N) scanf("%d", A+i);
  rep(i, M){
    int B;
    scanf("%d", &B);
    int p = 0;
    rep(j, N) if(B >= A[j]){ p = j; break;}
    c[p]++;
  }
  //      cout << "ok\n";
  int res =0;
  rep(i, N) if(c[res] <= c[i]) res = i;
  printf("%d\n", res+1);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

class BinaryIndexedTree {
 private:
  int n;
  vector<int64> xs;
 public:
  BinaryIndexedTree(int n) : n(n), xs(n) {}

  // Adds x to the i-th element.
  void Add(int i, int64 x) {
    int cur = i;
    while (cur < n) {
      xs[cur] += x;
      cur = cur | (cur + 1);
    }
  }

  // Returns a sum of a range [l r).
  int64 SumOfRange(int l, int r) {
    if (l >= r) return 0;
    if (l > 0) {
      return SumOfRange(0, r) - SumOfRange(0, l);
    }
    int64 s = 0;
    int i = r - 1;
    while (i >= 0) {
      s += xs[i];
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
};

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

  int n, q;
  cin >> n >> q;
  BinaryIndexedTree bit(n);
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  for (int i = 0; i < n; i++) {
    bit.Add(i, xs[i]);
  }
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 0) {
      int p, x;
      cin >> p >> x;
      bit.Add(p, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << bit.SumOfRange(l, r) << "\n";
    }
  }
}


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

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

    vector<int> p(n);
    int cnt = 0, min = 200001;
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
        if (p.at(i) <= min) cnt++;
        if (p.at(i) < min) min = p.at(i);
    }

    cout << cnt << endl;

    return 0;
}

/*
      Ashraful Islam Paran
      27-August-2020
      19:56:18
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, i, j, cnt = 0, l, x;
    cin >> n;
    x = n + 1;
    f(n)
    {
        cin >> j;
        if (j < x)
        {
            cnt++;
            x = j;
        }
    }
    cout << cnt << endl;

    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


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

using namespace std;

int main(void)
{
	int n1 , n2;
	vector<int> val1 , val2 , ans;
	int input;

	cin >> n1 >> n2;

	for (int i = 0; i < n1; i++)
	{
		cin >> input;
		val1.push_back(input);
		ans.push_back(0);
	}
	for (int i = 0; i < n2; i++)
	{
		cin >> input;
		val2.push_back(input);
	}

	for (int i = 0; i < n2; i++)
	{
		for (int j = 0; j < n1; j++)
		{
			if (val2[i] >= val1[j])
			{
				ans[j]++;
				break;
			}
		}
	}

	int Max = -100;
	int index = -1;

	for (int i = 0; i < ans.size(); i++)
	{
		if (ans[i] > Max)
		{
			Max = ans[i];
			index = i;
		}
	}

	cout << index + 1 << endl;

	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a)
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	map<int,int> f;
	int x;
	vector<int> a;
	for(int i=0;i<n;i++){x=in();f[x]++;}
	for(auto i:f)
	{
		int t=i.second;
		t/=2;
		for(int _=0;_<t;_++)a.push_back(i.first);
	}
	sort(a.rbegin(),a.rend());
	if(a.size()<=1)cout<<0;
	else cout<<a[0]*a[1];

}


#include <bits/stdc++.h>

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    if (s[0] == s[1] && s[1] == s[2] && s[0] == 'R') {
        cout << 3 << endl;
    }
    else if (s[1] == 'R' && (s[0] == 'R' || s[2] == 'R')) {
        cout << 2 << endl;
    }
    else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string s;
    cin>>s;
    int ans = 0;
    int ma = INT_MIN;
    for(int i=0;i<s.size();i++) {
        if(s[i] == 'R') {
            ans++;
        }
        else {
            ma = max(ma, ans);
            ans = 0;
        }
    }
     ma = max(ma, ans);

    cout<<ma<<endl;
}


#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF_L = 1e17+7;
const long long INF_I = 1e9+7;
const long long MOD = 1e9+7;
const double EPS = 1e-8;
const double PI=acos(-1);

using namespace std;

int main(){

	long long n,m,d;
	cin >> n >> m >> d;
	long double ans;

	if(d>0){
		ans=(double)(m-1)*(2*(double)(n-d)/(double)(pow(n,2)));
	}else if(d==0){
		ans=(double)(m-1)*((double)1/(double)(pow(n,1)));
	}

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

	return 0;
}

#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
#define  inf 1e6+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=500001;
#define  pq priority_queue
#define  ff first
#define  ss second
#define pb  push_back
#define lb lower_bound

ll k1=0;
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
	k1=max(k1,abs(a.ff-b.ff)+abs(a.ss-b.ss));
	if(a.ff>b.ff)
		return 1;

	if(a.ff==b.ff&&a.ss>b.ss)
		return 1;
	return 0;
}
int dx[]={1,-1};
int dy[]={1,-1};
int main()
{
	fastio;
	int t;
	ll i,j,k,n,m,l;
	cin>>n>>k>>l;
	if(k*l>=n)
		cout<<"Yes";
	else
		cout<<"No";

}
//Lordvishnu@almighty


#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi = vector<int>;
using vl= vector<ll>;
using vs=vector<string>;

ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a);}
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
ll power(ll a,ll b) {long long res = 1; while (b > 0) {if (b & 1)res = res * a;a = a * a;b >>= 1;} return res;}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;

    for(int p=0;p<testcase;p++){
        ll a=0,b=0,m=0;
        cin>>a>>b>>m;
        ll array[a]={0};
        ll array2[b]={0};
        ll array3[m]={0};
        ll mina=9999999999,minb=9999999999;
        for(int i=0;i<a;i++){
            cin>>array[i];
            mina=min(array[i],mina);
        }
        for(int i=0;i<b;i++){
            cin>>array2[i];
            minb=min(array2[i],minb);
        }
        ll min1=9999999999;
        ll min_index=0;
        for(int i=0;i<m;i++){
            ll tempa=0,tempb=0,tempc=0;
            cin>>tempa>>tempb>>tempc;
            array3[i]=array[tempa-1]+array2[tempb-1]-tempc;
            if(array3[i]<=min1)
            min1=array3[i];
        }
        min1=min(min1,mina+minb);

        cout<<min1;

        }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 510;
int p[10010];
vector<int> primes;
int a[N * 2], b[N * 2];

void init() {
    for (int i = 2; i < 10000; i++) {
        if (!p[i]) {
            for (int j = i + i; j < 10000; j += i) {
                p[j] = 1;
            }
            primes.push_back(i);
        }
    }
}

long long res[N][N];
set<long long> has;

long long lcm(long long a, long long b) {
    long long c = __gcd(a, b);
    return (a / c) * b;
}

int main() {
    init();
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        a[i] = primes[cnt++];
    }
    for (int i = 0; i < n; i++) {
        b[i] = primes[cnt++];
    }
    memset(res, -1, sizeof res);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                int aa = i + j >> 1;
                int bb = (i - j + n) >> 1;
                res[i][j] = 1ll * a[aa] * b[bb];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i + j) % 2 == 0) {
                continue;
            }
            long long foo = 1ll;
            if (i > 0) {
                foo = lcm(foo, res[i - 1][j]);
            }
            if (i + 1 < n) {
                foo = lcm(foo, res[i + 1][j]);
            }
            if (j > 0) {
                foo = lcm(foo, res[i][j - 1]);
            }
            if (j + 1 < n) {
                foo = lcm(foo, res[i][j + 1]);
            }
            int it = 1;
            while (has.count(foo * it)) {
                it++;
            }
            has.insert(foo * it);
            res[i][j] = foo * it + 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            printf("%lld ", res[i][j]);
        }
        printf("\n");
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
typedef long long ll;

const int MAXN=505,MAXD=7919;
const int movx[4]={-1,0,1,0},movy[4]={0,1,0,-1};

int n; ll a[MAXN][MAXN];
bool vis[MAXD]; ll prime[MAXN<<1];

inline ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}

inline ll lcm(ll a,ll b){
	if(!a||!b) return a|b;
	return a/gcd(a,b)*b;
}

inline void judge(){
	int x,a[505][505];
	scanf("%d",&x); lor(i,1,x) lor(j,1,x) scanf("%d",&a[i][j]);

}

int main(){
	scanf("%d",&n);

	if(n==2) return printf("4 7\n23 10\n"),0;

	lor(i,2,MAXD){
		if(!vis[i]) prime[++prime[0]]=i;
		for(register int j=1;j<=prime[0]&&i*prime[j]<=MAXD;++j) vis[i*prime[j]]=true;
	}

	lor(i,1,n) lor(j,1,n) if(!((i+j)&1)){
		a[i][j]=prime[(i+j)>>1]*prime[n+(n+1)/2+(i-j)/2];
	}
	lor(i,1,n) lor(j,1,n) if((i+j)&1){
		a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i+1][j],a[i][j+1]))+1;
	}
	lor(i,1,n){
		lor(j,1,n) printf("%lld ",a[i][j]); printf("\n");
	}

	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int result=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            result+=abs(v[i]);
        }
        else
        {
            result+=abs(v[i]-v[i-1]);
        }
        if(i==n-1)
        {
            result+=abs(v[i]);
        }
    }
    int prev=0;
    int next=v[1];
    for(int i=0;i<n;i++)
    {
        if(i==0)
            prev=0;
        else
            prev=v[i-1];
        if(i==n-1)
            next=0;
        else
            next=v[i+1];
        int temp;
        temp=abs(v[i]-prev);
        temp+=abs(v[i]-next);
        int tempresult=result;
        tempresult-=temp;
        tempresult+=abs(next-prev);
        cout<<tempresult<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

int main(){
    ll N; cin >> N;
    vector<ll> a(N + 2, 0), s(N + 2, 0);
    rep(i, N){
        cin >> a[i + 1];
        s[i + 1] = s[i] + abs(a[i] - a[i + 1]);
    }
    s[N + 1] = s[N] + abs(a[N] - a[N + 1]);

    rep(i, N){
        pt(s[i] + abs(a[i + 2] - a[i]) + s[N + 1] - s[i + 2]);
    }
    return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

int main(){
	int a,b,k; scanf("%d%d%d",&a,&b,&k);
	rep(i,k){
		if(i%2==0){
			if(a%2==1) a--;
			b+=a/2;
			a/=2;
		}
		else{
			if(b%2==1) b--;
			a+=b/2;
			b/=2;
		}
	}
	printf("%d %d\n",a,b);
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> AB(2);
    for (int i=0;i<2;++i) cin >> AB[i];
    int K; cin >> K;
    for (int i=0;i<K;++i){
        if (AB[i&1]&1) --AB[i&1];
        AB[(i&1)^1]+=AB[i&1]/2;
        AB[i&1]/=2;
    }
    cout << AB[0] << ' ' << AB[1] << '\n';
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int r,g;
  cin>>r>>g;
  cout<<g-r+g<<'\n';
  return 0;
}

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

    int main() {
      double late = 0.0 , wanna = 0.0;
      cin >> late >> wanna;
      cout << wanna * 2 - late;
    }


#include<cstdio>
#include<algorithm>
using namespace std;
const int N=602,K=200020;
int n,m,a,b,i,j,d;
bool col[N][N];
void Col(int x){
    d=0;
    while(x%4==0)
        x/=4,d++;
    if(x&1){
        for(i=0;i<m;i++)
            for(j=0;j<m;j++)
                if((i>>d&1)^(j>>d&1))
                    col[i][j]=1;
    }
    else{
        for(i=0;i<m;i++)
            for(j=0;j<m;j++)
                if((i>>d&1))
                    col[i][j]=1;
    }
}
int main(){
    scanf("%d%d%d",&n,&a,&b);
    m=n*2;
    n*=n;
    Col(a);Col(b);
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
            if(col[i][j]==0){
                printf("%d %d\n",i,j);
                n--;
                if(!n)return 0;
            }
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define x first
#define y second

namespace QAQ
{
	typedef std::pair<int,int> pii;

	const int N=303;

	int type[N*2][N*2];
	int n,d0,d1;

	bool vis[N*2][N*2];
	std::vector<pii> mv;

	void dfs(int nx,int ny,int val,int cur=0)
	{
		if(nx<0 || ny<0 || nx>=n*2 || ny>=n*2 || vis[nx][ny])return;

		vis[nx][ny]=1,type[nx][ny]^=cur,cur^=val;

		for(int i=0;i<(int)mv.size();i++)
			dfs(nx+mv[i].x,ny+mv[i].y,val,cur);
	}

	void work(int dis,int val)
	{
		mv.resize(0);
		for(int i=0;i*i<=dis;i++)
			for(int j=0;i*i+j*j<=dis;j++)
				if(i*i+j*j==dis)
				{
					mv.push_back(pii(i,j));
					mv.push_back(pii(-i,j));
					mv.push_back(pii(i,-j));
					mv.push_back(pii(-i,-j));
				}

		memset(vis,0,sizeof(vis));
		for(int i=0;i<n*2;i++)
			for(int j=0;j<n*2;j++)
				if(!vis[i][j])dfs(i,j,val);
	}
	std::vector<pii> ans[4];
	void solve()
	{
		scanf("%d%d%d",&n,&d0,&d1);
		work(d0,1),work(d1,2);

		for(int i=0;i<n*2;i++)
			for(int j=0;j<n*2;j++)
				ans[type[i][j]].push_back(pii(i,j));
		int ind=0;
		for(int i=1;i<4;i++)
			if(ans[i].size()>ans[ind].size())ind=i;

		if((int)ans[ind].size()<n*n)printf("O_O\n");

		for(int i=0;i<n*n;i++)
			printf("%d %d\n",ans[ind][i].x,ans[ind][i].y);
	}
}

int main()
{
	QAQ::solve();
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> num(55556);
    for(int i = 0; i < 55556; i++) num[i] = i;
    num[0] = -1;
    num[1] = -1;
    for(int i = 2; i < 55556; i++){
        if(num[i] == -1) continue;
        int t = 2;
        while(i * t <= 55555){
            num[i * t] = -1;
            t++;
        }
    }
    vector<int> sosuu;
    for(int i = 0; i < 55556; i++){
        if(num[i] != -1) sosuu.push_back(num[i]);
    }
    vector<int> cnt(5, 0);
    for(int i = 0; i < sosuu.size(); i++){
        cnt[sosuu[i] % 5]++;
    }
    int t = 0;
    for(int i = 0; i < sosuu.size(); i++){
        if(t == N) break;
        if(sosuu[i] % 5 == 1) {
            cout << sosuu[i] << ' ';
            t++;
        }
    }
    cout << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> p(60000,1);
  vector<int> q;
  for(int i=2;i<55556;i++){
    if(p[i]){
      for(int j=i*2;j<=55555;j+=i){
        p[j]=0;
      }
      if(i%5==1){
        q.push_back(i);
      }
    }
  }
  for(int i=0;i<N;i++){
    cout<<q[i];
    if(i-1==N){
      cout<<endl;
    }
    else{
      cout<<" ";
    }
  }
}


#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n;
    cin>>n;
    n=2*n;
    int a[2*n];

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

    sort(a,a+n);

    int s=0;

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

    cout<<s<<endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

    int N;
    cin>>N;
    vector<int> vi;
    int L;
    for(int i=0;i<2*N;++i){
        cin>>L;
        vi.push_back(L);
    }

    sort(vi.begin(), vi.end());
    int sum=0;
    for(int i=0;i<vi.size();i+=2){
        sum+=vi[i];
    }
    cout<<sum;
    return 0;
}


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

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

pair<int,int> func(map<int,int> m){
    int MAX = -1; int IDX;
    for(auto i=m.begin();i!=m.end();i++){
        if(MAX<i->second){IDX=i->first; MAX=i->second;}
    }
    pair<int, int> p = make_pair(IDX,MAX);
    return p;
}

int main() {
    int n; cin >> n;
    map<int,int> m1{};
    map<int ,int> m2{};
    for(int i=0;i<n;i++){
        int m; cin>>m;
        if(i%2==0)m1[m]++;
        else m2[m]++;
    }
    pair<int, int> M1 = func(m1);
    pair<int, int> M2 = func(m2);
    //cout << M1.first << M2.first << endl;
    if(M1.first == M2.first){
        m1[M1.first]=0; m2[M2.first]=0;
        pair<int, int> M3 = func(m1);
        pair<int, int> M4 = func(m2);
        cout << n-max(M1.second+M4.second, M2.second+M3.second) << endl;
    }
    else cout << n-M1.second- M2.second << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b

signed main(){
	ll n; cin>>n;
	map<ll,ll> a,b;
	rep(i,1,n+1){
		ll m; cin>>m;
		if(i%2==0){//偶数
			a[m]++;
		}
		else{
			b[m]++;
		}
	}
	vector<pair<ll,ll>> q(n),p(n);
	// q=even p=odd
	for(auto c:a) q.push_back(make_pair(c.second,c.first));
	for(auto c:b) p.push_back(make_pair(c.second,c.first));
	sort(all(p)); reverse(all(p));
	sort(all(q)); reverse(all(q));
	ll x,y;
	ll ans=n;
	rep(i,0,q.size()){
		if(i==2)break;
		rep(j,0,p.size()){
			if(j==2)break;
			if(q[i].second!=p[j].second){
				chmin(ans,n-q[i].first-p[j].first);
			}
		}
	}
	if(ans==n)ans/=2;
	cout<<ans<<endl;

	return 0;
}