#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
#define int long long
#define ll long long
#define pii std::pair<int, int>
#define pdd std::pair<double, double>
#define INF (1LL << 33)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(p) \
    if (test)   \
        cout << #p " : " << p << endl;
bool test = false;
template <class T>
[[maybe_unused]] bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
int N, M;
vector<int> A, B;
vector<vector<int>> dp;
signed main()
{
    test = true;
    cin >> N >> M;
    A.resize(N);
    B.resize(M);
    for (auto& v : A) {
        cin >> v;
    }
    for (auto& v : B) {
        cin >> v;
    }
    dp.resize(N + 1);
    REP(i, N + 1)
    {
        dp.at(i).resize(M + 1, 0);
        REP(j, M + 1)
        {
            if (i == 0) {
                dp.at(i).at(j) = j;
            } else if (j == 0) {
                dp.at(i).at(j) = i;
            } else {
                dp.at(i).at(j) = dp.at(i - 1).at(j) + 1;
                chmin(dp.at(i).at(j), dp.at(i).at(j - 1) + 1);
                chmin(dp.at(i).at(j), dp.at(i - 1).at(j - 1) + (A.at(i - 1) == B.at(j - 1) ? 0 : 1));
            }
        }
    }
    cout << dp.at(N).at(M) << endl;

    return 0;
}

#include <bits/stdc++.h>
#define SIZE 200005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE];
int L[SIZE],R[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		A[i]--;
	}
	set <int> zan,need;
	for(int i=0;i+1<n;i++)
	{
		if(need.find(A[i])!=need.end()) need.erase(A[i]);
		else zan.insert(A[i]);
		if(zan.find(i)!=zan.end()) zan.erase(i);
		else need.insert(i);

		if(zan.size()!=1)
		{
			puts("-1");
			return 0;
		}
		L[i]=*zan.begin();
		R[i]=*need.begin();
		//printf("%d %d\n",L[i],R[i]);
	}
	queue <int> que;
	for(int i=0;i<n-1;i++)
	{
		if(A[i]==L[i]&&A[i+1]==R[i])
		{
			que.push(i);
		}
	}
	vector <int> vec;
	while(!que.empty())
	{
		int v=que.front();que.pop();
		vec.push_back(v);
		swap(A[v],A[v+1]);
		if(v>0&&L[v-1]==A[v-1]&&R[v-1]==A[v]) que.push(v-1);
		if(v<n-1&&L[v+1]==A[v+1]&&R[v+1]==A[v+2]) que.push(v+1);
	}
	if(vec.size()<n-1) puts("-1");
	else
	{
		for(int i=0;i<n-1;i++) printf("%d\n",vec[i]+1);
	}
}


#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, x;
    read(n, x);
    auto a = read_array<int>(n);
    for(auto y : a){
        if(y != x) write(y, " ");
    }
    write("\n");
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
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 (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// clang++ -std=c++11 -stdlib=libc++

int n, x;

int main() {
  cin >> n >> x;
  vi ans;
  rep(i, n) {
    int a;
    cin >> a;
    if (a == x)
      continue;
    ans.pb(a);
  }
  rep(i, ans.size()) {
    printf("%d%c\n", ans[i], i == ans.size() - 1 ? '\n' : ' ');
  }
  return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

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

	int N; cin >> N;
	VI P(N), pos(N);
	REP(i, N) {
		cin >> P[i];
		pos[P[i] - 1] = i;
	}
	VI A = P;
	SORT(A);

	VI ans;
	int now = 0;
	vector<bool>F(N, false);
	REP(i, N - 1) {
		//REP(i, N)cout << pos[i] << endl;
		//cout << endl;
		while (pos[now] <= now) {

			now++;
			if (now == N) {
				cout << -1 << endl;
				return 0;
			}
		}
		{
			if (!F[pos[now]]) {
				F[pos[now]] = 1;
				ans.push_back(pos[now]);
			}
			else {
				cout << -1 << endl;
				return 0;
			}

			pos[P[pos[now] - 1] - 1]++;
			pos[now]--;
		}
	}
	fore(i, ans) {
		swap(P[i - 1], P[i]);
	}

	if (A == P)fore(i, ans)cout << i << '\n';
	else cout << -1 << endl;
	return 0;
}

/*include&using-----------------------------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
/*debug-------------------------------------------------------------------------------*/
#define _GLIBCXX_DEBUG
#ifdef _DEBUG
#define debug(...) COUT(__VA_ARGS__)
#else
#define debug(...)
#endif
/*typename----------------------------------------------------------------------------*/
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using P = pair<T,T>;
template <class T> using M = map<T,T>;
template <class T> using S = set<T>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQG = priority_queue<T,V<T>,greater<T>>;
using ll = long long;
using st = string;
using vl = V<ll>;
using vvl = V<V<ll>>;
using vc = V<char>;
using vvc = V<V<char>>;
using vs = V<st>;
using vvs = V<V<st>>;
using vb = V<bool>;
using vvb = V<V<bool>>;
/*constant----------------------------------------------------------------------------*/
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
/*macro-------------------------------------------------------------------------------*/
#define re(n) for(ll _ = 0; _ < (ll) n; _++)
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define repp(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define bitrep(i,n) for(ll i = 0; i < (1<<(ll)n); i++)
#define each(x,A) for(auto &(x): (A))
#define all(A) A.begin(), A.end()
#define len(A) ll(A.size())
#define pb(a) push_back(a)
#define mp make_pair
#define pc cout << setprecision(15) << fixed
/*input-------------------------------------------------------------------------------*/
void CIN(){}
template <class Head,class... Tail>
void CIN(Head&& h,Tail&&... t){cin>>h; CIN(t...);}
#define CINL(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define CINS(...) string __VA_ARGS__;CIN(__VA_ARGS__)
#define CIND(...) double __VA_ARGS__;CIN(__VA_ARGS__)
/*output------------------------------------------------------------------------------*/
void COUT(){cout << endl;}
template <class Head, class... Tail>
void COUT(Head h, Tail... t){cout << h << " "; COUT(t...);}
/*function----------------------------------------------------------------------------*/
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
template <class T> T ceil(T a,T b){return (a+b-1)/b;}
template <class T> void chmax(T &a, const T& b){if(a<b){a=b;}}
template <class T> void chmin(T &a, const T& b){if(a>b){a=b;}}
template <class T> T gcd(T a,T b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
template <class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template <class T> T modpow(T x,T n,T mod){T res=1; for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
bool range(ll ny, ll nx, ll H, ll W) {if(ny < 0 || ny >= H || nx < 0 || nx >= W) return false; return true;}
/*------------------------------------------------------------------------------------*/

int main() {
    CINS(s);
    rep(i,len(s)){
        if(i%2==0 && !('a'<=s[i] && s[i]<='z')){
            COUT("No");
            return 0;
        }
        if(i%2==1 && !('A'<=s[i] && s[i]<='Z')){
            COUT("No");
            return 0;
        }
    }
    COUT("Yes");
}


#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int32_t main()
{
	int n,q;
	cin>>n>>q;
	ordered_set input;
	for(int i=0; i<n; i++)
	{
		int temp;
		cin>>temp;
		input.insert(temp);
	}
	while(q--)
	{
		int k;
		cin>>k;
		int ans=k;
		int less = input.order_of_key(ans+1);
		/*
			3 5 6 7
			k==5
			less = 2
			k==7
			less = 2
			k==9
			less = 0
		*/
		int prev = less;
		while(less!=0)
		{
			ans+=less;
			less = input.order_of_key(ans+1);
			int temp=prev;
			prev=less;
			less-=temp;
		}

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

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int n;
	int m;
	cin >> n >> m;
	vector <long long int> v;
	long long int a[m];
	for (int i = 0; i < m; i++) cin >> a[i];
	sort(a, a + m);
	if (m == 0) {
		cout << 1 << "\n";
	}
	else {
		for (int i = 0; i < m; i++) {
			if (i == 0) {
				long long int tmp = a[i] - 1;
				if (tmp) v.push_back(tmp);
			}
			else {
				long long int tmp = a[i] - a[i - 1] - 1;
				if (tmp) v.push_back(tmp);
			}
		}
		if (a[m - 1] != n) {
			v.push_back(n - a[m - 1]);
		}
		sort(v.begin(), v.end());
		if (v.size()) {
			long long int ans = 0;
			long long int tmp = v[0];
			for (auto i : v) {
				ans += (i + tmp - 1) / tmp;
			}
			cout << ans << "\n";
		}
		else cout << 0 << "\n";
	}
	return 0;
}


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

template <typename T>
struct point {
    T x, y;
    point() : x(), y() { }
    point(T x, T y) : x(x), y(y) { }

    point operator+() const { return *this; }
    point operator-() const { return point(-x, -y); }

    point &operator+=(const point &p) { return x += p.x, y += p.y, *this; }
    point &operator-=(const point &p) { return x -= p.x, y -= p.y, *this; }
    point &operator*=(const T &val) { return x *= val, y *= val, *this; }
    point &operator/=(const T &val) { return x /= val, y /= val, *this; }

    point operator+(const point &p) { return point(x + p.x, y + p.y); }
    point operator-(const point &p) { return point(x - p.x, y - p.y); }
    point operator*(const T &val) { return point(x * val, y * val); }
    point operator/(const T &val) { return point(x / val, y / val); }

    friend T dot(const point &a, const point &b) {
        return a.x * b.x + a.y * b.y;
    }

    friend point operator*(const T &val, const point &p) { return point(val * p.x, val * p.y); }

    bool operator==(const point &p) const {
        return x == p.x && y == p.y;
    }

    friend ostream &operator<<(ostream &os, const point &p) {
        return os << '(' << p.x << ',' << p.y << ')';
    }
};

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

    int n;
    cin >> n;

    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    int m;
    cin >> m;

    vector<point<long long>> pref_x(m + 1), pref_y(m + 1);
    vector<int> swaps(m + 1);

    pref_x[0] = pref_y[0] = {0, 1};
    for (int i = 1; i <= m; i++) {
        int t, p;
        cin >> t;
        pref_x[i] = pref_x[i - 1], pref_y[i] = pref_y[i - 1], swaps[i] = swaps[i - 1];
        if (t == 1) {
            swaps[i] ^= 1;
            swap(pref_x[i], pref_y[i]);
            pref_y[i] = -pref_y[i];
        } else if (t == 2) {
            swaps[i] ^= 1;
            swap(pref_x[i], pref_y[i]);
            pref_x[i] = -pref_x[i];
        } else if (t == 3) {
            cin >> p;
            pref_x[i] = point<long long>(2 * p, 0) - pref_x[i];
        } else {
            cin >> p;
            pref_y[i] = point<long long>(2 * p, 0) - pref_y[i];
        }
    }

    //1 = (y, -x)
    //2 = (-y, x)
    //3, (2p - x, y)
    //4, (x, 2p - y)

    int q;
    cin >> q;

    while (q--) {
        int a, b;
        cin >> a >> b, --b;
        if (!swaps[a]) {
            cout << pref_x[a].x + pref_x[a].y * x[b] << ' ';
            cout << pref_y[a].x + pref_y[a].y * y[b] << '\n';
        } else {
            cout << pref_x[a].x + pref_x[a].y * y[b] << ' ';
            cout << pref_y[a].x + pref_y[a].y * x[b] << '\n';
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

const int N = 1e5 + 1;
int arr[N], n;

double fun(double x){
    double ans =0 ;
    for(int i =0 ; i < n;  i++){
        ans += (x + (double)(arr[i]) - min((double)(arr[i]), 2.0*x));
    }
    return ans;
}

void solve()
{
    cin>> n;
    int mn = 1e9;
    for(int i =0 ; i < n;i ++){
        cin>> arr[i];
        mn = min(arr[i], mn);
    }
    double l = (double(mn) / 2.0), r = 1e9, e = 1e-7;
    while(r - l >= e){
        double m1 = l + (r - l) / 3;
        double m2 = r - (r - l) / 3;
        double v1 = fun(m1);
        double v2 = fun(m2);
        if(v1 > v2){
            l = m1;
        }else{
            r = m2;
        }
    }
    double x = r;
    double ans = fun(x) / (double(n));
    cout<< ans << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("Debug.txt", "w", stderr);
    #else
    #endif
    cout << fixed << setprecision(10);
    int _t =1;
    // cin>>_t;
    F(int, i, 1, _t, 1){
	// cout << "Case #" << i << ": ";
	solve();
    }
}


//https://atcoder.jp/contests/abc183/tasks/abc183_c
//C - Travel
#include <bits/stdc++.h>

using namespace std;

const int MAXN=10;
int nums[MAXN][MAXN];

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

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

    vector<int> idx(n+2);
    iota(idx.begin(), idx.end(), 0);
    idx[n+1]=1;
    int ans=0;
    do {
        int sum=0;
        for (i=2; i<=n+1; i++) {
            sum+=nums[idx[i-1]][idx[i]];
        }
        if (sum==k) {
            ans++;
        }
    } while (next_permutation(idx.begin()+2, idx.end()-1));

    cout<<ans<<"\n";

    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){

  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//cout<<""<<endl;
int main(){
  ll N,M;cin>>N>>M;
  vl H(N),W(M);
  rep(i,N)cin>>H[i];
  rep(i,M)cin>>W[i];
  sort(all(H));
  sort(all(W));
  vl wa1(N);
  vl wa2(N);
  wa1[0]=-H[0];
  wa2[0]=H[0];
  for(ll i=1;i<N;i++){
    if(i%2==1){
      wa1[i]=wa1[i-1]+H[i];
      wa2[i]=wa2[i-1]-H[i];
    }
    else{
      wa1[i]=wa1[i-1]-H[i];
      wa2[i]=wa2[i-1]+H[i];
    }
  }
  ll ans=1000000000000000;

  rep(i,M){
    ll cnt=0;
    auto iter =  lower_bound(all(H), W[i]);
    ll x= iter-H.begin();
    if(x%2==1){
      cnt+=W[i];
      cnt +=wa1[x-1]+wa2[N-1]-wa2[x-1];
    }
    else{
      cnt-=W[i];
      cnt +=wa1[x-1]+wa2[N-1]-wa2[x-1];
    }
    ans =min(ans,cnt);
  }
  cout<<ans<<endl;
}


/*問題番号：A*/

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

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

    if(N%100 == 0){
        cout << N/100 << endl;
    }
    else{
        cout << N/100 + 1 << endl;
    }
}

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

using ll = long long;

void Main() {
    // input
    ll N;
    cin >> N;

    // process

    // output
    cout << N - 1 << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
#define ll long long
#define for1(i,n,a,b) for(ll (i)=(n);(i)<=(a);(i)+=(b))
#define for2(i,n,a,b) for(ll (i)=(n);(i)>=(a);(i)-=(b))
ll a[1005];
int main()
{
	ll n;
	cin>>n;
	for1(i,1,n,1)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for1(i,2,n,1)
	{
		if(a[i]-a[i-1]!=1)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
// mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rng(int lim)
// {
//     uniform_int_distribution<int> uid(0, lim - 1);
//     return uid(rang);
// }
const int mod = 1'000'000'007;
//=======================================================================
int isPalindrome(string str)
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = str.size() - 1;

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            //printf("%s is Not Palindrome", str);
            return 0;
        }
    }
    return 1;
}
int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}
int getSum(int n)
{
    int sum = 0;
    while (n != 0)
    {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int countDigit(int n)
{
    if (n == 0)
        return 0;
    return 1 + countDigit(n / 10);
}
ll factorial(ll n)
{
    ll res = 1, i;
    for (i = 2; i <= n; i++)
        res *= ((i * 1LL) % mod);
    return res;
}

//----------------------------------------------------------------------------
int main()
{
    // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    ll i, j, n, a[100000], count = 0, sum = 0;

    unordered_set<int> s;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> j;
        s.insert(j);
    }
    if (s.size() == n)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << endl
#define hh cout << endl
#define INF 1e18
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

template <typename C,
          typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
          typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto &x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}

ll mod_pow(ll a, ll b)
{
    if (b < 0)
        return 0;
    a %= mod;
    if (b == 0)
        return 1;
    if (b == 1)
        return a % mod;
    if (b == 2)
        return ((a % mod) * (a % mod)) % mod;
    return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod;
}

bool isPrime(int n)
{
    if (n == 1)
        return false;
    if (n == 2)
        return true;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

// Keep calm and Keep coding //

void solve()
{
    int n, m;
    cin >> n;

    int a = ceil((sqrt(1 + 8 * n) - 1) / 2.0);
    cout << a;
    hh;
    return;
}

int32_t main()
{
    fast int tc = 1;
    // cin >> tc;
    while (tc--)
    {
        solve();
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int i = a; i <= (n); ++i)
#define repD(i, a, n) for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll m = 998244353;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	ll a,b,c; cin >> a >> b >> c;
	ll ans = 1;
	a = a*(a+1)/2;
	b = b*(b+1)/2;
	c = c*(c+1)/2;
	a %= m;
	b %= m;
	c %= m;
	ans = (ans*a)%m;
	ans = (ans*b)%m;
	ans = (ans*c)%m;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;

vector<int> v = {1, 1, 2, 6, 24};
int ans = 0;
vector<int> v1;
int n;

void fun(int x, int c, vector<int> a)
{
  if(c == 4)
  {
    int t1 = 24;
    for(int i = 0; i < 10; i++)
      t1 /= v[a[i]];
    ans += t1;
    return;
  }
  if(x >= n | c > 4)
    return;
  fun(x+1, c, a);
  a[v1[x]]++;
  fun(x+1, c+1, a);
  a[v1[x]]++;
  fun(x+1, c+2, a);
  a[v1[x]]++;
  fun(x+1, c+3, a);
  a[v1[x]]++;
  fun(x+1, c+4, a);
  a[v1[x]] -= 4;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << setprecision(20) << fixed;

	string s;
	cin >> s;
	int c = 0;
	int i = 0;
	vector<int> a(10, 0);
	for(char x : s)
  {
	  if(x == 'o')
	  {
	    c++;
	    a[i]++;
	  }
	  if(x == 'o' || x == '?')
	   v1.push_back(i);
	 i++;
  }
  n = v1.size();
	fun(0, c, a);
	cout << ans << endl;

	return 0;
}

/*
	Author : $%U%$
	Time : $%h%$:$%m%$:$%s%$, $%D%$/$%M%$/$%Y%$
*/

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

using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

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

// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
	return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(it); } // element that doesn't exist from (multi)set

#define el '\n'

void solve()
{
	str st; cin>>st;
    int ans = 0;
    for(int i=0;i<=9999;i++)
    {
        bool arr[10];
        memset(arr,false,sizeof(arr));
        int temp = i;
        for(int j=0;j<4;j++)
        {
            arr[temp%10] = true;
            temp /= 10;
        }
        bool flag = true;
        for(int j=0;j<10;j++)
        {

            if(st[j]=='o' and !arr[j]) flag = false;
            if(st[j]=='x' and arr[j]) flag = false;
        }
        ans += flag;
    }
    cout<<ans;

}

int main()
{
    cin.tie(0)->sync_with_stdio(0);

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

}


#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define rep0(i,n) for ((i)=0;(i)<(n);(i)++)
using namespace std;
long long n,m,s,i;
vector<int> ans;
long long gcd(long long x,long long y){
	if(!y) return x;
	long long t=gcd(y,x%y);
	s+=x/y;return t;
}
void print(long long x,long long y){
	if(!x){
		while(y--)ans.push_back(2);
		return;
	}
	if(!y){
		while(x--)ans.push_back(1);
		return;
	}
	if(x>y){
		while(x>=y){
			ans.push_back(3);
			x-=y;
		}
	}
	else{
		while(x<=y){
			ans.push_back(4);
			y-=x;
		}
	}
	print(x,y);
}
int main(){
	srand(time(NULL));
	cin>>n;
	for(;;){
		m=(rand()+rand()*65536ll+rand()*65536ll*65536ll/*+rand()*65536ll*65536ll*65536ll*/)%n;
		s=0;
		long long g=gcd(n,m);
		if(s+g>130) continue;
		print(n,m);
		printf("%d\n",ans.size());reverse(ans.begin(),ans.end());
		rep0(i,ans.size())printf("%d\n",ans[i]);
		return 0;
	}
	return 0;
}

#include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll               long long
#define lll              __int128
#define ull              unsigned ll
#define ld               long double
#define pb               push_back
#define pf               push_front
#define dll              deque<ll>
#define vll              vector<ll>
#define vvll             vector<vll>
#define pll              pair<ll,ll>
#define vpll             vector<pll>
#define dpll             deque<pll>
#define mapll            map<ll,ll>
#define umapll           umap<ll,ll>
#define endl             "\n"
#define all(v)           v.begin(),v.end()
#define ms(a,x)          memset(a,x,sizeof(a))
#define random(l,r,T)    uniform_int_distribution<T>(l,r)(rng)

//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;

template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;

int32_t main()
{
    clock_t clk = clock();
    fast_az_fuk
    string s; cin>>s; deque<char> ans; ans.pb(s[0]); bool back=1; if(s[0] == 'R') {ans.pop_back();} s.erase(s.begin());
    for(char c : s){
        if(c == 'R') back = 1 - back;
        else {
            if(back){
                ans.pb(c);
            }
            else{
                ans.pf(c);
            }
        }
    }
    if(!back) reverse(all(ans));
    string final; ll n = ans.size(); final += '?';
    for(ll i=0;i<n;i++){
        if(final.back() == ans[i]){
            final.pop_back();
        }
        else final += ans[i];
    }
    final.erase(final.begin());
    cout<<final;
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <fstream>
#include <iostream>

#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>

#define all(container) (container).begin(), (container).end()
#define sz(container) static_cast<int>((container).size())

using namespace std;

class Solver {
public:
  void solve(istream& in, ostream& out) {
    out.precision(20);

    int tests;
    cin >> tests;
    for (int test = 1; test <= tests; test++) {
      solveOne(in, out);
    }
  }

private:
  void solveOne(istream& in, ostream& out) {
    const string t = "atcoder";

    string s;
    cin >> s;

    if (t < s) {
      out << 0 << endl;
      return;
    }

    string worst = s;
    sort(all(worst));
    reverse(all(worst));

    if (worst <= t) {
      out << -1 << endl;
      return;
    }

    int answer = sz(s);
    int n = sz(s);
    int m = min(sz(s), sz(t));
    for (int to = 0; to < m; to++) {
      for (int from = 0; from < n; from++) {
        swap(s[to], s[from]);
        if (t < s) {
          answer = min(answer, abs(to - from));
        }
        swap(s[to], s[from]);
      }
    }
    cout << answer << endl;
  }
};

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

  Solver solver;
  solver.solve(cin, cout);

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n, m;
string s, t="atcoder";
int solve(int w) {
	string p = s;
	int ans = 0;
	for (int i=0; i<w; ++i) {
		int ok = 0;
		for (int j=i; j<n; ++j) {
			if (p[j]==t[i]) {
				for (int k=j; k>i; --k) swap(p[k],p[k-1]);
				ans += j-i;
				ok = 1;
				break;
			}
		}
		if (!ok) return 100000;
	}
	for (int i=w; i<n; ++i) {
		auto tmp = p;
		for (int k=i; k>w; --k) swap(p[k],p[k-1]);
		if (p>t) return ans+i-w;
		p = tmp;
	}
	return 100000;
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		cin >> s;
		n = s.size();
		m = t.size();
		int ans=1e9;
		for (int i=0; i<min(n,m-1); ++i) {
			ans = min(ans, solve(i));
		}
		if (ans>1000) ans=-1;
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const ll mod = 1e9+7;

main(){
    ll a,b;cin>>a>>b;
    ll now = 2*a + 100;
    cout<<now-b;
}

/*

    I am the Best of The World

    Nafis_Cruciatus

*/

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

/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    is;*/

#define fb find_by_order
#define ok order_of_key

typedef long long ll;
typedef int ii;

#define INF 10000000000000007
#define pi 3.141592654

#define T while(t--)
#define for2(i,a,b) for(i=a;i>=b;i--)
#define for3(i,a,b) for(i=a;i<=b;i=i+2)
#define for1(i,a,b) for(i=a;i<=b;i=i+1)

#define pb push_back
#define mp make_pair

#define ff first
#define ss second

#define si set<ll>
#define se multiset<ll>

typedef long double ld;
typedef vector<ll> vi;

#define all(v) sort(v.begin(),v.end())
#define all1(v) sort(v.rbegin(),v.rend())

#define pf(uuv) printf("%lld\n",uuv)

#define pf1(uu) printf("%.20Lf\n",uu)

ii main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    //cin>>t;
    while(t--){
        ll a,b; cin>>a>>b;
        cout<<((2*a)+100)-b<<"\n";

    }

}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int used[111];

vector<int> v[111];
void dfs(int x){
    used[x]=1;
    for(auto to: v[x]){
        if(used[to])continue;
        dfs(to);
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s[n];
    rep(i,n)cin>>s[i];
    rep(i,n)rep(j,n){
        if(s[i][j]=='1'){
            v[j].push_back(i);
        }
    }
    long double ans = 0;
    rep(i,n){
        rep(i,n)used[i]=0;
        dfs(i);
        int cnt = 0;
        rep(i,n)cnt+=used[i];
        ans+= (long double)1.0 / cnt;
    }
    cout<<fixed<<setprecision(15)<<ans<<endl;
    return 0;
}

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

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define f first
#define s second
#define ar array
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(X) ((int)(X).size())
#define rsz resize
#define pcnt __builtin_popcount
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define ms(c, x)  memset(c,x,sizeof c)
#define  No(x) cout<<(x?"NO":"No")<<endl;
#define  Yes(x) cout<<(x?"YES":"Yes")<<endl;
#define  nl cout<<endl;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = l; i <r; i++)
#define fored(i, l, r) for(int i = r-1; i >=l; i--)
#define ford(i, n) for (int i = n - 1; i >= 0; --i)
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

template<typename T>
using osl = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using osg = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
// for greater use greater<T>
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out << x << " ";
    }
    out << "\n";
    return out;
}

template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out + x;
    }
    return out;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &vec) {
    for (auto &x : vec) {
        in >> x;
    }
    return in;
}

template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }

template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL

void debug() { cerr << endl; }

template<class T, class... Args>
void debug(const T &t, const Args &... args) {
    cerr << t << " ";
    debug(args...);
}

#define dbg(...) {cerr<<__LINE__<<" [[DEBUG]] ";debug(__VA_ARGS__);};
#else
#define dbg(...) void(0)
#endif
const ll mod = 1e9 + 7;
//const int mod = 998244353;
const ll INF = 1e17 + 6;

inline ll power(ll x, ll y) {
    ll res = 1;
    x = x;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int MXN = 2e5 + 5;

void solve() {
    int n;
    cin>>n;
    vector<vi>a(n,vi(n));
    forn(i,n){

        string s;
        cin>>s;
        forn(j,n){
            a[i][j]=s[j]-'0';
        }
        a[i][i]=1;
    }
    forn(k,n)forn(i,n)forn(j,n){
        a[i][j]|=a[i][k]&&a[k][j];
    }
    long double ans=0;
    forn(i,n){
        int d=0;
        forn(j,n){
            d+=a[j][i];
        }
        ans+=(long  double)1/d;
    }
    cout<<ans<<endl;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1, tc = 1;
//    cin >> t;
    while (t--) {
//        cout<<"Case #"<<tc<<": " ;
        solve();
        tc++;
    }
#ifdef LOCAL
    cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
    return 0;
}
//look if it requires ll


/*
problem :
algorithm :
created : Programmer_juruo
*/

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

#define int long long
#define N 2000005
#define M 2005
#define lowbit(x) x & (-x)
#define F1(i, n) for(int i = 1; i <= n; i++)
#define F(i, a, n) for(int i = a; i <= n; i++)
#define F0(i, n) for(int i = 0; i < n; i++)
#define dbg(x) cout << #x << ":" << x << endl;
#define se second
#define fi first
#define y1 juruo
#define mp make_pair
#define pb push_back
#define arr vector<int>
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

typedef pair <int, int> pii;
typedef priority_queue <int> pq;
typedef long long ll;

const int inf = 0x3f3f3f3f;
const int p = 107;
const int P = 100007;
const int Mod = 1e9+7;

int n, m;

void work() {
	cin >> n >> m;
	cout << (m-1) + (100*m+n-1) / n <<endl;
}

signed main() {
  //freopen("1.in", "r", stdin);
  //freopen("1.out", "w", stdout);
  int T = 1;

  //cin >> T;

  while(T--) {
  	work();
  }

  return 0;
}

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

 #define dbg(x) cout<<x<<ln
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int main()
{
fast_cin();
ll a[3];
rep(i,3)
{
    cin>>a[i];

}  sort(a,a+3);
cout<<a[2]+a[1];
return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

    string S;
    cin >> S;
    queue<int> I;
    for (ll i = 0; i < N; ++i) {
        if (S[i] == '1') {
            I.emplace(i);
        }
    }

    string T;
    cin >> T;
    vector<int> E;
    for (ll i = 0; i < N; ++i) {
        if (T[i] == '1') {
            E.emplace_back(i);
        }
    }

    ll E_size = E.size();
    ll I_size = I.size();
    if ((E_size - I_size) % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    ll I_first;
    ll I_second;
    for (auto E_num : E) {
        if (I.empty()) {
            cout << -1 << endl;
            return 0;
        }
        I_first = I.front();
        I.pop();
        while (I_first < E_num) {
            if (I.empty()) {
                cout << -1 << endl;
                return 0;
            }
            I_second = I.front();
            I.pop();
            ans += I_second - I_first;

            if (I.empty()) {
                cout << -1 << endl;
                return 0;
            }
            I_first = I.front();
            I.pop();
        }
        ans += I_first - E_num;
    }

    while (!I.empty()) {
        I_first = I.front();
        I.pop();
        I_second = I.front();
        I.pop();
        ans += I_second - I_first;
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    string S, T; cin >> S >> T;
    //1101100011100
    //0100101010100
    queue<int> T_one;
    ll ans = 0;
    rep(i, N){
        //cout << i << endl;
        if(T[i] == '1') T_one.push(i);
        if(S[i] == '1' && T_one.empty()){
            int old_i = i;
            i++;
            while(i < N && S[i] == '0'){
                if(T[i] == '1') T_one.push(i);
                i++;
            }
            if(T[i] == '1') T_one.push(i);
            ans += i-old_i;
        }
        else if(S[i] == '1'){
            int aim = T_one.front();
            T_one.pop();
            ans += i-aim;
        }
    }
    if(T_one.empty()) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fin(a) { cout << a << endl; return 0; }
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using ld = long double;
using P = pair<int,int>;
using Pl = pair<lint,lint>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << '{' << p.first << ',' << p.second << '}';
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e : v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e : v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

template<class T>
vector<T> Dijkstra(int s, const vector<vector<pair<T,int>>> &g, vector<int> prev = {}) {

    using pi = pair<T,int>;
    const T inf = numeric_limits<T>::max()/2;
    vector<T> dist(g.size(), inf);
    dist[s] = 0;

    prev.assign(dist.size(), -1);

    priority_queue<pi, vector<pi>, greater<pi>> que;
    que.emplace(0,s);

    while(!que.empty()) {
        P p = que.top(); que.pop();
        int now = p.second;
        if(dist[now] < p.first) continue;
        for(P np : g[now]) {
            int next = np.second;
            if(dist[next] > dist[now] + np.first) {
                prev[next] = now;
                dist[next] = dist[now] + np.first;
                que.emplace(dist[next], next);
            }
        }
    }
    return dist;
}

const int inf = INF;

int main(){
    int n, m;
    cin >> n >> m;
    V<V<P>> g(n*2);
    rep(i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].emplace_back(c,b+n);
        g[a+n].emplace_back(0,a);
    }

    rep(i,n) {
        auto dist = Dijkstra(i,g);
        int ans = dist[i+n];
        if(ans == inf) ans = -1;
        cout << ans << endl;
    }
}

// Problem : D - Takahashi Unevolved
// Contest : AtCoder - AtCoder Beginner Contest 180
// URL : https://atcoder.jp/contests/abc180/tasks/abc180_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;

typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;

typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;

#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll x,y,a,b;
	cin>>x>>y>>a>>b;
	y--;
	ll cnt=0;
	while((ll)(x)<(ll)(b/(a-1)) && y>x){
		cnt++;
		x*=a;
	//	bug(x);
	}
//	cout<<cnt<<cl;
	cnt+=(y-x)/b;
	cout<<cnt;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


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

int main() {
  vector<int> tileID(50 * 50);
  vector<int> steped(50 * 50);
  int x, y;
  string ans = "";
  cin >> y >> x;
  rep(i,50 * 50) {
    cin >> tileID[i];
  }
  steped[0] = tileID[50 * y + x];
  int i = 0;
  while(true) {
    steped[i] = tileID[50 * y + x];
    if (*find(steped.begin(), steped.end(), tileID[50 * (y - 1) + x]) != tileID[50 * (y - 1) + x] && y != 0) {
      y -= 1;
      ans += 'U';
    } else if (*find(steped.begin(), steped.end(), tileID[50 * y + x - 1]) != tileID[50 * y + x - 1] && x != 0) {
      x -= 1;
      ans += 'L';
    } else if (*find(steped.begin(), steped.end(), tileID[50 * (y + 1) + x]) != tileID[50 * (y + 1) + x] && y != 49) {
      y += 1;
      ans += 'D';
    } else if (*find(steped.begin(), steped.end(), tileID[50 * y + x + 1]) != tileID[50 * y + x + 1] && x != 49) {
      x += 1;
      ans += 'R';
    } else {
      break;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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; }

//==================param==========
ll depth = 10;
//=================================

ll si, sj;
vector<vector<ll>> board(50, vector<ll>(50));
vector<vector<ll>> point(50, vector<ll>(50));
map<ll, bool> already;
vector<char> way_char = {'R', 'D', 'L', 'U'};
vector<vector<ll>> ways = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
stack<ll> max_ans;
stack<ll> ans;
ll max_point = 0;
ll now_point = 0;
clock_t start;

void get_input() {
  cin >> si >> sj;
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> board.at(i).at(j);
    }
  }
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> point.at(i).at(j);
    }
  }
  already[board.at(si).at(sj)] = true;
}

bool can_move(ll way) {
  ll nh = si + ways.at(way).at(0), nw = sj + ways.at(way).at(1);
  if (nh < 0 || nw < 0 || nh >= 50 || nw >= 50) {
    return false;
  }
  if (already[board.at(nh).at(nw)]) {
    return false;
  }
  return true;
}

void make_move(ll way) {
  si += ways.at(way).at(0), sj += ways.at(way).at(1);
  already[board.at(si).at(sj)] = true;
  ans.push(way);
  now_point += point.at(si).at(sj);
  if (now_point > max_point) {
    max_ans = ans;
    max_point = now_point;
  }
}
void rev_move() {
  ll way = ans.top();
  ans.pop();
  now_point -= point.at(si).at(sj);
  already[board.at(si).at(sj)] = false;
  si -= ways.at(way).at(0), sj -= ways.at(way).at(1);
}

ll cnt = 0;
bool fin = false;
void dfs() {
  if (fin) {
    return;
  }
  cnt += 1;
  if (cnt % 1000 == 0) {
    clock_t end = clock();
    ld time = (ld)(end - start) / CLOCKS_PER_SEC * 1000.0;
    if (time > 1900) {
      fin = true;
      return;
    }
  }
  for (ll i = 0; i < 4; ++i) {
    if (can_move(i)) {
      make_move(i);
      dfs();
      rev_move();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  start = clock();
  get_input();
  dfs();
  string s_ans = "";
  while (!max_ans.empty()) {
    s_ans += way_char.at(max_ans.top());
    max_ans.pop();
  }
  reverse(rng(s_ans));
  cout << s_ans << "\n";
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int k = ri();
	int m = ri();

	auto add = [&] (int &a, int b) {
		a += b;
		if (a >= m) a -= m;
	};

	std::vector<std::vector<int> > dp(n + 1);
	dp[0] = { 1 };
	for (int i = 1; i < n; i++) {
		dp[i].resize(dp[i - 1].size() + k * i);
		for (int j = 0; j < (int) dp[i - 1].size(); j++) {
			int cur = dp[i - 1][j];
			add(dp[i][j], cur);
			if (j + (k + 1) * i < (int) dp[i].size()) add(dp[i][j + (k + 1) * i], m - cur);
		}
		for (int j = 0; j + i < (int) dp[i].size(); j++) add(dp[i][j + i], dp[i][j]);
	}

	/*
	for (auto i : dp) {
		for (auto j : i) std::cerr << j << " ";
		std::cerr << std::endl;
	}*/

	for (int i = 0; i < n; i++) {
		auto &r0 = dp[i];
		auto &r1 = dp[n - 1 - i];
		int res = 0;
		for (int j = 0; j < (int) r0.size() && j < (int) r1.size(); j++) res = (res + (int64_t) r0[j] * r1[j]) % m;
		res = ((int64_t) res * (k + 1)) % m;
		if (--res < 0) res += m;
		printf("%d\n", res);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 102;

int n, k, mod;
int dp[N][N * N * N];
int acc[N];

int main()
{
  cin >> n >> k >> mod;
  dp[0][0] = 1;
  int mxs = k * n * (n - 1) / 2;
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < i; j++)
      acc[j] = 0;
    for(int j = 0; j <= mxs; j++) {
      acc[j % i] += dp[i - 1][j];
      if(j - (k + 1) * i >= 0) {
        acc[j % i] -= dp[i - 1][j - (k + 1) * i];
      }
      acc[j % i] %= mod;
      dp[i][j] = (acc[j % i] % mod + mod) % mod;
    }
  }

  for(int m = 1; m <= n; m++) {
    int ans = -1;
    for(int sum = 0; sum <= mxs; sum++) {
      ans += 1LL * dp[m - 1][sum] * dp[n - m][sum] % mod * (k + 1) % mod;
      ans %= mod;
    }
    ans = (ans + mod) % mod;
    cout << ans << endl;
  }

  return 0;
}


#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void pr(pair<ll,ll> p){
	cout << "[" << p.ff << ", " << p.ss << "]\n";
}
void pr(set<pair<ll,ll>> s){
	for(auto u : s){
		pr(u);
	}
}
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	fast;
	ll T = 1, i, j;

	//cin >> T;
	while (T--) {
		ll n;
		cin >> n;
		string s, t;
		cin >> s >> t;
		ll ca = 0;
		for(auto u : s){
			ca += (u - '0');
		}
		//cout << ca << endl;
		for(auto u : t){
			ca -= (u - '0');
		}
		if(ca != 0){
			cout << -1;
			return 0;
		}
		vector<ll> a, b;
		for(i =0 ; i < n; i++){
			if(s[i] == '0'){
				a.pb(i);
			}
			if(t[i] == '0'){
				b.pb(i);
			}
		}
		ll ans = 0;
		for(i = 0; i < a.size(); i++){
			ans += (a[i] != b[i])
;		}
		cout << ans << endl;
	}
	return 0;
}

#include <bits/stdc++.h>

#define N 500005

using namespace std;

char A[N], B[N];

set<int>st[2];

int C[N], D[N];

int ans = 0;

int main()
{
	int n;
	scanf("%d", &n);
	scanf("%s", A);
	for (int i = 0; i < n; ++i) if (A[i] == '0') C[++C[0]] = i;
	scanf("%s", B);
	for (int i = 0; i < n; ++i) if (B[i] == '0') D[++D[0]] = i;
	if (C[0] != D[0]) puts("-1");
	else
	{
		for (int i = 1; i <= C[0]; ++i) if (C[i] != D[i]) ++ans;
		printf("%d\n", ans);
	}
}


#include<bits/stdc++.h>

typedef long double db;

db slope(int x1,int y1,int x2,int y2){return 1.0*(y1-y2)/(x1-x2);}

int main(){
	int n,D,H;
	std::cin>>n>>D>>H;
	db min=INFINITY;
	for(int i=0;i<n;++i){
		int d,h;
		std::cin>>d>>h;
		min=std::min(min,slope(d,h,D,H));
	}
	std::cout<<std::max((db)0,H-min*D)<<std::endl;
	return 0;
}

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

int main(){
  int n, k, m;
  cin >> n >> k >> m;
  int a, sum=0;
  rep(i, n-1){
    cin >> a;
    sum += a;
  }
  int m2 = m*n;
  int dif = m2 - sum;
  if(dif > k) cout << -1 << endl;
  else if(dif < 0) cout << 0 << endl;
  else cout << dif << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  sort(A.begin(), A.end());
  ld x;
  if (N % 2 == 0)
    x = (A.at(N / 2 - 1) + A.at(N / 2)) / 4.0L;
  else
    x = A.at(N / 2) / 2.0L;

  ld ans = N * x + accumulate(A.begin(), A.end(), 0LL);
  for (ll i = 0; i < N; i++)
  {
    ans -= min((ld)A.at(i), 2 * x);
  }
  ans /= N;
  cout << fixed << setprecision(15) << ans << endl;
}

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

int lcm(int a, int b){
    int lcm = 0, m = min(a, b);
    for (int i = m; i > 0; i--){
        if (a%i==0 && b%i==0){
            lcm = i;
            break;
        }
    }
    return lcm;
}

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

    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int LCM = A[0];
    for (int i = 1; i < N; i++){
        LCM = lcm(A[i], LCM);
    }

    cout << LCM;
}


#include <bits/stdc++.h>

#define Mod 998244353

using namespace std;

typedef long long ll;

inline int read() {
	int out = 0;
	bool flag = false;
	register char cc = getchar();
	while (cc < '0' || cc > '9') {
		if (cc == '-') flag = true;
		cc = getchar();
	}
	while (cc >= '0' && cc <= '9') {
		out = (out << 3) + (out << 1) + (cc ^ 48);
		cc = getchar();
	}
	return flag ? -out : out;
}

inline void write(int x, char ch) {
	if (x < 0) putchar('-'), x = -x;
	if (x == 0) putchar('0');
	else {
		int num = 0;
		char cc[22];
		while (x) cc[++num] = x % 10 + 48, x /= 10;
		while (num) putchar(cc[num--]);
	}
	putchar(ch);
}

int fpow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = 1ll * res * x % Mod;
		x = 1ll * x * x % Mod;
		y >>= 1;
	}
	return res;
}

int n, m, ans = 1; char col[1010], s[510][510];

int main() {
	n = read(), m = read();
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	for (int i = 2; i <= n + m; i++) col[i] = '.';
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] == '.') continue;
			if (col[i + j] == '.') col[i + j] = s[i][j];
			else if (col[i + j] != s[i][j]) return puts("0"), 0;
		}
	}
	for (int i = 2; i <= n + m; i++) if (col[i] == '.') ans = ans * 2 % Mod;
	cout << ans << endl;
	return 0;
}

// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL MOD = 998244353;
int board[1010][1010]; // マスの色(0: 色なし, 1: 赤, 2: 青).
int cnt[1010][3];      // 出現回数(0: 色なし, 1: 赤, 2: 青).

int main(){

    // 1. 入力情報.
    int H, W;
    scanf("%d %d", &H, &W);
    rep(i, H){
        char c[505];
        scanf("%s", c);
        rep(j, W){
            if(c[j] == 'R') board[i][j] = 1;
            if(c[j] == 'B') board[i][j] = 2;
        }
    }

    // 2. 右上から左下に向かって, マスの色を確認.
    rep(k, H + W - 1){
        rep(i, H + W - 1){
            int j = k - i;
            if(j >= 0) cnt[k][board[i][j]]++;
            else       break;
        }
    }
    // rep(i, H + W - 1) printf("n=%d r=%d b=%d\n", cnt[i][0], cnt[i][1], cnt[i][2]);

    // 3. 色なしのみをカウント.
    // -> 赤, 青が混在している場合は, 着色不可能と判定.
    // -> 開始地点, 終了地点も, '.' となる場合があるので, 注意.
    LL ans = 1;
    int noColor = 0;
    rep(i, H + W - 1){
        if(cnt[i][1] && cnt[i][2])   ans = 0;
        if(!cnt[i][1] && !cnt[i][2]) noColor++;
    }

    // 4. 塗り方の総数は？
    rep(i, noColor) ans <<= 1, ans %= MOD;

    // 5. 出力.
    printf("%lld\n", ans);
    return 0;

}


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

int main() {

  int T;
  cin>>T;

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

    int64_t L,R;
    cin>>L>>R;

    int64_t A=R-L*2+1;

    if(A<1) cout<<0;
    else{
      cout<<A*(A+1)/2;
    }
    cout<<endl;

  }

}

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

void solve() {
    ll l, r;
    cin >> l >> r;

    ll ans;

    if (2 * l <= r)
        ans = (r - 2 * l + 2) * (r - 2 * l + 1) / 2;
    else
        ans = 0;

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

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

    while (t--)
        solve();

    return 0;
}


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

// loops
#define fora(i,a,b) for(int i=a;i<=b;++i)
#define forb(i,a,b) for(int i=a;i>=b;--i)
#define forc(i,a,b) for(int i=a;i<b;++i)
#define For(x,y) for(auto x : y)

// data structure
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
const int N = 2005;
int a[N];
int n;
map<int,int> mp;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	fora(i,1,n){
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	fora(i,1,n){
		for(int j = 1;j * j <= a[i];++j){
			if (a[i] % j == 0){
				mp[j] = __gcd(mp[j],a[i]);
				mp[a[i]/j] = __gcd(mp[a[i]/j],a[i]);
			}
		}
	}
	int ans = 0;
	For(x,mp){
		if (x.fi > a[1]) break;
		if (x.fi == x.se) ++ans;
	}
	cout << ans << "\n";
}

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

bool check(int k, int n, vector<int> &v)
{
    vector<int> vk;
    for (int x: v)
    {
        if (x%k == 0)
            vk.push_back(x);

        if (k > x)
            return false;
    }

    if (vk.size() == 0)
        return false;

    int G = vk[0];
    for (int x: vk)
        G = __gcd(G, x);

    if (G != k)
        return false;

    return true;
}

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

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

    set<int> possibles;
    for (int i=0; i<n; i++)
    {
        int x = v[i];
        for (int i=1; i*i<=x; i++)
            if (x%i == 0)
                possibles.insert(i), possibles.insert(x/i);
    }

    int sum = 0;
    for (int x: possibles)
        sum += check(x, n, v);

    cout << sum << '\n';
}


#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int t, n;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    for(int cases = 0; cases < t; cases++)
    {
        cin >> n;
        string s;
        for(int i = 0; i < 3; i++)
            cin >> s;
        for(int i = 0; i < n; i++)
            cout << "0";
        for(int i = 0; i < n; i++)
            cout << "1";
        cout << "0\n";
    }
    return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <cassert>
#include <queue>
#include <cstring>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
//#define int long  long

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;

const int inf = 1e9 + 228;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-14;

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("stones.in", "r", stdin);
//    freopen("stones.out", "w", stdout);
}

void solve(){
    int n, x;
    cin >> n >> x;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a != x)
            cout << a << " ";
    }
}

signed main(){
     fast_io();
//  srand(time(NULL));
    cout << fixed << setprecision(10);
    int q = 1;
//    cin >> q;
    while(q--)
        solve();
}


    /**   Created by: Humberto Yusta
          Codeforces User: humbertoyusta
          Country: Cuba                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline","03") // Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero=upper") // Enable AVX
//#pragma GCC target("avx2") // Enable AVX
//#pragma comment(linker, "/STACK:1024000000,1024000000") // Increase stack limit
//#pragma GCC target("sse,sse2,sse,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // I don't know what it is
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 1000010;
const int mod = 1000000007;
const int mod2 = 998244353;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 1ll * mod * mod;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return pwur * pwur % mod;
}
int modinv(int x){ return qpow(x,mod-2); }
bool isprime(int x){
    for(int i=2; i*i<=x; i++)
        if( x % i == 0 )
            return false;
    return true;
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);

    vector<int> pr;
    for(int i=2; i<=50; i++){
        if( isprime(i) )
            pr.pb(i);
    }

    int n;
    cin >> n;

    vector<int> a(n+2);
    for(int i=1; i<=n; i++)
        cin >> a[i];

    int ans = -1;
    for(int i=0; i<(1<<(pr.size())); i++){
        int curr = 1;
        for(int j=0; j<pr.size(); j++){
            if( i & (1<<j) )
                curr *= pr[j];
        }
        bool can = 1;
        for(int j=1; j<=n; j++){
            if( __gcd( curr , a[j] ) == 1 )
                can = 0;
        }
        if( can ){
            if( ans == -1 ) ans = curr;
                else ans = min( ans , curr );
        }
    }

    cout << ans << '\n';

    return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    vector<long long> a(n);
    for (long long &x : a)
        scanf("%lld", &x);

    long long ans = LONG_LONG_MAX;
    vector<long long> nums = {2,
                              3,
                              5,
                              7,
                              11,
                              13,
                              17,
                              19,
                              23,
                              29,
                              31,
                              37,
                              41,
                              43,
                              47};
    int m = nums.size();
    function<void(int, long long)> f = [&](int k, long long h) {
        if (k == m)
        {
            for (long long x : a)
            {
                if (__gcd(x, h) == 1)
                    return;
            }
            ans = min(ans, h);
        }
        else
        {
            f(k + 1, h);
            f(k + 1, h * nums[k]);
        }
    };
    f(0, 1);
    printf("%lld", ans);
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)

ll INF = 1ll << 60;

// UnionFind木
const int MAX = 200010;
int par[MAX], c[MAX];
map<int,int> m[MAX];

void init(){
  rep(i, 0, MAX){
    par[i] = -1;
    m[i][c[i]] = 1;
  }
}

int root(int x){
  if(par[x] < 0){
    return x;
  }
  return par[x] = root(par[x]);
}

int size(int x){
  return -par[root(x)];
}

void unite(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx == ry){
    return;
  }
  if(size(rx) < size(ry)){
    swap(rx, ry);
  }
  for(auto [key,value]:m[ry]){
    if(m[rx].count(key))
      m[rx][key] += value;
    else
      m[rx][key] = value;
  }
  par[rx] += par[ry];
  par[ry] = rx;
  return;
}

bool same(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx < 0 || ry < 0){
    if(rx >= 0){
      return rx == y;
    }
    if(ry >= 0){
      return ry == x;
    }
    return false;
  }
  return rx == ry;
}

int main(){
  int n, q;
  cin >> n >> q;
  rep(i, 0, n){
    cin >> c[i];
    c[i]--;
  }

  init();

  rep(i, 0, q){
    int t, a, b;
    cin >> t >> a >> b;
    t--;a--;b--;
    if(t){
      cout << m[root(a)][b] << endl;
    }
    else
      unite(a,b);
  }

  return 0;

}

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

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT  = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL   = std::numeric_limits<long long>::max();

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

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////

struct mint {
    static const int mod = 1000000007;
    long long x; // typedef long long ll;
    mint(long long 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(long long 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; }
};
std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x; }
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x; }

void countNb(ll& res) {
    ll n, a, b; cin >> n >> a >> b;

    // ensure A <= B
    if (b < a) {
        ll tmp = a;
        a = b;
        b = tmp;
    }

    mint N(n), A(a), B(b);

    mint nbA = N - (A - 1); nbA = nbA * nbA;
    mint nbB = N - (B - 1); nbB = nbB * nbB;
    mint nbtotal = nbA * nbB;

    // dupulication: inside
    mint nbAb = B - (A - 1); nbAb = nbAb * nbAb;
    mint nbInside = nbAb * nbB;

    // cross
    mint cnt = 0;
    for (ll alpha = 1; alpha < a; ++alpha) {
        mint Alpha(alpha);
        mint nbCross = (B - A + Alpha * 2) * 4;
        mint nbIn = N - (B + Alpha - 1); nbIn = nbIn * nbIn;
        cnt += nbCross * nbIn;
    }

    mint count = nbtotal - nbInside - cnt;
    res = count.x;
}

void countNb2(ll& res) {
    mint N, A, B; cin >> N >> A >> B;
    ll nbSpace = N.x - A.x - B.x;
    mint x3 = (nbSpace >= 0) ? (N-A-B+2)*(N-A-B+1) : 0;
    mint x2 = (N-A+1)*(N-B+1) - x3;
    mint x1 = x2 * x2;
    mint total = (N-A+1)*(N-B+1) * (N-A+1)*(N-B+1);
    mint ans = total - x1;
    res = ans.x;
}

void Main() {
    ll T; cin >> T;
    vector<ll> res(T);
    for (ll i = 0; i < T; ++i) {
        countNb2(res[i]);
    }

    rep(i, T) {
        cout << res[i] << endl;
    }
}

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

    double tmp;
    cin >> tmp;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[500005],t[500005];
int f[500005][2],v[500005];
int main()
{
    int n,cnt=0;
    long long ans=0;
    scanf("%d",&n);
    scanf("%s\n%s",s+1,t+1);
    for(int i=1;i<=n;i++)if(s[i]=='1')v[++cnt]=i;
    long long now=1;
    for(int i=1;i<=n;i++)
    {
        while(now<=cnt&&v[now]<i)
        {
            if(now==cnt){puts("-1");return 0;}
            ans+=v[now+1]-v[now];
            now+=2;
        }
        if(t[i]=='0')
        {
            while(now<=cnt&&v[now]<=i)
            {
                if(now==cnt){puts("-1");return 0;}
                ans+=v[now+1]-v[now];
                now+=2;
            }
        }
        else
        {
            if(now>cnt){puts("-1");return 0;}
            else ans+=v[now]-i,now++;
        }
    }
    printf("%lld",ans);
    return 0;
}

#include <iostream>
#include <climits>
#include <vector>

using namespace std;

int main()
{
  int n;
  string s, t;
  cin >> n;
  cin >> s;
  cin >> t;

  // 偶奇が同じか判別する
  int sSum = 0, tSum = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') sSum++;
    if (t[i] == '1') tSum++;
  }
  if ((sSum - tSum) % 2 == 1 || sSum < tSum) {
    cout << -1;
    return 0;
  }
  long ans = 0;
  int sNow = 0, tNow = 0;
  int sBefore = -1;
  while (tNow < n) {
    // tの最初を探す
    if (t[tNow] == '0') {
      tNow++;
      continue;
    }
    else {
      // 相方になり得るsを探す
      while (sNow < n && s[sNow] == '0')
        sNow++;
      if (sNow == n) {
        cout << -1;
        return 0;
      }
      if (sNow >= tNow && sBefore == -1) {
        // 相方として決定
        ans += sNow - tNow;
        sNow++;
        tNow++;
      }
      else {
        // 相殺するものとする
        if (sBefore == -1) {
          sBefore = sNow;
          sNow++;
        }
        else {
          ans += sNow - sBefore;
          sBefore = -1;
          sNow++;
        }
      }
    }
  }
  while (sNow < n) {
    if(s[sNow] == '0')
    {
      sNow++;
    }
    else {
      // 相殺
      if (sBefore == -1) {
        sBefore = sNow;
        sNow++;
      }
      else {
        ans += sNow - sBefore;
        sBefore = -1;
        sNow++;
      }
    }
  }
  cout << ans;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const long long mod=(long long)1e9+7;
long long ans,cnt[3010][3010],n,s[3010],Now;
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&Now);
		s[i]=s[i-1]+Now;
	}
	cnt[1][0]=1;
	for(int i=1;i<n;i++)
		for(int j=i;j>=1;j--)
		{
			Now=cnt[j][s[i]%(long long)j];
			cnt[j+1][s[i]%(long long)(j+1)]=(cnt[j+1][s[i]%(long long)(j+1)]+Now)%mod;
		}
	for(int j=1;j<=n;j++)
		ans=(ans+cnt[j][s[n]%(long long)j])%mod;
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const long long int MOD = 998244353;
int N,K;
int board[50][50];
long long int fact[51];
bool check1[50];
bool check2[50];
int uf[50];

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

bool merge(int x,int y)
{
	x = find(x);
	y = find(y);
	if(x==y)
	{
		return false;
	}
	uf[x] += uf[y];
	uf[y] = x;
	return true;
}

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

	/*
	vector <int> v = {1,2,3,4};

	queue <vector<int>> que;
	set <vector<int>> visited;
	visited.insert(v);
	que.push(v);

	while(!que.empty())
	{
		vector <int> now = que.front();
		que.pop();

		vector <int> next = now;
		int t = next[0];
		next[0] = next[1];
		next[1] = t;
		if(visited.find(next)==visited.end())
		{
			visited.insert(next);
			que.push(next);
		}

		next = now;
		t = next[2];
		next[2] = next[3];
		next[3] = t;
		if(visited.find(next)==visited.end())
		{
			visited.insert(next);
			que.push(next);
		}

 		/*
		next = now;
		t = next[0];
		next[0] = next[3];
		next[3] = t;
		if(visited.find(next)==visited.end())
		{
			visited.insert(next);
			que.push(next);
		}

		next = now;
		t = next[1];
		next[1] = next[2];
		next[2] = t;
		if(visited.find(next)==visited.end())
		{
			visited.insert(next);
			que.push(next);
		}

	}

	cout << visited.size() << '\n';

	return 0;
	*/

	cin >> N >> K;

	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			cin >> board[i][j];
		}
	}
	fact[0] = 1;

	for(int i=1;i<=50;i++)
	{
		fact[i] = ((fact[i-1]%MOD)*(i%MOD)%MOD);
		fact[i]%=MOD;
	}

	long long int res = 1;
	memset(uf,-1,sizeof(uf));
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			bool ok = true;
			for(int k=0;k<N;k++)
			{
				if(board[i][k] + board[j][k] > K)
				{
					ok = false;
					break;
				}
			}
			if(ok)
			{
				merge(i,j);
			}
		}
	}

	for(int i=0;i<N;i++)
	{
		if(uf[i] < 0)
		{
			res = ((res%MOD)*(fact[abs(uf[i])]%MOD)%MOD);
			res%=MOD;
		}
	}

	memset(uf,-1,sizeof(uf));

	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			bool ok = true;
			for(int k=0;k<N;k++)
			{
				if(board[k][i] + board[k][j] > K)
				{
					ok = false;
					break;
				}
			}
			if(ok)
			{
				merge(i,j);
			}
		}
	}

	for(int i=0;i<N;i++)
	{
		if(uf[i] < 0)
		{
			res = ((res%MOD)*(fact[abs(uf[i])]%MOD)%MOD);
			res%=MOD;
		}
	}

	cout << res << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std ;
#define time cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
typedef unsigned long long int ull ;
#define int long long
int MOD = 1e7+7 ;

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

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

void solve(){

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

  int c = a+b  ;

  if(c>=15 && b>=8){
    cout << 1 ;
  }
  else
  if(c>=10 && b>=3){
    cout << 2;
  }
  else
  if(c>=3){
    cout << 3;
  }
  else{
    cout << 4 ;
  }

}
int32_t main()
{
  fast ;   time ;
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  solve()  ;
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

using LL = long long;
using LD = long double;
using ordered_set = tree<LL,null_type,less<LL>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

const LL MOD = 998244353;
const LL INF = 1e18;
const LL N = 2e5+5;

#define S second
#define F first
#define vt vector

LL binpow(LL x, LL p, LL m) {
	LL res = 1;
	x %= m;
	while (p) {
		if (p&1) {
			res = res * x % m;
		}
		x = x * x % m;
		p >>= 1;
	}
	return res;
}

int main() {
	fastio();

	LL n, m;
	cin >> n >> m;

	LL sub = 0;

	LL mi = binpow(m, MOD-2, MOD);
	LL mp = binpow(m, n-1, MOD);

	vt<LL> dmx(m+1, 1);

	for (LL d = 2; d <= n; ++d) {
		LL tim = n-d+1;
		LL res = 0;

		mp = (mp*mi) % MOD;

		for (LL x = 1; x <= m; ++x) {
			//
			res = (res + dmx[m-x] % MOD * mp) % MOD;
			dmx[m-x] = dmx[m-x]*(m-x) % MOD;
		}
		LL trm = (res * tim) % MOD;
		//cerr << trm << "?";
		sub = (sub + trm) % MOD;

	}

	LL ans = n*binpow(m, n, MOD) % MOD;

	ans -= sub;
	if (ans < 0) {
		ans += MOD;
	}

	cout << ans << "\n";

}


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

int main() {
	// your code goes here;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
 ll t=1;
 //cin>>t;
 while(t--)
 {
    ll n;
    cin>>n;
    ll prmi=0;
    ll a[n];
    map<ll,ll>m;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]=1;
        if(m[prmi]==0)
        {
         cout<<prmi<<endl;
        }
        else{
         while(m[prmi]!=0)
         {
            prmi++;
         }
         cout<<prmi<<endl;
        }
    }
 }
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ll LINF = 1ll << 55;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

/// cin/cout overloading
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    out << *it << " ";
  }
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const pair<T, T> &P) {
  out << P.first << " " << P.second;
  return out;
}

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

template <typename T>
istream &operator>>(istream &in, pair<T, T> &P) {
  in >> P.first >> P.second;
  return in;
}

#define error(args...)                       \
  {                                          \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr << endl;                            \
  }

void err(istream_iterator<string>) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}

#define all(x) (x).begin(), (x).end()
#define coutp(x, y) cout << (x) << " " << (y) << endl
#define coutn(x) cout << (x) << endl
#define coutd(x) cout << setprecision(10) << (x) << endl

/// main函数
int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  ll sqsum = 0;
  ll sumsq = 0;
  ll A;
  for (int i = 0; i < N; ++i) {
    cin >> A;
    sqsum += A * A;
    sumsq += A;
  }
  sumsq *= sumsq;
  ans = N * sqsum - sumsq;
  coutn(ans);
  return 0;
}


// time-limit: 2000
// problem-url: https://atcoder.jp/contests/abc185/tasks/abc185_e
#include <bits/stdc++.h>

#define endl "\n"
#define int long long
#define double long double
#define precise \
    fixed << setprecision(12)
#define debug(var) \
    if (debugging) \
    cerr << (#var) << ": " << var << endl

const bool debugging = 1;
const int mod = 1e9 + 7;

using namespace std;

template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
    for (auto v : V)
    {
        os << v << " ";
    }
    return os << "";
}

template <class T>
ostream &operator<<(ostream &os, vector<vector<T>> V)
{
    for (int i = 0; i < V.size(); i++)
    {
        for (int j = 0; j < V[i].size(); j++)
        {
            os << V[i][j] << " ";
        }
        os << endl;
    }
    return os << "";
}

template <class T>
ostream &operator<<(ostream &os, set<T> S)
{
    for (auto s : S)
    {
        os << s << " ";
    }
    return os << "";
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
    return os << P.first << " " << P.second;
}

template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M)
{
    os << endl;
    for (auto m : M)
    {
        os << m << endl;
    }
    return os << "";
}

const int max_val = 1e3 + 10;

int dp[max_val][max_val];
int N, M;
vector<int> arr1;
vector<int> arr2;

int recur(int ptr1, int ptr2)
{
    if (ptr1 == N || ptr2 == M)
    {
        return (N - ptr1) + (M - ptr2);
    }

    if (dp[ptr1][ptr2] != -1)
    {
        return dp[ptr1][ptr2];
    }

    dp[ptr1][ptr2] = INT64_MAX;
    dp[ptr1][ptr2] = min(dp[ptr1][ptr2], 1 + recur(ptr1 + 1, ptr2));
    dp[ptr1][ptr2] = min(dp[ptr1][ptr2], 1 + recur(ptr1, ptr2 + 1));
    dp[ptr1][ptr2] = min(dp[ptr1][ptr2], (arr1[ptr1] != arr2[ptr2]) + recur(ptr1 + 1, ptr2 + 1));
    return dp[ptr1][ptr2];
}

void solve()
{
    cin >> N >> M;
    arr1.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> arr1[i];
    }

    arr2.resize(M);
    for (int i = 0; i < M; i++)
    {
        cin >> arr2[i];
    }

    fill_n(&dp[0][0], max_val * max_val, -1);
    cout << recur(0, 0) << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {if (val < 0) val += MOD;}
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {return val ? MOD - val : 0;}
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {val += r.val;if (val >= MOD) val -= MOD;return *this;}
    constexpr Fp& operator -= (const Fp& r) noexcept {val -= r.val;if (val < 0) val += MOD;return *this;}
    constexpr Fp& operator *= (const Fp& r) noexcept {val = val * r.val % MOD;return *this;}
    constexpr Fp& operator /= (const Fp& r) noexcept {long long a = r.val, b = MOD, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}val = val * u % MOD;if (val < 0) val += MOD;return *this;}
    constexpr bool operator == (const Fp& r) const noexcept {return this->val == r.val;}
    constexpr bool operator != (const Fp& r) const noexcept {return this->val != r.val;}
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {return os << x.val;}
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {if (n == 0) return 1;auto t = modpow(a, n / 2);t = t * t;if (n & 1) t = t * a;return t;}
};

const ll INF = 1LL<<60;

struct edge
{
    int to;
    ll cost;
};

void dijkstra(const vector<vector<edge>> &G, int s , vector<ll> &dist)
{
    priority_queue<P,vector<P>,greater<P>> que;
    dist[s] = 0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        int d =  p.first;
        //if(dist[v] < d) continue;
        for(auto e : G[v]) {
            if(dist[e.to] > dist[v]+e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

using mint = Fp<MOD>;

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

    vecl d(N);
    REP(i,N) d[i] = INF;
    vecvecl dist(N,vecl(N, INF));
    vector<vector<edge>> G1(N, vector<edge>());

    REP(i,M) {
        int a,b; cin >> a >> b;
        --a,--b;
        ll t; cin >> t;
        if(a != b) G1[a].push_back({b,t});
        if(a == b) d[a] = min(d[a],t);
    }

    REP(s,N) {
        vector<ll> dist1(20010, INF);
        dijkstra(G1,s,dist1);
        REP(t,N) {
            dist[s][t] = min(dist[s][t],dist1[t]);
        }
    }

    // REP(i,N) {
    //     REP(j,N) cout << dist[i][j] << " ";
    //     cout << endl;
    // }

    REP(s,N) {
        ll ans = INF;
        REP(t,N) {
            if(s!=t) if(dist[s][t] == INF || dist[t][s] == INF) continue; else chmin(ans,dist[s][t] + dist[t][s]);
        }
        if(ans == INF) {
            if(d[s] != INF) cout << d[s] << endl;
            else cout << -1 << endl;
        } else {
            if(d[s] != INF) cout << min(ans,d[s]) << endl;
            else cout << ans << endl;
        }
    }

    return 0;
}


#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> void show_vec(T v) {for (int i=0;i<v.size();i++) cout<<v[i]<<endl;}
template<class T> void show_pair(T p) {cout<<p.first<<" "<<p.second<<endl;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 29;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;

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

    int t;
    ll n;
    cin >> t >> n;

    vector<ll> bac(100 + t,0);
    for (int i = 0; i < 100; i++){
        bac[(100 + t) * i / 100]++;
    }
    vector<ll> ans;
    for (int i = 1; i < 100 + t; i++){
        if (bac[i] <= 0) ans.push_back(i);
    }

    // show_vec(ans);

    ll x = ans.size();
    ll r = 100 + t;
    n--;

    cout << ((n / x) * r) + ans[n % x] << endl;
}

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

#define int         long long
#define ull         unsigned long long
#define ll          long long
#define M           998244353
#define pb          push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp          make_pair
#define lb          lower_bound
#define ub          upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (int i=begin;i<end;i++)
#define repd(i, begin, end) for (int i=end-1;i>=begin;i--)
#define ini(a,n,b)  for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)     __builtin_popcountll(a)
#define hell        1000000007
#define re          resize
const int INF=1e18;
const int N=1e2+5;

int powm(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1)
    res=(res*a)%M;
      a=(a*a)%M;
      b>>=1;
  }

  return res;
}

int pow(int a,int b)
{
  int res=1;
  while(b)
  {
    if(b&1)
    res=(res*a);
      a=(a*a);
      b>>=1;
  }

  return res;
}

vi a[N],vis(N,0),len(N,0);
set<pair<int,int> > s;

void dfs(int node,int par)
{
  vis[node]=1;
  for(auto j:a[node])
  {
    if(!vis[j])
    {
       len[j]=len[node]+1;
       s.insert({node,j});
       dfs(j,node);
    }
    else if(j!=par&&len[j]<len[node])
    {
       s.insert({node,j});
    }
  }
}
signed main(void)
{ios
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("answer.txt", "w", stdout);
    #endif

    int n,m;
    cin>>n>>m;
    vi u(m),v(m);
    rep(i,0,m)
    {
       cin>>u[i]>>v[i];
    }

    vi c(n+1);
    rep(i,1,n+1) cin>>c[i];
    vi dir(m,0);
    rep(i,0,m)
    {
       if(c[u[i]]>c[v[i]])
       {
         dir[i]=1;
       }
       else if(c[v[i]]>c[u[i]])
       {
         dir[i]=0;
       }
       else
       {

         a[u[i]].pb(v[i]);
         a[v[i]].pb(u[i]);
       }
    }

    rep(i,1,n+1)
    {
       if(!vis[i])
       {
         dfs(i,0);
       }
    }

    rep(i,0,m)
    {
       if(c[u[i]]==c[v[i]])
       {
         if(s.find({u[i],v[i]})!=s.end()) dir[i]=1;
         else dir[i]=0;
       }
    }

    rep(i,0,m)
    {
       if(dir[i]==1) cout<<"->"<<endl;
       else cout<<"<-"<<endl;
    }

}