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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

int dp[101][1001001], sum[101][101][10101];

void Main(){
    int N,K,M; cin >> N >> K >> M;
    VI s(N,0); REP(i,N) s[i] = s[max(0,i-1)] + (i+1)*K;
    dp[0][0] = 1; REP(i,N*N) sum[0][0][i+1] = 1;
    REP(i,N){
        REP(j,s[i]+1){
            int mod = j%(i+1), div = j/(i+1);
            (dp[i+1][j] += sum[i][mod][div+1] - sum[i][mod][max(0,div-K)]) %= M;
            if(dp[i+1][j] < 0) dp[i+1][j] += M;
            mod = j%(i+2); div = j/(i+2);
            sum[i+1][mod][div+1] += dp[i+1][j];
            if(sum[i+1][mod][div+1]>=M) sum[i+1][mod][div+1] -= M;
        }
        REP(j,i+2)REP(k,N*N){
            sum[i+1][j][k+1] += sum[i+1][j][k];
            if(sum[i+1][j][k+1]>=M) sum[i+1][j][k+1] -= M;
        }
    }

    FOR(x,1,N+1){
        ll ans = 0;
        REP(j,N*N*K+1){
            (ans += 1LL*dp[N-x][j]*dp[x-1][j]%M*(K+1)) %= M;
        }
        ans--;
        if(ans<0) ans += M;
        cout << ans << en;
    }
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    while(t--) Main();
    return 0;
}

/*
             author:ryo3ihara
            　　　　　　　”継続は力なり、雨だれ石を穿つ”
            　　　　　　　　　　”slow but steady wins the race”
*/

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

//#include<atcoder/all>
//using namespace atcoder;

/*
// 多倍長テンプレ
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/

using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pld = pair<ll, ld>;
using ppiii =  pair<pii, int>;
using ppiill = pair<pii, ll>;
using ppllll = pair<pll, ll>;
using pplii = pair<pli, int>;
using mii = map<int, int>;
using dll = deque<ll>;
using qll = queue<ll>;
using pqll = priority_queue<ll>;
using pqrll = priority_queue<ll, vector<ll>, greater<ll>>;
using vint = vector<int>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvint = vector<vector<int>>;
using vvpll = vector<vector<pll>>;

//マクロ
//forループ
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000; //10^12:∞
const ll MAXR = 100000; //10^5:配列の最大のrange

//最大化問題最小化問題
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//高速冪乗化　modの時は一部入れ替える
ll power(ll x, ll y) {
    if(y == 1) {
        return x;
    }
    ll ans;
    if(y % 2 == 1) {
        ll r = power(x,(y-1)/2);
        //ans = r * r % MOD;
        //ans = ans * x % MOD;
        ans = x * r * r;
    }
    else {
        ll r = power(x,y/2);
        //ans = r * r % MOD;
        ans = r * r;
    }
    return ans;
}
/*
Bint powerb(Bint x, Bint y) {
    if(y == 1) {
        return x;
    }
    Bint ans;
    if(y % 2 == 1) {
        Bint r = powerb(x,(y-1)/2);
        //ans = r * r % MOD;
        //ans = ans * x % MOD;
        ans = x * r * r;
    }
    else {
        Bint r = powerb(x,y/2);
        //ans = r * r % MOD;
        ans = r * r;
    }
    return ans;
}
*/

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N,M;
    cin >> N >> M;

    vll H(N),W(M);
    REP(i,N) cin >> H[i];
    REP(i,M) cin >> W[i];

    sort(ALL(H));
    sort(ALL(W));

    vll left((N+1)/2);
    vll right((N+1)/2);

    for(int i =0;i+1<N;i+=2){
        left[i/2+1] = left[i/2] + H[i+1] - H[i];
    }
    for(int i =N-2;i>0;i-=2){
        right[i/2] = right[i/2+1] + H[i+1]-H[i];
    }

    vll dist(N);
    ll ans = INF;
    REP(i,M){
        ll x = lower_bound(H.begin(),H.end(),W[i])-H.begin();
        if(x & 1) x ^= 1;
        chmin(ans,left[x/2] + right[x/2] + abs(H[x] - W[i]));
    }

    //本文

    //出力
    cout << ans << endl;
    //cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

VI C;
VVI g;
VI ans;

void dfs(int v, int p, multiset<int>& se){
    if(se.find(C[v]) == se.end()){
        ans.eb(v);
    }
    for(int u : g[v]){
        if(u == p) continue;

        se.insert(C[v]);
        dfs(u,v,se);
        se.erase(se.find(C[v]));

    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    C.resize(N);
    REP(i,N) cin >> C[i];

    g.resize(N);
    REP(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].eb(b);
        g[b].eb(a);
    }

    multiset<int> se;
    dfs(0,-1, se);
    sort(ans.begin(), ans.end());
    for(int x : ans){
        cout << x + 1 << "\n";
    }

}

#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l,r,x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l,r,x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
typedef __int128 INT;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int a[500005];
bool good[500005];
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string ans="";
	int n;
	cin>>n;
	n*=2;
	for(int i=0; i<n; i++) ans.push_back('#');
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	vi idx(n);
	iota(idx.begin(), idx.end(), 0);
	sort(idx.begin(), idx.end(), [&](int x, int y){
		return a[x] < a[y];
	});
	for(int i=0; i<n/2; i++){
		good[idx[i]]=1;
	}
	stack<int> st;
	for(int i=0; i<n; i++){
		if(st.empty()){
			ans[i]='(';
			st.push(i);
		}
		else{
			int t=st.top();
			if(good[t]==good[i]){
				st.push(i);
			}
			else{
				st.pop();
				ans[t]='(';
				ans[i]=')';
			}
		}
	}
	cout<<ans<<endl;
}


#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 int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend()
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int>
#define vpi           vector<pii>
#define ordered_set   tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

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

void solve() {
	int n;
	cin >> n;
	int x[n], y[n], z[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	auto cal = [&](int i, int j) {
		return abs(x[i]-x[j]) + abs(y[i]-y[j]) + max(0LL, z[j]-z[i]);
	};

	int dp[n][(1<<n)];
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < (1<<n); j++)
			dp[i][j] = inf;
	}
	dp[0][1] = 0;
	for(int j = 3; j < (1<<n); j++) {
		if(!(j&1)) continue;
		for(int i = 0; i < n; i++) {
			if((j>>i)&1) {
				for(int k = 0; k < n; k++) {
					if(i != k)
					dp[i][j] = min(dp[i][j], dp[k][j^(1<<i)] + cal(k, i));
				}
			}
		}
	}
	// cout << dp[0][(1<<n)-1] << endl;
	// cout << dp[1][(1<<n)-1] << endl;
	int ans = inf;
	for(int j = 0; j < n; j++) {
		ans = min(ans, dp[j][(1<<n)-1] + cal(j, 0));
	}
	cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    start = clock();

    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(20);

    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}

/**
 *    author:  longvu
**/
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define FASTIO std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);

#define nax (int) (100001)

const int mod = 1e9 + 7;

int32_t main()
{
    FASTIO

    int n;

    cin >> n;

    string s1, s2;

    cin >> s2;

    s1 = s2.substr(0, n);
    s2 = s2.substr(n, n);

    int q;

    cin >> q;

    while (q--)
    {
        int type, a, b;

        cin >> type >> a >> b;

        if (type == 1)
        {
            a--; b--;
            char c;
            int flag = 0;

            if (a > s1.size() - 1)
            {
                flag = 1;
                a -= s1.size();
                c = s2[a];
            }

            if (b > s1.size() - 1)
            {
                b -= s1.size();
                if (flag)
                {
                    s2[a] = s2[b];
                    s2[b] = c;
                }
                else
                {
                    c = s2[b];
                    s2[b] = s1[a];
                    s1[a] = c;
                }
            }
            else
            {
                c = s1[a];
                s1[a] = s1[b];
                s1[b] = c;
            }
        }
        else
        {
            swap(s1, s2);
        }
    }

    cout << s1 + s2;

    return 0;
}


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

int main() {
  string s;cin>>s;
  int i;
  int an[10];rep(i,10)an[i]=0;
  for (auto c: s) {
    i = c - '0';
    if (an[i]<3) an[i]++;
  }
  vi bn;
  rep(i, 10) {
    rep(j, an[i]) bn.push_back(i);
  }

  int n = bn.size();
  if (n == 1) {
      if (bn[0] % 8 == 0) {
        cout<<"Yes"<<endl;
        return 0;
      }
  } else if (n == 2) {
      if ((bn[0]*10 + bn[1]) % 8 == 0 or (bn[1]*10 + bn[0]) % 8 == 0) {
        cout<<"Yes"<<endl;
        return 0;
      }
  } else {
    rep(i,n) rep(j,n) rep(k,n) {
      if (i==j or j==k or k==i) continue;
      if ((bn[i]*100 + bn[j]*10 + bn[k]) % 8 == 0) {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }

  cout<<"No"<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  string k;
  cin >> k;
  if(k.length() == 1){
    if(k[0] == '8'){
      cout << "Yes";
      return 0;
    }
    cout << "No";
    return 0;
  }
  if(k.length() == 2){
    if((k[0] * 10 + k[1]) % 8 == 0 || (k[1] * 10 + k[0]) % 8 == 0){
      cout << "Yes";
      return 0;
    }
    cout << "No";
    return 0;
  }
  int bucket[10] = {0};
  for(int i = 0;i < k.length();i++){
    bucket[k[i] - '0']++;
  }
  for(int i = 112;i <= 1000;i += 8){
    if(i % 10 == 0 || i / 10 % 10 == 0){
      continue;
    }
    int ge = i % 10;
    int shi = i / 10 % 10;
    int bai = i / 100;
    int b1[10] = {0};
    b1[ge]++;
    b1[shi]++;
    b1[bai]++;
    bool ok = true;
    for(int i = 1;i <= 9;i++){
      if(b1[i] > bucket[i]){
        ok = false;
        break;
      }
    }
    if(ok){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}


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

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

  vector<vector<char>> tree(N, vector<char>(M));
  int a, b;

  //for (int i = 0; i < M; i++){

  int seiki;

  if (N % 100 == 0)
    seiki = N / 100;
  else
    seiki = N / 100 + 1;

  cout << seiki << endl;

}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cctype>
#include <limits> // INT_MAX ...

using namespace std;

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

int main() {
  int y;
  cin >> y;
  cout << (y + 99) / 100 << '\n';

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> r(n);
  r[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 2 * i; j <= n; j += i) {
      if (r[i - 1] + 1 > r[j - 1]) r[j - 1] = r[i - 1] + 1;
    }
  }
  for (auto e : r) cout << e << ' ';
  cout << endl;
}

#include <bits/stdc++.h>

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

using namespace std;

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

	int n; cin>>n;
	cout << 1 << " \n"[n == 1];
	int num = 1;
	int dex = 2;
	int ind = 2;
	int i = 0;
	while (num < n)
	{
		if (i == dex)
		{
			i = 0;
			dex *= 2;
			ind++;
		}
		cout << ind << " \n"[num == n - 1];
		i++;
		num++;
	}
	cout << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
typedef vector<int> vi;
typedef vector<string> vs;
const int mod = 1000000007;
const int inf = 1061109567;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
signed main()
#define N_MAX 200200
{
    int n;
    cin >> n;
    vi p(n);
    vector<bool> check(N_MAX, false);
    set <int> s;
    int x;
    int ans = 0;
    rep(i,n){
        cin >> x;
        if(check[x]) { cout << ans << endl; continue;}
        check[x] = true;
        while(1){
            if(!check[ans]) { cout << ans << endl; break;}
            ans++;
        }

    }

    return 0;
}

#define _GLIBCXX_DEBUG//これが最後の手段だ!
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

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

typedef long long ll;

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

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

  int n,m = 0;
  cin >> n;
  vector<int> p(n),a(200002),b(200002);

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

  for (int i = 0; i < n; i++){
    cin >> p[i];
    b[p[i]] = 1;
    while(b[m] == 1) ++m;
    cout << m << '\n';
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pqueue priority_queue
#define umap unordered_map
#define uset unordered_set
#define bit(s, i) ((1 << i) & s ? 1 : 0)
#define bits(x) __builtin_popcount((x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x) / gcd(x, y) * (y))
#define inf 4557430888798830399LL
#define mst(dp, val) memset(dp, val, sizeof(dp))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repd(i, a, b, d) for (int i = a; i <= b; i += d)
#define rep_(i, a, b) for (int i = a; i >= b; --i)
#define repd_(i, a, b) for (int i = a; i >= b; i -= d)
#define mxm(a, b) a = max(a, b)
#define mnm(a, b) a = min(a, b)
#define Max *max_element
#define Min *min_element
#define pb push_back
#define X first
#define Y second
#define L size()
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << "=" << x << endl
#define readArr(a, n) for (int i = 1; i <= n; i++) cin >> a[i];
#define printArr(a, n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
#define print(e) cout << (e) << endl
const int mod = 1e9 + 7;
#define Add(x, val) x = (x + (val)) % mod
// #define MULTI_CASES
// #define PRE

const int N = 2e5 + 5;
int a[N];

void solve() {
    int n; cin >> n;
    readArr(a, n);
    int mx = 0;
    int preSum = 0;
    int h = 0;
    rep(k, 1, n) {
        mx = mxm(mx, a[k]);
        preSum += a[k];
        h += preSum;
        print(k*mx + h);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    #ifdef PRE
        pre();
    #endif
    #ifdef MULTI_CASES
        int t; cin >> t;
        while (t--) solve();
    #else
        solve();
    #endif
    return 0;
}

#include<iostream>
using namespace std;
long n,a[200020],rui[200020];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],rui[i]=i==0?a[i]:a[i]+rui[i-1];
	long ans=0,M=0;
	for(int i=0;i<n;i++)M=max(M,a[i]),ans+=rui[i],cout<<(ans+M*(i+1))<<'\n';
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printvm(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i].val() << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvvm(vector<vector<T>>& v) {for (auto u : v) printvm(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    ll a;
    char c;
    vl r, g, b;
    REP(i, n * 2) {
        cin >> a >> c;
        if (c == 'R') r.emplace_back(a);
        else if (c == 'G') g.emplace_back(a);
        else if (c == 'B') b.emplace_back(a);
    }

    SORT(r);
    SORT(g);
    SORT(b);

    if (sz(r) % 2 == 0 and sz(g) % 2 == 0 and sz(b) % 2 == 0) {
        cout << 0 << endl;
        return;
    }

    ll rg = LINF;
    for (auto e : g) {
        auto it = lower_bound(ALL(r), e);
        if (it == r.end()) chmin(rg, abs(r[sz(r) - 1] - e));
        else if (it == r.begin()) chmin(rg, abs(r[0] - e));
        else {
            int idx = distance(r.begin(), it);
            chmin(rg, abs(r[idx - 1] - e));
            chmin(rg, abs(r[idx] - e));
        }
    }
    ll rb = LINF;
    for (auto e : b) {
        auto it = lower_bound(ALL(r), e);
        if (it == r.end()) chmin(rb, abs(r[sz(r) - 1] - e));
        else if (it == r.begin()) chmin(rb, abs(r[0] - e));
        else {
            int idx = distance(r.begin(), it);
            chmin(rb, abs(r[idx - 1] - e));
            chmin(rb, abs(r[idx] - e));
        }
    }
    ll gb = LINF;
    for (auto e : b) {
        auto it = lower_bound(ALL(g), e);
        if (it == g.end()) chmin(gb, abs(g[sz(g) - 1] - e));
        else if (it == g.begin()) chmin(gb, abs(g[0] - e));
        else {
            int idx = distance(g.begin(), it);
            chmin(gb, abs(g[idx - 1] - e));
            chmin(gb, abs(g[idx] - e));
        }
    }

    if (sz(r) % 2 == 0) cout << min(rg + rb, gb) << endl;
    else if (sz(g) % 2 == 0) cout << min(rg + gb, rb) << endl;
    else if (sz(b) % 2 == 0) cout << min(rb + gb, rg) << endl;
}

#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define pb push_back
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp>inline void chmax(_Tp &a,const _Tp &b){a=a<b?b:a;}
template <typename _Tp>inline void chmin(_Tp &a,const _Tp &b){a=a<b?a:b;}
const int N=100005;
typedef long long ll;
std::vector<ll> a[3];
ll last[3];
ll calc(const std::vector<ll> &a,const std::vector<ll> &b){
	std::vector<std::pair<ll,int>> v;
	for(auto it:a)v.pb({it,0});
	for(auto it:b)v.pb({it,1});
	std::sort(v.begin(),v.end());
	last[0]=last[1]=-1e18;
	ll ans=1e18;
	for(auto [x,y]:v)chmin(ans,x-last[!y]),last[y]=x;
	return ans;
}
int main(){
	int n;read(n);
	for(int i=1;i<=n+n;++i){
		ll x;read(x);
		char ch;do{ch=getchar();}while(!isalpha(ch));
		a[ch=='R'?0:ch=='G'?1:2].pb(x);
	}
	if(SZ(a[0])%2==0&&SZ(a[1])%2==0&&SZ(a[2])%2==0)return puts("0"),0;
	int p=-1;for(int i=0;i<3;++i)if(SZ(a[i])%2==0)p=i;
	std::vector<ll> x,y,z=a[p];
	if(p==0)x=a[1],y=a[2];
	else if(p==1)x=a[0],y=a[2];
	else if(p==2)x=a[0],y=a[1];
	printf("%lld\n",std::min(calc(x,y),calc(x,z)+calc(y,z)));
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <string>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define manytests int TT;cin >> TT; while (TT--)

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORd(i,a,b) for (int i = (a); i >= (b); --i)

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define rev reverse

#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vs vector<string>
#define vld vector<ld>
#define vb vector<bool>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>

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

    int a, b;
    cin >> a >> b;
    int x = 0, y = 0;
    while (a) {
        x += a%10;
        a/=10;
    }
    while (b) {
        y += b%10;
        b/=10;
    }
    cout << max(x, y) << "\n";

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 998244353;

////素因数分解 O(n**1/2)
map<int, int> prime_factor(int n){
    map<int, int> res;
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

const int MAX_N = 400000;

ll fact[MAX_N+100];
ll frev[MAX_N+100];

ll rev(ll a, ll p){
    if(p == 0) return 1;
    ll tmp = rev(a, p/2);
    tmp = tmp * tmp % MOD;
    if(p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}

void calc_fact(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}

ll comb(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[k] % MOD * frev[n-k] % MOD;
}

ll perm(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[n-k] % MOD;
}

void prepare(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}

ll solve(ll n, ll k){
    return comb(n+k-1, n);
}

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

    //in main function
    prepare();

    ll ans = 0;
    REPi(m, 1, M+1){
        auto prime = prime_factor(m);
        ll tmp = 1;
        for(auto& [p, cnt] : prime){
            //tmp *= solve(N-1, cnt);
            //tmp *= solve(N-1, cnt+1);
            tmp *= solve(cnt, N);
            tmp %= MOD;
        }
        //printf("%d : %lld\n", m, tmp);
        ans += tmp;
        ans %= MOD;
    }

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


#include<bits/stdc++.h>
#define int long long
#define rep(a,b,c) for(register int a=(b);a<=(c);++a)
#define dow(a,b,c) for(register int a=(b);a>=(c);--a)
using namespace std;
const int MaxN=200000+5;
int arr[MaxN],dif[MaxN],Sum[MaxN];
signed main()
{
	register int n,q;
	scanf("%lld%lld",&n,&q);
	rep(i,1,n)
	{
		scanf("%lld",&arr[i]);
		dif[i]=(arr[i]-arr[i-1])-1;
		Sum[i]=(Sum[i-1]+dif[i]);
	}
	register int val,pos;
	while(q--)
	{
		scanf("%lld",&val);
		pos=(upper_bound(Sum+1,Sum+n+1,val-1)-(Sum+1));
		printf("%lld\n",arr[pos]+(val-Sum[pos]));
	}
	return 0;
}

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

#define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define dep(i, r, l) for (int i = r; i >= l; --i)

void read (int &x) {
	x = 0; char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9')
		x = x * 10 + c - 48, c = getchar();
}

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

int n, m, k, fac[N], inv[N];

int C (int n, int m) {
	if (n < m) return 0;
	if (m == 0) return 1;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int Pow (int a, int k) {
	if (k == 1) return a;
	int S = Pow (a, k >> 1);
	if (k & 1) return S * S % mod * a % mod;
	else return S * S % mod;
}

signed main () {

	fac[0] = 1; rep(i, 1, N - 1) fac[i] = fac[i - 1] * i % mod;
	inv[N - 1] = Pow(fac[N - 1], mod - 2);
	dep(i, N - 2, 0) inv[i] = inv[i + 1] * (i + 1) % mod;

	read(n), read(m), read(k);
	if (m == 0 && k < n || m + k < n) puts("0");
	else printf("%lld", (C(n + m, n) - C(n + m, m + k + 1) + mod) % mod);

	return 0;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int i,j;
	while (cin>>i){
		int arr[200]={0};
		long ans = 0;
		for (int a=0;a<i;a++){
			cin>>j;
			ans+=arr[j%200];
			arr[j%200]+=1;
		}
		cout<<ans<<'\n';
	}
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <climits>
#include <map>
#include <set>
#include <iomanip>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

#ifndef ONLINE_JUDGE
#define imie(x) cerr << #x << " = " << x << '\n';
#else
#define imie(x)
#endif

void debug(vector<int> v) {
	cerr << "[";
	int n = (int)v.size();
	for(int i = 0; i < n; i++) {
		cerr << v[i] << (i == n-1 ? "" : ", ");
	}
	cerr << "]" << '\n';
}

// const int INF = 1e5 + 5;

void test_case() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, long long> freq;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		freq[a[i] % 200]++;
	}
	long long cnt = 0;
	for(auto x : freq) {
		cnt += (long long)x.second * (x.second-1);
	}
	cout << cnt / 2LL << '\n';

}
/*
1. Multiset?
2. binary or two pointers
3. edgecases (can it be 0 or 1)
3. Upper_bound or Lower_bound???

Easy Problem = Easy Solution
*/

int32_t main() {
#ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
 freopen("Error.txt", "w", stderr);
 freopen("output.txt", "w", stdout);
#endif
 std::ios_base::sync_with_stdio(false);
 std::cin.tie(NULL);
 int T;
 T = 1;
 while(T-- >0) {
 	test_case();
 }
}


#include <iostream>
#define DENOM 998244353

using namespace std;

int main(){
    long long a, b, c;
    cin >> a >> b >> c;
    cout << ((((a*(a+1)/2)%DENOM) * ((b*(b+1)/2)%DENOM))%DENOM * ((c*(c+1)/2)%DENOM))%DENOM << endl;
    return 0;
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

const long long MOD = 998244353;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

void solve(ll _A, ll _B, ll _C) {
  mint c = _C;
  mint b = _B;
  mint a = _A;

  mint p = (c * (c + 1)) / 2;
  mint q = (b * (b + 1)) / 2;
  mint r = (a * (a + 1)) / 2;

  cout << p * q * r << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  ll C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
void solve(){
    long long x,y,a,b,tot=0;cin>>x>>y>>a>>b;
    while(x<y){
        if(1e18-b<=x){
            while(x<y){
                if(1e18/a<=x) break;
                x*=a;
                tot++;
            }
            break;
        }
        if(1e18/a<=x){
            while(x<y){
                if(1e18-b<=x) break;
                    x+=b;tot++;
            }
            break;
        }
        if(x*a>x+b) {
            tot+=(y-x)/b;
            x+=((y-x)/b)*b;
            break;
        }
        else {
            x*=a;tot++;
        }
    }
    if(x >= y) tot--;
    cout<<tot<<endl;
}
int main()
 {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("bhar.txt", "w", stdout);
    #endif
    long long q(1);//cin>>q;
    while(q--){
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define trace(...) debug(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void debug(const char* name, Arg1&& arg1){
  cerr <<fixed<<setprecision(6)<< name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void debug(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " | ";
  debug(comma + 1, args...);
}
#define mp(x,y) make_pair(x,y)
const int INF=1000000000+5;
const int N=100+5;
const int M=3e5+5;
const ll oo=1e18+5;
const ll mod=998244353;
const long double eps = 1e-9;

ll extended_gcd(ll a,ll b,ll& x,ll& y){
	ll t;
	if(b==0){
		x=1,y=0;
		return a;
	}
	ll d=extended_gcd(b,a%b,x,y);
	t=x;
	x=y;
	y=t-a/b*y;
	return d;
}

void solve(){
	ll X,Y,P,Q;
	cin>>X>>Y>>P>>Q;
	ll ans=LLONG_MAX;
	for(int y=0;y<Y;++y){
		for(int q=0;q<Q;++q){
			//~ n*(2*X+2*Y)+X+y=m*(P+Q)+P+q
			 //~ n*u-m*v=w
			ll u=(2*X+2*Y);
			ll v=(P+Q);
			ll w=P+q-X-y;
			ll s,t;
			ll gcd=extended_gcd(u,v,s,t);
			if(w%gcd) continue;
			s*=w/gcd;
			t*=w/gcd;
			if(s>=0){
				s%=v/gcd;
			}
			else{
				s+=(-s+v/gcd-1)/(v/gcd)*(v/gcd);
			}
			ll cur=s*u+X+y;
			ans=min(ans,cur);
		}
	}
	//~ trace(ans);
	if(ans==LLONG_MAX) cout<<"infinity";
	else cout<<ans;
	cout<<endl;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	//~ int s,t;
	//~ int d=extended_gcd(4,6,s,t);
	//~ trace(d);
	//~ trace(s,t);
	//~ trace(4*s+6*t);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m);
    vector<ll> a(n),b(m);
    in(a,b);
    vector2d(int,dp,n+1,m+1,INF);
    rep(i,n+1)dp[i][0]=i;
    rep(i,m+1)dp[0][i]=i;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            chmin(dp[i][j],dp[i][j-1]+1);
            chmin(dp[i][j],dp[i-1][j]+1);
            if(a[i-1]==b[j-1]){
                chmin(dp[i][j],dp[i-1][j-1]);
            }else{
                chmin(dp[i][j],dp[i-1][j-1]+1);
            }
        }
    }
    out(dp[n][m]);
}

#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

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

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}

string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int a[n*2],b[n*2],ans[n*2];
    array<int,2> c[n*2];
    for (int i=0;i<n*2;++i)
    {
        cin>>a[i];
        c[i]={a[i],i};
    }
    sort(c,c+n*2);
    for (int i=0;i<n;++i)
        b[c[i][1]]=0;
    for (int i=n;i<n*2;++i)
        b[c[i][1]]=1;
    stack<int> s;
    for (int i=0;i<n*2;++i)
    {
        if (s.empty()||b[i]==b[s.top()])
            s.push(i);
        else
        {
            ans[s.top()]=1;
            ans[i]=0;
            s.pop();
        }
    }
    for (int i=0;i<n*2;++i)
    {
        if (ans[i])
            cout<<'(';
        else
            cout<<')';
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int h,w;
    cin >> h >> w;

    int min_ = INF;

    vector<vector<int> > a(h,vector<int>(w));

    for(int i = 0;i<h; i++){
        for(int j = 0; j<w; j++){
            cin >> a[i][j];
            min_ = min(a[i][j],min_);
        }
    }

    int ans = 0;
        for(int i = 0;i<h; i++){
        for(int j = 0; j<w; j++){
            ans +=  (a[i][j]-min_);
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
template<typename T> bool chmax(T &a, T b) {if(a<b){a=b; return 1; } return 0; }
template<typename T> bool chmin(T &a, T b) {if(a>b){a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll mpow(ll x, ll p) {
	if (p==0) return 1;
	ll res=mpow(x,p/2); res=res*res%MOD;
	return p%2?res*x%MOD:res;
}
ll lpow(ll x, ll p) {
	if (p==0) return 1;
	ll res=lpow(x,p/2); res*=res;
	return p%2?res*x:res;
}

#ifndef fenwick_tree_hpp
#define fenwick_tree_hpp

#include<vector>

template<typename T> struct Fenwick_Tree {
	private:
		int n;
		std::vector<T> bit;
	public:
		Fenwick_Tree(int _n): n(_n), bit(_n, 0) {}
		// [0, r)の要素の総和
		T sum(int i) {
			T s = 0;
			while (i > 0) {
				s += bit[i-1];
				i -= i & -i;
			}
			return s;
		}
		// [l, r)の要素の総和
		T sum(int l, int r) {
			return sum(r) - sum(l);
		}
		void add(int i, T x) {
			i += 1;
			while (i <= n) {
				bit[i-1] += x;
				i += i & -i;
			}
		}
};

#endif // fenwick_tree_hpp

const int M = 100000;

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> batsu(n+1, 0);
	Fenwick_Tree<double> fw_a(M+M+5), fw_b(M+M+5);
	rep(i,k) {
		int x; cin >> x;
		batsu[x]++;
		fw_a.add(x, 1);
	}
	for (int i = n-1; i >= 0; --i) {
		if (batsu[i]) continue;
		fw_a.add(i, fw_a.sum(i+1, i+m+1)/m);
		fw_b.add(i, fw_b.sum(i+1, i+m+1)/m + 1);
	}
	double a = fw_a.sum(0, 1);
	double b = fw_b.sum(0, 1);
	if (1 - a == 0) cout << -1 << endl;
	else {
		double ans = b / (1 - a);
		cout << fixed << setprecision(10) << ans << endl;
	}
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VLL = vector <long long>;

int main() {
    int K;
    cin >> K;
    string S;
    string T;

    cin >> S >> T;

    double winning = 0;
    VLL remain(10, K);
    VVI cnt(2, VI(10));

    for (int i = 0; i < 4; ++i) {
        --remain[S[i]-'0'];
        --remain[T[i]-'0'];
        ++cnt[0][S[i]-'0'];
        ++cnt[1][T[i]-'0'];
    }

    long long totCard = 9*K-8;
    double sumProb = 0;

    for (int a = 1; a <= 9; ++a) {
        for (int b = 1; b <= 9; ++b) {
            double prob = 0;
            VVI ncnt = cnt;
            ++ncnt[0][a];
            ++ncnt[1][b];

            if (a==b) {
                if (remain[a] < 2) {
                    continue;
                }
                prob = (double)remain[a]*(remain[b]-1)/(totCard*(totCard-1));
            } else {
                if (remain[a] < 1 || remain[b] < 1) {
                    continue;
                }
                prob = (double)remain[a]*remain[b]/(totCard*(totCard-1));
            }

            VLL score(2);

            for (int i = 0; i < 2; ++i) {
                for (int j = 1; j <= 9; ++j) {
                    long long base = j;
                    for (int k = 0; k < ncnt[i][j]; ++k) {
                        base *= 10;
                    }

                    score[i] += base;
                }
            }

            // if T wins
            // cout << "GO " << a << " " << b << " " << score[0] << " " << score[1] << endl;
            if (score[0] > score[1]) {
                // cout << "NOW " << a << " " << b << " " << prob << endl;
                winning += prob;
            }
            sumProb += prob;
        }
    }

    cout << setprecision(15) << fixed << winning << endl;
    // cout << setprecision(15) << fixed << sumProb << endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>

typedef long long LL;

const int N = 505;
const LL MOD = 998244353;

int a[N][N];

inline int read() {
    char ch = getchar();
    while (ch != 'B' && ch != 'R' && ch != '.') ch = getchar();
    if (ch == 'B') return 0;
    if (ch == 'R') return 1;
    return 2;
}

void solve() {
    int n, m;
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            a[i][j] = read();
        }
    }
    int ans = 0;
    for (int i = 1; i <= n + m - 1; i++) {
        int tt[] = {0, 0, 0};
        for (int j = i; j >= 1; j--) {
            if (j > n) continue;
            int t = i - j + 1;
            if (t > m) continue;
            tt[a[j][t]]++;
        }
        if (tt[0] != 0 && tt[1] != 0) {
            puts("0");
            return;
        } else if (tt[0] == 0 && tt[1] == 0) {
            ans ++;
        }
    }
    LL res = 1;
    for (int i = 0; i < ans; i++) {
        res = res * 2 % MOD;
    }
    std::cout << res << std::endl;
}

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

/*
2 4
..B.
....
*/

#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) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) per(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

const int MAXN = 2e5 + 10;
const int P = 998244353;

int qpower(int a, int x) {
	int ret = 1;
	for (; x; x >>= 1, a = 1ll * a * a % P) x & 1 ? ret = 1ll * ret * a % P : 0;
	return ret;
}

int n, E[MAXN], cnt, vis[MAXN];

void work(int st, int idx) {
	if (vis[st]) return ;
	int cur = st;
	while (1) {
		vis[cur] = idx;
		cur = E[cur];
		if (vis[cur]) {
			cnt += vis[cur] == idx;
   			break;
		}
	}
}

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n);
	REP(i, n) IO::read(E[i]), E[i]--;
	REP(i, n) work(i, i + 1);
	IO::write((qpower(2, cnt) - 1 + P) % P);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,w;
    cin>>n>>w;
    cout<<n/w;
}

// Author:- Pratik Kinger
// Birla Institute of Technology
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(a) (a).begin(), (a).end()
#define fi first
#define si second
#define sz(x) (ll) x.size()
#define endl '\n'
#define mod 1000000007
#define mset(m, v) memset(m, v, sizeof(m))
using namespace std;
const ll MOD = 1000000000 + 7;
ll powermod(ll a, ll b, ll modi)
{
    a %= modi;
    ll res = 1;
    while (b)
    {
        if (b % 2)
        {
            res = (res * a) % modi;
        }
        b /= 2;
        a = (a * a) % modi;
    }
    return res;
}
ll power(ll a, ll b)
{

    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll binarySearch(ll a[], ll low, ll high, ll key)
{
    while (low <= high)
    {
        ll mid = (low + high) / 2;
        if (a[mid] < key)
        {
            low = mid + 1;
        }
        else if (a[mid] > key)
        {
            high = mid - 1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}
ll binarytodecimal(string n)
{
    string num = n;
    ll dec_value = 0;

    ll base = 1;

    ll len = num.length();
    for (ll i = len - 1; i >= 0; i--)
    {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
string dtb(ll n)
{
    string s = "";
    while (n > 0)
    {
        if (n % 2 == 0)
            s.pb('0');
        else
            s.pb('1');
        n /= 2;
    }
    reverse(all(s));
    return s;
}
vi seive;
void Seive()
{
    const ll maxn = 1e6 + 5;
    seive.resize(maxn);
    f(i, 0, maxn) seive[i] = i;
    for (ll i = 2; i <= maxn; i += 2)
        seive[i] = 2;
    seive[1] = -1;
    seive[0] = -1;
    for (ll i = 3; i <= maxn; i += 2)
        if (i == seive[i])
            for (ll j = i * i; j < maxn; j += i)
                if (seive[j] == j)
                    seive[j] = i;
}
//------------------------------CODE--HERE--------------------------
//----------global--variables-------------------
//------------end-------------------------------
void solve()
{
    ll n,w;
    cin>>n>>w;
    cout<<floor(n/w)<<endl;
}
//------------------------------
int main()
{
    //FAST INPUT OUTPUT
    FIO;

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

    ll t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
    int N, K, M;
    cin >> N >> K >> M;
    vector<int> A(N-1);
    int sum = 0;
    rep(i, N-1) {
        cin >> A[i];
        sum += A[i];
    }

    for (int i=0; i<=K; ++i) {
        double s = sum + i;
        if (s/N >= M) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

}

#include <bits/stdc++.h>

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

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

    ll N,K,M; cin >> N >> K >> M;

    ll sum = 0;
    for (int i = 0;i < N-1;i++){
        ll a; cin >> a;
        sum += a;
    }

    ll goal = M*N;

    if(goal <= sum) cout << 0 << endl;
    else if(goal-sum > K) cout << -1 << endl;
    else cout << goal-sum << endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
int main() {
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int n;
  cin >> n;
  n = min(n, 8);
  vector<int> a(n);
  for (auto& ai : a) {
    cin >> ai;
  }
  vector<int> f(200, -1);
  for (int mask = 1; mask < (1 << n); ++mask) {
    int64_t sum = 0;
    for (int bit = 0; bit < n; ++bit) {
      if (mask & (1 << bit)) {
        sum += a[bit];
      }
    }
    sum %= 200;
    if (f[sum] != -1) {
      auto print_mask = [&] (int mask) -> void {
        cout << __builtin_popcount(mask) << " ";
        for (int bit = 0; bit < n; ++bit) {
          if (mask & (1 << bit)) {
            cout << bit + 1 << " ";
          }
        }
        cout << "\n";
      };
      cout << "Yes\n";
      print_mask(f[sum]);
      print_mask(mask);
      return 0;
    } else {
      f[sum] = mask;
    }
  }
  cout << "No\n";
  return 0;
}

#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>
#include <algorithm>

// URL:

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n)? "YES": "NO") << endl
#define Yes(n) cout << ((n)? "Yes": "No") << endl

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fore(x, a) for(auto& (x) : (a))

#define FORL(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)

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

#define VECCIN(x) for(auto& youso_: (x)) cin >> youso_
#define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = 1e18;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  ll T;
  cin >> T;
  repll(i,T) {
    ll N;
    cin >> N;
    if (N % 2 == 1) {
      cout << "Odd" << endl;
    }
    else {
      N /= 2;
      if (N % 2 == 1) {
        cout << "Same" << endl;
      }
      else {
        cout << "Even" << endl;
      }
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
int main() {
	long n;
	cin>>n;
	set<long> ans;
	for(long d=1;d*d<=n;d++) {
		if(n%d==0) {
			ans.insert(d);
			ans.insert(n/d);
		}
	}
	for(auto x:ans) cout<<x<<endl;
}

#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, a, b) for (ll i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n; cin>>n;
    map<ll, ll> mp;
    rrep(i, 2, n + 1) {
        ll temp = i;
        for (ll j = 2; j * j <= temp; ++j) {
            ll cur = 0;
            while (temp % j == 0) {
                cur++;
                temp /= j;
            }
            chmax(mp[j], cur);
        }
        chmax(mp[temp], 1ll);
    }
    ll ans = 1;
    for (auto p : mp) {
        rep(i, p.se) ans *= p.fi;
    }
    cout<<ans + 1<<endl;
}


#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

//printf("%.10f\n", n);
typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

ld d[105][105];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
  cout << fixed << setprecision(15);

	ll n; cin >> n;
	vector<ll> x(n + 5), y(n + 5);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
  if(n==1){
    cout<<max(100-y[0],100+y[0])/2<<endl;
    return 0;
  }
	//行けないか
	vector<vector<ll> > G(123456);
	rep(i, n) {
		rep(j, n) {
			if (i != j) { G[i].push_back(j); }
			d[i][j] = sqrt(pow(abs(x[i] - x[j]), 2) + pow(abs(y[i] - y[j]), 2));
		}
	}
	rep(i, n) {
		G[i].push_back(n);
		d[i][n] = y[i] + 100;
	}
	//cout << 222 << endl;
	ld ans = 200;
	rep(aa, n) {
		queue<ll> que; queue<ld> cnt;
		vector<ld> visit(n + 1, INF); visit[aa] = 100 - y[aa];
		for (int i = 0; i < G[aa].size(); i++) {
        	if (G[aa][i] == n) { ans = min(ans, max(visit[aa], d[aa][G[aa][i]])); }
			que.push(G[aa][i]); cnt.push(max(visit[aa], d[aa][G[aa][i]]));
			visit[G[aa][i]] = max(visit[aa], d[aa][G[aa][i]]);
		}
		while (que.size()) {
			//cout << visit[que.front()] << endl;
			for (int i = 0; i < G[que.front()].size(); i++) {
				ld uio = 0;
				if (G[que.front()][i] == n) {
					uio = max(cnt.front(), d[que.front()][G[que.front()][i]]);
					ans = min(ans, uio); continue;
				}
				uio = max(cnt.front(), d[que.front()][G[que.front()][i]]);
				if (visit[G[que.front()][i]] > uio) {
					que.push(G[que.front()][i]);
					cnt.push(uio); visit[G[que.front()][i]] = uio;
				}
			}
			que.pop(); cnt.pop();
		}
	}
	ans /= 2;
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
#define LOG(...) cerr << "[" << #__VA_ARGS__ << "]: " << repr(__VA_ARGS__) << endl;
#define MSG(args) cerr << args << "\n";
#define debug(x) x
#else
#define LOG(...)
#define MSG(args)
#define debug(x)
#endif

#define mp make_pair
#define pb push_back
#define sz(x) (int)((x).size())
#define ms(x, v) memset((x), v, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vvi = vector<vi>;

class UnionFind
{
    int N, cnt;
    vector<int> parent, size;

public:
    UnionFind() { N = 0; }
    UnionFind(int N) :N(N) { clear(); }

    void clear() { cnt = N; size.assign(N + 1, 1); parent.assign(N + 1, 0); for(int i = 1; i <= N; i++) parent[i] = i; }
    void reset(int sz) { N = sz; clear(); }
    inline int count() const { assert(N != 0); return cnt; }
    int getSetSize(int i) { assert(N != 0 && i >= 1 && i <= N); return size[findSet(i)]; }
    int findSet(int i) { assert(N != 0 && i >= 1 && i <= N); return (parent[i] == i) ? i : (parent[i] = findSet(parent[i])); }
    bool isSameSet(int i, int j) { assert(N != 0 && i >= 1 && i <= N && j >= 1 && j <= N); return findSet(i) == findSet(j); }

    void unite(int i, int j)
    {
        assert(N != 0 && i >= 1 && i <= N && j >= 1 && j <= N);
        int x = findSet(i), y = findSet(j);
        if(x == y)
            return;
        if(size[x] < size[y])
            swap(x, y);
        parent[y] = x;
        size[x] += size[y];
        cnt--;
    }
};

const ld eps = 1e-7;

int N;
pll nails[111];

bool can(ld R)
{
    UnionFind uf(N + 2);
    int up = N + 1, down = N + 2;
    REPV(i, 1, N + 1)
    {
	if(100 - nails[i].second <= 2 * R) uf.unite(i, up);
	if(100 + nails[i].second <= 2 * R) uf.unite(i, down);
    }
    REPV(i, 1, N + 1)
	REPV(j, i + 1, N + 1)
	    if(pow(nails[i].first - nails[j].first, 2) + pow(nails[i].second - nails[j].second, 2) <= 4 * R * R)
		uf.unite(i, j);
    return !uf.isSameSet(up, down);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    REPV(i, 1, N + 1) cin >> nails[i].first >> nails[i].second;
    ld lo = 0.0, hi = 500.0;
    while(hi - lo > eps)
    {
	ld mid = (hi + lo) / 2.0;
	if(can(mid)) lo = mid;
	else hi = mid;
    }
    cout.precision(9);
    cout << fixed << lo << "\n";
    return 0;
}


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

int main() {

    ll N;
    cin>>N;
    vector<pair<ll,char> > vp(2*N);

    ll n;
    char c;

    map<char,ll> mp;

    for(int i=0;i<2*N;i++){
        cin>>n;
        cin>>c;
        vp[i]=make_pair(n,c);
        mp[c]++;
    }
    vector<pair<char,int> > vcc;
    vector<pair<char,int> > vce;
    for(auto a:mp){

       //cout<<a.first<<" "<<a.second<<endl;
        //a.second=(a.second)%2;
       // cout<<a.first<<" "<<a.second<<endl;
        if(a.second%2==1){
            vcc.push_back(make_pair(a.first,0));
        }else{
            vce.push_back(make_pair(a.first,0));
        }
    }
    /*
    for(auto a:vcc){
        cout<<a.first<<" "<<a.second;

    }
    for(auto a:vce){
        cout<<a.first<<" "<<a.second;

    }
    */

    sort(vp.begin(),vp.end(),[](pair<ll,char> a,pair<ll,char> b){
        return a.first<b.first;
    });
    /*
    for(auto a: mp){
        cout<<a.first<<" "<<a.second<<endl;
    }
    */

    vector<pair<ll,pair<char,char> > > vc;

    for(int i=0;i<2*N-1;i++){
        vc.push_back(pair<ll,pair<char,char> >(abs(vp[i].first-vp[i+1].first),pair<char,char>(vp[i].second,vp[i+1].second)));
    }
    sort(vc.begin(),vc.end(),[](pair<ll,pair<char,char> > a,pair<ll,pair<char,char> > b){
        return a.first<b.first;
    });
    ll ans=0;

    ll ans1=0;
    ll ans2=0;
    ll cnt=0;
    bool flag1=false;
    bool flag2=false;

    //cout<<mp['R']<<" "<<mp['B']<<" "<<mp['C']<<endl;

    if(mp['R']%2==0&&mp['B']%2==0&&mp['G']%2==0){
        ans=0;
    }else{
       // cout<<"---"<<endl;
        for(int i=0;i<2*N-1;i++){
            if(((vc[i].second.first==vcc[0].first)&&(vc[i].second.second==vcc[1].first))||(vc[i].second.first==vcc[1].first&&vc[i].second.second==vcc[0].first)){
               //cout<<vc[i].first<<endl;
                if(cnt==0){
                   // cout<<"0000"<<endl;
                    ans1+=vc[i].first;
                    flag1=true;
                }
                cnt++;

            }else{
                if(((vc[i].second.first==vce[0].first)&&(vc[i].second.second==vcc[0].first))||(vc[i].second.first==vcc[0].first&&vc[i].second.second==vce[0].first)){

                    if(vcc[0].second==0){
                        ans2+=vc[i].first;
                    }
                    vcc[0].second++;

                }else if(((vc[i].second.first==vce[0].first)&&(vc[i].second.second==vcc[1].first))||(vc[i].second.first==vcc[1].first&&vc[i].second.second==vce[0].first)){

                    if(vcc[1].second==0){
                        ans2+=vc[i].first;
                    }
                    vcc[1].second++;
                }

            }

        }
        if(vcc[0].second>0&&vcc[1].second>0){
            flag2=true;
        }
        if(flag1==true&&flag2==false){
            ans=ans1;
        }else if(flag1==false&&flag2==true){
            ans=ans2;
        }else{
            ans=min(ans1,ans2);
        }

    }

    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll id(char c) {
    if (c=='R') return 0;
    if (c=='G') return 1;
    return 2;
}

bool is_end(vector<vector<ll>> vec) {
    for (auto a : vec) {
        if (a.size()%2) return false;
    }
    return true;
}

int main() {
    ll N; cin >> N;
    vector<vector<ll>> a(3);
    rep(i,2*N) {
        ll x; char c;
        cin >> x >> c;
        a[id(c)].push_back(x);
    }

    ll cnt0 = 0;
    rep(i,3) if (a[i].size()==0) cnt0++;

    if (cnt0==2) Cout(0);

    if (is_end(a)) Cout(0);
    rep(i,2) if (a[i].size()%2==0) swap(a[i],a[2]);
    rep(i,3) sort(all(a[i]));

    ll ans = inf;
    rep(i,a[0].size()) {
        ll x = a[0][i];
        ll l = -1, r = a[1].size();
        ll res = inf;
        while (r-l>1) {
            ll m = (l+r)/2;
            if (a[1][m]<=x) l = m;
            else r = m;
        }
        if (r<a[1].size()) chmin(res,abs(a[1][r]-x));
        if (l>=0) chmin(res,abs(a[1][l]-x));
        chmin(ans,res);
        if (ans==0) Cout(0);
    }

    if (cnt0==1) Cout(ans);

    vector<ll> X, Y;
    rep(i,a[2].size()) {
        ll x = a[2][i];
        rep(j,2) {
            ll l = -1, r = a[j].size();
            ll res = inf;
            while (r-l>1) {
                ll m = (l+r)/2;
                if (a[j][m]<=x) l = m;
                else r = m;
            }
            if (r<a[j].size()) chmin(res,abs(a[j][r]-x));
            if (l>=0) chmin(res,abs(a[j][l]-x));
            if (j%2) X.push_back(res);
            else Y.push_back(res);
        }
    }
    sort(all(X)); sort(all(Y));
    chmin(ans,X[0]+Y[0]);
    Cout(ans);
}


#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool umax(T& a, T b){
    bool ret = a < b;
    if(ret) a = b;
    return ret;
}
template<typename T>
bool umin(T& a, T b){
    bool ret = a > b;
    if(ret) a = b;
    return ret;
}
struct edge{
    int to; ll cost;
    int from;
    edge(){ edge(0,0);}
    edge(int to_, ll cost_) : to(to_), cost(cost_){}
    edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){}
};

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

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

template<typename T>
vector<T> read_array(int sz){
    vector<T> ret(sz);
    for(auto & x : ret) cin >> x;
    return ret;
}

void solve(){
    int n;
    read(n);
    ll ans = 2e9;
    REP(i, n){
        ll a, p, x;
        read(a, p, x);
        if(a < x){
            umin(ans, p);
        }
    }
    if(ans > (ll) 1e9) ans = -1;
    write(ans,"\n");
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::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 main( )
{
    ll n,a,b,c;
    cin>>n;
    ll ans = INT_MAX,cnt=0;
    while(n--)
    {
        cin>>a>>b>>c;
        if(c-a > 0){ans=min(ans,b);++cnt;}
    }
    if(cnt)cout<<ans<<endl;
    else cout<<-1<<endl;
}


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

const int maxl=2e5+10;
const int mod=1e9+7;

int n,k;
int a[maxl];
ll dp[maxl][17][2][2];
char s[maxl];

inline ll dfs(int pos,int st,bool up,bool lead)
{
	int cnt=__builtin_popcount(st);
	if(cnt>k) return 0;
	if(pos>n) return cnt==k;
	ll &ret=dp[pos][cnt][up][lead];
	if(ret!=-1)
		return ret;
	ret=0;
	int r=up?a[pos]:15;
	for(int i=0;i<=r;i++)
		ret=(ret+dfs(pos+1,(!i&&!lead)?st:st|(1<<i),up&&(i==r),lead|i))%mod;
	return ret;
}

int main()
{
	scanf("%s",s+1);scanf("%d",&k);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	if(s[i]>='A' && s[i]<='Z')
		a[i]=s[i]-'A'+10;
	else
		a[i]=s[i]-'0';
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",dfs(1,0,1,0));
	return 0;
}


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

const int Maxn = 3005, p = 1e9 + 7;
int n, trans[Maxn][Maxn], maxi[Maxn][Maxn];
long long ans, a[Maxn], sum[Maxn], f[Maxn][Maxn];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]), sum[i] = sum[i - 1] + a[i];
		for (int j = 1; j <= n; j++)
		{
			trans[i][j] = maxi[j][sum[i] % j];
			maxi[j][sum[i] % j] = i;
		}
	}
	f[0][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (trans[i][j] != -1)
				(f[i][j] += f[trans[i][j]][j] + f[trans[i][j]][j - 1]) %= p;
	for (int i = 1; i <= n; i++)
		(ans += f[n][i]) %= p;
	printf("%lld", ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

template<long long M, typename T=long long>
struct modint {
  modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {}
  using this_type = modint<M, T>;
  T val;
  this_type operator++(int) {
    this_type ret = *this;
    val++; val %= M;
    return ret;
  }
  this_type operator--(int) {
    this_type ret = *this;
    val += M-1; val %= M;
    return ret;
  }
  this_type &operator++() {
    val++; val %= M;
    return *this;
  }
  this_type &operator--() {
    val += M-1; val %= M;
    return *this;
  }
  this_type operator+() const { return *this; }
  this_type operator-() const { return this_type(M-val); };
  friend this_type operator+(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) += rhs;
  }
  friend this_type operator-(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) -= rhs;
  }
  friend this_type operator*(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) *= rhs;
  }
  friend this_type operator/(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) /= rhs;
  }
  this_type pow(long long b) const {
    this_type ret = 1, a = *this;
    while(b != 0) {
      if(b % 2 != 0) {
        ret *= a;
      }
      b /= 2;
      a = a * a;
    }
    return ret;
  }
  this_type inv() const {
    return pow(M-2);
  }
  this_type& operator+=(const this_type &rhs) {
    val += rhs.val; val %= M; return *this;
  }
  this_type& operator-=(const this_type &rhs) {
    val += M - rhs.val; val %= M; return *this;
  }
  this_type& operator*=(const this_type &rhs) {
    val *= rhs.val; val %= M; return *this;
  }
  this_type& operator/=(const this_type &rhs) {
    *this *= rhs.inv(); return *this;
  }
  friend bool operator==(const this_type &lhs, const this_type &rhs) {
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const this_type &lhs, const this_type &rhs) {
    return lhs.val != rhs.val;
  }
  T mod() const {return M;}
};

using mi = modint<1000000007>;
using vmi = vector<mi>;
using vvmi = vector<vmi>;

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N; RI(N);
  vi A(N); RVI(A);

  vvmi ans(N+1, vmi(N+1, 0));
  fill(all(ans[1]), 1);
  ans[1][0] = 0;
  REP(2, N+1, k) {
    vi prev(N+1, -1);

    i64 S = 0;
    vi res(k, -1);
    res[0] = 0;
    REP(1, N+1, i) {
      S += A[i-1];
      S %= k;
      prev[i] = res[S];
      res[S] = i;
    }

    REP(1, N+1, i) {
      ans[k][i] = 0;
      if(prev[i] != -1) {
        ans[k][i] += ans[k][prev[i]];
        ans[k][i] += ans[k-1][prev[i]];
      }
    }
  }

  mi a = 0;
  REP(1, N+1, k) {
    a += ans[k].back();
  }
  WI(a.val);

  return 0;
}


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

int main() {
  cin.tie(nullptr); // Do not flush "cout" when processing "cin".

  int n, k;
  cin >> n >> k;

  vector<vector<int>> t(8, vector<int>(8));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> t.at(i).at(j);
    }
  }

  // 都市番号は 0-indexed とする。
  // 都市番号が 1 〜 n-1 の都市について、全ての順列を試す。
  //
  // p の要素番号は 0 〜 n-2 となる。
  vector<int> p;
  for (int i = 1; i < n; i++) {
    p.push_back(i);
  }

  int ans = 0;
  do {
    // 都市 0 から都市 p[0] までの移動距離
    int total = t.at(0).at(p.at(0));
    // 都市 p[0] から都市 p[1] への移動時間
    // ...
    // 都市 p[n-3] から都市 p[n-2] への移動時間
    //
    // 上記の移動時間をそれぞれ加算する。
    for (int i = 0; i < n - 2; i++) {
      int from = p.at(i);
      int to = p.at(i + 1);
      total += t.at(from).at(to);
    }
    // 都市 p[n-2] から都市 0 への移動時間
    total += t.at(p.at(n - 2)).at(0);

    if (total == k) {
      ans++;
    }
    // ### next_permutation
    //
    // 今回の場合、vector コンテナクラスのメンバ変数である
    // vector<int>::iterator 型の値を引数に取る。
    //
    // [first, last) で指定した区間の要素を順列に並べ替える。
    // そのため、next_permutation の第一引数を p.begin() + 1
    // とする場合、0 番目の要素は並べ替えられない。
    //
    // また、next_permutation は次の順列を生成することができる場合、
    // true、生成できない場合は false を返す。
    //
    // next_permutation は辞書順に並び替えて順列を生成する。
    // そのため、以下の例では {1, 2, 3}, {1, 3, 2} の組み合わせは生成されない。
    // {2, 1, 3} の次は、辞書順で {2, 3, 1} が生成される。
    //
    //   vector<int> v = {2, 1, 3};
    //   do {
    //     ...
    //   } while (next_permutation(v.begin(), v.end()));
    //
    // 次の順列が生成できなくなった時点で vector コンテナは
    // 辞書順の最後の並びとなっている。
    //
    //   上記 v = {2, 1, 3} の例では、
    //   v = {3, 2, 1} に並び替えられている。
    //
    // おそらく、順列が生成できず false を返すタイミングで、
    // vector コンテナの要素を reverse(v.begin(), v.end()) で
    // 辞書順の最初の並びにしている。
    //
    //   上記例では v = {3, 2, 1} を
    //   v = {1, 2, 3} にしている。
    //
    // これより do-while の実行前に vector の要素を予め
    // sort している場合は、do-while 終了後に vector の値が
    // 元に戻っている（あるいは、do-while ブロック内でのみ
    // 順番が変更されている）ように見える。
    //
  } while (next_permutation(p.begin(), p.end()));

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

const bool isDebugMode = true;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const int SHOWSIZE = 1 << 5;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {0, 0, 1, 1};
const long long dx[] = {0, 1, 0, 1};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
long long power(long long a, long long n){long long res = 1; while(n > 0){if(n & 1)res = res * a; a = a * a; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, min(v.size(), SHOWSIZE)){rep(j, min(v[i].size(), SHOWSIZE)) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : 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...);}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // cin >> testcase;
    while(testcase--) solve();
    return 0;
}

void solve(){
    ll H, W; cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    ll ans = 0;
    rep(i, H - 1)rep(j, W - 1){
        ll cnt = 0;
        rep(k, 4){
            if(valid(H, W, i + dx[k], j + dy[k]) && s[i + dx[k]][j + dy[k]] == '.') cnt++;
        }
        if(cnt % 2) ans++;
    }
    pt(ans);
}


#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7; // 998244353
const ll LINF = LLONG_MAX; // ~ 10^18 ~ 1<<60
const int INF = INT_MAX;
const double PI = acos(-1);

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

	vector<ll> h(n);
	vector<ll> w(m);

	rep(i,0,n){
		cin >> h[i];
	}

	rep(i,0,m){
		cin >> w[i];
	}

	sort(all(h));

	vector<ll> L(n, 0);
	vector<ll> R(n, 0);

	for(int i = 0; i <= n - 3; i += 2){
		ll x = abs(h[i] - h[i + 1]);
		L[i] = x;
		L[i + 1] = x;
		if(i != 0){
			L[i] += L[i - 1];
			L[i + 1] += L[i - 1];
		}
	}

	for(int i = n - 1; i >= 1; i -= 2){
		ll x = abs(h[i] - h[i - 1]);
		R[i] = x;
		R[i - 1] = x;
		if(i != n - 1){
			R[i] += R[i + 1];
			R[i - 1] += R[i + 1];
		}
	}

	ll ans = LINF;

	for(int i = 0; i < m; i++){
		ll it = lower_bound(all(h), w[i]) - h.begin();
		ll temp = 0;
		if(it % 2 == 1){
			temp = abs(w[i] - h[it - 1]);
			if(it - 2 >= 0) temp += L[it - 2];
			if(it + 1 < n) temp += R[it + 1];
		}else{
			temp = abs(w[i] - h[it]);
			if(it - 1 >= 0) temp += L[it - 1];
			if(it + 1 < n) temp += R[it + 1];
		}
		ans = min(ans, temp);
	}

	cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) (x & (-x))

const ll inf  = 1e17+9;
const ll mod  = 1e9+7;
const ll maxn = 2e5+8;

int n,m;
int h[maxn],w[maxn];
ll L[maxn],R[maxn];
ll ans=1e18;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i) cin>>h[i];
    for(int i=1;i<=m;++i) cin>>w[i];

    sort(h+1,h+1+n);

    for(int i=2;i<=n;i+=2) L[i]=L[i-2]+abs(h[i]-h[i-1]);
    for(int i=n-1;i>=1;i-=2) R[i]=R[i+2]+abs(h[i]-h[i+1]);

    for(int i=1;i<=m;++i){
        int pos=lower_bound(h+1,h+1+n,w[i])-h;
        if(pos%2==0) pos--;
        ans=min(ans,L[pos-1]+R[pos+1]+abs(h[pos]-w[i]));
    }

    cout<<ans<<endl;

    return 0;
}


#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
int dx[4] = { 1, 0, -1,0 }, dy[4] = { 0, 1, 0, -1 };
int si, sj;
int N = 50;
int t[50][50];
int p[50][50];
map<pair<int, int>, pair<int, int>>mp;
bool seen[50][50];
int f(string s) {
	int ans = p[si][sj];
	int n = s.size();
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)seen[i][j] = false;
	seen[si][sj] = true;
	int nowi = si, nowj = sj;
	for (int i = 0; i < n; i++) {
		char now = s[i];
		int ni = nowi, nj = nowj;
		int c = 0;
		if (now == 'D') {
			c = 0;
		}
		else if (now == 'R') {
			c = 1;
		}
		else if (now == 'U') {
			c = 2;
		}
		else {
			c = 3;
		}
		ni += dx[c];
		nj += dy[c];
		if (ni < 0 || ni >= N || nj < 0 || nj >= N)return 0;
		//if (t[ni][nj] == t[nowi][nowj] || seen[mp[{ni, nj}].first][mp[{ni, nj}].second])return 0;
		if (seen[ni][nj])return 0;
		seen[ni][nj] = true;
		ans += p[ni][nj];
		nowi = ni, nowj = nj;
	}
	return ans;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	clock_t start = clock();
	cin >> si >> sj;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> t[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> p[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			mp[{i, j}] = { i, j };
			for (int s = 0; s < 4; s++) {
				int ni = i + dx[s], nj = j + dy[s];
				if (0 <= ni && ni < N && 0 <= nj && nj < N && t[ni][nj] == t[i][j]) {
					mp[{i, j}] = { ni, nj };
				}
			}
		}
	}
	string ans = "";
	int nowscore = 0;
	clock_t end = clock();
	int cnt = 0;
	while ((double)(end - start) / CLOCKS_PER_SEC < 0.98) {
		end = clock();
		cnt++;
		queue<pair<int, int>>q;
		vector<vector<int>>dist(N, vector<int>(N, -1));
		q.push({ si, sj });
		dist[si][sj] = 0;
		string s = "";

		while (!q.empty()) {
			pair<int, int> pa = q.front(); q.pop();
			vector<int>v;
			for (int s = 0; s < 4; s++) {
				int ni = pa.first + dx[s], nj = pa.second + dy[s];
				if (0 <= ni && ni < N && 0 <= nj && nj < N && dist[ni][nj] == -1) {
					if (t[ni][nj] != t[pa.first][pa.second] && dist[mp[{ni, nj}].first][mp[{ni, nj}].second] == -1) {
						v.push_back(s);
					}
				}
			}
			int n = v.size();
			if (n == 0)break;
			int idx = v[rand() % n];
			if (idx == 2)s += 'U';
			else if (idx == 0)s += 'D';
			else if (idx == 1)s += 'R';
			else s += 'L';
			int ni = pa.first + dx[idx], nj = pa.second + dy[idx];
			if (0 <= ni && ni < N && 0 <= nj && nj < N && dist[ni][nj] == -1) {
				if (t[ni][nj] != t[pa.first][pa.second]) {
					q.push({ ni, nj });
					dist[ni][nj] = dist[pa.first][pa.second] + 1;
				}
			}
		}
		int tscore = f(s);
		if (nowscore < tscore) {
			nowscore = tscore;
			ans = s;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
//#include "atcoder/all"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
//using namespace atcoder;
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> P;
constexpr ll inf=1ll<<61;
constexpr ll mod=998244353;
int a[1005],b[1005];
ll dp[1005][1005];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	rep(i,n+1)rep(j,m+1)dp[i][j]=inf;
	dp[0][0]=0;
	rep(i,n+1){
		rep(j,m+1){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
			if(a[i]==b[j]){
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
			}
			else{
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+1);
			}
		}
	}
	cout<<dp[n][m]<<endl;
}


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

#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1

#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

inline bool check(li x, li m){
    while(x>0){
        if(x%m==7)return false;
        x/=m;
    }
    return true;
}

int main() {
    li n;
    cin>>n;
    li res=0;
    repp(i,1,n+1){
        if(check(i,8)&&check(i,10))res++;
    }
    cout<<res<<endl;

    return 0;
}

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

bool solve(ll x){
  while(x>0){
    if(x%10==7) return true;
    x/=10;
  }
  return false;
}

bool solve2(ll x){
  while(x>0){
    if(x%8==7) return true;
    x/=8;
  }
  return false;
}

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  for(ll i=1;i<=n;i++){
    if(solve(i)||solve2(i)){
      ans++;
    }
  }
  cout<<n-ans<<endl;
  return 0;
}


#include<iostream>
using namespace std;
double a, b;
int main() {
	cin >> a >> b;
	cout << 100.0l - b * 100 / a;

}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;
using ll = long long;
//ループ
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
//コンテナ
#define all(x) (x).begin(),(x).end()
//関数
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

//-----global variable------------

//-----function definition--------

//-----main-----------------------
int main() {
    //----code here------------
    double a, b ;
    cin >> a >> b ;
    cout << std::fixed << std::setprecision(15);

    cout << 100.0 * ( a - b ) / a << endl;

    //----return---------------
    return 0;
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define li long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define rev(a) reverse(all(a))
#define sort(a) sort(all(a))
#define pb push_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define vli vector<li>
#define MAXN 1e5+10
const li mod = 1e9+7;
using namespace std;

li power(li a, li b) { a%=mod; li ret = 1; while(b){ if(b&1) ret*=a; a*=a;; if(ret>=mod) ret%=mod; if(a>=mod) a%=mod; b>>=1; } return ret; }

template <class T> void read(T& x){
  cin>>x;
}

template <class T, class... U> void read(T& x, U&... u){
  read(x);
  read(u...);
}

template <class A> void read(vector<A>& v){
  for(auto &it:v)
    read(it);
}

template <class A> void print(A x){
  cout<<x;
}

template <class A> void printl(A x){
  cout<<x<<endl;
}

template <class A> void print(vector<A>& v)
{
  for(auto &it:v){
    print(it);
    cout<<' ';
  }
  cout<<endl;
}

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

    vector<pair<li,li> > v;
    rep(i,0,n){
      li a,b;
      cin>>a>>b;

      v.pb({a,b});
    }

    rep(i,0,n){
      rep(j,i+1,n){
        rep(k,j+1,n){
              li x1 = v[i].first;
              li y1 = v[i].second;
              li x2 = v[j].first;
              li y2 = v[j].second;
              li x3 = v[k].first;
              li y3 = v[k].second;
              li area = abs(x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2);
              if(area==0){
                cout<<"Yes\n";
                return;
              }
          }
        }
      }

    cout<<"No\n";
}

int main()
{
  IOS;

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

  solve();

  return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const long double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;

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

    int *x = new int[N];
    int *y = new int[N];
    double dt[100][100];
    double c[100][100];

    for (int i=0; i<N; i++)
    {
        cin >> x[i] >> y[i];
    }

    for (int i=0; i<N-1; i++)
    {
        for (int j=i+1; j<N; j++)
        {
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            if (dx!=0)
            {
                dt[i][j] = 1.0*dy/dx;
                c[i][j] = y[i]-x[i]*dt[i][j];
            }
            else
            {
                dt[i][j] = INFINITY;
                c[i][j] = INFINITY;
            }
        }
    }

    for (int i=0; i<N-2; i++)
    {
        for (int j=i+1; j<N-1; j++)
        {
            for (int k=j+1; k<N; k++)
            {

                if (dt[i][j] == dt[i][k] && c[i][j] == c[i][k])
                {
                    /*
                    cout << "i: " << i << "  j: " << j << "  k: " << k << endl;
                    cout << "dtij: " << dt[i][j] << "  dtik: " << dt[i][k] << endl;
                    cout << "cij: " << c[i][j] << "  cik: " << c[i][k] << endl;
                    */
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
int main()
{
    ll a, b, w;
    cin >> a >> b >> w;
    w *= 1000;
    ll ans1 = 0;
    ll ans2 = 0;
    rep(i, 1000100)
    {
        if (a * i <= w && b * i >= w)
        {
            ans1 = i;
            break;
        }
    }
    rep(i, 1000100)
    {
        if (a * i <= w && b * i >= w)
        {
            ans2 = i;
        }
    }
    if (ans1 != 0 || ans2 != 0)
    {
        cout << ans1 << " " << ans2 << endl;
    }
    else
    {
        cout << "UNSATISFIABLE" << endl;
    }
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include <bitset>
// #include <atcoder/all>
#include <fstream>
#include <random>
#include <cassert>

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e16;
const ll INF = 1e16;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const long double PI = 3.1415926535897932;

using Graph = vector<vector<ll>>;

bool check(string s, string t)
{
	ll sz = 0, so = 0, tz = 0, to = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0') sz++;
		else so++;

		if (t[i] == '0') tz++;
		else to++;
	}

	if (sz == tz && so == to)
		return true;
	else
		return false;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(15);		// 15桁表示指定

	ll n;
	cin >> n;

	string s, t;
	cin >> s >> t;

	if (!check(s, t))
	{
		cout << -1 << endl;
		ret;
	}

	ll sc = 1;
	ll tc = 1;
	ll ans = 0;

	ll br = false;

	for (int i = 0; i < n; i++)
	{
		br = false;
		sc = max(sc, i + 1LL);
		tc = max(tc, i + 1LL);
		if (t[i] == s[i])
		{
			continue;
		}

		if (t[i] != s[i])
		{
			if (t[i] == '0')
			{
				for (; sc < n; sc++)
				{
					if (s[sc] == '0')
					{
						ans++;

						char tmp = s[i];
						s[i] = s[sc];
						s[sc] = tmp;
						sc++;
						br = true;
						break;
					}
				}
			}
			if (br)continue;
			if (s[i] == '0')
			{
				for (; tc < n; tc++)
				{
					if (t[tc] == '0')
					{
						ans++;

						char tmp = t[i];
						t[i] = t[tc];
						t[tc] = tmp;
						tc++;
						br = true;
						break;
					}
				}
			}
			if (br)continue;
		}
	}

	cout << ans << endl;

	return 0;
}