#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  st s;
  cin >> s;
  if(s.size()==3){
    swap(s[0],s[2]);
  }
  cout << s << endl;
}

#include <bits/stdc++.h>

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

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

using namespace std;

using ll = long long;

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

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

void solve(std::string S) {
  if (S.size() == 2) {
    cout << S << endl;
  } else {
    cout << string(S.rbegin(), S.rend()) << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int cnt = 0;
  while (1) {
    rep(i, n) {
      if (a[i] % 2 != 0) {
        cout << cnt << endl;
        return 0;
      }
      a[i] *= 0.5;
    }
    cnt++;
  }

  return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int num_2(int a) {
	int ret=0;
	while (a % 2 == 0) {
		ret++;
		a /= 2;
	}
	return ret;
}
int even(vector<vector<int>> a) {
	int ret = a.at(1).at(0);
	for (int i = 0; i < a.at(0).size(); i++) {
			if (ret > a.at(1).at(i))ret = a.at(1).at(i);
	}
	return ret;
}
int main() {
	int n;
	cin >> n;
	vector<vector<int>> a(2,vector<int> (n));
	for (int i = 0; i < n; i++) {
		cin >> a.at(0).at(i);
	}
	for (int i = 0; i < n; i++) {
		a.at(1).at(i) = num_2(a.at(0).at(i));
	}
	cout << even(a) << endl;

}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2003,INF=10000;

int main(){

    int N;cin>>N;
    vector<pair<double,double>> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].first>>S[i].second;
    }

    for(int i=0;i<N;i++){
        double a1=0,a2=M_PI,b1=M_PI,b2=M_PI*2.0;
        double ans=0.0;
        for(int j=0;j<N;j++){
            if(i==j) continue;
            if(S[i].first==S[j].first){
                if(S[i].second<S[j].second){
                    a1=0.0;
                    a2=0.0;
                }else{
                    b1=M_PI*2.0;
                    b2=M_PI*2.0;
                }
            }else if(S[i].first>S[j].first){
                if(S[i].second==S[j].second){
                    a2=min(a2,M_PI/2.0);
                    b1=max(b1,M_PI*1.5);
                }else if(S[i].second>S[j].second){
                    double x=S[i].first-S[j].first,y=S[i].second-S[j].second;
                    double a=-x/y;
                    a2=min(a2,atan(a)+M_PI);
                    b1=max(b1,atan(a)+M_PI*2.0);
                }else if(S[i].second<S[j].second){
                    double x=S[i].first-S[j].first,y=S[i].second-S[j].second;
                    double a=-x/y;
                    a2=min(a2,atan(a));
                    b1=max(b1,atan(a)+M_PI);
                }
            }else if(S[i].first<S[j].first){
                if(S[i].second==S[j].second){
                    a1=max(a1,M_PI/2.0);
                    b2=min(b2,M_PI*1.5);
                }else if(S[i].second>S[j].second){
                    double x=S[i].first-S[j].first,y=S[i].second-S[j].second;
                    double a=-x/y;
                    a1=max(a1,atan(a));
                    b2=min(b2,atan(a)+M_PI);
                }else if(S[i].second<S[j].second){
                    double x=S[i].first-S[j].first,y=S[i].second-S[j].second;
                    double a=-x/y;
                    a1=max(a1,atan(a)+M_PI);
                    b2=min(b2,atan(a)+M_PI*2.0);
                }
            }
        }
        if(a1<a2) ans+=(a2-a1)/(M_PI*2.0);
        if(b1<b2) ans+=(b2-b1)/(M_PI*2.0);
        cout<<setprecision(15)<<ans<<endl;
    }
}

#include<bits/stdc++.h>
#define mems(a,x) memset(a,x,sizeof(a))
#define first fi
#define second se
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=105;
const double eps=1e-8,pi=3.1415926535898;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
ll qpow(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
ll qpow(ll a,ll n,ll mod){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b,ll mod){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
struct vec
{
    double x,y;
    int id;
    vec(double x=0,double y=0):x(x),y(y){}
    vec operator+(const vec&o)const{ return vec(x+o.x,y+o.y);}
    vec operator-(const vec&o)const{ return vec(x-o.x,y-o.y);}
    double operator*(const vec&o)const{ return x*o.x+y*o.y;}
    double operator^(const vec&o)const{ return x*o.y-y*o.x;}
    vec operator/(const double&o)const{ return vec(x/o,y/o);}
    vec operator*(const double&o)const{ return vec(x*o,y*o);}
    void sc(){scanf("%lf%lf",&x,&y);}
    double len(){return sqrt(x*x+y*y);}
}a[N],s[N];
int n,top;
bool cmp(vec x,vec y)
{
    double k1=atan2(x.y-a[1].y,x.x-a[1].x),k2=atan2(y.y-a[1].y,y.x-a[1].x);
    if(fabs(k1-k2)<eps) return x.x<y.x;
    return k1<k2;
}
double ans[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) a[i].sc(),a[i].id=i;
    for(int i=1;i<=n;i++)
        if(a[i].y<a[1].y||a[i].y==a[1].y&&a[i].x<a[1].x)
        swap(a[i],a[1]);
    sort(a+2,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        while(top>=2&&((s[top-1]-a[i])^(s[top]-a[i]))<=0) top--;
        s[++top]=a[i];
    }
    if(top==1) ans[s[1].id]=1;
    else if(top==2) ans[s[1].id]=ans[s[2].id]=0.5;
    else
        for(int i=1;i<=top;i++)
        {
            vec l,r;
            if(i==1) l=s[top];
            else l=s[i-1];
            if(i==top) r=s[1];
            else r=s[i+1];
            double res=(r-s[i])*(l-s[i]);
            res/=(r-s[i]).len()*(l-s[i]).len();
            res=pi-acos(res);
            res/=2*pi;
            ans[s[i].id]=res;
        }
    for(int i=1;i<=n;i++)
        printf("%.10f\n",ans[i]);
}


#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
	vector<int> v;
	int m, nmin, nmax, gap = -1, gapnum;
	for (;;) {
		cin >> m >> nmin >> nmax;
		if (m == 0 && nmin == 0 && nmax == 0) break;
		v.resize(m);
		for (int i = 0; i < m; i++) cin >> v[i];

		for (int i = nmin-1; i < nmax; i++) {
			if (gap == -1) {
				gap = v[i] - v[i + 1];
				gapnum = i+1;
			}
			else {
				if (gap <= v[i] - v[i + 1]) {
					gap = v[i] - v[i + 1];
					gapnum = i+1;
				}
			}
		}
		cout << gapnum << endl;
		gap = -1;
	}
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for(int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  int ans = 200000;
  for(int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    if(a.at(x - 1) + b.at(y - 1) - c < ans) {
      ans = a.at(x - 1) + b.at(y - 1) - c;
    }
    if(i == M - 1) {
      sort(a.begin(), a.end());
      sort(b.begin(), b.end());
      if(a.at(0) + b.at(0) < ans) {
        ans = a.at(0) + b.at(0);
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
    ll l,r;
    scanf(" %lld %lld",&l,&r);
    vector<int> modulos(2019,0);
    for(int i = l, j = 0; i <= r && j <= 10000;++i,++j)
        ++modulos[i%(2019ll)];
    int ans = 10000;
    for(int i = 0; i < modulos.size();++i){
        for(int j = i; j < modulos.size();++j){
            if(i == j && modulos[i] > 1)
                ans = min(ans,(i*i)%2019);
            else if(i != j && modulos[i] && modulos[j])
                ans = min(ans,(i*j)%2019);
        }
    }
    printf("%d\n",ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	int mn = 2019;
	if(b-a+1>=2019) cout<<0;
	else{
		for(int i=a; i<=b; i++){
			for(int j=i+1; j<=b; j++){
				mn = min(mn,( (i%2019)*(j%2019) )%2019);
			}
		}
		cout<<mn;
	}
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int par[213456];//親
int depth[213456];//木の深さ
//n要素で初期化
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
edge es[345678];
int kruskal(int V, int E) { //頂点数と辺数
	sort(es, es + E, comp); //edge.costが小さい順にソート
	init(V); //Union-Findの初期化
	int res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}
signed main() {
	int n; cin >> n;
	vector<vector<int>>aa(n, vector<int>(3));
	vector<vector<int>>bb(n, vector<int>(3));
	for (int h = 0; h < n; h++) {
		cin >> aa[h][0] >> aa[h][1]; aa[h][2] = h;
		bb[h][0] = aa[h][1]; bb[h][1] = aa[h][0]; bb[h][2] = h;
	}
	sort(aa.begin(), aa.end());
	int x = 0;
	for (int h = 1; h < n; h++) {
		es[x] = { aa[h - 1][2], aa[h][2], min(abs(aa[h - 1][0] - aa[h][0]),abs(aa[h - 1][1] - aa[h][1])) };
		x++;
	}
	sort(bb.begin(), bb.end());
	for (int h = 1; h < n; h++) {
		es[x] = { bb[h - 1][2], bb[h][2], min(abs(bb[h - 1][0] - bb[h][0]),abs(bb[h - 1][1] - bb[h][1])) };
		x++;
	}
	cout << kruskal(n, x) << endl;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<vector<ll>> citys(n, vector<ll>(2));
	foreach(i, citys){
		foreach(j, i)cin>>j;
	}

	vector<vector<pll>> roads(n);

	rep(i, 2){
		vector<pll> line;
		rep(j, n){
			line.emplace_back(citys[j][i], j);
		}
		sort(all(line));
		rep(j, n-1){
			pll a = line[j];
			pll b = line[j+1];
			roads[a.second].emplace_back(abs(a.first-b.first), b.second);
			roads[b.second].emplace_back(abs(a.first-b.first), a.second);
		}
	}

	vector<bool> used(n, false);
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll ans = 0;
	pq.emplace(0, 0);
	while(pq.size()){
		pll d = pq.top();
		pq.pop();
		if(used[d.second])continue;
		used[d.second] = true;
		ans += d.first;
		foreach(i, roads[d.second]){
			if(used[i.second])continue;
			pq.push(i);
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
  int n, q;
  while(true){
    cin >> n >> q;
    if(n == 0)
      break;

    int m;
    vector< vector<int> > sch(n, vector<int>(101, 0));
    for(int i=0; i<n; i++){
      cin >> m;
      for(int j=0; j<m; j++){
        int temp;
        cin >> temp;
        sch[i][temp] = 1;
      }
    }

    int ans, nmax = 0;
    for(int i=0; i<101; i++){
      int sum = 0;
      for(int j=0; j<n; j++){
        sum += sch[j][i];
          }
      if(sum > nmax){
        ans = i;
        nmax = sum;
      }
    }

    if(nmax < q)
      ans = 0;
    cout << ans << endl;
  }

  return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main() {
  int n,q;
  while( cin >> n >> q, n|q) {
    map<int,int> mp;
    int maxi = -1;
    for(int i=0;i<n;++i) {
      int m;
      cin >> m;
      for(int j=0;j<m;++j) {
	int data;
	cin >> data ;
	++mp[data];
	maxi = max(mp[data],maxi);
      }
    }
    vector<int> vec;
    for(auto v : mp) {
      if( v.second >= q ) {
	if( maxi == v.second ) {
	  vec.push_back(v.first);
	}
      }
    }
    if( vec.size() ) {
      sort(vec.begin(),vec.end());
      cout<< vec[0] << endl;
    }else {
      cout << 0 << endl;
    }
  }
  return 0;
}


//https://atcoder.jp/contests/abc178/tasks/abc178_f
#include <bits/stdc++.h>

using namespace std;

const int MAXN=2e5+4;
long long a[MAXN];
long long b[MAXN];

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

    reverse(b, b+n);

#if 0
    cout<<"\n";
    for (int i=0; i<n; i++) {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
    for (int i=0; i<n; i++) {
        cout<<b[i]<<" ";
    }
    cout<<"\n";
#endif

    //寻找重合的区间
    int c=-1;
    int l=n;
    int r=-1;
#if 1
    for (int i=0; i<n; i++) {
        if (-1==c && a[i]==b[i]) {
            //第一次出现相等
            c=a[i];
            l=i;
            r=i;
        } else if (-1!=c && a[i]==b[i]) {
            //最后一次出现相等
            r=i;
        }
    }
    //cout<<l<<" "<<r<<"\n";
#else
    l=n;
    r=-1;
    for (int i=0; i<n; i++) {
        if (a[i]==b[i]) {
            c=a[i];
            break;
        }
    }
    for (int i=0; i<n; i++) {
        if (c==a[i] && c==b[i]) {
            l=min(l, i);
            r=max(r, i);
        }
    }
    cout<<l<<" "<<r<<"\n";
#endif

    //交换数据
    for (int i=0; i<n; i++) {
        if (c!=a[i] && c!=b[i] && l<=r) {
            swap(b[i], b[l]);
            l++;
        }
    }

    if (l<=r) {
        cout<<"No\n";
    } else {
        cout<<"Yes\n";
        for (int i=0; i<n; i++) {
            cout<<b[i]<<" ";
        }
    }

    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e9;
const int mod = 1e9 + 7;

struct Dice {
    V v;
    Dice() {}
    Dice(V _v) : v(_v) {}
    void rot(char c) {
        int t = v[0];
        switch(c) {
            case 'N':
                v[0] = v[1];
                v[1] = v[5];
                v[5] = v[4];
                v[4] = t;
                break;
            case 'S':
                v[0] = v[4];
                v[4] = v[5];
                v[5] = v[1];
                v[1] = t;
                break;
            case 'W':
                v[0] = v[2];
                v[2] = v[5];
                v[5] = v[3];
                v[3] = t;
                break;
            case 'E':
                v[0] = v[3];
                v[3] = v[5];
                v[5] = v[2];
                v[2] = t;
                break;
        }
    }
};

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

    V v(6);
    rep(i, 6) cin >> v[i];
    Dice d(v);

    string s;
    cin >> s;
    for (const auto& c : s) {
        d.rot(c);
    }

    cout << d.v[0] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){
  if(A[i][j]=='#'){  B[i][j]=1; C.push_back(make_pair(i, j)); }
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
}

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

using namespace std;

void print_vec(vector<vector<int> > a, int H, int W){
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}

int find_max(vector<vector<int> > a,int H, int W){
  int max = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(max < a.at(i).at(j))
        max = a.at(i).at(j);
    }
  }
  return max;
}

int main(int argc, char *argv[])
{
  int H,W,x,y;
  char tmp;
  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,1,0,-1};
  queue<int> queue_x,queue_y;
  cin >> H >> W;
  vector<vector<int> > a(H, vector<int>(W)), visited(H,vector<int>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> tmp;
      if(tmp == '.'){
        a.at(i).at(j) = 0;
        visited.at(i).at(j) = 0;
      }
      else{
        a.at(i).at(j) = 1;
        visited.at(i).at(j) = 1;
        queue_x.push(j);
        queue_y.push(i);
      }
    }
  }
  //print_vec(a,H,W);
  //print_vec(visited,H,W);
  while(!queue_x.empty() && !queue_y.empty()){
    x = queue_x.front();
    y = queue_y.front();
    queue_x.pop();queue_y.pop();
    //cout << "x: " << x << " y: " << y << endl;
    for(int i = 0;i < 4;i++){
      if(0 <= x+dx[i] && x+dx[i] < W && 0 <= y+dy[i] && y+dy[i] < H &&
          a.at(y+dy[i]).at(x+dx[i]) == 0 &&
          visited.at(y+dy[i]).at(x+dx[i]) == 0){
        queue_x.push(x+dx[i]);
        queue_y.push(y+dy[i]);
        visited.at(y+dy[i]).at(x+dx[i]) = visited.at(y).at(x) + 1;
      }
    }
  //print_vec(visited,H,W);
  }
  //print_vec(visited,H,W);
  int ans = find_max(visited,H,W);
  cout << ans-1 << endl;
  return 0;
}


#include <iostream>
const int NUM = 10000;
const int INF = 1 << 20;

using namespace std;

int main() {
    long long i, a[NUM];
    long long max = -INF, min = INF, sum = 0;
    cin >> i;
    i = 0;
    while (cin >> a[i]) {
        if (max < a[i]) max = a[i];
        if (min > a[i]) min = a[i];
        sum += a[i++];
    }
    cout << min << ' ' << max << ' ' << sum << endl;
    return 0;
}

#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
int main(){
        int n;
        cin>>n;
        vector<long>ar(n);
        for(auto&e:ar){
                scanf("%ld",&e);
        }
        long long sum1=0;
        for(int i=0;i<n;i++){
                sum1+=ar[i];
        }
    sort(ar.begin(),ar.end());
    printf("%ld %ld %lld\n",ar[0],ar[n-1],sum1);
        return 0;
}


#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main()
{
    string times;
    int x=0;
    int n;
    vector <int> number;
getline(cin,times);
stringstream s(times);
while(s>>n)
    number.push_back(n);

x=(60*(number[2]-number[0])+(number[3]-number[1]))-number[4];

    cout<<x<<endl;

    return 0;
}

//Now you are making me a boy with luvv...
//I don't want to do this but I'm being forced to ....pls help!!
#include <bits/stdc++.h>
using namespace std;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define ed end()
#define bg begin()
# define ld long double
#define ll long long
#define ub(v,a) upper_bound(all(v),a)
#define lb(v,a) lower_bound(all(v),a)
#define sz(a) (int)(a.size())
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tr(v,it) for(auto it=v.begin();it!=v.end();it++)
#define present(v,x) (v.find(x)!=v.end()) //set/map etc.
#define vpresent(v,x) (find(all(v),x)!=v.end()) // vector
typedef vector< int > vi;
typedef vector< long long > vll;
typedef vector<pair<ll,ll>> vp;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
const long long max_sz = 1e5 + 1;
const long long mod = 1e9 + 7;
const long long MAXN = 4e18 + 1;
char flip(char k){ if(k=='0') return '1'; return '0'; }
ll sum_digit(ll n){ ll a=0,i; for(i=n;i>0;i=i/10){ a+=(i%10);} return a; }
ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int main(){
                   // ios_base::sync_with_stdio(false);
                    //cin.tie(NULL);
                    //cout.tie(NULL);

                     ll t;
                    // cin >> t;
                     t=1;
                     while (t--){
                             ll h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
                             if(m2>m1){
                                 ll diff=(h2-h1)*60 + m2-m1;
                                 cout<<diff-k<<endl;
                             }
                             else{
                                 ll diff=(h2-h1)*60 +m2-m1;
                                 cout<<diff -k<<endl;
                             }
                     }
                    cerr << endl
                                  << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
                      return 0;
}


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

int
main ()
{

  string str;
  cin >> str;
  int n;
  cin >> n;

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

      string a = "";
      int b = 0;
      int c = 0;
      string d = "";
      cin >> a;
      cin>>b>> c;

      if (a == "replace")
	{
	  cin >> d;
	  str.replace (b, c - b + 1, d);

	}
      else if (a == "reverse")
	{
	  string s=str.substr (b, c - b + 1);
	  reverse (s.begin (),s.end ());
           str=str.substr(0,b)+s+str.substr(c+1,str.length());

	}
      else if (a=="print")
	{
	  cout << str.substr (b, c - b + 1) << endl;

	}
  }

  return 0;
}

#include<iostream>
#include<string>

using namespace std;

int main() {
	string str, cmd;
	int a, b, q;
	cin >> str >> q;
	for (int i = 0; i < q; i++) {
		cin >> cmd >> a >> b;
		if (cmd == "print") {
			for (int j = a; j <= b; j++)
				cout << str[j]; cout << endl;
		}
		else if (cmd == "reverse") {
			int fend = (b - a + 1) / 2;
			for (int j = 0; j < fend; j++)
				swap(str[a++], str[b--]);
		}
		else if (cmd == "replace") {
			string p; int n = 0;
			cin >> p;
			for (int k = a; k <= b; k++) {
				str[k] = p[n++];
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){

    int n; cin >> n;
    vector<vector<pair<int,ll>>> g(n);
    rep(i,n-1){
        int a, b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].pb(make_pair(b,c));
        g[b].pb(make_pair(a,c));
    }

    int q, k; cin >> q >> k;
    k--;
    vector<int> x(q),y(q);
    rep(i,q) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }

    queue<int> que;
    que.push(k);
    vector<bool> vis(n,false);
    vis[k] = true;
    vector<ll> dist(n);

    while(que.size()){
        int v = que.front();
        que.pop();
        for(auto i : g[v]){
            if(!vis[i.first]){
                vis[i.first] = true;
                dist[i.first] = dist[v] + i.second;
                que.push(i.first);
            }
        }
    }

    rep(i,q){
        cout << dist[x[i]] + dist[y[i]] << endl;
    }
}

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

#define INF INT_MAX

using Weight = long long;
using Weights = vector<Weight>;
using Matrix = vector<Weights>;

bool WF(const Matrix &g, Matrix &dist, vector<vector<int>> &prev) {
	int V = g.size();
	dist = g;
	prev.assign(V, vector<int>(V, -1));
	for (int k = 0; k < V; ++k) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				if (dist[i][k] == INF || dist[k][j] == INF) continue;
				if (dist[i][j] > dist[i][k] + dist[k][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
					prev[i][j] = k;
				}
			}
		}
	}
	for (int i = 0; i < V; ++i) if (dist[i][i] < 0) return true;
	return false;
}

void buildPath(const vector< vector<int> > &prev,
	int s, int t, vector<int> &path) {
	int u = prev[s][t];
	if (u < 0) path.push_back(s);
	else buildPath(prev, s, u, path), buildPath(prev, u, s, path);
}
vector<int> buildPath(
	const vector< vector<int> > &prev, int s, int t) {
	vector<int> path;
	buildPath(prev, s, t, path);
	path.push_back(t);
	return path;
}

int main(void) {
	int V, E;
	cin >> V >> E;
	Matrix g(V, vector<Weight>(V, INF));
	for (int i = 0; i < V; ++i) g[i][i] = 0;
	for (int i = 0; i < E; ++i) {
		long long s, t, w;
		cin >> s >> t >> w;
		g[s][t] = w;
	}

	Matrix dist;
	vector<vector<int>> prev;
	bool nc = WF(g, dist, prev);
	if (nc) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (i == j) cout << "0";
			else if (dist[i][j] == INF) cout << "INF";
			else cout << dist[i][j];
			if (j != V - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}


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

int main(void){
    ll n, x, cnt = 0;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    for (int i=0; i<n; i++){
        if ((i<n-1 && a[i]<=x) || (i==n-1 && a[i]==x)){
            x -= a[i];
            cnt++;
        } else{
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
    int N;
    long long x;
    cin >> N >> x;
    vector<long long> cost(N);
    long long sum = 0;
    for(int i=0; i<N; i++){
        cin >> cost[i];
        sum += cost[i];
    }

    if(sum == x){
        cout << N << endl;
        return 0;
    }

    sort(cost.begin(), cost.end());

    int k = 0;
    long long tmp_sum = 0;
    while(k < N){
        tmp_sum += cost[k];

        if(tmp_sum > x){
            cout << k << endl;
            return 0;
        }

        k += 1;
    }

    cout << N-1 << endl;
    return 0;

}


#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
  int n, m, i, j;
  while(cin >> n >> m) {
    int vote[n] = {};
    int cost[n] = {};
    int req;

    for(i = 0; i < n; i++) {
      cin >> cost[i];
    }
    for(i = 0; i < m; i++) {
      cin >> req;
      for(j = 0; j < n; j++) {
	if(req >= cost[j]) {
	  vote[j]++;
	  break;
	}
      }
    }
    int ans = 0;
    for(i = 0; i < n; i++) {
      if(vote[ans] < vote[i]) {
	ans = i;
      }
    }
    cout << ans + 1 << endl;
  }
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;cin>>n>>m;
  int A[n], B[m];
  FOR(i,0,n)cin>>A[i];
  FOR(i,0,m)cin>>B[i];
  int cnt[n+1];
  int ans = -1, num = 0;
  CLR(cnt);
  FOR(i,0,m){
      FOR(j,0,n){
          if(A[j] <= B[i]){
              cnt[j+1]++;
              if(cnt[j+1] > cnt[ans]) ans = j + 1;
              break;
          }
      }
  }
  cout << ans << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
#define OFFSET 200000

vector< vector<int> > pl_d(400001);
vector< vector<int> > pl_r(400001);
vector< vector<int> > pl_u(400001);
vector< vector<int> > pl_l(400001);
vector< vector<int> > df_u(400001);
vector< vector<int> > df_d(400001);
vector< vector<int> > df_r(400001);
vector< vector<int> > df_l(400001);
vector< vector<int> > xs_u(200001);
vector< vector<int> > xs_d(200001);
vector< vector<int> > ys_l(200001);
vector< vector<int> > ys_r(200001);

int minimum_col(const vector<int> &v1,const vector<int> &v2,int rat){
  if(!(v1.size() > 0 && v2.size() > 0))return 10000000;
  int j = 0;
  int ret = 10000000;
  REP(i,v1.size()){
    int x_ = v1[i];
    //cerr<<x_<<" "<<v2[j]<<endl;
    while(x_ > v2[j]){
      //cerr<<"dbg "<<x_<<" "<<v2[j]<<endl;
      j++;
      if(j == v2.size())return ret*rat;
    }
    ret = min(ret,v2[j] - x_);
  }
  return ret*rat;
}

int main(){
  int x[200000],y[200000];
  char u[200000];

  int n;
  cin>>n;
  REP(i,n){
    cin>>x[i]>>y[i]>>u[i];
    switch(u[i]){
      case 'U':
        pl_u[x[i]+y[i]].push_back(x[i]);
        df_u[x[i]-y[i]+OFFSET].push_back(x[i]);
        xs_u[x[i]].push_back(y[i]);
        break;
      case 'D':
        pl_d[x[i]+y[i]].push_back(x[i]);
        df_d[x[i]-y[i]+OFFSET].push_back(x[i]);
        xs_d[x[i]].push_back(y[i]);
        break;
      case 'L':
        pl_l[x[i]+y[i]].push_back(x[i]);
        df_l[x[i]-y[i]+OFFSET].push_back(x[i]);
        ys_l[y[i]].push_back(x[i]);
        break;
      case 'R':
        pl_r[x[i]+y[i]].push_back(x[i]);
        df_r[x[i]-y[i]+OFFSET].push_back(x[i]);
        ys_r[y[i]].push_back(x[i]);
        break;
    }
  }
  int ret = 10000000;

  for(auto &e : pl_u){
    sort(ALL(e));
  }
  for(auto &e : pl_d){
    sort(ALL(e));
  }
  for(auto &e : df_u){
    sort(ALL(e));
  }
  for(auto &e : df_d){
    sort(ALL(e));
  }
  for(auto &e : pl_l){
    sort(ALL(e));
  }
  for(auto &e : pl_r){
    sort(ALL(e));
  }
  for(auto &e : df_r){
    sort(ALL(e));
  }
  for(auto &e : df_l){
    sort(ALL(e));
  }
  for(auto &e : xs_u){
    sort(ALL(e));
  }
  for(auto &e : xs_d){
    sort(ALL(e));
  }
  for(auto &e : ys_l){
    sort(ALL(e));
  }
  for(auto &e : ys_r){
    sort(ALL(e));
  }

  REP(i,400001)ret = min(ret,minimum_col(pl_d[i],pl_l[i],10));
  REP(i,400001)ret = min(ret,minimum_col(df_u[i],df_l[i],10));
  REP(i,400001)ret = min(ret,minimum_col(pl_r[i],pl_u[i],10));
  REP(i,400001)ret = min(ret,minimum_col(df_r[i],df_d[i],10));
  REP(i,200001)ret = min(ret,minimum_col(xs_u[i],xs_d[i],5));
  REP(i,200001)ret = min(ret,minimum_col(ys_r[i],ys_l[i],5));

  if(ret >= 10000000)cout<<"SAFE"<<endl;
  else cout<<ret<<endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500010;
const int INF = 1000000010;

int n, m;
int cntNode;

int dist[MAXN];

vector<int> adj[MAXN];
vector<int> weight[MAXN];

deque<int> d;

map<int,int> indNode[MAXN];

void BFS01(int s)
{
	for(int i = 1 ; i <= cntNode ; i++)
		dist[i] = INF;

	dist[s] = 0;
	d.push_front( s );

	while( !d.empty() )
	{
		int cur = d.front();
		d.pop_front();

		for(int i = 0 ; i < (int)adj[cur].size() ; i++)
		{
			int viz = adj[cur][i];
			int w = weight[cur][i];

			if( dist[viz] <= dist[cur] + w ) continue;

			dist[viz] = dist[cur] + w;

			if( w == 0 ) d.push_front( viz );
			else d.push_back( viz );
		}
	}
}

int getExpandedNode(int node, int color)
{
	if( indNode[node][color] == 0 )
		indNode[node][color] = ++cntNode;

	return indNode[node][color];
}

void addEdge(int U, int V, int W)
{
	adj[U].push_back( V );
	weight[U].push_back( W );
}

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

	cntNode = n;

	for(int i = 1 ; i <= m ; i++)
	{
		int U, V, C;
		scanf("%d %d %d",&U,&V,&C);

		int A = getExpandedNode( U , C );
		int B = getExpandedNode( V , C );

		addEdge( A , B , 0 );
		addEdge( B , A , 0 );
	}

	for(int i = 1 ; i <= n ; i++)
	{
		for(auto it = indNode[i].begin() ; it != indNode[i].end() ; it++)
		{
			addEdge( i , it->second , 0 );
			addEdge( it->second , i , 1 );
		}
	}

	BFS01( 1 );

	if( dist[n] == INF ) printf("-1\n");
	else printf("%d\n",dist[n]);
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    ll pow2 = 1;
    ll sum = 0;
    ll mod = 7LL + 1e9;
    rep(_i, 61) {
        ll one = 0, zero = 0;
        rep(i, n) {
            ll v = A[i] % 2;
            if (v == 1) one++;
            else zero++;
            A[i] /= 2;
        }

        sum += (one * zero % mod) * pow2 % mod;
        sum %= mod;

        pow2 *= 2;
        pow2 %= mod;
    }

    put(sum);
}
signed main(){ Main();return 0;}

#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;

const int mod = 1000000007  ;
const int inf = 100005;
const int N = 3e5, M = N;
ll i,j,n,m,idx,cnt;
char d[31][31];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};

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

 vl vec(61);
 ll ans = 0,x;
 cin>>x;
 fo(i,0,61) {
    if(x & (1LL<<i)) vec[i]++;
 }
 ll k;
 fo(i,1,n) {
    cin>>x;
    fo(j,0,61) {
        if(x & (1LL<<j)) {
            k = i - vec[j];
            ans = (ans%mod + ((1LL<<j)%mod * k%mod)%mod)%mod;
            vec[j]++;
        }
        else {
            k = vec[j];
            ans = (ans%mod + ((1LL<<j)%mod * k%mod)%mod)%mod;
        }
    }

 }
 cout<<ans<<"\n";
}

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

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

    return 0;
}


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

int main() {
	double n,x,t;
	cin >> n >> x >> t;
	x = ceil(n/x);
	cout << int(x * t) << endl;
}

#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
void Fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}
const int Max=1e5+8;
const int OO=-1e6;
int xt[4]= {1,0,0,-1};
int yt[4]= {0,1,-1,0};
ll n,m,f,l;
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}

int mem[209][209][209],k;
        string st,st2;

void init()
{
    memset(mem,-1,sizeof mem);
}
/////////////////////////////////////////////////////////////////////
int solve (int i=0,int t=0,int j=n )
{

}

int main()
{

    int T=1;
///T=D();
    while(T-->0)
    {
       n=D();
      int x=D();
      int t= D();
    int ans=  (n/x)*t;
    if(n%x)ans+=t;
    cout<<ans;

    }

}


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

int main(int argc, char const *argv[]) {
    int k, x;
    cin >> k >> x;

    for (int i = 1; i < 2 * k; i++) cout << x - k + i << ' ';
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>

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

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

	int sum = 0;
	int m = 10000;

	for (int i = 0;i < 4;i++){
		int tmp; cin >> tmp;
		sum += tmp;
		m = min(m,tmp);
	}

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

	cout << sum-m+max(a,b) << endl;

	return 0;

}


#include <functional>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <type_traits>
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	self_type operator+(const self_type& x) const noexcept {
		const int y = m_value + x.m_value;
		return unsafe_construct(y >= MOD ? y - MOD : y);
	}
	self_type operator*(const self_type& x) const noexcept {
		return unsafe_construct(
			static_cast<long long>(m_value) * x.m_value % MOD);
	}
	self_type& operator+=(const self_type& x) noexcept {
		return (*this = *this + x);
	}
	self_type& operator*=(const self_type& x) noexcept {
		return (*this = *this * x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
using namespace std;
static const int MOD = 1000000007;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<int> b(n);
	b[0] = a[0];
	for(int i = 1; i < n; ++i){ b[i] = b[i - 1] ^ a[i]; }
	vector<int> c(n + 1);
	for(int i = 0; i < n; ++i){ c[i + 1] = c[i] + (b[i] == 0 ? 1 : 0); }
	vector<mint> dp0(1 << 20), dpx(1 << 20);
	vector<int> last(1 << 20);
	for(int i = 0; i < n; ++i){
		const int k = c[i] - c[last[b[i]]];
		dp0[b[i]] += dpx[b[i]] * k;
		dpx[b[i]] += dp0[b[i]] + 1;
		last[b[i]] = i;
	}
	mint answer = 0;
	if(b.back() == 0){
		for(int i = 1; i < (1 << 20); ++i){ answer += dpx[i]; }
		mint z = 1;
		for(int i = 1; i < c.back(); ++i){ z *= 2; }
		answer += z;
	}else{
		answer = dp0[b.back()] + 1;
	}
	cout << answer << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9+7;

int main(){
	int N; cin >> N;
	vector<int> A(N);
	int x = 0, y = 0;
	vector<vector<vector<int>>> name(1<<20,vector<vector<int>>(2,vector<int>(2,0)));
	vector<vector<LL>> dp(1<<20,vector<LL>(3,0));
	repp(i,0,N){
		cin >> A[i];
		x ^= A[i];
		if(x == 0){
			++y;
		} else {
			if(dp[x][2] < y){
				(dp[x][0] += dp[x][1]*(y-dp[x][2])) %= mod;
				dp[x][2] = y;
			}
			(dp[x][1] += dp[x][0]+1) %= mod;
		}
	}
	if(x == 0){
		LL ans = 1;
		repp(i,1,y) ans = ans*2%mod;
		repp(k,1,1<<20){
			(ans += dp[k][1]) %= mod;
		}
		cout << ans << endl;
	} else {
		cout << dp[x][0]+1 << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
const int MN=100000+5,P=1000000007,inv2=P+1>>1;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n;
int a[4][MN],c[2];
int t[MN];
int lowbit(int x){return x&(-x);}
void add(int p,int d){while(p<=n)t[p]+=d,p+=lowbit(p);}
int sum(int p){int c=0;while(p)c+=t[p],p-=lowbit(p);return c;}
void input(){
	IN(n);
	for(int i=1;i<=3;++i)for(int j=1;j<=n;++j)IN(a[i][j]);
	for(int i=1;i<=n;++i){
		if(a[2][i]%3!=2||abs(a[2][i]-a[1][i])!=1||abs(a[3][i]-a[2][i])!=1||(a[2][i]/3)&i&1)return puts("No"),void();
		c[i&1]^=(a[1][i]>a[3][i]);
	}
	for(int i=1;i<=n;i+=2)c[0]^=(sum(n)-sum(a[2][i]/3+1))&1,add(a[2][i]/3+1,1);
	memset(t,0,sizeof t);
	for(int i=2;i<=n;i+=2)c[1]^=(sum(n)-sum(a[2][i]/3+1))&1,add(a[2][i]/3+1,1);
	if(c[0]==0&&c[1]==0)puts("Yes");
	else puts("No");
}
int main(){
	input();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    V<> a(n+2);
    a[0] = a[n+1] = 0;
    for(int i = 1; i <= n; i++) cin >> a[i];
    ll sum = 0;
    for(int i = 0; i < n + 1; i++) {
        sum += abs(a[i] - a[i + 1]);
    }
    for(int i = 1; i <= n; i++) {
        ll ans = sum;
        ans -= abs(a[i - 1] - a[i]);
        ans -= abs(a[i + 1] - a[i]);
        ans += abs(a[i - 1] - a[i + 1]);
        cout << ans << endl;
    }
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int n,m;
    ll x1,x2,X=0,y1,y2,Y=0;
    cin>>n>>m;
    //x
    cin>>x1;
    rep(i,n-1){
        cin>>x2;
        X=(X+(x2-x1)*(i+1)*(n-i-1))%mod;
        x1=x2;
    }
    //y
    cin>>y1;
    rep(i,m-1){
        cin>>y2;
        Y=(Y+(y2-y1)*(i+1)*(m-i-1))%mod;
        y1=y2;
    }
    cout<<(X*Y)%mod<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll maxn = 1e3 + 10;

ll a[maxn];

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

	ll n , res = 0;
	cin >> n;

	for (ll i = 1; i <= 2 * n; i++)
    {
        cin >> a[i];
    }

    sort(a + 1 , a + 2 * n + 1);

    for (ll i = 1; i <= n; i++)
    {
        res += a[2 * i - 1];
    }

    cout << res;
}

#include <iostream>
#include <algorithm>

signed main() {
  int n;
  std::cin >> n;
  n = 2*n;

  int l[n];
  for(int i = 0; i < n; i++)
    std::cin >> l[i];

  std::sort(l, l+n);

  int ans = 0;
  for(int i = n-2; i >= 0; i -= 2)
    ans += l[i];

  std::cout << ans << std::endl;

  return 0;
}


#include<iostream>

using namespace std;

int main() {
	string str;
	cin >> str;
	//0から4文字分
	str.replace(0, 4, "2018");
	printf("%s", str.c_str());

	return 0;
}

#include <stdio.h>

int main (){
	int year;
	int month;
	int date;
	int x;

	scanf ("%d/%d/%d", &year, &month, &date);

	x = year + 1;

	printf ("%d/%02d/%02d\n", x, month, date);

	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,p;
  while(cin >> n >> p, n!=0 && p!=0){
    int s[n];
    int index = 0;
    int stone = p;
    for(int i=0;i<n;i++){
      s[i] = 0;
    }
    while(true){
      if(stone > 0){
    s[index]++;
    stone--;
      }else if(stone == 0){
    stone = s[index];
    s[index] = 0;
      }

      if(s[index] == p) break;
      if(index == n-1){
    index = 0;
      }else{
    index++;
      }
    }
    cout << index << endl;
  }
}

#include <iostream>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int main(){
  int n;
  int p;
  int a[100];
  int b[100];
  int flag = 0;
  int i = 0;
  int pp;
  while(cin >> n >> p){
    pp = p;
    for(int j = 0;j < n;j++){
      a[j] = 0;
    }
    i = 0;
    flag = 0;
    if(n == 0 && p == 0){
      break;
    }
    while(flag == 0){
      if(p > 0){
        a[i] += 1;
        p -= 1;
      }else{
        p = a[i];
        a[i] = 0;
      }
      if(a[i] == pp){
        cout << i << endl;
        flag = 1;
      }
      i++;
      if(i == n){
        i = 0;
      }
    }
  }
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 10005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M;
struct node {
    int to,next,val;
}E[1005];
int sumE,head[25],pos[(1 << 15) + 5];
int f[16][(1 << 15) + 5],h[16][(1 << 15) + 5],sum[(1 << 15) + 5];
void add(int u,int v,int c) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].val = c;
    head[u] = sumE;
}
inline int lowbit(int x) {
    return x & (-x);
}
void Init() {
    read(N);read(M);
    int u,v,c;
    for(int i = 1 ; i <= M ; ++i) {
        read(u);read(v);read(c);
        add(u,v,c);add(v,u,c);
        h[u][1 << v - 1] = c;
        h[v][1 << u - 1] = c;
    }
    for(int i = 1 ; i <= N ; ++i) {
        for(int j = 1 ; j < (1 << N) ; ++j) {
            if(lowbit(j) == j) continue;
            h[i][j] = h[i][j - lowbit(j)] + h[i][lowbit(j)];
        }
    }
    for(int i = 1 ; i <= N ; ++i) pos[(1 << i - 1)] = i;
    for(int i = 1 ; i < (1 << N) ; ++i) {
        sum[i] = sum[i - lowbit(i)] + h[pos[lowbit(i)]][i - lowbit(i)];
    }
}
void Solve() {
    for(int i = 1 ; i <= N ; ++i) {
        for(int j = 0 ; j < (1 << N) ; ++j) {
            f[i][j] = -1e9;
        }
    }
    f[1][1] = 0;

    for(int j = 0 ; j < (1 << N - 1) ; ++j) {
        for(int i = 1 ; i <= N ; ++i) {
            int S = j << 1 | 1;
            if(!(S & (1 << i - 1))) continue;
            int L = S ^ (1 << i - 1);
            for(int T = L; T ; T = (T - 1) & L) {
                if(f[i][S ^ T] >= 0)
                    f[i][S] = max(f[i][S],f[i][S ^ T] + sum[T ^ (1 << i - 1)]);
            }
            if(f[i][S] >= 0) {
                for(int k = head[i] ; k ; k = E[k].next) {
                    int v = E[k].to;
                    if(!(S & (1 << v - 1))) {
                        f[v][S ^ (1 << v - 1)] = max(f[v][S ^ (1 << v - 1)],f[i][S] + E[k].val);
                    }
                }
            }
        }
    }
    out(sum[(1 << N) - 1] - f[N][(1 << N) - 1]);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}

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

template <typename T>
struct segtree_lazy {
	int n;
	vector<T> tree, lazy;
	T def = numeric_limits<T>::max(), none = -1;

	segtree_lazy(int n_) {
		for (n = 1; n < n_; n *= 2) {

		}
		tree.assign(2 * n, def);
		lazy.assign(2 * n, none);
	}

	T merge(T a, T b) {
		return max(a, b);
	}

	void set_lazy(int index, T x) {
		tree[index] = x;
		lazy[index] = x;
	}

	void push(int index) {
		if (lazy[index] == none) {
			return;
		}
		set_lazy(2 * index, tree[index]);
		set_lazy(2 * index + 1, tree[index]);
		lazy[index] = none;
	}

	void fix(int index) {
		tree[index] = merge(tree[2 * index], tree[2 * index + 1]);
	}

	void update(int a, int b, int index, int l, int r, T x) {
		if (r <= a || b <= l) {
			return;
		}
		if (a <= l && r <= b) {
			set_lazy(index, x);
			return;
		}
		push(index);
		update(a, b, 2 * index, l, (l + r) / 2, x);
		update(a, b, 2 * index + 1, (l + r) / 2, r, x);
		fix(index);
	}

	void update(int l, int r, T x) {
		update(l, r, 1, 0, n, x);
	}

	T query(int a, int b, int index, int l, int r) {
		if (r <= a || b <= l) {
			return none;
		}
		if (a <= l && r <= b) {
			return tree[index];
		}
		push(index);
		T puni = query(a, b, 2 * index, l, (l + r) / 2);
		T muni = query(a, b, 2 * index + 1, (l + r) / 2, r);
		return merge(puni, muni);
	}

	T query(int l, int r) {
		return query(l, r, 1, 0, n);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	segtree_lazy<int> seg(n);
	for (int i = 0; i < q; i++) {
		bool b;
		cin >> b;
		if (b) {
			int x;
			cin >> x;
			cout << seg.query(x, x + 1) << endl;
		} else {
			int s, t, x;
			cin >> s >> t >> x;
			seg.update(s, t + 1, x);
		}
	}
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
#define int ll
int costs(int now) {
    for (int i = 0; i < 62; ++i) {
        if (now < (1 << i)) {
            return i + 1;
        }
    }
}

int secret_d = 10;
int n;

int interact(int a) {
    int ans = 0;
    cout << "? " << a << endl;
    if (true) {
        int r = 1;
        for (int i = 0; i < 60; ++i) {
            if ((secret_d & (1LL << i))) {
                ans += costs(r) * costs(a);
                r = r * a % n;
            }
            ans += costs(a) * costs(a);
            a = a * a % n;
        }
    }
    else {
        cin >> ans;
    }
    return ans;
}

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

long double comb(int a, int b) {
    ld ans = 1;
    for (int q = 0; q < b; ++q) {
        ans *= (ld)(a - q);
        ans /= (ld)(q + 1);
    }
    return ans;
}

void solve(){
    int n;
    cin >> n;
    vector<int> inputs;
    int ans = 0;
    REP(i, n) {
        int a;
        cin >> a;
        inputs.push_back(a);
    }
    if (inputs[0] != 0) {
        cout << -1 << endl;
        return;
    }
    for (int q = 1; q < n; ++q) {
        if (inputs[q] > inputs[q - 1] + 1) {
            cout << -1 << endl;
            return;
        }
        if (inputs[q] == inputs[q - 1] + 1) {
            ans++;
        }
        else {
            ans += inputs[q];
        }
    }
    cout << ans << endl;
}

#undef int
int main() {
    init();
    solve();
}

#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}

int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
        if(i==0){
            if(a[i]!=0){
                cout << -1 << endl;
                return 0;
            }
        }
        else{
            if(a[i]-a[i-1]>=2){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    ll ans=0;
    REP(i,n){
        if(i==0)continue;
        if(a[i]-a[i-1]==1){
            ans++;
        }
        else{
            ans+=a[i];
        }
    }
    cout << ans << endl;
}


#include <iostream>
using namespace std;

int main(){
  long long n, a, b; cin >> n >> a >> b;
  long long x[n];
  for(int i = 0; i < n; ++i) cin >> x[i];
  long long dp[n+1];
  dp[0] = 0;
  dp[1] = 0;
  for(int i =2; i <= n; ++i){
    dp[i] = min(a*(x[i-1]-x[i-2]), b) + dp[i-1];
  }
  cout << dp[n] << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;
using ULL = unsigned long long;
int main() {
  ULL N, a, b, west, east, chk, ans = 0;
  cin >> N >> a >> b >> west;
  rep(i, 1, N) {
    cin >> east;
    chk = (east - west) * a;
    if (chk > b) {
      ans += b;
    } else {
      ans += chk;
    }
    west = east;
  }
  cout << ans << endl;
  getchar();
}


 #include <stdio.h>

   int e;

   int x, y, z;
   int m;

   int main(void)
   {
      while(1) {
          m = 1000000;
          y = 0;
          z = 0;
          scanf("%d", &e);
          if (e == 0) break;
          while (z * z * z <= e) {
              while (y * y <= e - z * z * z) {
                  x = e - y * y - z * z * z;
                  if (m > x + y + z) {
                      m = x + y + z;
                  }
                  y++;
              }
              y = 0;
              z++;
          }
          printf("%d\n", m);
      }
  }

#include<iostream>
#include<vector>

using namespace std;

int main(void){
  int a,b,c,n;
  while(cin>>a>>b>>c,a+b+c){
  cin>>n;
  vector<int> in(a+b+c+1,2);
  vector<vector<int> > jud(n,vector<int>(4,0));
  for(int l = 0 ; l < n ; l ++){
    int i , j , k , r;
    cin>>i>>j>>k>>r;
    if(r == 1){
      in[i] = in[j] = in[k] = 1;
    }
    jud[l][0] = i ; jud[l][1] = j ;
    jud[l][2] = k ; jud[l][3] = r;
  }

  for(int i = 0 ; i < jud.size() ; i ++){
    if(jud[i][3] == 0){
      if(in[jud[i][0]] == 1 && in[jud[i][1]] == 1) in[jud[i][2]] = 0;
      if(in[jud[i][2]] == 1 && in[jud[i][0]] == 1) in[jud[i][1]] = 0;
      if(in[jud[i][2]] == 1 && in[jud[i][1]] == 1) in[jud[i][0]] = 0;
    }
  }

  for(int i = 1 ; i < in.size() ; i ++)
    cout<<in[i]<<endl;
  }
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define F first
#define S second
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define MP make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define debug(x) cout << " > " << #x << ':' << x << endl;
#define kiyohime ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using vec = vector<T>;
template<typename T> using Prior = priority_queue<T>;
template<typename T> using prior = priority_queue<T, vec<T>, greater<T>>;

const int INF = 1e9;
const ll LLINF = (ll)4*1e18;
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;
const int xx[8] = {0,1,0,-1,1,1,-1,-1};
const int yy[8] = {1,0,-1,0,1,-1,-1,1};

void pmod(ll &a, ll b) {a = (a+b)%MOD;}
void mmod(ll &a, ll b) {a = (a-b+MOD)%MOD;}
void tmod(ll &a, ll b) {a = (a*b)%MOD;}
ll POW(ll a, ll b) {ll res=1; do{if(b%2)tmod(res,a);tmod(a,a);}while(b>>=1); return res;}
template<typename T> void amax(T &a, T b) {if(a < b) a = b;}
template<typename T> void amin(T &a, T b) {if(a > b) a = b;}

#define N 20
#define lowbit(x) (x&(-x))

void solve(){
    int n;
    ll a[N][N], dp[(1<<16) + 10] = {};

    cin >> n ;
    rep(i, n) rep(j, n) cin >> a[i][j];

    rep1(i, (1<<n)-1){
        rep(j, n) REP(u, j+1, n-1)
            if((i & (1<<j)) && (i & (1<<u)))
                dp[i] += a[j][u];

        int tmp = (i-1) & i;
        while(tmp){
            amax(dp[i], dp[i-tmp] + dp[tmp]);
            tmp = (tmp - 1) & i;
        }
    }

    cout << dp[(1<<n) - 1] << endl;
}

int main(){
//    kiyohime
    int T = 1;

//    cin >> T;
    while(T--){
        solve();
    }
}

#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,m,q;
  cin>>n>>m>>q;
  vector<string> t(n+2);
  for(int i:irange(0,n)) {
    string s;
    cin>>s;
    t[i+1] = "0" + s + "0";
  }
  t[0] = t[n+1] = string(m+2, '0');
  vector<vecint> connects_v(n, vecint(m+1));
  vector<vecint> connects_h(n+1, vecint(m));
  for(int i:irange(0,n)) {
    for (int j:irange(0,m+1)) {
      bool left = t[i+1][j] == '1';
      bool right = t[i+1][j+1] == '1';
      if (left && right) {
        connects_v[i][j] = 1;
      }
    }
  }
  for (int i:irange(0,n+1)) {
    for (int j:irange(0,m)) {
      bool top = t[i][j+1] == '1';
      bool bottom = t[i+1][j+1] == '1';
      if (top && bottom) {
        connects_h[i][j] = 1;
      }
    }
  }
  vector<vecint> psumcv(n+1, vecint(m+2));
  vector<vecint> psumch(n+2, vecint(m+1));
  for(int i:irange(0,n)) {
    for (int j:irange(0,m+1)) {
      psumcv[i+1][j+1] = psumcv[i][j+1] + connects_v[i][j];
    }
  }
  for (int i:irange(0,n+1)) {
    for (int j:irange(0,m+1)) {
      psumcv[i][j+1] += psumcv[i][j];
    }
  }
  for (int i:irange(0,n+1)) {
    for (int j:irange(0,m)) {
      psumch[i+1][j+1] = psumch[i+1][j] + connects_h[i][j];
    }
  }
  for (int i:irange(0,n+1)) {
    for (int j:irange(0,m+1)) {
      psumch[i+1][j] += psumch[i][j];
    }
  }
  vector<vecint> surfs(n+1, vecint(m+1));
  for (int i:irange(0,n)) {
    for (int j:irange(0,m)) {
      if (t[i+1][j+1] == '1') {
        surfs[i+1][j+1] = 1;
      }
    }
  }
  for (int i:irange(0,n+1)) {
    for (int j:irange(0,m)) {
      surfs[i][j+1] += surfs[i][j];
    }
  }
  for (int i:irange(0,n)) {
    for (int j:irange(0,m+1)) {
      surfs[i+1][j] += surfs[i][j];
    }
  }
  for(int query : irange(0,q)) {
    int x1,y1,x2,y2;
    cin>>y1>>x1>>y2>>x2;
    int connects = 0;
    connects += psumcv[y2][x2] - psumcv[y1-1][x2] - psumcv[y2][x1] + psumcv[y1-1][x1];
    connects += psumch[y2][x2] - psumch[y2][x1-1] - psumch[y1][x2] + psumch[y1][x1-1];
    --y1;--x1;
    int s = surfs[y2][x2] - surfs[y2][x1] - surfs[y1][x2] + surfs[y1][x1];
    int res = s - connects;
    cout<<res<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int extgcd(int a, int b, int &x, int &y){
    int d = a;
    if(b != 0){
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return d;
}

int gcd_multi(vec a){
    int x, y, g;
    g = a[0];
    FOR(i, 1, a.size()) g = extgcd(g, a[i], x, y);
    return g;
}

signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);

    int odd = 0, oddi;
    REP(i, N){
        if(A[i] % 2 == 1){
            odd++;
            oddi = i;
        }
    }

    if((N - odd) % 2 == 1){
        cout << "First";
        return 0;
    }

    if(!(odd == 1 && A[oddi] > 1)){
        cout << "Second";
        return 0;
    }

    bool f = true;

    while(true){

        A[oddi]--;
        int g = gcd_multi(A);
        REP(i, N) A[i] /= g;

        odd = 0, oddi;
        REP(i, N){
            if(A[i] % 2 == 1){
                odd++;
                oddi = i;
            }
        }

        if((N - odd) % 2 == 1){
            f = !f;
            break;
        }

        if(!(odd == 1 && A[oddi] > 1)) break;

        f = !f;
    }

    if(f){
        cout << "First";
    }else{
        cout << "Second";
    }

    return 0;
}

template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int x;
  cin >> x;
  int ans = 0;
  ans += (x / 500) * 1000;
  x %= 500;
  ans += (x / 5) * 5;

  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second

/*
//functions from gfg

long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }

        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;

    }
    return res%p;
}

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

long long int binomialCoeff(long long int n, ll k)
{
    ll res = 1;

    // Since C(n, k) = C(n, n-k)
    if (k > n - k)
        k = n - k;

    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}

void sieve(int n, vector<ll> &primes)
{
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == 1)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = 0;
        }
    }

    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }

}

void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}

*/

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

    ll n,i,j,p,k,m,t,ans=0;
    cin>>n>>t;
    ll dp[3005][3005];
    memset(dp, 0, sizeof(dp));
    vector<ll> a(n),b(n);
    vector<pair<ll,ll> > val(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        val[i].F=a[i];
        val[i].S=b[i];
    }
    sort(val.begin(),val.end());
    for(i=0;i<n;i++)
    {
        a[i]=val[i].F;
        b[i]=val[i].S;
    }
    for(i=0;i<t;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i+a[j]<t)
            {
                dp[j+1][i+a[j]] = max(dp[j][i]+b[j],dp[j+1][i+a[j]]);
            }

            dp[j+1][i] = max(dp[j][i],dp[j+1][i]);

        }
    }
    for(i=0;i<n;i++)
    {
        ans=max(ans,dp[i][t-1]+b[i]);
    }
    cout<<ans<<endl;

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

    return 0;
}

#include<iostream>
using namespace std;

int angka [10], brpkali, total;

int main (){
	for (int i=1; i<=3; i++){
		cin>>angka[i];
	}
	cin>>brpkali;
	for (int i=1; i<=3; i++){
		for (int j=1; j<=3; j++){
			if (j==i){
			}else if (angka [i]>angka [j]){			//sort;
				swap(angka [i], angka [j]);
			}
		}
	}
	for (int i=1; i<=brpkali; i++){				//multipy big num
		angka [1]*=2;
	}
	for (int i=1; i<=3; i++){					//sum total
		total+=angka [i];
	}
	cout<<total<<endl;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long K;
long long po[20], C[20], res;
void Do(int b, int e, long long S, long long c) {
	if (!c)return;
	if (b >= e) {
		if (S == K) {
			if (b == e)res += 10*c;
			else res+=c;
		}
		return;
	}
	if (abs(S - K) > po[e + 1])return;
	int i;
	for (i = -9; i <= 9; i++) {
		int t = 10 - abs(i);
		if (i >= 0 && b==0)t--;
		Do(b+1, e-1, S+i*C[b], t*c);
	}
}
void Calc(int L) {
	int i;
	for (i = 0; i < L; i++) {
		C[i] = po[L - i - 1] - po[i];
	}
	Do(0, L - 1, 0, 1);
}
int main() {
	int i;
	po[0] = 1;
	for (i = 1; i <= 18; i++)po[i] = po[i - 1] * 10;
	scanf("%lld", &K);
	for (i = 2; i <= 18; i++) {
		Calc(i);
	}
	printf("%lld\n", res);
}

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define MOD 1000000007
#define mod 998244353
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 2000009
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define umap unordered_map<int, int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

vector<pair<int,int> > arr(10);

map<pair<int,int>,ld> mp;
ld ans = 0;
int n;
void fun(vector<int> temp, ld curr) {
    if(temp.size() == n) {
        ans+= curr;
        // for(auto it : temp) {
        //     cout<<it<<" ";
        // }
        // cout<<endl;
        return;
    }
    for(int i=0; i<n; i++) {
        if(find(all(temp),i) == temp.end()) {
            int prev = temp.back();
            temp.push_back(i);
            fun(temp,curr + mp[mpr(i,prev)]);
            temp.pop_back();
        }
    }
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

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

void test_case() {

    cin>>n;

    COMinit();

    rep(i,n) {
        int x,y;
        cin>>x>>y;
        arr[i] = mpr(x,y);
    }

    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            ld  d= pow(arr[i].first - arr[j].first,2) + pow(arr[i].second -arr[j].second,2);
            d = sqrt(d);
            // cout<<d<<endl;
            mp[mpr(i,j)] = d;
            mp[mpr(j,i)] = d;
        }
    }

    vec temp;
    for(int i=0; i<n; i++) {
        temp.push_back(i);
        fun(temp,0.0);
        temp.pop_back();

    }

    ld fin = ans/fac[n];

    // cout<<ans<<endl;

    cout<<fin<<endl;

}

signed main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}


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

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

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

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

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

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

vector<vector<int>> d(10, vector<int>(10, 1000000));

void warshall_floyd(int n) {
    rep(k,n) rep(i,n) {
        rep(j,n) {
            d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
        }
    }
}
int main()
{
    ll n; cin >> n;
    vector<ll> a;
    int ans = 20;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            a.push_back(i);
            a.push_back(n/i);
        }
    }
    for (int i = 0; i < a.size(); i += 2) {
        int tmp1 = to_string(a[i]).length();
        int tmp2 = to_string(a[i+1]).length();
        ans = min(ans, max(tmp1, tmp2));
    }
    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
  ll n,m,t,i,res=0;
  cin >> n;
  m=(ll)sqrt(n);
  for(i=m;i>0;i--)
    if(n%i==0){
      t=n/i;
      while(t>0){
        t/=10;
        res++;
      }
      cout << res << endl;
      return 0;
    }
  return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pi std::pair<int, int>
#define mkp std::make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second

//{{{IO
namespace IO{
	template <class I> void read(I &x){
		x = 0; char ch = getchar(); bool f = false;
		for(; !isdigit(ch); ch = getchar()) f |= (ch == '-');
		for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
		return ;
	}

	int read_int(){ int x; return read(x), x;}
	ll read_ll(){ ll x; return read(x), x;}
	template <class I>
		void chmax(I &x, I y){x = x > y ? x : y;}
	template <class I>
		void chmin(I &x, I y){x = x < y ? x : y;}
#define ri read_int()
#define rl read_ll()
}
using IO::read_int;
using IO::read_ll;
using IO::chmax;
using IO::chmin;
//}}}

//{{{Mod
namespace Mod{
//	const int mod = 1e9 + 7;
//	const int mod = 1004535809;
	const int mod = 998244353;

	inline void MOD(int &x){ x -= x >= mod ? mod : 0;}
	inline void add(int &x, int y){ x = x + y >= mod ? x + y - mod : x + y;}
	inline int Add(int x, int y){ return x + y >= mod ? x + y - mod : x + y;}
	inline void mul(int &x,  int y){ x = 1ll * x * y % mod;}
	inline int Mul(int x, int y){ return 1ll * x * y % mod;}
}
//}}}

#define N 100005

int n, s, cnt;
int x[N], num[N];
ll a[N];

void solve(int l, int r){
	if(l > r) return ;
	if(l == r) return num[++cnt] = l, void();
	if(x[l] > s){
		while(r >= l) num[++cnt] = r--;
		return ;
	}
	if(x[r] < s){
		while(r >= l) num[++cnt] = l++;
		return ;
	}
	if(a[l] >= a[r]){
		num[++cnt] = r; a[l] += a[r]; solve(l, r - 1);
	}
	else{
		num[++cnt] = l; a[r] += a[l]; solve(l + 1, r);
	}
	return ;
}

int main(){
	n = ri; s = ri;
	for(int i = 1; i <= n; ++i)
		x[i] = ri, a[i] = ri;
	solve(1, n); ll res = 0;
//	for(int i = cnt; i >= 1; --i)
//		debug("%d ", num[i]);
	for(int i = cnt; i >= 1; --i)
		res += abs(x[num[i]] - s), s = x[num[i]];
	printf("%lld\n", res);
	return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> ac(n, 0);
  vector<int> wa(n, 0);
  rep(i, m)
  {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (ac[p] == 1)
      continue;
    if (s == "AC")
      ac[p] = 1;
    else
      wa[p]++;
  }
  rep(i, n)
    wa[i] *= ac[i];
  cout << accumulate(ac.begin(), ac.end(), 0) << ' ' << accumulate(wa.begin(), wa.end(), 0) << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#define llint long long
#define mod 1000000007
#define inf 1e18

using namespace std;
typedef pair<double, llint> P;
typedef pair<llint, P> E;

llint n;
llint a, b, c, d;
llint dp[1005][1005];

const int FACT_MAX = 2005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

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

	cin >> n;
	cin >> a >> b >> c >> d;

	dp[a-1][0] = 1;
	for(int i = a-1; i < b; i++){
		for(int j = 0; j <= n; j++){
			dp[i+1][j] += dp[i][j],  dp[i+1][j] %= mod;
			llint mul = 1;
			for(int k = 1; k <= d && j+k*(i+1) <= n; k++){
				mul *= comb(n-j-(k-1)*(i+1), i+1), mul %= mod;
				if(k >= c){
					(dp[i+1][j+k*(i+1)] += dp[i][j] * mul % mod * fact_inv[k] % mod) %= mod;
				}
			}
		}
	}

	cout << dp[b][n] << endl;

	return 0;
}


/*solved by RAKIB JOY*/
#include<stdio.h>
#include<stdbool.h>
bool dislike[10];
int main()
{
    int n,k,a;
    scanf("%d%d",&n,&k);
    while(k--)
    {
        scanf("%d",&a);
        dislike[a]=true;

    }
    for(int i=n;;i++)
    {
       int maybe=i;
       bool ok=true;
       while(maybe)
       {
          int last_digit=maybe%10;
          if(dislike[last_digit])
          {
             ok=false;
             break;
          }
          maybe/=10;
       }
       if(ok)
       {
          printf("%d\n",i);
          return 0;
       }
    }
    return 0;

}

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;cin>>n>>m;
    vector<ll>par(n+1);
    vector<ll>dim(n+1);
    vector<vector<ll> >G(n+1);
    rep(i,n+m-1){
        ll a,b;cin>>a>>b;
        dim[b]++;
        G[a].pb(b);
    }
    queue<ll>q;
    ll p;
    REP(i,1,n+1){
        if(dim[i]==0)p=i;
    }
    q.push(p);
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto e:G[now]){
            dim[e]--;
            if(dim[e]==0){
                par[e]=now;
                q.push(e);
            }
        }
    }
    REP(i,1,n+1){
        cout<<par[i]<<endl;
    }
}


#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  string s[3];
  for (int i = 0; i < 3; i++)
    cin >> s[i];

  int count = 0;

  for (;;)
  {
    char tmp = s[count][0];
    //cout << tmp << " " << s[count] << endl;

    if (s[count].size() == 0)
      break;
    if (tmp == 'a')
    {
      s[count].erase(0, 1);
      count = 0;
    }
    else if (tmp == 'b')
    {
      s[count].erase(0, 1);
      count = 1;
    }
    else if (tmp == 'c')
    {
      s[count].erase(0, 1);
      count = 2;
    }
  }
  char ans;
  for (int i = 0; i < 3; i++)
  {
    if (count == i)
    {
      ans = 'A' + i;
      cout << ans << endl;
      break;
    }
  }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
#define INF 1e9
#define INFL 1e12

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }

typedef pair<int, bool> edge;

int v, e;
vector<vector<edge>> G;
vector<int> ord, low;
set<int> ans;
vector<bool> seen;
int k;
int zero_degree;

void dfs(int u){
    // pr(u);
    seen[u] = true;
    ord[u] = k; k++;
    low[u] = ord[u];
    for(edge &ed: G[u]){
        int v = ed.first;
        if(!seen[v]){
            ed.second = true;
            dfs(v);
            chmin(low[u], low[v]);
            if(u!=0 && ord[u] <= low[v] && ans.find(u)==ans.end()){
                // printf("(%d %d) is pushed\n", u, v);
                ans.insert(u);
            }
            // printf("(%d: %d %d) ",u, ord[u], low[u]);
            // printf("(%d %d)", ord[u], low[u]);
        }else if(ed.second==false){
            // if(ord[u]==low[v]) continue;
            chmin(low[u], ord[v]);
        }
    }
    // printf("(%d: %d %d) ",u, ord[u], low[u]);
}

int main()
{
    cin >> v >> e;
    // cout << v << " " << e << endl;
    G.resize(v); ord.resize(v), low.resize(v); seen.resize(v);

    int a, b;
    rep(i, e){
        cin >> a >> b;
        G[a].push_back({b, false});
        G[b].push_back({a, false});
    }
    // cout << G.size();
    // rep(i, v){
    //     for(auto ed: G[i]){
    //         printf("(%d %d) ", i, ed.first);
    //     }
    //     printf("\n");
    // }
    rep(i, v) seen[i]=false;
    int k = 0;

    dfs(0);

    // cout << endl;
    // rep(i, v){
    //     printf("(%d: %d %d) ",i, ord[i], low[i]);
    // }
    // cout << ans.size() << endl;
    int tmp=0;
    // printf("\n");
    for(edge ed: G[0]){
        // printf("%d\n", ed.second);
        if(ed.second) tmp++;
    }
    if(tmp>1) ans.insert(0);

    for(int i: ans){
        pr(i);
    }
    return 0;
}


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

int n, m;

vector <int> g[15], c[15];
void add_edge(int u, int v, int w) {
	g[u].push_back(v);
	c[u].push_back(w);
}

int dp[1 << 15][15];
int prep[1 << 15][15];

void upd(int &x, int y) {
	if (y < x) x = y;
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		-- u; -- v;
		add_edge(u, v, w);
		add_edge(v, u, w);
	}
	memset(dp, 0x3f, sizeof(dp));
	int full = (1 << n) - 1;
	for (int msk = 1; msk < (1 << n); ++ msk) {
		for (int i = 0; i < n; ++ i) if (!(msk >> i & 1)) {
			for (int e = 0; e < g[i].size(); ++ e) {
				if (msk >> g[i][e] & 1) prep[msk][i] += c[i][e];
			}
		}
	}
	dp[1][0] = 0;
	for (int msk = 1; msk < (1 << n); ++ msk) {
		for (int u = 0; u < n; ++ u) if (msk >> u & 1) {
			for (int e = 0; e < g[u].size(); ++ e) {
				int v = g[u][e];
				if (!(msk >> v & 1))
					upd(dp[msk | 1 << v][v], dp[msk][u] + prep[msk ^ 1 << u][v]);
			}
			for (int s = full ^ msk; s; s = (s - 1) & (full ^ msk)) {
				int cur = 0;
				for (int i = 0; i < n; ++ i) if (s >> i & 1)
					cur += prep[msk ^ 1 << u][i];
				upd(dp[msk | s][u], dp[msk][u] + cur);
			}
		}
	}
	printf("%d\n", dp[full][n - 1]);
	return 0;
}

#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

set<pair<int,pair<int,int> > > query; //time, q, x. q=0:delete or 1: insert or 2:query
Int N,Q;

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

    for(int i = 0;i < N;i++) {
        int s,t,x;
        cin>>s>>t>>x;
        query.insert({s-x, make_pair(1, x)});
        query.insert({t-x, make_pair(0, x)});
    }
    for(int i = 0;i < Q;i++) {
        int d;
        cin>>d;
        query.insert({d, make_pair(2, i)});
    }

    vector<int> D(Q);
    multiset<int> se;
    for(auto it: query) {
        int time = it.first;
        int q = it.second.first;
        int x = it.second.second;
        if(q == 0) {
            se.erase(se.find(x));
        } else if(q == 1) {
            se.insert(x);
        } else {
            if(se.empty()) {
                D[x] = -1;
            } else {
                D[x] = *se.begin();
            }
        }
    }

    for(int i = 0;i < Q;i++) {
        cout<<D[i]<<endl;
    }

    return 0;
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

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

  int n, x;  cin >> n >> x;
  vector<int> a(n); cin >> a;
  ll ans = max(0, a[0]-x);
  for (int i = 0; i < n-1; ++i){
    ll now = max (min(a[i]+a[i+1]-x, a[i+1]), 0);
    ans += now;
    a[i+1] -= now;
  }
  cout << ans << "\n";
  return 0;
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  ll ans = 0;
  ll hu = 0, k = 0;
  rep(i,N) hu += a[i] * b[i];
  rep(i,N) k += b[i];
  ans = (k - 1) + (hu - 1) / 9;
  cout << ans << endl;
}


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

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

int main() {
  ll s;
  cin >> s;
  int cnt = 0;
  ll S = s;
  while(S > 0){
    S /= 10;
    cnt++;
  }
  const int f = 753;
  int ans = 1000;
  for(int i = 3; i <= cnt; i++){
    int x = s/pow(10,cnt -i);
    ans = min(abs(x-f), ans);
    ll p = pow(10,cnt+2-i);
    s %= p;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  string S;
  cin>>S;

  int ans=100000;

  for(int i=0;i<=S.size()-3;i++){
    string res;
    res[0]=S[i];
    res[1]=S[i+1];
    res[2]=S[i+2];

    int X=stoi(res);

    ans=min(abs(X-753),ans);
  }

  cout<<ans<<endl;
}


/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int N;

int cnt[10];

int main(){
	do{
		cin>>N;
		if (N){
			fill(cnt,cnt+10,0);
			REP(i,N){
				int a;
				cin>>a;
				cnt[a]++;
			}
			REP(i,10){
				if (cnt[i]==0){
					cout<<'-'<<endl;
				}else{
					REP(j,cnt[i]){
						cout<<'*';
					}
					cout<<endl;
				}
			}
		}
	}while (N);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll u[4010];
	bool flag;
	vector<int> v;
	while(1)
	{
		for(int i=0;i<4010;i++)
		{
			u[i]=0;
		}
		flag=true;
		int n;
		cin >> n;
		if(n==0)break;
		v.clear();
		for(int i=0;i<n;i++)
		{
			int x;
			ll y,z;
			cin >> x >> y >> z;
			if(!(u[x]))
			{
				v.pb(x);
			}
			u[x]+=y*z;
		}
		for(int i=0;i<v.size();i++)
		{
			if(u[v[i]]>=1000000)
			{
				flag=false;
				cout << v[i] << endl;
			}
		}
		if(flag)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

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

struct Graph {
  int n;
  int time;
  vector<vector<int>> g;
  vector<int> num, low;
  vector<vector<int>> scc;
  stack<int, deque<int>> S;
  vector<bool> inS;

  Graph(int n) : n(n), g(n), num(n, -1), low(n, -1), inS(n) {}

  void addEdge(int u, int v) {
    g[u].push_back(v);
  }
  void dfs(int u) {
    num[u] = low[u] = time++;
    S.push(u);
    inS[u] = true;
    for (auto&& v : g[u]) {
      if (num[v] == -1) {
        dfs(v);
        low[u] = min(low[u], low[v]);
      } else if (inS[v]) {
        low[u] = min(low[u], num[v]);
      }
    }
    if (low[u] == num[u]) {
      scc.push_back({});
      while (true) {
        int v = S.top(); S.pop();
        inS[v] = false;
        scc.back().push_back(v);
        if (u == v) break;
      }
    }
  }
  void stronglyConnectedComponents() {
    for (int i = 0; i < n; ++i) {
      if (num[i] == -1) dfs(i);
    }
  }
};

int main() {
  int n, m; cin >> n >> m;
  Graph g(n);
  while (m--) {
    int s, t; cin >> s >> t;
    g.addEdge(s, t);
  }

  g.stronglyConnectedComponents();
  vector<int> id(n);
  for (int i = 0; i < g.scc.size(); ++i) {
    for (auto&& x : g.scc[i]) id[x] = i;
  }

  int q; cin >> q;
  while (q--) {
    int u, v; cin >> u >> v;
    cout << (id[u] == id[v]) << endl;
  }
  return 0;
}


#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define eps 1e-8

using namespace std;

string a3[3]={"aa.","..b","..b"};
string a4[4]={"aabc","ddbc","efgg","efhh"};
string a5[5]={"aabbc","dde.c","ffegg","..hij","..hij"};
string a6[6]={"aabbcc","ddeeff","ghi...","ghi...","...jkl","...jkl"};
string a7[7]={"aabbcc.","ddeef..","gg..fhh","..ij..k","..ij..k","....lmn","....lmn"};
string *ap[8]={NULL,NULL,NULL,a3,a4,a5,a6,a7};
string a[1005];

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	int n;
	cin>>n;
	if(n<3) cout<<"-1\n";
	else if(n==3){
		for(int i=0;i<3;i++)
			cout<<a3[i]<<"\n";
		cout<<"\n";
	}
	else{
		fill(a,a+n,string(n,'.'));
		while(n>=8){
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++)
					a[i+n-4][j+n-4]=a4[i][j];
			}
			n-=4;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				a[i][j]=ap[n][i][j];
		}
		n=a[0].size();
		for(int i=0;i<n;i++)
			cout<<a[i]<<"\n";
	}
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
int main(){
  for(;;){
    vector<int> lot(5);
    int ans = 0;
    if(scanf("%d",&lot[0]) == EOF) break;
    for(int i=1; i<5; i++) scanf(",%d",&lot[i]);
    sort(lot.begin(),lot.end());
    map<int,int> card;
    for(int i=0; i<5; i++) card[lot[i]]++;
    for(map<int,int>::iterator it = card.begin(); it!=card.end(); it++){
      if(it->second == 2) ans+=2;
      if(it->second == 3) ans+=3;
      if(it->second == 4) ans+=6;
    }
    if(ans == 2) cout <<"one pair"<<endl;
    if(ans == 3) cout <<"three card"<<endl;
    if(ans == 4) cout <<"two pair"<<endl;
    if(ans == 5) cout <<"full house"<<endl;
    if(ans == 6) cout <<"four card"<<endl;
    if(lot[0]+1 == lot[1] && lot[1]+1 == lot[2] && lot[2]+1 == lot[3] && lot[3]+1 == lot[4]) cout <<"straight"<<endl;
    else if(lot[0] == 1 && lot[1] == 10 && lot[2] == 11 && lot[3] == 12 && lot[4] == 13) cout <<"straight"<<endl;
    else if(ans == 0) cout<<"null"<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    intl len = s.length();
    if(len < 26){
        bool f[26];
        m0(f);
        rep(i,len)f[s[i] - 'a'] = true;
        rep(i,26){
            if(!f[i]){
                s += (char)(i + 'a');
                break;
            }
        }
    }
    else{
        vector<char> v;
        rep(i,len)v.pb(s[i]);
        next_permutation(all(v));
        string t = "";
        rep(i,26){
            t += v[i];
            if(s[i] != v[i])break;
        }
        s = t;
        if(s == "a")s = "-1";
    }
    cout << s << endl;
    return 0;
}

#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (n != 26) {
        vector<bool> flg(26, false);
        rep(i, n) flg[s[i]-'a'] = true;
        cout << s;
        rep(i, 26) {
            if (!flg[i]) {
                cout << (char)(i + 'a') << endl;
                return 0;
            }
        }
    }
    else {
        string t = s;
        if (!next_permutation(t.begin(), t.end())) {
            cout << -1 << endl;
            return 0;
        }
        rep(i, n) {
            cout << t[i];
            if (t[i] != s[i]) {
                cout << endl;
                break;
            }
        }
    }
    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

ll n;
st s;
vc a;
bool b;

void srch(ll z,ll f){
  if(z==0){
    a[0]='S';
  }
  else{
    a[0]='W';
  }
  if(f==0){
    a[1]='S';
  }
  else{
    a[1]='W';
  }
  FOR(i,1,n-1){
    if((a[i]=='S'&&s[i]=='o')||(a[i]=='W'&&s[i]=='x')){
      a[i+1]=a[i-1];
    }
    else{
      if(a[i-1]=='W'){
        a[i+1]='S';
      }
      else{
        a[i+1]='W';
      }
    }
  }
  b=true;
  rep(i,2){
    ll cnt=0;
    if(a[(n-1+i)%n]=='W'){
      cnt++;
    }
    if(s[(n-1+i)%n]=='x'){
      cnt++;
    }
    if(a[(n-2+i)%n]!=a[i%n]){
      cnt++;
    }
    if(cnt%2==1){
      b=false;
    }
  }
}
int main(){
  cin >> n >> s;
  a.resize(n);
  b=false;
  srch(0,0);
  if(b){
    rep(i,n){
      cout << a[i];
    }
    return 0;
  }
  srch(0,1);
  if(b){
    rep(i,n){
      cout << a[i];
    }
    return 0;
  }
  srch(1,0);
  if(b){
    rep(i,n){
      cout << a[i];
    }
    return 0;
  }
  srch(1,1);
  if(b){
    rep(i,n){
      cout << a[i];
    }
    return 0;
  }
  cout << -1 << endl;
}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1E5;
bool isSheep[MAXN];
bool o[MAXN];
bool options[2] = {true, false};

bool isValid(int n)
{
    bool firstSheep = isSheep[0];
    for (int i = 1; i < n; i++)
    {
         if (isSheep[i] && o[i] || !isSheep[i] && !o[i])
         {
             isSheep[(i + 1) % n] = isSheep[i - 1];
         }
         else if (isSheep[i] && !o[i] || !isSheep[i] && o[i])
         {
             isSheep[(i + 1) % n] = !isSheep[i - 1];
         }
    }
    if (isSheep[0] != firstSheep)
        return false;
    if (firstSheep && o[0] || !firstSheep && !o[0])
    {
        return isSheep[n - 1] == isSheep[1];
    }
    else
    {
        return isSheep[n - 1] != isSheep[1];
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        o[i] = c == 'o';
    }
    bool valid = false;
    for (bool s1 : options)
    {
        for (bool s2 : options)
        {
            isSheep[0] = s1;
            isSheep[1] = s2;
            if (isValid(n))
            {
                valid = true;
                break;
            }
        }
        if (valid)
            break;
    }
    if (valid)
    {
        stringstream ss;
        for (int i = 0; i < n; i++)
        {
            if (isSheep[i])
                ss << "S";
            else
                ss << "W";
        }
        cout << ss.str() << endl;
    }
    else
        cout << -1 << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
const int mod = 1e9+7;
const int inf = 2e9+10;

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

	int x, y; cin>>x>>y;
	long long ans1 = y>=x? y-x:inf, ans2 = -y>=x? -y-x+1:inf,
	ans3 = y>=-x? y+x+1:inf, ans4 = -y>=-x? -y+x+2:inf;

	cout << min(min(ans1, ans2), min(ans3, ans4)) <<'\n';
	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int h,w,n;
  cin>>h>>w>>n;
  if(w>h)swap(w,h);
  int ans=ceil((double)n/h);
  cout<<ans<<endl;

  return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const double EPS = 1e-9;

int main(){
	int l[10], v[2];
	while(scanf("%d,", &l[0])!=EOF){
		for(int i=1; i<10; i++){
			scanf("%d,", &l[i]);
		}
		scanf("%d,%d", &v[0], &v[1]);

		int total=0;
		for(int i=0; i<10; i++){
			total += l[i];
		}

		double t = (double)total/(v[0]+v[1]);
		double d = v[0]*t -EPS;
		int sum=0;
		for(int i=0; i<10; i++){
			sum += l[i];
			if(sum > d){
				cout << i+1 << endl;
				break;
			}
		}
	}
    return 0;
}