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

int main(){
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  vi cnt(n);
  for(int i = n-1; 0 <= i; i--){
    int sum = 0;
    for(int j = i; j < n; j += i+1) sum ^= cnt[j];
    cnt[i] = sum^a[i];
  }
  vi ans;
  rep(i,n) if(cnt[i]) ans.push_back(i+1);
  cout << ans.size() << "\n";
  if(ans.size()) for(auto x : ans) cout << x << " ";
  cout << "\n";
  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;

const int mod = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<bool> a(N + 1);

    for (int i = 1; i <= N; i++) {
        int ai;
        cin >> ai;
        if (ai == 1) {
            a[i] = false;
        } else {
            a[i] = true;
        }
    }

    vector<bool> c(N + 1, false); //すくなくとも1つはiの倍数（i自身）があるのでfalse(割ったあまりが1)
    vector<vector<int>> divisor(N + 1);
    for (int i = 1; i <= N; i++) {
        for (int j = 2 * i; j <= N; j += i) {
            divisor[j].push_back(i);
        }
    }

    vector<int> b;
    for (int i = N; i >= 1; i--) {
        if (a[i] == c[i]) {
            b.push_back(i);
            for (int d : divisor[i]) {
                c[d] = !c[d];
            }
        }
    }

    reverse(b.begin(), b.end());
    int M = b.size();
    cout << M << endl;
    rep(i, M)
    {
        printf("%d%c", b[i], i == M - 1 ? '\n' : ' ');
    }

    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  k--;
  cout << n - k << endl;
}

#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}

int main(){
  int A,B; cin>>A>>B;
  cout<<A-B+1;

}

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

vector<vector<char>> d(100, vector<char>(100));
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){
    int r,c;
    cin >> r >> c;
    int sy = 0, sx = 0;
    int gx, gy;
    gx = r-1, gy = c-1;
    int cnt_w = 0;
    rep(i, r){
        rep(j, c){
            cin >> d.at(i).at(j);
            if(d[i].at(j) == '.'){
                cnt_w++;
            }
        }
    }
    vvi dep(r, vi(c, -1));
    dep.at(sy).at(sx) = 0;

    queue<pair<int, int> > que;
    que.push(make_pair(sy, sx));

    while(!que.empty()){
        pair<int, int> pos = que.front();
        que.pop();
        int x = pos.second;
        int y = pos.first;

        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx > c-1 || ny < 0 || ny > r-1)
            continue;
            if(d.at(ny).at(nx) == '#')
            continue;

            if(dep.at(ny).at(nx) == -1){
                que.push(make_pair(ny, nx));
                dep.at(ny).at(nx) = dep.at(y).at(x) + 1;
            }
        }
    }
    /*
    rep(i, r){
        rep(j, c){
            printf("%3d", dep.at(i).at(j));
        }
        cout << endl;
    }
    */
    if(dep.at(gx).at(gy) == -1) {
        cout << -1 << endl;
    }
    else {
        cout << cnt_w - dep.at(gx).at(gy)-1 << endl;
    }
    return 0;
}

// D - Make Them Even

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

struct Cell {
	int y;
	int x;
	int c;
};

struct Move {
	int y1;
	int x1;
	int y2;
	int x2;
};

int field[500][500];
Cell cells[500 * 500];

int main() {
	int H, W;
	cin >> H >> W;

	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			cin >> field[i][j];
		}
	}

	int k = 0;
	for (int i=0; i<H; i++) {
		if (i % 2 == 0) {
			for (int j=0; j<W; j++) {
				cells[k] = {i, j, field[i][j]};
				k++;
			}
		} else {
			for (int j=W-1; j>=0; j--) {
				cells[k] = {i, j, field[i][j]};
				k++;
			}
		}
	}

	int N = 0;
	vector<Move> ans;
	for (int i=0; i<H*W-1; i++) {
		if (cells[i].c % 2 == 1) {
			ans.push_back(Move{cells[i].y, cells[i].x, cells[i+1].y, cells[i+1].x});
			cells[i+1].c++;
			N++;
		}
	}

	cout << N << endl;
	for (Move a : ans) {
		cout << a.y1 + 1 << " " << a.x1 + 1 << " " << a.y2 + 1 << " " << a.x2 + 1 << endl;
	}

	return 0;
}


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

int main(){
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int hour;
  int min;

  int t1, t2, t3;
  t3 = h2 * 60 + m2;
  t2 = t3 - k;
  t1 = h1 * 60 + m1;

  int ans;

  ans = t2 - t1;

  cout << ans << endl;

}

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

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

char sep[2] = {' ', '\n'};

int main() {
  int i, j, k;
  int n;
  int a[110];

  cin >> n;
  rep(i, n) cin >> a[n - i - 1];
  rep(i, n) cout << a[i] << sep[(i == n - 1)];
  cout << flush;

  return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int insertionSort(int, int, int);
void shellSort(int* , int);
int cnt = 0;
int main(void)
{
	int A[1000000], N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	shellSort(A, N);
}
int insertionSort(int A[], int n, int g)
{
	int v, j, cnt = 0;
	for (int i = g; i < n; i++) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
	return (cnt);
}
void shellSort(int A[], int n)
{
	int cnt = 0;
	int m = 0;
	int G[13] = {  };
	do {
		if (m == 0) { G[0] = n - 1; }
		else { G[m] = G[m - 1] / 2; }
		m++;
	} while (G[m - 1] > 1);
	cout << m << endl;
	for (int i = 0; i < m; i++) {
		cnt += insertionSort(A, n, G[i]);
		cout << G[i] << " ";
	}
	cout << endl << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << A[i] << endl;
	}
}

/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}

int main()
{

    fastread();

    ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

    bool flag=true;

    string str;

    cin>>n;

    ll ara[n+2],bra[n+2];

    input(ara,n);
    input(bra,n);

    sort(bra,bra+n,greater<ll>());

    for(i=0; i<n; i++)
    {
        if(ara[i]==bra[i])
        {

        bool ok=false;

            for(j=0; j<n; j++)
            {
                if(j<i && ara[i]!=bra[j]  && bra[i]!=ara[j])
                {
                    swap(bra[i],bra[j]);

                    ok=true;
                    break;
                }

                else if(n-j-1>i)
                {
                    p=n-j-1;

                    if(ara[i]!=bra[p])
                    {
                        swap(bra[i],bra[p]);

                        ok=true;
                        break;
                    }
                }
            }

            if(ok==false)
            {
                flag=ok;
                break;

            }

        }
    }

    if(flag)
    {
        for(i=0; i<n; i++)
        {
            if(ara[i]==bra[i])
            {
                flag=false;
                break;
            }
        }
    }

    if(flag==false)
        cout<<"No"<<endl;

    else
    {
        cout<<"Yes"<<endl;

        for(i=0; i<n; i++)
        {
            cout<<bra[i]<<" ";
        }

        cout<<endl;
    }

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 20000
#define ARRAY_MAX 200005

typedef struct union_find{

    int pa[ARRAY_MAX];
    int ra[ARRAY_MAX];
    //vector<int> pa(ARRAY_MAX);//親
    //vector<int> ra(ARRAY_MAX);//木の深さ
    //n要素で初期化
    void init(int n){
        for(int i = 0;i < n;i++){
            pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
            ra[i] = 0;/*各ノード自体の高さは0*/
        }
    }
    //木の根を求める
    int find(int x){
        if(pa[x] == x){
            return x;/*根ならそのノードの番号を返す*/
        }else{
            return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
        }
    }

    //xとyの属する集合を併合する
    void unite(int x,int y){
        x = find(x);//xの根の番号を探す
        y = find(y);//yの根の番号を探す
        if(x == y){//一致すればつながっている
            return;
        }
        if(ra[x] < ra[y]){//xの高さが低いなら高いほうにつなぐ、そして高さは大きい方(y)になる
            pa[x] = y;
        }else{
            pa[y] = x;//yの高さが低いなら高いほうにつなぐ、そして高さは大きいほう(x)になる
            if(ra[x] == ra[y]){//高さが一致しているなら併合の高さは1増える
                ra[x]++;
            }
        }
    }

    //xとyが同じ集合に属するか判定
    bool same(int x,int y){
        return find(x) == find(y);//同じ集合なら1、違うなら0が返る
    }
}UF;

UF road,rail;

int main(){

    int n,k,l;
    cin >> n >> k >> l;
    road.init(n+2);
    rail.init(n+2);
    REP(i,k){
        /*道路*/
        int p,q;
        cin >> p >> q;

        p--;q--;/*配列の添え字に合わせる*/
        road.unite(p,q);
    }

    REP(i,l){
        /*鉄道*/
        int r,s;
        cin >> r >> s;
        r--;s--;/*配列の添え字に合わせる*/
        rail.unite(r,s);
    }

    map<P,int> mp;
    REP(i,n){
        /*i番目の都市の親のペアをカウント、一致するペアがあればi番目の都市と道路でも鉄道でも連結している*/
        mp[P(road.find(i),rail.find(i))]++;
    }

    map<P,int>::iterator itr;
    REP(i,n){
        if(i == 0){
            cout <<  mp[P(road.find(i),rail.find(i))];
        }else{
            cout << " " << mp[P(road.find(i),rail.find(i))];
        }
    }
    cout << endl;

}

#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

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

    int a, b;
    vector<vector<int>> count(501, vector<int>(501, 0));
    rep(i, m){
        cin >> a >> b;
        count[a][b]++;
    }
    vector<vector<int>> sum(501, vector<int>(501, 0));
    _rep(i, 1, n + 1)_rep(j, 1, n + 1){
        sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + count[i][j];
    }
    rep(i, q){
        cin >> a >> b;
        cout << sum[b][b] - sum[b][a - 1]- sum[a - 1][b] + sum[a - 1][a - 1] << endl;
    }
}


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

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  bool ans = true;
  //1
  if (S[0]!='A') ans = false;

  //2
  int Ccnt = 0;
  for  (int i = 2; i <= S.length()-2; i++) {
    if (S[i]=='C') Ccnt++;
  }
  if (Ccnt!=1) ans = false;

  //3
  int CpCnt = 0;
  for (int i = 0; i < S.length(); i++) {
    if (('A'<= S[i]) && (S[i] <= 'Z')) CpCnt++;
  }
  if (CpCnt != 2) ans = false;

  if (ans) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int k, n;
int main() {
    DAU
    cin >> k >> n;
    for (int i = n - k + 1; i < n + k; ++i)
        cout << i << ' ';
    PLEC
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int ans[N];
#define pii pair<int, int>
set<pair<int, pii> > s;
set<pii> pers;
int main(){
    int n, q;
    sc(n);sc(q);
    fr(i, 1, n){
        int st, en, x;
        sc(st);sc(en);sc(x);
        s.insert({x, {st, en}});
    }
    fr(i,1,q){
        int x;sc(x);
        pers.insert({x, i});
    }
    fr(i, 1, q) ans[i] = -1;
    for(auto it: s){
        int x = it.fi;
        int st = it.se.fi;
        int en = it.se.se;
        while(pers.size()){
            auto lb = pers.lower_bound({st - x, -1});
            if (lb == pers.end()) break;
            if (lb->fi < en-x){
                pers.erase(lb);
                ans[lb->se] = x;
            }
            else break;
        }
    }
    fr(i,1,q){
        pr(ans[i]);n_l;
    }
    return 0;
}


#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main(){

	double x1, x2, y1, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	if (x1 == x2){
		cout << setprecision(12) << fabs(y1 - y2) << endl;
	}
	else if (y1 == y2){
		cout << setprecision(12) << fabs(x1 - x2) << endl;
	}
	else {
		cout << setprecision(12) << sqrt(pow(fabs(x1 - x2), 2) + pow(fabs(y1 - y2), 2)) << endl;
	}

	return 0;
}

#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int main(){
	double x1, y1, x2, y2;
	double ans;

	cin >> x1 >> y1 >> x2 >> y2;
	ans = pow((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1), 0.5);

	printf("%.8f\n", ans);

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K;

int main(){
	getint(N), getint(K);
	return printf("%d\n", N - K + 1), 0;
}

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

int main(){
    int n; cin>> n;
    vector<ll> a(100000);
    set<ll> memo;

    for(int i=0; i<n; i++){
        cin >> a[i];
        if(memo.count(a[i])){
            memo.erase(a[i]);
        }else{
            memo.insert(a[i]);
        }
    }
    int ans = memo.size();
    cout << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;

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

	while(n--){
		int out = 0;
		int first=0,second=0,third=0,score=0;
		while(out < 3){
			string s;
			cin>>s;
			if(s == "HIT"){
				score += third;
				third = second;
				second = first;
				first = 1;
			}
			else if(s == "HOMERUN"){
				score += third + second + first + 1;
				third = second = first = 0;
			}
			else{
				out++;
			}
		}
		cout<<score<<endl;
	}

	return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;
  string event;
  getline(cin,event,'\n');
  int i=0,out,b,score;
  while(n>0){
    out = 0;
    b = 0;
    score=0;
    while(out<3){
      getline(cin,event,'\n');
      if(event=="HIT"){
	b*=2;
	b+=1;
	if(b>8){
	  b-=8;
	  score++;
	}
      }
      if(event=="HOMERUN"){
	while(b>0){
	  score+=b%2;
	  b/=2;
	}
	score++;
      }
      if(event=="OUT"){
	out++;
      }
    }
    cout<<score<<endl;
    n--;
  }
  return 0;
}


#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;

int main(){
	int n;
	string line;
	scanf("%d ",&n);

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

#include <iostream>
#include <algorithm>
#include <stdio.h>
static const int MAX = 200000;

using namespace std;

int bubbleSort(int a[], int n){
  int sw = 0;
  bool flag = 1;
  for(int i = 0; flag; i++){
    flag = 0;
    for(int j = n -1; j >= i + 1; j--){
      if(a[j] < a[j-1]){
        swap(a[j], a[j-1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main(int argc, const char * argv[]) {
  int n, a[MAX], sw;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];

  sw = bubbleSort(a, n);

  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}


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

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

#define PI 3.14159265358979323846264338327950L

int main() {
	int R;
	double ans;
	cin >> R;
	ans = R * PI * 2;
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <functional>

template<typename T> struct segment_tree {
private :
	int N;
	std::vector<T> value;
public :
	const std::function<T(T, T)> op;
	const T id;

	segment_tree(const std::vector<T>& a, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int n = a.size(), m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
		for (int i = 0; i < n; i++) value[N + i] = a[i];
		for (int i = N - 1; i > 0; i--) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	segment_tree(const int& n, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
	}

	inline const int& size()const{return N;}

	void point_update(int i, const std::function<T(T, T)>& f, const T& t) {
		i += N;
		value[i] = f(value[i], t);
		while (i /= 2) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	T range_fold(const int& L, const int& R, const int& i = 1, const int& l = 0, int r = -1) {
		if (r == -1) r = N;
		if (L <= l && r <= R) return value[i];
		if (r <= L || R <= l) return id;
		return op(
			range_fold(L, R, i * 2, l, (l + r) / 2),
			range_fold(L, R, i * 2 + 1, (l + r) / 2, r)
		);
	}

	inline const T& operator[](const int& i)const{return value[N + i];}
};

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<long long> a(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];

	segment_tree<long long> sg(a, [](long long a, long long b){return a + b;}, 0);
	while (q--) {
		int op;
		std::cin >> op;
		if (op == 0) {
			int p; long long x;
			std::cin >> p >> x;
			sg.point_update(p, [](long long a, long long b){return a + b;}, x);
		} else {
			int l, r;
			std::cin >> l >> r;
			std::cout << sg.range_fold(l, r) << '\n';
		}
	}

	return 0;
}

#include <bits/stdc++.h>
#include <atcoder/all>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;
using namespace atcoder;

using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;

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

int main() {
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep (i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    rep (i, q) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 0) fw.add(a, b);
        else cout << fw.sum(a, b) << endl;
    }

    return 0;
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    if (N==1){
        cout << M << "\n";
        return 0;
    }
    vector<int> div;
    for (int i=1;i*i<=M;i++){
        if (M%i == 0){
            div.push_back(i);
            if (i*i!=M){
                div.push_back(M/i);
            }
        }
    }
    sort(div.begin(),div.end());
    int p = 0;
    for (int i=0;i<div.size();i++){
        if ((ll)div[i]*(ll)N>(ll)M) {
            p = i;
            break;
        }
    }
    int ans;
    ans = div[p-1];
    cout << ans << "\n";
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n,m;
ll num[10]={2,5,5,4,5,6,3,7,6};
string dp[11000];
void chmax2(string &a,string b){
    if(a=="-") a=b;
    if(a.size()<b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    cin>>n>>m;
    vl a(m);rep(i,m)cin>>a[i];
    rep(i,11000)dp[i]="-";
    dp[0]="";
    for(int i=0;i<=n;i++){
        if(dp[i]=="-") continue;
        for(auto aa:a){
            string b=dp[i]+(char)('0'+aa);
            chmax2(dp[i+num[aa-1]],b);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


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

int main(){
    long long n, l;
    cin >> n >> l;

    long long n_sum = n*l + n*(n-1)/2;

    long long min_delta = 1e12;
    long long minv;

    for(long long i = 0; i < n; i++){
        long long sum = n_sum - (l+i);
        if(min_delta > abs(n_sum - sum)){
            min_delta = abs(n_sum - sum);
            minv = sum;
        }
    }
    cout << minv << endl;
    return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    int min = INT32_MAX;
    int flavor = 0;
    for (int i = 1; i <= n; ++i) {
        if (abs(i + l - 1) < abs(min)) {
            min = i + l - 1;
        }
        flavor += i + l - 1;
    }
    flavor -= min;
    cout << flavor << '\n';
}


#include <iostream>
using namespace std;
int main(){
  int n; cin >>n;
  for(int i = n; i < 1000; i++){
    if(i % 111 == 0){
		cout << i << endl;
      	return 0;
    }
  }
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s, t;
ll prime[2000000];

// < ----------- func eh ---------------- ? //

// <------------- Start of main() -------------------> //

void MAIN() {
	ll h, m1, m2;
	cin >> h >> m1; m1 += 60 * h;
	cin >> h >> m2; m2 += 60 * h;

	cin>>k;
	m2-=k;

	cout<<max(0ll,m2-m1);newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int par[10010];

void init(int n){
	REP(i,n){
		par[i]=i;
	}
}

int find(int x){
	if(par[x]==x){
	   return x;
	}else{
	  return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return;

	par[x]=y;
}

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

struct edge { int from,to,cost; };

bool comp(const edge& e1,const edge& e2){
	return e1.cost<e2.cost;
}

edge es[100010];

int V,E;

int kruskal(){
	sort(es,es+E,comp);
	init(V);
	int res=0;
	REP(i,E){
		edge e=es[i];
		if(!same(e.from,e.to)){
			unite(e.from,e.to);
			res+=e.cost;
		}
	}
	return res;
}

int main(void){

	          cin >> V >> E;
	          REP(i,E){
	        	  cin >> es[i].from >> es[i].to >> es[i].cost;
	          }

	          cout << kruskal() << endl;

	          return 0;
}


//g++ -std=c++14 test.cpp -o test.out
//問題URL:
//https://atcoder.jp/contests/arc100/tasks/arc100_b

//参考：
// https://drken1215.hatenablog.com/entry/2018/08/28/193000

// ポイント：理想の状況がどういう時かを考える
// Max-minが最小になるのはどういう時？
// →PQSTどれ2つをとっても、差ができるだけ小さくなっているはず
// （あえて大きくしてもいいが、それだとMax-minが大きくなってしまう危険をはらんでいる上に、
// Max-minをもっと小さくする、といったことができない）

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;

#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = INF;

void solve(){
	vector<LL> accum(N,A[0]);
	for(int i=1;i<N;i++) accum[i] = accum[i-1] + A[i];

	//切れ込み3箇所のうち、真ん中を決めうち
	//インデックスi番目の直後に入れることを想定
	for(int middle=1;middle<=N-3;middle++){
		auto search = [&](int left_index,int right_index){
			LL left = left_index;
			LL right = right_index-1;
			while(left+1<right){
				LL center = (left+right)/2LL;
				LL leftside = accum[center] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[center];
				if(leftside==rightside) return center;
				if(leftside>rightside) right = center;
				if(leftside<rightside) left = center;
			}
			LL left_diff,right_diff;
			{
				LL leftside = accum[left] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[left];
				left_diff = abs(rightside-leftside);
			}
			{
				LL leftside = accum[right] - ((left_index==0)?0:accum[left_index-1]);
				LL rightside = accum[right_index] - accum[right];
				right_diff = abs(rightside-leftside);
			}
			return (left_diff<right_diff)?left:right;
		};
		LL left = search(0,middle);
		LL right = search(middle+1,N-1);

		LL P = accum[left];
		LL Q = accum[middle] - accum[left];
		LL R = accum[right] - accum[middle];
		LL S = accum[N-1] - accum[right];
		LL cand = max(max(P,Q),max(R,S)) - min(min(P,Q),min(R,S));
		ans = min(ans,cand);
	}
}

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

    solve();

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

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <limits>
#include <set>
#include <map>
#include <functional>

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

using namespace std;
typedef long long ll;

#ifndef PRId64
#define PRId64 "lld"
#endif
#ifndef SCNd64
#define SCNd64 "lld"
#endif
#define SC sc()
#define PT pr()
#define FORi(i,b,e) for (int i = (b), _ = (e); i < _; ++i)
#define FORe(i,b,e) for (int i = (b), _ = (e); i <= _; ++i)
#define FORre(i,b,e) for (int i = (b), _ = (e); i >= _; --i)

static int sc_ret = 0;
struct sc
{
    sc& operator()(char& v) { v = sc_ret = getchar(); return *this; }
    sc& operator()(int& v) { sc_ret = scanf("%d", &v); return *this; }
    sc& operator()(unsigned& v) { sc_ret = scanf("%u", &v); return *this; }
    sc& operator()(double& v) { sc_ret = scanf("%lf", &v); return *this; }
    sc& operator()(char* v) { sc_ret = scanf("%s", v); return *this; }
    sc& operator()(string& v) { sc_ret = (bool)(cin >> v); return *this; }
    sc& operator()(ll& v) { sc_ret = scanf("%" SCNd64, &v); return *this; }
    sc& ch(char& v) { sc_ret = scanf(" %c", &v); return *this; }
    sc& gets(char* v) { sc_ret = fgets(v, INT_MAX, stdin) != 0; v[strlen(v) - 1] = 0; return *this; }
    operator bool() const { return sc_ret > 0; }
    void read(int& v)
    {
        int x = 0, k = 1;
        char c = getchar();
        while (c < '0' || c > '9')
        {
            if (c == '-') k = -1;
            c = getchar();
        }
        while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c - 48), c = getchar();
        v = x * k;
    }
};
struct pr
{
    pr& ln() { putchar('\n'); return *this; }
    pr& operator()(char v) { putchar(v); return *this; }
    pr& operator()(int v) { printf("%d", v); return *this; }
    pr& operator()(double v) { printf("%.2f", v); return *this; }
    pr& operator()(const char* fmt, double v) { printf(fmt, v); return *this; }
    pr& operator()(const char* v) { printf("%s", v);return *this; }
    pr& operator()(string v) { printf("%s", v.c_str());return *this; }
    pr& operator()(ll v) { printf("%" PRId64, v);return *this; }

    void write(int v)
    {
        int cnt = 0; char c[15];
        if (v == 0)
        {
            putchar('0');
            return;
        }
        if (v < 0) putchar('-'), v = -v;
        while (v) c[++cnt] = (v % 10) + 48, v /= 10;
        while (cnt > 0) putchar(c[cnt--]);
    }
    template <typename T>
    void ln(T* arr, int size)
    {
        if (size > 0)
        {
            (*this)(arr[0]);
            for (int i = 1; i < size; ++i)
            {
                putchar(' ');
                (*this)(arr[i]);
            }
            putchar('\n');
        }
    }

    template <typename T>
    void muln(T* arr, int size)
    {
        for (int i = 0; i < size; ++i)
        {
            (*this)(arr[i]);
            putchar('\n');
        }
    }
};

const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 200000 + 10;
const int maxm = 100000 + 10;

ll a[maxn];

int main()
{
    int n, t, k;
    SC(n);
    FORe(i, 1, n)
    {
        int v;
        SC.read(v);
        a[i] = v + a[i - 1];
    }
    int l = 1, r = 3; ll ret = a[n];
    FORi(i, 2, n - 1)
    {
        for (; l < i - 1; ++l)
        {
            if (min(a[l], a[i] - a[l]) >= min(a[l + 1], a[i] - a[l + 1]))
                break;
        }
        for (; r < n - 1; ++r)
        {
            if (min(a[r] - a[i], a[n] - a[r]) >= min(a[r + 1] - a[i], a[n] - a[r + 1]))
                break;
        }
        ret = min(ret, max(max(a[r] - a[i], a[n] - a[r]), max(a[l], a[i] - a[l]))
            - min(min(a[l], a[i] - a[l]), min(a[r] - a[i], a[n] - a[r])));
    }
    PT(ret);
    return 0;
}


#include<bits/stdc++.h>

#define Bye return 0
#define ll long long

using namespace std;

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

    int next = a[0];
    int cont = 1;
    for (int i=1; i<n; i++){
        if(a[i]<=next){
            next = a[i];
            cont++;
        }
    }
    cout<<cont<<endl;
}

int main(){
    solve();
    Bye;
}

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] *= -1;
	}
	vector<int> seq(N, 1 << 30);
	for (int i = 0; i < N; ++i) {
		*lower_bound(seq.begin(), seq.end(), A[i] + 1) = A[i];
	}
	cout << lower_bound(seq.begin(), seq.end(), 1 << 30) - seq.begin() << endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main(){
  int A[100],N;

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

  int count = 0;
  int flag = 1;
  while(flag) {
    flag = 0;
    for (int i=N-1;i>0;i--) {
      if (A[i] < A[i-1]) {
        count++;
        int tmp = A[i];
        A[i] = A[i-1];
        A[i-1] = tmp;
        flag = 1;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, a[5];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, 5) cin >> a[i];
	ll res = 0;
	REP(i, 5) res = max(res + 1, i + (n+a[i]-1)/a[i]);
	cout << res << endl;
	return 0;
}


#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
#define INF 200000000000
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(pair<int, int> a, pair<int, int> 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};
int main() {
    ll H,W;
    cin>>H>>W;
    vector<vector<char>> G(H,vector<char>(W));
    ll cnt = 0;

    vector<vector<ll>> dist(H,vector<ll>(W,-1));
    queue<Pi> que;
    rep(i,H){
        rep(j,W){
            cin>>G[i][j];
            if(G[i][j] == '#'){
                dist[i][j] = 0;
                que.push(mp(i,j));
            }
        }
    }

    ll ans = 0;

    while(!que.empty()){
        Pi v =que.front();
        que.pop();

        rep(dir,4){
            ll ny = v.first + dy[dir];
            ll nx = v.second + dx[dir];

            if(!In_map(ny,nx,H,W)) continue;
            if(dist[ny][nx] != -1) continue;
            if(G[ny][nx] == '#') continue;
            dist[ny][nx] = dist[v.first][v.second]+1;
            que.push(mp(ny,nx));
            chmax(ans,dist[ny][nx]);
        }

    }

    cout<<ans<<endl;

    return 0;

}

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

int main() {
  int N, T;
  cin >> N >> T;
  int t[N];
  for (int i=0; i<N; i++)
    cin >> t[i];
  long ans = 0, start = t[0], prev = t[0];
  for (int i=1; i<N; i++) {
    if (t[i]>prev+T) {
      ans += prev+T-start;
      start = t[i];
    }
    prev = t[i];
  }
  ans += prev+T-start;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define ld long double
#define inf 1000000000
#define N 100005
int n,s; ll a[N],b[N],ans;
int main(){
	scanf("%d%d",&n,&s);
	rep (i,1,n) scanf("%d%d",&a[i],&b[i]);
	int l=1,r=n; ans=0;
	while (l<=r){
		if (s<=a[l]){ ans+=a[r]-s; break; }
		if (s>=a[r]){ ans+=s-a[l]; break; }
		if (b[l]>=b[r]){
			ans+=a[r]-a[l];
			while (l<r && b[l]>=b[r]) b[l]+=b[r--];
		} else{
			ans+=a[r]-a[l];
			while (l<r && b[l]<b[r]) b[r]+=b[l++];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

	int ans = 0;
	for (int i = a; i <= b; i++) {
		string a_tmp, b_tmp;
		string ch = to_string(i);
		for (int j = 0; j < ch.size(); j++) {
			a_tmp.push_back(char(ch[j]));
			b_tmp.push_back(char(ch[ch.size() - j-1]));
		}
		if (a_tmp == b_tmp)ans++;
	}
	cout << ans << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

deque<int> col;

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    col.push_front(a[0]);
    for (int i = 1; i < n; i++){
        int idx = lower_bound(col.begin(), col.end(), a[i]) - col.begin();
        if(idx == 0){
            col.push_front(a[i]);
        }else{
            col[idx-1] = a[i];
        }
    }
    int ans = col.size();
    cout << ans << endl;
}

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

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

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 ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vi A(N);
    for(auto &x : A)cin >> x;

    vector<vector<ll>> dp(N+1, vector<ll>(2, 0));
    dp[0][1]=-INF;
    for(int i=0; i<N; i++){
        dp[i+1][0]=max(dp[i][0]+A[i], dp[i][1]-A[i]);
        dp[i+1][1]=max(dp[i][0]-A[i], dp[i][1]+A[i]);
    }
    cout << dp[N][0] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    int left = l;
    int right = l + n - 1;
    int eat = 0;
    if (left >= 0) {
        eat = left;
    } else if (right <= 0) {
        eat = right;
    } else {
        eat = 0;
    }
    int ans = ((left + right) * n / 2) - eat;
    cout << ans << endl;
    return 0;
}

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

string s1, s2;

void solve() {
  int dp[s1.size() + 1][s2.size() + 1];
  for (int i = 0; i <= s1.size(); i++) {
    dp[i][0] = i;
  }
  for (int i = 0; i <= s2.size(); i++) {
    dp[0][i] = i;
  }

  for (int i = 1; i <= s1.size(); i++) {
    for (int j = 1; j <= s2.size(); j++) {
      int flag;
      if (s1[i - 1] == s2[j - 1]) flag = 0;
      else flag = 1;
      dp[i][j] =
	min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + flag));
    }
  }
  cout << dp[s1.size()][s2.size()] << endl;
}

int main() {
  cin >> s1 >> s2;
  solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,p[200005],r[200005];
ll d,a[200005],f[200005],g[200005],ans;

vector <pair<ll,pi>> s;

int Par(int nod){
	if(p[p[nod]]==p[nod]) return p[nod];
	else return p[nod]=Par(p[nod]);
}

void Unite(int x, int y){
	x=Par(x); y=Par(y);
	if(x==y) return;
	if(r[x]>r[y]) swap(x,y);
	if(r[x]==r[y]) r[y]++;
	p[x]=y;
}

void DC(int l, int r){
	if(l==r) return;
	int mid=(l+r)/2;
	DC(l,mid);
	DC(mid+1,r);
	int x=0,y=0;
	for(int i=l;i<=mid;i++){
		if(f[i]<f[x]) x=i;
	}
	for(int i=mid+1;i<=r;i++){
		if(g[i]<g[y]) y=i;
	}
	for(int i=l;i<=mid;i++){
		s.pb({f[i]+g[y],{i,y}});
	}
	for(int i=mid+1;i<=r;i++){
		s.pb({f[x]+g[i],{x,i}});
	}
}

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
#ifdef LOCAL_DEFINE
	ifstream cin("input.in");
#endif

	cin >> n >> d;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		p[i]=i;
		f[i]=-d*i+a[i];
		g[i]=d*i+a[i];
	}
	f[0]=g[0]=LINF;
	DC(1,n);
	sort(s.begin(),s.end());
	for(pair<ll,pi> i : s){
		if(Par(i.y.x)==Par(i.y.y)) continue;
		Unite(i.y.x,i.y.y);
		ans+=i.x;
	}
	cout << ans;

#ifdef LOCAL_DEFINE
	cerr << "\nTime elapsed: " << 1.0*clock()/CLOCKS_PER_SEC << " \n";
#endif
}

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

typedef long long ll;
const int maxn = 1000005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n;
char s[maxn], t[maxn];
int ans, l, r, q[maxn];

int main()
{
	scanf("%d\n%s%s", &n, s + 1, t + 1);

	int i;
	for (i = 1; i <= n; ++i)
		if (s[i] != t[i]) break;
	if (i > n) return puts("0"), 0;

	int up = n, down = n;
	l = 1; r = 0;
	while (down) {
		while (down && t[down - 1] == t[down]) --down;
		while (up && (up > down || s[up] != t[down])) --up;
		if (!up) return puts("-1"), 0;
		while (l < r && q[l] - (r - l + 1) >= down) ++l;
		if (up != down) q[++r] = up;
		ans = max(ans, r - l + 2);
		--down;
	}

	printf("%d\n", ans);

	return 0;
}


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

int main() {
	int a,b,c,d,e,k;
  	cin>>a>>b>>c>>d>>e>>k;

  	bool dis=true;

  if(e-a>k){

  	dis=false;
  }

  if(dis){
  	cout<<"Yay!"<<endl;
  }

  else{
  	cout<<":("<<endl;
  }

}

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

int main(){
  int n=5;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	int d; cin>>d;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(v[j]-v[i]>d){cout << ":(" << endl; return 0;}
		}
	}
	cout << "Yay!" << endl;
}


//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const usize n = scan<usize>();
  const u64 m = scan<u64>();
  const auto add = [&](u64 &l, const u64 r) { l = (l + r) % m; };
  auto dp = md_vec(3 * n + 1 + 3, n + 1 + 1, u64(0));
  dp[0][0] = 1;
  for (const usize i : rep(0, 3 * n + 1)) {
    for (const usize j : rep(0, n + 1)) {
      add(dp[i + 1][j], dp[i][j]);
      add(dp[i + 2][j + 1], dp[i][j] * (i + 1) % m);
      add(dp[i + 3][j + 1], dp[i][j] * (i + 1) % m * (i + 2) % m);
    }
  }
  u64 ans = 0;
  for (const usize i : rep(0, n + 1)) {
    add(ans, dp[3 * n][i]);
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}

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

int main () {
  string S;
  cin >> S;
  const int num = S.size();

  string T;

  for (int64_t tmp = 0; tmp < (1 << 3); tmp++) {

    bitset<3> b(tmp);

    int sum = S.at(0)-'0';
    T = "";
    for (int i = 0; i < 3; i++) {

      if(b.test(0)){
        sum += S.at(i+1)-'0';
		T += "+";
      }else{
        sum -= S.at(i+1)-'0';
      	T += "-";
      }
      b = b >> 1;

    }

    if(sum == 7)
      break;
  }

  for (int i = 0; i < 3; i++) {
   cout << S.at(i) << T.at(i);
  }
  cout << S.at(3) << "=7" << endl;

}


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll n, a, b, res;
int main() {
	cin >> n;
	vector<ll> s(n);
	REP(i, n) {
		cin >> a >> b;
		s[i] = a + b;
		res -= b;
	}
	sort(s.rbegin(), s.rend());
	REP(i, n) res += s[i++];
	cout << res << '\n';
	return 0;
}

//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;

#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
vector<tuple<LL,LL,LL>> dish;

LL ans = 0;

void solve(){
	sort(dish.begin(),dish.end());
	for(int i=0;i<N;i++){
		int j = N-1-i;
		//cout << get<1>(dish[j]) << " " << get<2>(dish[j])<< endl;
		if(i%2==0){
			ans += get<1>(dish[j]);
		}
		if(i%2==1){
			ans -= get<2>(dish[j]);
		}
	}
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
    	LL a,b;cin >> a >> b;
    	dish.push_back(tuple<LL,LL,LL>(a+b,a,b));
    }

    solve();

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


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

int main(){
  int n, m;
  while(1){
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0)return 0;
    int res = 0, tmp;
    vector<int> points, points2;
    for(int i = 0;i < n;i++){
      scanf("%d", &tmp);
      if(tmp < m)points.push_back(tmp);
    }
    vector<int>::iterator it1,it2;
    for(it1 = points.begin();it1 != points.end();it1++){
      points2.push_back(*it1);
      for(it2 = points.begin();it2 != points.end();it2++){
	if(*it1 + *it2 <= m)points2.push_back(*it1 + *it2);
      }
    }
    sort(points2.begin(),points2.end());
    for(it1 = points2.begin();it1 != points2.end();it1++){
      it2 = upper_bound(points2.begin(), points2.end(), m - *it1);
      res = max(res, *it1);
      if(it2 == points2.begin())continue;
      it2--;
      res = max(res, *it1 + *it2);
    }
    printf("%d\n",res);
  }
}

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

int main(){
  vector<int> outp;
  int icn;
  int icd;
  int g;
  vector<int> ice;
  for(g = 0;;g++){
    vector<int> ice(10,0);
    cin >> icn;
    if(icn == 0){
      break;
    }else{
    for(int a = 0;a< icn;a++){
      cin >> icd;
      ice[icd] += 1;
    }
    outp.insert(outp.end(),ice.begin(),ice.end());
  }
  }
  for(int n = 0;n<g * 10;n++){
    if(outp[n] == 0){
      cout << "-";
    }else{
      for(int c = 0;c<outp[n];c++){
        cout << "*" ;
      }
    }
    cout << endl;
  }
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;

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

struct Edge {
  int to;
  ll weight;
  Edge(int t, ll w) : to(t), weight(w) { }
};

int N, M;
bool seen[110000];
using Graph = vector<vector<int>>;

void dfs(int v, const Graph& G, vector<int>& order) {
  seen[v] = true;

  for (auto nv : G[v]) {
    if (seen[nv]) continue;
    dfs(nv, G, order);
  }

  order.push_back(v);
}

int main () {
  cin >> N >> M;
  Graph G(N+1);
  Graph Gyaku(N+1);

  Rep(i, N-1+M) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    Gyaku[b].push_back(a);
  }

  vector<int> order;
  rep(i, N) {
    if (seen[i]) continue;
    dfs(i, G, order);
  }

  reverse(All(order));

  map<int, int> mp;

  rep(i, N) {
    mp[order[i-1]] = i;
    //cout << order[i-1] << "\n";
  }

  rep(i, N) {
    if (mp[i] == 1) {
      cout << 0 << "\n";
    } else {
      int tmp = 0;
      int tmp_p = 0;
      for (auto nv: Gyaku[i]) {
        //cout << " " << nv << " " << mp[nv] << "\n";

        if (mp[nv] > tmp) {
          tmp = mp[nv];
          tmp_p = nv;
        }
      }

      cout << tmp_p << "\n";
    }
  }

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 110;

int a[MAXN];
int js[MAXN];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int cnt = 0;
	int n = ri;
	int m = ri;
	if(m == 1) {
		if(n == 1) {
			cout << 1 << endl;
			cout << 1 << endl;
			cout << 1 << endl;
		} else {
			cout << n << endl;
			cout << 2 << endl;
			cout << 1 << ' ' << n - 1 << endl;
		}
	}
	else {
		for(int i = 1; i <= m; i++) {
			a[i] = ri;
			if(a[i] & 1)
				js[cnt++] = i;
		}
		if(cnt > 2) puts("Impossible");
		else {
			if(js[0] && js[0] != 1) swap(a[1], a[js[0]]);
			if(js[1] && js[1] != m) swap(a[m], a[js[1]]);
			for(int i = 1; i <= m; i++) printf("%d ", a[i]); puts("");
			a[1]++, a[m]--;
			if(!a[m]) --m;
			printf("%d\n", m);
			for(int i = 1; i <= m; i++) printf("%d ", a[i]); puts("");
		}
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int in()
{
	int x;cin>>x;
	return x;
}
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

int main ()
{
	int n,m;
	while(cin>>n>>m&&n&&m)
	{
		vector<long long > a,b;
		b.push_back(0);
		rep(i,n)
		{
			b.push_back(in());
		}
		rep(i,n+1)
		{
			rep(l,n+1)
			{
				a.push_back(b[i]+b[l]);
			}
		}
		long long ans = 0;
		sort(a.begin(),a.end());
		rep(i,a.size())
		{
			vector<long long>::iterator t=upper_bound(a.begin(),a.end(),m-a[i]);
			if(t==a.begin())continue;
			t--;
			ans=max(ans,*t+a[i]);
		}
		cout<<ans<<endl;

	}

}

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

const int INF = 1<<30;

int N,M;

int main(){
  while(scanf("%d%d", &N,&M) && N||M){
    vector<int>a,v;
    a.push_back(0);
    for(int i=0;i<N;i++){
      int x;scanf("%d", &x);
      a.push_back(x);
    }
    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++){
	if(a[i]+a[j] <= M) v.push_back(a[i]+a[j]);
    }
    v.push_back(INF);

    sort(v.begin(), v.end());
    int res = 0;
    for(int i=0;i<v.size()-1;i++){
      int x = M-v[i];
      vector<int>::iterator it = upper_bound(v.begin(), v.end(), x); if(it != v.begin()) it--;
      res = max(res, v[i] + *it);
    }
    printf("%d\n", res);
  }
  return 0;
}


#include <assert.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1000000007;

// UnionFind
template<class T>
struct UnionFind {
  std::vector<T> uni;
  T num;
  UnionFind(T s) : uni(s, -1), num(s) {}

  //頂点aが所属するグループ
  T root(T a) {
    if (uni[a] < 0) {
      return a;
    }
    return uni[a] = root(uni[a]);
  }

  // a,bをつなげる
  bool connect(T a, T b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      return false;
    }

    if (uni[a] > uni[b]) {
      std::swap(a, b);
    }

    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  // a,bが同グループか確認
  bool isConnect(T a, T b) { return root(a) == root(b); }

  // aが属するグループの要素数
  T size(T a) { return -uni[root(a)]; }

  //グループ数を返す
  T groups() {
    std::set<T> b;
    for (T i = 0; i < num; i++) {
      b.insert(root(i));
    }
    return b.size();
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,k,l;
  std::cin>>n>>k>>l;
  UnionFind<int> load(n),rail(n);
  rep(i,0,k){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    load.connect(a,b);
  }
  rep(i,0,l){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    rail.connect(a,b);
  }
  std::vector<P> temp1(n),temp2(n);
  rep(i,0,n){
    temp1[i]=P(load.root(i),rail.root(i));
    temp2[i]=P(load.root(i),rail.root(i));
  }
  sort(all(temp1));
  rep(i,0,n){
    auto low=std::lower_bound(all(temp1),temp2[i]);
    auto up=std::upper_bound(all(temp1),temp2[i]);
    std::cout<<up-low<<" ";
  }
  return 0;
}

#define NguyenDangQuan the_author

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define ull unsigned long long
#define task "codejam"
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}

const int N = 2e5 + 2;
int m, n, k;
vector<int> ker[N], kel[N];
int ltr[N], ltl[N];

void Enter(){
	read(n); read(m); read(k);
	while(m--){
		int a, b;
		read(a); read(b);
		ker[a].pb(b);
		ker[b].pb(a);
	}
	while(k--){
		int a, b;
		read(a); read(b);
		kel[a].pb(b);
		kel[b].pb(a);
	}
}

void BFS(int i, int lt[], vector<int> ke[]){
	++m;
	lt[i] = m;
	queue<int> open;
	open.push(i);
	while(open.size()){
		int c = open.front();
		open.pop();
		for(auto i : ke[c]){
			if((!lt[i]))
				open.push(i), lt[i] = m;
		}
	}
}

void solve(){
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltr[i] == 0)
			BFS(i, ltr, ker);
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltl[i] == 0)
			BFS(i, ltl, kel);
	map<int, map<int, int> > s;
	for(int i = 1; i <= n; ++i){
		++s[ltr[i]][ltl[i]];
//		cerr << ltr[i] << " " << ltl[i] << "\n";
	}
	for(int i = 1; i <= n; ++i){
		int& v = s[ltr[i]][ltl[i]];
		cout << v << " ";
	}
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		int v = t;
		while(t--){
			Enter();
			cout << "Case #" << v - t << ": ";
			solve();
		}
	}
	else{
		Enter();
		solve();
	}
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){

	int a,b;
	cin>>a>>b;
	cout<<max(a+(a-1),max(b+(b-1),a+b))<<endl;

	return 0;
}

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
char ans[N][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n = 100;
	int a, b;
	cin >> a >> b;
	MEM(ans, '#');
	for (int i = 1; i <= n / 2; i++)
	{
		for (int j = 1; j <= 100; j++) ans[i][j] = '.';
	}
	a--, b--;
	for (int i = 1; i <= n / 2; i += 2)
	{
		for (int j = 1; j <= 100 && b > 0; j += 2, b--)
		{
			ans[i][j] = '#';
		}
	}
	for (int i = n; i >= n / 2; i -= 2)
	{
		for (int j = 1; j <= 100 && a > 0; j += 2, a--)
		{
			ans[i][j] = '.';
		}
	}
	puts("100 100");
	for (int i = 1; i <= n; i++)
	{
		ans[i][n + 1] = 0;
		puts(ans[i] + 1);
	}
	return 0;
}


#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, K;

ll solve(ll N);

int main()
{
    cin >> N >> K;
    cout << solve(N) << endl;
}

ll solve(ll N)
{
    if (N == 1)
    {
        return 2;
    }
    return min(solve(N - 1) * 2, solve(N - 1) + K);
}

#include <iostream>
using namespace std;

int main(void){
  int n,x,t;
  int ans;

  cin >> n >> x >> t;
  ans = t * ((n+x-1)/x);
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, k);
	int n = 50, p = k / n, q = k % n;
	vector< int > a(n, n + p - q - 1);
	REP(i, q) {
		a[i] += 51;
	}

	OUT(n)BR;
	REP(i, n) {
		OUT(a[i]);
		if (i < n - 1) SP;
	}
	BR;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
 int K;
 string S;
 cin>>K>>S;
 int a=S.size();
 if(a<=K){
   cout<<S<<endl;
 }
 else{
   for(int i=0;i<K;i++){
     cout<<S.at(i);
   }
    cout<<"..."<<endl;
 }
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    vector<int> key(n);
    rep(i,n) cin >> key[i];
    int x = 0;
    string str;
    cin >> str;
    while(key.size() < str.size()){
      if(x==key.size()) x = 0;
      key.push_back(key[x]);
      x++;
    }
    rep(i,str.size()){
      rep(j,key[i]){
        if(str[i]=='a') str[i] = 'Z';
        else if(str[i]=='A') str[i] = 'z';
        else str[i]--;
      }
    }
    rep(i,str.size()) cout << str[i];
    cout << endl;
  }
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int main(){
    cin.sync_with_stdio(false);
    int n;
    while(cin >> n, n) {
        int key[n];
        rep(i, n) cin >> key[i];
        string s;
        cin >> s;
        int i = 0;
        rep(j, s.size()) {
            if ('a' <= s[j] && s[j] <= 'z') {
                if (key[i] <= 26) {
                    if (s[j] - 'a' >= key[i]) s[j] = (char)(s[j] - key[i]);
                    else s[j] = (char)('Z' - (key[i] - (s[j] - 'a') - 1));
                } else {
                    s[j] = (char)(s[j] + ('A' - 'a'));
                    if (s[j] - 'A' >= key[i] - 26) s[j] = (char)(s[j] - key[i] + 26);
                    else s[j] = (char)('z' - (key[i] - (s[j] - 'A') - 27));
                }
                i = (i + 1) % n;
            } else {
                if (key[i] <= 26) {
                    if (s[j] - 'A' >= key[i]) s[j] = (char)(s[j] - key[i]);
                    else s[j] = (char)('z' - (key[i] - (s[j] - 'A') - 1));
                } else {
                    s[j] = (char)(s[j] - ('A' - 'a'));
                    if (s[j] - 'a' >= key[i] - 26) s[j] = (char)(s[j] - key[i] + 26);
                    else s[j] = (char)('Z' - (key[i] - (s[j] - 'a') - 27));
                }
                i = (i + 1) % n;
            }
        }
        cout << s << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define endl "\n"
#define v vector
#define b begin()
#define e end()
using namespace std;
typedef long long ll;
typedef long l;
typedef long long unsigned ull;

int main(){

    /*int t;
    while(t--){

    }*/
    ll n;
    cin>>n;
    ll m = n/500;
    ll q = m*1000;
    n -= (m*500);
    ll p = (n/5)*5;
    cout<<q+p;

    return 0;

}

#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define isz(c) (int)c.size();

using namespace std;
using ll = long long;
using vi = vector<int>;

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

    b--;
    a--;

    cout << (a + b - 1) / a << endl;

    return 0;
}


#include <iostream>
#include <string>

int main()
{
  int K;
  std::string S;
  std::cin >> K;
  std::cin >> S;
  if (S.length() <= K) std::cout << S << std::endl;
  else std::cout << S.substr(0, K) << "..." << std::endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n)

    {
        i=m+n;
        j=m-n;
        k=m*n;
        cout<<max(i,max(j,k))<<endl;

    }
    return 0;
}


    /**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(rall(v));
    int ans=1,cnt=0;
    for(int i=0;i<n-1;){
        if(v[i]==v[i+1]&&cnt<2){
            ans*=v[i];
            i+=2;
            cnt++;
        }
        else i++;
    }
    if(cnt==2)cout<<ans;
    else cout<<0;
    return 0;
}

#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    map<ll,int> mli;
    rep(i,n){
        ll x;
        cin >> x;
        mli[x]++;
    }
    vector<pair<ll,int>> v;
    for(auto u : mli){
        v.push_back({u.first,u.second});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    ll ans = 1;
    bool one = 0;
    for(auto u : v){
        if(u.second>=2){
            if(u.second>=4){
                if(one) cout << ans*u.first << endl;
                else cout << u.first*u.first << endl;
                return 0;
            }
            else{
                if(one) {
                    cout << ans*u.first << endl;
                    return 0;
                }
                else ans *= u.first;
            }
            one = 1;
        }
    }
    cout << 0 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
bool flg;
vector<ll> adj[N],col(N);
void dfs(ll node,ll clr){
    if(col[node]!=0){
        if(col[node]!=clr)flg=0;
        return;
    }
    col[node]=clr;
    for(auto &v:adj[node])dfs(v,-clr);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll u,v;cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll c1=0,c2=0,c3=0;
    for(ll i=1;i<=n;i++){
        if(col[i]!=0)continue;

        if(adj[i].size()==0)c1++;
        else{
            flg=1;
            dfs(i,1);
            if(flg)c2++;
            else c3++;
        }
    }
    ll ans = 2*n*c1 - c1*c1 + c3*c3 + 2*c3*c2 + 2*c2*c2;
    cout<<ans;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

//わけわかめ
int P[100001];
bool dame[100001];
int Find(int A) {
	if (P[A] < 0) return A << 1;
	return P[A] = Find(P[A] >> 1) ^ (P[A] & 1);
}

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

	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a = Find(getint());
		int b = Find(getint());

		//なんてセンスのない
		int a1 = a >> 1;
		int b1 = b >> 1;
		if (a1 == b1) {
			if (!((a ^ b) & 1)) dame[a1] = true;
			continue;
		}
		if (P[a1] > P[b1]) {
			P[b1] += P[a1];
			dame[b1] |= dame[a1];
			P[a1] = b ^ !(a & 1);
		}
		else {
			P[a1] += P[b1];
			dame[a1] |= dame[b1];
			P[b1] = a ^ !(b & 1);
		}
	}

	ll x = 0, y = 0, z = 0;
	rep1(i, N) {
		if (P[i] < 0) {
			if (P[i] == -1) z++;
			else if (dame[i]) y++;
			else x++;
		}
	}
	printf("%lld\n", x * x + (x + y) * (x + y) + 2 * N * z - z * z);

	Would you please return 0;
}


#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> east(N + 1);
    east[0] = 0;
    rep(i,N){
        if(S[i] == 'E')east[i + 1]++;
    }
    rep(i,N){
        east[i + 1] += east[i];
    }
    ll ans = INF;
    for(ll i = 1;i <= N;i++){
        ans = min(ans,i - 1 - east[i - 1] + east[N] - east[i]);
    }
    cout << ans << endl;
}

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

ll solve(int n, string s) {
  vector<int> w(n, 0), e(n, 0);
  if(s[0] == 'W') {
    w[0] = 1;
  } else {
    e[0] = 1;
  }
  for(int i=1;i<n;i++) {
    if(s[i] == 'W') {
      w[i] = w[i-1] + 1;
      e[i] = e[i-1];
    } else {
      e[i] = e[i-1] + 1;
      w[i] = w[i-1];
    }
  }
  int res = min(numeric_limits<int>::max(), e[n-1] - e[0]);
  for(int i=1;i<n-1;i++) {
    res = min(res, w[i-1] + e[n-1] - e[i]);
  }
  res = min(res, w[n-2]);
  return res;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s);
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n),b(n);
    //方針:自分が幸福度高い皿を取りたいし、相手の幸福度高い皿を先にとってしまいたい
    //->おのおのa[i]+b[i]が高い順に取っていけばいいのでは？
    priority_queue<pair<int64_t,int>> dish;
    rep(i,n){
        cin>>a[i]>>b[i];
        dish.push(mp(a[i]+b[i],i));
    }
    vector<bool> eaten(n,false);
    int64_t tp=0,ap=0;
    rep(turn,n){
           while(eaten[dish.top().second]){
               dish.pop();
           }
           eaten[dish.top().second]=true;
           if(turn%2==0)tp += a[dish.top().second];
           else ap += b[dish.top().second];
           dish.pop();
    }
    cout<<tp-ap<<endl;
}

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;
int sa[100010];
signed main(){
  int n;cin>>n;
  int ans=0;
  rep(i,n){
    int a,b;cin>>a>>b;
    sa[i]=a+b;
    ans-=b;
  }
  sort(sa,sa+n,greater<int>());
  for(int i=0;i<n;i+=2){
    ans+=sa[i];
  }
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e10
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef unsigned long long ll;

int main(){
    unordered_map<char, string>cards;
    cin >> cards['a']>> cards['b']>> cards['c'];

    unordered_map<char, int>ct;
    char curr = 'a';

    while (true){
        ct[curr]++;
        if(ct[curr] > cards[curr].size()){
            if(curr=='a') cout << 'A' << endl;
            else if (curr=='b') cout << 'B' << endl;
            else cout << 'C' << endl;
            return 0;
        }
        curr = cards[curr][ct[curr]-1];
    }

}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    S += "*";
    vec L(Q), R(Q);
    REP(i,0,Q) {
        cin >> L[i] >> R[i];
    }

    vec P(N+1, 0);
    ll c = 0, i = 0;
    while(i < N-1) {
        if(S[i] == 'A' && S[i+1] == 'C') {
            P[i+1] = c;
            P[i+2] = c+1;
            ++c;
            i += 2;
        }
        else {
            P[i+1] = c;
            ++i;
        }
    }
    P[N] = c;

    REP(i,0,Q) {
        PR(P[R[i]]-P[L[i]]);
    }

    return 0;
}

/*

*/


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
bool solve(int x,int y,int c);
int ux[2][8]={{0,1,2,3,0,1,2,3},
	      {0,1,0,1,0,1,0,1}};
int uy[2][8]={{0,0,0,0,1,1,1,1},
	      {0,0,1,1,2,2,3,3}};
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int w,h,n;
int b[105][105];
int xs,ys,xg,yg;
int main(void){
  while(1){
    scanf("%d %d",&w,&h);
    if(!w && !h) break;
    memset(b,0,sizeof(b));
    scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
    scanf("%d",&n);
    int c,d,tx,ty;
    for(int i=0;i<n;i++){
      scanf("%d %d %d %d",&c,&d,&tx,&ty);
      for(int j=0;j<8;j++){
	b[tx+ux[d][j]][ty+uy[d][j]]=c;
      }
    }
    if(b[xs][ys]!=0 && b[xg][yg]!=0 && b[xs][ys]==b[xg][yg] && solve(xs,ys,b[xs][ys])) puts("OK");
    else puts("NG");
  }
}

bool solve(int x,int y,int c){
  if(x==xg && y==yg) return true;
  b[x][y]=0;
  for(int i=0;i<4;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(0<nx && nx<=w && 0<ny && ny<=h){
      if(b[nx][ny]==c){
	if(solve(nx,ny,c)) return true;
      }
    }
  }
  return false;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
int dp[3010][3010];

int main(){
	int n, time; scanf("%d %d", &n, &time);
	vector<P> a(n);
	for(int i = 0; i < n; i++) scanf("%d %d", &a[i].first, &a[i].second);
	sort(a.begin(), a.end());

	for(int i = 0; i < n; i++){
		for(int j = 0; j <= time; j++){
			dp[i + 1][j] = dp[i][j];
			if(j - a[i].first >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - a[i].first] + a[i].second);
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, dp[i][time - 1] + a[i].second);
	printf("%d\n", ans);
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define lc now<<1
#define rc now<<1|1
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(LL x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(LL x){write(x);putchar('\n');}
const LL inf=1e18;
const int MAXN=200005;
int n,D,a[MAXN];
struct node
{
	int p;LL c;
	node(){}
	node(int _p,LL _c){p=_p;c=_c;}
};
node _min(node u1,node u2){return u1.c<u2.c?u1:u2;}
struct segtree1
{
	node mn[2][MAXN*4];
	void buildtree(int now,int l,int r)
	{
		if(l==r){mn[0][now]=mn[1][now]=node(l,inf);return ;}
		int mid=(l+r)/2;
		buildtree(lc,l,mid);buildtree(rc,mid+1,r);
		mn[0][now]=mn[1][now]=_min(mn[0][lc],mn[1][rc]);
	}
	void modify(int now,int l,int r,int p,node c,int opt)
	{
		if(l==r){mn[opt][now]=c;return ;}
		int mid=(l+r)/2;
		if(p<=mid)modify(lc,l,mid,p,c,opt);
		else modify(rc,mid+1,r,p,c,opt);
		mn[opt][now]=_min(mn[opt][lc],mn[opt][rc]);
	}
	node qry(int now,int l,int r,int ql,int qr,int opt)//0 左边   1 右边
	{
		if(l==ql&&r==qr)return mn[opt][now];
		int mid=(l+r)/2;
		if(qr<=mid)return qry(lc,l,mid,ql,qr,opt);
		else if(mid+1<=ql)return qry(rc,mid+1,r,ql,qr,opt);
		else return _min(qry(lc,l,mid,ql,mid,opt),qry(rc,mid+1,r,mid+1,qr,opt));
	}
}seg1,seg2;//1  未加入   2  加入
struct segtree2
{
	node mn[MAXN*4];
	void buildtree(int now,int l,int r)
	{
		if(l==r){mn[now]=node(l,inf);return ;}
		int mid=(l+r)/2;
		buildtree(lc,l,mid);buildtree(rc,mid+1,r);
		mn[now]=_min(mn[lc],mn[rc]);
	}
	void pushup(int now,int l,int r)
	{
		int mid=(l+r)/2;
		mn[now]=_min(mn[lc],mn[rc]);
		node u1=seg1.mn[0][lc],u2=seg2.mn[1][rc];
//		u1=seg1.qry(1,1,n,l,mid,0),u2=seg2.qry(1,1,n,mid+1,r,1);
		mn[now]=_min(mn[now],node(u1.p,u1.c+u2.c));
		u1=seg1.mn[1][rc],u2=seg2.mn[0][lc];
//		u1=seg1.qry(1,1,n,mid+1,r,1),u2=seg2.qry(1,1,n,l,mid,0);
		mn[now]=_min(mn[now],node(u1.p,u1.c+u2.c));
	}
	void modify(int now,int l,int r,int p)
	{
		if(l==r){mn[now].c=inf;return ;}
		int mid=(l+r)/2;
		if(p<=mid)modify(lc,l,mid,p);
		else modify(rc,mid+1,r,p);
		pushup(now,l,r);
	}
}seg3;
int main()
{
	n=read();D=read();
	if(n==1)return puts("0"),0;
	for(int i=1;i<=n;i++)a[i]=read();
	seg1.buildtree(1,1,n);
	seg2.buildtree(1,1,n);
	seg3.buildtree(1,1,n);
	for(int i=2;i<=n;i++)
	{
		seg1.modify(1,1,n,i,node(i,(LL)-D*i+a[i]),0);
		seg1.modify(1,1,n,i,node(i,(LL)D*i+a[i]),1);
	}
	seg2.modify(1,1,n,1,node(1,(LL)-D*1+a[1]),0);
	seg2.modify(1,1,n,1,node(1,(LL)D*1+a[1]),1);

	seg3.modify(1,1,n,1);
	LL ans=0;
	for(int i=1;i<n;i++)
	{
		ans+=seg3.mn[1].c;
		int u=seg3.mn[1].p;
		seg1.modify(1,1,n,u,node(u,inf),0);seg1.modify(1,1,n,u,node(u,inf),1);
		seg2.modify(1,1,n,u,node(u,(LL)-D*u+a[u]),0);seg2.modify(1,1,n,u,node(u,(LL)D*u+a[u]),1);
		seg3.modify(1,1,n,u);
	}
	pr2(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using pll = pair<ll, ll>;

int main(){
    ll n, d;
    cin >> n >> d;
    vector<ll> a(n);
    for(auto& i : a) cin >> i;
    auto cost = [&](ll x, ll y){
        return a[x] + a[y] + abs(x - y) * d;
    };
    vector<ll> l(n), r(n);
    l[0] = 0;
    for(ll i = 1; i < n; i++) l[i] = min(l[i - 1], i, [&](ll x, ll y){ return cost(i, x) < cost(i, y); });
    r[n - 1] = n - 1;
    for(ll i = n - 1; i--; ) r[i] = min(r[i + 1], i, [&](ll x, ll y){ return cost(i, x) < cost(i, y); });
    ll ans = 0;
    pll last;
    for(ll i = 0; i < n - 1; i++) if(last != pll{l[i], r[i + 1]}){
        last = {l[i], r[i + 1]};
        ans += cost(l[i], r[i + 1]);
    }
    for(ll i = 1; i < n - 1; i++) if(l[i] != i && r[i] != i) ans += min(cost(i, l[i - 1]), cost(i, r[i + 1]));
    cout << ans << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	for(ll i = m/n; i >= 1; --i){
		ll r = m - i * n;
		if(r < 0) continue;
		if(r%i == 0){
			cout << i << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
vector<long long> divisor(long long n){//nの約数列挙
    vector<long long> res;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}
int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> v = divisor(M);
    sort(v.begin(), v.end());
    long long ans = 0;
    for(int i = 0; i < v.size(); i++){
        if(M / v[i] >= N) ans = max(ans, v[i]);
    }
    cout << ans << endl;
}


#pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
using namespace std;

#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif

/***** type *****/
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
/***** define *****/
#define all(c) (c).begin(), (c).end()            // begin to end
#define coutld cout << fixed << setprecision(10) // cout double
#define output(x) do{cout<<x<<endl;exit(0);}while(0)
#define rep(i, b, e) for (ll i = b; i < e; i++)  // repeat
#define repr(i, b, e) for (ll i = b; e < i; i--) // repeat reverse
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)      // for each
/***** const value *****/
#define llong_max 9223372036854775807            // 9 * 10^18
#define ldbl_max 1.79769e+308                    // 1.7 * 10^308
#define pi 3.1415926535897932                    // 3.14 ...
/***** lambda *****/
auto Ceil = [] // if (a % b != 0) return a / b + 1;
(auto x) { return (ll)ceil(x); };
auto Count = [] // long long count value
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = [] // char to number
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = [] // number to char
(auto n) { return (char)('0' + n); };
auto Pow = [] // long long pow
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = [] // long long pow2
(auto n) { return (1LL << n); };
auto Pow10 = [] // long long pow10
(auto n) { return (ll)pow(10, n); };
auto Size = []  // long long collection size
(auto& c) { return (ll)(c).size(); };
auto Sum = [] // long long accumulate
(auto b, auto e) { return accumulate(b, e, 0LL); };

/***** template *****/
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{	// vector<vector<T>> resize + fill
	v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{	// vector<vector<vector<T>>> resize + fill
	v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{	// input vector<T> (T != struct) + fix
	v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{	// input vector<vector<T>> (T != struct) + fix
	MakeVVT(ys, xs, v, fix);
	rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{	// input vector<vector<vector<T>>> (T != struct) + fix
	v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}

/**************************************/
/********** BEGIN OF NYA LIB **********/
/**************************************/

namespace NyaGadget {}

/**************************************/
/*********** END OF NYA LIB ***********/
/**************************************/

using namespace NyaGadget;
//using mll = NT_ModLL< 1000000007 >;
//using mll = ModLL< 998244353 >;

int main(void)
{
	ll M; cin >> M;
	vt<pll> dc(M); each(i, e, dc) cin >> e.first >> e.second;

	ll sum = 0;
	ll keta = 0;
	each(i, e, dc)
	{
		sum += e.first * e.second;
		keta += e.second;
	}
	cout << (sum - 1) / 9 + keta - 1;
	return 0;
}

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;
const long long INF = 1e15;

int n;
int a[MAXN];
// long long dpl[MAXN], dpr[MAXN];
// pair<long long, long long> pl[MAXN], pr[MAXN];
long long sum;
long long total;
multiset <long long> st1, st2;

int main() {

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

  for (int i = n - 1; i > 0; i--) {
    sum += a[i];
    st2.insert(sum);
  }

  sum = 0;
  long long ans = INF;
  for (int i = 0; i + 1 < n; i++) {
    sum += a[i];
    if (st2.find(total - sum) != st2.end()) {
      st2.erase(st2.find(total - sum));
    }

    if (sz(st1) && sz(st2)) {
      vector<long long> v1, v2;
      auto it = st1.lower_bound(sum / 2);
      if (it != st1.end()) {
        v1.push_back(*it);
      }
      if (it != st1.begin()) {
        it--;
        v1.push_back(*it);
      }

      it = st2.lower_bound((total - sum) / 2);
      if (it != st2.end()) {
        v2.push_back(*it);
      }
      if (it != st2.begin()) {
        it--;
        v2.push_back(*it);
      }

      for (auto x : v1) {
        for (auto y : v2) {
          long long mn = min(x, y);
          long long mx = max(x, y);
          mn = min(mn, min(sum - x, total - sum - y));
          mx = max(mx, max(sum - x, total - sum - y));
          ans = min(ans, mx - mn);
        }
      }
    }

    st1.insert(sum);
  }

  // for (int i = 0; i < n; i++) {
  //   sum += a[i];
  //   dpl[i] = INF;
  //   if (sz(st)) {
  //     auto it = st.lower_bound(sum / 2);
  //     if (it != st.end()) {
  //       long long cur = *it;
  //       dpl[i] = min(dpl[i], abs(cur - (sum - cur)));
  //     }
  //     if (it != st.begin()) {
  //       it--;
  //       long long cur = *it;
  //       dpl[i] = min(dpl[i], abs(cur - (sum - cur)));
  //     }
  //   }
  //   st.insert(sum);
  // }

  // st.clear();
  // sum = 0;
  // for (int i = n - 1; i >= 0; i--) {
  //   sum += a[i];
  //   dpr[i] = INF;
  //   if (sz(st)) {
  //     auto it = st.lower_bound(sum / 2);
  //     if (it != st.end()) {
  //       long long cur = *it;
  //       dpr[i] = min(dpr[i], abs(cur - (sum - cur)));
  //     }
  //     if (it != st.begin()) {
  //       it--;
  //       long long cur = *it;
  //       dpr[i] = min(dpr[i], abs(cur - (sum - cur)));
  //     }
  //   }
  //   st.insert(sum);
  // }

  // for (int i = 0; i < n; i++) {
  //   cerr << dpl[i] << " ";
  // }
  // cerr << endl;

  /* long long ans = INF;
  for (int i = 1; i + 2 < n; i++) {
    ans = min(ans, max(dpl[i], dpr[i + 1]));
  } */

  cout << ans << endl;

  return 0;
}


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

typedef struct {
	int h;
	int w;
	int D;
} RECTANGLE;

RECTANGLE rectangle[30000];

bool cmp(const RECTANGLE& A, const RECTANGLE& B)
{
	if (A.D == B.D){
		return (A.h < B.h);
	}
	return (A.D < B.D);
}

int main()
{
	int i, n;

	for (int w = 2, i = 0; w <= 150; w++){
		for (int h = 1; h < w; h++){
			rectangle[i].h = h;
			rectangle[i].w = w;
			rectangle[i].D = h * h + w * w;
			i++;
			n = i;
		}
	}

	sort(rectangle, rectangle + n, cmp);

	int h, w;
	while (scanf("%d %d", &h, &w), h + w){
		for (int i = 0; i < n; i++){
			if (h == rectangle[i].h && w == rectangle[i].w){
				printf("%d %d\n", rectangle[i + 1].h, rectangle[i + 1].w);
				break;
			}
		}
	}

	return (0);
}

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

using namespace std;

int min(int a, int b) { return(a < b) ? a : b; }

class Solution
{
public:
	int minDistance(const string &word1, const string &word2)
	{
		const size_t m = word1.size() + 1;
		const size_t n = word2.size() + 1;

		vector<vector<int> > k(m, vector<int>(n));

		for (size_t i = 0; i < m; ++i)
			k[i][0] = i;

		for (size_t j = 0; j < n; ++j)
			k[0][j] = j;

		for (size_t i = 1; i < m; ++i)
		{
			for (size_t j = 1; j < n; ++j)
			{
				if (word1[i - 1] == word2[j - 1])
					k[i][j] = k[i - 1][j - 1];
				else
					k[i][j] = min(k[i - 1][j - 1], min(k[i - 1][j], k[i][j - 1])) + 1;
			}
		}
		return k[m - 1][n - 1];
	}
};

int main() {
	string a, b;
	cin >> a >> b;
	Solution A;
	cout << A.minDistance(a, b) << endl;
}