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

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

using namespace std;
typedef long long ll;

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

        vector<pair<double,string> > v;
        map<double,vector<string> > ma;
        rep(i,n) {
            string l;
            int p,a,b,c,d,e,f,s,m;
            cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;

            double sum = a + b + c + d + e;
            sum += (m-1) * (d + e);
            int num = f*s*m - p;

            v.push_back(make_pair(num/sum,l));
            ma[num/sum].push_back(l);
        }

        vector<string> ans;
        map<double,vector<string> >::iterator ite;
        for(ite = ma.begin();ite != ma.end();ite++) {
            sort(ite->second.begin(),ite->second.end(),greater<string>());
            rep(i,ite->second.size()) {
                ans.push_back(ite->second[i]);
                // cout << ite->first << " " << ite->second[i] << endl;
            }
        }

        reverse(ans.begin(),ans.end());
        rep(i,ans.size()) cout << ans[i] << endl;

        cout << "#" << endl;

    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  const int sqrtN = 512;
  const ll inf = (1LL<<31)-1;
  int n, q;
  cin >> n >> q;
  int bucket_sz = (n+sqrtN-1)/sqrtN;
  vector<ll> a(n, inf);
  vector<ll> bucketUp(bucket_sz, 0);
  vector<bool> bucketFlag(bucket_sz, false);
  auto push = [&](int k) {
    bucketFlag[k] = false;
    int l = k*sqrtN, r = (k+1)*sqrtN;
    for(int i = l; i < r; ++i) a[i] = bucketUp[k];
  };
  auto update = [&](int s, int t, int x) {
    for(int i = 0; i < bucket_sz; ++i) {
      int l = i*sqrtN, r = (i+1)*sqrtN;
      if(r <= s || t <= l) continue;
      if(s <= l && r <= t) {
	bucketUp[i] = x;
	bucketFlag[i] = true;
      } else {
	if(bucketFlag[i]) push(i);
	for(int j = max(s, l); j < min(t, r); ++j) {
	  a[j] = x;
	}
      }
    }
  };
  auto get = [&](int k)->ll{
    if(bucketFlag[k/sqrtN]) push(k/sqrtN);
    return a[k];
  };
  while(q--) {
    int t;
    cin >> t;
    if(t == 0) {
      ll s, t, x;
      cin >> s >> t >> x;
      update(s, t+1, x);
    } else {
      int k;
      cin >> k;
      cout << get(k) << endl;
    }
  }

  return 0;
}


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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

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

    rep(i, n){
        if (s.substr(i) == t.substr(0,n-i)) {
            // cout << s << t.substr(n-i) << endl;
            cout << s.size() + t.substr(n-i).size() << endl;
            return 0;
        }
    }
    cout << 2 * n << endl;
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
  }
  vector<bool> vis(N);
  vector<int> path;
  vector<int> ans;
  function<void(int, int)> dfs = [&](int tmp, int par) {
    if(vis[tmp]) {
      auto from = find(all(path), tmp);
      int size = path.end() - from;
      if(size != 0) {
        if(ans.size() == 0 || size < (int)ans.size()) {
          ans = vector<int>(size);
          copy(from, path.end(), ans.begin());
        }
      }
      return;
    }
    path.push_back(tmp);
    vis[tmp] = true;
    for(int ne: G[tmp]) dfs(ne, tmp);
    path.pop_back();
  };
  rep(i, N) dfs(i, -1);
  if(ans.size() == 0) {
    cout << -1 << endl;
  } else {
    auto check = [&](vector<int>& path) {
      set<int> se;
      for(int v: path) se.insert(v);
      int n = path.size();
      rep(i, n) {
        for(int ne: G[path[i]]) {
          if(se.count(ne) && ne != path[(i+1)%n]) {
            return make_pair(path[i], ne);
          }
        }
      }
      return make_pair(-1, -1);
    };

    while(true) {
      auto ret = check(ans);
      if(ret.first == -1) break;
      vector<int> newPath;
      int n = ans.size();
      int begin = find(all(ans), ret.second) - ans.begin();
      int end = find(all(ans), ret.first) - ans.begin();
      for(int i=begin; i!=end; i=(i+1)%n) {
        newPath.push_back(ans[i]);
      }
      newPath.push_back(ans[end]);
      ans = vector<int>(newPath.size());
      copy(all(newPath), ans.begin());
    }
    cout << ans.size() << endl;
    for(int a: ans) cout << a+1 << endl;
  }
  return 0;
}

#include<iostream>

using namespace std;

#define NMAX 20

int main(){

	int M,N,l;
	int x[NMAX],y[NMAX];
	char d;
	bool ok[21][21];

	while(1){

		cin>>N;

		if(N==0) break;

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

		cin>>M;
		int nx=10,ny=10;
		for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				ok[i][j]=false;
			}
		}
		ok[10][10]=true;
		for(int i=0;i<M;i++){
			cin>>d>>l;
			for(int j=0;j<l;j++){
				if(d=='N') ny++;
				if(d=='S') ny--;
				if(d=='W') nx--;
				if(d=='E') nx++;
				ok[ny][nx]=true;
			}
		}
		bool f=true;
		for(int i=0;i<N;i++){
			if(!ok[y[i]][x[i]]) f=false;
		}
		if(f) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 2010;
int f[N][N * 3], P, ans, n;
int main(){
	read(n); read(P);
	f[0][0] = 1;
	for (int i = 0; i <= n; i++)
		for (int j = 1; j <= 3 * n; j++){
			if (j > 0) f[i][j] = (f[i][j] + f[i][j - 1]) % P;
			if (j > 1 && i > 0) f[i][j] = (f[i][j] + 1ll * f[i - 1][j - 2] * (3 * n - j + 1)) % P;
			if (j > 2 && i > 0) f[i][j] = (f[i][j] + 1ll * f[i - 1][j - 3] * (3 * n - j + 2) % P * (3 * n - j + 1)) % P;
		}
	for (int i = 0; i <= n; i++)
		ans = (ans + f[i][3 * n]) % P;
	printf("%d\n", ans);
	return 0;
}

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

int H, W;
vector<string> grids;
vector<vector<bool>> visited;

Pii link_size(int i, int j) {
    visited[i][j] = true;
    bool color = grids[i][j] == '#';

    Pii ret = Pii(0, 0);
    if (color) ret.first++;
    else ret.second++;

    Pii t;
    if (i > 0 && grids[i][j] != grids[i-1][j] && !visited[i-1][j]) {
        t = link_size(i-1, j);
        ret.first += t.first;
        ret.second += t.second;
    }
    if (i < H-1 && grids[i][j] != grids[i+1][j] && !visited[i+1][j]) {
        t = link_size(i+1, j);
        ret.first += t.first;
        ret.second += t.second;
    }
    if (j > 0 && grids[i][j] != grids[i][j-1] && !visited[i][j-1]) {
        t = link_size(i, j-1);
        ret.first += t.first;
        ret.second += t.second;
    }
    if (j < W-1 && grids[i][j] != grids[i][j+1] && !visited[i][j+1]) {
        t = link_size(i, j+1);
        ret.first += t.first;
        ret.second += t.second;
    }
    return ret;
}

int main() {
    cin >> H >> W;
    grids.resize(H);
    for (int i = 0; i < H; i++) cin >> grids[i];
    visited.resize(H);
    for (int i = 0; i < H; i++) visited[i].resize(W);
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) visited[i][j] = false;

    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!visited[i][j]) {
                Pii t = link_size(i, j);
                ans += (ll)t.first * (ll)t.second;
            }
        }
    }
    cout << ans << endl;
}


#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s,ans;
	cin >> s;
	ans = s;
	map<char, int>m;
	rep(i, 26)m[char('a' + i)]++;
	if(s.size() == 26){
		char c = ' ';
		for (int i = 25; i > 0;i--) {
			if (s[i-1] < s[i]) {
				ans = s.substr(0, i - 1);
				c = s[i -1];
				break;
			}
		}
		for (auto ss : ans)m[ss]--;
		for (auto mm : m) {
			if (mm.second == 1 && c < mm.first) {
				ans += mm.first;
				break;
			}
		}

	}
	else {
		for (auto ss : s)m[ss]--;
		for (auto mm : m) {
			if (mm.second == 1) {
				ans = s + mm.first;
				break;
			}
		}
	}
	if (s != ans) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n,a[N];

inline int calc_status() {
	int c1=0, c2=0;
	for(int i=1;i<=n;i++)
		(a[i]&1) ? ++c1 : ++c2;
	if(c2&1) return 1;
	else if(c1>=2) return 0;
	else {
		int g=0;
		for(int i=1;i<=n;i++) {
			if(a[i]&1) {
				if(a[i]==1) return 0;
				else --a[i];
			}
			g=__gcd(a[i],g);
		}
		for(int i=1;i<=n;i++) a[i]/=g;
		return calc_status() ? 0 : 1;
	}
}
int main() {
	n=rd();
	if(n==1) {puts("Second"); return 0;}
	for(int i=1;i<=n;i++) a[i]=rd();
	if(calc_status()==1) puts("First");
	else puts("Second");
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

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

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    const int w = 52;
    const int h = 100;
    char field[h][w];
    int a, b;
    cin >> a >> b;
    a--, b--;

    rep(i, h / 2)
    {
        rep(j, w)
            field[i][j] = '.';
    }
    rep(i, h / 2)
    {
        rep(j, w)
            field[i + h / 2][j] = '#';
    }

    rep(i, 20)
    {
        if (b == 0)
            break;
        else
        {
            rep(j, 25)
            {
                if (b == 0)
                    break;
                else
                {
                    field[2 * i + 1][2 * j + 1] = '#';
                    b--;
                }
            }
        }
    }

    rep(i, 20)
    {
        if (a == 0)
            break;
        else
        {
            rep(j, 25)
            {
                if (a == 0)
                    break;
                else
                {
                    field[2 * i + h / 2 + 1][2 * j + 1] = '.';
                    a--;
                }
            }
        }
    }

    cout << h << " " << w << endl;
    rep(i, h)
    {
        rep(j, w)
                cout
            << field[i][j];
        cout << endl;
    }

    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    cout << 100 << " " << 100 << endl;
    vector< vector<int> > grad(100, vector<int>(100));
    for(int i=0; i<50; i+=2) {
        for(int j=0; j<100; j+=2) {
            if(A > 1) {
                grad[i][j] = 1;
                --A;
            }
        }
    }
    for(int i=50; i<100; i++) {
        for(int j=0; j<100; j++) {
            grad[i][j] = 1;
            if(B > 1 && i>50 && i%2 == 1 && j%2) {
                grad[i][j] = 0;
                --B;
            }
        }
    }
    for(int i=0; i<100; i++) {
        for(int j=0; j<100; j++) {
            if(grad[i][j]) {
                cout << '.';
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main(void) {
	int N, K;
	scanf("%d %d", &N, &K);
	int l[50];
	for (int i = 0; i < N; i++) {
		scanf("%d", &l[i]);
	}
	sort(l, l + N, greater<int>());
	int ans = 0;
	for (int i = 0; i < K; i++) {
		ans += l[i];
	}

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

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

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

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<> a(n);
    cin >> a;
    sort(rall(a));
    int ans = accumulate(a.begin(), a.begin() + k, 0);
    cout << ans << endl;
}


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

#define ll long long
#define mod 1000000007
#define mod2 998244353
#define pii pair<ll,ll>
#define pb push_back

#define debug(a) { cout << #a << " = " << a << endl;}

void sep() {
    cout << "-------------BLOCK-----------------\n";
}

template<typename T>
void debugv(vector<T> arr) {
    for (auto t: arr)
        cout << t << " ";
    cout << "\n";
}

template<typename T>
void debugarr(T arr, int n) {
    for (int i=0;i<n;i++) cout << arr[i] << " ";
    cout << "\n";
}

ll __min(ll a, ll b) {
    return a < b ? a : b;
}

ll __max(ll a, ll b) {
    return a > b ? a : b;
}

const int maxn = 1e5+1;
ll arr[maxn], n, m, t, k, q;
unordered_map<ll,ll> u;

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

    int arr[26]={0};
    string s;
    cin>>s;
    for (char c: s) arr[c-'a']++;
    for (int i=0;i<26;i++) {
        if (arr[i] == 0) {
            char c = 'a' + i;
            cout << c << endl;
            exit(0);
        }
    }
    cout << "None\n";
}

#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() {
  string s;
  cin >> s;
  vector<bool> found(26, false);
  rep(i, s.size()) found[s[i] - 'a'] = true;
  int a = -1;
  rep(i, 26) if (found[i] == false) {
    a = i;
    break;
  }
  if (a == -1) cout << "None" << endl;
  else {
    char c = a + 'a';
    cout << c << endl;
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#define maxn 200005
using namespace std;
int n,k,l;
int father1[maxn];
int father2[maxn];
map<pair<int,int>,int>mp;
int find1(int x)
{
    if(father1[x]!=x)
       father1[x]=find1(father1[x]);
    return father1[x];
}
int find2(int x)
{
    if(father2[x]!=x)
        father2[x]=find2(father2[x]);
    return father2[x];
}
void unionn1(int x,int y)
{
    int fa=find1(x);
    int fb=find1(y);
    if(fa!=fb)
        father1[fa]=fb;
}
void unionn2(int x,int y)
{
    int fa=find2(x);
    int fb=find2(y);
    if(fa!=fb)
        father2[fa]=fb;
}
int main()
{scanf("%d%d%d",&n,&k,&l);
for(int i=0;i<=n;i++)
    {father1[i]=i;
    father2[i]=i;
    }
int p,q;
for(int i=1;i<=k;i++)
{scanf("%d%d",&p,&q);
    unionn1(p,q);
}
int r,s;
for(int i=1;i<=l;i++)
{scanf("%d%d",&r,&s);
unionn2(r,s);
}
for(int i=1;i<=n;i++)
mp[make_pair(find1(i),find2(i))]++;
for(int i=1;i<=n;i++)
    if(i!=n)
    printf("%d ",mp[make_pair(find1(i),find2(i))]);
else
    printf("%d\n",mp[make_pair(find1(i),find2(i))]);
return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<char> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        if (n != 1)
        {
            if (a[i] == 1)
            {
                if (b[i] == '0')
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        a[i]--;
    }

    for (int i = 0; i < m - 1; i++)
    {
        for (int j = i + 1; j < m; j++)
        {
            if (a[i] == a[j])
            {
                if (b[i] != b[j])
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    int nx = pow(10, n);

    for (int i = 0; i < nx; i++)
    {
        string str = to_string(i);
        if (str.size() != n) continue;

        int flg = 1;
        for (int j = 0; j < m; j++)
        {
            if (str[a[j]] != b[j]) flg = 0;
        }
        if (flg)
        {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,now=0;
    cin>>n;
    string s,t;
    cin>>s>>t;
    while(1){
        if(s.substr(now,n-now)==t.substr(0,n-now)){
            break;
        }
        now++;
    }
    cout<<n+now<<endl;
    return 0;
}

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

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


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define rand rund
#define pb push_back
#define eb emplace_back

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rand();
	a*=RAND_MAX;
	a+=rand();
    return a;
}

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
ll k;
ll e,a[N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back((raand()%MOD+13893829)%MOD);
	cin>>k;
	e=10;
	e*=1000;
	e*=1000;
	e*=1000;
	e*=1000;
	e*=1000;
	for (int n=2;n<=50;++n) if (k<=e*n)
	{
		ll z=(k+n-1)/n;
		for (int i=0;i<n-1;++i) a[i]=z+n-1;
		a[n-1]=z;
		int imp=z*n-k;
		if (imp)
		{
			--a[n-1];
			--imp;
		}
		int st=n-2;
		while (imp)
		{
			a[st]-=st+1;
			--imp;
			--st;
		}
		cout<<n<<endl;
		for (int i=0;i<n;++i) cout<<a[i]<<' ';
		break;
	}
}

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

using namespace std;

int main(){
	long long k;
	cin >> k;
    vector<long long> a(50, 49);
    long long x = (k + 50) / 50, y = (k % 50);
    for(int i = 0; i < 50; i++){
        a[i] += x;
        if(i >= y) a[i] -= y + 1;
    }
	cout << 50 << endl;
    for(int i = 0; i < 49; i++){
        cout << a[i] << " ";
    }
    cout << a[49] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char getClass(int m, int e, int j) {
	if (m == 100 || e == 100 || j == 100 || (m + e) / 2 >= 90
			|| (m + e + j) / 3 >= 80)
		return 'A';
	if ((m + e + j) / 3 >= 70 || (m + e + j) / 3 >= 50 && m >= 80 || e >= 80)
		return 'B';
	return 'C';
}
int main() {
	int n, pm, pe, pj;
	while (cin >> n && n) {
		for (int i = 0; i < n; i++) {
			cin >> pm >> pe >> pj;
			cout << getClass(pm, pe, pj) << endl;
		}
	}
	return 0;
}

#include <stdio.h>

int dividing(int math, int english, int japanese)
{
	if (math == 100 || english == 100 || japanese == 100) {
		printf("A\n");
	}else if (math + english >= 180) {
		printf("A\n");
	}else if (math + english + japanese >= 240) {
		printf("A\n");
	} else if (math + english + japanese >= 210) {
		printf("B\n");
	} else if (math + english + japanese >= 150 && math >= 80) {
		printf("B\n");
	} else if (math + english + japanese >= 150 && english >= 80) {
		printf("B\n");
	} else {
		printf("C\n");
	}
}

int main(void)
{
	while (1) {
		int number;
		scanf("%d", &number);
		if (number == 0) {
			break;
		}
		for (int i = 0; i < number; i++) {
			int math;
			int english;
			int japanese;
			scanf("%d %d %d", &math, &english, &japanese);
			dividing(math, english, japanese);
		}
	}
}


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


#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x == 1) ans += 300000;
    if(x == 2) ans += 200000;
    if(x == 3) ans += 100000;
    if(y == 1) ans += 300000;
    if(y == 2) ans += 200000;
    if(y == 3) ans += 100000;
    if(x == 1 && y == 1) ans += 400000;

    cout << ans << endl;

    return 0;
}

#include "iostream"
using namespace std;
int main(){
    int x,y,price=0;
    cin>>x>>y;
    for (int i=1; i<=3; i++) {
        if (x==i) {
            price+=(4-i)*100000;
        }
        if (y==i) {
            price+=(4-i)*100000;
        }
    }
    if (x==1&&y==1) {
        cout<<"1000000"<<endl;
    } else {
        cout<<price<<endl;
    }
}


#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int32_t main()
{

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

//     int t;
//      cin >> t;

//      while(t--){

// }

 int k;
 string s;
 cin >> k >> s;
 int n = s.length();
 if(k >= n)cout << s << endl;
 else{
 	string res;
 	fo(i,0,k)res += s[i];
 	res += "...";
 	cout << res << endl;
 }

return 0;
}

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

int main() {
	int k;
	string s;
	cin >> k>>s;
	auto out = s;
	if(s.size()>k) out = s.substr(0,k) + "...";
	cout << out << endl;
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

using i64=long long;

template <typename T>
struct BinaryIndexedTree {
    size_t n;
    vector<T> tree;
    BinaryIndexedTree(size_t n, T e=0): n(n) {
        tree = vector<T>(n+1, e);
    }
    void add(size_t i, T w) {
        // v[i] += w;
        // i in [1, n]
        for (size_t j=i; j<=n; j+=j&-j)
            tree[j] += w;
    }
    T sum(T m) {
        // returns sum of v[i] for i in [1, m]
        T sum_=0;
        for (size_t i=m; i>0; i-=i&-i)
            sum_ += tree[i];

        return sum_;
    }
};

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    map<int, size_t> m;
    for (size_t i=0; i<n; ++i)
        m[a[i]] = i;

    vector<int> b(n);
    int rank_=1;
    for (pair<const int, size_t> p: m)
        b[p.second] = rank_++;

    BinaryIndexedTree<i64> tree(n+1);
    i64 res=0;
    for (size_t i=0; i<n; ++i) {
        res += i-tree.sum(b[i]);
        tree.add(b[i], 1);
    }

    printf("%lld\n", res);
    return 0;
}

#include <iostream>
#include <vector>

#define SENTINEL 1000000001

using namespace std;

long long cnt = 0;

void merge(vector<int> &A, int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	vector<int> L(n1 + 1), R(n2 + 1);
	for (int i = 0; i < n1; i++)
	{
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; i++)
	{
		R[i] = A[mid + i];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++)
	{
		if (L[i] <= R[j])
		{
			A[k] = L[i];
			i++;
		}
		else
		{
			A[k] = R[j];
			cnt += n1 - i; // L[]は昇順に整列されているので、i番目以降のL[]の要素(n1 - i)個はすべてR[j]より大きくなる
			j++;
		}
	}
}

void mergeSort(vector<int> &A, int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main() {
	int n;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; i++)
	{
		cin >> S[i];
	}
	mergeSort(S, 0, n);

	cout << cnt << endl;
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

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

class CGridRepainting2 {
public:
	void solve(std::istream& in, std::ostream& out) {
    int h,w;
    in >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    REP(i,h)REP(j,w){
      in >> s[i][j];
    }
    vector<P> action = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
    REP(i,h) REP(j,w){
      if(s[i][j] == '#') {
        bool f = false;
        for (P p : action) {
          if (i + p.first >= 0 && i + p.first < h && j + p.second >= 0 && j + p.second < w) {
            f |= s[i + p.first][j + p.second] == '#';
          }
        }
        if (!f) {
          out << "No" << endl;
          return;
        }
      }
    }
    out << "Yes" << endl;
	}
};

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	CGridRepainting2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    char buf[1<<10];
    size_t q;
    scanf("%s %zu", buf, &q);
    string str(buf);

    for (size_t i=0; i<q; ++i) {
        size_t a, b;
        scanf("%s %zu %zu", buf, &a, &b);
        string instr(buf);

        if (instr == "print") {
            printf("%s\n", str.substr(a, b-a+1).c_str());
        } else if (instr == "reverse") {
            reverse(str.begin()+a, str.begin()+b+1);
        } else if (instr == "replace") {
            scanf("%s", buf);
            string p(buf);
            str.replace(a, b-a+1, p);
        }
    }

    return 0;
}


//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define memset(a,first,last,val) fs(i,first,last,1) a[i]=val
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

vl vb;
int N;

class triplet{ll f, s, t;};

vl in(ll n){
    vl ar;
    ll x;
    f(i,n)
    cin>>ar[i];
    return ar;
}
vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void printArray(vector<int> arr, int n)
{
    ll num=0;
    for (int i = 0; i < n; i++)
    num*=10, num+=i;

    if(n==N)
    vb.pb(num);

}

int printfactorialof(int n){
    if(n<=1)
        return 1;

    return n*printfactorialof(n-1);
}

void solve(){
    ll a,b;
    cin>>a>>b;
    if(a+b <= 16){
        if(a<=8 && b<=8)
            cout<<"Yay!",nl
        else
        {
            cout<<":(",nl
        }

    }
}

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


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

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

	int maximum;
	scanf("%d", &maximum);

	long long ans = 0;
	for(int i = 1; i < N; i++)
	{
		int person;
		scanf("%d", &person);

		if(person >= maximum)
			maximum = person;

		else
			ans += maximum - person;
	}

	printf("%lld", ans);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll x;
    cin>>x;
    ll a[x];
    ll ans = 0;
    ll maxT = 0;
    for(int i=0;i<x;i++) {
        cin>>a[i];
        if(i == 0) {
            maxT = a[0];
        }
        if(i > 0) {
            if(a[i] < a[i-1]) {
                ans += (a[i-1]-a[i]);
                a[i] = a[i-1];
            }
            maxT = a[i];
        }
    }
    // 2 1 5 4 3
    cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string s;

    cin >> k >> s;

    if (s.size()>k) {
        string sub = s.substr(0, k);
        cout << sub << "..." <<endl;
    }
    else{
        cout << s <<endl;
    }

}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a>8||b>8){
        cout << ":(";
    }else{
        cout << "Yay!";
    }
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[100010];

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

  ll sum = 0;

  rep( i, N ) {
    std::cin >> A[i];
    sum ^= A[i];
  }

  ll ans = sum;

  rep( i, N )
    A[i] &= ~sum;

  ll r = 0;

  repd( i, 61 ) {
    ll j = r;
    for( ; j < N; ++j ) {
      if( A[j]>>i&1 ) {
        std::swap( A[r], A[j] );

        break;
      }
    }

    if( j == N )
      continue;

    rep( j, N ) {
      if( j == r )
        continue;

      if( A[j]>>i&1 )
        A[j] ^= A[r];
    }

    ++r;
  }

  ll x = 0;

  rep( i, r )
    x ^= A[i];

  ans += x*2;

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

  return 0;
}


//#include "atcoder/all"
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
// using namespace atcoder;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X, Y;
  cin >> X >> Y;

  if (Y >= X)
    cout << min(Y - X, abs(X + Y) + 1) << endl;
  else
    cout << min(X - Y + 2, abs(X + Y) + 1) << endl;

  return 0;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 998244353; //1000000007;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int x, y;
	get(x, y);

	int ans = 0;
	if (tp_abs(x) < tp_abs(y)) {
		if (x < 0) {
			ans++;
		}
		ans += tp_abs(y) - tp_abs(x);
		if (y < 0) {
			ans++;
		}
	}
	else {
		if (x > 0) {
			ans++;
		}
		ans += tp_abs(x) - tp_abs(y);
		if (y > 0) {
			ans++;
		}
	}
	printf("%d\n", ans);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

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

  vector<ll> p(n);
  ll x,y;
  cin>>x;
  ll dai=x;

  repo(i,n){
    cin>>p[i];
    x=gcd(x,p[i]);
    dai=max(dai,p[i]);
  }

  cout << (k%x==0 && k<=dai ? "POSSIBLE":"IMPOSSIBLE") << endl;

}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int g = a[0];
  for (int i = 1; i < n; i++) {
    g = __gcd(g, a[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] >= k && (a[i] - k) % g == 0) {
      cout << "POSSIBLE" << '\n';
      return;
    }
  }
  cout << "IMPOSSIBLE" << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define memset(a,first,last,val) fs(i,first,last,1) a[i]=val
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

vl vb;
int N;

class triplet{ll f, s, t;};

vl in(ll n){
    vl ar;
    ll x;
    f(i,n)
    cin>>ar[i];
    return ar;
}
vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void printArray(vector<int> arr, int n)
{
    ll num=0;
    for (int i = 0; i < n; i++)
    num*=10, num+=i;

    if(n==N)
    vb.pb(num);

}

int printfactorialof(int n){
    if(n<=1)
        return 1;

    return n*printfactorialof(n-1);
}

void solve(){
    ll a,b;
    cin>>a>>b;
    if(a+b <= 16){
        if(a<=8 && b<=8)
            cout<<"Yay!",nl
        else
        {
            cout<<":(",nl
        }

    }
}

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

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " "
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

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

	if(a<=8 && b<=8) cout<< "Yay!" << endl;
	else cout<< ":(" << endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 100010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,K,ans;
int head[maxn],nxt[maxn],to[maxn],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
int dep[maxn];
void dfs(int x,int las)
{
    for(int i=head[x];i;i=nxt[i])
    {
        dfs(to[i],x);
        dep[x]=max(dep[x],dep[to[i]]);
    }
    dep[x]++;
    if(dep[x]==K&&las!=1)  ans++,dep[x]=0;
}
int main()
{
    n=read();K=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        if(i==1)  ans+=(x!=1);
        else{
            add(x,i);
        }
    }
    for(int i=head[1];i;i=nxt[i])  dfs(to[i],1);
    cout<<ans<<endl;
    return 0;
}

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

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

  vector<ll> c(n + 1, 0);

  for (ll i = 0; i < n; i++)
  {
    c[i + 1] = c[i];
    if (s[i] == 'W')
    {
      c[i + 1]++;
    }
  }

  ll ans = n;
  for (ll i = 1; i < n + 1; i++)
  {
    ans = min(ans, c[i - 1] + (n - i) - (c[n] - c[i]));
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[200010];
int b[200010];

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> a[i+1];

    for(int i = (n+1)/2; i <= n; i++){
        b[i] = a[i];
    }

    for(int k = n; k >= 1; k--){
        int tmp = 0;
        for(int i = 2 * k; i <= n; i += k){
            tmp += b[i];
        }
        tmp += a[k];
        if (tmp%2 == 0) b[k] = 0;
        else b[k] = 1;
    }

    int cnt = 0;
    rep(i, n) cnt += b[i+1];
    cout << cnt << endl;
    if (cnt == 0) return 0;
    rep(i, n) if (b[i+1] > 0) cout << i+1 << " ";
    cout << endl;

    return 0;
}

#include <iostream>
#include <vector>
using namespace std;
vector<long long> divisor(long long n){//nの約数列挙
    vector<long long> res;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}
int main(){
    int N;
    cin >> N;
    vector<int> a(N + 1);
    for(int i = 1; i < N + 1; i++) cin >> a[i];
    vector<int> sum(N + 1, 0);
    vector<int> ko(N + 1, 0);
    int cnt = 0;
    for(int i = N; i > 0; i--){
        if(sum[i] % 2 != a[i]){
            ko[i]++;
            sum[i]++;
            cnt++;
            vector<long long> d = divisor(i);
            for(int j = 0; j < d.size(); j++){
                if(d[j] != i){
                    sum[d[j]]++;
                }
            }
        }
    }
    cout << cnt << endl;
    for(int i = 1; i <= N; i++){
        if(ko[i] == 1){
            cout << i << endl;
        }
    }
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
typedef pair< int , int> P;
int gcd( int x, int y ){
   return y ? gcd(y, x%y) : x;
 }
bool pairCompare(const P& firstElof, const P& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
while(  std::cin >> x>>y){
if(x==0)return 0;
  std::vector< int > v(x);
  rep(i,x)std::cin >> v[i];
  sort(rall(v));
  rep(i,x){
    if((i+1)%y==0)continue;
    z+=v[i];
  }
  std::cout << z << '\n';
  z=0;
}
}

#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

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

        for(int i=0; i<=n; ++i){
            for(int j=0; j<=n; ++j){
                cout << setw(5) << num[i][j];
            }
            cout << endl;
        }
    }
}


#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

class Dice{
	private:
		int label[6];
	public:
		void initialize(int number[]);
		void command(char houkou);
		int getResult();
};

//ラベルに数字を代入
void Dice::initialize(int number[])
{
	for(int i = 0; i < 6; i++){
		label[i] = number[i];
	}
}

//命令を実行
void Dice::command(char houkou)
{
	int temp[6];
	for(int i = 0; i < 6; i++) {
		temp[i] = label[i];
	}

	if(houkou == 'E'){
		label[0] = temp[3];
		label[2] = temp[0];
		label[3] = temp[5];
		label[5] = temp[2];
	}
	else if(houkou == 'W'){
		label[0] = temp[2];
		label[2] = temp[5];
		label[3] = temp[0];
		label[5] = temp[3];
	}
	else if(houkou == 'N'){
		label[0] = temp[1];
		label[1] = temp[5];
		label[4] = temp[0];
		label[5] = temp[4];
	}
	else if(houkou == 'S'){
		label[0] = temp[4];
		label[1] = temp[0];
		label[4] = temp[5];
		label[5] = temp[1];
	}
}

//結果を取得
int Dice::getResult()
{
	return label[0];
}

int main(){
	Dice dice;
	int number[6];
	for(int i = 0; i < 6; i++){
		cin >> number[i];
	}
	dice.initialize(number);

	string meirei;
	cin >> meirei;
	for(int i = 0; i < meirei.length(); i++){
		dice.command(meirei[i]);
	}
	cout << dice.getResult() << endl;

	return 0;
}

//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 300111;
char s[maxn];
int n;
int dp[maxn][3][3];
void upd(int &x, int v) {x=(x+v)%mod;}
int main()
{
	scanf("%s", s);
	n = strlen(s);
	dp[0][0][0] = 1;
	for (int i=0; i<n; i++)
	{
		for (int x=0; x<3; x++)
		{
			for (int y=0; y<3; y++)
			{
				int cur = dp[i][x][y];
				if (!cur) continue;
				for (int t=0; t<2; t++)
				{
					if (s[i]!='?'&&s[i]-'0'!=t) continue;
					int nx, ny;
					if (x==2) nx=2, ny=0;
					else
					{
						if (t==0) nx=x, ny=y+1==3?1:y+1;
						else
						{
							if (y==0) nx=x+1, ny=0;
							else nx=x, ny=y-1;
						}
					}
					upd(dp[i+1][nx][ny], cur);
				}
			}
		}
	}
	int ans = 0;
	upd(ans, dp[n][2][0]);
	upd(ans, dp[n][1][0]);
	upd(ans, dp[n][0][0]);
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][2];
int n, t[4];

void table() {
	for (int t3 = 0; t3 <= t[3]; t3++){
		int pr1 = t3 % 2, pr2 = (pr1 + 1) % 2;
		for (int t2 = 0; t2 <= n; t2++)
			for (int t1 = 0; t1 <= n; t1++) {
				int t0 = n - (t1 + t2 + t3);
				ld &ans = dp[t1][t2][pr1];
				if (t0 == n)
					ans = 0;
				else {
					ans = 1;
					if (t1)
						ans += dp[t1 - 1][t2][pr1] * ((ld) t1 / n);
					if (t2)
						ans += dp[t1 + 1][t2 - 1][pr1] * ((ld) t2 / n);
					if (t3)
						ans += dp[t1][t2 + 1][pr2] * ((ld) t3 / n);
					ans /= (1 - ((ld) t0 / n));
				}
			}
	}
}

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

/*------------------RandomStuff------------------*/
//      Author: CNH_Tourist
//      Date: 30/08/2020
//      Time: 15:26:22
/*-----------------------------------------------*/
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")
using namespace std;
/*---------------------Define--------------------*/
#define filename "TestCode"
#define pi acos(-1)
#define endl '\n'
#define X first
#define Y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define ull unsigned long long
#define hash OoOoO
#define gcd __gcd
#define y1 FlyingTuna
/*-----------------------------------------------*/
const long long mod  = 1e9+7;
const long long mod2 = 1e9+9;
const long long INF  = 1e15;
const long long oo   = 2e18+7;
const long long base = 31;
const double eps = 1e-8;
int test=1;
/*-----------------------------------------------*/
void FlyingTuna()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
/*
    ifstream *fi = new ifstream (filename".inp");
    ofstream *fo = new ofstream (filename".out");
    if(*fi)
    {
        cin.rdbuf( fi->rdbuf() );
        cout.rdbuf( fo->rdbuf() );
    }
*/
}
/*-------------------Global----------------------*/
int n;
ll d[100010];
ll f[100010], a[17][17];
/*------------------Functions--------------------*/

/*-----------------------------------------------*/
void In()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= n; j ++)
            cin >> a[i][j];
}

void Solve()
{
    In();

    for(int mask = 1; mask < 1 << n; mask ++)
    {
        for(int i = 0; i < n; i ++)
            for(int j = i + 1; j < n; j++)
                if((1 & (mask >> i)) == 1 && (1 & (mask >> j)) == 1)
                    d[mask] += a[i+1][j+1];
    }

    for(int mask = 1; mask < 1 << n; mask ++)
    {
        f[mask] = max(f[mask], d[mask]);
        for(int i = mask; i > 0; i =((i-1)&mask))
            f[mask] = max(f[mask], f[i] + d[i^mask]);
    }

    int t = (1 << n) - 1;
    cout << f[t];

}

int32_t main()
{
    FlyingTuna();

    //cin>>test;while(test--)
    Solve();

}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const double INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> T add(T x, T y){ if(abs(x+y) < EPS*(abs(x)+abs(y))) return 0; return x + y; }
template<typename T> inline bool semieq(T x, T y){ return abs(x - y) < EPS; }
template<typename T> inline bool semige(T x, T y){ return y - x < -EPS; }
template<typename T> inline bool semile(T x, T y){ return x - y < -EPS; }

const int MAX_N = 10;
const int n = MAX_N;
double x[MAX_N+1];
double v[2];

int main()
{
  while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &x[1], &x[2], &x[3], &x[4], &x[5], &x[6], &x[7], &x[8], &x[9], &v[0], &v[1])){
    double len = 0.0;
    rep(i, n) len += x[i];
    double left  = 0.0;
    double right = INF;
    double t;
    while(semile(left, right)){
      t = (left + right) / 2.0;
      if((v[0] + v[1]) * t > len) right = t;
      else left = t;
    }
    rep(i, n-1) x[i+1] += x[i];
    cout << upper_bound(x, x+n, v[0] * t) - x + 1<< endl;
  }

  return 0;
}

// 2016-12-03
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int m, min, max, n;
	int p[200];
	while (cin >> m >> min >> max, m) {
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}
		n = min - 1;
		for (int i = min; i < max; i++) {
			if (p[i] - p[i + 1] >= p[n] - p[n + 1]) {
				n = i;
			}
		}
		cout << n + 1 << endl;
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX 300000

int n, pm, pe, pj;

int main() {
	while (1) {
		scanf("%d", &n);
		if (n == 0)
			return 0;

		while(n-- > 0) {
			scanf("%d %d %d", &pm, &pe, &pj);
			if(max(pm, max(pe, pj)) == 100 || pm + pe >= 180 || pm + pe + pj >= 240)
				puts("A");
			else if(pm + pe + pj >= 210 || pm + pe + pj >= 150 && max(pm, pe) >= 80)
				puts("B");
			else
				puts("C");
		}
	}
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;

bool solve(){
	int n;
	cin>> n;
	if(!n) return false;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>> a[i];
	}
	string str;
	cin>> str;

	for(int i=0;i<str.size();i++){
		int k = a[i%n];
		k %= 52;
		char c = str[i];
		if(k>26){
			if(islower(c)){
				c = toupper(c);
			}else{
				c = tolower(c);
			}
			k -= 26;
		}
		if(islower(c)){
			if(islower(c-k)){
				c -= k;
			}else{
				k -= c - 'a';
				c = 'Z' - (k - 1);
			}
		}else if(isupper(c)){
			if(isupper(c-k)){
				c -= k;
			}else{
				k -= c - 'A';
				c = 'z' - (k - 1);
			}
		}
		cout<< c;
	}
	cout<< endl;

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve()){}

	return 0;
}


#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 21001
#define int long long
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
const int MOD=1e9+7;
int n,a[MN],B[MN],x,mmh=0,mm[20][20][2][2];
inline int M(int x){return x<0?x+10:x;}
inline void work(int p,int n,int a,int b){
    if (mm[p][n][a][b]!=-1) {mmh+=mm[p][n][a][b];return;}
    int u=mmh;
    if (p+p-1==n){
        if (a==0&&b==0) mmh+=10*(B[p]==0);else
        if (a==1&&b==1) mmh+=10*(B[p]==9);
        return;
    }
    if (p+p-1>n){
        mmh+=a==b;
        return;
    }
    for (int i=p==1;i<=9;i++)
    for (int j=0;j<=9;j++)
    if (M(i-j-b)==B[p]&&(a==(j<i)||j==i)&&(M(j-i)==B[n+1-p]||M(j-1-i)==B[n+1-p])){
        if (a){
            if (j==i&&B[n+1-p]==0) continue;
            work(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }else{
            if (j==i&&B[n+1-p]==9) continue;
            work(p+1,n,M(j-1-i)==B[n+1-p],i-b-j<0);
        }
    }
    mm[p][n][a][b]=mmh-u;
}
signed main(){
    int i,j,k;
    x=n=read();
    if (n%9) return puts("0"),0;
    for (k=1;k<=10&&x;k++) B[k]=x%10,x/=10;k--;
    for (int i=k;i<=18;i++) memset(mm,-1,sizeof(mm)),work(1,i,0,0);
    printf("%lld\n",mmh);
}

#include <iostream>
#include <string>

using namespace std;

int getvalue(char c){
  if(c == 'I'){
	  return 1;
	}else if(c == 'V'){
	  return 5;
	}else if(c == 'X'){
	  return 10;
	}else if(c == 'L'){
	  return 50;
	}else if(c == 'C'){
	  return 100;
	}else if(c == 'D'){
	  return 500;
	}else if(c == 'M'){
	  return 1000;
	}
  return -1;
}

int parseStr(string str){
  int ret=0;
  int now;
  int next;

  for(int i=0;i<str.size();i++){
	now = getvalue(str[i]);
	if(i != str.size() - 1){
	  next = getvalue(str[i+1]);
	}else{
	  next = -1;
	}

	if(now >= next){
	  ret += now;
	}else{
	  ret += next - now;
	  i++;
	}
  }
  return ret;
}

int main(void){
  string tmp;

  while(cin >> tmp){
	cout << parseStr(tmp) << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

int main() {
    int n; std::cin >> n;
    bool used[1000000] = {};
    std::vector<int> ans;
    for (int i = 2; i <= 55555; i++) {
        if (used[i]) continue;
        if (i % 5 == 1) ans.push_back(i);
        int w = i;
        while (w <= 555555) {
            used[w] = true;
            w += i;
        }
    }
    for (int i = 0; i < n; i++) std::cout << ans[i] << " \n"[i == n - 1];
    return 0;
}

#include<stdio.h>
int main()
{
	int i,j,n;
	const int N=10001;
	bool p[N];
	for(i=2;i<N;++i)p[i]=true;
	for(i=2;i<=N/2;++i)if(p[i])for(j=2*i;j<N;j+=i)p[j]=false;
	while(scanf("%d",&n),n){for(i=n;;--i)if(p[i]&&p[i-2])break;printf("%d %d\n",i-2,i);}
	return 0;
}


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

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for (size_t i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        v[l-1]++;
        v[r]--;
    }

    int ans = 0, num = 0;
    for (size_t i = 0; i < n; i++) {
        num += v[i];
        if (num == m) ans++;
    }

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

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

int main() {
  int N , M ;
  cin >> N >> M ;
  int max_L = 0 ;
  int min_R = 5+ 10e5 ;

  for(int i = 0 ; i < M ; i++ ){
    int L , R ;
    cin >> L >> R ;
    max_L = max(max_L , L);
    min_R = min(min_R , R);
  }
  min_R++ ;
  if(min_R > max_L){
  	cout << min_R - max_L << endl ;
  }
  else{
    cout << 0 << endl ;
  }

}


#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------------------------head--------------------------------------------------

const int inf=0x3f3f3f3f;
const int N=1000005,M=100005,mod=998244353;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,fac[N],ifac[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	n=1000000;fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[n]=exp(fac[n],mod-2);
	for(int i=n;i;i--) ifac[i-1]=(ll)ifac[i]*i%mod;
	read(n,m);
	int ans=0;
	for(int i=1;i<=min(n,m);i++)
		ch(ans,(ll)ifac[i]*ifac[i]%mod*ifac[n-i]%mod*ifac[m-i]%mod*fac[i*2-1]%mod*fac[n+m-2*i]%mod*i);
	ans=(ll)ans*fac[n]%mod*fac[m]%mod*ifac[n+m]%mod;
	ch(ans,max(n,m));
	print(ans);
	return 0;
}

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

int main()
{
    int d;
    ll g;
    vector<ll> p, c;
    cin >> d >> g;
    p.resize(d);
    c.resize(d);
    rep(i, d)
    {
        cin >> p[i] >> c[i];
    }
    ll res = 1 << 29;
    for (int bit = 0; bit < (1 << d); ++bit)
    {
        ll sum = 0;
        ll num = 0;

        rep(i, d)
        {
            if (bit & (1 << i))
            {
                sum += c[i] + p[i] * 100 * (i + 1);
                num += p[i];
            }
        }
        if (sum >= g)
        {
            res = min(res, num);
        }
        else
        {
            for (int i = d - 1; i >= 0; i--)
            {
                if (bit & (1 << i))
                {
                    continue;
                }
                rep(j, p[i])
                {
                    if (sum >= g)
                    {
                        break;
                    }
                    sum += 100 * (i+1);
                    num++;
                }
            }
            res = min(res, num);
        }
    }
    cout << res << endl;
}


#include<bits/stdc++.h>

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

using namespace std;

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

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

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

int main(){
    int k, x; cin >> k >> x;
    int pos=max(x-k+1, -1000000);
    while(pos <= 1000000 && pos <= x+k-1){
        cout << pos << " ";
        pos++;
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int min_P, max_P;
    min_P = X-K+1;
    max_P = X+K-1;

    FOR(i, min_P, max_P){
        cout << i << " ";
    }

    cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

static const int INF = 99999;

int main(){

	int n,array[100][100];

	cin>>n;

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

		fill(array[i],array[i]+n,INF);

	}

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

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

			int tmp;

			cin>>tmp;

			if(tmp!=-1) array[i][j]=tmp;

		}

	}

	int ans=INF;

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

		bool flag[100];

		fill(flag,flag+n,false);

		flag[k]=true;

		int tmp=0;

		while(1){

			int u=-1,minv=INF;

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

				if(!flag[i]) continue;

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

					if(!flag[j] && array[i][j]<=minv){

						minv = array[i][j];

						u = j;

					}

				}

			}

			if(minv==INF){

				break;

			}else{

				tmp += minv;

				flag[u]=true;

			}

		}

		ans = min(ans,tmp);

	}

	cout<<ans<<endl;

	return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * n; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

class UnionFind {
	typedef size_t U;
	vector<int32_t> v;
public:
	UnionFind(U n) : v(n, -1) {}
	U find(U x) { return v[x] < 0 ? x : (v[x] = find((U)v[x])); }
	bool same(U x, U y) { return find(x) == find(y); }
	U size(U x) { return (U)-v[find(x)]; }
	void unite(U x, U y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}
};

struct Edge{ uint32_t to, id; };
typedef vector<vector<Edge>> Graph;

template<class T> struct Kruskal{
	typedef uint32_t U;
	template<class V> Kruskal(U n, const V & u, const V & v, const vector<T> & w) : g(n) {
		vector<U> es(w.size());
		iota(es.begin(), es.end(), 0);
		sort(es.begin(), es.end(), [&](U i, U j) { return w[i] < w[j]; });
		UnionFind uf(n);
		for (U i : es) {
			if (!uf.same(u[i], v[i])) {
				uf.unite(u[i], v[i]); cost += w[i];
				g[u[i]].push_back({ (U)v[i], i }); g[v[i]].push_back({ (U)u[i], i });
			}
		}
	}
	Graph g; T cost = 0;
};

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

	ll n; cin >> n;
	vl u, v, w;
	REP(i, n) REP(j, n) {
		ll x; cin >> x;
		if (x != -1) {
			u.push_back(i);
			v.push_back(j);
			w.push_back(x);
		}
	}
	Kruskal<ll> mst(n, u, v, w);
	cout << mst.cost << endl;
}


#include<bits/stdc++.h>
#define MN 600
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
pair<int,int> q[MN+5];
int n,d,D,s[MN+5][MN+5],vis[MN+5][MN+5],num[4],top;
void Mark(int x,int y,int c,int S)
{
    if(S) s[x][y]|=c;vis[x][y]=1;
    for(int j=1;j<=top;++j)
        for(int dx=-1;dx<=1;dx+=2) for(int dy=-1;dy<=1;dy+=2)
        {
            int nx=x+dx*q[j].first,ny=y+dy*q[j].second;
            if(nx>0&&ny>0&&nx<=n<<1&&ny<=n<<1&&!vis[nx][ny]) Mark(nx,ny,c,S^1);
        }
}
void Solve(int d,int c)
{
    top=0;
    for(int i=0;i*i<=d;++i)
    {
        int j=d-i*i,flag=-1;
        for(int k=0;k*k<=j;++k) if(k*k==j) flag=k;
        if(flag>=0) q[++top]=make_pair(i,flag);
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j) if(!vis[i][j]) Mark(i,j,c,0);
}
int main()
{
    n=read();d=read();D=read();
    Solve(d,1);Solve(D,2);
    for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j) ++num[s[i][j]];
    for(int k=0;k<4;++k) if(num[k]>=n*n)
    {
        int left=n*n;
        for(int i=1;i<=n<<1;++i) for(int j=1;j<=n<<1;++j)
            if(s[i][j]==k&&left) --left,printf("%d %d\n",i-1,j-1);
        return 0;
    }
    return 0;
}

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

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

	string f, e;
	cout << 0 << endl;
	cin >> f;
	if( f == "Vacant" ) return 0;
	cout << N - 1 << endl;
	cin >> e;
	if( e == "Vacant" ) return 0;
	int l = 0;
	int r = N - 1;
	while( r - l > 1 ) {
		int m = (l + r) / 2;
		string now;
		cout << m << endl;
		cin >> now;
		if( now == "Vacant" ) return 0;
		int s = r - m;
		if( s % 2 == 0 && now != e || s % 2 && now == e ) {
			l = m;
			f = now;
		}
		else {
			r = m;
			e = now;
		}
	}
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 10005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M,s[2],l[2];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    int x;
    for(int i = 1 ; i <= N ; ++i) {
	read(x);
	x = (x + MOD) % MOD;
	update(l[0],inc(mul(i - 1,x),MOD - s[0]));
	update(s[0],x);
    }
    int y;
    for(int i = 1 ; i <= M ; ++i) {
	read(y);
	y = (y + MOD) % MOD;
	update(l[1],inc(mul(i - 1,y),MOD - s[1]));
	update(s[1],y);
    }
    out(mul(l[0],l[1]));
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    vector<ll> num(26,0);
    ll ans = 0;

    rep(i,s.size()){
        for(char c = 'a'; c<='z'; c++){
            if(c == s[i]) num[c - 'a']++;
        }
    }

    rep(i,26) ans += (num[i]*(num[i]-1))/2;

    cout << (s.size()*(s.size()-1))/2 - ans + 1 << endl;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;

    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n || k < 0) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

ll dp[305][305][305];

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int d[305];
    int m = 0;
    int c = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0'){
            d[m] = c;
            m++;
            c = 0;
        }
        else c++;
    }
    d[m] = c;
    m++;
    int b[305];
    b[m] = 0;
    for(int i = m - 1; i >= 0; i--) b[i] = b[i + 1] + d[i];
    int p;
    cin >> p;
    dp[m - 1][0][d[m - 1]] = 1;
    for(int i = m - 1; i > 0; i--){
        for(int j = 0; j <= min(p, b[i]); j++){
            for(int k = d[i - 1]; k <= b[i - 1]; k++){
                for(int l = max(d[i], k - d[i - 1]); l <= b[i - 1]; l++){
                    if(k - d[i - 1] < l - d[i]) dp[i - 1][j][k] = (dp[i - 1][j][k] + dp[i][j][l]) % MOD;
                    else dp[i - 1][j + (k - d[i - 1]) - (l - d[i])][k] = (dp[i - 1][j + (k - d[i - 1]) - (l - d[i])][k] + dp[i][j][l]) % MOD;
                }
            }
        }
    }
    ll ans = 0;
    for(int j = 0; j <= min(p, 300); j++){
        for(int k = 0; k <= 300; k++) ans = (ans + dp[0][j][k]) % MOD;
    }
    cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 998244353LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,x,y,K_;

int main(){
  ll ans=0;
  string s;cin>>s;
  cin >> K_;
  n=s.length();
  ll zn=0;
  for(ll i=0;i<n;i++){
    if (s[i]=='0')zn++;
  }
  ll nn=n-zn;//1の数
  K_=min(K_,nn);

  if ((n==zn)|(zn==0)|(K_==0)){
    cout<<1<<endl;
    return 0;
  }

  zn++;
  vvi zrange(zn, vi(2));//0からみて左に1が今何個減らせるか、最大何個まで増やせるか
  ll znw=zn-1;
  ll totalone=0;
  s+="0";
  for(ll i=n;i>=0;i--){
    if (s[i]=='0')
    {
      zrange[znw][1]=totalone;
      for(;;)
      {
        i--;
        if (i==-1)break;
        if (s[i]=='1'){
          zrange[znw][0]++;
          totalone++;
        }else{i++;break;}
      }
      znw--;
    }else{
      totalone++;
    }
  }

  /*
  for(ll i=0;i<zn;i++){
    cout<<zrange[i][0]<<" "<<zrange[i][1]<<endl;
  }
  */

/*
  for(ll i=0;i<zn;i++){
    zrange[i][1]+=zrange[i][0];
  }
*/

  vi dp(nn+1,0);
  vi dp_n(nn+1,0);
  vvi score(nn+1, vi(K_*2+1,0));
  vvi score_n(nn+1, vi(K_*2+1,0));

  dp[0]=1;
  score[0][0]=1;
  for(ll i=0;i<zn;i++){//さいがいループ、0の左に何個つけられるか

    for(ll j=0;j<nn+1;j++){
      dp_n[j]=0;
      for(ll k=max(j-zrange[i][1],0LL);k<=min(j+zrange[i][0],nn);k++){
        dp_n[j]+=dp[k];
        for(ll l=0;l+abs(j-k)<K_*2+1;l++){
          score_n[j][l+abs(j-k)]+=score[k][l];
          score_n[j][l+abs(j-k)]%=MOD;
        }
      }
      dp_n[j]%=MOD;
    }

    /*
    for(ll j=0;j<nn+1;j++){
      dp[j]=dp_n[j];
      dp_n[j]=0;
    }
    */
    dp.swap(dp_n);
    for(ll j=0;j<nn+1;j++){
      for(ll k=0;k<K_*2+1;k++){
        score[j][k]=score_n[j][k];
        score_n[j][k]=0;
      }
    }
    //score.swap(score_n);
  }

  //cout<<dp[0]<<endl;

  for(ll i=0;i<K_*2+1;i++){
    //cout<<score[0][i]<<endl;
    ans+=score[0][i];
    ans%=MOD;
  }

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


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N, M, X, Y; cin >> N >> M >> X >> Y;
  vector<int> x(N); REP(i, N) cin >> x[i];
  vector<int> y(M); REP(i, M) cin >> y[i];
  sort(all(x)); sort(all(y));
  string ans = "War";
  for(int i = X + 1; i <= Y; ++i) {
    if(x[N - 1] < i && i <= y[0]) ans = "No War";
  }
  cout << ans << endl;
}

# include <bits/stdc++.h>
using namespace std ;
bool is_war ( const vector <int >& x , const vector <int >& y ) {
for ( int Z = -100; Z <= 100; ++ Z ) {
bool is_ok = true ;
for ( int i = 0; i < x . size (); ++ i ) {
if ( x [ i ] >= Z ) is_ok = false ;
}
for ( int i = 0; i < y . size (); ++ i ) {
if ( y [ i ] < Z ) is_ok = false ;
}
if ( is_ok ) return false ;
}
return true ;
}
int main () {
int N , M ; cin >> N >> M ;
vector <int > x ( N +1) , y ( M +1);
cin >> x [0] >> y [0];
for ( int i = 0; i < N ; ++ i ) {
cin >> x [ i +1];
}
for ( int i = 0; i < M ; ++ i ) {
cin >> y [ i +1];
}
if ( is_war (x , y )) {
cout << " War " << endl ;
}
else {
cout << "No War " << endl ;
}
}


#include <bits/stdc++.h>

using namespace std;
int64_t mod = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int64_t>arr(n);
    for(auto & i : arr)
        cin >> i;
    vector<int64_t>sufsum;
    sufsum.push_back(0);
    for(int i = n-1; i > 0; --i){
        auto a = sufsum.back();
        a+=arr[i];
        sufsum.push_back(a);
    }
    reverse(sufsum.begin(),sufsum.end());
    int64_t ans = 0;
    for(int i = 0 ; i < n; ++i){
        ans+=(arr[i]*(sufsum[i]%mod));
        ans%=mod;
    }
    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int main(){
    ll n;
    scanf("%lld",&n);
    ll a[n+1];
    ll sum=0;
    for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum=(sum+a[i])%mod;
	}
	ll ans=0;
	for(int i=1;i<n;i++){
		sum=(sum+mod-a[i])%mod;
		ans=(ans+a[i]*sum)%mod;
	}
	cout<<ans%mod<<endl;
}


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

class BNode{
public:
	int value;
	BNode *right,*left;
};

class BTree{
	BNode *root;
	void Inorder(BNode *cur){
		if(cur){
			Inorder(cur->left);
			cout << " " << cur->value;
			Inorder(cur->right);
		}
	}
	void Preorder(BNode *cur){
		if(cur){
			cout << " " << cur->value;
			Preorder(cur->left);
			Preorder(cur->right);
		}
	}
public:
	BTree(){
		root = NULL;
	}
	void Insert(int v){
		BNode *cur = root;
		BNode *prt = NULL;
		BNode *node = new BNode();
		node->value = v;

		while(cur){
			prt = cur;
			if(cur->value < v){
				cur = cur->right;
			}else{
				cur = cur->left;
			}
		}
		if(prt){
			if(prt->value > v){
				prt->left = node;
			}else{
				prt->right = node;
			}
		}
		if(!root){
			root = node;
		}
	}
	void PrintInorder(){
		Inorder(root);
		cout<<endl;
	}
	void PrintPreorder(){
		Preorder(root);
		cout<<endl;
	}
	void Find(int v){
		BNode *cur = root;

		while(cur){
			if(cur->value == v){
				cout<<"yes"<<endl;
				return;
			}else if(cur->value > v){
				cur = cur->left;
			}else{
				cur = cur->right;
			}
		}
		cout<<"no"<<endl;
	}
	BNode* Next(BNode *cur){
		cur = cur->right;
		while(cur->left){
			cur = cur->left;
		}
		return cur;
	}
	void Delete(int v){
		BNode *cur = root;
		BNode *prt = NULL;

		while(cur){
			if(cur->value == v){
				if(cur->left==NULL && cur->right==NULL){
					if(prt){
						if(prt->value > v){
							prt->left = NULL;
						}else{
							prt->right = NULL;
						}
					}else{
						root = NULL;
					}
				}else if(cur->left!=NULL && cur->right==NULL){
					if(prt){
						if(prt->value > v){
							prt->left = cur->left;
						}else{
							prt->right = cur->left;
						}
					}else{
						root = cur->left;
					}
				}else if(cur->left==NULL && cur->right!=NULL){
					if(prt){
						if(prt->value > v){
							prt->left = cur->right;
						}else{
							prt->right = cur->right;
						}
					}else{
						root = cur->right;
					}
				}else{
					int temp = Next(cur)->value;
					Delete(temp);
					cur->value = temp;
				}
				return;
			}else if(cur->value > v){
				prt = cur;
				cur = cur->left;
			}else{
				prt = cur;
				cur = cur->right;
			}
		}
	}
};

int main() {
	BTree bt;
	int m, v;
	string com;

	cin>>m;
	for(int i=0;i<m;++i){
		cin>>com;
		if(com=="insert"){
			cin>>v;
			bt.Insert(v);
		}else if(com=="print"){
			bt.PrintInorder();
			bt.PrintPreorder();
		}else if(com=="find"){
			cin>>v;
			bt.Find(v);
		}else if(com=="delete"){
			cin>>v;
			bt.Delete(v);
		}
	}

	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const string v = "Vacant";
const string m = "Male";
const string f = "Female";

int main(){
  int n;
  cin >> n;
  cout << 0 << endl;
  string sl;
  cin >> sl;
  if(sl == v) return 0;
  string sr;
  cout << n-1 << endl;
  cin >> sr;
  if(sr == v) return 0;
  int l = 0, r = n-1;
  rep(i, 20){
    int m = (l+r)/2;
    cerr << l << " " << m << " " << r << endl;
    int dl = m - l, dr = r - m;
    cout << m << endl;
    string sm;
    cin >> sm;
    if(sm == v) return 0;
    if(dl % 2 == 0){
      if(sl == sm){
        l = m;
      }else{
        sr = sm;
        r = m;
      }
    }else{
      if(sl != sm){
        sl = sm;
        l = m;
      }else{
        sr = sm;
        r = m;
      }
    }
  }
  return 1;
}


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

int main() {
	int r, g;
	cin >> r;
	cin >> g;
	cout << g - r + g << endl;
}

#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();

	int x, y,ave=0;
	cin >> x >> y;
	ave = (2 * y) - x;
	cout << ave << endl;

}


//
// Created by Koki Igarashi on 7/28/20.
//

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int, Int> pii;
typedef pair<Int, double> pid;
typedef pair<double, double> pdd;
typedef pair<Int, pii> pip;
typedef pair<pii, Int> ppi;
typedef pair<double, Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<pii> vecpii;
typedef vector<ppi> vecppi;
typedef vector<veci> mati;
typedef vector<vecll> matll;
typedef vector<vecd> matd;
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i, a, b) for(int i = (a);i <= (b);i++)
#define FORO(i, n) REP(i,0,(int)n-1)
#define FORI(i, n) REP(i,1,(int)n)
#define FORIT(i, t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
#define DEBUG 1
#if DEBUG
#define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false)
#else
#define DUMP(a)
#define DUMPLN(a)
#endif
template<typename T, typename U>
inline void getMin(T &a, U b) { if (a > b) a = b; }
template<typename T, typename U>
inline void getMax(T &a, U b) { if (a < b) a = b; }
template<typename T>
vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T>
vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T>
vector<T> getEmptyVector() { return vector<T>(); }
template<typename T>
void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1 << 17;
const int inf = 1 << 20;
const int NIL = -inf;
int popcount(int x) { return __builtin_popcount(x); }

int N;
mati A;

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

    cin >> N;
    A.resize(N);
    FORO(i, N) {
        A[i].resize(N - 1);
        FORO(j, N - 1) {
            cin >> A[i][j];
        }
    }
    veci idx(N);
    int day = 0;
    int gcnt = 0;
    while(gcnt < N * (N - 1) / 2) {
        day++;
        veci used(N);
        bool no_game = true;
        for(int i = 0;i < N;i++) {
            if(used[i] || idx[i] == N - 1) continue;
            int opp = A[i][idx[i]] - 1;
            if(used[opp]) continue;
            if(A[opp][idx[opp]] == i + 1) {
                idx[opp]++;
                idx[i]++;
                used[i] = used[opp] = 1;
                gcnt++;
                no_game = false;
            }
        }
        if(no_game) break;
    }

    cout << (gcnt == N * (N - 1) / 2 ? day : -1) << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using P = pair<int, int>;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  REP(i, n) {
    REP(j, n - 1) {
      cin >> a[i][j];
      a[i][j]--;
    }
    REVERSE(a[i]);
  }
  vector<P> que;
  auto check = [&](int i) {
    if (a[i].size() == 0) return;
    int j = a[i].back();
    if (a[j].back() == i) {
      if (i > j) que.push_back(P(j, i));
      else
        que.push_back(P(i, j));
    }
  };
  REP(i, n) {
    check(i);
  }
  int day = 0;
  while (que.size() > 0) {
    day++;
    SORT(que);
    que.erase(unique(que.begin(), que.end()), que.end());
    vector<P> prevQ;
    swap(prevQ, que);
    EACH(p, prevQ) {
      int i = p.first;
      int j = p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    EACH(p, prevQ) {
      int i = p.first;
      int j = p.second;
      check(i);
      check(j);
    }
  }
  REP(i, n) {
    if (a[i].size() != 0) {
      cout << -1 << endl;
      return;
    }
  }
  cout << day << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <string.h>

using namespace std;
static const int INF = 1e9;
static const int SIZE = 10001;
typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

bool isUsed[SIZE];
vector<edge> G[SIZE];

void solve()
{
	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; ++i)
	{
		int from, to, cost;
		cin >> from >> to >> cost;
		edge e1, e2;
		e1.to = to;
		e1.cost = cost;
		e2.to = from;
		e2.cost = cost;
		G[from].push_back(e1);
		G[to].push_back(e2);
	}
	memset(isUsed, 0, sizeof(isUsed));
	int ans = 0;
	priority_queue<P, vector<P>, greater<P> > pque;
	pque.push(P(0, 0));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		if (isUsed[v])
		{
			continue;
		}
		isUsed[v] = true;
		ans += p.first;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge e = G[v][i];
			pque.push(P(e.cost, e.to));
		}
	}
	cout << ans << endl;
}

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

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include<stdio.h>
#include <map>
using namespace std;

int uni[100100];

int oya(int a){
if (uni[a]<0){
	return a;
}
else{
	uni[a]=oya(uni[a]);
	return oya(uni[a]);
}
}

bool ren(int a,int b){
	a=oya(a);
	b=oya(b);
	if(a==b){
	return	false;
	}
	else{

	return true;
	}
}

int main() {
	int co=0;

vector <pair<int, int> > be;
int e,v;
cin>>v>>e;
for(int y=0;y<v;y++){
	uni[y]=-1;
}
for(int u=0;u<e;u++){
	int z,x,c;
	cin>>z>>x>>c;
	be.push_back(pair<int, int>(c,z*100100+x));
}
sort(be.begin(), be.end());

for(int y=0;y<e;y++){
	int z,x,c;
	c=be[y].first;
	z=(be[y].second)/100100;
	x=(be[y].second)%100100;
	if(ren(z,x)==true){
		co=co+c;
		uni[oya(z)]=x;
	}
}
cout<<co<<endl;

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, k, T, x, y, cnt;
ll vv[55];

int main(void)
{
	cin>>k; n=50; T=k/n; ll i;
	x=T+2*n-k%n; y=x-n-1;
	for(i=1 ; i<=k%n ; i++) vv[i]=x;
	for(i=k%n+1 ; i<=n ; i++) vv[i]=y;
	cout<<n<<"\n";
	for(i=1 ; i<=n ; i++) cout<<vv[i]<<" ";
	return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

bool check(long long a,long long b,long long c){
    return true;
}

int main(){
    string str;

    cin >> str;

    if(str.size()%2!=0){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<str.size()-1; i+=2){
        if(str.at(i)=='h' && str.at(i+1)=='i'){
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}