#include<stdio.h>
#include<limits.h>
#define NIL -1
static const int MAX = 500;
static const int INFTY = (1<<21);
int n, i, j, e, v, sum, u , minV;
main(){

  int M[MAX][MAX], key[MAX], L[MAX],A[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

  for(i = 0; i < n; i++){
    key[i] = INT_MAX;
    L[i] = NIL;
    A[i] = NIL;
  }

  key[0]=0;

  for(;;){

    u = NIL;

    minV = INT_MAX;

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

      if(key[i] < minV && A[i] == NIL){

        u = i;

        minV = key[i];

      }

    }
    if(u == NIL)break;

    A[u] = u;

    for(v = 0; v < n; v++){
      if(M[u][v] < key[v] && A[v] == NIL){
        key[v] = M[u][v];
        L[v] = u;
      }
    }
  }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( L[i] != -1 ) sum +=M[L[i]][i];
  }

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

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    map<int, int> mp;
    vector<ll> v;
    REP(i, N) {
        int x = ++mp[a[i]];
        if ((x & 1) == 0) {
            v.push_back(a[i]);
        }
    }
    sort(v.rbegin(), v.rend());
    if (v.size() >= 2)
        cout << (ll)v[0] * (ll)v[1] << endl;
    else
        cout << 0 << endl;
}


#include <stdio.h>

int main (){
    char all[20];
    scanf("%s", all);
    all[0] = '2';
    all[1] = '0';
    all[2] = '1';
    all[3] = '8';
    printf("%s", all);

    return 0;
}

#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        }
        if (res < 0) { res += _mod; } return res;
}

int main()
{
        string S;
        cin >> S;
        if (len(S) == 2) {
                cout << S << endl;
        } else {
                reverse(all(S));
                cout << S << endl;
        }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

#define BV_SIZE 64ULL // 64bit
#define MAX_BV_NUM 100 // m <= 100*64 = 6400

unsigned long long Peq[MAX_BV_NUM][0x100];
int levenshteinDistance(string a,string b) {
  int m=a.size(),n=b.size();
  int num_of_bv = (m + BV_SIZE -1) / BV_SIZE;

  for (int i = 0; i < m; i++) {
    Peq[i / BV_SIZE][a[i]] |= 1ULL << ((unsigned long long)i % BV_SIZE);
  }

  int score = m;
  unsigned long long Pv[MAX_BV_NUM], Mv[MAX_BV_NUM], Ph[MAX_BV_NUM], Mh[MAX_BV_NUM], Xv[MAX_BV_NUM], Xh[MAX_BV_NUM], Eq[MAX_BV_NUM], Xt[MAX_BV_NUM], Xa[MAX_BV_NUM];
  unsigned long long top = 1ULL << (((unsigned long long)m - 1ULL) % BV_SIZE);

  for(int i = 0; i < num_of_bv; i++) {
    Pv[i] = ~0ULL; Mv[i] = 0ULL;
  }

  for (int j = 0; j < n; j++) {
    for(int i = 0; i < num_of_bv; i++){
      Eq[i] = Peq[i][b[j]];
      Xv[i] = Eq[i] | Mv[i];
      Xt[i] = Eq[i] & Pv[i];
    }

    unsigned long long carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      Xa[i] = Xt[i] + Pv[i] + carry;
      if(Xt[i] == ~0ULL && carry == 1ULL){
        carry = 1ULL;
      }else{
        unsigned long long cXt = Xt[i] + carry;
        carry = (((cXt & Pv[i]) | ((cXt | Pv[i]) & ( ~ (cXt + Pv[i]) ))) >> 63ULL) & 1ULL;
      }
    }

    for(int i = 0; i < num_of_bv; i++){
      Xh[i] = (Xa[i] ^ Pv[i]) | Eq[i];

      Ph[i] = Mv[i] | ( ~ (Xh[i] | Pv[i]) );
      Mh[i] = Pv[i] & Xh[i];
    }

    if((Ph[num_of_bv - 1] & top) != 0ULL)score++;
    else if((Mh[num_of_bv - 1] & top) != 0ULL)score--;

    unsigned long long Ph_carry = 1ULL;
    unsigned long long Mh_carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      unsigned long long nxt_Ph_carry = (Ph[i] >> 63ULL) & 1ULL;
      Ph[i] = (Ph[i] << 1ULL) | Ph_carry;
      Ph_carry = nxt_Ph_carry;

      unsigned long long nxt_Mh_carry = (Mh[i] >> 63ULL) & 1ULL;
      Pv[i] = ((Mh[i] << 1ULL) | Mh_carry ) | ( ~ (Xv[i] | Ph[i]) );
      Mh_carry = nxt_Mh_carry;

      Mv[i] = Ph[i] & Xv[i];
    }

  }
  return score;
}

int main(){
	string a,b;
  cin>>a>>b;
  cout<<levenshteinDistance(a,b)<<endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define INF 10000000
typedef long long ll;
using namespace std;
const int MAX_N = 1001;
int d[MAX_N][MAX_N];
int main(){
        string ch1,ch2;
        cin >> ch1;
        cin >> ch2;
        rep(y,ch1.size()+1) rep(x,ch2.size()+1){
                if(y==0) {d[y][x]=x; continue;}
                if(x==0) {d[y][x]=y; continue;}

                int m_l_u = min(d[y-1][x]+1,d[y][x-1]+1);
                if(ch1[y-1] == ch2[x-1]) {
                        d[y][x] = min(m_l_u,d[y-1][x-1]);
                }else{
                        d[y][x] = min(m_l_u,d[y-1][x-1]+1);
                }

        }
        cout << d[ch1.size()][ch2.size()] << endl;
        return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100 + 47;

string s;
int ROW[MAX][MAX];
int COL[MAX][MAX];
int dp[3][MAX][MAX][MAX];

void Max(int& key, int val)
{
	key = max(key, val);
}

int getCol(int col, int i, int j)
{
	if (i > j) return 0;
	int res = COL[j][col];
	if (i) res -= COL[i - 1][col];
	return res;
}

int getRow(int row, int i, int j)
{
	if (i > j) return 0;
	int res = ROW[row][j];
	if (i) res -= ROW[row][i - 1];
	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int h, w, x, y;
	cin >> h >> w;
	FOR(i, 0, h)
	{
		cin >> s;
		FOR(j, 0, SZ(s))
		{
			if (s[j] == 'o')
			{
				COL[i][j] = 1;
				ROW[i][j] = 1;
			}

			if (j) ROW[i][j] += ROW[i][j - 1];
			if (i) COL[i][j] += COL[i - 1][j];

			if (s[j] == 'E')
			{
				x = i;
				y = j;
			}
		}
	}

	FILL(dp, -1);
	dp[0][0][0][0] = 0;
	int ans = 0;
	int C = 0;
	int N = 1;
	//cout << w << ""
	//cout << x << " " << y << endl;

	FOR(L, 0, w + 1)
	{
		FOR(R, 0, w + 1)
		{
			FOR(U, 0, h + 1)
			{
				FOR(D, 0, h + 1)
				{
					//cout << L << " " << R << " " << U << " " << D << endl;
					if (dp[C][R][U][D] == -1) continue;
					//cout << L << " " << R << " " << U << " " << D << ": " << dp[C][R][U][D] << endl;
					ans = max(ans, dp[C][R][U][D]);
					{
						int l = max(R, y - L);
						int r = min(y + R, w - 1 - L);

						if (h - 1 - x - U - D > 0)
						{
							Max(dp[C][R][U][D + 1], dp[C][R][U][D] + getRow(x + D + 1, l, r));
						}

						if (x - D - U > 0)
						{
							//cout << "*" << endl;
							Max(dp[C][R][U + 1][D], dp[C][R][U][D] + getRow(x - U - 1, l, r));
							//cout << dp[C][R][U + 1][D] << endl;
						}
					}

					{
						int l = max(D, x - U);
						int r = min(x + D, h - 1 - U);
						if (w - 1 - y - L - R > 0)
						{
							Max(dp[C][R + 1][U][D], dp[C][R][U][D] + getCol(y + R + 1, l, r));
						}

						if (y - L - R > 0)
						{
							Max(dp[N][R][U][D], dp[C][R][U][D] + getCol(y - L - 1, l, r));
						}
					}
				}
			}
		}

		swap(C, N);
		FOR(R, 0, w + 1)
		{
			FOR(U, 0, h + 1)
			{
				FOR(D, 0, h + 1)
				{
					dp[N][R][U][D] = -1;
				}
			}
		}
	}
	//FOR(L, 0, y + 1)
	//{
	//	FOR(R, 0, w - y)
	//	{
	//		FOR(U, 0, x + 1)
	//		{
	//			FOR(D, 0, h - x)
	//			{
	//				cout << L << " " << R << " " << U << " " << D << ": " << dp[L][R][U][D] << endl;
	//			}
	//		}
	//	}
	//}

	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

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

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

	int n;
	cin >> n;

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

	ll dp[n+1][6];
	ll INF = 1e18;

	rep(i, n+1) rep(j, 3) dp[i][j] = -INF;
	rep(i, 3) if(i < n) dp[i][i] = a[i];

	rep(i, n) rep(j, 3){
		for(int d = 0; j + d < 3; d++){
			int bef = i - 2 - d;
			if(bef < 0) continue;
			chmax(dp[i][j+d], dp[bef][j] + a[i]);
		}
	}

	ll ans = -INF;
	int d = 1 + n%2;
	rep(i, d+1){
		int j = n - 1 - i;
		if(j >= 0) chmax(ans, dp[j][d - i]);
	}

	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 10000000
#define rep(i,a,b) for(ll (i)=a;(i)<(ll)(b);(i)++)
using ipair = pair<ll,ll>;

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp

vector<vector<ll>> capacity;
vector<vector<ll>> flow;
vector<ll> pred;

//増加させることができる経路を探す
//可能経路は，predに保存される ex. pred[v] = u ... u->vの経路
bool findPath(ll s, ll t){
    ll N = capacity.size();
    pred.assign(N,-1);

    //幅優先探索
    queue<ll> que; que.push(s);
    while(!que.empty()){
        ll u = que.front(); que.pop();

        //Flowネットワークを調べる
        for(ll v=0;v<N;v++){
            //「経路がある」「先の点が未探索」「増加可能」
            if(capacity[u][v]>0 && pred[v]==-1 && capacity[u][v]>flow[u][v]){
                pred[v] = u;
                if (v== t) return true;
                que.push(v);
            }
        }
        //残余ネットワークを調べる
        for(ll v=0;v<N;v++){
            if(capacity[v][u]>0 && pred[v]==-1 && flow[v][u]>0){
                pred[v] = u;
                que.push(v);
            }
        }
    }
    return false;
}

//ネットワークを更新する．
void update(ll s, ll t){
    ll tmp,u,v,delta = INF;//増加分

    //最小の増加量をtargetから遡って探す
    v = t;
    while(v!=s){
        u = pred[v];
        if(capacity[u][v]>0) tmp = capacity[u][v] -flow[u][v];
        else if (capacity[v][u]>0) tmp = flow[v][u];
        delta = min(delta,tmp);
        v = u;
    }
    //求まった増加量を実際のネットワークに反映させる
    v = t;
    while(v!=s){
        u = pred[v];
        if(capacity[u][v]>0) flow[u][v] += delta;
        else if (capacity[v][u]>0) flow[v][u] -= delta;
        v = u;
    }
}

ll edmonds_karp(ll s, ll t){
    //増加経路を探索し，見つかったら更新する
    while(1){
        if(findPath(s,t)==false) break;
        else update(s,t);
    }
    ll ans = 0;
    for(ll v=0;v<capacity.size();v++) ans += flow[s][v];
    return ans;
}

int main(){
    ll N;
    cin >> N;
    ll nodeNum = N+N+2;
    capacity.assign((nodeNum),vector<ll>((nodeNum),0));
    flow.assign((nodeNum),vector<ll>((nodeNum),0));

    vector<ipair> red(N),blue(N);
    rep(i,0,N) cin >> red[i].first >> red[i].second;
    rep(i,0,N) cin >> blue[i].first >> blue[i].second;
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());

    //条件を満たすノードを追加
    rep(i,0,N){//blue
        rep(j,0,N){//red
            if(blue[i].first<=red[j].first) break;
            else if(blue[i].second>red[j].second) capacity[i][N+j]=1;
        }
    }
    //start[2N] -> blue -> red -> end[2N+1]
    rep(i,0,N){
        capacity[nodeNum-2][i] = 1;
        capacity[N+i][nodeNum-1] = 1;
    }

    cout << edmonds_karp(nodeNum-2,nodeNum-1) << endl;
}

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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

// 距離でやると困る
int main(){
    int N;
    cin >> N;

    int a[N], b[N], c[N], d[N];
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
    for(int i=0; i<N; i++) cin >> c[i] >> d[i];

    P rl[N];
    for(int i=0; i<N; i++){
        rl[i] = P(c[i], d[i]);
    }

    sort(rl, rl+N);

    int cnt = 0;
    bool used[N];
    fill(used, used+N, false);
    for(int i=0; i<N; i++){
        int rx = rl[i].first;
        int ry = rl[i].second;
        int mx = -1;
        int ind = -1;
        for(int j=0; j<N; j++){
            if(used[j]) continue;
            if(i == j) continue;
            if(rx <= a[j] || ry <= b[j]) continue;
            if(mx < b[j]){
                mx = b[j];
                ind = j;
            }
        }
        if(ind != -1){
            cnt++;
            used[ind] = true;
            // cout << i << " " << ind << endl;
        }
    }

    cout << cnt << endl;

    return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,m;cin>>n;
    string s;
    map<string,int> dic;
    for(int i=0;i<n;i++){
        cin>>s;
        dic[s]++;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>s;
        dic[s]--;
    }
    int ans=0;
    for(auto p:dic){
        auto v=p.second;
        if(v>ans)ans=v;
    }
    cout<<ans<<endl;
}

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

int main() {
	int n, k;

	cin >> n >> k;
	vector<int> x(n);
	rep(i, n)
		cin >> x[i];

	int ans=INT_MAX;
	for (int i = 0;i < n - k + 1;++i) {
		int l = x[i];
		int r = x[i + k - 1];
		int m = min(abs(l), abs(r)) + abs(l - r);
		ans = min(ans, m);
	}

	cout << ans << endl;
}


#include<iostream>
using namespace std;

int main(){
	int m, d, ans, month, i, total = 0;
	while(1){
		cin >> m >> d;
		if (m == 0) break;
		for(i = 1; i < m; i ++){
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
				total += 31;
			}
			else if(i == 2){
				total += 29;
			}
			else{
				total += 30;
			}
		}
		total += d;

		ans = total % 7;

		switch (ans){
		case 1:cout << "Thursday" << endl;
			break;
		case 2:cout << "Friday" << endl;
			break;
		case 3:cout << "Saturday" << endl;
			break;
		case 4:cout << "Sunday" << endl;
			break;
		case 5:cout << "Monday" << endl;
			break;
		case 6:cout << "Tuesday" << endl;
			break;
		case 0:cout << "Wednesday" << endl;
			break;
		}

		ans = 0, total = 0;
	}

	return 0;
}

#include <stdio.h>
int main(){
  int a,i;
  long long b,c,d,j;
  scanf("%d",&a);
  if(a==2){
    scanf("%lld %lld",&b,&c);
    if(b>c)i=c;
    else i=b;
    for(j=1;j<=i;j++)if(b%j==0&&c%j==0)printf("%lld\n",j);
  }else {
    scanf("%lld %lld %lld",&b,&c,&d);
    if(b<c&&b<d)i=b;
    if(c<b&&c<d)i=c;
    if(d<c&&d<b)i=d;
    for(j=1;j<=i;j++)if(b%j==0&&c%j==0&&d%j==0)printf("%lld\n",j);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int x,y;
  cin>>x>>y;
  if(x==0 || y==0){
    if(y>x)
      cout<<y+abs(x)<<endl;
    else
      cout<<abs(y)+x+1<<endl;
  }else if(x*y>0){
    if(x<y)
      cout<<y-x<<endl;
    else
      cout<<x-y+2<<endl;
  }else if(x*y<0)
    cout<<abs(abs(y)-abs(x))+1<<endl;
}

#include <iostream>

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

using namespace std;

int main(){
  int x, y;
  cin >> x >> y;
  // 入力終了

  // 1.初めにBを押すか押さないか決める
  // 2.Aを0回以上押す
  // 3.最後にBを押すか押さないか決める
  int firstB[2] = {-1, 1}, secondB[2] = {-1, 1};

  int ans = 2000000000;
  int tmpx, tmpy;
  rep(i, 2){
    rep(j, 2){
      int tmp = 0;
      // 初めにBを押すなら-xを代入，押さないならxを代入
      tmpx = x*firstB[i];
      if(firstB[i] == -1)
	tmp++;
      // 最後にBを押すなら-yを代入，押さないならyを代入
      tmpy = y*secondB[j];
      if(secondB[j] == -1)
	tmp++;

      // tmpx > tmpyなら，Aを押しても題意を満たさない
      if(tmpx > tmpy)
	continue;

      // tmpxからtmpyまでAを押す
      tmp = tmp + tmpy - tmpx;
      ans = min(ans, tmp);
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    ll N;
    cin >> N;

    if (N == 0) {
        print(0);
        return 0;
    }

    vector<pair<ll, ll>> v;

    ll l = 0, r = 0;
    ll c = 1;
    REP(i, 50) {
        v.eb(l, r);
        if (l <= N && N <= r) break;
        (i % 2 ? l : r) += c;

        c *= -2;
    }

    string S(v.size() - 1, '0');

    c /= -2;
    REVFOR(i, 1, v.size()) {
        if (v[i].fi <= N && N <= v[i].se && (v[i-1].fi > N || v[i-1].se < N)) {
            S[i - 1] = '1';
            N -= c;
        }

        c /= -2;
    }

    reverse(ALL(S));
    print(S);
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int merge(VI& a, int s1, int s2, int t){
  int i, j, res = 0;
  VI tmp;
  for(i=s1,j=s2;i<s2&&j<t;){
	if(a[i] > a[j]){
	  tmp.PB(a[j++]);
	  res += s2-s1-(i-s1);
	}
	else{
	  tmp.PB(a[i++]);
	}
  }
  while(i<s2) tmp.PB(a[i++]);
  while(j<t) tmp.PB(a[j++]);

  for(i=s1;i<t;++i)
	a[i] = tmp[i-s1];
  return res;
}

int sort(VI& a, int s, int t){
  if(s+1 >= t) return 0;
  int m = (s + t) / 2, res = 0;
  res += sort(a, s, m);
  res += sort(a, m, t);
  res += merge(a, s, m, t);
  return res;
}

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

  int N; cin >> N;
  VI a(N); REP(i,N) cin >> a[i];
  int ans = sort(a, 0, N);

  cout << a[0];
  REP(i,N-1) cout << " " << a[i+1];
  cout << endl;

  cout << ans << endl;

  return 0;
}


#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    int h, w;
    int h2;
    double w2;
    for (;;) {
	scanf("%d %d", &h, &w);
	if (h == 0 && w == 0)
	    return 0;

	int z = pow(h, 2) + pow(w, 2);
	w2 = sqrt(z);
	for(h2 = h+1; h2 < w2; h2++) {
	    w2 = sqrt(z - pow(h2, 2));
	    if (w2 == static_cast<int>(w2))
		break;
	}
	if(w2 <= h2) {
	    z++;
	    for (int flag = 0; flag == 0; z++) {
		for(h2 = 1; pow(h2,2) < z/2; h2++) {
		    w2 = sqrt(z - pow(h2, 2));
		    if (w2 == static_cast<int>(w2)) {
			flag = 1;
			break;
		    }
		}
	    }
	}
	printf("%d %d\n", h2, static_cast<int>(w2));
    }
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	vector<pair<int, pair<int,int>>>v;
	for (int i = 1; i <= 150; i++) {
		for (int j = i + 1; j <= 150; j++) {
			v.push_back({ i*i + j*j ,{i,j} });
		}
	}
	sort(v.begin(), v.end());
	cin >> H >> W;
	while (H) {
		bool flag = false;
		for (auto i : v) {
			if (flag) {
				cout << i.second.first << " " << i.second.second << endl;
				break;
			}
			if (i.second.first == H&&i.second.second == W) {
				flag = true;
			}
		}
		cin >> H >> W;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    string s; cin >> s;

    // 長さ2ならXXのみ
    if(s.size() == 2) {
        if(s[0] == s[1]) cout << 1 << " " << 2 << endl;
        else cout << -1 << " " << -1 << endl;
        return 0;
    }

    // XXがあったら出力して終了
    rep(i, s.size()-1) {
        if(s[i] == s[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }

    // XYXがあったら出力して終了
    rep(i, s.size()-2) {
        if(s[i] == s[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    // どれもなければ-1
    cout << -1 << " " << -1 << endl;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long ans[510][510];
int p[21000];
vector<int>v;
long long gcd(long long a,long long b){
	while(a){b%=a;swap(a,b);}return b;
}
int main(){
	int a;scanf("%d",&a);
	if(a==2){
		printf("4 7\n23 10\n");return 0;
	}
	p[0]=p[1]=-1;
	for(int i=2;i<21000;i++){
		if(p[i]!=-1){
			if(i>2)v.push_back(i);
			p[i]=1;
			for(int j=i+i;j<21000;j+=i)p[j]=-1;
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if((i+j)%2)continue;
			int X=(i+j)/2;
			int Y=(i-j+500)/2+500;
			long long ks=1;
			ks*=v[X];
			ks*=v[Y];
			ans[i][j]=ks;
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if((i+j)%2){
				long long cur=1;
				if(i)cur=cur/gcd(cur,ans[i-1][j])*ans[i-1][j];
				if(j)cur=cur/gcd(cur,ans[i][j-1])*ans[i][j-1];
				if(i<a-1)cur=cur/gcd(cur,ans[i+1][j])*ans[i+1][j];
				if(j<a-1)cur=cur/gcd(cur,ans[i][j+1])*ans[i][j+1];

				cur++;
				ans[i][j]=cur;
			}
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if(j)printf(" ");
			printf("%lld",ans[i][j]);
		}
		printf("\n");
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int ans = 111;
    rep(i,n){
        if(ans >= n){
            cout << ans;
            return 0;
        }
        ans +=111;
    }
}

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

int main(){
  int n;
  cin >> n;
  cout << ceil(n/111.0)*111 << endl;
  return 0;
}


#include <iostream>
using namespace std;

void call(int n) {
    for(int i=1;i<n+1;i++)
    {
        if( i%3==0 )
        {
            cout << " " << i;
        }
        else
        {
            int x = i;
            while(x>0)
            {
                if( x%10==3 )
                {
                    cout << " " << i;
                    break;
                }
                x = x/10;
            }
        }
    }
    cout << endl;
}

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

#include<stdio.h>
int main(void)
{
	int x,a,c;

	scanf("%d",&x);
		a=3;
	for(c=1;c<=x;c++){
		a=x*x*x;
	}
	printf("%d\n",a);

	return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// ?§?????????¨????????¨???????????????????¨???????????§???????
template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

template <typename T>
using Graph = vector< vector< Edge<T> > >;

// ??¢??????????±??????? (artPoints)
// ???????±??????? (bridges)

// ??¢?????????????????????????????¨????????£?????§???????????£???????????????????????????????????¨
// ????????????????????????????????£?????§???????????£????????????????????????????????¨

template <typename T>
struct graphLink {
    vector<int> ord, low, parent;
    vector< vector< Edge<T> > > G;
    vector< pair<int, int> > brdgs;
    int cnt, v;

    // init
    graphLink(int _n) : ord(_n, -1), low(_n, 0),
                        parent(_n, -1), G(_n), cnt(0), v(_n) {}

    bool is_bridge(int x, int y) {
        if(ord[x] > ord[y]) swap(x, y);
        return ord[x] < low[y];
    }

    // example: dfs(0);
    void dfs(int cur, int prev=-1) {
        low[cur] = cnt;
        ord[cur] = cnt++;

        for(auto x : G[cur]) {
            if(ord[x.to] < 0) {
                parent[x.to] = cur;
                dfs(x.to, cur);

                low[cur] = min(low[cur], low[x.to]);
            }
            else if(x.to != prev) {
                low[cur] = min(low[cur], ord[x.to]);
            }
            if(cur != x.to && is_bridge(cur, x.to)) {
                brdgs.emplace_back(make_pair(cur, x.to));
            }
        }
    }

    set<int> artPoints(int root) {
        set<int> se;
        int num = 0;
        rep(i,0,v) {
            // printf("%lld: %lld %lld\n", i, ord[parent[i]], low[i]);
            if(parent[i] < 0) continue;
            if(parent[i] == root) num++;
            else if(ord[parent[i]] <= low[i]) se.insert(parent[i]);
        }
        if(num >= 2) se.insert(0);
        return se;
    }

    // vp ??? ???????????±?????????
    set<pii> bridges(vector<pii> vp) {
        set<pii> se;
        rep(i,0,vp.size()) {
            if(ord[vp[i].first] < low[vp[i].second] || ord[vp[i].second] < low[vp[i].first]) {
                // se.insert(vp[i]);

                // ????????? (????????????????????????????????°???????????????????????§??\??????)
                int mi = min(vp[i].first, vp[i].second);
                int ma = max(vp[i].first, vp[i].second);
                se.insert(pii(mi, ma));
            }
        }
        return se;
    }
};

signed main() {
    int V, E; cin >> V >> E;
    graphLink<int> gr(V);
    rep(i,0,E) {
        int s, t; cin >> s >> t;
        gr.G[s].push_back(Edge<int>(t, 1));
        gr.G[t].push_back(Edge<int>(s, 1));
    }
    gr.dfs(0);
    set<int> ans = gr.artPoints(0);
    for(auto x : ans) cout << x << endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 1;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
ll n, m, x = 0, y,z,w,h, sum= 0, ans = 0;
string s, t;
int main() {
	cin >> h >> w; vector<vector<int>> a(h, vector<int>(w));
	rep(i, h) {
		rep(j, w) cin >> a[i][j];
	}vector<pair<int, int>> p,q;
	rep(i, h) {
		if (i % 2 == 0) {
			rep(j, w - 1) {
				if (a[i][j] % 2 == 1) {
					a[i][j + 1]++;
					sum++;
					p.push_back({ i,j });
					q.push_back({ i,j + 1 });
				}
			}
			if (a[i][w - 1] % 2 == 1 && i != h - 1) {
				a[i + 1][w - 1]++;
				sum++;
				p.push_back({ i,w - 1 });
				q.push_back({ i + 1,w - 1 });
			}
		}
		else {
			rrep(j, w) {
				if (a[i][j] % 2 == 1) {
					a[i][j - 1]++;
					sum++;
					p.push_back({ i,j });
					q.push_back({ i,j - 1 });
				}
			}
			if(a[i][0] % 2 == 1 && i != h - 1) {
				a[i + 1][0]++;
				sum++;
				p.push_back({ i,0 });
				q.push_back({ i + 1,0 });
			}
		}
	}
	cout << sum << endl;
	rep(i, p.size()) {
		cout << p[i].first + 1 << " " << p[i].second+ 1 << " " << q[i].first+1 << " ";
		cout << q[i].second + 1 << endl;
	}
}


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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //

// - library ------------- //

// --------- library end - //

int main(){

  ll N = il();
  vector<ll> as;
  rep(i, N){
    as.push_back(il());
  }

  // 構成可否判定
  if (as[0] != 0){
    cout << -1 << endl;
    return 0;
  }

  rep(i, N-1){
    // i : 0 ~ N-2
    if (as[i] < as[i+1]-1){
      cout << -1 << endl;
      return 0;
    }
  }

  // ここから必ず構成可能

  ll ans = 0;

  // i-as[i]があったらそれをキーとして値を1にする
  unordered_map<ll, ll> flags;

  DREP(i, N-1, -1){
    // i : N-1 ~ 0
    if (flags[i-as[i]] == 0){
      ans += as[i];
      flags[i-as[i]] = 1;
    }
  }

  cout << ans << endl;

}

#include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int parent;
};

node v[100];
vector<tuple<int, int, int>> cost;
vector<int> path;

int find(node x){
    if(x.parent == -1){
        REP(i, path.size())
            v[path[i]].parent = x.id;
        path.clear();
        return x.id;
    }
    else{
        path.push_back(x.id);
        return find(v[x.parent]);
    }
}

void marge(node x, node y){
    int x_id = find(x);
    int y_id = find(y);
    if(x_id == y_id)
        return;
    else
        v[y_id].parent = x_id;
    return;
}

bool judge(node x, node y){
    vector<int> xpath, ypath;
    return find(x) == find(y);
}

int main() {
    cin >> n;
    REP(i, n) REP(j, n) {
        int tmp;
        cin >> tmp;
        if(tmp != -1)
            cost.push_back(make_tuple(tmp, i, j));
    }
    REP(i, n){
        v[i].id = i;
        v[i].parent = -1;
    }
    sort(ALL(cost));
    REP(i, cost.size()){
        node from = v[get<1>(cost[i])];
        node to = v[get<2>(cost[i])];
        if(judge(from, to)){
            continue;
        }
        res += get<0>(cost[i]);
        marge(from, to);
    }

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


#include<iostream>
using namespace std;
int main ()
{
    int n, a, p, k;
    cin >> n;
    a = n / 100;
    k = a * 100 + a * 10 + a;
    p = (a + 1) * 100 + (a + 1) * 10 + a + 1;
    if(n <= k)
        cout << k;
    else
        cout << p;
    return 0;
}

#include <bits/stdc++.h>

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
int main() {
    cin >> n;
    for (int i = 1; i < 10; ++i) {
        if (i * 111 >= n) {
            cout << i * 111 << endl;
            exit(0);
        }
    }
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

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

  ll n,m; cin>>n>>m;
  auto v=divisor(m);

  ll ans=1;
  for(auto e: v){
    if(m-e*(n-1)>0 && (m-e*(n-1))%e==0) chmax(ans,e);
  }
  cout<<ans<<endl;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define p 1000000007
using namespace std;
namespace ywy{
	inline ll mi(int a,int b){
		ll ans=1,tmp=a;while(b){
			if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1;
		}return(ans);
	}int jc[5000001],jcny[5000001],dp[2022][2022];
	inline ll cnm(int n,int m){
		if(n<m)return(0);ll cjr=jc[n];cjr*=jcny[m];cjr%=p;cjr*=jcny[n-m];return(cjr%p);
	}
	inline void pre(int n){
		jc[0]=1;for(register int i=1;i<=n;i++)jc[i]=((ll)jc[i-1]*i)%p;jcny[n]=mi(jc[n],p-2);
		for(register int i=n-1;i>=0;i--)jcny[i]=((ll)jcny[i+1]*(i+1))%p;
	}
	void ywymain(){
		int n,k;cin>>n>>k;if(k==1){
			cout<<1<<endl;return;
		}pre(n*k);dp[1][0]=dp[1][1]=1;for(register int i=2;i<=n;i++){
			for(register int j=i;j>=0;j--){
				if(!j)dp[i][j]=dp[i][j+1];else{
					dp[i][j]=(dp[i][j+1]+((dp[i-1][j-1]*(ll)i)%p)*cnm(i*k-j-1,k-2))%p;
				}
			}
		}cout<<dp[n][0]<<endl;
	}
}
int main(){
	ywy::ywymain();return(0);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		string str;
		int out=0;
		int rui=0;
		int score=0;
		for(;out<3;){
			cin>>str;
			if(str=="HIT"){
				if(rui==3)score++;
				else rui++;
			}
			if(str=="HOMERUN"){
				score+=rui+1;
				rui=0;
			}
			if(str=="OUT"){
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

#include <iostream>
#include <string>

class Baseball{
public:
    Baseball();
    void init();
    int getPoint();
    void hit();
    void homerun();
    // @return false - the inning ends.
    bool out();

private:
    int point;
    unsigned int outs;
    bool base[3];
};

Baseball::Baseball(){
    init();
}

void Baseball::init(){
    point = 0;
    outs = 0;
    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

inline int Baseball::getPoint(){
    return point;
}

void Baseball::hit(){
    if (base[2]) {
        ++point;
    }
    for (int i=2; i>0; --i) {
        base[i] = base[i-1];
    }
    base[0] = true;
}

void Baseball::homerun(){
    ++point;    // batter's point
    // runner's point
    for (int i=0; i<3; ++i) {
        if (base[i]) {
            ++point;
        }
    }

    for (int i=0; i<3; ++i) {
        base[i] = false;
    }
}

bool Baseball::out(){
    ++outs;
    if (outs > 2) {
        return false;
    }else{
        return true;
    }
}

int main(){
    int n;  // number of data sets

    std::cin >> n;

    for (int i=0; i<n; ++i) {
        Baseball inning;
        std::string str;

        while (true) {
            std::getline(std::cin,str);
            if (str=="HIT"){
                inning.hit();
            }
            else if (str=="HOMERUN"){
                inning.homerun();

            }
            else if (str=="OUT"){
                if (!inning.out()) {
                    break;
                }
            }
        }

        // output
        std::cout << inning.getPoint() << std::endl;
    }

    return 0;
}


#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif

using namespace std;

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

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

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll ans = 0;
	ll a;
	double b, f;
	cin >> a >> b;
	ll w = b*100 + 0.01;

	ans = (a*w) / 100;

	cout << fixed << ans << endl;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        int a,b;
        cin>>a>>b;
        cout<<a*b;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool check = true;
    int C_place;

    //一個目
    if(s[0] != 'A'){
        check = false;
    }

    //二個目
    int cnt = 0;
    for(int i=2; i<n-1; i++){
        if(s[i] == 'C'){
            cnt++;
            C_place = i;
        }
    }
    if(cnt != 1) check = false;

    //三個目
    rep(i, n){
        if(i == C_place || i == 0) continue;
        if(!('a' <= s[i] && s[i] <= 'z')){
            check = false;
        }
    }
    cout << (check ? "AC" : "WA") << endl;
}
/*

一個ずつ判定する
・s[0] == 'A'
・2 <= i <= s.size()-2      cnt = 1
・上二つ以外の座標において'a' <= s[i] <= 'z'を満たす

*/

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll N; cin >> N;
	bool isPrime = true;
	vector<ll> div;
	for(ll i = 1; i * i <= N; i++) {
		if(N % i == 0) {
			if(i != 1) isPrime = false;
			div.push_back(i);
		}
	}
	ll n = div.back(), m = N / n;
	string ans = to_string(m);
	cout << ans.size() << endl;
	return 0;
}


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

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

    string ans = "Yes";
    if (s.at(a) != '-') {
        ans = "No";
    }
    for (int i = 0; i < a+b+1; i++) {
        if (i == a) continue;
        if (s.at(i) == '-') ans = "No";
    }

    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    double P1x,P1y,P2x,P2y;
    cin >> P1x >> P1y >> P2x >> P2y;
    printf("%.8lf\n", sqrt((P1x-P2x)*(P1x-P2x)+(P1y-P2y)*(P1y-P2y)));
    return 0;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(a<9 && b<9){
    cout<<"Yay!"<<"\n";
  }
  else{
    cout<<":("<<"\n";
  }
  return 0;
}

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

int main() {
  string a,b;
  cin>>a>>b;
  cout<<b<<a;
}


#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<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
    int n, ans;
    cin>>n;
    ans = n/11;
    bool f = 0;
    if(ans%2)f = 1;
    ans*=2;
    n%=11;
    if(f){
     if(n>5)ans+=2;
    else if(n) ans += 1;
    }
    else{
    if(n>6)ans+=2;
    else if(n) ans += 1;
    }
    cout<<ans<<endl;
}

int32_t main() {
   Fast;

   solve();
    return Okay;
}

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

long long int MOD = 1000000007;

int main() {
  long long int X;
  cin >> X;
  if (X % 11 == 0) cout << X / 11 * 2 << endl;
  else if (X % 11 <= 6) cout << X / 11 * 2 + 1 << endl;
  else cout << X / 11 * 2 + 2 << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
#include <cstring>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n, m; cin >> n >> m;
    vec<bool> ac(n, false);
    vec<int> wa(n, 0);

    int ans1 = 0, ans2 = 0;
    while (m--) {
        int p; cin >> p; --p;
        char s[3]; cin >> s;
        if (strcmp(s, "AC") == 0) {
            if (!ac[p]) {
                ++ans1;
                ans2 += wa[p];
            }
            ac[p] = true;
        }
        else {
            ++wa[p];
        }
    }

    cout << ans1 << ' ' << ans2 << endl;
}

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

// これだとWAになる・・・
int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> waCountMap;
    map<int, bool> acMap;
    int p;
    string s;
    for (int i = 0; i < M; i++) {
        cin >> p >> s;
        if (acMap.find(p) == acMap.end()) {
            if (s == "AC") {
                acMap[p] = true;
            } else {
                waCountMap[p]++;
            }
        }
    }
    int waCount = 0;
    for (auto itr = waCountMap.begin(); itr != waCountMap.end(); itr++) {
        if (acMap.find(itr->first) != acMap.end()) {
            waCount += itr->second;
        }
    }
    cout << acMap.size() << " " << waCount;
}


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

using namespace std;

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

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

int dis[110][110];
const int INF=100100100/3;

int main() {
	int n,k;
	int a,b,c,d,e;
	int x,y;
	while(cin>>n>>k,n){
		for(x=0;x<n;x++){
			for(y=0;y<n;y++){
				dis[x][y]=(x==y?0:INF);
			}
		}
		while(k--){
			if(in()==1){
				cin>>c>>d>>e;
				c--;d--;
				chmin(dis[c][d],e);
				chmin(dis[d][c],e);
				for(x=0;x<n;x++){
					for(y=0;y<n;y++){
						chmin(dis[x][y],dis[x][c]+dis[c][d]+dis[d][y]);
						chmin(dis[x][y],dis[x][d]+dis[d][c]+dis[c][y]);
					}
				}
			}else{
				cin>>a>>b;
				a--;b--;
				if(dis[a][b]==INF){
					cout<<-1<<endl;
				}else{
					cout<<dis[a][b]<<endl;
				}
			}
		}
	}
	return 0;
}

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

const int INF = 1<<25;

using namespace std;

int main()
{
	int n,m,i,j;
	int cost[101][101],time[101][101];

	for(;;)
	{
		cin >> n >> m ;
		if(n==0 && m==0)
			break;

		for(i=0;i<m+1;i++)
		{
			for(j=0;j<m+1;j++)
			{
				if(i!=j)
					cost[i][j]=time[i][j]=INF;
				else
					cost[i][j]=time[i][j]=0;
			}
		}

		for(i=0;i<n;i++)
		{
			int a,b,co,ti;
			cin >> a >> b >> co >> ti ;
			cost[a][b]=cost[b][a]=co;
			time[a][b]=time[b][a]=ti;
		}

		int inp;
		cin >> inp ;

		for(int k=0;k<m+1;k++)
		{
			for(i=0;i<m+1;i++)
			{
				for(j=0;j<m+1;j++)
				{
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
					time[i][j]=min(time[i][j],time[i][k]+time[k][j]);
				}
			}
		}

		for(i=0;i<inp;i++)
		{
			int st,en,se;
			cin >> st >> en >> se ;

			if(se==0)
				cout << cost[st][en] << endl;
			else
				cout << time[st][en] << endl;
		}
	}
}


int main() {
    int a;
    __builtin_scanf("%d", &a);
    __builtin_printf("%d\n", static_cast<int>(__builtin_pow(a, 3)));
}

#include<bits/stdc++.h>
using namespace std;
int main(void){
int input;
cin >> input;
cout << input*input*input << endl;
return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvin;
typedef vector<pair<ll,ll>> vpll;
typedef vector<pair<int,int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll x; cin>>x;
string ans;
while (x) {
  if (x%26) ans+=('a'+(x%26)-1);
  else {--x; ans+='z';}
  x/=26;
}
reverse (fall(ans));
cout<<ans;
return 0;
}

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

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

    if (N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

bool combox(pair<int,int> a,pair<int,int> b)
{
	int ta = a.FI * a.FI + a.SE * a.SE;
	int tb = b.FI * b.FI + b.SE * b.SE;

	if(ta > tb)
	{
		return true;
	}
	else if(ta == tb)
	{
		if(a.FI > b.FI)
			return true;
		else
			return false;
	}
	else
		return false;

}

int main()
{
	int h,w;
	while(cin>>h>>w,h|w)
	{
		  pair<int,int> p = MP(h,w);

		  pair<int,int> ans = MP(10*h,10*w);

		  bool flag = true;
		  for(int i = 3;i < h+w+50;i++)
		  {
			  flag = false;
			  for(int j = 1;j < i-j;j++)
			  {
				  pair<int,int> tmp =MP(j,i-j);
				  if(combox(tmp,p)&&combox(ans,tmp))ans = tmp;
			  }
		  }

		  cout << ans.FI << ' ' << ans.SE << endl;

	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

pair<int, int> nxt[256][256];

int main()
{
    int h, w;
    vector<pair<int, pair<int, int> > > v;

    for (int i = 1; i <= 150; i++){
        for (int j = i + 1; j <= 150; j++){
            v.push_back(make_pair(i * i + j * j, make_pair(i, j)));
        }
    }

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

    for (int i = 0; i < v.size() - 1; i++){
        pair<int, int> now = v[i].second, next = v[i + 1].second;
        nxt[now.first][now.second] = next;
    }

    while (scanf("%d %d", &h, &w) && w){
        printf("%d %d\n", nxt[h][w].first, nxt[h][w].second);
    }

    return (0);
}


const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"Yes", "No"};
string ANS[2] = {"YES", "NO"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double n, m, d;
    cin >> n >> m >> d;
    printf("%.9f", (m - 1) * (1 + (d != 0)) * (n - d) / n / n);
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    ll n,m,d;
    cin >> n >> m >> d;
    if(d == 0) cout << setprecision(10) << 1.0/(double)n*(double)(m-1) << endl;
    else cout << setprecision(10) << (double)(2*n - 2*d)/(double)(n*n)*(m-1) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

ll modPow(ll x, ll n) {
    ll ret = 1;
    while(n) {
        if(n&1LL) (ret *= x) %= MOD;
        n >>= 1;
        (x *= x) %= MOD;
    }
    return ret;
}

ll dp[41][(1<<17)+10];

int main(){
    int n;
    vi v(3);
    cin >> n;
    rep(i, 3) cin >> v[i];
    int sum_v = v[0] + v[1] + v[2];
    dp[0][0] = 1;
    auto check = [&](int mask) {
        bool f = true;
        f &= (mask >>=(v[2]-1)) & 1;
        f &= (mask >>=v[1]) & 1;
        f &= (mask >>=v[0]) & 1;
        return f;
    };
    auto pop_mask = [&](int mask) {
        if(mask == 0) return 0;
        bool f = true;
        repr(i, sum_v) {
            if(mask & (1<<i)) {
                if(f) {
                    mask -= (1<<i);
                    f = false;
                    break;
                }
            }
        }
        return mask;
    };
    auto getSize = [&](int mask) {
        if(mask == 0) return 0;
        repr(i, sum_v) {
            if(mask&(1<<i)) {
                return i+1;
            }
        }
        return 0;
    };
    auto push_mask = [&](int mask, int add) {
        if(add > sum_v) return 0;
        while(getSize(mask)+add > sum_v) {
            mask = pop_mask(mask);
        }
        mask <<= add;
        mask |= 1<<(add-1);
        return mask;
    };
    rep(i, n) rep(mask, 1<<sum_v) {
        REP(k, 1, 11) {
            int nxt = push_mask(mask, k);
            if(check(mask) || check(nxt)) continue;
            (dp[i+1][nxt] += dp[i][mask]) %= MOD;
        }
    }
    ll sum = 0LL;
    rep(mask, 1<<sum_v) (sum += dp[n][mask]) %= MOD;
    ll ans = modPow(10, n);
    (ans += MOD - sum) %= MOD;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i,n) cin >> A[i];
  sort(A.begin(),A.end());
  rep(i,n-1){
    if(A[i]!=A[i+1])continue;
    cout << "NO" <<endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<string> s(N);
  int g=0;
  int ans=0;
  string tans;
  for(int i=0;i<N;i++){
    cin>>s.at(i);
  }
  int M;
  cin>>M;
  vector<string> t(M);
  for(int i=0;i<M;i++){
    cin>>t.at(i);
  }
  for(int i=0;i<N;i++){
    tans=s.at(i);
    g=0;
    for(int j=0;j<N;j++){
      if(tans==s.at(j)){
        g++;
      }
    }
    for(int j=0;j<M;j++){
      if(tans==t.at(j)){
        g--;
      }
    }
    if(i==0){
      ans=g;
    }
    if(i!=0){
      if(ans<g){
        ans=g;
      }
    }
  }
  if(ans<=0){
    ans=0;
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int p = 1000005;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;
	return 0;
}

#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 <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	string S;
	cin >> S;
	long long streaks = 0;
	long long max_streaks = 0;
	for (auto s : S) {
		if (s == 'R') {
			++streaks;
		}
		else {
			max_streaks = max(streaks, max_streaks);
			streaks = 0;
		}
	}
	max_streaks = max(streaks, max_streaks);

	cout << max_streaks << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

class Solution {
  public:
    int Solve(int N, int K) {
        if (N % K == 0)
            return 0;
        else
            return 1;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    Solution s;
    cout << s.Solve(n, k) << endl;

    return 0;
}

#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
  	cin >> a >> b;
  	if( a % b == 0 ) cout << 0;
    else cout << 1;
}


#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int>PP;
int n;
int board[1005][1005];
void paint4(int ni, int nj) {
	board[ni][nj] = 1;
	board[ni][nj + 1] = 1;
	board[ni][nj + 2] = 3;
	board[ni][nj + 3] = 4;
	board[ni + 1][nj] = 2;
	board[ni + 1][nj + 1] = 2;
	board[ni + 1][nj + 2] = 3;
	board[ni + 1][nj + 3] = 4;
	board[ni + 2][nj] = 5;
	board[ni + 2][nj + 1] = 6;
	board[ni + 2][nj + 2] = 7;
	board[ni + 2][nj + 3] = 7;
	board[ni + 3][nj] = 5;
	board[ni + 3][nj + 1] = 6;
	board[ni + 3][nj + 2] = 8;
	board[ni + 3][nj + 3] = 8;
}
void paint(int ni, int nj, int N) {
	board[ni][nj] = 1;
	board[ni][nj + 1] = 1;
	board[ni][nj + 2] = 2;
	board[ni + 1][nj] = 3;
	board[ni + 1][nj + 2] = 2;
	board[ni + 2][nj] = 3;
	board[ni + 2][nj + 1] = 4;
	board[ni + 2][nj + 2] = 4;
	for (int i = ni; i<ni + 3; i++) {
		for (int j = nj + 3; j < nj + N; j += 2) {
			if (((j - 3) / 2) & 1) {
				board[i][j] = 5 + i % 2;
				board[i][j + 1] = 5 + i % 2;
			}
			else {
				board[i][j] = 6 + i % 2;
				board[i][j + 1] = 6 + i % 2;
			}
		}
	}
	for (int i = ni + 3; i < ni + N; i += 2) {
		for (int j = nj; j<nj + 3; j++) {
			if (((i - 3) / 2) & 1) {
				board[i][j] = 7 + j % 2;
				board[i + 1][j] = 7 + j % 2;
			}
			else {
				board[i][j] = 8 + j % 2;
				board[i + 1][j] = 8 + j % 2;
			}
		}
	}
}
bool hante() {
	set<int>S1;
	rep(i, n)if (board[i][0])S1.insert(board[i][0]);
	if (S1.size() != 4)return false;
	rep(i, n) {
		set<int>S;
		rep(j, n)if (board[i][j])S.insert(board[i][j]);
		if (S1.size() != S.size())return false;
	}
	rep(i, n) {
		set<int>S;
		rep(j, n)if (board[j][i])S.insert(board[j][i]);
		if (S1.size() != S.size())return false;
	}
	return true;

}
void disp() {
	rep(i, n) {
		rep(j, n) {
			if (board[i][j] == 0)cout << '.';
			else cout << (char)('a' + board[i][j]);
		}
		cout << endl;
	}
	cout << endl;
}
void search(int ni, int nj, int num) {
	if (ni == n) {
		if (hante())disp();
		return;
	}
	int mi = ni, mj = nj + 1;
	if (mj == n) {
		mj = 0; mi++;
	}
	if (board[ni][nj] == 0) {
		if (nj != n - 1 && board[ni][nj + 1] == 0) {
			board[ni][nj] = num;
			board[ni][nj + 1] = num;
			search(mi, mj, num + 1);
			board[ni][nj] = 0;
			board[ni][nj + 1] = 0;
		}
		if (ni != n - 1 && board[ni + 1][nj] == 0) {
			board[ni][nj] = num;
			board[ni + 1][nj] = num;
			search(mi, mj, num + 1);
			board[ni][nj] = 0;
			board[ni + 1][nj] = 0;
		}
	}
	search(mi, mj, num);
}
signed main() {
	cin >> n;

	//	search(0,0,1);

	if (n == 2)cout << -1 << endl;
	else if (n == 7) {
		string s[7] = {
			"..bcd..",
			"..bcd..",
			"hhqq.oo",
			"ii..wnn",
			"jj..wpp",
			"..akl..",
			"..akl.."
		};
		rep(i, 7)cout << s[i] << endl;
	}
	else if (n == 11) {
		string s[11] = {
			"..bcd......",
			"..bcd......",
			"hhqq.oo....",
			"ii..wnn....",
			"jj..wpp....",
			"..akl......",
			"..akl......",
			".......aabc",
			".......ddbc",
			".......abff",
			".......abgg"
		};
		rep(i, 11)cout << s[i] << endl;
	}
	else if (n % 3 == 0) {
		for (int i = 0; i<n; i += 3)paint(i, i, 3);
		disp();
	}
	else {
		rep(i, n + 1) {
			rep(j, n + 1) {
				if (5 * i + 4 * j == n) {
					for (int m = 0; m < 5 * i; m += 5)paint(m, m, 5);
					for (int m = 5 * i; m < n; m += 4)paint4(m, m);
					goto X;
				}
			}
		}
	X:;
		disp();
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][N];
bool mark[N][N][N];
int n;

ld solve(int t1, int t2, int t3) {
	int t0 = n - (t1 + t2 + t3);
	if (t0 == n)
		return 0;
	ld &ans = dp[t1][t2][t3];
	if (mark[t1][t2][t3])
		return ans;
	mark[t1][t2][t3] = 1;
	ans = 1;
	if (t1)
		ans += solve(t1 - 1, t2, t3) * ((ld) t1 / n);
	if (t2)
		ans += solve(t1 + 1, t2 - 1, t3) * ((ld) t2 / n);
	if (t3)
		ans += solve(t1, t2 + 1, t3 - 1) * ((ld) t3 / n);
	ans /= (1 - ((ld)t0 / n));
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t[4] = {};
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		t[a]++;
	}
	cout << fixed << setprecision(12) << solve(t[1], t[2], t[3]);
	return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,q,count=0; cin>>n;
    long long S[10001],T[501];
    for(int i=0;i<n;i++) cin>>S[i];
    cin>>q; bool x =false;
    for(int j=0;j<q;j++) cin>>T[j];
    for(int j=0;j<q;j++){
        x=false;
        for(int i=0;i<n;i++){
            if(S[i]==T[j]&&x==false){
                count++; x=true;
            }

        }
    }
    cout<<count<<endl;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
//#define INF (1e9+1)
#define INF (1LL<<59)

#define int ll

signed main(){
    int v,e;
    cin>>v>>e;
    int d[101][101];
    rep(i,101)rep(j,101)d[i][j] = INF;
    rep(i,101)d[i][i] = 0;

    rep(i,e){
        int s,t,c;
        cin>>s>>t>>c;
        d[s][t] = c;
    }

    rep(k,v){
        rep(i,v){
            rep(j,v){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    rep(i,v){
        if(d[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }

    rep(i,v){
        rep(j,v){
            if(j)cout<<" ";
            int res=d[i][j];
            if(res>=INF/2)cout<<"INF";
            else cout<<res;
        }
        cout<<endl;
    }
}

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename W>
struct N003 {
   typedef std::vector<long> LI;
   typedef std::vector<W>    LW;
   long n, e;
   LI ss, ds;
   LW ws;
   std::vector<LI> iss;
   N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
      : n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
      iss.resize(n+1);
      for(long i = 0; i < e; ++i) {
         iss[ss[i]].push_back(i);
      }
   }
};

template<typename W>
struct N006 {
   std::vector<std::vector<W>> xss;
   bool negativeCycle;
   N006(const N003<W>& g, W inf) : negativeCycle(false) {
      xss.resize(g.n+1);
      for(auto& xs : xss) xs.resize(g.n+1, inf);
      for(long i = 0; i < g.n+1; ++i) xss[i][i] = 0;
      for(long i = 0; i < g.e; ++i) {
         xss[g.ss[i]][g.ds[i]] = g.ws[i];
      }
      for(long z = 0; z < g.n+1; ++z) {
         for(long x = 0; x < g.n+1; ++x) {
            for(long y = 0; y < g.n+1; ++y) {
               W d = xss[x][y];
               W nd = xss[x][z] + xss[z][y];
               xss[x][y] = std::min(d, nd);
            }
         }
      }
      for(long x = 0; x < g.n+1; ++x) {
         for(long y = 0; y < g.n+1; ++y) {
            if( xss[x][y] >= inf / 2 ) {
               xss[x][y] = inf;
            }
         }
         if( xss[x][x] < 0 ) {
            negativeCycle = true;
         }
      }
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      typedef std::vector<long> LI;
      long v, e;
      scan(v, e);
      LI ss(e+1), ds(e+1);
      LI ws(e+1);
      for(long i = 0; i < e; ++i) {
         scan(ss[i], ds[i], ws[i]);
      }
      N003<long> g(v, ss, ds, ws);
      N006<long> warshallfloyd(g, (1LL << 60));
      if( warshallfloyd.negativeCycle ) {
         puts("NEGATIVE CYCLE");
      }
      else {
         for(long i = 0; i < v; ++i) {
            for(long k = 0; k < v; ++k) {
               if( warshallfloyd.xss[i][k] == (1LL << 60) ) {
                  printf("INF");
               }
               else {
                  printf("%ld", warshallfloyd.xss[i][k]);
               }
               putchar( k == v - 1 ? '\n' : ' ');
            }
         }
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}


#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

class dice{
public:
    int top, bottom, right, left, front, back;
    void North();
    void East();
    void South();
    void West();
};
void dice:: North(){
    int tmp = top;
    top = front;
    front = bottom;
    bottom = back;
    back = tmp;
}
void dice:: East(){
    int tmp = top;
    top = left;
    left = bottom;
    bottom = right;
    right = tmp;
}
void dice:: South(){
    int tmp = top;
    top = back;
    back = bottom;
    bottom = front;
    front = tmp;
}
void dice:: West(){
    int tmp = top;
    top = right;
    right = bottom;
    bottom = left;
    left = tmp;
}

signed main(){
    dice d;
    cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
    string s;
    cin >> s;
    rep(i, 0, s.size()){
        // switch (s[i]){
            // case 'N': d.North();
            //case 'E': d.East();
            //case 'S': d.South();
            //case 'W': d.West();
        if(s[i] == 'N') d.North();
        else if(s[i] == 'E') d.East();
        else if(s[i] == 'S') d.South();
        else if(s[i] == 'W') d.West();
           // cout << d.top << endl;
    }
    cout << d.top << endl;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int siz[6], damy;
	char mozi[2];
	for (int abc = 0; abc < 6; abc++) {
		cin >> siz[abc];
	}
	fgets(mozi,2,stdin);
	while(true){
		fgets(mozi,2,stdin);
		if (mozi[0] == '\n') {
			cout << siz[0] << endl;
			break;
		}
		switch (mozi[0]) {
		case 'S':
			damy = siz[0];
			siz[0] = siz[4];
			siz[4] = siz[5];
			siz[5] = siz[1];
			siz[1] = damy;
			break;
		case 'E':
			damy = siz[0];
			siz[0] = siz[3];
			siz[3] = siz[5];
			siz[5] = siz[2];
			siz[2] = damy;
			break;
		case 'N':
			damy = siz[0];
			siz[0] = siz[1];
			siz[1] = siz[5];
			siz[5] = siz[4];
			siz[4] = damy;
			break;
		case 'W':
			damy = siz[0];
			siz[0] = siz[2];
			siz[2] = siz[5];
			siz[5] = siz[3];
			siz[3] = damy;
			break;
		}
	}
	return 0;
}


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

int main () {
	int a,b,n,i;
	char c;
	string str,s,f,g;
	cin >> str;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> s >>a >> b;
		if(s[2]=='i'){cout << str.substr(a,b-a+1) << endl;}
		else if(s[2]=='v'){
			f=str.substr(a,b-a+1);
			reverse(f.begin(),f.end());
			str = str.replace(a,b-a+1,f);
		}
		else if(s[2]=='p'){
			cin >> g;
			str = str.replace(a,b-a+1,g);
		}
	}
}

/***

    Muhammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/

#include<bits/stdc++.h>

/**Definitions**/

#define   ld             long double
#define   ll             long long
#define   boost_         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define   pb             push_back
#define   ppb            pop_back
#define   ull            unsigned long long
#define   over           return 0
#define   scan(i,n,a)    for(i=0;i<n;i++) cin>>a[i]
#define   MP             make_pair
#define   spc            " "

using namespace std;

/** Predefined Functions **/

int gcd(int x,int y){
    if(x==0) return y;
    else return gcd(y%x,x);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }

/** Main Function **/

int main(){

    boost_;
    ll n;
    cin>>n;
    ll a[n],i,a1=0,a2=0,a3=0;
    vector<ll>v,q;
    map<ll,ll>mp;
    scan(i,n,a);

    sort(a,a+n,greater<int>());

    for(i=0;i<n;++i){
        mp[a[i]]++;
        if(mp[a[i]]==1) q.pb(a[i]);
    }

    for(i=0;i<q.size();++i){
        if(mp[q[i]]>=2) v.pb(q[i]);
        if(v.size()==2) break;
    }
    if(v.size()==0) cout<<0<<endl;
    else{

       if(v.size()==1){if(mp[v[0]]>=4) cout<<v[0]*v[0]<<endl; else cout<<0<<endl;}
       else{
           if(mp[v[0]]>=4) cout<<v[0]*v[0]<<endl;
           else cout<<v[0]*v[1]<<endl;
       }
    }

    over;
}


#include<stdio.h>
int main()
{
    int D,T,S;
    scanf("%d%d%d",&D,&T,&S);
    if((T*S) >= D)printf("Yes");
    else printf("No");

}

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

int main(){
  int N,K;
  cin>>N>>K;
  if(N%K!=0){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}


#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>
#include<unordered_map>
#include<unordered_set>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

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

int main()
{
	IO;
	int n{},res{},ans{},f{};
	cin>>n;
	vector<ll>v(n);
	For(i,0,n)cin>>v[i];
	while(true){
		For(i,0,n)
		{
			if(v[i]&1){f=1;break;}
			else if(!(v[i]%2))res++,v[i]/=2;
		}
		if(f){cout<<ans<<'\n';break;}
		if(res==n)ans++;
		res=0;
	}
//	system("pause");
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int kai(int a) {
	int n = 0;
	while (1) {
		if (a % 2 == 0) {
			a = a / 2;
			n++;
		}
		else break;
	}
	return n;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int count = 100000;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		count = min(kai(A[i]), count);
	}
	cout << count << endl;
	return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    for(;;){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)break;
        vector<int> ns(n+1);
        for(int i=0;i<n;i++){
            scanf("%d",&ns[i]);
        }
        ns[n]=0;
        vector<int> ntwos;
        for(int i=0;i<n+1;i++){
            for(int j=i;j<n+1;j++){
                ntwos.push_back(ns[i]+ns[j]);
            }
        }
        sort(ntwos.begin(),ntwos.end());
        int ma=0;
        for(int i=0;i<ntwos.size();i++){
            vector<int>::iterator it;
            if((it=upper_bound(ntwos.begin(),ntwos.end(),m-ntwos[i]))!=ntwos.begin()){
                ma=max(ma,ntwos[i]+*(it-1));
            }
        }
        printf("%d\n",ma);
    }
}

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

int main(){
    int N,Q;
    while( cin >> N >> Q, N||Q ){
        vector<int> date(100, 0);
        for(int i = 0; i < N; i++){
            int m;
            cin >> m;
            for(int j = 0; j < m; j++){
                int a;
                cin >> a;
                date[a] += 1;
            }
        }
        int most_conv, max_v = 0;
        for(int i = 0; i < 100; i++){
            if( date[i] > max_v ){
                most_conv = i;
                max_v = date[i];
            }
        }
        if( max_v >= Q ) cout << most_conv << endl;
        else cout << 0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

bool dfs(int now, vector<vector<int>> &g, set<int> &used, vector<int> &route, vector<bool> &memo) {
    if (!memo[now]) return false;
    memo[now] = false;
    used.insert(now);
    route.push_back(now);

    for (int to : g[now]) {
        if (contain(used, to)) return true;
        bool ok = dfs(to, g, used, route, memo);
        if (ok) return true;
    }

    route.pop_back();
    used.erase(now);
    return false;
}

vector<int> min_cycle(int n, vector<vector<int>> &g, vector<int> &route) {
    map<int, int> used;
    rep(i, route.size()) used[route[i]] = i;

    rep(i, route.size()) {
        int now = route[i];
        int next = -1;

        for (int to : g[now]) {

            if (used.find(to) == used.end()) continue;
            int next_i = used[to];
            if (next_i > i) {
                // 次以降
                continue;
            }
            // 手前
            cmax(next, next_i);

        }

        if (next != -1) {
            // 切った。
            vector<int> ans;
            for (int j = next; j <= i; j++) ans.push_back(route[j]);
            return ans;
        }

    }

    return route;
}

int main() {
//    ifstream cin("C:\\Users\\riku\\Downloads\\case_30.txt");

    int n, m;
    cin >> n >> m;
    vector<P> v(m);
    for (P &p:v) cin >> p.first >> p.second, p.first--, p.second--;

    vector<vector<int>> g(n);
    for (P p: v) g[p.first].push_back(p.second);

    vector<bool> memo(n, true);
    vector<int> route = [&]() {
        rep(i, n) {
            set<int> used;
            vector<int> route;
            bool ok = dfs(i, g, used, route, memo);
            if (ok) {
                return route;
            }
        }
        return vector<int>(0);
    }();

    if (route.empty()) {
        cout << -1 << endl;
        ret();
    }
    route = min_cycle(n, g, route);

    vector<ll> costs(n, INF);
    vector<ll> pre(n, -1);

    queue<int> q;
    q.push(route.front());
    costs[route.front()] = 0;

    while (!q.empty()) {
        int now = q.front();
        q.pop();
        ll next_cost = costs[now] + 1;
        for (int next : g[now]) {
            if (next_cost < costs[next]) {

                q.push(next);
                costs[next] = next_cost;
                pre[next] = now;
            }
        }
    }

    int now = route.back();
    vector<int> ans;
    while (now != route.front()) {
        ans.push_back(now);
        now = pre[now];
    }
    ans.push_back(now);

    cout << ans.size() << endl;
    for (int a : ans) cout << a + 1 << endl;

//    for (P p : v) {
//        if (find(ans.begin(), ans.end(), p.first) != ans.end() && find(ans.begin(), ans.end(), p.second) != ans.end()) {
//            cout << p.first + 1 << ' ' << p.second + 1 << endl;
//        }
//    }

}

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

int main() {
    int n, m;
    cin >> n >> m;
    int all_path[2];
    all_path[0] = 1;
    all_path[1] = n;
    rep(i, m){
        int l, r;
        cin >> l >> r;
        if(all_path[0] < l) all_path[0] = l;
        if(r < all_path[1]) all_path[1] = r;
    }
    if (all_path[1] < all_path[0])cout << 0 << endl;
    else cout << all_path[1] - all_path[0] + 1 << endl;
}


#include <iostream>
#include <string>

using namespace std;

class DICE {
public:
	int top;
	int bottom;
	int right;
	int left;
	int front;
	int back;
	void South();
	void North();
	void East();
	void West();
};

void DICE::South() {
	int kari = front;
	front = top;
	top = back;
	back = bottom;
	bottom = kari;
}

void DICE::North() {
	int kari = front;
	front = bottom;
	bottom = back;
	back = top;
	top = kari;
}

void DICE::West() {
	int kari = top;
	top = left;
	left = bottom;
	bottom = right;
	right = kari;
}

void DICE::East() {
	int kari = top;
	top = right;
	right = bottom;
	bottom = left;
	left = kari;
}

int main() {
	DICE d;
	cin >> d.top >> d.front >> d.left >> d.right >> d.back >> d.bottom;
	string a;
	cin >> a;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'S') {
			d.South();
		} else if (a[i] == 'N') {
			d.North();
		} else if (a[i] == 'E') {
			d.East();
		} else {
			d.West();
		}
	}
	cout << d.top << endl;
	return 0;
}

#include <iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.size()-1; i++){
		if(s[i]=='A'&&s[i+1]=='C'){
			cout << "Yes" << endl;
			exit(0);
		}
		if(s[i]=='a'&&s[i+1]=='c'){
			cout << "Yes" << endl;
			exit(0);
		}
	}
	cout << "No" << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 2e5 + 7;

vector <pair <int, int>> who[N];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  for (int a = -1000; a <= 1000; ++a) {
    for (int b = -1000; b <= 1000; ++b) {
      if (a * a + b * b < N) {
        who[a * a + b * b].push_back({a, b});
      }
    }
  }

  int n, d1, d2;
  cin >> n >> d1 >> d2;
  int m = 2 * n;
  vector <vector <int>> g1(m * m), g2(m * m);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      for (auto p : who[d1]) {
        int x = i + p.first, y = j + p.second;
        if (0 <= x && x < m && 0 <= y && y < m) {
          g1[i * m + j].push_back(x * m + y);
        }
      }
      for (auto p : who[d2]) {
        int x = i + p.first, y = j + p.second;
        if (0 <= x && x < m && 0 <= y && y < m) {
          g2[i * m + j].push_back(x * m + y);
        }
      }
    }
  }
  vector <int> c1(m * m, -1), c2(m * m, -1);
  function <void(int, vector <vector <int>> &, vector <int> &)> dfs = [&] (int u, vector <vector <int>> &g, vector <int> &c) {
    for (auto v : g[u]) {
      if (c[v] == -1) {
        c[v] = c[u] ^ 1;
        dfs(v, g, c);
      }
    }
  };
  for (int i = 0; i < m * m; ++i) {
    if (c1[i] == -1) {
      c1[i] = 0;
      dfs(i, g1, c1);
    }
  }
  for (int i = 0; i < m * m; ++i) {
    if (c2[i] == -1) {
      c2[i] = 0;
      dfs(i, g2, c2);
    }
  }
  for (int t1 = 0; t1 < 2; ++t1) {
    for (int t2 = 0; t2 < 2; ++t2) {
      vector <pair <int, int>> have;
      for (int i = 0; i < m * m; ++i) {
        if (c1[i] == t1 && c2[i] == t2) {
          have.push_back({i / m, i % m});
        }
      }
      if ((int)have.size() >= n * n) {
        for (int i = 0; i < n * n; ++i) {
          cout << have[i].first << ' ' << have[i].second << '\n';
        }
        return 0;
      }
    }
  }
}

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

const int N = 610;

int n, col[N][N], cnt[3];
vector<pair<int,int>> diff;

void dfs(int x, int y, int c) {
    if (x >= 0 && x < 2*n && y >= 0 && y < 2*n && col[x][y] == 0) {
        col[x][y] = c;
        cnt[c]++;
        for (auto d : diff) dfs(x+d.first, y+d.second, 3-c);
    }
}

int main() {
    cin >> n;

    int iter = 2; while (iter--) {
        // calcular arcos
        int d; cin >> d;
        diff.clear();
        for (int dx = 0; dx < 2*n; dx++)
            for (int dy = 0; dy < 2*n; dy++)
                if (dx*dx + dy*dy == d) {
                    diff.emplace_back(dx,dy);
                    diff.emplace_back(-dx,dy);
                    diff.emplace_back(dx,-dy);
                    diff.emplace_back(-dx,-dy);
                }

        // partir bipartito
        for (int i = 0; i < 2*n; i++)
            for (int j = 0; j < 2*n; j++) if (col[i][j] == 0)
                dfs(i,j,1);

        // quedarse con particion mayor
        int best = (cnt[1] > cnt[2] ? 1 : 2);
        for (int i = 0; i < 2*n; i++)
            for (int j = 0; j < 2*n; j++)
                col[i][j] = (col[i][j] == best ? 0 : 3);
    }

    int need = n*n;
    for (int i = 0; i < 2*n; i++)
        for (int j = 0; j < 2*n; j++) if (col[i][j] == 0) {
            cout << i << ' ' << j << endl;
            if (--need == 0) return 0;
        }

    return 0;
}


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

int main(void)
{
	int n;

	scanf("%d", &n);
	while(n-- > 0){
		int base[3] = {0};
		int score = 0;
		char s[10];
		int out = 0;
		while(out < 3){
			scanf("%s", s);
			string str = s;
			if(str == "HIT"){
				if(base[2] == 1) score++;
				base[2] = base[1];
				base[1] = base[0];
				base[0] = 1;
			}
			else if(str == "HOMERUN"){
				score += base[0];
				score += base[1];
				score += base[2];
				score++;
				base[0] = base[1] = base[2] = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", score);
	}

	return(0);
}

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string str;
	int n;
	int E=0,out=0,score=0,base=0;

	cin >> n ;
	for(;;)
	{
		if(E==n)
			break;
		cin >> str ;
		if(str=="OUT")
		{
			out++;
		}
		else if(str=="HIT")
		{
			base++;
			if(base==4)
			{
				score++;
				base--;
			}
		}
		else
		{
			score+=base+1;
			base=0;
		}

		if(out==3)
		{
			cout << score << endl;
			out=base=score=0;
			E++;
		}
	}
}