#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t, r;
	int n, a, b;
	cin >> s >> n;
	for (int i = 0; i < n; i++) {
		cin >> t >> a >> b;
		if (t == "print")
			cout << s.substr(a, b - a + 1) << endl;
		else if (t == "reverse")
			for (int j = 0; j < (b - a + 1) / 2; j++)
				swap(s[a + j], s[b - j]);
		else {
			cin >> r;
			s.replace(a, b - a + 1, r);
		}
	}
}

// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long llong;
using namespace std;

int main() {
	char strin[1010];
	int a, b;
	int q;
	char querin[10];
	char repin[1100];
	char revin[1100];

	scanf("%s", strin);
	getchar();
	cin >> q;
	for (int i = 0; i < q; i++) {
		scanf("%s %d %d", querin, &a, &b);
		if (!strcmp(querin, "replace")) {
			scanf("%s", repin);
			for (int j = a; j <= b; j++) {
				strin[j] = repin[j - a];
			}
		}
		else if (!strcmp(querin, "print")) {
			for (int j = a; j <= b; j++) {
				printf("%c", strin[j]);
			}
			cout << '\n';
		}
		else if (!strcmp(querin, "reverse")) {
			for (int j = a; j <= b; j++) {
				revin[j - a] = strin[j];
			}
			for (int j = b; j >= a; j--) {
				strin[a + b - j] = revin[j - a];
			}
		}
	}

	return 0;
}


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

int main() {
    int wh, bk; cin >> wh >> bk;
    int h = 100 / 2, w = 100;
    cout << h * 2 << " " << w << endl;
    auto func = [&](char c0, char c1, int cnt) {
        vector<string> s(h, string(w, c0));
        for (int i = 1; i < h - 1; i += 2) for (int j = 0; j < w; j += 2) {
            if (cnt) s[i][j] = c1, cnt--;
        }
        for (auto &si: s) cout << si << endl;
    };
    func('.', '#', bk - 1);
    func('#', '.', wh - 1);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll a,b,k;
    cin>>a>>b>>k;
    bool t=1;
    while (k--)
    {
        if (t)
        {
            if (a&1)
                a--;
            b=b+a/2;
            a/=2;
            t=0;
        }
        else
        {
            if (b&1)
                b--;
            a=a+b/2;
            b/=2;
            t=1;
        }
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> query(Q+2,-1e9);
  for(int i=1; i<=Q; i++){
    cin >> query.at(i);
  }
  query.at(Q+1) = 1e9+10;
  vector<vector<int>> in(Q+2,vector<int>(0));
  vector<vector<int>> out(Q+2,vector<int>(0));

  vector<int>::iterator pos;
  int idx;
  for(int i=0; i<N; i++){
    int s = vec.at(i).at(0);
    int e = vec.at(i).at(1);
    int p = vec.at(i).at(2);
    pos = lower_bound(query.begin(),query.end(),s-p);
    idx = distance(query.begin(),pos);
    in.at(idx).push_back(p);
    pos = lower_bound(query.begin(),query.end(),e-p);
    idx = distance(query.begin(),pos);
    out.at(idx).push_back(p);
  }

  map<int,int> mp;
  mp[1e9+10] = 1;
  for(int i=0; i<Q+1; i++){
    for(int j=0; j<in.at(i).size(); j++){
      if(mp.count(in.at(i).at(j))){
        mp[in.at(i).at(j)]++;
      }
      else{
        mp[in.at(i).at(j)] = 1;
      }
    }
    for(int j=0; j<out.at(i).size(); j++){
      mp[out.at(i).at(j)]--;
      if(mp[out.at(i).at(j)] == 0){
        mp.erase(out.at(i).at(j));
      }
    }
    if(i != 0){
      int x = mp.begin()->first;
      if(x == 1e9+10){
        cout << -1 << endl;
      }
      else{
        cout << x << endl;
      }
    }
  }
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

inline int Calcu(int a,int b){
    return min(a, b);
}

class SegTree{
    public:
        int n;
        int g;
        std::vector<int> data;

        SegTree(std::vector<int> a, int _g){
            g = _g;
            for (n = 1; n < (int) a.size(); n *= 2);
            data.resize(n * 2, g);
            //for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i];
            //for (int i = n - 1; i >= 1; i--)
            //    data[i] = min(data[i], Calcu(data[i * 2], data[i * 2 + 1]));
        }

        int rec(int l, int r, int node, int node_l, int node_r, int val) {
            if (node_r <= l || node_l >= r) return g;
            if (node_l >= l && node_r <= r) return data[node] = min(data[node], val);
            int mid = (node_l + node_r) / 2;
            return Calcu(
                rec(l, r, node * 2, node_l, mid, val),
                rec(l, r, node * 2 + 1, mid, node_r,val));
        }

        void query(int l,int r, int val){
            rec(l,r,1,0,n,val);
        }

        int get(int index){
            int res = data[index += n];
            for(;index /= 2;)
                res = min(res, data[index]);
            return res;
        }
};

int main()
{
    int n, q; cin >> n >> q;
    vector<tuple<int,int,int>> p(n);
    vector<int> c(q);
    for(int i = 0; i < n; i++) {
        int a, b, c; cin >> a >> b >> c;
        a -= c;
        b -= c;
        p[i] = tie(a, b, c);
    }
    for(int i = 0; i < q; i++)cin >> c[i];
    map<int,int> mp;
    for(int i = 0; i < n; i++)mp[get<0>(p[i])] = -1, mp[get<1>(p[i])] = -1;
    for(int i = 0; i < q; i++)mp[c[i]] = -1;

    int za = 0;
    for(auto &i : mp)i.second = za++;

    for(int i = 0; i < n; i++)get<0>(p[i]) = mp[get<0>(p[i])], get<1>(p[i]) = mp[get<1>(p[i])];
    for(int i = 0; i < q; i++)c[i] = mp[c[i]];

    const int INF = 2e9;
    SegTree tree(vector<int>(za), INF);
    for(int i = 0; i < n; i++) {
        int a, b, c; tie(a, b, c) = p[i];
        tree.query(a, b, c);
    }

    for(int i = 0; i < q; i++) {
        cout << (tree.get(c[i]) == INF ? -1 : tree.get(c[i])) << endl;
    }

}


#include <iostream>
#include <string>

int func(int x)
{
  return x * x;
}

int main(void)
{
  const int max_x = 600;
  int d = 0;

  while (std::cin >> d) {
    int loop = max_x / d;

    int sum = 0;
    for (int i = 0; i < loop; i++) {
      sum += d * func(d * i);
    }

    std::cout << sum << std::endl;
  }

  return 0;
}


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

class MP
{
public:
    vector<long long> pattern;
    long long plen;
    vector<long long> table;
    MP(const vector<long long>& s) : pattern(s), plen((long long)pattern.size()), table(plen + 1){
        table[0] = -1;
        long long j = -1;
        for(long long i = 0; i < plen; ++i){
            while(j >= 0 && pattern[i] != pattern[j]){
                j = table[j];
            }
            table[i+1] = ++j;
        }
    }
    void search(const vector<long long>& text, vector<long long>& res){
        long long head = 0, j = 0, tlen = (long long)text.size();
        while(head + j < tlen){
            if(pattern[j] == text[head + j]) {
                if(++j == plen){
                    res.push_back(head);
                    head = head + j - table[j];
                    j = table[j];
                }
            }else{
                head = head + j - table[j];
                if(j) j = table[j];
            }
        }
    }
    void minimum_cycle(vector<long long>& res){
	    res.resize((long long)pattern.size());
	    for(long long i = 0; i < (long long)pattern.size(); ++i){
	    	res[i] = i + 1 - table[i+1];
	    }
    }
};

int main(){
    //input
    long long N;
    cin >> N;
    long long a[N], b[N];
    long long i;
    for(i=0; i<N; i++){
        cin >> a[i];
    }
    for(i=0; i<N; i++){
        cin >> b[i];
    }

    //exceptional
    if(N==1){
        cout << 0 << " " << (a[0]^b[0]) << endl;
        system("pause");
        return 0;
    }

    //calc
    vector<long long> AA,BB;
    for(i=0; i<N-1; i++){
        AA.push_back(a[i]^a[i+1]);
    }
    AA.push_back(a[N-1]^a[0]);
    for(i=0; i<N-1; i++){
        AA.push_back(a[i]^a[i+1]);
    }
    AA.push_back(a[N-1]^a[0]);
    for(i=0; i<N-1; i++){
        BB.push_back(b[i]^b[i+1]);
    }
    MP BBBB(BB);
    vector<long long> adj;
    BBBB.search(AA,adj);
    for(i=0; i<adj.size(); i++){
        if(adj[i]>=N) break;
        cout << adj[i] << " " << (a[adj[i]]^b[0]) << endl;
    }
    system("pause");
    return 0;
}

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

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

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

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}

int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}

int powz(int a,int b){
	int res=1;
	while(b){
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}

const int N=1000002;

int dp[51][51];

void solve(){
	int n;
	cin>>n;
	ll ans=0;
	for(int i=0;i<n;i++){
		double x;
		cin>>x;
		long long val=(x+1e-12)*1e9;
		ll tw=0,fv=0;
		if(val==0){
			ans+=n;
			continue;
		}
		while(val%2==0){
			tw++;
			val/=2;
		}
		while(val%5==0){
			fv++;
			val/=5;
		}
		for(int j=0;j<=50;j++){
			if(tw+j<18){
				continue;
			}
			for(int k=0;k<=50;k++){
				if(fv+k>=18){
					ans+=dp[j][k];
				}
			}
		}
		dp[tw][fv]++;
	}
	cout<<ans;

}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	// cin>>tc;
	for(int _=0;_<tc;_++){
		// cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;
struct UnionFind {
  vector<ll> par, sizes;
  ll cnt;
  UnionFind(ll N) : par(N), sizes(N, 1), cnt(N) {
    for (ll i = 0; i < N; i++) par[i] = i;
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll size(ll x) { return sizes[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
    cnt--;
  }

  ll count() const { return cnt; }
};
int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, t;
  cin >> n >> t;

  vll as(n), bs(n);
  rep(i, n) cin >> as[i] >> bs[i];

  vvll dp1(n + 1, vll(t, 0));
  vvll dp2(n + 2, vll(t, 0));

  rep(i, n) {
    rep(j, t - 1) {
      dp1.at(i + 1).at(j + 1) = dp1.at(i + 1).at(j);
      chmax(dp1.at(i + 1).at(j + 1), dp1.at(i).at(j + 1));
      if (j + 1 - as[i] >= 0)
        chmax(dp1.at(i + 1).at(j + 1), bs[i] + dp1.at(i).at(j + 1 - as[i]));
    }
  }

  rep(i, n) {
    rep(j, t - 1) {
      dp2.at(i + 1).at(j + 1) = dp2.at(i + 1).at(j);
      chmax(dp2.at(i + 1).at(j + 1), dp2.at(i).at(j + 1));
      if (j + 1 - as[n - 1 - i] >= 0)
        chmax(dp2.at(i + 1).at(j + 1),
              bs[n - 1 - i] + dp2.at(i).at(j + 1 - as[n - 1 - i]));
    }
  }

  ll juee = 0;
  rep(i, n) {
    rep(j, t){
      ll tmp = dp1[i][j] + bs[i] + dp2[n - 1 - i][t - 1 - j];
      chmax(juee, tmp);
    }
  }

  cout << juee << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, t;
    cin >> n >> t;

    vector<P> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;

    vector<vector<ll>> dp(n + 1, vector<ll>(t + (*max_element(all(ab))).first + 1));
    ll ans = 0;
    sort(all(ab));
    rep(i, n) {
        rep(j, t) {
            ll nxt = j + ab[i].first;
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][j] + ab[i].second);
            ans = max(ans, dp[i + 1][nxt]);
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


#include<bits/stdc++.h>
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
using namespace std;
int n;
double dp[301][301][301];

double solve(int x, int y, int z){
  if(x<0 || y<0 || z<0)
    return 0.0;
  if(x==0&&y==0&&z==0)
    return 0.0;
  if(dp[x][y][z] > -0.9)
    return dp[x][y][z];
  double exp = n + x*solve(x-1,y,z) + y*solve(x+1,y-1,z) + z*solve(x,y+1,z-1);

  return dp[x][y][z] = exp/(x+y+z);
}

int main(){
  cin>>n;
  int x,y,z;
  x = y = z = 0;
  memset(dp, -1, sizeof(dp));
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    if(t==1)
      x++;
    else if(t==2)
      y++;
    else
      z++;
  }
  //cout<<solve(x,y,z)<<endl;
  cout<<fixed<<setprecision(10)<<solve(x,y,z)<<endl;
  return 0;
}

#include <iostream>
#include <math.h>
#include <stdio.h>
#define MAX 100001

int A[MAX];
int n;

int partition(int r) {
    int judge_n = A[r];
    int i = -1;
    int j = 0;
    for (j = 0; j < n; j++) {
        if (A[j] <= judge_n) {
            i++;
            std::swap(A[i], A[j]);
        }
    }
    return i;
}

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

    // ????????????????????????????????¨??????
    int index = partition(n-1);

    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        if (i == index) printf("[%d]", A[i]);
        else printf("%d", A[i]);
    }
    printf("\n");

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b)
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

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

    vector<int> odd_hist(MAX, 0), even_hist(MAX, 0);
    rep(i,n) {
        if (i & 1) odd_hist[a[i]]++;
        else even_hist[a[i]]++;
    }

    vector<PII> odd, even;
    rep(i,MAX) {
        odd.push_back(PII(odd_hist[i], i));
        even.push_back(PII(even_hist[i], i));
    }
    sort(odd.begin(), odd.end(), greater<PII>());
    sort(even.begin(), even.end(), greater<PII>());

    if (odd[0].second != even[0].second) {
        cout << n - (odd[0].first + even[0].first) << endl;
    }
    else {
        cout << n - max(odd[0].first + even[1].first,
                odd[1].first + even[0].first) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    queue<int> A[n];
    rep(i, n) {
        rep(_, n - 1) {
            int a;
            cin >> a;
            A[i].push(a-1);
        }
    }
    int ans = 0;
    while(1) {
        bool flag = 1, end = 1;
        vector<int> op(n, -1);
        rep(i, n) {
            if (A[i].empty()) {
                continue;
            } else {
                end = 0;
            }
            op[i] = A[i].front();
            if (op[A[i].front()] == i) {
                A[op[i]].pop();
                A[i].pop();
                flag = 0;
            }
        }
        if (end) break;
        if (flag) {
            cout << -1 << endl;
            return;
        }
        ans++;
    }
    cout << ans << endl;
}

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


#include <iostream>
using namespace std;

void bubble_sort(int N, float* A){
	int nchange = 0;
	bool cont = true;

	for(int i=0; cont; i++){
		cont = false;
		//未ソート部分列のスワップが発生しない場合停止
		for(int j=N-1; j>i; j--){
			if(A[j-1] > A[j]){
				swap(A[j-1], A[j]);
				cont = true;
				nchange++;
			}
		}
	}

	for(int i=0; i<N; i++){
		if(i==N-1){
			cout << A[i] << endl;
		}else{
			cout << A[i] << " ";
		}
	}
	cout << nchange << endl;
}

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

	float A[N];
	for(int i=0; i<N; i++) cin >> A[i];

	bubble_sort(N, A);
	return 0;
}

#include <iostream>
#include <iterator>
#include <sstream>
#include <string>

#include <set>
#include <list>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>

#include <algorithm>
#include <utility>

using namespace std;
namespace patch
{
    template <typename T>
    string to_string(const T& n)
    {
        ostringstream stm;
        stm << n;
        return stm.str();
    }
    int stoi(string str)
    {
        int ret;
        istringstream stm(str);
        stm >> ret;
        if (stm.fail())
        {
            throw -1;
        }
        return ret;
    }
    vector<string> split(const string &str)
    {
        istringstream stm(str);
        vector<string> ret;
        copy(istream_iterator<string>(stm),
            istream_iterator<string>(),
            back_inserter(ret));
        return ret;
    }
    vector<string> split(const string &str, char delim)
    {
        istringstream stm(str);
        vector<string> ret;
        string buf;
        while (getline(stm, buf, delim))
        {
            ret.push_back(buf);
        }
        return ret;
    }
}

int bubbleSort(vector<int>& vs)
{
    int end = vs.size();
    if (end == 1)
    {
        return 0;
    }
    int cnt = 0;
    for (int j = 0; j < end - 1; ++j)
    {
        for (int i = 0; i < end - j - 1; ++i)
        {
            if (vs[i] > vs[i+1])
            {
                swap(vs[i], vs[i+1]);
                ++cnt;
            }
        }
    }
    return cnt;
}

// bubble sort
int main()
{
    ios::sync_with_stdio(false);

    // line 1
    string s1;
    getline(cin, s1);
    int n = patch::stoi(s1);

    // line 2
    vector<int> vs(n);
    vector<string> ss;
    string s2;
    getline(cin, s2);
    ss = patch::split(s2);
    for (int n = 0, sz = ss.size(); n < sz; ++n)
    {
        vs[n] = patch::stoi(ss[n]);
    }

    int cnt = bubbleSort(vs);

    bool isFirst = true;
    for (int n : vs)
    {
        //cout << n << " ";
        if (isFirst)
        {
            cout << n;
            isFirst = false;
        }
        else
        {
            cout << " " << n;
        }
    }
    cout << "\n";
    cout << cnt << "\n";

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
        }

        for (int x = i; x > 0; x /= 10) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
        }
    }

    cout << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    unordered_map<ll, ll> mp;
    rep(i, n){
        cin >> a[i];
        if (mp.find(a[i]) != mp.end()){
            mp[a[i]] += 1;
        }else{
            mp[a[i]] = 1;
        }
    }

    ll ans=0;
    for(auto x: mp){
        if (x.second % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long
#define d double
using namespace std;

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

  string s,t;
  cin>>s>>t;
  cout<<t+s<<endl;

  return 0;
}

#include <bits/stdc++.h>

const int INF =1e9;
const int MOD =1e9+7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
int n,r;
cin>>n>>r;
cout<<r+(10-min(10,n))*100<<endl;
}


#include <bits/stdc++.h>
#define MOD 998244353
using namespace std ;
int n , m , k ;
int jc[ 200005 ] ;
int ans = 0 ;
inline int qpow ( int a , int b ) {
    int res = 1 ;
    while ( b ) {
        if ( b & 1 ) res = 1LL * res * a % MOD ;
        b >>= 1 ;
        a = 1LL * a * a % MOD ;
    }
    return res % MOD ;
}
inline void init () {
    jc[ 0 ] = 1 ;
    for ( int i = 1 ; i <= n ; i ++ ) jc[ i ] = 1LL * jc[ i - 1 ] * i % MOD ;
}
inline int inv ( int a ) { return qpow ( a , MOD - 2 ) ; }
inline int C ( int n , int m ) { return 1LL * jc[ n ] * inv ( 1LL * jc[ m ] * jc[ n - m ] % MOD ) % MOD ; }
signed main () {
    scanf ( "%d%d%d" , &n , &m , &k ) ;
    init () ;
    for ( int i = 0 ; i <= k ; i ++ ) {
        ans = ( ans + 1LL * m * C ( n - 1 , i ) % MOD * qpow ( m - 1 , n - i - 1 ) % MOD ) % MOD ;
    }
    printf ( "%d\n" , ans % MOD ) ;
    return 0 ;
}
/*
题目简述：
给 n 个方格染 m 种颜色，要求最多有 k 组块相连且颜色相同，求方案数对 998244353 取模的结果。
*/

#include<stdio.h>
#include<math.h>
int main(){

  double x1,x2,y1,y2,ans;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

  ans=(x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);

  printf("%lf\n",sqrt(ans));

  return 0;
}


#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long int N,H,W,i,j,k,ans,count,cost,tmp;
    long long int S[200010];
    long long int Ssum[200010];
    string T;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    flag=false;
    cin >>N>>H;
    for (i=H-(N-1);i<=H+(N-1);i++){
        if (i==H+(N-1)){

            cout <<i <<endl;
        }
        else{
            cout <<i << " ";
        }

    }

    return 0;

}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int k,x,st,i;
    cin>>k>>x;
    x-=--k;
    k=2*k+1;
    while(k--)
    cout<<x++<<" ";
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int a[N];

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  map<int, int> h;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    if (i) a[i] += a[i-1];
    a[i] %= m;
    ++h[a[i]];
  }
  for (const auto &e: h) {
    if (e.first == 0) continue;
    ans += 1LL*e.second*(e.second-1)/2;
  }
  ans += 1LL*h[0]*(h[0]+1)/2;
  printf("%lld", ans);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N, M;
ll A[100010];

int main(int argc, char **argv)
{
	cin >> N >> M;
	REP(i, N) cin >> A[i];
	A[0] %= M;
	REP(i, N-1)
		(A[i+1] += A[i]) %= M;

	map<ll, ll> m;
	REP(i, N)
		++m[A[i]];

	ll res{0};
	for (auto &p : m)
	{
		if (p.first == 0)
			res += p.second;
		res += p.second * (p.second-1) / 2;
	}

	std::cout << res << std::endl;
}


#include <bits/stdc++.h>
using namespace std;
#define long long ll
#define f(i,n) for(int i=0;i<n;i++)
const int maxn=305;
double dp[maxn][maxn][maxn];
double recur(int k, int b, int c,int n){
	if(dp[k][b][c]>=0)return dp[k][b][c];
	if(k==0&&b==0&&c==0)return 0.0;
	double res=0.0;
	// dp[k][b][c]=0.0;
	if(k>0)res+=(k)*recur(k-1,b,c,n);
	if(b>0)res+=(b)*recur(k+1,b-1,c,n);
	if(c>0)res+=(c)*recur(k,b+1,c-1,n);
	// dp[k][b][c]/=(n-k-c-b);
	res+=n;
	res*=1.0/(k+b+c);
	return dp[k][b][c]=res;
}
int main() {

	cout<<fixed<<setprecision(10);
	int n;
	cin>>n;
	vector<int>a(4,0);
	f(i,n){int x;
	cin>>x;
	a[x]++;
	}
	memset(dp, -1, sizeof(dp));
	cout<<fixed<<setprecision(9)<<recur(a[1],a[2],a[3],n)<<endl;

	return 0;
}

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

double dp[305][305][305];

int main(){
  int n, a;
  cin >> n;
  vector<int> sushi(3);
  for(int i=0; i<n; ++i){
    cin >> a;
    ++sushi[a-1];
  }
  int sum1 = sushi[2];
  int sum2 = sushi[1] + sushi[2];
  int sum3 = sushi[0] + sushi[1] + sushi[2];
  for(int k=0; k <= sum1; ++k) for(int j=0; j+k <= sum2; ++j) for(int i=0; i+j+k <=sum3; ++i){
    if(i>0) dp[i][j][k] += (dp[i-1][j][k] +(double)n/(i+j+k)) *i /(i+j+k);
    if(j>0) dp[i][j][k] += (dp[i+1][j-1][k] +(double)n/(i+j+k)) *j /(i+j+k);
    if(k>0) dp[i][j][k] += (dp[i][j+1][k-1] +(double)n/(i+j+k)) *k /(i+j+k);
  }
  printf("%.15f\n",dp[sushi[0]][sushi[1]][sushi[2]]);
}


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

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  vector<int> graph[n];
  for (int a, b; cin >> a >> b; ) {
    graph[a - 1].emplace_back(b - 1);
    graph[b - 1].emplace_back(a - 1);
  }
  int takahashi[n], aoki[n], parent[n], result = 0;
  auto bfs = [&](int start, int* distance) {
    queue<int> q;
    q.emplace(start);
    distance[start] = 0;
    vector<bool> visited(n);
    visited[start] = true;
    parent[start] = start;
    do {
      for (auto next : graph[q.front()]) {
        if (!visited[next]) {
          parent[next] = q.front();
          distance[next] = distance[q.front()] + 1;
          visited[next] = true;
          q.emplace(next);
        }
      }
      q.pop();
    } while (!q.empty());
  };
  bfs(u - 1, takahashi);
  bfs(v - 1, aoki);
  if (aoki[u - 1] != 1) {
    for (int i = 0; i < n; ++i) {
      if (takahashi[i] <= aoki[i]) {
        result = max(result, aoki[parent[parent[i]]] + 1);
      }
    }
  }
  cout << result;
  return 0;
}

#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll INF=1LL<<60;
const int MOD=998244353;
const int N=2e5+5;

int main(){
    int N, u, v; cin >> N >> u >> v;
    u--, v--;
    vector<vi> G(N);
    for(int i=0; i<N-1; i++){
        int A, B; cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<vi> dist(2, vi(N, -1));
    for(int i=0; i<2; i++){
        queue<int> que;
        que.push(v+(u-v)*i);
        dist[i][v+(u-v)*i]=0;
        while(!que.empty()){
            int p=que.front();
            que.pop();
            for(auto &np : G[p]){
                if(dist[i][np] != -1) continue;
                dist[i][np]=dist[i][p]+1;
                que.push(np);
            }
        }
    }
    int res=0;
    for(int i=0; i<N; i++){
        if(dist[0][i] > dist[1][i]) res=max(res, dist[0][i]);
    }
    res--;
    cout << res << endl;
    return 0;
}


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

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

  double t=s.size();
  string a ;

  for(int i=0 ; i<(t/n) ; i++ ){
    a+=s.at(0+i*n);
  }

  cout << a << endl;
}

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

int main(){
	string s; int w; cin>>s>>w;
	int k=s.size();
	rep(i,k){
		if(i%w==0) cout<<s[i];
	}
	cout<<endl;
}


#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
ll dp[210][100009];
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if(k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	ll n,x;
	cin>>n>>x;
	vector<ll> a;
	map<ll,ll> mope;
	setkaijo(100009);
	setinv(100009);
	for(int i=0;i<n;i++){
		ll tx;
		cin>>tx;
		a.pb(tx);
		mope[tx]++;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	vector< pair<ll,ll> > v;
	for(int i=0;i<n;i++){
		if( mope[ a[i] ] != 0){
			v.pb( mp( a[i], mope[a[i]]) );
			mope[a[i]] = 0;
		}
	}
	dp[0][x] = 1;
	ll rem = n;
	for(int i=0;i<v.size();i++){
		ll md = v[i].first;
		ll num = v[i].second;
		ll cb = comb(rem-1,num-1);
		ll cb2 = comb(rem-1,num);
		for(int j=0;j<=100000;j++){
			dp[i+1][j%md] += ( dp[i][j] * cb )%inf;
			dp[i+1][j] += (dp[i][j] * cb2)%inf;
		}
		rem -= num;
	}
	ll ans = 0;
	for(int i=0;i<=x;i++){
		ans = (ans + i*dp[v.size()][i])%inf;
	}
	cout<<ans<<endl;
	return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
const int N=205,M=1e5+5;
const int mod=1e9+7;
int dp[N][M],a[N],n,X;
int dfs(int u,int x) {
    if(!u) return x%a[u];
    if(dp[u][x]!=-1) return dp[u][x];
    return dp[u][x]=(dfs(u-1,x%a[u])+1LL*u*dfs(u-1,x))%mod;
}
int main() {
    scanf("%d%d",&n,&X);
    for(int i=0;i<n;i++) scanf("%d",a+i);
    std::sort(a,a+n);
    memset(dp,-1,sizeof(dp));
    printf("%d\n",dfs(n-1,X));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;

int MOD = 1e9+7;

//ll po(ll b, ll p){ return !p?1:po(b*b%MOD,p/2)*(p&1?b:1)%MOD;}
// ll pomd(ll a, ll k, ll md) { ll p; if (k == 0){ return 1; } p = pomd(a, k / 2, md); p = p * p % md; if (k % 2){ p = p * a % md; } return p; }
// counting divsrs: vi arr(N); for(int i{1}; i<N; ++i) for(int j=i; j<N; j+=i) d[j]++;

#define mp make_pair
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)

void setIO(string name = ""){
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main(){
 	ios_base::sync_with_stdio(0); cin.tie(0);
	// setIO();
 	ll n,x; cin >> n >> x;
 	if(n>=10){
 		cout << x << "\n";
 	}else{
 		cout << x+100*(10-n) << "\n";
 	}

}

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

int main(){
    int n,m;
    cin >> n >> m;
    set<int> s;
    for(int i = 2;i<=sqrt(m);i++){
        if(m%i==0) {
            s.insert(i);
            s.insert(m/i);
        }
    }
    s.insert(m);

    int ans = 1;

    for(auto it = s.begin();it!=s.end();it++){
        if((*it)<=m/n) ans = *it;
        else break;
    }

    cout << ans << endl;

    //for(auto it=s.begin();it!=s.end();it++) cout << *it << endl;

 }


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

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

  cout << min(N % K, 1) << endl;
  return 0;
}

#include <stdio.h>

int main() {
	int start = 1, n, t, x = 0;
	scanf("%d", &n);
	scanf("%d", &t);

	for(int i = 0; i < (n-x); i++) {
		while(start < t) {
			if(x >= n) {
				break;
			}
			start *= 2;
			x++;
		}
		if(x >= n) {
			break;
		}
		start += t;
	}
	printf("%d", start);

	return 0;
}


//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 1e5 + 7;
int n, m, v, p, a[N];
ll s[N];

int main() {
	rd(n, m), rd(v, p), rda(a, n);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) s[i] = a[i] + s[i-1];
//	for (int i = 1; i <= n; i++) debug("%d%c", a[i], " \n"[i==n]);
	for (int i = 1; i <= n; i++) {
		int c = n + 1 - (upper_bound(a + 1, a + n + 1, a[i] + m) - a);
		if (c + 1 > p) continue;
		int d = (upper_bound(a + 1, a + n + 1, a[i]) - a) - 2;
//		debug("%d %d %d\n", i, c, d);
		ll o = 1ll * m * (v - 1 - c - d) - (1ll * (a[i] + m) * (n - 1 - c - d) - (s[n-c] - s[d+1]));
//		dbg(o);
		if (o <= (s[n-c] - s[n-p+1]) - 1ll * (p - 1 - c) * a[i]) {
			print(n - i + 1);
			break;
		}
	}
	return 0;
}

#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll num[110][8];

int main(){
    int H,W,k;
    ll ans;
    cin>>H>>W>>k;
    num[0][0]=1;
    bool f=true;
    for(int i=1;i<8;i++) num[0][i]=0;
    for(int h=1;h<=H;h++){
        for(int w=0;w<(1<<(W-1))-1;w++){
            for(int i=0;i<W-1;i++){
                if(w>>i & 1  &&  w>>(i+1) & 1) f=false;
            }
            if(f){
                int v[]={0,1,2,3,4,5,6,7};
                for(int i=0;i<W-1;i++){
                    if(w>>i & 1){
                        v[W-1-i]--;
                        v[W-1-i-1]++;
                    }
                }
                for(int i=0;i<8;i++){
                    num[h][i]+=num[h-1][v[i]];
                    num[h][i]%=MOD;
                }
            }
            f=true;
        }
    }
    if(W==1){
        ans=1;
    }else{
        ans=num[H][k-1];
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    int size = s.size();
    reverse(s.begin(), s.end());
    s += '0';
    int carry = 0;
    int ans = 0;
    for (int i = 0; i < size + 1; i++) {
        int add = 0;
        if (s.at(i) - '0' + carry <= 4) {
            add = (s.at(i) - '0') + carry;
            carry = 0;
        } else if (s.at(i) - '0' + carry == 5) {
            add = 5;
            if (s.at(i + 1) - '0' >= 5) {
                carry = 1;
            } else {
                carry = 0;
            }
        } else {
            add = 10 - ((s.at(i) - '0') + carry);
            carry = 1;
        }

        ans += add;
    }

    cout << ans << endl;
}

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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0)
{
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

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

const int maxn = 2e6 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k)
    return 0;
  if(n < 0 || k < 0)
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (fat[i-1] * i) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll dp[maxn][2];
string s;

ll solve(int pos, int carry)
{
  if(pos == s.size())
    return carry;
  ll &ans = dp[pos][carry];
  if(ans != -1)
    return ans;
  int val = s[pos] - '0' + carry;
  ans = 1LL << 60;
  ans = min(ans, solve(pos + 1, 1) + 10 - val);
  ans = min(ans, solve(pos + 1, 0) + val);
  return ans;
}

int main()
{
  ios::sync_with_stdio(false);
  MSET(dp, -1);
  cin >> s;
  reverse(s.begin(), s.end());
  cout << solve(0,0) << endl;
  return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int M,ans=-1,g=0;
  cin>>M;
  vector<pair<int,int>> A(M);
  for(pair<int,int> &p:A){
    cin>>p.first>>p.second;
    ans+=p.second;
    g+=p.first*p.second;
  }
  cout<<ans+(g-1)/9<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF/10;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main() {
 ll n; cin>>n;
  ll k = 0;
  ll wa = 0;
  ll ans = 0;
  rep(i,n){
    ll a,b; cin>>a>>b;
    wa += a*b;
    k += b;
  }
  ll f;
  while(wa>=10){
    f = wa%10;
    wa/=10;
    k+=wa;
    wa +=f;}
  cout << k-1 << endl;}


#include<iostream>
using namespace std;
int a[13][32];
void day(void)
{
    int check=3;
    for(int i=1;i<13;i++){
        for(int j=1;j<32;j++){
            a[i][j]=check;
            check++;
            if(check==7)check=0;
            if((i==4||i==6||i==9||i==11)&&j==30)break;
            else if(i==2&&j==29)break;
        }
    }
}
int main()
{
    int mon,date;
    day();
    while(1){
        cin>>mon>>date;
        if(mon==0&&date==0)break;
        if(a[mon][date]==0)cout<<"Monday\n";
        else if(a[mon][date]==1)cout<<"Tuesday\n";
        else if(a[mon][date]==2)cout<<"Wednesday\n";
        else if(a[mon][date]==3)cout<<"Thursday\n";
        else if(a[mon][date]==4)cout<<"Friday\n";
        else if(a[mon][date]==5)cout<<"Saturday\n";
        else cout<<"Sunday\n";
    }

}

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

int main()
{
	int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	int m,day,sumday;
    while(1){
		cin >> m; // 月
		if (m==0){ break;}
		cin >> day;  //日付
		for(int i=0;i<m;i++){
			day+=month[i];
		}
		switch(day%=7){
			case 1:
				cout<<"Thursday"<<endl;
				break;
			case 2:
				cout<<"Friday"<<endl;
				break;
			case 3:
				cout<<"Saturday"<<endl;
				break;
			case 4:
				cout<<"Sunday"<<endl;
				break;
			case 5:
				cout<<"Monday"<<endl;
				break;
			case 6:
				cout<<"Tuesday"<<endl;
				break;
			default:
				cout<<"Wednesday"<<endl;
				break;
		}

	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<cmath>
#include<list>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 200000 + 8;

int n,a[maxn];
ll num = 0;

void Merge(int a[],int left,int mid,int right,int temp[])
{
    int i = left,j = mid + 1, cur = 0;
    //cout << left << " "<< mid <<" "<< right << " " << n1 <<endl;
    while(i <= mid && j <= right)
    {
        if(a[i] <= a[j]) {
            temp[cur++] = a[i++];
        } else{
            temp[cur++] = a[j++];
            num += mid - i + 1;
        }
    }

    while(i <= mid) temp[cur++] = a[i++];
    while(j <= right) temp[cur++] = a[j++];

    for(int z = 0; z < cur; ++z)
    {
        a[left + z] = temp[z];
    }
}
void MergeSort(int a[],int left,int right,int temp[])
{
    if(left < right)
    {
        int mid = (right + left) / 2;
        MergeSort(a, left, mid, temp);
        MergeSort(a, mid+1, right, temp);
        Merge(a,left,mid,right, temp);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; ++i)
        scanf("%d",&a[i]);

    int temp[maxn];
    MergeSort(a, 0, n-1,temp);
    printf("%lld\n", num);
    return 0;
}

/*
5
3 5 2 1 4
6
3 5 2 6 1 4
*/

#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;

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

ll n ;
cin>>n;

ll arr[n];
for(ll index = 0 ;index < n;index++)
{
    cin>>arr[index];
    if(arr[index]%2)
    {
        cout<<0<<endl;
        return 0;
    }
}

int ans =INT_MAX;

for(ll index =0;index <n;index++)
{
    int div = 2;
    int curr=0;
    while(arr[index]%div==0)
    {
        curr++;
        div*=2;
    }
    ans =min(ans,curr);
}

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


#include<bits/stdc++.h>
#define ll long long int
#define mod 998244353
#define ld long double
#define pb push_back
#define inf INT_MAX
#define N 1000000
using namespace std;
int n,m,k;
ll ans=0;
ll inv[N+3];
ll fact_inv[N+3];
ll fact[N+3];
//modulo inverse
void inverse(){
	inv[1]=1;//MMI
	int i;
	for(i=2;i<=N;i++){
		inv[i]=mod-(mod/i)*inv[mod%i]%mod;
	}
}
void factinv(){
	int i;
	fact_inv[0]=1;
	for(i=1;i<=N;i++){
		fact_inv[i]=fact_inv[i-1]*inv[i]%mod;
	}
}
void facto(){
	int i;
	fact[0]=1;
	for(i=1;i<=N;i++){
		fact[i]=(fact[i-1]*i)%mod;
	}
}
ll power(int a,int b){
	if(b==0)
	return 1;
	else if(b==1)
	return a;
	else{
		if(b&1)
		return ((a%mod)*(power(a,b-1)%mod))%mod;
		else
		return ((power(a,b/2)%mod)*(power(a,b/2)%mod))%mod;
	}
}
void solve(int p){
	ll a=((fact_inv[n-p-1]%mod)*(fact_inv[p]%mod))%mod;
	ll b=(m*power(m-1,n-p-1)%mod)%mod;
	ll c=(a*b)%mod;
	ans+=(fact[n-1]*c)%mod;
	ans%=mod;
}
int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i;
	cin>>n>>m>>k;
	facto();
	inverse();
	factinv();
	//cout<<inv[123]<<endl;
	for(i=0;i<=k;i++)
	solve(i);
	cout<<ans<<endl;
}

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

int main(){
  int N;
  cin>>N;
  int cnt=0;
  string A,B,C;
  cin>>A>>B>>C;
  for(int i=0;i<N;i++){
    if((A.at(i) == B.at(i))&&(B.at(i) == C.at(i))) continue;
    if((A.at(i) != B.at(i))&&(B.at(i) == C.at(i))){
      cnt++;
      continue;
    }
    if((A.at(i) == B.at(i))&&(B.at(i) != C.at(i))){
      cnt++;
      continue;
    }
    if((A.at(i) == C.at(i))&&(B.at(i) != C.at(i))){
      cnt++;
      continue;
    }
    cnt++;
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string s, t;
  cin >> N >> s >> t;
  for(int l=N; l<=2*N; l++) {
    string S(l, ' ');
    rep(i, N) S[i] = s[i];
    bool ok = true;
    rep(i, N) if(S[l-N+i] != ' ' && S[l-N+i] != t[i]) ok = false;
    if(ok) {
      cout << l << "\n";
      return 0;
    }
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int N;
    string s,t;
    cin>>N>>s>>t;
    long long len1,len2,count=0;
    len1=s.length();
    len2=t.length();
if(len1==len2&&len1==N&&N>=1&&N<=100){
 if (N>=len1+len2){
        count=N;
 }
else {
    count=len1+len2;
        for(int i=0;i<=len1;i++){
            for(int j=1;j<=len2;j++){
                if(s.substr(i,len1)==t.substr(0,j)&&len1+len2-j>=N){
                    count=min(len1+len2-j,count);
                }
            }
        }
}
cout<<count;
}
    return 0;
}


#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000*1000*1000+7;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, 1000);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(h); readint(w); readint(a); readint(b);
        vector<string> grid(h, string(w, '0'));
        forr(i,0,b) {
            forr(j,0,a) {
                grid[i][j] = '1';
            }
        }
        for(int i = b; i < h; ++i) {
            for(int j = a; j < w; ++j) {
                grid[i][j] = '1';
            }
        }
        for (auto s : grid) {
            cout << s << endl;
        }
    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

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

int main() {
    int H,W,A,B; cin >> H >> W >> A >> B;
    rep(i,H) {
        rep(j,W) {
            if (i < B) {
                cout << ((j < A) ? 0 : 1);
            } else {
                cout << ((j < A) ? 1 : 0);
            }
        }
        cout << endl;
    }
}


#include <stdio.h>

int main(void)
{
    int i, n, x;
    i = 1;
    x = i;
    scanf("%d", &n);

    while (i <= n) {
        x = i;
        if(x%3==0)
            printf(" %d", i);
        else {
            while(x) {
                if(x%10==3) {
                    printf(" %d", i);
                    break;
                } else
                    x/=10;
            }
        }
        i = i+1;
    }
    printf("\n");

    return 0;
}

#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x = i;
        if(x%3==0){
            cout<<' '<<i;
        }
        else if(x%10==3){
            cout<<' '<<i;
        }else{
            while(x/=10){
                if(x%10==3){
                cout<<' '<<i;
                break;
                }
            }

        }
    }
    cout<<endl;
	return 0;
}


#include <stdio.h>
int main(){
	int A;
	int B;
	int C;

	scanf("%d %d %d",&A,&B,&C);
	if (A==B && B!=C && C!=A) {
		printf("Yes\n");
	}
	else if (A==C && A!=B && C!= B){
		printf("Yes\n");
	}
	else if (B==C && A!=B && C!=A){
		printf ("Yes\n");
	}
	else printf ("No\n");
	return 0;
}

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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") {
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  set<int> nums;
  int a;
  while (cin >> a) nums.insert(a);
  cout << ((nums.size() == 2) ? "Yes" : "No") << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int N;
string S;

string Mena(string str) {
  string res = str;
  for (int i = 2; i < N; i++) {
    if ((S[i-1] == 'o' && res[i-1] == 'S') || (S[i-1] == 'x' && res[i-1] == 'W')) {
      res += res[i-2];
    } else {
      if (res[i-2] == 'W') {
        res += 'S';
      } else {
        res += 'W';
      }
    }
  }
  bool m = true;
  if ((S[N-1] == 'o' && res[N-1] == 'S') || (S[N-1] == 'x' && res[N-1] == 'W')) {
    if (res[N-2] != res[0]) {
      m = false;
    }
  } else {
    if (res[N-2] == res[0]) {
      m = false;
    }
  }
  if ((S[0] == 'o' && res[0] == 'S') || (S[0] == 'x' && res[0] == 'W')) {
    if (res[N-1] != res[1]) {
      m = false;
    }
  } else {
    if (res[N-1] == res[1]) {
      m = false;
    }
  }
  if (m) return res;
  else return "NG";
}
int main() {
  cin >> N >> S;
  string cand[4];
  cand[0] = Mena("SS");
  cand[1] = Mena("SW");
  cand[2] = Mena("WS");
  cand[3] = Mena("WW");
  for (int i = 0; i < 4; i++) {
    if (cand[i] != "NG") {
      cout << cand[i] << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

#include "algorithm"
#include "iostream"
#include "cmath"
#include "string"
#include "map"
using namespace std;

const char dir[4]={'N','E','S','W'};
int x[20],y[20];
int nx,ny,cnt;

void find(char d,int I,int N){
int a=-1;
  for(int i=0;i<4;++i){
    if(dir[i]==d)a=i;
  }
  for(int i=0;i<I;++i){
    if(a==0)ny+=1;
    if(a==1)nx+=1;
    if(a==2)ny-=1;
    if(a==3)nx-=1;
    for(int j=0;j<N;++j){
      if(x[j]==nx && y[j]==ny){
        ++cnt;
        x[j]=-1;
        y[j]=-1;
        break;
      }
    }
  }
}

int main(){
  while(true){
    int N,M,I;
    cnt=0;
    nx=10;
    ny=10;

    char d;
    cin >> N;
    if(!N)break;
    for(int i=0;i<N;++i){
      cin >> x[i] >> y[i];
    }
    cin >>M;
    while(M--){
      cin >> d >> I;
      find(d,I,N);
    }
    if(cnt==N)cout << "Yes" <<endl;
    else cout << "No" <<endl;
  }
  return 0;
}


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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

class Plant{
public:
	string name;
	int d,m;
	bool operator<(const Plant plant)const{
		if(m*plant.d==plant.m*d){
			return name<plant.name;
		}else{
			return m*plant.d>plant.m*d;
		}
	}
};

vector<Plant> plants;

int main() {
	int n;
	while(n=in()){
		plants.clear();
		string l;
		int p,a,b,c,d,e,f,s,m;
		int i;
		for(i=0;i<n;i++){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			Plant plant;
			plant.name=l;
			plant.d=a+b+c+(d+e)*m;
			plant.m=f*s*m-p;
			plants.push_back(plant);
		}
		sort(plants.begin(),plants.end());
		for(i=0;i<n;i++){
			cout<<plants[i].name<<endl;
//cout<<plants[i].d<<" "<<plants[i].m<<endl;
		}
		cout<<"#\n";
	}
	return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n)
	{
		long int ary[5001] = {};

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

		long int ans = -9999999999;
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ans = max(ans, ary[j] - ary[i]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int n, m;
	while(cin >> n, n) {
		int cnt[10] = {};
		rep(i,n) {
			cin >> m;
			cnt[m]++;
		}
		rep(i,10) {
			if(cnt[i]==0) cout << "-";
			else {
				rep(j,cnt[i]) cout << "*";
			}
			cout << endl;
		}
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int N;
long M,V,P;
long A[1<<17];
long po[1<<17];
main()
{
	cin>>N>>M>>V>>P;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	int Li=-1,Ri=N-1;
	long okv=A[N-P];
	while(Ri>=0&&A[Ri]>=okv)Ri--;
	Ri++;
	while(Ri-Li>1)
	{
		int Mi=(Li+Ri)/2;
		long dist=A[Mi]+M;
		long ret=M*(V-1);
		int okid=Mi;
		for(int i=0;i<N;i++)
		{
			if(i==Mi)po[i]=-1;
			else
			{
				if(A[i]<=dist)
				{
					po[i]=min(dist-A[i],M);
					okid=i;
				}
				else po[i]=0;
				ret-=po[i];
			}
		}
		if(N-okid-1>=P)
		{
			Li=Mi;
			continue;
		}
		if(ret<=0)
		{
			Ri=Mi;
			continue;
		}
		int id=N-1;
		for(int i=0;i<P-1;i++)
		{
			if(id==Mi)id--;
			if(id<0)break;
			ret-=M-po[id];
			id--;
		}
		if(ret<=0)
		{
			Ri=Mi;
		}
		else Li=Mi;
	}
	cout<<N-Ri<<endl;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N  = 5100;
int n,tot; ll a[N][N];
int vis[N * 20],pri[N];
void init()
{
	vis[1] = 1;
	for(int i = 2;i <= 10000;i ++)
	{
		if(!vis[i]) pri[++ tot] = i;
		for(int j = 1;j <= tot && pri[j] * i <= 10000;j ++)
		{
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0) break;
		}
	}
}
ll gcd(ll x,ll y){return y ? gcd(y,x % y) : x;}
ll lcm(ll x,ll y){if(!x || !y) return x | y; return x / gcd(x,y) * y;}
int main()
{
	n = read(); init();
	if(n == 2) {puts("4 7\n23 10"); return 0;}
	for(int i = 1;i <= n;i ++)
		for(int j = (i + 1 & 1) + 1;j <= n;j += 2)
			a[i][j] = pri[(i + j) / 2] * pri[n + (i - j) / 2 + (n + 1) / 2];
	for(int i = 1;i <= n;i ++)
		for(int j = (i & 1) + 1;j <= n;j += 2)
			a[i][j] = lcm(lcm(a[i - 1][j],a[i][j - 1]),lcm(a[i][j + 1],a[i + 1][j])) + 1;

	for(int i = 1;i <= n;i ++,cout << "\n") for(int j = 1;j <= n;j ++) cout << a[i][j] << " ";
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

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

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

ll a , b;

int main(){
    migmig
    ll ans = 1e18;
    cin >> a >> b;
    if(a <= b)ans = min(ans , b-a);
    if(-a <= b)ans = min(ans ,b+a+1);
    if(-a <= -b)ans = min(ans ,a-b+2);
    if(a <= -b)ans = min(ans , -b-a+1);
    cout << ans;
    return(0);
}


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

int main() {
  int n, r;
  cin >> n >> r;
  int ans = r + 100*max(0,10-n);
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <algorithm>

int main() {
  long long n, t;
  std::cin >> n >> t;
  long long timings[n], intervals[n - 1];
  for (long long i = 0; i < n; i++) {
    std::cin >> timings[i];
    if (i > 0) {
      intervals[i - 1] = timings[i] - timings[i - 1];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    ans += std::min(intervals[i], t);
  }
  ans += t;
  std::cout << ans << "\n";
  return 0;
}


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

int main() {
  const int MAX=1e5+10;
  int n,q;
  cin>>n>>q;
  string str;
  cin>>str;
  str+=' ';
  vector<int> a(MAX,0),s(MAX,0);
  for(int i=0;i<n;i++) {
    if(str[i]=='A'&&str[i+1]=='C') a[i+1]=1;
  }
  for(int i=0;i<MAX;i++) s[i+1]=s[i]+a[i];
  int l,r;
  for(int i=0;i<q;i++) {
    cin>>l>>r;
    cout<<s[r]-s[l]<<endl;
  }
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), wa(n);

  for (int i = 0; i < m; i++)
  {
    int p;
    string s;
    cin >> p >> s;

    if (ac[p - 1])
    {
      continue;
    }

    if (s == "WA")
    {
      wa[p - 1]++;
    }
    else
    {
      ac[p - 1] = 1;
    }
  }
  int AC = 0;
  int WA = 0;
  for (int i = 0; i < n; i++)
  {
    AC += ac[i];
    if (ac[i])
    {
      WA += wa[i];
    }
  }
  cout << AC << " " << WA << endl;
}


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

int main() {

  int n, m;
  while( cin >> n, n ) {
    int  student[n+1]; // 2:friend 1:friends_frined 0:others
    for(int i=1; i<=n; i++) student[i] = 0;
    cin >> m;
    int a[m+1], b[m+1];
    for(int i=0; i<m; i++) {
      cin >> a[i] >> b[i];
      if( a[i] == 1 ) student[b[i]] = 2;
    }

    for(int i=0; i<m; i++) {
      if( student[a[i]] == 2 && student[b[i]] != 2 ) {
	student[b[i]] = 1;
      }
      else if( student[b[i]] == 2 && student[a[i]] != 2 ) {
	student[a[i]] = 1;
      }
    }

    int ans = 0;
    for(int i=2; i<=n; i++) {
      if( student[i] > 0 ) ans++;
    }

    cout << ans << endl;
  }
}

#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct Edge
{
	int MFrom;
	int MTo;
};

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector< vector<int> > Vertex(n);
		vector<Edge> Vec(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> Vec[i].MFrom >> Vec[i].MTo;
			Vec[i].MFrom--; Vec[i].MTo--;
		}
		for(int i = 0; i < m; ++i)
		{
			Edge e = Vec[i];
			Vertex[e.MFrom].push_back(e.MTo);
			Vertex[e.MTo].push_back(e.MFrom);
		}
		set<int> Set;
		for(int i = 0; i < Vertex[0].size(); ++i)
		{
			int To = Vertex[0][i];
			Set.insert(To);
			for(int j = 0; j < Vertex[To].size(); ++j)
			{
				Set.insert(Vertex[To][j]);
			}
		}
		Set.count(0) ? cout << Set.size() - 1 : cout << Set.size();
		cout << endl;
	}
}

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


#include <stdio.h>

#define MYSCAN scanf

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

	while (true){

		MYSCAN("%d", &n);
		if (n == 0){ break; }
		for (int i = 0; i < n; i++){
			MYSCAN("%d%d%d", &pm, &pe, &pj);
			if (pm == 100 || pe == 100 || pj == 100){
				printf("A\n");
			}
			else if (pm + pe >= 180){
				printf("A\n");
			}
			else if (pm + pe + pj >= 240){
				printf("A\n");
			}
			else if (pm + pe + pj >= 210){
				printf("B\n");
			}
			else if (pm + pe + pj >= 150 && (pm >= 80 || pe >= 80)){
				printf("B\n");
			}
			else{
				printf("C\n");
			}
		}
	}
	return 0;
}

#include <iostream>

using namespace std;

char divide(int m, int e, int j) {
    if (m == 100 || e == 100 || j == 100) return 'A';
    if ( (m+e)/2 >= 90 ) return 'A';
    if ( (m+e+j)/3 >= 80 ) return 'A';
    if ( (m+e+j)/3 >= 70 ) return 'B';
    if ( (m+e+j)/3 >= 50 && (m >= 80 || e >= 80) ) return 'B';
    return 'C';
}

int main() {
    int n;
    while (cin >> n, n) {
        while (n--) {
            int pm, pe, pj;
            cin >> pm >> pe >> pj;
            cout << divide(pm, pe, pj) << endl;
        }
    }
    return 0;
}


//
//  abc167_Bracket_Sequencing.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265

std::map<int, int> factorization (int n) {
  std::map<int, int> f;
  for (int i = 2; i*i <= n; i++) {
    while (n%i == 0) {
      f[i] += 1;
      n /= i;
    }
  }
  if (n > 1) {
    f[n] += 1;
  }
  return f;
}

ll modpow (int x, int n) {
  if (n==0) return 1%mod;
  ll u = modpow(x, n/2);
  u = (u*u)%mod;
  if (n%2==1) u = (u*x)%mod;
  return u;
}

void dfs(vector<int> A, int n, int m)  {
  if  (A.size() > n) {
    for (int i = 1; i <= n; i++) {
      std::cout << A[i];
    }
    std::cout << std::endl;
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A, n, m);
    A.back()++;
  }
}

const int MAX = 510000;

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

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

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

ll HCOM(int n, int k) {
    return (n == 0 && k == 0) ? 1 : COM(n+k-1, k);
}

int main() {
  ll n;
  std::cin >> n;
  std::vector<string> s;

  priority_queue<pair<ll, ll> > pos_q;
  priority_queue<pair<ll, ll> > neg_q;

  ll final_balance = 0;
  for (int i = 0; i < n; i++) {
    std::string t;
    std::cin >> t;
    s.push_back(t);

    ll balance = 0;
    ll min_prefix = 0;
    for (int j = 0; j < t.size(); j++) {
      if (t[j] == '(') {
        balance++;
      }
      else {
        balance--;
      }
      min_prefix = min(min_prefix, balance);
    }
    final_balance += balance;
    if (balance != 0 || min_prefix != 0) {
      if (balance >= 0) {
        pos_q.push(make_pair(min_prefix, balance));
      }
      else {
        neg_q.push(make_pair(min_prefix - balance, -balance)); // reverse sequence
      }
    }
  }

  bool check_pos = true;
  int b_pos = 0;

  while (!pos_q.empty()) {
    pair<int, int> pos = pos_q.top();
    pos_q.pop();
    int prefix = b_pos + pos.first;
    if (prefix < 0) { check_pos = false; break; }
    b_pos += pos.second;
  }

  bool check_neg = true;
  int b_neg = 0;

  while (!neg_q.empty()) {
    pair<int, int> neg = neg_q.top();
    neg_q.pop();
    int prefix = b_neg + neg.first;
    if (prefix < 0) { check_neg = false; break; }
    b_neg += neg.second;
  }

  if (final_balance == 0 && check_neg && check_pos) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  // std::cout << " balance: " << final_balance << " prefix: " << final_prefix << std::endl;

  return 0;
}

//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
using namespace std;

#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vector<int>>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int>
#define all(v)          v.begin(),v.end()
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define itr(v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fd(i,n)         for(int i=n-1;i>=0;i--)
#define fir(i,a,b)      for(int i=a;i<b;i++)
#define fin(s)          freopen(s,"r",stdin);
#define fout(s)         freopen(s,"w",stdout);
#define MAXZ            200005
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}
bool cmp(pii a,pii b){
    int c1=a.first-a.second;
    int c2=b.first-b.second;
    if(c1*c2>=0){
        if(c1>=0 && c2>=0){
            return a.second<b.second;
        }
        else{
            return a.first>b.first;
        }

    }
    else{
        if(c1>0){
            return 1;
        }
        else{
            return 0;
        }
    }
}
 string a[2000001];
int32_t main()
{
    FIO
    int n; cin>>n;
    fi(i,n) cin>>a[i];
    vector<pii> v;
    int uop=0,ucp=0;
    fi(i,n) {
        int op=0,cp=0;
        int count=0;
        for(int j=0;j<a[i].length();j++){
            if(a[i][j]=='('){
                count++;
            }
            else{
                if(count<=0) {
                    cp++;
                }
                else count--;
            }
        }
        op+=count;
        pii p1(op,cp);
        if(op==0 || cp==0){
            uop+=op;
            ucp+=cp;
        }
        else v.pb(p1);
        // cout<<a[i]<<" "<<op<<" "<<cp<<"\n";
    }
    sort(v.begin(),v.end(),cmp);
    int ans=1;
    int op=uop;
    for(int i=0;i<v.size();i++){
        // cout<<v[i].first<<" "<<v[i].second<<"\n";
        op=op-v[i].second;
        if(op<0) {
            ans=0;
            break;
        }
        op+=v[i].first;
    }
    op-=ucp;
    if(op==0 && ans){
        cout<<"Yes\n";
    }
    else cout<<"No\n";

}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;

    vector<vector<int>> A(N, vector<int>(N)), day(N, vector<int>(N));
    vector<int> index(N);

    rep(i, N) {
        rep(j, N - 1) {
            cin >> A[i][j];
        }
    }

    int maxloop = (N * (N - 1)) / 2;
    int before = 0;
    for (int l = 0; l < maxloop; l++) {
        for (int i = 0; i < N; i++) {
            if (index[i] < N - 1) {
                int to = A[i][index[i]];
                if (i + 1 == A[to - 1][index[to - 1]]) {
                    int value = max(day[i][index[i]], day[to - 1][index[to - 1]]);
                    // cout << i + 1 << " " << to << " " << value + 1 << endl;
                    day[i][index[i] + 1] = value + 1;
                    day[to - 1][index[to - 1] + 1] = value + 1;
                    index[i]++; index[to - 1]++;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < N; i++) {
            res += index[i];
        }
        if (res == before || res == (N - 1) * N) break;
        before = res;
    }

    int sum = 0;
    rep(i, N) sum += index[i];

    int cnt = 0;
    rep(i, N) {
        chmax(cnt, day[i][N - 1]);
    }

    if (sum == (N - 1) * N) {
        cout << cnt << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

int main(){
    /*
    int n; cin >> n;
    vi x(n), y(n);
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
    }
    */
    int n; cin >> n;
    vector<queue<int>> com(n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            int a; cin >> a;
            a--;
            com[i].push(a);
        }
    }

    set<int> prev;
    for(int i=0; i<n; i++) prev.insert(i);
    int ans=0;
    while(!prev.empty()){
        set<int> tmp;
        bool flag=false;
        for(auto p: prev){
            if(com[p].empty()) continue;
            int op=com[p].front();
            flag=true;
            if(com[op].front() == p){
                tmp.insert(p);
                tmp.insert(op);
            }
        }
        for(auto p: tmp){
            com[p].pop();
        }
        if(tmp.empty()){
            if(flag) ans=-1;
            break;
        }
        ans++;
        prev=tmp;
    }

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=1e18;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n),dp(n+1,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    dp[i+1]=dp[i]+a[i];
  }
  for(int split=2;split+1<n;split++){
    ll p=0,q=dp[split],r=0,s=dp[n];
    auto itr1 = lower_bound(dp.begin(), dp.end(), dp[split]/2);
    auto itr2 = lower_bound(dp.begin(), dp.end(), (dp[n]+dp[split])/2);

    for(int d=-1;d<2;d++){
      if(max(p,q-p)>max(*(itr1+d),q-*(itr1+d))){
        p=*(itr1+d);
      }
      if(max(r-q,s-r)>max(*(itr2+d)-q,s-*(itr2+d))){
        r=*(itr2+d);
      }
    }
    ll diff=max({s-r,r-q,q-p,p})-min({s-r,r-q,q-p,p});
    ans=min(ans,diff);
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int n,ans,q[1<<17],f[1<<17],dp[1<<17],a[1<<17];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	memset(q,0x3f,sizeof(q));
	for(int i=1;i<=n;i++){
		f[i]=upper_bound(q+1,q+n,-a[i])-q;
		q[f[i]]=-a[i];
		ans=max(ans,f[i]);
	}
	cout<<ans<<endl;
 }


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int find_(int x,vector<pair<ll,ll>> &v){
    if(v[x].first<0) return x;
    v[x].first=find_(v[x].first,v);
    return v[x].first;
}

int same_(int a,int b,vector<pair<ll,ll>> &v){
    if(find_(a,v)==find_(b,v)) return 1;
    return 0;
}

void union_(int a,int b,vector<pair<ll,ll>> &v){
    if(same_(a,b,v)) return;
    int a_p=find_(a,v),b_p=find_(b,v);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p].first+=v[b_p].first;
    v[a_p].second+=v[b_p].second;
    v[b_p].first=a_p;
}

/*
void print_v(vector<pp> v){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int size_(int a,vector<pp> &v){
    return -v[find_(a,v)];
}
*/

int main() {
    int h,w; cin>>h>>w;
    vector<string> s(h,"");
    rep(i,h) cin>>s[i];
    vector<pair<ll,ll>> v(h*w,mk(-1,0));
    rep(i,h*w){
        if(s[i/w][i%w]=='#') v[i].second=-1;
    }
    rep(i,(h-1)*w) if(s[i/w][i%w]!=s[i/w+1][i%w]) union_(i,i+w,v);
    rep(i,h*w){
        if(i%w==w-1) continue;
        if(s[i/w][i%w]!=s[i/w][i%w+1]) union_(i,i+1,v);
    }
    ll ans=0;
    rep(i,h*w){
        if(v[i].first<0)
        ans+=(-v[i].second)*(v[i].second-v[i].first);
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;
  vector<string> m(h);
  for (int i = 0; i < h; ++i) {
    cin >> m[i];
  }

  vector<vector<bool>> seen(h, vector<bool>(w, false));

  long long ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; j++) {
      long long b_cnt, w_cnt;
      b_cnt = w_cnt = 0;
      stack<array<int, 3>> st;
      st.push({i, j, m[i][j] != '#'});
      while (!st.empty()) {
        auto t = st.top();
        int y = t[0], x = t[1], p = t[2];
        st.pop();

        if (y < 0 || y >= h || x < 0 || x >= w) {
          continue;
        }

        if (seen[y][x] || p == m[y][x]) {
          continue;
        }

        seen[y][x] = true;

        if (m[y][x] == '.') {
          w_cnt++;
        } else {
          b_cnt++;
        }

        st.push({y - 1, x, m[y][x]});
        st.push({y + 1, x, m[y][x]});
        st.push({y, x + 1, m[y][x]});
        st.push({y, x - 1, m[y][x]});
      }

      ans += b_cnt * w_cnt;
    }
  }

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


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<int> c(N + 1, 0);
  c[0] = 3;

  LL v = 1;
  int index = 0;
  for (int i = 0; i < N; ++i) {
    int x; cin >> x;
    LL y = c[x];
    v = (v * y) % kMod;

    --c[x];
    ++c[x+1];

#if 0
    index = max(index, x + 1);
    cout << x << ":";
    for (int i = 0; i <=index; ++i) cout << c[i] << " ";
    cout << "->" << y << endl;
#endif
  }
  cout << v << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
    int n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    int cnt=0;
    rep(i,n){
        char aa=a.at(i);
        char bb=b.at(i);
        char cc=c.at(i);
        if(aa!=bb && aa!=cc && bb!=cc)cnt+=2;
        else if(aa==bb && aa!=cc)cnt++;
        else if(aa==cc && aa!=bb)cnt++;
        else if(bb==cc && bb!=aa)cnt++;
    }
    cout << cnt << endl;
}


#include<iostream>
using namespace std;

main(){
  int K,X,s,e,max_x = 1000000, min_x = -1000000;
  cin>>K>>X;
  if(X-K+1>min_x) s = X-K+1;
  else s = min_x;
  if(X+K>max_x) e=max_x;
  else e = X+K;
  for(int i=s;i<e;i++){
    cout<<i<<" ";
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))

//3111111111111111111111111111111

	bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}

	void solve(){

		ini(n);
		vi morty;
		int i = 1;
		while(morty.size()!=55){
			i++;
			int tmp = i*5+1;
			while(!isprime(tmp)){
				i++;
				tmp = i*5+1;
			}
			morty.push_back(tmp);
		}
		FOR(i,0,n){
			cout<<morty[i]<<" ";
		}
		out();

	}

int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall

	solve();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl
#define TGET(a, b) get<b>(a)

#define MAXN 200100

ll arr[MAXN] = {0};
ll odd_pos[MAXN] = {0};
ll even_pos[MAXN] = {0};

ll dp[MAXN] = {0};

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", arr + i);
    }

    for (int i = 1; i <= n; i += 2)
    {
        if (i == 1)
        {
            odd_pos[i] = arr[i];
            even_pos[i + 1] = arr[i + 1];
        }
        else
        {
            odd_pos[i] = arr[i] + odd_pos[i - 2];
            even_pos[i + 1] = arr[i + 1] + even_pos[i - 1];
        }
    }
    // ll ans = even_pos[n-1];
    // for (int i = 1; i <= n; i += 2)
    // {
    //     ans = max(ans, odd_pos[n] - arr[i]);
    //     ans = max(ans, (odd_pos[i] - arr[i]) + (even_pos[n - 1] - even_pos[i - 1]));
    //     ans = max(ans, (odd_pos[i] - arr[i]) + arr[i + 1] + (odd_pos[n] - odd_pos[i + 2]));
    // }
    // printf("%ld\n", ans);
    for (int i = 2; i <= n; i++)
    {
        if (i % 2)
        {
            dp[i] = max(dp[i - 2] + arr[i], dp[i - 1]);
        }
        else
        {
            dp[i] = max(odd_pos[i - 1], dp[i - 2] + arr[i]);
        }
    }
    printf("%lld\n", dp[n]);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  vector<vector<vector<ll>>>
    dp(N+1, vector<vector<ll>>(2, vector<ll>(3, -longinf))); // index, select(1) or not(0), not select count
  dp[0][0][0] = 0;
  rep(i, N) {
    rep(k, 3) { // select
      dp[i+1][1][k] = max(dp[i][0][k]+A[i], dp[i+1][1][k]);
    }
    if(i) { // not select
      rep(k, 3) { // selected previous index
        dp[i+1][0][k] = max(dp[i][1][k], dp[i+1][0][k]);
      }
      rep(k, 2) { // not selected previous index
        dp[i+1][0][k+1] = max(dp[i][0][k], dp[i+1][0][k+1]);
      }
    } else {
      dp[i+1][0][1] = 0;
    }
  }

  ll ans = -longinf;
  if(N%2) ans = max(dp[N][1][2], dp[N][0][1]);
  else ans = max(dp[N][1][1], dp[N][0][0]);
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	int before_min = arr[0];
	int ret = 0;
	for(int i=0; i<n; i++){
		before_min = min(before_min,arr[i]);
		if(before_min>=arr[i]) ret++;
	}
	cout<<ret;
}

#include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   string s;cin >>s;
   string ans="";
   int w;cin >>w;
   for(int i=0;i<(int)s.size();i+=w){
     ans+=s[i];
   }
   cout <<ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {
ll A,B;
  cin>>A>>B;
  ll ans=1;
  for(ll i=2;i<=sqrt(min(A,B));i++) {
if(A%i==0&&B%i==0) {
ans++;
}
    if(A%i==0) {
while(A%i==0) {
A/=i;
}
    }

    if(B%i==0) {
while(B%i==0) {
B/=i;
}
    }
  }

  if(A>1&&B>1) {
if(A%B==0||B%A==0) {
ans++;
}
  }

  cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    ll A,B;
    cin >>A>>B;

    const auto &res = prime_factorize(gcd(A,B));

    cout<<res.size()+1<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int k,x;
    cin >> k >> x;
    int a = k-1;
    for(int i=x-a;i<=x+k-1;i++){
        cout << i;
        cout << " ";
    }
    cout << endl;
}

#include <stdio.h>

int main (){
	char w1[101], w2[101];
	scanf ("%s %s", &w1, &w2);
	printf ("%s%s", w2, w1);
	return 0;
}


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

int main() {
string az="abcdefghijklmnopqrstuvwxyz";
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    int i=0,j=0;
    for(int j=0;j<s.length();j++) {
        if(az[i]==s[j]) {
		i++;
		}
        if(i==26) {
		cout << "None" << endl;
		return 0;
		}
    }
    cout << az[i];
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main()
{
	string s;
	set<int> m2;
	vector<int> result;
	cin>>s;
	for(int i = 0; i < s.length(); i++){
		int num = s[i] - 'a';
		if(m2.count(num) == 0) m2.insert(num);
	}

	for(int i = 0; i < 26; i++){
		if( m2.count(i) == 0) result.push_back(i);
	}
	if( result.size() == 0){
		cout<<"None"<<endl;
	}else{
		cout<<(char)(result[0] + 'a')<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
void changeString(string &t,string p){
    if(t=="0") t=p;
    else if(t.size()<p.size()) t=p;
    else if(t.size()==p.size()){
        if(t<p) t=p;
    }
}
string dp[MAX];
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    sort(ALL(a));
    REP(i,m)IN(a[i]);
    int num[10]={0,2,5,5,4,5,6,3,7,6};
    REP(i,MAX){
        dp[i]="0";
    }
    dp[0]="";
    REP(i,n+1){
        if(dp[i]=="0")continue;
        REP(j,m){
            changeString(dp[i+num[a[j]]],dp[i]+(char)(a[j]+'0'));
        }
    }
    OUT(dp[n]);
    return 0;
}

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

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

  vector<int> v = {2,5,5,4,5,6,3,7,6};

  int n,m;
  cin >> n >> m;
  int use = 0;
  rep(i,m){
    int a;
    cin >> a;--a;
    use |= (1<<a);
  }
//  cout << bitset<9>(use) << endl;
  vector<int> dp(n+1,-INT_MAX/5);
  dp[0] = 0;
  rep(i,n+1){
    for(int j=8;j>=0;j--){
      if((1<<j) & use) {
	int nidx = i + v[j];
	if(nidx<=n){
	  dp[nidx] = max(dp[nidx],dp[i]+1);
	  //	  cout << "i ni dpni " << i << " " << nidx << " " << dp[nidx] << endl;
	}
      }
    }
  }
  int cidx = n;
  while(cidx!=0){
    for(int j=8;j>=0;j--){
      if((1<<j) & use) {
	int nidx = cidx - v[j];
	if(nidx>=0 && dp[nidx] +1 == dp[cidx]){
	  cidx=nidx;
	  cout << j+1;
	  break;
	}
      }
    }
  }
  cout << endl;
  //  cout << dp[n] << endl;

  return 0;

}


#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
    int n,m;
    string S;
    int dice[6];
    for(int i=0;i<6;i++){
        cin>>dice[i];
    }
    cin>>S;
    for(int i=0;i<S.size();i++){
        if(S[i]=='N'){
            m=dice[0];
            dice[0]=dice[1];
            dice[1]=dice[5];
            dice[5]=dice[4];
            dice[4]=m;
        }
        else if(S[i]=='S'){
            m=dice[0];
            dice[0]=dice[4];
            dice[4]=dice[5];
            dice[5]=dice[1];
            dice[1]=m;
        }
        else if(S[i]=='W'){
            m=dice[0];
            dice[0]=dice[2];
            dice[2]=dice[5];
            dice[5]=dice[3];
            dice[3]=m;
        }
        else if(S[i]=='E'){
            m=dice[0];
            dice[0]=dice[3];
            dice[3]=dice[5];
            dice[5]=dice[2];
            dice[2]=m;
        }
        m=0;
    }
    cout<<dice[0]<<endl;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	string a,b,c; cin>>a>>b>>c;
	int ans=0;
	rep(i,0,n){
		if(a[i]!=b[i] && b[i]!=c[i] && a[i]!=c[i])ans+=2;
		else if(a[i]==b[i] && b[i]==c[i] && a[i]==c[i])ans=ans;
		else ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	ll N;cin>>N;
  vi z(5);
  rep(i,5)cin>>z[i];

  ll neck = distance(z.begin(), min_element(all(z)));

  //DEBUG(neck);

  ll ans = 0;
  ans += 4;
  ans += (N+z[neck]-1)/z[neck];

  cout<<ans<<endl;
}

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

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

    vector<int> a(3);
    int k;
    rep(i,3) cin >> a[i];
    cin >> k;
    sort(a.begin(),a.end(),greater<>());
    rep(i,k) a[0]*=2;
    cout << a[0]+a[1]+a[2] << endl;

    return 0;

}