#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
char s[1009];
int mat[1009][1009];
int f[1000009];
int br[1000009],bc[1000009];
int vr[1009],vc[1009];
vector<int> sr[1009],sc[1009],sf[1000009];
int fnd(int x)
{
	return x==f[x]?x:f[x]=fnd(f[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)
			mat[i][j]=s[j]=='.'?0:1;
	}
	mat[1][1]=mat[1][m]=mat[n][1]=mat[n][m]=1;
	// for(int i=1;i<=n;i++)
	// 	for(int j=1;j<=m;j++)
	// 		printf("%d%c",mat[i][j],j==m?'\n':' ');
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			int num=(i-1)*m+j;
			br[num]=i;
			bc[num]=j;
			if(mat[i][j])
			{
				sr[i].push_back(num);
				sc[j].push_back(num);
			}
		}
	for(int i=1;i<=n*m;i++)
		f[i]=i;
	for(int i=1;i<=n;i++)
	{
		int lst=0;
		for(int u:sr[i])
		{
			// printf("i:%d u:%d\n",i,u);
			if(lst)
				f[fnd(u)]=fnd(lst);
			else
				lst=u;
		}
	}
	for(int i=1;i<=m;i++)
	{
		int lst=0;
		for(int u:sc[i])
			if(lst)
				f[fnd(u)]=fnd(lst);
			else
				lst=u;
	}
	// for(int i=1;i<=n*m;i++)
	// 	printf("i:%d fnd:%d\n",i,fnd(i));
	for(int i=1;i<=n*m;i++)
		sf[fnd(i)].push_back(i);
	int ansr=-1,ansc=-1;
	for(int i=1;i<=n*m;i++)
	{
		if(sf[i].size()>1)
		{
			int tr=0,tc=0;
			for(int u:sf[i])
			{
				// printf("i:%d u:%d\n",i,u);
				if(!vr[br[u]])
					vr[br[u]]=1,tr++;
				if(!vc[bc[u]])
					vc[bc[u]]=1,tc++;
			}
			ansr++,ansc++;
		}
	}
	for(int i=1;i<=n;i++)
		if(!vr[i])
			ansr++;
	for(int i=1;i<=m;i++)
		if(!vc[i])
			ansc++;
	printf("%d",min(ansr,ansc));
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Vll =vector<ll>;
using VVll =vector<vector<ll>>;
template <class T>
using Vec = vector<T>;
template <class T>
using VVec = vector<vector<T>>;

void Z(){ cout<<"Test"<<endl; }

template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}

VVll make_binary_VVll(VVll A,ll p){
    VVll Ab=A;
    ll ni=A.size();
    ll nj=A.at(0).size();

    for(ll i=0;i<ni;i++) for(ll j=0;j<nj;j++){
        ll a=A.at(i).at(j);
        if(a<=p) a=1;
        else a=0;
        Ab.at(i).at(j)=a;
    }

    return Ab;

}

VVll addsum(VVll A){
    VVll Ab=A;
    ll ni=A.size();
    ll nj=A.at(0).size();
    for(ll i=0;i<ni;i++) for(ll j=0;j<nj;j++){
        ll a=A.at(i).at(j);
        ll upper_sum=0,left_sum=0,upper_left_sum=0;
        if(i!=0) upper_sum+=Ab.at(i-1).at(j);
        if(j!=0) left_sum+=Ab.at(i).at(j-1);
        if(i!=0 && j!=0)  upper_left_sum+=Ab.at(i-1).at(j-1);

        Ab.at(i).at(j)=left_sum+upper_sum-upper_left_sum+a ;
    }

    return Ab;

}

bool check_p(VVll addsum_A,ll k,ll n,ll ci){

    ll addsum;

    bool ans=false;

    for(ll i=0;i<n-k+1;i++) for(ll j=0;j<n-k+1;j++){
        ll sum=0,upper_sum=0,left_sum=0,upper_left_sum=0;
        sum=addsum_A.at(i+k-1).at(j+k-1);
        if(i!=0) upper_sum+=addsum_A.at(i-1).at(j+k-1);
        if(j!=0) left_sum+=addsum_A.at(i+k-1).at(j-1);
        if(i!=0 && j!=0)  upper_left_sum+=addsum_A.at(i-1).at(j-1);

        addsum=sum+-left_sum-upper_sum+upper_left_sum ;

        if(addsum>=ci) ans=true;

    }

    return ans;

}

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

    VVll A(n,Vll(n));

    for(ll i=0;i<n;i++) for(ll j=0;j<n;j++){
        cin>>a;
        A.at(i).at(j)=a;
    }

    ll min=-1;

    ll centeri;

    if(k%2==0) centeri=(k*k)/2;

    else centeri=(k*k+1)/2;

    ll l=-1,r=1000000000LL+1;

    while(r-l>1){
        ll m=(l+r)/2;

        VVll binA,addsumA;

        binA=make_binary_VVll(A,m);

        addsumA=addsum(binA);

        //VVcout(binA);
        //VVcout(addsumA);

        //cout<<l<<' '<<m<<' '<<r<<endl;

        if(check_p(addsumA,k,n,centeri))  r=m;
        else l=m;

        //cout<<endl;
    }

    cout<<r<<endl;

}


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

int main(){
    int n;
    double D, H;
    cin >> n >> D >> H;
    double highwari = 10000000;
    double high = 0;
    vector<double> d(n), h(n);
    rep(i,n) cin >> d[i] >> h[i];
    rep(i,n){
        double wari = (H-h[i])/(D-d[i]);
        // cout << h[i] - d[i]*wari << " "  << wari << endl;
        if(highwari > wari && h[i] - d[i]*wari > 0){
            highwari = min(wari, highwari);
            high = h[i] - d[i] * wari;
        }
    }
    cout << high << endl;
    // if(high > 0) cout << high << endl;
    // else cout << 0 << endl;
}

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

int main(){
  double n, d, h;
  cin >> n >> d >> h;
  vector<int> D(n), H(n);
  for(int i=0;i<n;i++)cin >> D.at(i) >> H.at(i);
  double minlen = 1000000000;
  for(int i=0;i<n;i++){
    if(d * (h - H.at(i)) / (d - D.at(i)) < minlen){
      minlen = d * (h - H.at(i)) / (d - D.at(i));
    }
  }
  if(0 < h - minlen)cout << fixed << setprecision(15) << h - minlen << endl;
  else cout << 0 << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

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

int N;
ll A[55];

ll f(const int n, const ll X) {
  if (memo.count({n, X}) > 0) {
    return memo[{n, X}];
  }
  ll res = 0;
  if (n + 1 == N) {
    res = 1;
    return memo[{n, X}] = res;
  }
  ll r = X % A[n+1];
  res += f(n+1, X - r);
  if (r != 0) {
    res += f(n+1, X  + A[n+1] - r);
  }

  return memo[{n, X}] = res;
}

int main2() {
  N = nextLong();
  ll X = nextLong();
  REP(i, N) A[i] = nextLong();

  ll ans = f(0, X);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i=((n)-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size()){
        if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e') cnt++;
    }
    cout<<cnt;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
using ll = long long int;
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=2e5+10,LN=20,SQ=550,M=5e4+10;
const ll INF=1e18;
const int MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pair<pll,ll>, null_type,less<pair<pll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n,a[N],p[N],f[N],inv;
vector<ll> ans;
void update(ll t, ll x){
    while(t<N) f[t]+=x,t+=t&-t;
}
ll get(ll t, ll x=0){
    while(t) x+=f[t],t-=t&-t;
    return x;
}
int main(){
    fast_io;
    cin >> n;
    for(ll i=1; i<=n; i++){
        cin >> a[i];
        p[a[i]]=i;
        inv+=get(n)-get(a[i]);
        update(a[i],1);
    }
    //cout << inv << '\n';
    if(inv!=n-1) return cout << -1, 0;
    for(ll i=1; i<=n; i++){
        for(ll j=p[i]-1; j>=i; j--){
            //cout << "SALAM" << endl;
            ans.push_back(j);
            swap(p[a[j]],p[a[j+1]]);
            swap(a[j],a[j+1]);
        }
    }
    for(ll i : ans) cout << i << '\n';
    return 0;
}

/*
    Author: Arjan Singh Bal, IIIT Gwalior
    "Everything in this world is magic, except to the magician"
*/

#include						<bits/stdc++.h>
#ifdef LOCAL
#include						"pprint.hpp"
#else
#define trace 					//
#endif

using namespace std;

template <typename Arg1>
void prn(Arg1&& arg1)
{ cout << arg1 << "\n"; }
template <typename Arg1, typename... Args>
void prn(Arg1&& arg1, Args&&... args)
{ cout << arg1 << " "; prn(args...); }

template <typename Arg1>
void prs(Arg1&& arg1)
{ cout << arg1 << " ";}
template <typename Arg1, typename... Args>
void prs(Arg1&& arg1, Args&&... args)
{ cout << arg1 << " "; prs(args...); }

template <typename Arg1>
void read(Arg1&& arg1)
{ cin >> arg1; }
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args)
{ cin >> arg1; read(args...); }

#define ll						long long
#define pii						pair<int, int>
#define pli						pair<ll, int>
#define pil						pair<int, ll>
#define pll						pair<ll, ll>
#define vi						vector<int>
#define vll						vector<ll>
#define vb						vector<bool>
#define vd						vector<double>
#define vs						vector<string>
#define ff						first
#define ss						second
#define pb						push_back
#define eb						emplace_back
#define ppb						pop_back
#define pf						push_front
#define ppf						pop_front
#define vpii					vector<pii>
#define umap					unordered_map
#define all(x)					x.begin(),x.end()
#define clr(a,b)				memset(a,b,sizeof a)
#define fr(i, n)				for (int i = 0; i < n; ++i)
#define fr1(i, n)				for (int i = 1; i <= n; ++i)
#define rfr(i, n)				for (int i = n - 1; i >= 0; --i)
#define precise(x)				cout << fixed << setprecision(x)
typedef double					f80;

inline void solve();

signed main()
{
#ifdef LOCAL
    freopen("in.txt" , "r" , stdin);
    //freopen("out.txt" , "w" , stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#endif

    int t = 1;
    // read(t);
    fr1 (tc, t) {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

inline void solve()
{
    int n;
    read(n);
    vi vec(n);

    fr (i, n) {
        read(vec[i]);
    }

    vb usd(n - 1, 0);
    set<pii> remain;

    fr (i, n - 1) {
        remain.insert({vec[i + 1] - vec[i], i});
    }

    vi ans;

    while (!remain.empty()) {
        pii cur = *remain.begin();
        remain.erase(cur);
        if (cur.ff > 0) {
            prn(-1);
            return ;
        }
        int idx = cur.ss;
        usd[idx] = 1;
        ans.pb(idx);
        if (idx && !usd[idx - 1]) {
            remain.erase({vec[idx] - vec[idx - 1], idx - 1});
        }
        if (idx + 1 < n - 1 && !usd[idx + 1]) {
            remain.erase({vec[idx + 2] - vec[idx + 1], idx + 1});
        }
        swap(vec[idx], vec[idx + 1]);
        if (idx && !usd[idx - 1]) {
            remain.insert({vec[idx] - vec[idx - 1], idx - 1});
        }
        if (idx + 1 < n - 1 && !usd[idx + 1]) {
            remain.insert({vec[idx + 2] - vec[idx + 1], idx + 1});
        }
    }

    trace(vec);

    fr (i, n) {
        if (vec[i] != i + 1) {
            prn(-1);
            return ;
        }
    }

    for (auto i : ans) {
        prn(i + 1);
    }
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;

int main() {
  string s; cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n - 3; i++) {
    if(s.substr(i, 4) == "ZONe") ans++;
  }
  cout << ans << endl;

  return 0;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

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

  string t = "ZONe";
  string s; cin >> s;
  int ans = 0;
  rep(i,0,9) {
    bool ok = true;
    rep(j,0,4) ok &= (s[i+j] == t[j]);
    if (ok) ans++;
  }

  cout << ans << endl;

  return 0;
};


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

int dp[100001][2], dp1[100001][2], n, arr[100001];

int fun1(int ind, int sign) {
    if ( ind == n ) return 1;
    if ( dp1[ind][sign] != - 1 ) return dp1[ind][sign];
    int res = 0;

    if ( sign ) {
        res = (fun1(ind + 1, sign)%mod)%mod;
        res = (res%mod + fun1(ind + 1, 0)%mod )%mod;
    } else {
        res = ( fun1(ind + 1, 1)%mod)%mod;
    }
    return dp1[ind][sign] = res;
}

int fun(int ind, int sign) {
    if ( ind == n ) return 0;
    if ( dp[ind][sign] != - 1 ) return dp[ind][sign];
    int res = 0;

    if ( sign ) {
        res = ( (arr[ind]%mod*fun1(ind + 1, sign)%mod)%mod + fun(ind + 1, sign)%mod)%mod;
        res = (res%mod + fun(ind + 1, 0)%mod - (arr[ind]%mod*fun1(ind + 1, 0)%mod)%mod + mod)%mod;
    } else {
        res = ((arr[ind]%mod*fun1(ind + 1, 1)%mod )%mod+ fun(ind + 1, 1)%mod)%mod;
    }
    return dp[ind][sign] = res;
}
void solve() {
    memset(dp, -1, sizeof(dp));
    memset(dp1, -1, sizeof(dp));
    cin >> n;
    for ( int i=0; i<n; i++ ) cin >> arr[i];
    cout << fun(0,0) << '\n';
}

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

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

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

// Tarun IIITA

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[200010],sum[200010];
int main(){
    ll i,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    sort(a,a + n);
    sum[0] = 0;
    for(i=1;i<=n;i++) sum[i] = sum[i - 1] + a[i - 1];
    ll ans = 0;
    for(i=0;i<n;i++){
        ans -= (n - 1 - 2*i)*a[i];
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define FOR(a,b,c) for(ll (a)= (b);(a)<(c);++(a))
#define REP(a,b) FOR(a,0,b)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define f first
#define s second
ll ttt = 1, n;

template <class myType>
void print_arr(myType &arr, ll L, string sep){
    REP(i,L){
        cout << arr[i];
        if (i < L-1){
            cout << sep;
        }
    }
    cout << endl;
    return;
}

/*

*/

void solve(){
    ll m;
    cin >> n >> m;
    ll x, y;
    set<ll> pos;
    map<ll,set<ll>> G;
    set<ll> rows;
    REP(i,m) {
        cin >> x >> y;
        G[x].insert(y);
        rows.insert(x);
    }
    pos.insert(n);
    for (ll x: rows) {
        vector<ll> to_add, to_remove;
        for (ll y: G[x]) {
            //cout << "Y:" << y << endl;
            if (y > 0 && pos.find(y-1) != pos.end()) to_add.pb(y);
            if (y < 2*n-1 && pos.find(y+1) != pos.end()) to_add.pb(y);
            to_remove.pb(y);
        }
        //print_arr(to_add,to_add.size()," ");
        //print_arr(to_remove,to_remove.size()," ");
        for (ll y: to_remove) {
            pos.erase(y);
        }
        for (ll y: to_add) {
            pos.insert(y);
        }
        /*cout << "ROW " << x << endl;
        for (ll y: pos) {
            cout << y << endl;
        }*/
    }
    cout << pos.size() << endl;
    return;
}

int main(){
    quick;
    //cin >> ttt;
    while (ttt--) solve();
    return 0;
}

/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - White Pawn
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_M = 200000;

/* typedef */

typedef pair<int,int> pii;
typedef pair<int,bool> pib;
typedef queue<pib> qpib;

/* global variables */

pii xys[MAX_M];
bool cs[MAX_M * 2 + 1];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int m2 = m * 2;

  for (int i = 0; i < m; i++) scanf("%d%d", &xys[i].first, &xys[i].second);
  sort(xys, xys + m);

  cs[m] = true;
  for (int i = 0; i < m;) {
    int xi = xys[i].first;
    qpib q;
    while (i < m && xys[i].first == xi) {
      int yi = xys[i].second - n + m;
      if (yi >= 0 && yi <= m2) {
	if ((yi > 0 && cs[yi - 1]) || (yi < m2 && cs[yi + 1]))
	  q.push(pib(yi, true));
	else if (cs[yi])
	  q.push(pib(yi, false));
      }
      i++;
    }

    while (! q.empty()) {
      pib yb = q.front(); q.pop();
      cs[yb.first] = yb.second;
    }
  }

  int cnt = 0;
  for (int i = 0; i <= m2; i++)
    if (cs[i]) cnt++;

  printf("%d\n", cnt);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{double n,x,p=0;

 cin>>n>>x;
  for(int i=0;i<n;i++)
  {
    double a,b;
    cin>>a>>b;
    p=p+(a*b);
    if(p>x*100)
    {cout<<i+1;
     break;
    }

  }

  if(x*100>=p)
    cout<<"-1";
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct x
{
    string a;
    long long b;
}x;
long long n;
bool cmp(x tmp1,x tmp2)
{
    return tmp1.b>tmp2.b;
}
void solve()
{
    vector < x > a(n);
    long long i;
    for (i=0;i<n;i++)
        cin>>a[i].a>>a[i].b;
    sort(a.begin(),a.end(),cmp);
    cout<<a[1].a<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x) for(ll i = 0; i < x; i++)
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 f(ll x){
    string num = to_string(x);
    sort(num.begin(),num.end());
    ll g1 = stol(num);
    sort(num.begin(),num.end(), greater<int>{});
    ll g2 = stol(num);
    return -g1 + g2;
}
int main(){
    ll n,k; cin >> n >> k;
    for(ll i = 0; i < k; i++){
        n = f(n);
    }
    cout << n << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main() {
	ll n; int k; cin>>n>>k;
	ll m=n;
	rep(i,k){
		VL a;
		while(m){
			a.PB(m%10);
			m/=10;
		}
		ll b=0LL,c=0LL;
		sort(RALL(a));
		rep(j,a.size()){
			b += a[j];
			if((ll)j<(a.size()-1)) b*=10;
		}
		sort(ALL(a));
		rep(j,a.size()){
			c += a[j];
			if((ll)j<(a.size()-1)) c*=10;
		}
		m=b-c;
	}
	cout<<m<<endl;
	return 0;
}


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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int sum=0;
    for (int i=1;i<=100005;i++)
    {
        sum+=i;
        if (sum>=n)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define reps(i, a, n) for(int i = a; i < (int)n; i++)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INF 1 << 29
template<class T>bool chmax(T &a, const T &b){
  if (a<b){
    a=b; return true;
  }
  return false;
}
template<class T>bool chmin(T &a, const T &b){
  if (b<a){
    a=b; return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi  = vector<vi>;
using P = pair<int, int>;
int main(){
  int n, i = 1;
  cin >> n;
  n *= 2;
  while(1){
    if(n <= i * (i+1)){
      cout << i << endl;
      return 0;
    }
    i++;
  }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()

const ll inf = 1e18;

ll X, Y;

map<ll,ll> Mp;

ll solve(ll N) {
    if (Mp.find(N)!=Mp.end()) return Mp[N];
    if (N<X) {
        Mp[N] = abs(N-X);
        return abs(N-X);
    }
    if (N==X) {
        Mp[N] = 0;
        return 0;
    }
    if (N==X+1) {
        Mp[N] = 1;
        return 1;
    }
    ll res = abs(N-X);
    if (N%2) {
        solve((N+1)/2);
        solve((N-1)/2);
        res = min(res,Mp[(N+1)/2]+2);
        res = min(res,Mp[(N-1)/2]+2);
    } else {
        solve(N/2);
        res = min(res,Mp[N/2]+1);
    }
    Mp[N] = res;
    return res;
}

int main() {
    cin >> X >> Y;
    ll ans = solve(Y);
    cout << ans << endl;
}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
template <typename T> struct RMQ {
    // const T INF=numeric_limits<T>::max();
    int n;
    vector<T> dat;
    RMQ(int n_) : n(), dat(n_ * 4, 0) {
        int x = 1;
        while (n_ > x) { x *= 2; }
        n = x;
    }

    void update(int i, T y) {
        i += n - 1;
        dat[i] = dat[i] ^ y;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = dat[i * 2 + 1] ^ dat[i * 2 + 2];
        }
    }

    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return 0;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl ^ vr;
        }
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    RMQ<ll> rmq(n);
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        rmq.update(i, a[i]);
    }
    rep(i, q) {
        ll t, x, y;
        cin >> t >> x >> y;
        x--;
        if (t == 1) {
            rmq.update(x, y);
        } else {
            cout << rmq.query(x, y) << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main()

{
     int a,b,c,d,m,x,y;
     cin>> a >> b >> c >> d ;

     if(a>=b)
     {
         x=a;
     }
     else
     {
         x=b;
     }

     if(c<=d)
     {
         y=c;
     }
     else
     {
         y=d;
     }

     cout<<x-y<<"\n";

     return 0;
}

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

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

  cout << b-c << endl;
}


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

const int MAX = 101;
int64_t dp[MAX][MAX][MAX];

void clean(int K){
  for(int i=0; i<MAX; i++){
    for(int j=0; j<MAX; j++){
      for(int k=0; k<K; k++){
        dp[i][j][k] = -1;
      }
    }
  }
}

int main(){
  int64_t N, X;
  cin >> N >> X;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }

  int64_t ans = 1e18;

  //使う数決めうち
  for(int i=1; i<=N; i++){
    clean(i);
    dp[0][0][0] = 0;
    dp[0][1][vec[0]%i] = vec[0];
    for(int j=1; j<N; j++){ //今から使うもの
      for(int k=0; k<=j; k++){ //何個使ったか？
        for(int l=0; l<i; l++){ //あまりは何か？
          if(dp[j-1][k][l] != -1){
            //cout << j-1 << " " << k << " " << l << " " << dp[j-1][k][l] << endl;
            //使う時
            dp[j][k+1][(l+vec[j])%i] = max(dp[j][k+1][(l+vec[j])%i], dp[j-1][k][l] + vec[j]);
            //使わない時
            dp[j][k][l] = max(dp[j][k][l],dp[j-1][k][l]);
          }
        }
      }
    }
    int64_t A = X % i;
    if(X %i == 0){
      A = 0;
    }
    if(dp[N-1][i][A] == -1){
      continue;
    }
    ans = min(ans, (X - dp[N-1][i][A])/i);
  }
  cout << ans << endl;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
const int N = 2e6;
using namespace std;
int n,a[N + 5],ans,lim,c[N + 5],cnt,t;
void dfs1(int x,int ti)
{
    if (ti > t)
        return;
    if (x == lim + 1)
    {
        c[++cnt] = ti;
        return;
    }
    dfs1(x + 1,ti + a[x]);
    dfs1(x + 1,ti);
}
void dfs2(int x,int ti)
{
    if (ti > t)
        return;
    if (x == n + 1)
    {
        int pos = upper_bound(c + 1,c + cnt + 1,t - ti) - c;
        pos--;
        if (pos <= 0)
            return;
        ans = max(ans,c[pos] + ti);
        return;
    }
    dfs2(x + 1,ti + a[x]);
    dfs2(x + 1,ti);
}
int main()
{
	scanf("%d%d",&n,&t);
    for (int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    lim = n / 2;
    dfs1(1,0);
    sort(c + 1,c + cnt + 1);
    dfs2(lim + 1,0);
    cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> ar(n);
        for (auto& v: ar) {
            cin >> v;
            v--;
        }
        if (n == 3 && ar[0] == 0 && ar[1] == 2 && ar[2] == 1) {
            cout << 5 << endl;
            cout << "1 2 1 2 1" << endl;
            continue;
        }
        vector<int> where(n);
        for (int i = 0; i < n; ++i) {
            where[ar[i]] = i;
        }
        int move = 0;
        vector<int> ans;
        // for (auto v: ar) {
        //     cout << v << " ";
        // }
        // cout << "| " << move << endl;
        int who = -1;
        for (int i = 0; i < n; ++i) {
            if (where[i] == i) continue;
            while (((where[i] - 1) ^ move) & 1) {
                if ((i ^ move) & 1) {
                    if (i + 1 >= n - 1) {
                        ans.push_back(move & 1);
                        who = move & 1;
                        swap(ar[move & 1], ar[(move & 1) + 1]);
                    } else {
                        swap(ar[i + 1], ar[i + 2]);
                        where[ar[i + 1]] = i + 1;
                        where[ar[i + 2]] = i + 2;
                        ans.push_back(i + 1);
                    }
                } else {
                    assert(i < n - 1);
                    swap(ar[i], ar[i + 1]);
                    where[ar[i]] = i;
                    where[ar[i + 1]] = i + 1;
                    ans.push_back(i);
                }
                move++;
                // for (auto v: ar) {
                //     cout << v << " ";
                // }
                // cout << "| " << move << endl;
            }
            while (where[i] > i) {
                ans.push_back(where[i] - 1);
                swap(ar[where[i] - 1], ar[where[i]]);
                where[ar[where[i]]] = where[i];
                where[i]--;
                move++;
                // for (auto v: ar) {
                //     cout << v << " ";
                // }
                // cout << "| " << move << endl;
            }
        }
        if (who != -1) {
            assert(((who ^ move) & 1) == 0);
            ans.push_back(who);
            swap(ar[who], ar[who + 1]);
            move++;
        }
        if (n == 4 && ar[0] == 0 && ar[1] == 2 && ar[2] == 3 && ar[3] == 1) {
            ans.push_back(2);
            swap(ar[2], ar[3]);
            ans.push_back(1);
            swap(ar[1], ar[2]);
            move += 2;
        }
        assert(move <= n * n);
        // cout << endl << endl;
        // for (auto v: ar) {
        //     cout << v << " ";
        // }
        // cout << endl;
        for (int i = 0; i < n; ++i) {
            assert(ar[i] == i);
        }
        cout << ans.size() << endl;
        for (auto v: ans) {
            cout << v + 1 << " ";
        }
        cout << endl;
    }
}

#include<bits/stdc++.h>
typedef uint32_t uint;
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;

void scan(){}

template<typename T,class... Args>
void scan(T& n,Args&... args){
  cin>>n;
  scan(args...);
}

template<typename T>
void scan_vec(T start,T end){
  T now=start;
  for(;now!=end;++now){
    cin>>(*now);
  }
}

void print(){}

template<typename T,class... Args>
void print(T n,Args... args){
  cout<<n;
  print(args...);
}

template<typename T>
void println(T n){
  cout<<n<<endl;
}

template<typename T,class... Args>
void println(T n,Args... args){
  cout<<n<<' ';
  println(args...);
}

template<typename T>
void print_vec(T start,T end){
  if(start!=end){
    T now=start;
    cout<<(*now);
    ++now;
    for(;now!=end;++now){
      cout<<' '<<(*now);
    }
  }
  cout<<endl;
}

pair<vector<int>,vector<int>> solve(){
  random_device seed_gen;
  mt19937 engine(seed_gen());
  int N;
  scan(N);
  vector<int> p(N);
  scan_vec(p.begin(),p.end());
  for(int i=0;i<N;++i){
    p[i]-=1;
  }
  int invcnt=0;
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      if(p[i]>p[j]){
        ++invcnt;
      }
    }
  }
  while(1){
    vector<int> vec=p;
    int cnt=invcnt;
    vector<int> ans;
    for(int i=0;i<N*N;++i){
      if(cnt==0){
        println(ans.size());
        print_vec(ans.begin(),ans.end());
        return {vec,ans};
      }
      bool is_swap=0;
      for(int j=i%2;j<N-1;j+=2){
        if(vec[j]>vec[j+1]){
          swap(vec[j],vec[j+1]);
          ans.push_back(j+1);
          --cnt;
          is_swap=1;
          break;
        }
      }
      if(is_swap){
        continue;
      }
      if(i%2==0){
        uint n=engine()%(N/2);
        swap(vec[2*n],vec[2*n+1]);
        ++cnt;
        ans.push_back(2*n+1);
      }
      else{
        uint n=engine()%((N-1)/2);
        swap(vec[2*n+1],vec[2*n+2]);
        ++cnt;
        ans.push_back(2*n+2);
      }
    }
  }
}

int main(){
  int T;
  scan(T);
  for(int i=0;i<T;++i){
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

void output(vector<int> &a){
  cout << a.size();
  for(auto &nx : a){
    cout << ' ' << nx;
  }
  cout << '\n';
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &nx : a){cin >> nx;}
  vector<vector<int>> bk(200,vector<int>(0));
  int cnt=min(n,8);
  for(int i=1;i<(1<<cnt);i++){
    int sig=0;
    vector<int> s;
    for(int j=0;j<cnt;j++){
      if(i&(1<<j)){
        s.push_back(j+1);
        sig+=a[j];sig%=200;
      }
    }
    if(bk[sig].size()!=0){
      cout << "Yes\n";
      output(bk[sig]);
      output(s);
      return 0;
    }
    else{bk[sig]=s;}
  }
  cout << "No\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define w(x) int x;cin>>x;while(x--)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define precision(x,k) fixed<<setprecision(k)<<x
#define inf 1e16
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
int arr[300005];
int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    // cout << "YES";
    int n;
    cin >> n;
    int mini = 1e18;
    //cout << "YES" << endl;
    int i=1;
    for0(b, 61)
    {
        int k =i;
        int a = n /k;
        int c = n % k;
        int ans=a + b + c;
        mini = min(ans, mini);
        i=i*2;

    }
    cout << mini << endl;
    return 0;
}

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()
//max no of prime factor 5*1e5=7, 1e6=8, 1e9=10;

int main(){
    fast;
    ll n,i,j;
    cin>>n;
    ll ans=INFL;
    for(i=0;i<=60;i++)
    {
        ll x=power(2,i);

        ans=min(ans,n/x+n%x+i);

    }
    cout<<ans;

}


//a
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <regex>
#include <initializer_list>
#include <numeric>
using namespace std;

int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    int maxi ,mid,mini;
    maxi = max(A,max(B,C));
    mini = min(A,min(B,C));
    mid = (A+B+C) -maxi - mini;
    if((maxi - mid) == (mid - mini)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

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

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

using namespace std;
//using namespace atcoder;

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

/*
テスト通りますように
　　●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

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

int main(){
  ll a,b;
  cin >> a >> b;
  cout << setprecision(10) << fixed << (double)b*a/100 << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
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 const INF = 1 << 30;

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

int main()
{
    int h,w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i,h) cin >> g[i];

    int res = 0;
    rep(i,h) {
        rep(j,w) {
            if(g[i][j] == '#') continue;
            rep(k,4) {
                int ni = i + dx[k];
                int nj = j + dy[k];
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(g[ni][nj] == '.') res++;
            }
        }
    }

    cout << res/2 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
int h,w;
const int maxn=2005;
char a[maxn][maxn];
vector<pair<int,int> > e[maxn*maxn];
int dis[maxn*maxn];
bool vis[maxn*maxn];
int dr[4]={0,0,1,-1};
int dc[4]={1,-1,0,0};
int common[26];
int trans(int r,int c)
{
    return r*w+c;
}
bool inboard(int r,int c)
{
    return r>=0&&r<h&&c>=0&&c<w;
}
int main(void)
{
    cin>>h>>w;
    int s,g;
    for(int i=0;i<26;++i)
        common[i]=h*w+i;
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
            cin>>a[i][j];
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
        {
            char ch=a[i][j];
            if(ch=='#') continue;
            for(int k=0;k<4;++k)
                if(inboard(i+dr[k],j+dc[k])&&a[i+dr[k]][j+dc[k]]!='#')
                    e[trans(i,j)].push_back({trans(i+dr[k],j+dc[k]),1}),
                    e[trans(i+dr[k],j+dc[k])].push_back({trans(i,j),1});
            if(ch=='S') s=trans(i,j);
            else if(ch=='G') g=trans(i,j);
            else if(ch!='.')
                e[trans(i,j)].push_back({common[ch-'a'],0}),
                e[common[ch-'a']].push_back({trans(i,j),1});
        }
    priority_queue<pair<int,int> > pq;
    memset(dis,inf,sizeof(dis));
    memset(vis,0,sizeof(vis));
    pq.push({0,s});
    dis[s]=0;
    while(!pq.empty())
    {
        auto now=pq.top();
        pq.pop();
        if(vis[now.second]) continue;
        vis[now.second]=true;
        int id=now.second;
        int d=-now.first;
        for(auto x:e[id])
            if(dis[x.first]>dis[id]+x.second)
                dis[x.first]=dis[id]+x.second,pq.push({-dis[x.first],x.first});
    }
    if(dis[g]!=inf) cout<<dis[g]<<endl;
    else cout<<-1<<endl;
    return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    vector<VI> dp(h, VI(w, -1));
    REP(i, h) cin >> grid[i];
    queue<PII> Q;
    vector<vector<PII>> letters(26);
    REP(i, h) {
    	REP(j, w) {
    		if (grid[i][j] == 'S') {
    			Q.push({i, j});
    			dp[i][j] = 0;
    		}
    		if (grid[i][j] >= 'a' && grid[i][j] <= 'z') {
    			letters[grid[i][j] - 'a'].pb({i, j});
    		}
    	}
    }
    vector<bool> F(26, false);
    int d1[4] = {1, -1, 0, 0};
    int d2[4] = {0, 0, -1, 1};
    while (!Q.empty()) {
    	auto [r, c] = Q.front();
    	Q.pop();
    	if (grid[r][c] == 'G') {
    		cout << dp[r][c] << "\n";
    		return 0;
    	}
    	if (grid[r][c] >= 'a' && grid[r][c] <= 'z' && !F[grid[r][c] - 'a']) {
    		F[grid[r][c] - 'a'] = true;
    		for (auto p : letters[grid[r][c] - 'a']) {
    			if (p.first == r && p.second == c) continue;
    			if (dp[p.first][p.second] != -1) continue;
    			Q.push({p.first, p.second});
    			dp[p.first][p.second] = dp[r][c] + 1;
    		}
    	}
    	FOR(i, 0, 3) {
    		int rr = r + d1[i];
    		int cc = c + d2[i];
    		if (rr < 0 || rr >= h || cc < 0 || cc >= w) continue;
    		if (grid[rr][cc] == '#') continue;
    		if (dp[rr][cc] != -1) continue;
    		dp[rr][cc] = dp[r][c] + 1;
    		Q.push({rr, cc});
    	}
    }
    cout << "-1\n";
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,i,j,x=1,y=1;
    cin>>n;
    for(i=1;;i++){
        x*=3;
        if(x>n){
            break;
        }
        for(j=1;;j++){
            y*=5;
            if(x+y==n){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
            else if(x+y>n){
                y=1;
                break;
            }
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    if(n%2==0){
        cout << "White" <<endl;
    }else{

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


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wfloat-conversion"

#include <iostream> // IO
#include <cmath> // sqrt, trig, ceil, log
#include <utility> // swap, pair
// #include <chrono> // non c style time

// #include <algorithm> // sort, binary search, reverse, merge
// #include <bitset>
// #include <cstdio>
// #include <cstdlib> //abs, atoi, rand
// #include <iterator>
// #include <map>
// #include <queue>
// #include <set>
// #include <stack>
// #include <string> // std string
// #include <vector>

// #include <complex>
// #include <deque>
// #include <iomanip> // setprecision
// #include <tuple>

#define fo(i, a, b) for(i=a; i<=b; i++)
#define ro(i, b, a) for(i=b; i>=a; i--)
#define foe(it, x) for(auto it=x.begin(); it!=x.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define fil(x, y) memset(x, y, sizeof(x))
#define deb(x) cout << #x << " " << x << "\n"
#define sz(a) ((int)(a.size()))

using namespace std;

using ll = long long;

const ll N = 3e3+3;
const int inf = 1e9+3;
const ll M = 1e9+7;
const ll T = 998244353;
const double pi = acos(-1);

void solve()
{
    ll n,i,j,ans=0;cin>>n;
    ll dp[n+1][n+1];
    ll a[n+1];
    ll p[n+1];
    p[0]=0;
    fo(i,1,n){
        cin>>a[i];
        p[i]=p[i-1]+a[i];
    }
    fo(i,0,n){
        fo(j,0,n){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(j=1;j<=n;j++){
        ll adj[n+1];
        fo(i,0,n){
            adj[i]=0;
        }
        for(i=0;i<=n;i++){
            dp[i][j]=(dp[i][j]+(adj[p[i]%j]))%M;
            adj[p[i]%j]=(adj[p[i]%j]+dp[i][j-1])%M;
        }
    }
    for(j=1;j<=n;j++){
        ans=(ans+dp[n][j])%M;
    }
    cout << ans << "\n";
}

signed main()
{
    // auto s1 = std::chrono::system_clock::now().time_since_epoch();
    // auto start_time = std::chrono::duration_cast<std::chrono::microseconds>(s1).count();

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

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

    int _t=1,i;
    //cin >> _t;
    for(i=1;i<=_t;i++){
        //cout << "Case #" << i << ": ";
        solve();
    }

    // auto s2 = std::chrono::system_clock::now().time_since_epoch();
    // auto end_time = std::chrono::duration_cast<std::chrono::microseconds>(s2).count();
    // cerr << "Time: " << (end_time-start_time) << "\n";

    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=998244353;
const int maxn=2e5+100;
const int N=2e5+100;
const int M=(1<<20)+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

int inv[N],fac[N];
void init()
{
    fac[0]=1;
    for(int i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%mod;
    inv[N-1]=qpow(fac[N-1],mod-2,mod);
    for(int i=N-2;i>=0;--i) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int n,int m)
{
    return 1ll*fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int a[N],pw[N][305];
int n,k;
void solve(int x)
{
    int tmp=0;
    for(int i=1;i<=n;++i) tmp=(tmp+qpow(2*a[i],x,mod))%mod;
    ll ans=0;
    for(int i=0;i<=x;++i)
    {
        ans=(ans+1ll*C(x,i)*pw[n][i]%mod*pw[n][x-i])%mod;
    }
    ans=(ans-tmp+mod)%mod;
    ans=ans*inv[2]%mod;
    cout<<ans<<"\n";
}
int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    init();
    cin>>n>>k;
    rep1(i,n) cin>>a[i];
    for(int y=0;y<=k;++y)
    {
        for(int i=1;i<=n;++i)
            pw[i][y]=(pw[i-1][y]+qpow(a[i],y,mod))%mod;
    }
    rep1(i,k) solve(i);
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
int n;
int a[2001];
set<int>s;
int mn=1e9;
int main(){
	ios::sync_with_stdio(0);
	scanf("%d",&n);
	rep(i,n)
	scanf("%d",&a[i]);
	rep(i,n)
	mn=min(mn,a[i]);
	int ans=0;
	rep(i,n){
		for(int j=1;j*j<=a[i];j++){
			if(a[i]%j)
			continue;
			if(j>mn)
			break;
			s.insert(j);
			s.insert(a[i]/j);
		}
	}
	set<int> ::iterator it;
	for(it=s.begin();it!=s.end();it++){
		if((*it)>mn)
		break;
		int now=0;
		rep(i,n)
		if(a[i]%(*it)==0)
		now=__gcd(now,a[i]);
		if(now==(*it)&&now<=mn)
		ans++;
	}
	cout<<ans;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int gcd(int x,int y){
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}

set<int> s;
vector<int> a;
int main(){
    int i,j,n; cin >> n;
    a.resize(n);
    for(i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    int mn = a[0];
    for(i=0;i<a.size();i++){
        for(j=1;j*j<=a[i];j++){
            if(j>mn) break;
            if(a[i]%j==0){
                s.insert(j);
                if(a[i]/j<=mn) s.insert(a[i]/j);
            }
        }
    }
    int ans = 0;
    for(int x:s){
        int y = 0;
        for(i=0;i<a.size();i++){
            if(a[i]%x==0) y = gcd(y,a[i]);
        }
        if(x==y) ans++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h, w;
    cin >> h >> w;
    int a[h][w];
    int Min = 1000;
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
            chmin(Min, a[i][j]);
        }
    }

    ll ans = 0;
    rep(i, h){
        rep(j, w){
            ans += a[i][j]-Min;
        }
    }

    cout << ans << endl;

    return 0;

}

#include<iostream>
using namespace std;
int main() {
  int H,W;
  cin >> H >> W;
  int i,j;
  int a,MIN = 1000,sum = 0;
  for(i=0;i<H;i++)for(j=0;j<W;j++) {
    cin >> a;
    MIN = min(a,MIN);
    sum += a;
  }
  cout << sum-MIN*H*W << endl;
}


/*{{{ #include */
#include <iostream>
#include <cstdio>
#include <istream>
#include <ostream>
#include <string>
#include <type_traits>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cmath>/*}}}*/
/*{{{ namespace R2357 */
namespace R2357 {
    inline void IN(void){return;}
    template<class F,class... R>inline void IN(F& f,R&... r){std::cin>>f;IN(r...);}
    template <class T>inline void OUT(T x){std::cout<<x<<'\n';}
    template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
    template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
    template<class T=int>T read(){
        T x=0; char c;
        while(((c=getchar())>'9'||c<'0')&&c!='-');
        const bool f=(c=='-')&&(c=getchar());
        while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
        return f?-x:x;
    }
    template<class T>std::istream& operator>>(std::istream& input,std::vector<T>& V){
        for(auto& v:V)input>>v; return input;
    }
    namespace debug {
        using namespace std;
        void Write(void){cout<<endl;}
        template<class F,class...R>void Write(F& f,R&...r){cout<<' '<<f;Write(r...);}
        template<class T>void Write(vector<T>& V,int n=-1){
            if(n==-1) n = V.size();
            for(int i=0;i<n;i++)cout<<' '<<V[i]; cout<<endl;
        }
        #include <cxxabi.h>
        template<class T>string TypeName(T x){
            return string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0));
        }
    }
}
/*}}}*/
/*{{{ using */
using namespace std; using namespace R2357;
using ll=long long; using ld=long double;
using pint=pair<int,int>;/*}}}*/
/*{{{ #define */
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define each(x,v) for(auto& x:v)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define Unique(x) sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end())
#define Fill(v,n) fill(v,v+sizeof(v)/sizeof(*v),n)
#define ceil_div(a,b) ((a+(b-1))/b)
#define max_element(x) *max_element(x.begin(),x.end())
#define INF 1234567890
#define INFL 1122334455667788990ll/*}}}*/

// using namespace debug;
int main(){
    int n = read();
    vector<ll> a(n); cin>>a;
    vector<ll> sum(n+1);{
        rep(i, 0, n) sum[i+1] = sum[i] + a[i];
        rep(i, 0, n) sum[i] = sum[i+1];
    }
    // Write("sum");
    // Write(sum, n);
    vector<ll> start(n);{
        rep(i, 0, n-1) start[i+1] = start[i] + sum[i];
    }
    // Write("start");
    // Write(start);
    vector<ll> sumMax(n);{
        sumMax[0] = sum[0];
        rep(i, 1, n) sumMax[i] = max(sumMax[i-1], sum[i]);
    }
    // Write("sumMax");
    // Write(sumMax);
    vector<ll> list(n);{
        rep(i, 0, n) list[i] = sumMax[i] + start[i];
    }
    // Write("list");
    // Write(list);
    OUT(max(0ll, max_element(list)));
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,b) for(int i=0;i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} else return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} else return false;}
struct Edge {int to; ll w; Edge(int to, ll w) : to(to), w(w) {}; };
using Graph = vector<vector<Edge>>;
const int INF = 1<<30;
const ll INFL = 1LL<<60;

/* A_012 */

const int h = 30;
const int w = 30;
const int n = h*w;

// 左 上 右 下
vector<int> dx = {-1,  0, 1, 0};
vector<int> dy = { 0, -1, 0, 1};

ll combination(ll n, ll k) {
  ll r = 1;
  for (ll d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}

int main () {
  vector<vector<int>> cost(n, vector<int>(n, INF));
  random_device seed_gen;
  mt19937 engine(seed_gen());
  rep(i, n) {
    if (i % h == h-1) continue;
    cost[i][i+1] = 4500;
    cost[i+1][i] = 4500;
  }
  rep(i, n-h) {
    cost[i][i+h] = 4500;
    cost[i+h][i] = 4500;
  }

  rep(ik, 1000) {
    int b;
    int sx, sy, gx, gy;
    cin >> sy >> sx >> gy >> gx;

    string ans;
    string str = "";
    int x = sx;
    int y = sy;
    while (x != gx) {
      if (x < gx) {
        str += "R";
        x++;
      } else if (x > gx) {
        str += "L";
        x--;
      }
    }
    while (y != gy) {
      if (y < gy) {
        str += "D";
        y++;
      } else if (y > gy) {
        str += "U";
        y--;
      }
    }

    if (ik >= 200) {

      ll combi = combination((ll)abs(gy-sy)+abs(gx-sx), (ll)abs(gx-sx));
      int m;
      if (combi > 1000) m = 1000;
      else m = (int)combi;

      /* シャッフルして文字列生成 */
      set<string> cand;
      cand.insert(str);

      rep(ij, m) {
        shuffle(str.begin(), str.end(), engine);
        cand.insert(str);
      }

      /*  コスト計算 */
      int min_cost = INF;
      for (auto v : cand) {
        int nowx = sx, nowy = sy;
        int now = nowy*h + nowx;
        int c = 0;
        rep(j, v.size()) {
          if (v[j] == 'L') {
            c += cost[now][now-1];
            now--;
          }
          else if (v[j] == 'R') {
            c += cost[now][now+1];
            now++;
          }
          if (v[j] == 'U') {
            c += cost[now][now-h];
            now -= h;
          }
          if (v[j] == 'D') {
            c += cost[now][now+h];
            now += h;
          }
        }
        if (min_cost > c) {
          min_cost = c;
          ans = v;
        }
      }
    } else {
      ans = str;
    }

    cout << ans << endl;
    cin >> b;

    /* コストを再計算（単純分配） */
    int nowx = sx, nowy = sy;
    int now = nowy*h + nowx;
    int ave = b/(int)ans.size();
    rep(i, (int)ans.size()) {
      if (ans[i] == 'L') {
        cost[now][now-1] = ave;
        now--;
      }
      else if (ans[i] == 'R') {
        cost[now][now+1] = ave;
        now++;
      }
      else if (ans[i] == 'U') {
        cost[now][now-h] = ave;
        now -= h;
      }
      else if (ans[i] == 'D') {
        cost[now][now+h] = ave;
        now += h;
      }
    }
  }
  return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define rev(a) a.rbegin(),a.rend()
#define all(a) a.begin(),a.end()
#define setbits(x) (__builtin_popcount(x))
#define pi pair<int,int>
#define fill(s,x,n) vector<s> x(n); rep(i,0,n) cin>>x[i];
#define precise(a,k) cout<<fixed<<setprecision(k)<<a;
#define minpq(type) priority_queue<type,vector<type>,greater<type>>
#define debug(...) cerr<<"{ "<<#__VA_ARGS__<<" = "<<(__VA_ARGS__)<<" }"<<endl;
#define debugp(...) cerr<<"{ "<<#__VA_ARGS__<<" = "<<"("<<(__VA_ARGS__).ff<<","<<(__VA_ARGS__).ss<<")"<<" }"<<endl;
#define debugv(...) cerr<<"{ "; for(int i=0; i<size(__VA_ARGS__); i++) cerr<<#__VA_ARGS__<<"["<<i<<"]"<<" = "<<(__VA_ARGS__)[i]<<" ; "; cerr<<"}"<<endl;
#define debugpv(...) cerr<<"{ "; for(int i=0; i<size(__VA_ARGS__); i++) cerr<<#__VA_ARGS__<<"["<<i<<"]"<<" = "<<"("<<(__VA_ARGS__)[i].ff<<","<<(__VA_ARGS__)[i].ss<<")"<<" ; "; cerr<<"}"<<endl;
#define mod 998244353
#define inf 1000000007
#define inf64 1000000000000000005
#define PI 3.141592653589793

void solve(){
    int n,m;
    cin>>n>>m;
    vector<array<int,2>> adj[n+1];
    vector<array<int,2>> rev[n+1];
    rep(i,0,m){
        int u,v,c;
        cin>>u>>v>>c;
        adj[u].pb({v,c});
        rev[v].pb({u,c});
    }
    rep(i,1,n+1){
        set<pi> s;
        vector<int> d(n+1,inf);
        d[i]=0;
        s.insert({0,i});
        while(!s.empty()){
            int v = s.begin()->ss;
            s.erase(s.begin());
            for(auto pp: adj[v]){
                if(d[pp[0]]>d[v]+pp[1]){
                    s.erase({d[pp[0]],pp[0]});
                    d[pp[0]] = d[v]+pp[1];
                    s.insert({d[pp[0]],pp[0]});
                }
            }
        }
        int ans = inf;
        for(auto pp: rev[i]){
            if(d[pp[0]]!=inf){
                ans = min(ans,d[pp[0]]+pp[1]);
            }
        }
        if(ans==inf) cout<<-1<<endl;
        else cout<<ans<<endl;
    }

}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    */
    int test;
    //cin>>test;
    test=1;
   // int cse=1;
    while(test--){
       //  cout<<"Case #"<<cse<<": ";//<<endl;
         solve();
         //cout<<endl;
         //cse++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

#include <bits/stdc++.h>

#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(), (V).end()
#define endl "\n"
#define pb push_back
#define mp make_pair

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;

int main(){

    int n;
    cin >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];

    ll diff = 0;
    bool able = true;

    rep(i, n){
        ll tmp = p[i] - (i + 1);
        if(tmp == 0){
            able = false;
            break;
        }
        diff += tmp;
        if(i != n - 1){
            if(diff == 0 || abs(diff) > n - 1){
                able = false;
                break;
            }
        }
    }

    if(!able){
        cout << -1 << endl;
        return 0;
    }

    vector<pair<ll, int>> v(n);

    rep(i, n){
        v[i] = mp(p[i], i + 1);
    }

    sort(ALL(v));
    vector<int> checked(n + 1, 0);
    vector<int> ans;

    ll k = 1;
    while(k <= n - 1){
        //auto itr = lower_bound(ALL(v), mp(k, 0));
        // pの中でkがあるindex
        int kidx = v[k - 1].second;
        for(int i = kidx - 1; i >= k; i--){
            if(checked[i] == 1){
                cout << -1 << endl;
                return 0;
            }
            checked[i] = 1;
            ans.pb(i);
        }
        k = kidx;
    }

    rep(i, n - 1){
        printf("%d\n", ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define ld long double
#define ALL(a) (a).begin(), (a).end()
#define Mod 1000000007

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

  ll ans;
  cin >> ans;
  vector<vector<ll>> a(2, vector<ll>(n));
  a[0][0] = ans;

  ll x=1, y=0, z;
  for(int i=1; i < n; i++){
    ll b;
    cin >> b;
    b %= Mod;
    a[0][i] += a[0][i-1] % Mod + (x*b) % Mod + a[1][i-1] % Mod + (y*b) % Mod;
    a[1][i] += a[0][i-1] % Mod - (x*b) % Mod;
    z = (x+y) % Mod;
    y = x % Mod;
    x = z;
  }

  ans = (a[0][n-1] + a[1][n-1]) % Mod;
  cout << ans << endl;

  return 0;
}

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

long long dp[100010], a[100010];
ll mod = 1e9+7;

int main()
{
    int n, prvi;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[0]=1;
    dp[1]=2;
    for(int i=2;i<=n-1;i++) dp[i] = (dp[i-1]+dp[i-2])%mod;

    if(n==2){
        cout<<2*a[1]<<endl;
        return 0;
    }

    long long res = (a[1]*dp[n-1])%mod;
    for(int i=2;i<=n;i++){
        long long pos = (dp[ i-2 ]*dp[n-i])%mod, neg;
        if(i==2){
            neg = dp[n-3];
        }
        else if(i==n){
            neg = dp[n-3];
        }
        else{
            neg = (dp[i-3]*dp[n-i-1])%mod;
        }
        res+=(a[i]*(pos-neg+mod)%mod)%mod;
        res%=mod;
    }

    cout<<res<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define ll long long

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count[26]{0};
    for(int i=0;i<n;i++)
      count[s[i]-'a']=1;
    for(int i=0;i<26;i++)
    {
      if(count[i]==0)
      {
        cout<<(char)('a'+i)<<endl;
        return;
      }
    }

    set<string>st;
    for(int i=0;i<n-1;i++)
    {
      string temp="";
      temp+=s[i];
      temp+=s[i+1];
      st.insert(temp);
    }
    for(int i=0;i<26;i++)
    {
      for(int j=0;j<26;j++)
      {
        string temp="";
        temp+=(char)('a'+i);
        temp+=(char)('a'+j);
        if(st.find(temp)==st.end())
        {
          cout<<temp<<endl;
          return;
        }
      }
    }

      set<string>stt;
      for(int i=0;i<n-2;i++)
      {
        string temp="";
        temp+=s[i];
        temp+=s[i+1];
        temp+=s[i+2];
        stt.insert(temp);
      }

      for(int i=0;i<26;i++)
      {
        for(int j=0;j<26;j++)
        {
          {
              string temp="a";
              temp+=(char)('a'+i);
              temp+=(char)('a'+j);
              if(stt.find(temp)==stt.end())
              {
                cout<<temp<<endl;
                return;
              }
          }
        }
      }
}
int32_t main() {
  IOS
    double a,b;
    cin>>a>>b;
    cout<<(a/100*b);
    //cout<<as;

}

#include <bits/stdc++.h> //yaad rkhne layak baatein
#include <bits/stdc++.h> // bool found = false use it to find some number after the given number with some cond.
                         // while (!found)
#include <iostream>      // freq.table-> int freq[26] = {0}; for (ll i = 0; i < s1.length(); i++) freq[s1[i] - 'A']++;
#define ll long long     //[s[i] - 'a'] ->this convers char to corr.int eg. 'c' to 3.
// if(a<=min1){
//         min2 = min1;
//         index2 = index1;
//         min1 = a;
//         index1 = i;         to find index of 2nd smallest element
//       }
//       else if(a<=min2){
//         min2 = a;
//         index2 = i;
//       }
#define INF 2000000000
#define pb push_back
using namespace std;
//cout<<fixed<<setprecision(12)<<ans<<endl;
const ll M = 1e9 + 7;
#define loop0(i, n) for (ll i = 0; i < n; i++)            //  str.insert(0, 5, '1'); => it will insert 1 five times in start of str.
#define loop00(i, n) for (ll i = 0; i <= n; i++)
#define loop1(i, n) for (ll i = 1; i < n; i++)
#define loop11(i, n) for (ll i = 1; i <= n; i++)
#define loopab(i, a, b) for (ll i = a; i <= b; i++)

void flashSpeed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}
long long mod(long long x)
{
    return ((x % M + M) % M);
}
long long add(long long a, long long b)      //to find max. multiple of x less than n=>(n/x)*x
{
    return mod(mod(a) + mod(b));
}
long long mul(long long a, long long b)
{
    return mod(mod(a) * mod(b));
}
ll modPow(ll a, ll b)
{
    if (b == 0)
        return 1LL;
    if (b == 1)
        return a % M;
    ll res = 1;
    while (b)
    {
        if (b % 2 == 1)
            res = mul(res, a);
        a = mul(a, a);
        b = b / 2;
    }
    return res;
}
const int N = 2e5 + 2;
int fact[N];

void precalc()
{
    fact[0] = 1;
    for (int i = 1; i < N; i++)
    {
        fact[i] = mul(fact[i - 1], i);
    }
}

ll inv(ll x)
{
    return modPow(x, M - 2);
}

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

ll nCr(ll n, ll r)
{
    return divide(fact[n], mul(fact[r], fact[n - r]));
}
double Round(double var)
{
    float value = (int)(var * 100 + .5);
    return (float)value / 100;
}
ll ceils(ll x, ll y) {
	return x / y + ((x % y) != 0);
}
ll Gcd(ll a, ll b)
{
    if (b > a)
    {
        return Gcd(b, a);
    }
    if (b == 0)
        return a;
    else
        return Gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / Gcd(a, b) * b;
}

bool isPal(string s)
{
    for (int i = 0; i < (int)s.size() / 2; i++)
    {
        if (s[i] != s[(int)s.size() - 1 - i])
            return false;
    }
    return true;
}

ll Sumdigits(ll a)
{                                 //two find no.of power of 2 in a number==>while(n%2==0){cnt++;n/=2}
    ll total = 0;
    while (a)
    {
        total += a % 10;
        a /= 10;
    }
    return total;
}
bool isPerfectSquare(int n)
{
    for (int i = 1; i * i <= n; i++) {
        if ((n % i == 0) && (n / i == i)) {
            return true;
        }
    }
    return false;
}
bool isPowerOfTwo(int n){
   return (ceil(log2(n)) == floor(log2(n)));
}
void lexosmallest(string s,string c){
    string t1 = s;
    sort(t1.begin(), t1.end());
    int index = -1;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t1[i]) {
            index = i;
            break;
        }
    }
    int j;
    for (int i = 0; i < s.length(); i++) {        //khela yha pe hua hai..loop poora chala hai
        if (s[i] == t1[index])
            j = i;
    }
    swap(s[index], s[j]);
}
void solution()
{
    int n;
    cin>>n;
    int sum=0;
    int arr[n];
    loop0(i,n){
        cin>>arr[i];
        if(arr[i]>=10){
            arr[i]=arr[i]-10;
            sum+=arr[i];
        }

    }
    cout<<sum<<endl;

}

int main()
{
    flashSpeed();
    int t=1;
   // cin>>t;
    while(t--)
    {
    solution();
}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

int n;
cin >> n;
int ans = (n - 1);
cout << ans;

 return 0;

}

#include <iostream>
using namespace std;

int main() {
	int n,count=0;
	cin>>n;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(i+j==n) count++;
        }
    }
    cout<<count;
	return 0;
}


// <-- Coded by Pasindu_Piumal -->
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

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

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b) for(int i=(a);i>=(b);i--)
#define FORZ(i,a) for(int i=0;i<(a);i++)
#define FORZi(i,a) for(int i=(a)-1;i>=0;i--)
#define trav(a,x) for (auto& a: x)
#define what_is(x) cout << #x << " is " << x << "\n"

#define printl(a) cout << a << "\n"
#define prints(a) cout << a << " "
#define printall(x) FORZ(i,sz(x))prints(x[i])
#define nextl cout << "\n"

ll mxN=1e5+1;

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

    int n;
    cin >> n;
    if(n%100==0) {
    	cout << "100\n";
    } else {
    	cout << 100-(n%100) << "\n";
    }

    return 0;
}

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 998244353
using namespace std;

bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

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

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

    return true;
}
ll power(ll x,ll n)
{ll x1=0;
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
       //  if(result>=1000000001) return 0;
        x=(x*x);
      //   if(x>=1000000001) return 0;
        n=n/2;
    }
    return result;
}
int main(){
   IOS;
ll t;t=1;//cin>>t;

while(t--){
ll n;cin>>n;
cout<<100-n%100<<"\n";
}

return 0;
}


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

using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#define sz(x) (int)(x).size()

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

#ifdef XVENOM
  #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: " << dbg_str(__VA_ARGS__)
#else
  #define dbg(...) ;
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const char* e) { return "\"" + string(e) + "\""; }
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
  string s = "[ "; for (auto& x : e) s += to_string(x) + " "; return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
  return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
string dbg_str () { return " \n"; }
template <typename U, typename... V> string dbg_str (U u, V... v) {
  return " " + to_string(u) + dbg_str(v...);
}
/* *** */
const int N = 55;
const ll Mod = 998244353;
int n, k, a[N][N];
int s[N], p[N];
ll fac[N];

ll mul (ll u, ll v) { return ((u % Mod) * (v % Mod)) % Mod; }
ll add (ll u, ll v) { return (u + v) % Mod; }

void init() {
  for (int i = 0; i < n; i++) {
    s[i] = 1;
    p[i] = i;
  }
}

int leader (int x) { return p[x] == x ? x : (p[x] = leader(p[x])); }
void combine (int u, int v) {
  u = leader(u); v = leader(v);
  if (u == v) return;
  if (s[u] > s[v]) swap(u, v);
  p[u] = v;
  s[v] += s[u];
}

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

  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  auto can_swap_cols = [&] (int u, int v) {
    for (int i = 0; i < n; i++) {
      if (a[i][u] + a[i][v] > k) return false;
    }
    return true;
  };

  auto can_swap_rows = [&] (int u, int v) {
    for (int i = 0; i < n; i++) {
      if (a[u][i] + a[v][i] > k) return false;
    }
    return true;
  };

  ll ans = 1;
  init();
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (can_swap_rows(i, j)) combine(i, j);
    }
  }

  for (int i = 0; i < n; i++) if (leader(i) == i) {
    ans = mul(ans, fac[s[i]]);
  }

  init();
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (can_swap_cols(i, j)) combine(i, j);
    }
  }

  for (int i = 0; i < n; i++) if (leader(i) == i) {
    ans = mul(ans, fac[s[i]]);
  }

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

#include <bits/stdc++.h>
using namespace std;
#define boostIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define ppcll(x) __builtin_popcountll(x)
void amn(int &x, int y) { x = min(x, y); }
void amx(int &x, int y) { x = max(x, y); }

#define mod 1000000007
const long long INF = 1e18;
// const int N = 5e5 + 5;

signed main() {
	boostIO;
	int n, m;
	cin >> n >> m;
	int a[n], b[m];
	set<int> sa, sb;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sa.insert(a[i]);
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		sb.insert(b[i]);
	}
	set<int> ans;
	for (int i = 0; i < n; i++) {
		if (sb.count(a[i]) == 0) {
			ans.insert(a[i]);
		}
	}
	for (int i = 0; i < m; i++) {
		if (sa.count(b[i]) == 0) {
			ans.insert(b[i]);
		}
	}
	for (int i : ans) {
		cout << i << " ";
	} cout << endl;
	return 0;
}
// Play Hard Kiddo...


#include<bits/stdc++.h>
using namespace std;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int int64_t
void _read();
int mod;
inline int inv(int a) {
  	a %= mod;
  	if (a < 0) a += mod;
  	int b = mod, u = 0, v = 1;
  	while (a) {
  		int t = b / a;
  		b -= t * a; swap(a, b);
  		u -= t * v; swap(u, v);
  	}
  	assert(b == 1);
  	if (u < 0) u += mod;
  	return u;
}
void test() {
	int n,s,k;
	cin >> n >> s >> k;
	mod = n;
	// kx == s;
	int d = __gcd(k,n);
	if(s % d) {
		cout << -1 << '\n';
		return;
	}
	k /= d;
	s /= d;
	n /= d;
	mod = n;
	s %= mod;
	k %= mod;
	int y = inv(k);
	int ans = (s * y) % mod;
	cout << mod - ans << '\n';
}
main () { _read();

	int tc;
	cin >> tc;
	while(tc--) test();
	return 0;
};

void _read() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	#endif
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
#define fo(i,a,b) for(int i=a;i<b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define sc(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define prs(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)
using namespace std;

ll GCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1LL;
		y = 0LL;
		return a;
	}
	ll x1, y1;
	ll d = GCD(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * 1LL * (a / b);
	return d;
}
void solve()
{
	ll n, s, k;
	sl(n), sl(s), sl(k);
	ll x, y;
	ll gc = __gcd(n, k);
	if (s % gc) {
		pl(-1LL);
	}
	else {
		// y->loops x->moves x*k+s=y*n => (x*k-y*n=-s)
		n /= gc, s /= gc, k /= gc;
		gc = GCD(k, n, x, y);
		ll mod_inv = (x % n + n) % n;
		ll ans = ((-s * mod_inv) % n + n) % n;
		pl(ans);
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	scanf("%d", &t);
	while (t--) {
		solve();
	}

}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{   if(k>n)
        return 0;
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    t=1;
    //cin>>t;
    while(t--)
    {
        lld n;
        cin>>n;
        lld ctr=1;
        lld ptr=0;
        lld ans=LLONG_MAX;
        while(ctr<=n)
        {
            ans=min(ans,n/ctr+ptr+n-((n/ctr)*ctr));
            ptr++;
            ctr=ctr*2;
        }
        cout<<ans<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
// 型
#define ll int64_t                  // ll -> int64_t
using graph = vector<vector<int>>;  // グラフ型
// for文
#define lp(i,n) for(int i=0;i<n;i++)      // 変数 i をおいて n 回繰り返し
#define lp_(i,n) for(int i=0;i<=n;i++)    // 条件に＝つき
#define lpp(i,n,m) for(int i=n;i<m;i++)   // 開始と終了を指定して繰り返し
#define lpp_(i,n,m) for(int i=n;i<=m;i++) // 開始と終了を指定，条件に＝つき
// vector定義
#define _GLIBCXX_DEBUG
#define vec(v,n) vector<int> v(n)       // int
#define vec_(v,n,m) vector<int> v(n,m)  // int 初期条件あり
#define vec64(v,n) vector<ll> v(n)      // int64_t
#define vec64_(v,n,m) vector<ll> v(n,m) // int64_t 初期条件あり
#define vecc(v,n) vector<char> v(n)     // char
#define vecs(v,n) vector<string> v(n)   // string
#define vece(v) vector<int> v;          // int 空
#define vecec(v) vector<char> v;        // char 空
#define vec2i(v,h,w) vector<vector<int>> v(h,vector<int>(w))    // 二次元配列 int
#define vec2c(v,h,w) vector<vector<char>> v(h,vector<char>(w))  // 二次元配列 char
// vector,string操作
#define all(v) v.begin(),v.end()
#define back(v) v.back()                         // 最後の要素
#define sum(v) accumulate(all(v),0)              // 総和
#define sort(v) sort(all(v))                     // ソート
#define reverse(v) reverse(all(v))               // 反転
#define lower(v,x) lower_bound(all(v),x)         // x<=a[i]となる最小のi / a[i]<xとなるiの個数
#define cou(v,n) count(all(v),n)                 // n の出現回数を数える
#define pb(v,n) v.push_back(n)                   // 最後尾に n を追加
#define ins(v,i,n) v.insert(v.begin()+i,n)       // 場所を指定してv[i]に n を追加
#define del(v) v.pop_back()                      // 最後尾を削除
#define del0(v) v.erase(v.begin())               // 最初の要素v[0]を削除
#define del_(v,i) v.erase(v.begin()+i)           // 場所を指定してv[i]を削除
#define del__(v,i,j) v.erase(v.begin()+i,v.begin()+j+1)  // 範囲を指定してv[i]~v[j]を削除
#define sub(s,i,j) s.substr(i,j-i+1)             // 範囲を指定してs[i]~s[j]を取得【stringのみ】
// others
const ll MOD=1000000007;
const ll INF=(1LL<<60);
#define under(n) cout<<fixed<<setprecision(n) // 小数点以下の桁数を指定
#define cout(n) cout<<n<<endl

int main()
{
  ll n,ans=INF;
  cin>>n;
  ll t=1;
  lp(i,61)
  {
    ll a=n/t;
    ll c=n%t;
    t*=2;
    ans=min(ans,a+i+c);
  }
  cout(ans);
}


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

int main() {
    ll N;
    cin >> N;
    N *= 2;

    int ans = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            if ((i + N / i) % 2 == 1) {
                ans += 2;
                if (i == N / i) ans--;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*............................................................................*/
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/* find_by_order(x) give iterator of the index x
   order_by_key(x) give the position where x will be placed*/
#define int long long
#define lop(i,a,b,c) for (int i=a;i<b;i+=c)
#define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c)
#define prii pair <int,int>
#define PB push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define vvii vector < vector < int > >
#define vii vector <int>
#define count_1(x) __builtin_popcount(x)
#define cn(a) scanf("%lld",&a);
#define cn_vl(arr,n) lop(i,0,n,1){scanf("%lld",arr+i);}
#define shw_vl(arr,n) lop(i,0,n,1){printf("%lld ",arr[i]);}printf("\n");
#define shw(CON) cout << &("NO\0YES"[3 * CON]) << '\n';
const int MAX=2e5+10;
/*......................................................................*/
void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
struct dsu
{
	int parent[MAX];int size[MAX];
	void init(){
		lop (i,1,MAX,1){parent[i]=i;size[i]=1;}
	}
	int trace(int a){
		return (a==parent[a])?a:parent[a]=trace(parent[a]);
	}
	bool connect(int a,int b){
		if ((a=trace(a))==(b=trace(b)))return false;
		if (size[b]>size[a])swap(a,b);
		parent[b]=a;size[a]+=size[b];
		return true;
	}
}ori;
vii adj[MAX];
typedef long double ld;
void solve(){
	int n,m;cn(n)cn(m)
	ld a=(ld)m/(ld)100;
	printf("%0.6Lf",a*n);
}
int32_t main(){
	int t;t=1;
	// cin>>t;
	while (t--){
		auto t_1=chrono::high_resolution_clock::now();
		solve();
		auto t_2=chrono::high_resolution_clock::now();
		// cout <<". Elapsed (ms): " << chrono::duration_cast<chrono::milliseconds>(t_2 - t_1).count() << endl;
	}
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  priority_queue<long long> max;
  vector<long long> sum(N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    max.push(a);
    if (i == 0) {
      sum.at(0) = a;
    }
    else {
      sum.at(i) = sum.at(i - 1) + a;
    }
    ans += sum.at(i);
    cout << ans + max.top() * (i + 1) << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(lint i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
///#pragma GCC optimize ("-O3")
ll input(){
    ll  n;
    cin >> n;
    return n;
}///input関数
ll combination(ll n,ll r){
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n-1,r-1) + combination(n-1,r));

}///nCr
ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}///階乗

int main(){
    ll n = input();
    vector<ll>a;
    ll a_max = 0;
    ll ans = 0;
    ll total = 0;
    ll pir = 0;
    rep(i,0,n){
        a.push_back(input());
        pir += total;
        total += a.at(i);
        a_max = max(a_max,a.at(i));
        ans = pir + total + a_max*(i+1);
        cout << ans << endl;
    }
}


/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
    Date:13/06/2020
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define ff first
#define clr(a,x) memset(a,x,sizeof(a))
#define ss string
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define ipair pair<int,int>
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)
ll mod=1000000007;
// int mod = 998244353;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int inf = 1e18;
bool test = 0;
const int N = 1e5+5;

int n,x;

void solve()
{
    cin >>n;
    set<int>st;
    for(int i = 1; i <= n; ++i)
    {
        cin >>x;
        st.insert(x);
    }

    while(st.size() > 1){
        int mnx = *st.begin();
        int mx = *st.rbegin();
        st.erase(mx);
        st.insert(mx-mnx);
    }
    cout<<*st.begin()<<"\n";

}

clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // precompute();
    if(test)
        cin>>t;
    while(t--)
    {
        solve();
    }
    DBG(getCurrentTime());
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int n;
int arr[100010];

bool judge(int k) {
    for(int i=1; i<=n; i++)
        if(arr[i] % k != 0)
            return false;
    return true;
}

int main() {
    int ans = 1;
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> arr[i];
    sort(arr+1, arr+n+1);
    for(int i=2; i<=arr[1]; i++)
        if(judge(i))
            ans = i;
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back

using namespace std;
const int N = 1e5+5;
const ll mod = 1e9+7;
ll n, m, t, k, ans, tong, a[N], b[N];

void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    vector<ll> kq;
    k = n / 2;
    for(int i = 1; i < (1<<k); i ++)
    {
        ll total = 0;
        for(int j = 0; j < k; j ++)
        {
            if((i>>j)&1)total += a[j+1];
        }
        if(total <= m)ans = max(ans, total);
        kq.pb(total);
    }
    sort(kq.begin(), kq.end());
    for(int i = 1; i < (1<<(n-k)); i ++)
    {
        ll total = 0;
        for(int j = 0; j < n-k; j ++)
        {
            if((i>>j)&1)total += a[j+k+1];
        }
        t = upper_bound(kq.begin(), kq.end(), m-total)-kq.begin();
        if(t != 0)
        {
            t = kq[t-1];
            ans = max(ans, t+total);
        }
        if(total <= m)ans = max(ans, total);
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)sol();
}
/*
2
10
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10

3
1 2
3 2
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

vl v;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll t, a[50];
  cin>>n>>t;
  REP(i, n){
    cin>>a[i];
  }
  if(n==1){
    cout<<(a[0]<=t ? a[0] : 0)<<'\n';
    return 0;
  }
  int m=n/2;
  int vsize=0;
  REP(i, (1<<(n-m))){
    ll tmp=0;
    REP(j, n-m){
      if(i>>j&1){
        tmp+=a[m+j];
      }
    }
    v.push_back(tmp);
  }
  sort(ALL(v));
  ll ans=0;
  REP(i, (1<<m)){
    ll tmp=0;
    REP(j, m){
      if(i>>j&1){
        tmp+=a[j];
      }
    }
    if(tmp>t){
      continue;
    }
    auto itr=upper_bound(ALL(v), t-tmp);
    CHMAX(ans, *(itr-1)+tmp);
  }
  cout<<ans<<'\n';
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define mod 1000000007

ll fa[200005];
ll p[200005];

ll gf(ll v){
	if(fa[v]==v){
		return v;
	}
	fa[v]=gf(fa[v]);
	return fa[v];
}
void merge(ll i,ll j){
	i=gf(i);
	j=gf(j);
	if(i!=j){
		fa[j]=i;
	}
}

int main()
{
	ll t,n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&p[i]);
	}
	for(i=1;i<=200005;i++)
	{
		fa[i]=i;
	}
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		j=n+1-i;
		if(gf(p[i])==gf(p[j])) continue;
		ans++;
		merge(p[i],p[j]);
//		for(ll ii=1;ii<=n;ii++) cout<<fa[ii]<<" ";cout<<endl;
	}
	cout<<ans;

	return 0;
}

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

template<typename T>
void view_1d(vector<T> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        cout << V[i];
        if (i == V.size() - 1) {
            cout << endl;
        } else {
            cout << sep;
        }
    }
}

template<typename T>
void view_2d(vector<vector<T>> V, string sep) {
    for (ll i=0; i<V.size(); i++) {
        for (ll j=0; j<V[i].size(); j++) {
            cout << V[i][j];
            if (j == V[i].size() - 1) {
                cout << endl;
            } else {
                cout << sep;
            }
        }
    }
}

//==============================//

vector<vector<int>> graph;
vector<int> seen;

void dfs(int v, int tmp) {
    seen[v] = tmp;
    for (auto next_v : graph[v]) {
        if (seen[next_v] != -1) continue;
        dfs(next_v, tmp);
    }
}

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

    int maxA = *max_element(A.begin(), A.end());
    graph.resize(maxA);

    for (int i=0; i<N/2; i++) {
        if (A[i] != A[N-1-i]) {
            graph[A[i]-1].push_back(A[N-1-i]-1);
            graph[A[N-1-i]-1].push_back(A[i]-1);
        }
    }

    seen.assign(maxA, -1);
    int cnt = 0;

    for (int v=0; v<maxA; v++){
        if (seen[v] != -1 || graph[v].empty()) continue;
        dfs(v, cnt);
        cnt++;
    }

    int ans = 0;
    if (cnt == 0) {
        ans = 0;
    } else {
        unordered_map<int,int> mp;
        for (int j=0; j<maxA; j++) {
            if (seen[j] != -1) mp[seen[j]]++;
        }
        for (auto x : mp) {
            ans += x.second - 1;
        }
    }

    cout << ans << endl;
}


#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
	int t, n;
	t = 1;
	while(t--) {
		string a, b;
		cin >> a >> b;
		int suma = 0, sumb = 0;
		for(int i = 0; i < a.length(); i++)
			suma += (a[i] - '0');
		for(int i = 0; i < b.length(); i++)
			sumb += (b[i] - '0');
		cout << max(suma, sumb) << endl;
	}
	return 0;
}

//   MUJHSE BILKUL BHI NAHI HO RHA.....still i am TRYING
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b,p=0,q=0;
    cin>>a>>b;
    while(a>0)
    {
      int d=a%10;
      p+=d;
      a/=10;

    }
    while(b>0)
    {
      int d=b%10;
      q+=d;
      b/=10;

    }
    cout<<max(p,q)<<endl;
}
return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
#define E (n+m)
using namespace std;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
	int n=read();
	for(ri int i=0;i<n;i++)
	{
		printf("%lld %lld\n",(i*2+1)%n+1,(i*2+2)%n+1);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

string s;

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

	cin >> s;
	for(ll i = 0; i < s.size(); i++){
		if(s[i] == '.') break;
		cout << s[i];
	}
	cout << '\n';
}