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

const double pi = 3.141592653589793;
int inf = 1001001001;
ll INF = 1001001001001001001;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
ll MOD = 1000000007;
using P = pair<ll, ll>;

double eps = 1e-12;

int main() {
    int N;cin >> N;
    string S;cin >> S;
    string T;cin >> T;
    vector<int> cnts;
    vector<int> cntt;
    vector<int> places;
    vector<int> placet;
    ll cnt = 0;
    rep(i, N) {
        if (S[i] == '0') {
            cnt++;
            cnts.pb(i);
            places.pb(cnt);
        }
    }
    cnt = 0;
    rep(i, N) {
        if (T[i] == '0') {
            cnt++;
            cntt.pb(i);
            placet.pb(cnt);
        }
    }
    if (cnts.size() !=cntt.size()) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;

    rep(i, cnts.size()) {
        if (cnts[i] == cntt[i]&&places[i] == placet[i]) continue;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define p_q priority_queue
#define m_p make_pair
#define pb push_back
#define ld long double
#define F first
#define S second
#define ull unsigned long long
#define mod 1000000007
#define md 998244353
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll qpow(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string iots(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int stoi(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,m;
bool g[1111][1111];
int par[2222];
int find(int x)
{
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void merge(int x,int y)
{
	par[find(x)]=find(y);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,n)
	{
		rep(j,m)
		{
			char c;
			cin>>c;
			if(c=='#')g[i][j]=1;
		}
	}
	g[0][m-1]=g[n-1][m-1]=g[n-1][0]=1;
	rep(i,n+m)par[i]=i;
	rep(i,n)
	{
		rep(j,m)
		{
			if(g[i][j]==1)
			{
				merge(i,n+j);
			}
		}
	}
	set<int>s1,s2;
	rep(i,n)s1.insert(find(i));
	rep(i,m)s2.insert(find(i+n));
	cout<<min(s1.size(),s2.size())-1<<endl;
	return 0;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

ll all;
vector<vector<vector<ll>>> memo;
ll h, w, a, b;
ll bit(ll i, ll j) {
    return 1ULL << (i * w + j);
}
bool empty(ll stat, ll i, ll j){
    if (i >= h) return false;
    if (j >= w) return false;
    if(stat & bit(i,j)) return false;
    return true;
}
ll dfs(ll stat, ll full, ll half, ll bi, ll bj) {
    if (full < 0 || half < 0) return 0;
    if (stat == all - 1) return 1;
    if (memo[stat][full][half] != -INF) return memo[stat][full][half];

    // 常に一番左上に置く
    ll ti = -1;
    ll tj = -1;
    for (ll j = bj; j < w; j++) {
        if(empty(stat,bi,j)){
          ti=bi;
          tj=j;
          break;
        }
    }
    for (ll i = bi+1; i < h; i++) {
        if (ti >= 0) break;
        for (ll j = 0; j < w; j++) {
            if (empty(stat,i,j)) {
                ti = i;
                tj = j;
                break;
            }
        }
    }
    return memo[stat][full][half] =
      dfs(stat | bit(ti,tj), full, half - 1, ti, tj) +
      (empty(stat,ti+1,tj) ? dfs(stat | bit(ti+1,tj) | bit(ti,tj), full - 1, half, ti, tj) : 0) +
      (empty(stat,ti,tj+1) ? dfs(stat | bit(ti,tj+1) | bit(ti,tj), full - 1, half, ti, tj) : 0);
}
int main() {
    cin >> h >> w >> a >> b;
    all = 1ll << (h * w);
    memo.resize(all, vector<vector<ll>>(a + 1, vector<ll>(b + 1, -INF)));
    print(dfs(0, a, b, 0, 0));
}

#include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout)
using ll=long long;using i64=long long;using db=double;
using u32=unsigned int;using u64=unsigned long long;using db=double;
using pii=pair<int,int>;using vi=vector<int>;
using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>;
#define pb push_back
#define mk make_pair
#define ins insert
#define era erase
#define fi first
#define se second
#define lowbit(x) x&-x
#define ALL(a) a.begin(),a.end()
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
template<class T>inline bool chkmin(T&a,T b){return b<a?a=b,true:false;}
template<class T>inline bool chkmax(T&a,T b){return a<b?a=b,true:false;}
int _w,_t;FILE* _f;

const int N=1<<16;
int h,w,a,b,mx,cnt;
ll f[2][N][17];

void solve(){
    scanf("%d%d%d%d",&h,&w,&a,&b);
    if(h<w){
        swap(h,w);
    }
    mx=1<<w;
    f[1][mx-1][0]=1;
    for(int i=1;i<=h;i++){
        for(int j=0;j<w;j++){
            memset(f[cnt],0,sizeof f[cnt]);
            cnt^=1;
            for(int k=0;k<mx;k++){
                for(int l=0;l<=b;l++){
                    if(j&&(k>>j&1)&&!(k>>(j-1)&1)){
                        f[cnt^1][k|(1<<(j-1))][l]+=f[cnt][k][l];
                    }
                    if(!(k>>j&1)){
                        f[cnt^1][k|(1<<j)][l]+=f[cnt][k][l];
                    }
                    if((k>>j&1)&&(l<b)){
                        f[cnt^1][k][l+1]+=f[cnt][k][l];
                    }
                    if((k>>j&1)){
                        f[cnt^1][k^(1<<j)][l]+=f[cnt][k][l];
                    }
                }
            }
        }
    }
    printf("%lld\n",f[cnt^1][mx-1][b]);
}

int main(){
    #ifdef MULTI_CASES
    _w=scanf("%d",&_t);while(_t--)
    #endif
    solve();
    return 0;
}


//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[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||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

VL pri;
void prii(LL n){LL i,j,k,p,f,s,a[8]={7,11,13,17,19,23,29,31};pri.PB(2);pri.PB(3);pri.PB(5);for(i=0;i<=n;i+=30)rep(j,8)if(i+a[j]<=n){p=i+a[j],f=0,s=sqrt(p)+1;FOR(k,3,pri.size()){if(pri[k]>s)break;if(p%pri[k]==0)f=1;}if(f==0)pri.PB(p);}}

int main(){
    FAST;
    LL i,j,ans=INF,N;
    cin>>N;
    VL X(N);
    rep(i,N)cin>>X[i];
    prii(100);
    rep(i,1<<15){
        LL a=1,f=1;
        rep(j,15)if(i&(1<<j))a*=pri[j];
        rep(j,N)if(GCD(X[j],a)==1)f=0;
        if(f)chmin(ans,a);
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define all(x) x.begin(), x.end()
const int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
void solve() {
   int n, m = sizeof(p) / sizeof(int);
   cin >> n;
   vector <int> a(n);
   ll ans = 1e18;
   for (auto &i : a)
      cin >> i;
   for (int k = 0; k < (1 << m); k++) {
      vector <bool> vs(n);
      ll res = 1;
      for (int i = 0; i < m; i++) {
         if ((k >> i) & 1)
            continue;
         res *= p[i];
         for (int j = 0; j < n; j++) {
            if (a[j] % p[i] == 0)
               vs[j] = true;
         }
      }
      if (count(all(vs), true) == n)
         ans = min(ans, res);
   }
   cout << ans << '\n';
}
int main() {
#ifndef ONLINE_JUDGE
   freopen("inp.txt", "r", stdin);      freopen("outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
   solve();
   return 0;
}


#ifdef _LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

string solve(ll n) {
    if(n == 0)
        return "Yes";

    while(n % 10ll == 0ll)
        n /= 10ll;

    string s = to_string(n);
    bool ok = true;
    int size = (int)s.size();
    for(int i = 0; i < size / 2; i++) {
        if(s[i] != s[size - 1 - i]) {
            ok = false;
            break;
        }
    }
    return ok ? "Yes" : "No";
}

#ifndef _LOCAL
int main() {
    ll n;
    cin >> n;
    cout << solve(n) << endl;
    return 0;
}
#endif

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,k,t,c=0,ss=0,ev=0,od=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2 ==0 && s[i]>='a' && s[i]<='z')c++;
        else if(i%2!=0 && s[i]>='A' && s[i]<='Z')ss++;

        if(i%2==0)ev++;
        else od++;
    }
    //cout<<ev<<" "<<od<<endl<<c<<" "<<ss<<endl;
    if(c==ev && ss==od)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


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

bool isPalindrome(string s){
  string rs=s;
  reverse(rs.begin(),rs.end());
  return rs==s;
}

int main() {
  int n;
  cin>>n;
  if(n==0){
    cout<<"Yes"<<endl;
    return 0;
  }
  while(n%10==0) n/=10;

  if(isPalindrome(to_string(n))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define SZ(x) (ll)(x).size()
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
// BIG p : 1000000000000037 , 100000000003
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 int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
const int lg = 20 ;
int ans = 1 ;
int main()
{
	migmig ;
	vec<char> v ;
	char c ;
	string s ;
	cin>>s ;
	if(s == "0"){
		cout<<"Yes" ; return 0 ;
	}
	for(int i = 0 ; i < SZ(s) ; i ++ ) v.pb(s[i]) ;
	while(v.back() == '0') v.pop_back() ;
	for(int i = 0 ; i <= SZ(v) / 2 ; i ++ ){
		if(v[i] != v[(SZ(v) - 1 - i)]) ans = 0 ;
	}
	if(ans) cout<<"Yes" ;
	else cout<<"No" ;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<ul>
#define ff first
#define ss second
#define INF 1000000000

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

   vector<ll>v;
   for(int i=0;i<n;i++)
   {
       ll k;
       cin>>k;
       v.pb(k);
   }

   for(int i=0;i<v.size();i++)
   {
       if(v[i]==x)
         continue;
       else
        cout<<v[i]<<" ";
   }
   cout<<"\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){char c;string s;cin>>c>>s;cout<<s<<c;}


#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  cout << (2*a + 100) - b << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000000001
#define INF 1e9+7
#define LINF 1e18+10
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 300000;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error

//////////////////////////////////////

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

    int ans=2*a+100-b;
    chmax(ans,0);
    cout<<ans<<endl;
    return 0;
}


/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 2000110;
const int P = 998244353;

int n, q, fa[N], d[N], ans[N], num[N];
vector<int> G[N], Q[N];
void dfs(int u, int dep) {
  map<int, int> M;
  for (int qi : Q[u]) {
    M[d[qi]] = num[d[qi]];
  }
  for (int v : G[u]) {
    dfs(v, dep + 1);
  }
  num[dep]++;
  for (int qi : Q[u]) {
    ans[qi] = num[d[qi]] - M[d[qi]];
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 2, n) cin >> fa[i], G[fa[i]].pb(i);

  cin >> q;
  rep(i, 1, q) {
    int u;
    cin >> u >> d[i];
    Q[u].pb(i);
  }

  dfs(1, 0);
  rep(i, 1, q) cout << ans[i] << "\n";
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

const int bm = 200010;
int BIT[bm];
void add(int A) {
	while (A <= bm) {
		BIT[A]++;
		A += A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret;
}

int Q[200001], ne[200001], he[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int H = getint(), W = getint(), M = getint();

	int X[200001], Y[200001];
	rep1(i, H) X[i] = W;
	rep1(i, W) Y[i] = H;
	rep(i, M) {
		int x = getint(), y = getint();
		if (y - 1 < X[x]) X[x] = y - 1;
		if (x - 1 < Y[y]) Y[y] = x - 1;
	}
	ll kotae = 1;
	int k = 1;
	for (int i = 2; i <= Y[1]; i++) {
		kotae += X[i];
		Q[k] = i;
		ne[k] = he[X[i]];
		he[X[i]] = k++;
	}

	int atta = X[1];
	for (int i = W; i > atta; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
	}
	for (int i = atta; i >= 2; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
		int are = query(Y[i]);
		kotae += Y[i] - are;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define JUGAD freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define po pop_back
#define pof pop_front
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pll pair<lli,lli>
#define pdd pair<ld,ld>
#define pq priority_queue
#define qq queue
#define ff first
#define ss second
#define decimal fixed<<setprecision(20)

const int N = 1e5+3;
const lli MOD = 1e9+7;

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

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

void solve(){
	string s;cin>>s;
	int ar[10];
	for(int i=0;i<10;i++){
		if(s[i]=='o'){
			ar[i]=1;
		}
		else if(s[i]=='x'){ar[i]=0;}
		else{ar[i]=2;}
	}
	int ans=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				for(int l=0;l<10;l++){
					bool ok=1;
					for(int a=0;a<10;a++){
						if(ar[a]==1){
							if(i!=a && j!=a && k!=a && l!=a){
								ok=0;break;
							}
						}
						else if(ar[a]==0){
							if(i==a || j==a || k==a || l==a){
								ok=0;break;
							}
						}
					}
					if(ok){ans++;}
				}
			}
		}
	}
	cout<<ans;
}

int main(){
	FAST;
	solve();
	return 0;
	int test_cases;cin>>test_cases;
	for(int tc=1;tc<=test_cases;tc++){

		cout<<"Case #"<<tc<<": ";
	}
}

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007LL
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define SHIFT(n) (1LL<<((ll)n))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
#define Sum(a) (accumulate(ALL(a),0LL))
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    deque<char>deq;
    ll fl = false;
    for(auto c:s){
        if(c == 'R'){
            fl++;
            fl %= 2;
        }else{
            if(fl){
                if(!deq.empty() && deq.front() == c){
                    deq.pop_front();
                }else{
                    deq.push_front(c);
                }
            }else{
                if(!deq.empty() && deq.back() == c){
                    deq.pop_back();
                }else{
                    deq.push_back(c);
                }
            }
        }
    }
    if(fl){
        while(!deq.empty()){
            cout << deq.back();
            deq.pop_back();
        }
    }else{
        while (!deq.empty()){
            cout << deq.front();
            deq.pop_front();
        }
    }
    cout << endl;
    return 0;
}


/*
  Submitter: Nick Hudson
  Anumber: A01634984

  */

#include <iostream>

int main(){
  int N,K,M,input;
  int sum;
  int neededScore;

  std::cin>>N>>K>>M;
  //std::cout<<N<<K<<M<<std::endl;

  for(int i = 0; i<N-1; ++i){
    std::cin>>input;
    //std::cout<<input<<std::endl;
    sum += input;
    //std::cout<<sum<<std::endl;
  }
  int x = N*M-sum;

  if(x<0){
    std::cout<<0;
  } else if(x<=K){
    std::cout<<x;
  } else
    std::cout<<-1;

  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#include <cmath>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INFI = 1001001001;
const ll INFL = 1001001001001001001;
const ll MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, in, fn) for (ll i = in; i <= fn; i++)
#define debug(x) cerr << #x << ": " << x << endl

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{
    int n = av.size();
    vector<ll> p(n), av2(n), bv2(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&](ll a, ll b) { return av[a] < av[b]; });
    for (int i = 0; i < n; i++)
    {
        av2[i] = av[p[i]];
        bv2[i] = bv[p[i]];
    }
    av = av2;
    bv = bv2;
}

int main()
{
    long long K;
    scanf("%lld", &K);
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(K), A2(K), num(K);
    std::vector<long long> B(K), sa(K);
    for (int i = 0; i < K; i++)
    {
        scanf("%lld", &A[i]);
    }

    ll sum = 0;
    rep(i, K)
    {

        A2[i] = A[i];
        num[i] = i;
        B[i] = M * A[i] / N;
        sum += B[i];
        //debug(B[i]);
        sa[i] = (llabs((B[i] + 1) * N - A[i] * M)) - (llabs(B[i] * N - A[i] * M));
        //debug(sa[i]);
    }
    ll amari = M - sum;
    sort2vectors(sa, num);
    rep(i, amari)
    {
        B[num[i]]++;
    }
    rep(i, K)
    {
        cout << B[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 2 * 1e5 + 5;

ll ans[MAX];
int dis[MAX];
vvint g;

void dfs(int v, int d = 0, int p = -1) {
    dis[v] = d;
    for (int n_v : g[v]) {
        if (n_v == p) continue;
        dfs(n_v, d + 1, v);
    }
}

void solve(int v, int p = -1) {
    for (int n_v : g[v]) {
        if (n_v == p) continue;
        ans[n_v] += ans[v];
        solve(n_v, v);
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    vector<P> dat(n);
    rep(i,n-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        dat[i] = P(a, b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0);
    // rep(i,n) cout << dis[i] << endl;
    int q; cin >> q;
    rep(i,q) {
        int t, e, x; cin >> t >> e >> x;
        e--;
        auto [a, b] = dat[e];
        if (t == 1) {
            if (dis[a] < dis[b]) {
                ans[0] += x;
                ans[b] -= x;
            } else {
                ans[a] += x;
            }
        } else {
            if (dis[a] < dis[b]) {
                ans[b] += x;
            } else {
                ans[0] += x;
                ans[a] -= x;
            }
        }
    }
    solve(0);
    rep(i,n) cout << ans[i] << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define LL long long

constexpr LL MOD = 1000000007;

typedef vector<vector<LL>> Mat;

Mat mul(Mat A, Mat B) {
  int N = A.size();
  Mat C(N, vector<LL>(N, 0));

  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++)
        C[i][j] = (C[i][j] + ((A[i][k] * B[k][j]) % MOD)) % MOD;
  return C;
}

LL extended_euclidean(LL a, LL b, LL &x, LL &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }

  LL x1, y1;
  LL g = extended_euclidean(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return g;
}

LL invmod(LL a) {
  LL x, y;
  extended_euclidean(a, MOD, x, y);
  return (x % MOD + MOD) % MOD;
}

vector<vector<int>> adj;
Mat A; // weight
Mat m; // transition matrix

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

  A.resize(N);
  adj.resize(N);
  m.resize(N);

  for (int i = 0; i < N; i++) {
    A[i].resize(1);
    cin >> A[i][0];
  }

  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  // calculate the matrix.
  LL inv2M = invmod(2 * M);
  for (int i = 0; i < N; i++) {
    m[i].assign(N, 0);
    m[i][i] = 1LL;

    for (int j : adj[i]) {
      m[i][j] = inv2M;
      m[i][i] = (m[i][i] - inv2M + MOD) % MOD;
    }
  }

  while (K > 0) {
    if (K & 1)
      A = mul(m, A);
    m = mul(m, m);
    K >>= 1;
  }

  for (int i = 0; i < N; i++)
    cout << A[i][0] << endl;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 2;

vector<int> as;

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

    as.push_back(0);
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        as.push_back(a);
    }
    as.push_back(N + 1);

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

    int max_interval = INF;
    for (int i = 0; i < (int) as.size() - 1; i++) {
        int l = as[i];
        int r = as[i + 1];
        int interval = r - l - 1;
        if (interval > 0) {
            chmin(max_interval, interval);
        }
    }

    int ans = 0;
    for (int i = 0; i < (int) as.size() - 1; i++) {
        int l = as[i];
        int r = as[i + 1];
        int interval = r - l - 1;
        if (interval > 0) {
            ans += (interval + max_interval - 1) / max_interval;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int M=1e5+5,N=(1<<8)+5;
int n,m,v[M],w[M],a[20],l[N],b[20],ans=998244353,f[N];
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",a+i);
	rep(i,1,m) scanf("%d%d",v+i,w+i);
	int S=(1<<n)-1;
	rep(i,1,S){
		int sum=0;
		rep(j,1,n) if((i>>(j-1))&1) sum+=a[j];
		rep(j,1,m) if(sum>w[j]) l[i]=max(l[i],v[j]);
	}
	rep(i,1,n) rep(j,1,m) if(a[i]>w[j]) return puts("-1"),0;
	rep(i,1,n) b[i]=i;
	do{
		f[0]=0;
		rep(i,2,n){
			int s=1<<b[i]-1; f[i]=0;
			per(j,i-1,1) s|=1<<b[j]-1,f[i]=max(f[i],f[j]+l[s]);
		}
		ans=min(ans,f[n]);
	}while(next_permutation(b+1,b+n+1));
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;

long long gcd(long long a, long long b){ return b? gcd(b, a%b) : a; }
long long lcm(long long a, long long b){ return (!a or !b)? 0 : a * b / gcd(a,b); }
long long  poww(long long  a, long long b){
	long long res = 1;
	while(b){
		if(b%2) res = res * a ;
		a = a * a;  b>>=1;
	} return res;
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using li = long long;
using vi = vc<int>;
using ii = pair<int,int>;
// ---- しゃけ ツナマヨ ('-')7

int main(){_

	auto solve=[&](){
		int n; cin>>n;
		string s; cin>>s;
		n++;
		vi v(n); fore(i,0,n)cin>>v[i];
		int k = inf<int>;
		fore(i,0,n-1)k=min(k,abs(v[i+1]-v[i]));
		cout<<k<<ENDL;
		fore(i,0,k){fore(j,0,n)cout<<(v[j]+i)/k<<" ";cout<<ENDL;}
	};
	//int t; cin>>t; while(t--)
	solve();
}

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

using namespace std;

int N;
string S;

int a[5050], t[5050], c[5050], g[5050];
int sum_A[5050], sum_T[5050], sum_C[5050], sum_G[5050];

int main(void) {

	cin >> N >> S;

	S = '#' + S;

	for (int i = 1; i <= N; i++) {
		if (S[i] == 'A') { a[i] = 1; }
		else if (S[i] == 'T') { t[i] = 1; }
		else if (S[i] == 'C') { c[i] = 1; }
		else if (S[i] == 'G') { g[i] = 1; }
	}

	for (int i = 1; i <= N; i++) {
		sum_A[i] = sum_A[i - 1] + a[i];
		sum_T[i] = sum_T[i - 1] + t[i];
		sum_C[i] = sum_C[i - 1] + c[i];
		sum_G[i] = sum_G[i - 1] + g[i];
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			if ((sum_A[j] - sum_A[i - 1] == sum_T[j] - sum_T[i - 1]) && (sum_G[j] - sum_G[i - 1] == sum_C[j] - sum_C[i - 1])) { ans++; }
		}
	}

	cout << ans << endl;

	return 0;
}


// Problem: C - To 3
// Contest: AtCoder - AtCoder Beginner Contest 182
// URL: https://atcoder.jp/contests/abc182/tasks/abc182_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)     \
  for (auto x : v)    \
    cout << x << " "; \
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define ump unordered_map
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) (ll)x.size()
#define ff first
#define ss second
#define I(a) for(auto &x:a) cin>>x;
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e5 + 5;
void solve()
{
	unsigned ll a;
	cin>>a;
	ll b[3]={0},sum=0,dig=0;
	while(a)
	{
		ll c=a%10;

		sum+=(c);
		sum%=3;
		b[c%3]++,dig++;
		a/=10;
	}
	if(sum==0)
	cout<<0;
	else if(sum==1)
	{
		if(b[1]&&dig>1)
		cout<<1;
		else if(b[2]>1&&dig>2)
		cout<<2;
		else
		cout<<-1;
	}
	else
	{
		if(b[2]&&dig>1)
		cout<<1;
		else if(b[1]>1&&dig>2)
		cout<<2;
		else
		cout<<-1;
	}

}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ff first
#define ss second
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,
              tree_order_statistics_node_update>pbds;
//order_of_key:index number if it was there in sorted array
//find_by_order:value at 3rd index in sorted array.
const ll maxs=1e6+5;
ll root[maxs];

class cmp{
  bool operator()(const ll &a,const ll &b)
  {
      return a<b;
  }
};
void init()
{
    iota(root,root+maxs,0);
}
ll find(ll u)
{
    ll f;
    if(root[u]==u)
    return u;
    else
    {
        ll f=find(root[u]);
        root[u]=f;
        return f;
    }
}
void Union(ll x,ll y)
{
    ll u=find(x);
    ll v=find(y);
    root[v]=u;
}
ll power(ll x,ll y,ll p)
{
    ll res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
        res=(res*x)%p;

        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}

ll solve(ll mid,vector<ll>&arr)
{
    ll cnt=0;
    for(auto i:arr)
    {
        if(i%mid==0)
         cnt++;
    }
    return cnt;
}
int main()
{
    ll t,n,i,k,y,x,j,a,b;
   cin>>n;
    vector<ll>arr;
    while(n>0)
    {
        ll d=n%10;
        arr.push_back(d);
        n/=10;

    }
    ll m=arr.size();
    ll ans=0;
    for(i=0;i<(1<<m);i++)
    {
        ll sum=0;
        for(j=0;j<m;j++)
        {
            if((1<<j)&i)
            {
                sum+=arr[j];
            }
        }
        if(sum%3==0)
        {
            ll f=__builtin_popcount(i);
            ans=max(ans,f);
        }
    }
    if(ans==0)
     cout<<-1<<endl;
     else
     {
         cout<<arr.size()-ans<<endl;
     }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define b back
#define cout(x) cout<<x<<endl
#define lb long double
#define sor(arr,n) sort(arr,arr+n)
#define inputVector(v,n) for(int i=0;i<n;i++) cin>>v[i]
#define sov(v) sort(v.begin(),v.end())
#define pl pair<ll,ll>
#define all(a)      (a).begin(),(a).end()
#define vpp vector<pair<ll,ll>>
#define fastIo ios_base::sync_with_stdio(false),cin.tie(0)
#define endl '\n'
typedef long long  int  ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int N=100001;
ll P=1e9+7;
void solve() {
    ll i,n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
   sov(a);
   if(n==1) {cout<<a[0]/2<<endl; return;}
   vector<ll> pref(n);
   pref[0]=a[0];
   for(int i=1;i<n;i++) { pref[i]=pref[i-1]+a[i]; }
   long double expectation=LLONG_MAX;
   for(int i=1;i<n;i++) {
       lb val=(a[i]/2.0);
       lb exp=val*n;
       exp+=pref[n-1]-pref[i-1];
       exp-=(n-i)*2*val;
       exp/=n;
       expectation=min(expectation,exp);
   }
   cout<<fixed<<setprecision(10)<<expectation<<endl;
}
int main() {
    ll t=1,i=1;
    fastIo;
    // cin>>t;
    while(t--) {
        solve();
        i++;
    }
    return 0;
}
// may be a binary search too on the probabilities lets see.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+9;
const int MAX=6e5+9;
const int MAX1=5e6+9;
const int INF=0x3f3f3f3f;
const double ep=1e-8;
const double ep1=1e-4;
const int mod=998244353;
const double inf=1e20;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PDI pair<double,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIIII pair<PII,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define PLIII pair<PLI,PII >
#define PLL pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
#define PR(x) printf("Case %d: ",(x))
#define INF 0x3f3f3f3f
typedef unsigned long long ull;
/*
*/
struct node{
	int to,nex;
	ll val;
}a[maxn];
int n,m;
int head[maxn],cnt;
void add(int fro,int to,ll val)
{
	a[++cnt].to=to;
	a[cnt].val=val;
	a[cnt].nex=head[fro];
	head[fro]=cnt;
}
ll d[maxn];
void bfs(int x)
{
	priority_queue<PLI,deque<PLI >,greater<PLI > >q;
	q.push(mk(0,x));
	bool ju=0;
	while(!q.empty())
	{
		PLI p=q.top();q.pop();
		int cur=p.se;
		ll val=p.fi;
		if(cur==x&&val)
		{
			plld(val);
			return;
		}
//		cout<<cur<<' '<<val<<endl;
		for(int i=head[cur];i;i=a[i].nex)
		{
			int to=a[i].to;
//			cout<<to<<' '<<a[i].val<<' '<<d[to]<<endl;
			if(val+a[i].val<d[to])
			{
				d[to]=val+a[i].val;
				q.push(mk(d[to],to));
//				if(to==x)ju=1;
			}
		}
	}
	puts("-1");
}
void solve()
{
	sdd(n,m);
	rep(i,1,m)
	{
		int u,v;
		ll w;
		sdd(u,v);
		slld(w);
		add(u,v,w);
	}
	rep(i,1,n)
	{
		memset(d,INF,sizeof d);
		bfs(i);
	}
}
int main()
{
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int T=1;
//    sd(T);
    while(T--)solve();
}


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

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

int main () {
    int n, m; cin >> n >> m;
    int x, y, z;
    vector<vector<pair<int, int>>> cs(n+1);
    for (int i = 0; i < m; ++i){
        cin >> x >> y >> z;
        cs[x-1].emplace_back(y, z);
    }
    vector<ll> dp(1 << n);
    dp[0] = 1;
    queue<int> q;
    unordered_set<int> hash;
    q.push(0);
    int pos = 0;
    while (!q.empty()) {
        int size = q.size();
        while (size--) {
            int state = q.front(); q.pop();
            for (int i = 0; i < n; ++i) {
                int num = (1 << i);
                if (state & num) continue;
                int newState = state | num;
                bool flag = true;
                for (auto &it : cs[pos]) {
                    y = it.first, z = it.second;
                    int mask = (1 << y) - 1;
                    if (__builtin_popcount(newState & mask) > z) {
                        flag = false; break;
                    }
                }
                if (flag) dp[newState] += dp[state];
                // cout << state << ' ' << newState << ' ' << dp[newState] << endl;
                if (!hash.count(newState))
                    q.push(newState), hash.insert(newState);
            }
        }
        // cout << pos <<endl;
        pos++;
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int>
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size()
#define PI 3.14159265358979323846

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

 const int N=3e5+10;

 const int INF=1e18;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};

int po(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res%mod * a%mod) % mod;
		a =(a%mod*a%mod) % mod;
		b >>= 1;
	}
	 return res;
  }

int gcdExtended(int a,int b,int* x,int* y) {
	 if(a==0) {
			  *x=0,*y=1;
			  return  b;
			}
		int x1,y1;
		int g=gcdExtended(b%a,a,&x1,&y1);
		*x=y1-(b/a)*x1;
		*y=x1;
		return g;
}

int modInverse(int a,int m) {
	  int x,y;
	  int g=gcdExtended(a,m,&x,&y);
	  int res=(x%m+m)%m;
	  return res;
	}

void solve() {
	int n,s,k;
	cin>>n>>s>>k;
	int g=__gcd(n,k);
	int lt=n-s;
	if((lt%g)!=0) {
		   cout<<-1<<endl;
		   return;
		}
		n/=g;
		k/=g;
		lt/=g;
		int yo=modInverse(k,n);
	 int ans=((lt)*yo)%n;
	 cout<<ans<<endl;
}

int32_t main() {
	cool;
	int t=1;
	//~ freopen("input.txt","r",stdin);
	//~ freopen("output.txt","w",stdout);

	cin>>t;
	while(t--)
	  solve();

  return 0;
}


/*     Jai Shree Ganesh
       Jai Mata Di
       Jai Shree Ram
       Jai Shree Krishna
       Har Har Mahadev
       Jai Bajrangbali
       */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
long int INF = 1000000005;
#define lab(i,a,b) for(i=a;i<=b;i++)
#define bal(i,a,b) for(i=b;i>=a;i--)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define po pop_back
#define se(v) v.begin(), v.end()
#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tc ll t;cin>>t;while(t--)
#define fceil(a,b) ceil((ld)a/(ld)b)
#define dis(v) for(auto it:v)cout<<it<<" "
#define yep cout<<"YES\n"
#define nope cout<<"NO\n"
bool isPrime(ll n){if(n <= 1)return false;if(n <= 3)return true;if(n%2==0||n%3==0)return false;for(ll i=5;i*i<= n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
bool cmp(pll &a, pll &b){ if(a.ss == b.ss)return a.ff < b.ff;return a.ss < b.ss;}
int main()
{
    fst

      ll n,i,f=0,j,x,y,z;cin>>x>>y;
      n=y-x;
      while(n>1)
      {
          z=y/n;z--;
          f=z*n;
          if(f>=x)break;
          n--;
      }
      cout<<n;
    return 0;
}

#include <bits/stdc++.h>
//#define rep(i,a,n) for (int i=a;i<n;i++)
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define rrep(i,a,n) for (int i=n-1;i>=a;i--)
#define ALL(x) x.begin(),x.end()

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pause "read -p 'Press Enter to continue...' var"

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
/*
テスト通りますように
　　●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

const ll INF = numeric_limits<ll>::max()/4;
const ll MAX = 1000'000'000;
const int MOD = 998244353;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll para[3005][5];
ll n;

ll mask(ll i, ll x){
  ll res = 0;
  rep(j,5){
    if(para[i][j] >= x) res += 1 << j;
  }
  return res;
}

bool check(ll x){
  int msk[1 << 5] = {0};
  rep(i,n){
    msk[mask(i,x)]++;
  }
  rep(i,1<<5){
    rep(j,1<<5){
      rep(k,1<<5){
        if((i | j | k) == ((1<<5) - 1) && msk[i] > 0 && msk[j] > 0 && msk[k] > 0 && msk[i] + msk[j] + msk[k] >= 3){
          return true;
        }
      }
    }
  }
  return false;
}

int main(){
  cin >> n;
  rep(i,n){
    rep(j,5){
      cin >> para[i][j];
    }
  }
  ll right = INF;
  ll left = 0;
  while((left + 1) != right){
    ll md = (right + left) / 2;
    if(check(md)) left = md;
    else right = md;
  }
  cout << left;
  return 0;
}


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

#define ll long long
#define ld long double
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define precision cout << fixed << setprecision(15);

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t time_p = clock();

void ktj() {
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre() {}

const int N = 2e5 + 5;
int a[N], b[N], order[N];
int bit[N];

void update(int idx, int val){
  for(; idx <= N; idx += (idx & (-idx))){
    bit[idx] += val;
  }
}

int query(int idx){
  int sum = 0;
  for(; idx > 0; idx -= (idx & (-idx))){
    sum += bit[idx];
  }
  return sum;
}

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
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(A v) {
  bool f = 1; string r = "{";
  for (const auto &x : v) {
    if (!f)r += ", "; f = 0; r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...);
}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void solve() {
  int h, w, m, i, j, k;
  cin >> h >> w >> m;

  for (i = 1; i <= h; i++)
    a[i] = w;
  for (i = 1; i <= w; i++)
    b[i] = h;

  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a[x] = min(a[x], y - 1);
    b[y] = min(b[y], x - 1);
  }

  long long ans = 0;

  for (i = 1; i <= b[1]; i++) {
    ans += a[i];
  }

  for (i = 1; i <= a[1]; i++) {
    order[i] = i;
  }

  sort(order + 1, order + a[1] + 1, [&](int x, int y) {
    return b[x] < b[y];
  });

  order[0] = 0;
  b[0] = 0;

  for (i = 1; i <= a[1]; i++) {
    for (j = b[order[i - 1]] + 1; j <= b[order[i]] and j <= b[1]; j++) {
      update(a[j], 1);
    }
    ans += b[order[i]] - (query(N) - query(order[i] - 1));
  }

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

#define GOOGLE 0
#define MULTIPLE_TC 0

int32_t main() {

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

  pre();

  int t = 1, T;

  if (MULTIPLE_TC)
    cin >> t;

  for (T = 1; T <= t; T++) {
    if (GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}

#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

int N=50,M=0;
int start_x,start_y;
vector<vector<int>> tile(N,vector<int>(N));
vector<vector<int>> wrote_point(N,vector<int>(N));
vector<int> point;
int start_tile;

vector<int> vari_x={0,0,-1,1},vari_y={-1,1,0,0};

struct date
{
	string route;
	int x;
	int y;
	int now_point;
	set<int> arrived;
	int rate;
	 bool operator<(const date& another) const {
        //メンバ変数であるnum1で比較した結果を
        //この構造体の比較とする
        return now_point < another.now_point;
    }
	 bool operator>(const date& another) const {
        //メンバ変数であるnum1で比較した結果を
        //この構造体の比較とする
        return now_point > another.now_point;
    }
};

int value(int a){
	return a;
}

bool check(int x,int y){
	return (0<=x&&x<N&&0<=y&&y<N);
}

date add(date a,int x,int y){//add_checkを通過していること
	if(x-a.x==1) a.route+="D";
	else if(x-a.x==-1) a.route+="U";
	else if(y-a.y==1) a.route+="R";
	else a.route+="L";
	a.arrived.insert(tile[x][y]);
	a.now_point+=point[tile[x][y]];
	a.x=x;
	a.y=y;
	return a;
}

bool add_check(date &a,int X,int Y){
	if(!check(X,Y)) return false;
	if(a.arrived.count(tile[X][Y])) return false;
	if(abs(a.x-X)+abs(a.y-Y)!=1) return false;
	return true;
}

void solve(){
	int range=30;
	date ans={"",start_x,start_y,point[start_tile],{start_tile},point[start_tile]};
	vector<date> looking={ans};
	while(looking.size()!=0&&clock()<1.9*CLOCKS_PER_SEC){
		vector<date> next_looking;
		ans=looking[0];
		rep(i,min(range,(int)looking.size())){
			rep(j,4){
				int s=looking[i].x+vari_x[j],t=looking[i].y+vari_y[j];
				if(add_check(looking[i],s,t)){
					next_looking.push_back(add(looking[i],s,t));
				}
			}
		}
		if(next_looking.size()==0) break;
		Sore(next_looking);
		looking=next_looking;
	}
	cout<<looking[0].route<<endl;
}

//main関数だよーーー
int main() {
	cin>>start_x>>start_y;
	rep(i,N) rep(j,N) cin>>tile[i][j],chmax(M,tile[i][j]);
	rep(i,N) rep(j,N) cin>>wrote_point[i][j];
	M++;
	point.resize(M);
	rep(i,N) rep(j,N) point[tile[i][j]]+=wrote_point[i][j];
	start_tile=tile[start_x][start_y];
	solve();
}


#include <iostream>
#include <cmath>
using namespace std;
long long int b[100005];
double c[100005];
int main()
{
	int n,a,ma=-100008;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		b[i]=b[i-1]+abs(a);//1
		c[i]=c[i-1]+pow(a,2);//2
		ma=max(ma,abs(a));
	}
	printf("%lld\n",b[n]);
	printf("%.15lf\n",sqrt(c[n]));
	printf("%d",ma);
	return 0;
}

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

int main()
{
    cout<<fixed<<setprecision(15);

    int n;
    cin>>n;
    vector<int>x(n);
    for(int i=0; i<n; i++)
        cin>>x[i];
    long ans1=0;
    for(int i=0; i<n; i++)
        ans1+=abs(x[i]);
    cout<<ans1<<endl;
    double ans2=0;
    for(int i=0; i<n; i++)
        ans2+=((double)abs(x[i])*(double)abs(x[i]));
    cout<<sqrt(ans2)<<endl;
    int ans3=0;
    for(int i=0; i<n; i++)
        ans3 = max(ans3, abs(x[i]));
    cout<<ans3<<endl;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int a[200009];

void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++) cin>>a[i];
	sort(a,a+m);
	int sz=infi;
	int pre=1;
	vector<int> segs;
	for(int i=0;i<m;)
	{
		int j=i;
		while(j<m && a[j]-a[i]==j-i) j++;
		if(pre!=a[i]) sz=min(sz,a[i]-pre),segs.pb(a[i]-pre);
		pre=a[j-1]+1;
		i=j;
	}
	if(pre!=n+1) sz=min(sz,n+1-pre),segs.pb(n+1-pre);
	int ans=0;
	//cout<<sz<<'\n';
	for(auto u:segs) ans+=(u+sz-1)/sz;
	cout<<ans<<'\n';
}

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

#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}

static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=1e9+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
	int getsize(){
		set<int> ma;
		rep(i,table.size())ma.insert(root(i));
		int re=ma.size();
		return re;
	}
};

int main(){
	//cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(16);
	lint n;
	int m;
	in(n,m);
	if(n==m){
		out(0);
		return 0;
	}
	if(m==0){
		out(1);
		return 0;
	}
	vlint a(m);
	in(a);
	a.pb(0);
	a.pb(n+1);
	sort(a);
	vlint b;
	arep(i,1,a.size()){
		if((a[i]-a[i-1])<=1)continue;
		b.pb(a[i]-a[i-1]-1);
	}
	lint ans=b[0];
	rep(i,b.size())ans=min(ans,b[i]);
	lint sum=0;
	rep(i,b.size())sum+=(b[i]+ans-1)/ans;
	out(sum);
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define ull unsigned long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<int, int>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 5e5+9;
constexpr int M = 998244353;
#ifdef int
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;
#else
constexpr int INF = 0x3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcf;
#endif

signed main() {
    fastio;
    int n;
    cin >> n;
    int lcm = 1;
    for (int i = 1; i <= n; i++) {
        lcm = lcm / __gcd(lcm, i) * i;
    }
    cout << lcm+1 << "\n";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<random>
#include<iomanip>
#include<queue>
#include<stack>
#include<assert.h>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 2330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	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;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
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 n, t;
int a[44];
int memo1[1050000], memo2[1050000];
signed main() {
	cin >> n >> t;
	rep(i, n)cin >> a[i];
	rep(i, 1 << (n / 2)) {
		int cnt = 0;
		rep(j, n / 2) {
			if ((i >> j) & 1)cnt += a[j];
		}
		memo1[i] = cnt;
	}
	rep(i, 1 << (n - n / 2)) {
		int cnt = 0;
		rep(j, n - n / 2) {
			if ((i >> j) & 1)cnt += a[j + n / 2];
		}
		memo2[i] = cnt;
	}
	sort(memo1, memo1 + (1 << (n / 2)));
	sort(memo2, memo2 + (1 << (n - n / 2)));
	int ans = 0;
	rep(i, 1 << (n / 2)) {
		int p = upper_bound(memo2, memo2 + (1 << (n - n / 2)), t - memo1[i]) - memo2;
		if (p == 0)ans = ans;
		else ans = max(ans, memo1[i] + memo2[p - 1]);
	}
	cout << ans << endl;
	ggr
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 50;
int n;
ll T, a[N];
vector<ll> v;
ll get(ll x){
    int p = upper_bound(v.begin(), v.end(), x) - v.begin();
    if (p == 0) return 0;
    return v[p-1];
}
int main(void){
    scanf("%d%lld", &n, &T);
    for (int i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
    }
    int m = n / 2, k = n - m;
    for (int i = 0; i < (1<<m); ++i){
        ll s = 0;
        for (int j = 0; j < m; ++j){
            if ((i >> j) & 1){
                s += a[j+1];
            }
        }
        v.push_back(s);
    }
    sort(v.begin(), v.end());
//    debug(v.size());
//    debug(m);
//    debug(k);
    ll ans = 0;
    for (int i = 0; i < (1<<k); ++i){
        ll s = 0;
        for (int j = 0; j < k; ++j){
            if ((i >> j) & 1){
                s += a[m+j+1];
            }
        }
        //debug(s);
        if (s <= T) ans = max(ans, s + get(T-s));
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")

#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
const int maxn=505;

//i_am_noob
#define wiwihorz
int n,a[maxn];
vector<int> res;

void op(int x){
    if((x+sz(res))&1){
        bug(x,sz(res));
    }
    if(sz(res)==60604) bug(x);
    assert((x+1+sz(res))&1);
    res.pb(x+1);
    swap(a[x],a[x+1]);
}

void report(){
    print(sz(res));
    for(auto i: res) print0(i);
    cout << "\n";
}

void orzck(){
    res.clear();
    cin >> n;
    rep(n) cin >> a[i];
    rep(n) a[i]--;
    if(n<=3){
        while(!is_sorted(a,a+n)){
            if(sz(res)&1) op(1);
            else op(0);
        }
        report();
        return;
    }
    rep3(i,n-1,4){
        int pos;
        rep1(j,n) if(a[j]==i) pos=j;
        if((pos+sz(res))&1){
            if(sz(res)&1) op(pos==2?3:1);
            else op(pos==1?2:0);
        }
        rep2(j,pos,i) op(j);
    }
    bug(sz(res));
    rep(n) bug(a[i]);
    int pos;
    if(sz(res)&1) op(1);
    rep(4) if(a[i]==3) pos=i;
    if((pos+1+sz(res))&1){
        rep2(i,pos,3) op(i);
    }
    else if(pos<3){
        op(2);
        rep2(i,pos,3) op(i);
    }
    rep(n) bug(a[i]);
    while(!is_sorted(a,a+n)){
        if(sz(res)&1) op(1);
        else op(0);
    }
    assert(is_sorted(a,a+n));
    report();
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    #ifdef i_am_noob
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    freopen("output2.txt","w",stderr);
    #endif
    cout << fixed << setprecision(15);
    int t;
    #ifdef wiwihorz
    cin >> t;
    #else
    t=1;
    #endif
    while(t--) orzck();
    return 0;
}

#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define rush()      int T; while(cin>>T) while(T--)
#define ms(a,b)     memset(a,b,sizeof a)
#define lowbit(x)   ((x)&(-x))
#define inf         0x7f7f7f7fll
#define eps         1e-11
#define sd(a)       scanf("%d",&a)
#define sll(a)      scanf("%lld",&a)
#define sll2(a,b)   scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sdd(a,b)    scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf(a)       scanf("%lf",&a)
//#define sc(a)       scanf("%c\n",&a)
#define ss(a)       scanf("%s",a)
#define pd(a)       printf("%d\n",a)
#define pdd(a,b)    printf("%d %d\n",a,b)
#define pddd(a,b,c) printf("%d %d %d\n",a,b,c)
#define pll(a)      printf("%lld\n",a)
#define pf(a)       printf("%.1lf\n",a)
#define pc(a)       printf("%c",a)
#define ps(a)       printf("%s\n",a)
#define rep(i,a,b)  for(int i=(a);i<=(b);i++)
#define forn(i,a,b,x)  for(int i=(a);i<=(b);i+=(x))
#define per(i,a,b)  for(int i=(b);i>=(a);i--)
#define pb(a)       push_back(a)
#define mp(a,b)     make_pair(a,b)
#define debug(a)    cout<<#a<<" : "<<a<<" "<<" ; "
#define dbg(a)      cout<<#a<<" : "<<a<<endl
#define show(a,b)   cout<<a<<" :\t"<<b<<"\t*"<<endl
#define IOS         ios::sync_with_stdio(0); cin.tie(0)
#define PAUSE       system("pause")
#define all(x)      x.begin(),x.end()
//#define print(a)    cout<<a<<endl;continue;
#define fr          first
#define sc          second
#define ceils(a,b)  ((a-1ll+b)/(b))
#define floors(a,b) floor(double(a)/double(b))
using namespace std;
//inline void swap(int &x,int &y){x^=y^=x^=y;}
typedef long long ll;
//using ui=unsigned int;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int limit=5e5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x<10) putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}

void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}

ll mod=2147483648;
const int N=3e5+5;

    int n, m, _;
    int i, j, k;
    int a[N];
    int pos[N];
    vector<int> ans;

signed main()
{
    //IOS;
    rush(){
        sd(n);
        rep(i, 1, n) sd(a[i]), pos[a[i]] = i;
        int opt = 1;
        rep(i, 1, n){
            if(i == pos[i]) continue;
            if((pos[i] - 1) % 2 != opt){
                if(pos[i] - 2 >= i){
                    ans.pb(pos[i] - 2);
                    int x = pos[i] - 2, y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    opt ^= 1;
                }
                else if(pos[i] == i + 1){
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    //ans.pb(i);
                    opt ^= 1;
                    int x = pos[i], y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    continue;
                }
            }
            for(int j = pos[i] - 1; j >= i; j--){
                ans.pb(j);
                int x = j, y = j + 1;
                swap(pos[a[x]], pos[a[y]]);
                swap(a[x], a[y]);
                opt ^= 1;
            }
        }
        pd(ans.size());
        for(auto it : ans) printf("%d ", it);
        puts("");
        ans.clear();
    }
    //PAUSE;
    return 0;
}


#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

int N;
string S;
string X;

void input(void){
	cin >> N >> S >> X;
}

map<pair<int, int>, int> memo;

bool canTWin(int i, int m){
	if (i == N) return (m == 0);
	if (memo[{i, m}] > 0)
		return memo[{i, m}] == 1;
	char p = X[i];
	int d = (int)(S[i] - '0');
	if (p == 'T'){
		bool ret = canTWin(i + 1, m * 10 % 7) || canTWin(i + 1, (m * 10 + d) % 7);
		memo[{i, m}] = ret ? 1 : 2;
		return ret;
	}
	bool ret = canTWin(i + 1, m * 10 % 7) && canTWin(i + 1, (m * 10 + d) % 7);
	memo[{i, m}] = ret ? 1 : 2;
	return ret;
}

int main(void){
	input();
	cout << (canTWin(0, 0) ? "Takahashi" : "Aoki") << endl;
	return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a,b) memset(a, b, sizeof(a))
#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)
#define forab(i,a,b) for(int i = a; i <= b; i++)
#define forba(i,b,a) for(int i = b; i >= a; i--)
#define each(val, v) for(auto val : v)
#define abs(u) (u >= 0 ? u : -u)

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

const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

int add(int a, int b){
    a += b;

    if( a >= MOD) a -= MOD;

    if(a < 0) a += MOD;

    return a;
}

int mul(int a, int b){
    int ret = (1LL * a * b)%MOD;

    return ret;
}

int pw(int a, int n){
    int ret = 1;

    while(n > 0){
        if(n&1 == 1){
            ret = mul(ret, a);
        }
        a = mul(a,a);
        n = n>> 1;
    }

    return ret;
}

int inv(int a){
    return pw(a,MOD-2);
}

int divide(int a, int b){
    return mul(a, inv(b));
}

void solve(){

    int a,b,c;
    cin >> a >> b >> c;

    int soma_a = mul( a, divide(a+1,2) );
    int soma_b = mul( b, divide(b+1,2) );
    int soma_c = mul( c, divide(c+1,2) );

    int ans = mul( soma_a, mul(soma_b, soma_c) );

    cout << ans << '\n';

}

int main(){

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

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

    return 0;
}


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

#define ll                     long long int
#define ld                     long double
#define ff                     first
#define ss                     second
#define pb                     push_back
#define pii                    pair <ll , ll>
#define vi                     vector <ll>
#define vii                    vector <pair <ll , ll>>
#define mii                    map <ll , ll>
#define mci                    map <char , ll>
#define mcc                    map <char , char>
#define pqb                    priority_queue <ll>
#define pqs                    priority_queue <ll , vi,greater<ll> >
#define setbits(x)             __builtin_popcountll(x)
#define zerobits(x)            __builtin_ctzll(x)
#define inf                    (ll) (9e18)
#define sp(x , y)              fixed << setprecision(y) << x
#define mk(arr , n , type)     type *arr = new type[n];
#define mar(arr , n , type)    type arr[n];
#define w(x)                   ll x; cin >> x; while(x--)
#define rep(i , j , n)         for(ll i = j ; i < n ; i++)
#define f(n)                   for(ll i = 0 ; i < n ; i++)
#define all(p)                 p.begin() , p.end()
#define ub(a , b)              upper_bound(all(a) , b)
#define lb(a , b)              lower_bound(all(a) , b)
#define in(arr , n)            for(ll i = 0 ; i < n ; i++) cin >> arr[i];
#define out(arr , n)           for(ll i = 0 ; i < n ; i++) cout << arr[i] << " "; cout << endl;
#define d(x)                   cerr << #x << " = " << x << endl;
#define len(x)                 x.length();
#define fast_io                ios_base::sync_with_stdio(false); cin.tie(NULL);

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

    mar(arr , n , ll);
    in(arr , n);

    ll ans = 0 , cnt = 0 , index = -1;
    for(ll i = 2 ; i <= 1000 ; i++) {
        cnt = 0;
        for(ll j = 0 ; j < n ; j++) {
            if(arr[j] % i == 0) {
                cnt ++;
            }
        }
        if(cnt >= ans) {
            ans = max(ans , cnt);
            index = i;
        }
    }

    cout << index << endl;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	vector<vector<int64>> aa(nn + 1, vector<int64>(1ll << nn, 0ll));
	for(int64 ii = 0;ii < (1ll << nn);ii++)
	{
		cin >> aa[0][ii];
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		for(int64 jj = 0;jj < 1ll << nn;jj += (2ll << ii))
		{
			int64 tmp = max(aa[ii][jj], aa[ii][jj + (1ll << ii)]);
			aa[ii + 1][jj] = tmp;
		}
		//cout << aa[ii + 1][0] << ' ';
		for(int64 jj = 1;jj < 1ll << nn;jj++)
		{
			if(aa[ii + 1][jj] == 0)
			{
				aa[ii + 1][jj] = aa[ii + 1][jj - 1];
			}
			//cout << aa[ii + 1][jj] << ' ';
		}
		//cout << endl;
	}
	int64 memo = aa[nn][0];
	if(aa[nn - 1][0] != memo)
	{
		memo = aa[nn - 1][0];
	}
	else
	{
		memo = aa[nn - 1][(1ll << nn) - 1];
	}
	for(int64 ii = 0;ii < 1ll << nn;ii++)
	{
		if(aa[0][ii] == memo)
		{
			cout << ii + 1 << endl;
			return 0;
		}
	}
	return 0;
}


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

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

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

const double eps = 1e-10;

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

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

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

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

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

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

	int64 N;
	cin >> N;
	auto S = make_v<int64>(2, N);
	REP(k, 2) REP(i, N) cin >> S[k][i];

	priority_queue<int64> pq[2];
	int64 cnt[2] = {};
	int64 res = 0;
	REP(i, N) {
	  res += max(S[0][i], S[1][i]);
	  if (S[0][i] > S[1][i]) {
      cnt[i%2]++;
      pq[i%2].push(S[1][i] - S[0][i]);
	  } else {
	    pq[1 ^ (i % 2)].push(S[0][i] - S[1][i]);
	  }
	}
	while (cnt[0] != cnt[1]) {
	  if (cnt[1] < cnt[0]) {
	    res += pq[0].top(); pq[0].pop();
	    cnt[1]++;
	  } else {
      res += pq[1].top(); pq[1].pop();
      cnt[0]++;
	  }
	}
	cout << res << endl;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ll  N,sum=0;
  cin>>N;
  vector<ll> A(N),B(N);
  for(ll &i:A)cin>>i,sum+=i;
  for(ll &j:B)cin>>j;
  ll M=N/2;
  vector<ll> C(M),D(M);
  for(ll i=0;i<M;i++)C[i]=B[i*2]-A[i*2];
  for(ll i=0;i<M;i++)D[i]=B[i*2+1]-A[i*2+1];
  sort(C.rbegin(),C.rend());
  sort(D.rbegin(),D.rend());
  ll ans=sum;
  for(ll i=0;i<M;i++){
    sum+=C[i]+D[i];
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
    template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
    int cnt = sizeof...(T);
    (std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 100025, INF = 1e18, MOD = 998244353, K = 19, inf = 1e7;
constexpr inline ll cdiv(ll x, ll m) { return x/m + (x%m ? (x<0) ^ (m>0) : 0); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

int dp[3001][3001][2];
int vis[3001][3001][2];
int DP(int n, int k, bool first) {
    if(k == 0 || n == 0) return n == 0 && k == 0;
    if(k > n) return 0;
    if(vis[n][k][first]) return dp[n][k][first];
    vis[n][k][first] = true;
    int &ans = dp[n][k][first];
    return ans = (DP(n-1, k-1, false) + DP(n, k*2, true)) % MOD;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    cout << DP(n, k, true) << '\n';
}

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<lint,lint> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
signed main(){
  int n,m;cin>>n>>m;
  map<P,int> st;
  rep(i,m){
    lint a,b;cin>>a>>b;
    st[{b,a}]=3;
    if(st.find({b-1,a-1})==st.end())st[{b-1,a-1}]=0;
    if(st.find({b,a-1})==st.end())st[{b,a-1}]=0;
    if(st.find({b+1,a-1})==st.end())st[{b+1,a-1}]=0;
    st[{b-1,a-1}]=max(st[{b-1,a-1}],1);
    st[{b,a-1}]=max(st[{b,a-1}],2);
    st[{b+1,a-1}]=max(st[{b+1,a-1}],1);
  }
  vector<int> status;
  int cur=0;
  st[{n,0}]=3;
  vector<vector<int>> edge(st.size());
  int start=-1;
  for(auto& val:st){
    status.push_back(val.second);
    val.second=cur++;
  }
  for(auto& [p,no]:st){
    auto& [y,x]=p;
    if(y==n&&x==0)start=no;
    auto it=st.find({y+1,x+1});
    if(it!=st.end()){
      if(status[it->second]==3)edge[no].push_back(it->second);
    }
    it=st.find({y-1,x+1});
    if(it!=st.end()){
      if(status[it->second]==3)edge[no].push_back(it->second);
    }
    it=st.upper_bound({y,x});
    if(it==st.end())continue;
    if(it->first.first==y&&it->first.second>x){
      if(status[it->second]<=2)edge[no].push_back(it->second);
    }
  }
  queue<int> que;
  que.push(start);
  vector<int> ok(edge.size(),0);
  ok[start]=1;
  while(!que.empty()){
    int buf=que.front();que.pop();
    for(auto& e:edge[buf]){
      if(ok[e]==0){
        ok[e]=1;
        que.push(e);
      }
    }
  }
  set<int> res;
  for(auto& [p,no]:st){
    if(ok[no]&&status[no]%2==1){
      auto it=st.upper_bound(p);
      if(it==st.end()){
        res.insert(p.first);
      }
      else if(it->first.first!=p.first){
        res.insert(p.first);
      }
    }
  }
  cout<<res.size()<<"\n";
  return 0;
}


#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG //checks for container overflows
#pragma GCC optimize "trapv" //to chcek for int overflow
#pragma -Wduplicated-cond //dupilcate conditions
#endif
#include "bits/stdc++.h"
using namespace std;
using namespace chrono;
typedef unsigned long long int ull;
typedef long long ll;
#define F first
// #define S second
#define nl '\n'
#define de1(x) cerr << #x << ":" << x <<nl;
#define de2(x,y) cerr << #x << ":" << x << " " << #y << ":" << y << nl
#define de3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define de4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define all(x) x.begin(), x.end()
#define rt return 0;
#define vvi vector<vector<int>>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define um unordered_map<int,int>
const float pi = 3.14;
const ull mod = 1ll << 32;

void solve()
{
  stack<char> s;

  int n;
  string str;
  cin >> n >> str;
  if (n <= 3 && str != "fox")
  {
    cout << n;
    return;
  }

  register int cnt = 0, i;

  for (i = 0; i < n; i++)
  {
    if (str[i] == 'x' && s.size() && s.top() == 'o')
    {
      s.pop();
      if (s.size() && s.top() == 'f')
      {
        cnt += 3;
        s.pop();
        continue;
      }
      s.push('o');
      s.push('x');
    }

    else
      s.push(str[i]);
  }

  cout << n - cnt;

}

int main() {

#ifndef ONLINE_JUDGE
  auto start = high_resolution_clock::now();
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast

  solve();

#ifndef ONLINE_JUDGE
  auto end = high_resolution_clock::now();
  double time_taken = duration_cast<nanoseconds>(end - start).count();
  time_taken *= 1e-9;
  cerr << "Time : " << fixed << time_taken << setprecision(9) << nl;
#endif
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
  return x;
  #undef nc
}

const int maxn = 1e6 + 10;
char A[maxn], B[maxn];
int n, m, nxt[maxn], st[maxn], pos[maxn];

int main() {
  scanf("%d%s",&n, A + 1);
  B[1]='f',B[2]='o',B[m=3]='x';
  for (int i = 2, j = 0; i <= m; i++) {
    while (j && B[i] != B[j + 1]) j = nxt[j];
    nxt[i] = B[i] == B[j + 1] ? ++j : j;
  }
  int top = 0;
  for (int i = 1, j = 0; i <= n; i++) {
    while (j && A[i] != B[j + 1]) j = nxt[j];
    j += A[i] == B[j + 1];
    pos[i] = j, st[++top] = i;
    if (j == m) {
      top -= m, j = pos[st[top]];
    }
  }
  printf("%d\n",top);
//  rep(i, 1, top) {
//    putchar(A[st[i]]);
//  }
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define RI(x) scanf("%d",&x)
#define RII(x,y) scanf("%d%d",&x,&y)
int cnt[10];
char s[200005];

int main(){
	ios::sync_with_stdio(false);
	cin>>s+1;
	int len=strlen(s+1);
	for (int i=1;i<=len;++i) cnt[s[i]-'0']++;
	if (len>=3){
		for (int x=0;x<1000;++x){
			if (x%8) continue;
			int a=x%10,b=(x/10)%10,c=x/100;
			--cnt[a];--cnt[b];--cnt[c];
			if (cnt[a]>=0&&cnt[b]>=0&&cnt[c]>=0){
				cout<<"Yes"<<endl;return 0;
			}
			++cnt[a];++cnt[b];++cnt[c];
		}
		cout<<"No";
	}
	else{
		if (len==1){
			if ((s[1]-'0')%8==0) cout<<"Yes";
			else cout<<"No";
		}
		else{
			if (((s[1]-'0')*10+s[2]-'0')%8==0) cout<<"Yes";
			else if (((s[2]-'0')*10+s[1]-'0')%8==0) cout<<"Yes";
			else cout<<"No";
		}
	}

	return 0;
}

#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define MOD 998244353
#define MAXN 200005

char c[200005];
int cnt[15]={0};
int len=0;

int main()
{
	scanf("%s",c);
	int len=strlen(c);
	for(int i=0;i<len;i++) cnt[c[i]-'0']++;
	if(len==1&&c[0]=='8') return puts("Yes"),0;
	for(int i=2;i<=12;i++)
	{
		if(i==11)
		{
			if(cnt[8]>=2)
			{
				cnt[8]-=2;
				if(len==2) return puts("Yes"),0;
				for(int j=2;j<=8;j+=2)
				{
					if(cnt[j])
					{
						puts("Yes");
						return 0;
					}
				}
				cnt[8]+=2;
			}
			continue;
		}
		if(i==5||i==10) continue;
		int op=i*8;
		int q=op/10,w=op%10;
		if(cnt[q]&&cnt[w])
		{
			if(len==2) return puts("Yes"),0;
			cnt[q]--,cnt[w]--;
			for(int j=2;j<=8;j+=2)
			{
				if(cnt[j])
				{
					puts("Yes");
					return 0;
				}
			}
			cnt[q]++,cnt[w]++;
		}
	}
	if(len<3) return puts("No"),0;
	for(int i=13;i<125;i++)
	{
		int op=i*8;
		int a=op/100,b=(op/10)%10,s=op%10;
		if(!a||!b||!c) continue;
		if(a==b&&b==s)
		{
			if(cnt[a]>=3) return puts("Yes"),0;
		}
		else if(a==b)
		{
			if(cnt[a]>=2&&cnt[s]) return puts("Yes"),0;
		}
		else if(b==s)
		{
			if(cnt[b]>=2&&cnt[a]) return puts("Yes"),0;
		}
		else if(a==s)
		{
			if(cnt[a]>=2&&cnt[b]) return puts("Yes"),0;
		}
		else if(cnt[a]&&cnt[b]&&cnt[s]) return puts("Yes"),0;
	}
	return puts("No"),0;
}


#include<bits/stdc++.h>
#define MAX 1000000007
#define MOD 998244353
#define ll long long int
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
#define in insert
#define cl clear
#define ld long double
#define mp make_pair
#define ii pair<int,int>
const ll inf = 10e16+7;
using namespace std;
typedef vector<vector<int>> vvi;

void print(int arr[], int n){
    fo(i,0,n){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}

int main(){

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

    // int t;
    // cin>>t;
    // while(t--){

    // }

    int n;
    cin>>n;

    ll ans = 0;
    for(int i=1;i<=n;i++){
        if(n-i>=1)ans++;
    }

    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  cout << N-1 << endl;
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll modpow(ll n, ll r, ll mod) {
    ll ret = 1;
    ll p = n % mod;
    while (r > 0) {
        if (r & 1)
            ret = (ret * p) % mod;
        p = (p * p) % mod;
        r >>= 1LL;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll ans = modpow(10, N, M * M) / M;
    cout << ans << endl;

    return 0;
}

#define LOCAL

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

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define uniq(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)

using pii = pair<int, int>;
using ll = long long;
const long double PI = acos(-1.0);

ll MOD;

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

void solve() {
	ll n, m; cin >> n >> m;
	MOD = m*m;
	ll lft=bin_pow(10,n);
	lft /= m;
	cout << lft << "\n";
}

int main() {
	IOS;
	int t; t=1;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

// union-find
struct union_find {
    vector<int> dat;

    union_find(int size) {dat.resize(size, -1);}

    int find(int x) {
        if (dat[x] < 0) {return x;}
        return dat[x] = find(dat[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) {return false;}
        if (dat[x] > dat[y]) swap(x, y);
        dat[x] += dat[y];
        dat[y] = x;
        return true;
    }

    int size(int x) {return -dat[find(x)];}

    vvint groups() {
        int n = dat.size();
        vector<vector<int>> res(n);
        for (int i = 0; i < n; i++) {
            res[find(i)].push_back(i);
        }
        res.erase(
            remove_if(res.begin(), res.end(),
                [](const vint &v) {return v.empty();}),
            res.end());
        return res;
    }
};

int main() {
    int n; cin >> n;
    vint x(n), y(n);
    rep(i,n) cin >> x[i] >> y[i];
    double ok = 0, ng = 200;
    while (ng - ok > 1e-10) {
        double mid = (ok + ng) / 2;
        union_find uf(n + 2);
        rep(i,n)rep(j,i) {
            double dis = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
            if (dis < 2 * mid) {
                uf.unite(i, j);
            }
        }
        rep(i,n) {
            if (y[i] - (-100) < 2 * mid) uf.unite(i, n);
            if (100 - y[i] < 2 * mid) uf.unite(i, n + 1);
        }
        if (uf.find(n) == uf.find(n + 1)) ng = mid;
        else ok = mid;
    }
    printf("%.10f\n", ok);
}

#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int N_MAX=11000;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int main()
{
  int n,i,j,k=0;
  PP b[N_MAX]; // 枝データ
  int c[N_MAX]; // 頂点iの属する集合番号
  int nc[N_MAX]; // 集合jの要素数
  int pc[N_MAX]; // 集合jの先頭の要素番号
  int pi[N_MAX]; // 頂点iと同じ集合の要素へのポインタ
  int i1,i2,s1,s2,p,pt;
  int x[N_MAX],y[N_MAX];
  cin >> n;
  for(i=1;i<=n;i++)
    cin >> x[i] >> y[i];
  for(i=1;i<=n+2;i++){
    c[i]=i;
    nc[i]=1;
    pc[i]=i;
    pi[i]=0;
  }
  for(i=1;i<=n;i++){
    for(j=i+1;j<=n;j++,k++){
      b[k].first=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
      b[k].second.first=i;
      b[k].second.second=j;
    }
    b[k].first=(y[i]-100)*(y[i]-100);
    b[k].second.first=i;
    b[k].second.second=n+1;
    k++;
    b[k].first=(y[i]+100)*(y[i]+100);
    b[k].second.first=i;
    b[k].second.second=n+2;
    k++;
  }
  b[k].first=200*200;
  b[k].second.first=n+1;
  b[k].second.second=n+2;
  k++;
  sort(b,b+k);
  for(i=0;i<k;i++){
    i1=b[i].second.first;
    i2=b[i].second.second;
    if(c[i1]!=c[i2]){
// 集合のマージここから
      s1=c[i1]; s2=c[i2];
      if(nc[s1]<nc[s2]){// 小さい方を潰す【重要】
        s1=c[i2]; s2=c[i1];
      }
      // res[i-1]=res[i]-nc[s1]*nc[s2];
      pt=pc[s1];
      p=pc[s2];
      pc[s1]=p;
      nc[s1]+=nc[s2];
      pc[s2]=0;
      nc[s2]=0;
      while(true){
        c[p]=s1;
        if(pi[p]==0) break;
        p=pi[p];
      }
      pi[p]=pt;
// 集合のマージここまで
    }
    if(c[n+1]==c[n+2]){
      cout << setprecision(8) << sqrt(b[i].first)/2 << endl;
      return 0;
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, rs = 0;
map<int, int> M;

void add(int key, int value) {
    M[key] = __gcd(M[key], value);
}

int main() {
#ifdef ACM
    freopen("input", "r", stdin);
#endif
    cin >> n;
    int x, minV = 2e9;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        minV = min(minV, x);
        for (int j = 1; j * j <= x; j++)
            if (x % j == 0) {
                add(j, x);
                if (x / j != j)
                    add(x / j, x);
            }
    }
    for (auto tmp:M) {
        if (tmp.first > minV)
            break;
        rs += (tmp.first == tmp.second);
    }
    cout << rs;
}

#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef WA_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll  = long long;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5+10;
int main() {
#ifndef WA_DEBUG
    ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
    int n;
    cin>>n;
    vector<int> a(n+1);
    int Min=inf;
    rep(i,1,n) {
        cin>>a[i];
        Min=min(a[i],Min);
    }
    set<int> s;
    rep(i,1,n) {
        rep(j,1,maxn) {
            if(j*j>a[i]) break;
            if(a[i]%j==0) {
                s.insert(j);
                if(j*j!=a[i]) s.insert(a[i]/j);
            }
        }
    }
    int cnt=0;
    for(int x:s) {
        if(x>Min) continue;
        int ans=-1;
        rep(i,1,n) {
            if(ans==1) break;
            if(a[i]%x==0) {
                if(ans==-1) ans=a[i]/x;
                else ans=__gcd(ans,a[i]/x);
            }
        }
        if(ans==1&&x<=Min) cnt++;
    }
    cout<<cnt<<'\n';
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,w;
    cin>>n>>w;
    cout<<n/w;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;

    int mn = min(a, b), mx = max(a, b);

    vector<int> ans;
    ll s1 = 0, s2 = 0;
    for(int i = 0; i < mx; i++) {
        ans.push_back(i + 1);
        s1 += i + 1;
    }
    for(int i = 0; i < mn; i++) {
        ans.push_back(-(i + 1));
        s2 += i + 1;
    }
    ll d = s1 - s2;
    ans[a+b-1] -= d;

    if(mn==a) {
        for(int i = 0; i < a + b; i++) ans[i] = ans[i] * -1;
    }

    for(int x : ans) cout << x << " ";

    return 0;
}