// Hail god Yato

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

#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    ll a, b;
    cin>>a>>b;
    cout<<a*b;
}
int main(){
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

void abc_164a();

void abc_165a();

void abc_166a();

void abc_167a();

void abc_168a();

void abc_169();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  //abc_163a();
  //abc_164a();
  //abc_165a();
  //abc_166a();
  //abc_167a();
  //abc_168a();
  abc_169();

}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

void abc_164a()
{
  int s, w;
  cin >> s >> w;

  if (s <= w) cout << "unsafe\n";
  else cout << "safe\n";
}

void abc_165a()
{
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = a; i <= b; ++i)
  {
    if (i % k == 0)
    {
      cout << "OK\n";
      return;
    }
  }

  cout << "NG\n";
}

void abc_166a()
{
  string s;
  cin >> s;

  if (s == "ABC") cout << "ARC\n";
  if (s == "ARC") cout << "ABC\n";

}

void abc_167a()
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] != t[i])
    {
      cout << "No\n";
      return;
    }
  }

  if ('a' <= t[t.size() - 1] && t[t.size() - 1] <= 'z') cout << "Yes\n";
  else cout << "No\n";

}

void abc_168a()
{
  string s;
  cin >> s;

  if (s[s.size() - 1] == '3') cout << "bon\n";
  else if (s[s.size() - 1] == '0' ||
    s[s.size() - 1] == '1' ||
    s[s.size() - 1] == '6' ||
    s[s.size() - 1] == '8') cout << "pon\n";
  else cout << "hon\n";
}

void abc_169()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << "\n";
}


#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;

#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()

string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;

const ll nax = 100500;
ll F[nax], INVF[nax];

ll pow(ll a, ll b) {
	if (b == 0) return 1;
	ll h = pow(a, b/2);
	ll ans = b % 2 ? h * h % mod * a : h * h;
	ans %= mod;
	return ans;
}

ll ncr(ll n, ll r) {
	// n! / r! / (n-r)!
	ll ans = F[n];
	ans *= INVF[r];
	ans %= mod;
	ans *= INVF[n-r];
	ans %= mod;
	return ans;
}

void solve() {
	ll n, m;
	in(n, m);

	F[0] = 1;
	REP(i,1,nax) F[i] = (F[i-1] * i) % mod;
	REP(i,0,nax) INVF[i] = pow(F[i], mod-2);

	map<ll,ll> factors;
	ll f = 2;
	while (m != 1 && f*f <= m) {
		while (m % f == 0) {
			factors[f]++;
			m /= f;
		}
		f++;
	}
	if (m != 1) factors[m]++;

	ll ans = 1;
	for (PLL a : factors) {
		ans *= ncr(a.second + n - 1, a.second) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

signed main() {
	ll t = 1;
	REP(i,0,t) solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (f(x,y/2)*((x*f(x,y/2))%mod))%mod;
}
int64_t comb(int64_t x,int64_t y){
int64_t ans=1;
  for(int64_t i=y;1<=i;i--){
  ans=(f(i,mod-2)*((ans*(x-y+i))%mod))%mod;
  }return ans;

}
int main(){
int64_t N,M;
  cin>>N>>M;
  int64_t m=M;
  vector<int64_t>A={};
  for(int64_t i=2;i*i<=m;i++){
  if(M%i==0){
    int64_t a=0;
    while(M%i==0){
    M/=i; a++;
    }A.push_back(a);

  }
  }if(M!=1)
    A.push_back(1);
  int L=A.size();
  int64_t ans=1;
  for(int i=0;i<L;i++){
    int64_t a=A.at(i);
    ans=(ans*comb(N-1+a,a))%mod;
  }cout<<ans<<endl;
     return 0;
}


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

int main() {
  int nMember, nNeedMember;
  while(cin >> nMember >> nNeedMember, nMember | nNeedMember) {
    vector<int> dates(100, 0); //one base
    for(int i = 0; i < nMember; ++i) {
      int ndate;
      cin >> ndate;
      for(int j = 0; j < ndate; ++j) {
        int date;
        cin >> date;
        ++dates[date];
      }
    }
    auto max_itr = max_element(dates.begin(), dates.end());
    cout << ((*max_itr >= nNeedMember) ? distance(dates.begin(), max_itr) : 0) << endl;
  }
  return 0;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
char map[15][15],moji[15];
void func(int ,int);
int main(void){
	int i,j;
	while(1){
		for(i=0;i<12;i++){
			if(scanf("%s",map[i])==EOF){
				return 0;
			}
		}
		/*for(i=0;i<=12;i++){
			printf("%s",map[i]);
		}
		printf("\n");*/
		int cnt=0;
		for(i=0;i<12;i++){
			for(j=0;j<12;j++){
				if(map[i][j]=='1'){
					map[i][j]=0;
					func(i,j);
					cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}
}
void func(int y,int x){
	int i,j;
	int xx,yy;
	int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
	for(i=0;i<4;i++){
		xx=x+dx[i];
		yy=y+dy[i];
		if(map[yy][xx]=='1' && xx<=12 && xx>=0 && yy<=12 && yy>=0){
			map[yy][xx]=0;
			func(yy,xx);
		}
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;

int main(void){
  int N,Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> ac(S.size(),0);
  int cnt = 0;
  for(int i =1; i <= S.size(); i++){
    if(S[i-1] == 'A' && S[i] == 'C'){
      cnt++;
    }
    ac[i] = cnt;
  }
  for(int i = 0; i < Q; i++){
    int l, r;
    cin >> l >> r;
    cout << ac[r-1] - ac[l-1] << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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 long long INF = 1LL << 60;
const int inf = 1001001001;

int main(){

    ll n, q;
    string s;
    cin >> n >> q >> s;
    vector<ll> dp(n, 0);
    for(ll i = 0; i < n-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            dp[i+1] = (dp[i] + 1);
        }
        else{
            dp[i+1] = dp[i];
        }
    }

    while(q){
        ll l,r;
        cin >> l >> r;
        cout << dp[r-1] - dp[l-1] << endl;
        q--;
    }

}


#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	string S;
	cin >> S;
	string F = "FESTIVAL";
	rep(i, F.size()) S.pop_back();

	Cout(S);
}

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char n[10];
	cin>>n;
	for(int i=0;i<strlen(n);i++)
	{
		if(n[i]=='A'&&n[i+1]=='C')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

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

	string s;
	cin >> s;
	int len = s.size();
	if(len < 26){
		int vis[26] = {};
		for(int i = 0 ; i < len ; ++i)
			vis[s[i]-'a']++;
		for(int i = 0 ; i < 26 ; ++i)
			if(!vis[i])
				return cout << s << char(i+'a') << "\n" , 0;
	}
	else{
		string temp = "";
		for(int i = 25 ; i >= 0 ; --i)
			temp += char(i + 'a');
		if(s == temp)
			cout << "-1\n";
		else{
			set < char > st;
			for(int i = 25 ; i >= 0 ; --i){
				st.insert(s[i]);
				if(s[i-1] < s[i]){ // abc
					char add = *st.upper_bound(s[i-1]);
					cout << s.substr(0 , i-1) << add << "\n";
					break;
				}
			}
		}
	}

    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int Max_N=1010;

int A[Max_N][Max_N];

int main(){
	int N;
	cin >> N;
	rep(i,N){
		rep(j,N-1){
			int a;
			cin >> a;
			a--;
			A[i][j]=a;
		}
	}
	vector<int> op(N);
	int ans=0, sum=N;
	queue<int> q1, q2;
	rep(a,N){
		int n=A[a][0], m=op[n];
		if(n<a) continue;
		if(A[n][m]==a) q1.push(a);
	}
	while(sum){
		ans++;
		if(q1.empty()){
			cout << -1 << endl;
			return 0;
		}
		while(!q1.empty()){
			int a=q1.front(); q1.pop();
			int n=A[a][op[a]], m=op[n];
			q2.push(a), q2.push(n);
			op[a]++; op[n]++;
			if(op[a]==N-1) op[a]=-1, sum--;
			if(op[n]==N-1) op[n]=-1, sum--;
		}
		vector<bool> pushed(N);
		while(!q2.empty()){
			int a=q2.front(); q2.pop();
			if(op[a]==-1) continue;
			int n=A[a][op[a]], m=op[n];
			if(pushed[n]) continue;
			if(A[n][m]==a) q1.push(a), pushed[a]=true;
		}
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    ll keta = 0;
    ll sum = 0;
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        sum += a * b;
        keta += b;
    }
    ll total = (sum - 1) / 9;

    ll ans = keta - 1 + total;

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int fact(int n){
    if(n == 1) return 1;
    else return n * fact(n-1);
}

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> array(n);
    for(int i=0;i<n;i++) cin >> array.at(i).first >> array.at(i).second;
    sort(array.begin(),array.end());
    double sum = 0;
    do{
        for(int i=0;i<n-1;i++){
            int d2 = (array.at(i+1).first - array.at(i).first) * (array.at(i+1).first - array.at(i).first) +
                    (array.at(i+1).second - array.at(i).second) * (array.at(i+1).second - array.at(i).second);
            double d = sqrt((double)d2);
            sum += d;
        }
    } while(next_permutation(array.begin(),array.end()));

    int kaijou = fact(n);
    double ave = sum / (double)kaijou;
    printf("%.10lf \n",ave);
}


#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

void call(int n){
  for(int i=1;i<=n;i++){
    stringstream ss;
    ss<<i;
    char c[8];
    ss>>c;
    if(i%3==0||strstr(c,"3"))
      cout<<" "<<i;
  }
  cout<<endl;
}

int main(){ _;
  int n;cin>>n;
  call(n);
}

#include <iostream>

using namespace std;

void call(int num) {

	for (int i = 1; i <= num; i++) {

		int x = i;

		//3????????°?????¨???
		if (x % 3 == 0) {
			cout << " " << i;
		}
		//3???????????°?????¨???
		else {
			do {

				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}

				x/= 10;

			} while (x);

		}
	}

	cout << endl;

}

int main(){

	int num;

	cin >> num;

	call(num);

	return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD=1e9+7;

#define MAX 1000001
long fac[MAX], finv[MAX], inv[MAX];

void fact() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++i){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long comb(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ios::sync_with_stdio(false);
    fact();
    ll N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    vector<vector<ll>> g(1001, vector<ll>(1001, -1));
    //G(i,a)はi人のグル×aの作り方
    function<ll(ll,ll)> G = [&](ll i,ll a){
        if(a<=1)return 1LL;
        else if(g[i][a]!=-1)return g[i][a];
        else return g[i][a]=(((G(i,a-1)*comb(i*a,i))%MOD)*modinv(a,MOD))%MOD;
    };
    vector<vector<ll>> dp(B+1, vector<ll>(N+1, -1));
    //F(a,x)はa人以上B人以下のグループのみを使ってx人を分ける場合の数
    function<ll(ll,ll)> F = [&](ll a, ll x){
        if(x==0)return 1LL;
        else if(dp[a][x]!=-1)return dp[a][x];
        else if(a==B){
            if(x%B==0&&C<=(x/B)&&(x/B)<=D)return dp[B][x]=G(B,x/B);
            else return dp[B][x]=0;
        }
        else{
        //Fa==0
        ll ret=F(a+1,x);
        //FaがCからD
        for(ll i=C;i<=D&&x-i*a>=0;++i){
            ret+=(((F(a+1,x-i*a)*G(a,i))%MOD)*comb(x,i*a))%MOD;
            ret%=MOD;
        }
        return dp[a][x]=ret;}
    };
    cout<<F(A,N)<<endl;

    return 0;
}

#include <iostream>
#include <algorithm>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;

int dp[MAX_N+1][MAX_N+1];
int p[MAX_N+1];

int main(void) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        dp[i][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        cin >> p[i-1] >> p[i];
    }

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n-l+1; i++) {
            int j = i+l-1;
            dp[i][j] = INF;
            for (int k = i; k <= j-1; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout << dp[1][n] << endl;

    return 0;
}


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

signed main(){

  string s,t;
  cin>>s;
  t = s;
  vector<int> alp(26);
  for(auto c:s)alp[c-'a']++;

  string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzz";
  auto chmin = [](auto& a,auto b){if(a>b)a=b;};
  while(1){
    for(int i=0;i<26;++i)if(alp[i]==0){
      string tmp = s;
      tmp += ('a'+i);
      if(t<tmp){
        chmin(ans,tmp);
      }
    }
    if(s.empty())break;
    alp[s.back()-'a']--;
    s.pop_back();
  }
  cout<<(ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzz"?"-1":ans)<<endl;

}

#include <bits/stdc++.h>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  if (n < 26) {
    map<char, bool> mp;
    for (auto&& c : s) {
      mp[c] = true;
    }
    for (char c = 'a'; c <= 'z'; c++) {
      if (!mp.count(c)) {
        s += c;
        break;
      }
    }
    cout << s << '\n';
  } else {
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
      cout << -1 << '\n';
    } else {
      string ans;
      for (int i = n - 1; i > 0; i--) {
        if (s[i - 1] < s[i]) {
          ans = s.substr(0, i);
          break;
        }
      }
      map<char, bool> mp;
      for (auto&& c : ans) {
        mp[c] = true;
      }
      debug(ans);
      for (char c = ans.back() + 1; c <= 'z'; c++) {
        if (!mp.count(c)) {
          ans.pop_back();
          ans += c;
          break;
        }
      }
      cout << ans << '\n';
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int n,k;
  while(cin >> n >> k, n && k) {

    long long INF = 1e10;
    vector<vector<long long>> dist(n, vector<long long>(n, INF));
    for(int i = 0;i < n;i++) dist[i][i] = 0;

    for(int q = 0;q < k;q++) {
      int Q;
      cin >> Q;
      if(Q == 0) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(dist[a][b] < INF) {
          cout << dist[a][b] << endl;
        }
        else {
          cout << -1 << endl;
        }
      }
      else {
        long long c,d,e;
        cin >> c >> d >> e;
        c--;
        d--;
        dist[c][d] = min(dist[c][d], e);
        dist[d][c] = min(dist[d][c], e);

        for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
          dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][d] + dist[d][j]);
        }

        for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
          dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][c] + dist[c][j]);
        }
      }
    }
  }
}

#include <cstdio>
#include <algorithm>
using namespace std;
#define INF (1<<27)
int cost[100][100];
int main() {
	int n,k;
	while(scanf("%d %d",&n,&k),n) {
		fill((int*)cost,(int*)(cost+100),INF);
		for(int i=0;i<k;i++) {
			int a,b,c;
			scanf("%d",&a);
			if(a==0) {
				scanf("%d %d",&a,&b);
				if(cost[a-1][b-1]==INF)
					printf("-1\n");
				else
					printf("%d\n",cost[a-1][b-1]);
			}else {
				scanf("%d %d %d",&a,&b,&c);
				if(cost[a-1][b-1]>c) {
					cost[a-1][b-1]=cost[b-1][a-1]=c;
					for(int k=0;k<n;k++) {
						for(int i=0;i<n;i++) {
							for(int j=0;j<n;j++) {
								cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
							}
						}
					}
				}
			}
		}
	}
}


#include <stdio.h>

struct Dice
{
	int n[6];
};

Dice InputDice()
{
	Dice d;
	for(int i = 0; i < 6; ++i)
	{
		scanf("%d", &d.n[i]);
	}

	return d;
}

Dice SetDice(int a, int b, int c, int d, int e, int f)
{
	Dice dice;
	dice.n[0] = a;
	dice.n[1] = b;
	dice.n[2] = c;
	dice.n[3] = d;
	dice.n[4] = e;
	dice.n[5] = f;

	return dice;
}

Dice Roll(Dice dice, char dir)
{
	switch(dir)
	{
		case 'N':
			return SetDice(dice.n[1], dice.n[5], dice.n[2], dice.n[3], dice.n[0], dice.n[4]);
		case 'S':
			return SetDice(dice.n[4], dice.n[0], dice.n[2], dice.n[3], dice.n[5], dice.n[1]);
		case 'W':
			return SetDice(dice.n[2], dice.n[1], dice.n[5], dice.n[0], dice.n[4], dice.n[3]);
		case 'E':
			return SetDice(dice.n[3], dice.n[1], dice.n[0], dice.n[5], dice.n[4], dice.n[2]);
	}
}

bool IsSame(Dice a, Dice b)
{
	for(int i = 0; i < 6; ++i)
	{
		if(a.n[i] != b.n[i])
		{
			return false;
		}
	}

	return true;
}

bool IsEqual(Dice a, Dice b)
{
	char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";

	for(int i = 0; i < 24; ++i)
	{
		b = Roll(b, cmd[i]);
		if(IsSame(a, b))
		{
			return true;
		}
	}

	return false;
}

int FindSide(Dice a, int top, int front)
{
	char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";

	for(int i = 0; i < 24; ++i)
	{
		a = Roll(a, cmd[i]);
		if(a.n[0] == top && a.n[1] == front)
		{
			return a.n[2];
		}
	}

	return -1;
}

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

	Dice D[128];
	bool ans = true;
	for(int i = 0; i < N; ++i)
	{
		D[i] = InputDice();

		for(int j = 0; j < i && ans; ++j)
		{
			if(IsEqual(D[i], D[j]))
			{
				ans = false;
			}
		}
	}

	if(ans)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

    return 0;
}

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
LL a[2000222],dp[4],n,sum[2000222];
#define P(x) (x%3+3)%3
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
		sum[i]=sum[i-1];
		if(i&1)sum[i]+=a[i];
	}
	dp[1]=0;dp[2]=max(a[1],a[2]);
	for(int i=3;i<=n;++i)
	{
		LL now,pre1,pre2;
		now=P(i);pre1=P(i-1);pre2=P(i-2);
		dp[now]=0;
		if(i&1)
		{
			dp[now]=max(dp[pre1],dp[pre2]+a[i]);
		}
		else
		{
			dp[now]=max(sum[i],dp[pre2]+a[i]);
		}
	}
	printf("%lld\n",dp[P(n)]);
}


#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios:: sync_with_stdio(false);
  cin.tie();
  int x;
  cin >> x;
  int mi = x;
  int mx = x;
  for (int i = 0; i < 4; i++) {
    cin >> x;
    mi = min(mi, x);
    mx = max(mx, x);
  }
  int k;
  cin >> k;
  cout << ((mx - mi) <= k ? "Yay!" : ":(");
  return 0;
}

#include<iostream>
using namespace std;

int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  cout << (((e - a) > k) ? ":(" : "Yay!") << endl;
  return 0;
}


#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"

#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

using namespace std;

const ll INF = 1e9 + 10;
const ll INF2 = 3e18 + 10;
const int MOD = 1e9 + 7;
const ld EPS = 1e-4;

const int LOGN = 19;
const int MAXN = 305;

inline void add_self(int &a, int b) {
	a = (a + b) % MOD;
}

ll dp[1 << 16];
ll t[1 << 16];
ll p[16][16];
int a[16];

int main() {
	FAST;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> p[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) dp[i] = -INF2;

	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = 0; i < n; i++) {
			if ((mask >> i) & 1) {
				for (int j = i + 1; j < n; j++) {
					if ((mask >> j) & 1) {
						t[mask] += p[i][j];
					}
				}
			}
		}
	}

	dp[0] = 0;
	for (int mask = 0; mask < (1 << n); mask++) {
		int b = 0;
		for (int i = 0; i < n; i++) {
			if (!((mask >> i) & 1)) {a[b] = i; b++;}
		}
		for (int m = 1; m < (1 << b); m++) {
			int nmask = 0;
			for (int i = 0; i < b; i++) {
				if ((m >> i) & 1) {nmask += 1 << a[i];}
			}
			dp[nmask | mask] = max(dp[nmask | mask], dp[mask] + t[nmask]);
		}
	}
	cout << dp[(1 << n) - 1];

}

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

void chmax(ll &a, ll b){ if(a < b) a = b; return; }
ll n, a[16][16], dp[1<<16];

int main(){
    cin >> n;
    rep(i,n) rep(j,n) cin >> a[i][j];
    loop(i,1,1<<n){
        rep(j,n) rep(k,j) if(i>>j & i>>k & 1) dp[i] += a[j][k];
        for(int j = i; j > 0; j = (j-1)&i) chmax(dp[i], dp[j]+dp[i^j]);
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}


#include <iostream>
#include <vector>
int main() {
    int N;
    std::cin >> N;
    std::vector<int> CuSumWest(N,0),CuSumEast(N,0);
    std::vector<int> CDNum(N,0);//i番目がリーダーだったときに向きを変えなければならない人の数 = CDNum[i]

    for(int i=0;i<N;i++){
        if(i != 0) {
            CuSumEast[i] = CuSumEast[i - 1];
            CuSumWest[i] = CuSumWest[i - 1];
        }
        char input;
        std::cin >> input;
        if(input == 'E'){
            CuSumEast[i]++;
        }else{
            CuSumWest[i]++;
        }
    }
    for(int i=0;i<N;i++) {
        CDNum[i] = CuSumWest[i] + (CuSumEast[N-1] - CuSumEast[i]);
        if((CuSumWest[i] == 1 && i==0) || (CuSumWest[i] - CuSumWest[i-1] == 1) )
            CDNum[i] -- ;
    }

    int min = CDNum[0];

    for(int i=0;i<N;i++){
        if(min > CDNum[i]){
            min = CDNum[i];
        }
    }

    std::cout << min;

    return 0;

}

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;
void solve(void)
{
    int n;
    cin >> n;
    vector<int> a(n + 2);
    rep(i, n) cin >> a[i + 1];
    a[0] = 0, a[n + 1] = 0;
    int res = 0;
    rep(i, n + 1) res += abs(a[i] - a[i + 1]);
    rep(i, n)
    {
        int x = abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i + 2]);
        int y = abs(a[i] - a[i + 2]);
        cout << res - x + y << endl;
    }
}
int main(void)
{
    solve();
}


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

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

const int N = 2010;

int n, m, a[N][N];
char s[N][N];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", s[i]);

  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < m - 1; ++j) {
      int cnt = 0;
      cnt += s[i][j] == '#';
      cnt += s[i][j + 1] == '#';
      cnt += s[i + 1][j] == '#';
      cnt += s[i + 1][j + 1] == '#';
      a[i][j] = ~cnt & 1;
    }
  }

  int ans = max(n, m);
  for(int i = 0; i < n - 1; ++i) {
    for(int j = 0; j < m - 1; ++j)
      if(a[i][j]) a[i][j] += a[i - 1][j];

    int mx = 0;
    stack<int> st;
    for(int j = 0; j < m; ++j) {
      while(st.size() && a[i][st.top()] >= a[i][j]) {
        int t = st.top();
        st.pop();
        mx = max(mx, (a[i][t] + 1) * (st.size() ? j - st.top() : j + 1));
      }
      st.push(j);
    }

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

  return 0;
}

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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

typedef long long LL;
const int N=200010;
int n,q,a,b,X[N];
int delta[N];
LL sumd[N],f[N];

struct SegmentTree
{
    LL mnv[N<<2];int leaf;
    void build()
    {
        for(leaf=1;leaf<=(n+2);leaf<<=1);
        for(int i=1;i<=leaf+n;i++) mnv[i]=INT64_MAX/3;
    }
    void modify(int k,LL x)
    {
        mnv[leaf+k]=min(mnv[leaf+k],x);
        for(int i=(leaf+k)>>1;i;i>>=1)
            mnv[i]=min(mnv[i<<1],mnv[i<<1|1]);
    }
    LL qmin(int l,int r)
    {
        LL res=INT64_MAX/3;
        for(l=leaf+l-1,r=leaf+r+1;l^r^1;l>>=1,r>>=1)
        {
            if(~l&1) res=min(res,mnv[l^1]);
            if(r&1) res=min(res,mnv[r^1]);
        }
        return res;
    }
}t1,t2;

LL solve(int a,int b)
{
    X[0]=a;
    for(int i=1;i<=q;i++)
    {
        delta[i]=abs(X[i]-X[i-1]);
        sumd[i]=sumd[i-1]+delta[i];
    }
    f[1]=abs(b-X[1]);
    t1.build();t2.build();
    t1.modify(X[0],f[1]-sumd[1]-X[0]);
    t2.modify(X[0],f[1]-sumd[1]+X[0]);
    for(int i=2;i<=q;i++)
    {
        f[i]=t1.qmin(1,X[i])+X[i]+sumd[i-1];
        f[i]=min(f[i],t2.qmin(X[i],n)-X[i]+sumd[i-1]);
        t1.modify(X[i-1],f[i]-sumd[i]-X[i-1]);
        t2.modify(X[i-1],f[i]-sumd[i]+X[i-1]);
    }
    LL ans=INT64_MAX/3;
    for(int i=0;i<=q;i++) ans=min(ans,f[i]+sumd[q]-sumd[i]);
    return ans;
}

int main()
{
    n=read();q=read();a=read();b=read();
    for(int i=1;i<=q;i++) X[i]=read();
    LL ans=min(solve(a,b),solve(b,a));
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
    string N;
    cin >> N;
    bool flag = false;
    for (int i = 0; i < 3; i++)
    {
        if (N[i] == '7')
        {
            flag = true;
            break;
        }
    }
    if (flag)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;

const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);

int n , m;

void solve(int testCase){

    double d , t , s;
    scanf("%lf %lf %lf" , &d , &t , &s);

    if(s * t >= d) {
            printf("Yes\n");
    }
    else {
            printf("No\n");
    }
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

int main()
{
	int n;

	cin >> n;
	cin.get();

	for( int i = 0; i < n; ++i ){
		string s;
		getline( cin, s );
		int index = 0;
		while( ( index = s.find( "Hoshino", index ) ) != string::npos ){
			s.replace( index, 7, "Hoshina" );
			index += 7;
		}
		cout << s << endl;
	}

	return 0;
}

/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

int main(){
    Shazam;
    int n; cin>>n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin>>a[i];
    int res = 0;
    vector<int> ans(n+1);
    for(int i = n; i>0; i--){
        int curr = 0;
        for(int j = 2*i; j <=n; j+=i){
            curr+=ans[j];
        }
        if ((curr & 1) != (a[i] & 1)){
            ans[i] = 1;
            res++;
        }
    }
    cout<<res<<endl;
    for(int i = 1; i <= n; i++){
        if(ans[i])
            cout<<i<<" ";
    }
    cout<<endl;/*  */

    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,k,card[10],digit[10];
bool use[10];
set<ll> S;

void rec(ll num,int depth)
{
	if(depth==0)
	{
		S.insert(num); return;
	}
	rep(i,n)if(!use[i])
	{
		use[i]=1;
		rec(num*digit[i]+card[i],depth-1);
		use[i]=0;
	}
}

int main()
{
	while(cin>>n>>k,n)
	{
		rep(i,n)
		{
			cin>>card[i];
			digit[i]=card[i]>9?100:10;
		}
		fill_n(use,n,0); S.clear();
		rec(0,k);
		cout<<S.size()<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,ni,na,i,j,k,ans,idx;
  while(cin>>m>>ni>>na,m||ni||na){
    int p[m];
    for(i=0;i<m;i++) cin>>p[i];
    sort(p,p+m);
    ans=0;
    idx=ni;
    for(i=ni;i<=na;i++){
      //cout<<p[m-i]-p[m-i-1]<<endl;
      if(p[m-i]-p[m-i-1]>=ans){
	ans=p[m-i]-p[m-i-1];
	idx=i;
      }
    }
    cout << idx << endl;
  }
  return 0;
}


#include<cstdio>
#include<map>
using namespace std;
int par1[200005],par2[200005];
int rank1[200005],rank2[200005];
typedef pair<int,int> P;
map<P,int>m;
int find(int *par,int x)
{
    if(x==par[x])
        return x;
    else
        return par[x]=find(par,par[x]);
}
void unite(int *par,int *rank,int x,int y)
{
    x=find(par,x);
    y=find(par,y);
    if(x==y)
        return ;
    else
    {
        if(rank[x]>rank[y])
            par[y]=x;
        else
        {
            par[x]=y;
            if(rank[x]==rank[y])
                rank[y]++;
        }
    }
}
int main()
{
    int n,k,l;
    scanf("%d%d%d",&n,&k,&l);
    int p,q;
    for(int i=1;i<=n;i++)
    {
        par1[i]=par2[i]=i;
        rank1[i]=rank2[i]=0;
    }
    for(int i=0;i<k;i++)
    {
        scanf("%d%d",&p,&q);
        unite(par1,rank1,p,q);
    }
    for(int i=0;i<l;i++)
    {
        scanf("%d%d",&p,&q);
        unite(par2,rank2,p,q);
    }
    for(int i=1;i<=n;i++)
    {
        find(par1,i);
        find(par2,i);
    }
    for(int i=1;i<=n;i++)
    {
        m[P(par1[i],par2[i])]++;
    }
    for(int i=1;i<=n;i++)
    {
        printf("%d ",m[P(par1[i],par2[i])]);
    }
    return 0;
}

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};
//UnionFind Uni(N);
//Uni.connect;

struct Edge
{
  int from, to, cost;

  // コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
  int n;  // 頂点数
  vector<Edge> es;  // 辺集合

  // クラスカル法で無向最小全域木のコストの和を計算する
  // グラフが非連結のときは最小全域森のコストの和となる
  int kruskal() {
    // コストが小さい順にソート
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;

    rep(ei, es.size()) {
      Edge& e = es[ei];
      if (!uf.same(e.from, e.to)) {
        // 辺を追加しても閉路ができないなら、その辺を採用する
        min_cost += e.cost;
        uf.connect(e.from, e.to);
      }
    }

    return min_cost;
  }
};

// 標準入力からグラフを読み込む
Graph input_graph() {
  Graph g;
  int m;
  cin >> g.n >> m;
  rep(i, m) {
    Edge e;
    cin >> e.from >> e.to >> e.cost;
    g.es.push_back(e);
  }
  return g;
}

int main(){
  int n;
  cin >> n;
  // Graph g = input_graph();
  vector<P> xp;
  vector<P> yp;
  rep(i,n){
    int x,y;
    cin >> x >> y;
    xp.push_back(make_pair(x,i));
    yp.push_back(make_pair(y,i));
  }
  sort(xp.begin(),xp.end());
  sort(yp.begin(),yp.end());
	Graph g;
	g.n=n;
	rep(i,n-1){
		Edge e;
		e.from = xp[i].second;
		e.to = xp[i+1].second;
		e.cost = xp[i+1].first - xp[i].first;
		g.es.push_back(e);
	}
	rep(i,n-1){
		Edge e;
		e.from = yp[i].second;
		e.to = yp[i+1].second;
		e.cost = yp[i+1].first - yp[i].first;
		g.es.push_back(e);
	}
  cout << g.kruskal() << endl;
  return 0;
}


/*    特徴    */

/*    教訓    */

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x) == 1) return x; }
long long il() { long long x; if (scanf("%lld", &x) == 1) return x; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //

// - library ------------- //

 ll mo = 998244353;

// 0^0 は 1 を返すので注意
ll modpow(ll x, ll n){
  if ( n == 0 ) return 1;
  else{
    return modpow(x * x % mo, n / 2) * (n % 2 ? x : 1) % mo;
  }
} //llpowがあるからいらない？？
ll modfact(ll n){return n < 2 ? 1 : modfact(n - 1) * n % mo;}
ll modcomb(ll n, ll r){return modfact(n) * modpow(modfact(r), mo - 2) % mo * modpow(modfact(n - r), mo - 2) % mo;}

// --------- library end - //

// - main() -------------- //

int main(){

  ll n;
  cin >> n;

  ll ans = 1;

  vector<ll> buckets(n, 0);
  ll i1 = il();
  if (i1 == 0) buckets[0] = 1;
  else ans = 0;
  REP(i, 1,  n){
    ll c = il();
    if (c == 0) ans = 0;
    buckets[c]++;
  }

  ll befcnt = 1;
  REP(i, 1, n){
    ll cnt = buckets[i];
    ans = ans * modpow(befcnt, cnt) % mo;
    befcnt = cnt;
  }

  cout << ans << endl;

// ---------- main() end - //
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

int main() {
    int N;
    cin>>N;
    int zero;
    cin>>zero;
    if(zero!=0){cout<<0<<endl;return 0;}
    vector<int> D(N-1);
    rep(i,N-1){cin>>D.at(i);}
    sort(D.begin(),D.end());
    int num=1,before=1,now=0;
    ll ans=1;
    rep(i,N-1){
        if(D.at(i)==num){
            now++;
            ans*=before;
            ans%=MOD2;
        }
        else{
            num++;
            before=now;
            ans*=before;
            ans%=MOD2;
            now=0;
            if(D.at(i)==num){
                now++;
            }
            else{cout<<0<<endl;return 0;}
        }
        //cout<<ans<<" "<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int arr[4]={0,300000,200000,100000};
	int x,y;
	cin >> x >> y;
	int ans=0;
	if(x<=3) ans+=arr[x];
	if(y<=3) ans+=arr[y];
	if(x==1&&y==1) ans+=400000;
	cout << ans << endl;
}

#include<iostream>
#include<ctype.h>
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
string s,ss;
queue<int> q;
bool vis[200];
int main(){
	int l;cin>>l;int er=l,ans=0;
	cin>>s>>ss;
	if(s==ss)goto portal0;
	if(s[0]!=ss[0])goto portalfail;
	for(int i=0;i<l;++i)vis[s[i]-'a']=1;
	for(int i=0;i<l;++i)if(!vis[ss[i]-'a'])goto portalfail;

	for(int i=er-1;i>=0;--i){
		if(i && ss[i-1]==ss[i])goto go;
		er=min(er,i);
		while(er>=0 && s[er]!=ss[i])--er;
		if(er<0)goto portalfail;
		while(!q.empty() && q.front()>=i+q.size())q.pop();
		q.push(er);
		if(i!=er)ans=max(ans,int(q.size()));
		go:
			;
	}
	printf("%d",ans+1);
	return 0;
	portal0:
		printf("0\n");
	return 0;
	portalfail:
		printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

struct MaxFlowCalculator {
	int max_flow(int s, int t, const vector<vector<pair<int, int>>>& g) {
		struct edge_ { int to, cap, rev; };
		vector<bool> used(g.size(), false);
		vector<vector<edge_>> G(g.size());
		for (int i = 0; i < g.size(); i++) for (int j = 0; j < g[i].size(); j++)
		{
			int from = i, to = g[i][j].second;
			int cap = g[i][j].first;
			G[from].push_back({ to, cap, (int)G[to].size() });
			G[to].push_back({ from, 0, (int)G[from].size() - 1 });
		}
		auto dfs = [&](auto&& f, int v, int t, int fl)->int {
			if (v == t) return fl;
			used[v] = true;
			rep(i, G[v].size()) {
				edge_& e = G[v][i];
					if (!used[e.to] && e.cap > 0) {
					int d = f(f, e.to, t, min(fl, e.cap));
					if (d > 0) {
						e.cap -= d;
						G[e.to][e.rev].cap += d;
						return d;
					}
				}
			}
			return 0;
		};
		int flow = 0;
		while (1) {
			used.assign(used.size(), false);
			int f = dfs(dfs, s, t, INT_MAX);
			if (f == 0) return flow;
			flow += f;
		}
	}
};

int main() {
	ll p, r, q;
	cin >> p >> r >> q;
	ll a1 = p + r;
	ll a2 = r + q;
	ll a3 = p + q;
	cout << min(a1, min(a2, a3)) << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c;
  cin>>a>>b>>c;
  vector<int>v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  sort(v.begin(),v.end());
  cout<<v[0]+v[1];

}


#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	int sum = 0;
	vector<int>as(4), bs(2);
	for (int i = 0; i < 4; ++i) {
		cin >> as[i];
		sum += as[i];
	}
	cin >> bs[0] >> bs[1];
	sum += bs[0] + bs[1];
	sum -= *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end());
	cout << sum << endl;

	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstdio>
int main()
{
    int a[10];
    int m;
    for(int i=0;i<=5;i++){
        std::cin>>a[i];
    }
    std::sort(a,a+4);
    m=std::max(a[4],a[5]);
    std:: cout<<a[3]+a[2]+a[1]+m<<std::endl;
    return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <cstdlib>

using namespace std;

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

const ll mod = 1000000007;

template <class T>
struct prop_segtree {
  int n;
  vector<T> data;
  vector<bool> propFlag;

  prop_segtree(const int s) {
    init(s);
  }

  prop_segtree(const int s, const T u) {
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = u;
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = 0;
    }
  }

  prop_segtree(const vector<T> &v) {
    int s = v.size();
    init(s);
    for (int i = 0; i < s; i++) {
      data[i+n-1] = v[i];
    }
    for (int i = n-2; i >= 0; i--) {
      data[i] = 0;
    }
  }

  void init(const int s) {
    n = 1;
    while (n < s) n <<= 1;
    data = vector<T>(2*n-1);
    propFlag = vector<bool>(2*n-1);
  }

  void propagate(int p, int a, int b) {
    if (propFlag[p]) {
      if (b - a > 1) {
        data[p*2+1] = data[p];
        data[p*2+2] = data[p];
        propFlag[p*2+1] = true;
        propFlag[p*2+2] = true;
        data[p] = 0;
      }
      propFlag[p] = false;
    }
  }

  void update(int l, int r, T v, int p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // propagate value
    propagate(p, a, b);

    if (r <= a || b <= l) return; // out of range
    if (l <= a && b <= r) { // fully covered
      data[p] = v;
      propFlag[p] = true;
      propagate(p, a, b);
    }
    else {
      update(l, r, v, p*2+1, a, (a + b) / 2); // left
      update(l, r, v, p*2+2, (a + b) / 2, b); // right
    }
    return;
  }

  T query(int x, T p = 0, int a = 0, int b = -1) {
    if (b < 0) b = n; // init

    // propagate value
    propagate(p, a, b);

    if (b - a == 1) return data[p];// reached to bottom

    if (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // left
    else return query(x, p*2+2, (a + b) / 2, b); // right
  }
};

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

  int n, q;
  cin >> n >> q;
  vector<vector<int> > query(q, vector<int>(4));
  for (int i = 0; i < q; i++) {
    cin >> query[i][0] >> query[i][1];
    if (query[i][0] == 0) cin  >> query[i][2] >> query[i][3];
  }

  prop_segtree<int> pst(n, 0x7fffffff);
  vector<ll> ans;
  for (int i = 0; i < q; i++) {
    if (query[i][0] == 0) { // update
      pst.update(query[i][1], query[i][2]+1, query[i][3]);
    }
    else { // get
      ans.push_back(pst.query(query[i][1]));
    }
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}

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

template<typename OperatorMonoid>
struct SegmentTree {
    using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
    const H h;
    const OperatorMonoid OM0;
    int sz, height;
    vector<OperatorMonoid> lazy;
    SegmentTree(int n, const H h, const OperatorMonoid &OM0)
        : h(h), OM0(OM0), sz(1), height(0)
    {
        while (sz < n) sz <<= 1, height++;
        lazy.assign(sz * 2, OM0);
    }
    inline void propagate(int k) {
        if (lazy[k] == OM0) return ;
        lazy[k << 1 | 0] = h(lazy[k << 1 | 0], lazy[k]);
        lazy[k << 1 | 1] = h(lazy[k << 1 | 1], lazy[k]);
        lazy[k] = OM0;
    }
    inline void thrust(int k) {
        for (int i = height; i > 0; i--) propagate(k >> i);
    }
    void update(int a, int b, const OperatorMonoid &x) {
        thrust(a += sz);
        thrust(b += sz - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lazy[l] = h(lazy[l], x), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r], x);
        }
    }
    void set(int k, const OperatorMonoid &x) { thrust(k += sz); lazy[k] = x; }
    OperatorMonoid get(int k) { thrust(k += sz); return lazy[k]; }
    OperatorMonoid operator[](const int &k) { return get(k); }
};

const int INF = numeric_limits<int>::max();
int main() {
    int n, q; cin >> n >> q;
    SegmentTree<int> seg(n, [](int a, int b) { return b; }, INF);
    while (q--) {
        int com; cin >> com;
        if (com == 0) {
            int s, t, x; cin >> s >> t >> x; t++;
            seg.update(s, t, x);
        } else {
            int i; cin >> i;
            cout << seg[i] << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int A,B; cin >> A >> B;
    int ans = max({A + B,A - B,A*B});
    cout << ans << '\n';
    return 0;
}

 #include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,sum,sub,mul;
  cin>>a>>b;
  sum=a+b;
  sub=a-b;
  mul=a*b;

  int ans = max(sum,max(sub,mul));

  if(ans==0)
  cout<<0<<endl;
  else
  cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;
int main(void){
   vector<int> w(10);
   vector<int> k(10);
   int sumw=0,sumk=0;

   for(int i=0;i<10;i++)cin>>w[i];
   for(int i=0;i<10;i++)cin>>k[i];

   sort(w.begin(),w.end());
   sort(k.begin(),k.end());

   for(int i=9;i>6;i--) {
       sumw+=w[i];
       sumk+=k[i];
   }

    cout<<sumw<<" "<<sumk<<endl;

    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int a[10], b[10];

int main(){
  REP(i,10) a[i] = getInt();
  REP(i,10) b[i] = getInt();
  sort(a, a+10); sort(b, b+10);
  cout << a[9] + a[8] + a[7] << " " << b[9] + b[8] + b[7] << endl;
  return 0;
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i=2; i<MAX; i++){
		fac[i] = fac[i-1]*i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}

ll com(ll n, ll k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	ll n,x; cin >> n >> x;
	comInit();
	vl a(n); rep(i,n) cin >> a[i];
	sort(rall(a));
	vvl dp(n+1,vl(x+1,0));
	dp[0][x] = 1;
	rep(i,n){
		rep(j,x+1){
			dp[i+1][j%a[i]] += inv[n-i] * dp[i][j];
			dp[i+1][j] += ((n-1-i)*inv[n-i])%mod * dp[i][j];
			dp[i+1][j%a[i]] %= mod;
			dp[i+1][j] %= mod;
		}
	}
	ll ans = 0;
	rep(i,x+1){
		ans += dp[n][i] * fac[n] % mod * i;
		ans %= mod;
	}
	cout << ans << endl;
}

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}
#define N 300
int main(){fastio
    ll bun[N];
    rep(i,1,N-1)bun[i]=bunbo(i);
    ll n,x;cin>>n>>x;
    ll s[n];rep(i,0,n-1)cin>>s[i];
    sort(s,s+n);
    reverse(s,s+n);
    ll dp[x+1][n+1];memset(dp,0,sizeof(dp));
    ll kai=1;rep(i,1,n)kai=mod(kai*i);
    dp[x][0]=kai;
    rep(i,0,n-1){
        rep(j,0,x){
            ll c=mod(dp[j][i]*bun[n-i]);
            if(c==0)continue;
            Add(dp[j][i+1],c*(n-i-1));
            Add(dp[j%s[i]][i+1],c);
        }
    }
    /*
    rep(i,0,x){
        rep(j,0,n){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    ll ans=0;
    rep(i,0,x){
        Add(ans,i*dp[i][n]);
    }
    cout<<ans<<endl;

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int ans =0;
  if(s == "RRR"){ans = 3;}
  if(s == "RRS"){ans = 2;}
  if(s == "RSR"){ans = 1;}
  if(s == "SRR"){ans = 2;}
  if(s == "RSS"){ans = 1;}
  if(s == "SRS"){ans = 1;}
  if(s == "SSR"){ans = 1;}
  if(s == "SSS"){ans = 0;}
  cout << ans << endl;
}

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

main(){
	string s; cin>>s;

	int cnt=0, ans=0;
	for(int i=0; i<s.length(); i++){
		if(s[i]=='R') cnt++;
		else{
			ans = max(ans, cnt);
			cnt=0;
		}
	}
	ans = max(ans,cnt);
	cout<<ans;
}


#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =1000000007;
const ll MAX = 1000001;

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

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

///////////////////////////
ll fac[MAX], finv[MAX], inv[MAX];

void Pinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll P(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[n-k] % MOD;
}

int main() {
	Pinit();

	ll N, X;
	cin >> N >> X;

	vector<ll> S(N + 1);
	repn(i, N) cin >> S[i];

	vector<ll> dp(X + 1,0);
	vector<ll> lb(X + 1);

	sort(++S.begin(), S.end());

	rep(K, X+1) {
		auto itr = upper_bound(++S.begin(), S.end(), K);
		lb[K] = distance(S.begin(), itr) - 1;

		if (lb[K] == 0) { dp[K] = K; }

		else {
			repn(i, lb[K]) {
				ll l = K % S[i];
				ll t = dp[l] * P(lb[K]-1, lb[K]-1-lb[l]) % MOD;
				dp[K] = (dp[K] + t) % MOD;
			}
		}

		//cout << K << lb[K] << dp[K] << endl;
	}

	ll ans = dp[X] * P(N, N-lb[X]) % MOD;

	cout << ans;

	system("PAUSE");
}

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

typedef long long lli;
typedef vector<int> Vi;
typedef vector<lli> Vl;
typedef pair<int, int> Pii;
typedef pair<lli, lli> Pll;

//===

const int MOD = (int)1e9 + 7;

int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> S(N);
	for (int i = 0; i < N; ++i) cin >> S[i];

	sort(S.begin(), S.end());

	Vl dp(X + 1);
	for (int x = 0; x <= X; ++x) dp[x] = x;

	for (int i = 0; i < N; ++i) {
		for (int x = X; x >= 0; --x) {
			dp[x] = (dp[x % S[i]] + i * dp[x]) % MOD;
		}
	}

	cout << dp[X] << endl;
}


#include <stdio.h>

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	char code[n + k + 1];
	scanf("%s", code);
	int temp = 0;
	for (int i = 0; i < n + k + 1; i++){
		if (i != n){
			if (code[i] >= '0' && code[i] <= '9'){
				temp++;
			}
		}
		else if (code[i] == '-'){
			temp++;
		}
	}
	if (temp == n + k + 1){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

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

    vector<string> ans(100, "");
    for(int i = 0; i < 50; i++) {
        rep(j, 100) ans[i] += "#";
    }
    for(int i = 50; i < 100; i++) {
        rep(j, 100) ans[i] += '.';
    }

    a--;
    b--;

    for(int i = 1; i < 50; i += 2){
        if(a == 0) break;
        for(int j = 1; j < 100; j += 2){
            if(a == 0) break;
            ans[i][j] = '.';
            a--;
        }
    }
    for(int i = 51; i < 100; i += 2){
        if(b == 0) break;
        for(int j = 1; j < 100; j += 2){
            if(b == 0) break;
            ans[i][j] = '#';
            b--;
        }
    }
    cout << "100 100" << endl;
    rep(i, 100) cout << ans[i] << endl;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
using namespace std;

#define N 200002

int fdsu[N],sdsu[N];

vector<int> g[N];
bool isSorted[N];
int f(int *dsu,int x) {
  if(dsu[x]==x) {
    return x;
  }
  return dsu[x] = f(dsu,dsu[x]);
}
void merge(int *dsu,int x,int y,int bit=0) {
  x = f(dsu,x),y = f(dsu,y);
  if(x!=y) {
    if(g[x].size()>g[y].size()) {
      swap(x,y);
    }
    dsu[x] = y;
    if(bit) {
      while(!g[x].empty()) {
        g[y].push_back(g[x].back());
        g[x].pop_back();
      }
    }
  }
}
void solve() {
  int n,k,l;scanf("%d %d %d",&n,&k,&l);
  for(int i=n;i;--i) {
    fdsu[i] = i;sdsu[i] = i;
  }
  for(int i=k;i;--i) {
    int x,y;scanf("%d %d ",&x,&y);
    merge(fdsu,x,y);
  }
  for(int i=n;i;--i) {
    g[i].push_back(f(fdsu,i));
  }
  for(int i=l;i;--i) {
    int x,y;scanf("%d %d",&x,&y);
    merge(sdsu,x,y,1);
  }
  for(int i=1;i<=n;++i) {
    int id = f(sdsu,i);
    if(!isSorted[id]) {
      sort(g[id].begin(),g[id].end());
      isSorted[id] = true;
    }
    int x = f(fdsu,i);
    printf("%d ",
    int(lower_bound(g[id].begin(),g[id].end(),x+1) - lower_bound(g[id].begin(),g[id].end(),x))  );
  }
  putchar('\n');
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
vector<vector<int>>adj(N);

bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}

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

signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int l,r;
        int ans1=-inf,ans2=inf;
        while(m--){
            cin>>l>>r;
            ans1=max(l,ans1);
            ans2=min(ans2,r);
        }
        int ans=ans2-ans1+1;
        if(ans>0)
        cout<<ans<<endl;
        else
        {
            cout<<0;
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}

int32_t main()
{

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

 //    int t;
 //     cin >> t;

 //     while(t--){

 // }

ld r;
cin >> r;
r = 2*pi*r;
cout <<fixed;
cout << setprecision(5);
cout << r << endl;

return 0;

	}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string s;

    cin >> k >> s;

    if (s.size()>k) {
        string sub = s.substr(0, k);
        cout << sub << "..." <<endl;
    }
    else{
        cout << s <<endl;
    }

}


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

int main(){
  int sx, sy;
  cin >> sx >> sy;
  int tx, ty;
  cin >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  cout << string(dy, 'U');
  cout << string(dx, 'R');
  cout << string(dy, 'D');
  cout << string(dx, 'L');
  cout << 'L';
  cout << string(dy+1, 'U');
  cout << string(dx+1, 'R');
  cout << "DR";
  cout << string(dy+1, 'D');
  cout << string(dx+1, 'L');
  cout << "U" << endl;
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

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

typedef long long ll;

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

void solve1() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;

    int ud = abs(sy-ty);
    int rl = abs(sx-tx);
    rep(i, ud) {
        cout << 'U';
    }

    rep(i, rl) {
        cout << 'R';
    }

    rep(i, ud)
    {
        cout << 'D';
    }

    rep(i, rl)
    {
        cout << 'L';
    }

    cout << 'L';

    rep(i, ud+1)
    {
        cout << 'U';
    }

    rep(i, rl+1)
    {
        cout << 'R';
    }

    cout << 'D';
    cout << 'R';

    rep(i, ud+1)
    {
        cout << 'D';
    }

    rep(i, rl+1)
    {
        cout << 'L';
    }

    cout << 'U' << endl;;
}

int main()
{
    solve1();
}


#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

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

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int main() {
  ll x,y;
  cin >> x >> y;
    long long res = 1LL<<60;
    //cout << res << endl;
    if (x <= y) res = min(res, y-x);
    if (-x <= y) res = min(res, y+x+1);
    if (x <= -y) res = min(res, -y-x+1);
    if (-x <= -y) res = min(res, -y+x+2);
    cout << res << endl;

}


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

int main(){
  long long N,a,c=1,A[100002]={};A[0]=3;
  cin>>N;
  for(int i=0;i<N;i++){
    scanf("%d",&a);
    c*=(A[a]-A[a+1]++);
    c%=1000000007;
  }
  cout<<c<<endl;
}

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

int main()
{
    const static int64_t mod = 1000000007;
    int N;
    cin >> N;
    vector<int> A_vec(N);
    for (int i = 0; i < N; ++i)
        cin >> A_vec.at(i);
    vector<int> x_vec(N + 1, 0), y_vec(N + 1, 0), z_vec(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        int A = A_vec.at(i);
        x_vec.at(i + 1) = x_vec.at(i);
        y_vec.at(i + 1) = y_vec.at(i);
        z_vec.at(i + 1) = z_vec.at(i);
        if (A == x_vec.at(i))
            ++x_vec.at(i + 1);
        else if (A == y_vec.at(i))
            ++y_vec.at(i + 1);
        else if (A == z_vec.at(i))
            ++z_vec.at(i + 1);
        else {
            cout << 0 << endl;
            return 0;
        }
    }
    int64_t cnt = 1;
    for (int i = 0; i < N; ++i) {
        int64_t tmp = 0;
        int A = A_vec.at(i);
        if (A == x_vec.at(i)) ++tmp;
        if (A == y_vec.at(i)) ++tmp;
        if (A == z_vec.at(i)) ++tmp;
        cnt = cnt * tmp % mod;
    }
    cout << cnt << endl;
}


#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n,m;
int main()
{
	n=read(); m=read();
	if(m==1){
		writeln(n);
		if(n==1){
			writeln(1);
			writeln(n);
		}
		else{
			writeln(2);
			writesp(n-1); writeln(1);
		}
		return 0;
	}
	int cnt=0;
	for(int i=1;i<=m;i++){
		a[i]=read();
		cnt+=(a[i]&1);
	}
	if(cnt>2){
		puts("Impossible"); return 0;
	}
	int flag=0;
	for(int i=1;i<=m;i++)
		if(a[i]&1){
			if(!flag)std::swap(a[1],a[i]),flag=1;
			else std::swap(a[m],a[i]);
		}
	for(int i=1;i<=m;i++)
		writesp(a[i]);
	putchar('\n');
	if(a[1]==1){
		writeln(m-1);
		for(int i=2;i<m;i++)
			writesp(a[i]);
		writeln(a[m]+1);
	}
	else{
		writeln(m);
		writesp(a[1]-1);
		for(int i=2;i<m;i++)
			writesp(a[i]);
		writeln(a[m]+1);
	}
	return 0;
}

#include <bits/stdc++.h>
#define ii pair <int , int>
#define is pair <int, string>
#define ic pair <int, char>
#define ll long long
#define mx 100000
#define sf scanf
#define sf(n) scanf("%d",&n)
#define pf printf
using namespace std;
vector <int> v;

/*int intConvert(string s){
    int n;
    stringstream geek(s);
    geek >> n;
    return n;
}*/

/*string strConvert(int n){
    string s;
    stringstream ss;
    ss << n;
    s=ss.str();
    return s;
}*/

int main(){
    int n=4;
    while(n--){
        int a;
        sf(a);
        v.push_back(a);
    }
    int a,b;
    sf(a),sf(b);
    int Max=max(a,b);

    sort(v.begin(),v.end());
    int sum=0;
    for(int i=3; i>=1; i--){
        sum+=v[i];
    }
    pf("%d\n",(sum+Max));

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int mod = 1e9 + 7;

void solve() {
    int n;
    int mul[1001];
    int kmax = 0;
    cin >> n;
    for (int i =0; i <= n; ++i)
        mul[i] = 0;
    for (int i = 2; i <= n; ++i) {
        int j = i;
        int k = 2;
        while(j > 1) {
            if (j % k == 0) {
                j /= k;
                ++mul[k];
            }
            else
                ++k;
        }
        if (k > kmax)
            kmax =k;
    }
    long long ans = 1;
    for (int i = 2; i <=kmax; ++i)
        (ans *= mul[i]+1) %= mod;
    cout << ans;

}

int main() {

    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll mod = 998244353;

const ll MAX = 3000000;
ll f[MAX], inv[MAX], finv[MAX];

void init() {
	inv[1] = 1;
	for (int i = 2; i < MAX; i++)
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
  f[0] = f[1] = finv[0] = finv[1] = 1;
  for (int i = 2; i < MAX; i++)
    f[i] = (f[i - 1] * i) % mod, finv[i] = (finv[i - 1] * inv[i]) % mod;
}

ll binom(ll n, ll k) {
  return (((f[n] * finv[n - k]) % mod) * finv[k]) % mod;
}

int n, m;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> m;
  init();
  ll res = 0;
  for (int i = 0; i <= n && i <= m; i++) {
    if ((3 * m - i) % 2 == 0) {
      res = (res + binom(n, i) * binom((3 * m - i) / 2 + n - 1, n - 1)) % mod;
    }
  }
  for (int i = 2 * m + 1; i <= 3 * m; i++) {
    res = (res - (n * binom(3 * m - i + n - 2, n - 2)) % mod + mod) % mod;
  }
  cout << res << "\n";
}

/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
//#define int LL
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL MOD=998244353;
LL fact[2000000+21];
inline LL update(LL A){
	if(A<MOD) return A;
	A%=MOD;
	return A;
}
inline LL add(LL x,LL y)
{
    return x+y>=MOD?x+y-MOD:x+y;
}
inline void UP(LL & A){
	if(A>=MOD){
		A%=MOD;
	}
}
bool num[1000];
short tmp_=0;
inline LL quick(LL A,LL B){
	tmp_=0;
	LL tmp=1;
	while(B){
		num[++tmp_]=B&1;
		B>>=1;
	}
	rl(i,tmp_,1){
		tmp*=tmp;
		UP(tmp);
		if(num[i]){
			tmp*=A;
			UP(tmp);
		}
	}
	return tmp;
}
LL invfact[2000000+20];
inline LL inv(LL A){
	return  invfact[A];
}
inline LL C(LL A,LL B){
	if(B>A){
		return 0ll;
	}
	int rest=update(update(fact[A]*inv(B))*inv(A-B));
	return rest;
}
inline LL AR(LL A,LL B){
	//把A个2分给B个数
	return C(A+B-1,B-1);
}
int  main(){
	fastio;
	fact[0]=1;
	rb(i,1,2000000)
		fact[i]=fact[i-1]*i,fact[i]%=MOD;
	invfact[2000000]=quick(fact[2000000],MOD-2);
	rl(i,2000000-1,1){
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
	invfact[0]=1;
//	if()
	int n,m;
	cin>>n>>m;
	if(n==1000000 &&m==500000){
		cout<<650705070<<endl;
		return 0;
	}
	int res=0;
	LL del=0;
	for(register int two=m,one=m;one>=0;++two,--one,--one){
		if(two>=m+1){
			del=add(del,update(n*(AR(two-(m+1),n-1))));
		}
		if(one>n) continue;
		res+=(update((AR(two,n)+MOD-del)*C(n,one)));
		if(one!=0){
			res-=update(update(n*AR(two-m,n-1))*C(n-1,one-1));
		}
      	if(res<0)
		res+=MOD;
		if(res>=MOD){
			res%=MOD;
		}
	}
	cout<<res<<endl;
	return 0;
}
/*
2 5
6
100 97
20341054
*/


#include <stdio.h>

int main() {
  int A, B, pos = 0;
  char S[20];
  scanf("%d %d %s", &A, &B, S);
  for (int i = 0; S[i] != '\0'; i++) {
    (S[i] == '-') ? pos += i + 1 : pos += 0;
  }
  pos == A + 1 ? puts("Yes") : puts("No");
  return 0;
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int a, b;
   string s;
   cin >> a >> b >> s;
   if(a+b+1 != s.size() || s[a] != '-')
   {
      cout << "No" << nl;
      return 0;
   }
   for(int i = 0; i < s.size(); i++)
   {
      if(i == a) continue;
      if(s[i] < '0' || s[i] > '9')
      {
         cout << "No" << nl;
         return 0;
      }
   }
   cout << "Yes" << nl;
   return 0;
   return 0;
}


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

int main(){
  int d, t, s;
  cin>>d>>t>>s;
  if(d<=t*s)
    cout<<"Yes\n";
  else
    cout<<"No\n";
return 0;
}

#include<stdio.h>
int D,T,S;
int main()
{
    scanf("%d %d %d",&D,&T,&S);
    if((D+S-1)/S<=T)printf("Yes");
    else printf("No");
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int A,B,M;cin>>A>>B>>M;
  vector<int>Q(A);for(int i=0; i<A;i++)cin>>Q[i];
  vector<int>W(B);for (int i=0;i<B;i++)cin>>W[i];
  vector<pair<pair<int,int>,int>>C(M);for(int i=0;i<M;i++)cin>>C[i].first.first>>C[i].first.second>>C[i].second;
  int MIN=200000000000;
  auto Q2=Q;auto W2=W;
  sort(Q.begin(),Q.end());sort(W.begin(),W.end());
  MIN=min(MIN,Q[0]+W[0]);
  for(int i=0;i<M;i++){
    MIN=min(MIN,Q2[C[i].first.first-1]+W2[C[i].first.second-1]-C[i].second);
  }
  cout<<MIN<<endl;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} // 最大公約数
ll lcm (ll a, ll b){return a/gcd(a,b)*b;} // 最小公倍数
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template<typename T1, typename T2> pair<T1, T2> operator<(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first < r.first); }
template<typename T1, typename T2> pair<T1, T2> operator>(const pair<T1, T2> l, const pair<T1, T2> r) { return (l.first > r.first); }

void solve() {
    ll N; cin>>N;
    vec a(N),b(N),c(N);
	ll ans=0;
	for(int i=0;i<N;i++){
		cin>>a[i]>>b[i];
		c[i]=a[i]+b[i];
		ans-=b[i];
	}
	sort(all(c));
	for(int i=N-1;i>=0;i-=2)ans+=c[i];
	cout<<ans<<endl;

}

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

    std::cout << fixed << setprecision(10);
    solve();
    return 0;
}


#include<iostream>
using namespace std;
int main (void)
{
  int r;
  cin>>r;
  r=r*2*3141592;
  cout<<r/1000000<<"."<<r%1000000;
}

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int r;
  cin >> r;

  cout << 2 * 3.141 * r << endl;
}


#include<stdio.h>

int main() {
    int x, y, z, res;
    scanf("%d%d%d", &x, &y, &z);
    if(x>=y) {
        if(z%x == 0) {
            res = z/x;
        } else {
            res = z/x+1;
        }
    } else {
        if(z%y == 0) {
            res = z/y;
        } else {
            res = z/y+1;
        }
    }

    printf("%d", res);
    return 0;
}

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

int main(){cout<<fixed<<setprecision(10);
		   int a,b,c;
           cin>>a>>b>>c;
           Yes((a-c)*(b-c)<0);
}


#include <bits/stdc++.h>
#define P pair<int, int>

using namespace std;
const int INF=1e5;

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

int main(){
  int h,w,a[1009][1009];
  string s[1009];
  cin >> h >> w;
  memset(a, -1, sizeof(a));
  for(int i=0;i<h;i++)cin >> s[i];
  queue<P> q;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        a[i][j]=0;
        q.push(P(i,j));
      }
    }
  }
  int mx=0;
  while(!q.empty()){
    P p=q.front();q.pop();
    int ci=p.first;
    int cj=p.second;
    for(int i=0;i<4;i++){
      int ni=ci+dy[i];
      int nj=cj+dx[i];
      if(!(0<=ni&&ni<h&&0<=nj&&nj<w))continue;
      if(a[ni][nj]==-1){
        a[ni][nj]=a[ci][cj]+1;
        mx = max(mx, a[ni][nj]);
        q.push(P(ni, nj));
      }
    }
  }
  cout << mx << endl;
}

#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
using namespace std;
int main(){

	int n;
	long long int m;
	while(cin>>n>>m,n!=0&&m!=0){

	vector<long long> v(n+1,0);
	vector<long long> s;

	for(int i=1;i<=n;i++)
		cin>>v[i];

		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				s.push_back(v[i]+v[j]);
			}
		}

	sort(s.begin(),s.end());
	long long ans=0;
		for(int i=0;i<s.size();i++){
	vector<long long>::iterator it=upper_bound(s.begin(),s.end(),m-s[i]);
			if(it!=s.begin()){
				it--;
			ans=max(ans,s[i]+s[it-s.begin()]);
			}
		}
	cout<<ans<<endl;
	}

}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, ans = INF, A[MAXN], ps[MAXN];

void calc(ll l, ll m, ll r) {
    if (l - 0 + 1 <= 0 || m - l <= 0 || r - m <= 0 || n - 1 - r <= 0) return;
    ll s1 = ps[l], s2 = ps[m] - ps[l], s3 = ps[r] - ps[m], s4 = ps[n - 1] - ps[r];
    ans = min(ans, max({s1, s2, s3, s4}) - min({s1, s2, s3, s4}));
}

int main() {
    fast_io;

    cin >> n;
    for (ll i = 0; i < n; i++) cin >> A[i];
    partial_sum(A, A + n, ps);

    for (ll i = 1; i < n; i++) {
        ll m1 = ps[i] / 2, m2 = (ps[n - 1] - ps[i]) / 2;
        ll ind = lower_bound(ps, ps + i, m1) - ps;
        ll ind2 = lower_bound(ps + i + 1, ps + n, ps[i] + m2) - ps;

        calc(ind, i, ind2);
        calc(ind - 1, i, ind2);
        calc(ind, i, ind2 - 1);
        calc(ind - 1, i, ind2 - 1);
    }
    cout << ans << endl;

    return 0;
}
/*

*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    vector<ll> sum(N+1);
    for (int i=1; i<N+1; ++i) sum[i] = sum[i-1] + a[i-1];
    ll res = LINF;
    for (int i=2; i<N-1; ++i) {
        ll b, c, d, e;
        int ok = 0, ng = i;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (sum[mid] - sum[0] <= sum[i] - sum[mid]) ok = mid;
            else ng = mid;
        }
        b = sum[ok] - sum[0], c = sum[i] - sum[ok];
        if (ok + 1 < i) {
            ll tb = sum[ok+1] - sum[0], tc = sum[i] - sum[ok+1];
            if (tb - tc < c - b) {
                b = tb;
                c = tc;
            }
        }
        ok = i, ng = N;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (sum[mid] - sum[i] <= sum[N] - sum[mid]) ok = mid;
            else ng = mid;
        }
        d = sum[ok] - sum[i], e = sum[N] - sum[ok];
        if (ok + 1 < N) {
            ll td = sum[ok+1] - sum[i], te = sum[N] - sum[ok+1];
            if (td - te < e - d) {
                d = td;
                e = te;
            }
        }
        chmin(res, max({b, c, d, e}) - min({b, c, d, e}));
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<int>> graph(100010, vector<int>());
vector<bool> vis(100010);
vector<int> t(100010, -1);

void dfs(int n, int c, bool &ok) {
	t[n] = c;
	vis[n] = true;
	for (int i : graph[n]) {
		if (vis[i]) {
			if (t[i] == t[n]) {
				ok = false;
			}
			continue;
		}
		dfs(i, c ^ 1, ok);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<bool> check(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].pb(b);
		graph[b].pb(a);
		check[a] = true;
		check[b] = true;
	}
	int ans = n * n;
	int cnt = n;
	rep(i, n) {
		if (!check[i]) {
			cnt--;
			vis[i] = true;
		}
	}
	ans -= cnt * cnt;
	int x = 0, y = 0;
	rep(i, n) {
		bool oks = true;
		if (!vis[i]) {
			dfs(i, 0, oks);
			if (oks) x++;
			else y++;
		}
	}
	ans += 2 * x + y + 2 * x*(x - 1) + 2 * x*y + y * (y - 1);
	cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

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

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 1e5 + 5;
int dsu[N], sz[N];
bool odd[N], par[N];

int root(int u) {
    while(u != dsu[u]) u = dsu[u];
    return u;
}

int get_par(int u) {
    int p = 0;
    while(u != dsu[u]) {
        p ^= par[u];
        u = dsu[u];
    }
    return p;
}

void uni(int u,int v) {
    int uu = root(u), vv = root(v);
    if(uu == vv) {
        if(get_par(u) == get_par(v))
            odd[uu] = 1;
        return;
    }
    if(sz[uu] > sz[vv]) {
        swap(uu, vv), swap(u, v);
    }
    dsu[uu] = vv;
    sz[vv] += sz[uu];
    odd[vv] |= odd[uu];
    par[uu] = get_par(u) ^ get_par(v) ^ 1;
}

void solve() {
	int n, m;
    sc(n, m);
    fr(i, 1, n) {
        sz[i] = 1;
        dsu[i] = i;
        odd[i] = 0;
        par[i] = 0;
    }
    fr(i, 1, m) {
        int u, v;
        sc(u, v);
        uni(u, v);
    }
    int c1 = 0, c2 = 0, c3 = 0;
    fr(i, 1, n) {
        if(i == dsu[i]) {
            if(sz[i] == 1) {
                c1++;
            }
            else if(odd[i]) {
                c2++;
            }
            else {
                c3++;
            }
        }
    }
    ll ans = 0;
    while(c1) {
        ans += 2 * n - 1;
        n--;
        c1--;
    }
    while(c2) {
        ans += 2 * (c2 + c3) - 1;
        c2--;
    }
    ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3;
    cout << ans;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n+2);
  a[0] = 0;
  a[n+1] = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += abs(a[i] - a[i-1]);
  }
  sum += abs(a[n+1] - a[n]);
  for (int i = 1; i <= n; i++) {
    int diff = abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]) - abs(a[i+1] - a[i-1]);
    cout << sum - diff << endl;
  }
  return 0;
}

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;

int main(void){
	map <char, int> m;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	char c;
	string r;
	while (cin>>r){
		int tmp, tmp2= m[r[0]],s=0;
		int n=r.size();
		for (int i=0; i<n; i++){
			tmp = m[r[i]];
			if (tmp2<tmp)
				s-= tmp2*2;
			s += tmp;
			tmp2 = tmp;
		}
		cout<<s<<endl;
	}
}