#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int N;
        cin>>N;
        if(!N)break;
        int rui[10000]={0};
        for(int i=1;i<=N;i++){
            int a;
            cin>>a;
            rui[i]=rui[i-1]+a;
        }
        int ans=-2000000000;
        //for(int i=0;i<=N;i++)printf("[%d]",rui[i]);
        for(int i=0;i<=N;i++){
            for(int j=i+1;j<=N;j++)ans=max(ans,rui[j]-rui[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int main()
{
    while(true) {
        int n;
        vi v;
        cin >> n;
        if(n==0) break;

        while(n--) {
            int tmp;
            cin >> tmp;
            v.push_back(tmp);
        }
        vi w(v);
        rep(i, v.size()) v[i] = max(v[i-1] + v[i], v[i]);
        P(*max_element(ALL(v)));
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;

int main()
{
    int N,M;
    cin >> N >> M;
    ve<vi> a(N,vi(M));
    rep(i,N) rep(j,M){ cin >> a[i][j]; a[i][j]--;}

    ve<bool> f(M,true);
    vi ii(N,0);
    int ans = infi;

    rep(i,M){
        vi aa(M,0);
        rep(j,N){
            while (!f[a[j][ii[j]]]) {
                ii[j]++;
            }
            aa[a[j][ii[j]]]++;
        }

        int jj = 0;
        int kk = 0;
        rep(k,M) if(kk<aa[k]) jj = k, kk = aa[k];
        ans = min(ans,kk);
        f[jj] = false;
    }

    cout << ans << endl;

    return 0;
}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=302;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n,m;
int a[M+2][M+2];
int col_pos_in_row[M+2];
bool chk(int mx)
{
    queue<int>q;
    int cnt[m+2],vis[m+2];clr(vis);
    f(i,1,n)col_pos_in_row[i]=1;
    clr(cnt);
    for(int i=1;i<=n;i++)
    {
         cnt[a[i][1]]++;
         if(cnt[a[i][1]]>mx && vis[a[i][1]]==0)
         {
             q.push(a[i][1]);
             vis[a[i][1]]=1;
         }
    }
    while(!q.empty())
    {
        int game=q.front();
        q.pop();
        for(int i=1;i<=n;i++)
        {
            if(a[i][col_pos_in_row[i]]==game)
            {
                while(1)
                {
                    col_pos_in_row[i]++;
                    if(col_pos_in_row[i]>m)return false;
                    int gm=a[i][col_pos_in_row[i]];
                    if(vis[gm]==0)
                    {
                        break;
                    }
                }
                int ngm=a[i][col_pos_in_row[i]];
                cnt[ngm]++;
                if(cnt[ngm]>mx && vis[ngm]==0)
                {
                    q.push(ngm);
                    vis[ngm]=1;
                }
            }
        }
    }
    return true;
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,n)f(j,1,m)cin>>a[i][j];
    int lo=1,hi=n;
    while(hi-lo>=2)
    {
        int mid=(lo+hi)>>1;
        if(chk(mid))hi=mid;
        else lo=mid+1;
    }
    f(i,lo,hi)
    {
        if(chk(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"ERROR"<<endl;
    return 0;

}


#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define enter putchar('\n')
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)

typedef long long ll;

using namespace std;

const int maxn = 3e5 + 5;
const int LOG = 35;
const int inf = 0x3f3f3f3f;

int n, m, a[maxn];

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

struct SEG {
	#define ls p << 1
	#define rs p << 1 | 1
	#define mid (l + r >> 1)
	struct Node {
		ll mn, tag;
		Node() { tag = 0; mn = (1ll << 60); }
	} t[maxn << 2];

	inline void pushtag(int p, ll x) {
		t[p].tag += x; t[p].mn += x;
	}

	inline void pushdown(int p) {
		if(t[p].tag) {
			pushtag(ls, t[p].tag);
			pushtag(rs, t[p].tag);
			t[p].tag = 0;
		}
	}

	inline void modify(int l, int r, int pos, int p, ll x) {
		if(l == r) { t[p].mn = min(t[p].mn, x); return; }
		pushdown(p);
		if(pos <= mid) modify(l, mid, pos, ls, x);
		else modify(mid + 1, r, pos, rs, x);
		t[p].mn = min(t[ls].mn, t[rs].mn);
	}

	inline void add(int l, int r, int ql, int qr, int p, ll x) {
		if(l == ql && r == qr) return pushtag(p, x);
		pushdown(p);
		if(qr <= mid) add(l, mid, ql, qr, ls, x);
		else if(ql > mid) add(mid + 1, r, ql, qr, rs, x);
		else add(l, mid, ql, mid, ls, x), add(mid + 1, r, mid + 1, qr, rs, x);
		t[p].mn = min(t[ls].mn, t[rs].mn);
	}

	inline ll query(int l, int r, int ql, int qr, int p) {
//		cerr << l << " " << r << " " << ql << " " << qr << endl;
		if(l == ql && r == qr) return t[p].mn;
		pushdown(p);
		if(qr <= mid) return query(l, mid, ql, qr, ls);
		else if(ql > mid) return query(mid + 1, r, ql, qr, rs);
		else return min(query(l, mid, ql, mid, ls), query(mid + 1, r, mid + 1, qr, rs));
	}

	inline ll getmin(int l, int r, int p, int ty) {
		if(l == r) return t[p].mn + ty * r;
		pushdown(p);
		return min(getmin(l, mid, ls, ty), getmin(mid + 1, r, rs, ty));
	}
	#undef ls
	#undef rs
	#undef mid
} T, RT;

int main() {
	n = read(); m = read(); a[1] = read(); a[2] = read();
	rep(i, 1, m) a[i + 2] = read();
	T.modify(1, n, a[1], 1, a[1]); RT.modify(1, n, a[1], 1, -a[1]);
	rep(i, 3, m + 2) {
		ll tmp = min(T.query(1, n, a[i], n, 1) - a[i], RT.query(1, n, 1, a[i], 1) + a[i]);
//		cerr << tmp << endl;
		T.add(1, n, 1, n, 1, abs(a[i] - a[i - 1]));
		RT.add(1, n, 1, n, 1, abs(a[i] - a[i - 1]));
		T.modify(1, n, a[i - 1], 1, tmp + a[i - 1]); RT.modify(1, n, a[i - 1], 1, tmp - a[i - 1]);
	}
	cout << T.getmin(1, n, 1, -1) << endl;
	return 0;
}
/*
f[2][1] = 0
f[3][1] = 5 -> ABB
f[3][2] = 2 -> ABA
f[4][1] = 7 -> ABBB
f[4][2] = 4 -> ABAA
f[4][3] = 5 -> ABAB
*/

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

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

#define N 262144
ll dp[2][2*N+5];
int n,q,a,b;

#define INM 100000000000000000LL
//0-index
void update(int id,int k,ll a)
{
	k += N-1;
	dp[id][k] = a;
	while(k > 0)
	{
		k = (k-1)/2;
		dp[id][k] = min(dp[id][k*2+1],dp[id][k*2+2]);
	}
}

ll query(int id,int a,int b,int k=0,ll l=0,ll r=N)
{
	if(r <= a || b <= l)return INM;
	if(a <= l && r <= b)return dp[id][k];
	else
	{
		ll vr = query(id,a,b,k*2+1,l,(l+r)/2);
		ll vl = query(id,a,b,k*2+2,(l+r)/2,r);
		return min(vr,vl);
	}
}

int main()
{
	cin >> n >> q >> a >> b;
	REP(i,2)REP(j,N)update(i,j,INM);

	vector<int> que;que.PB(a);

	REP(i,q)
	{
		int tmp;cin >> tmp;que.PB(tmp);
	}

	update(0,b,b);
	update(1,b,n-b);

	//cout  << query(1,0,n+1) << endl;

	ll sum = 0;
	for(int i = 1;i <= q;i++)
	{
		ll tmp = abs(que[i-1]-que[i]);
		sum += tmp;

		ll mi = min(query(1,0,que[i]+1)-(n-que[i]),query(0,que[i],n+1)-que[i]);
		//cout << query(1,0,que[i]+1)-que[i]+1<< ' ' << query(0,que[i],n+1)-que[i] << endl;
		update(0,que[i-1],mi-tmp+que[i-1]);
		update(1,que[i-1],mi-tmp+n-que[i-1]);
	}

	ll ans = INM;

	REP(i,n+1)
	{
		ans = min(ans,dp[0][i+N-1]-i);
		ans = min(ans,dp[1][i+N-1]-(n-i));
	}

	cout << ans + sum << endl;

	return 0;
}


#include<iostream>
using namespace std;
long long n[50], p;
int main() {
	n[0] = 1; n[1] = 1; n[2] = 2;
	for (int i = 3; i < 40; i++) {
		n[i] = n[i - 1] + n[i - 2] + n[i - 3];
	}
	while (true) {
		cin >> p;
		if (!p) { break; }
		cout << (n[p] + 3649) / 3650 << endl;
	}
}


#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) (int)floor(pow(a,n))
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mp;
void Solve()
{
    ll n;
    cin>>n;
    vll v;
    bool prime[100000];
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=false;
    for (ll p=2; p<=n; p++)
    {

        if (prime[p] == true)
        {

            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    ll i,j,sum=0,ans=1;
    rep(i,0,n+1)
    {
        if(prime[i])
        {
            v.pb(i);

        }
    }

    rep(i,0,v.size())
    {
        rep(j,1,10){
            sum+=(n/power(v[i],j));
        }
        ans*=(sum+1);
        ans%=mod;
        sum=0;
    }
    cout<<ans<<endl;
}

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

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
    int n,m;cin >> n >> m;
    vector<int> a(n),b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(RALL(a));
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    sort(RALL(b));
    LL h=0,w=0;
    LL ans = 1, res = 0;
    for (int i = n*m; i >= 1; i--) {
        if(h < n && i == a[h] && w < m && i == b[w]){
            h++;
            w++;
            res += h + w - 2;
        }
        else if(h < n && i == a[h]){
            if(w==0) ans = 0;
            h++;
            res += w - 1;
            ans = ans * w % mod;
        }
        else if(w < m && i == b[w]){
            if(h==0) ans = 0;
            w++;
            res += h - 1;
            ans = ans * h % mod;
        }
        else{
            if(res <= 0) ans = 0;
            ans = ans * res % mod;
            res--;
        }
    }
    cout << ans << endl;
    return 0;
}


// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int pointW[10], pointK[10];

void solve() {
	sort(pointW, pointW + 10, greater<int>());
	sort(pointK, pointK + 10, greater<int>());

	cout << pointW[0] + pointW[1] + pointW[2] << " " << pointK[0] + pointK[1] + pointK[2] << endl;
}

int main() {
	for_(i,0,10) cin >> pointW[i];
	for_(i,0,10) cin >> pointK[i];
	solve();
	return 0;
}

#include <iostream>
using namespace std;

int main() {
	int n, m, d;
	cin >> n >> m >> d;
	double ans = (double)2 * (n-d) / n / n * (m-1);
	if (d == 0) ans /= 2;
	printf("%.15lf\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];
double w[1000],v[1000];
double box[200010];

#define MAX 10000
struct Edge{int to,cost;};
vector<Edge> G[MAX];
int mincost[MAX];
bool used[MAX];

int prim(){
  int res = 0;
  rep(i,0,n){
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  while(1){
    int v = -1;
    rep(i,0,n){
      if(!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i;
    }
    if(v == -1)break;
    used[v] = true;
    res += mincost[v];
    rep(i,0,G[v].sz){
      mincost[G[v][i].to] = min(mincost[G[v][i].to],G[v][i].cost);
    }
  }
  return res;
}

int main(){
  int m;
  int p,q,r;
  cin >> n >> m;
  rep(i,0,m){
    int p,q,r;
    cin >> p >> q >> r;
    G[p].pb(Edge{q,r});
    G[q].pb(Edge{p,r});
  }
  cout << prim() << endl;
  return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#define PAIR pair<long long,int>
using namespace std;

class island{
public:
    vector<PAIR> road;
    void add(int goal,int much){
        road.push_back(PAIR(much,goal));
    }
};
long long func(vector<island>&,int,int);
int main(){
    int n,m;
    while(cin>>n>>m&&n){
        vector<island> map(n+1);
        for(int i=0;i<m;++i){
            int type;
            cin>>type;
            if(type==1) {
                int a,b,much;
                cin>>a>>b>>much;
                map[a].add(b,much);
                map[b].add(a,much);
            }else{
                int s,g;
                cin>>s>>g;
                cout<<func(map,s,g)<<endl;
            }
        }
    }
    return 0;
}

long long func(vector<island>& map,int s,int g){
    vector<long long> much(map.size()+1,-1);
    priority_queue<PAIR,vector<PAIR>,greater<PAIR> > que;
    que.push(PAIR(0,s));
    much[s]=0;
    while(!que.empty()){
        PAIR dpair = que.top();
        que.pop();
        long long time = dpair.first;
        int np = dpair.second;
        if(much[np]!=time){
            continue;
        }
        for(vector<PAIR>::iterator itr = map[np].road.begin();itr!=map[np].road.end();++itr){
            long long ntime = time + itr->first;
            int ng = itr->second;
            if(much[ng]==-1||much[ng]>ntime){
                much[ng]=ntime;
                que.push(PAIR(ntime,ng));
            }
        }
    }
    return much[g];
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;
int cnt=0;
void bubbleSort(vector<int> &A, int N){ // N 個の要素を含む 0-オリジンの配列 A
  int flag = 1; // 逆の隣接要素が存在する
    while (flag){
      flag = 0;
      for (int j=N-1;j>=1;j--){
        if (A[j] < A[j-1]){
          cnt++;
          swap(A[j],A[j-1]);
          flag = 1;
        }
      }
    }
}
int main() {
  int64_t X;
  cin>>X;
  cout<<X/500*1000+X%500/5*5<<endl;;
  return 0;
}

//
//  ALDS12A_BubbleSort.cpp
//  CppAlgorithmSet
//
//  Created by 蒋春恺 on 2018/12/19.
//  Copyright © 2018 蒋春恺. All rights reserved.
//

#include <iostream>

using namespace std;

template <class T>
void printArray(T Array, int size)
{
    for (int i = 0; i < size; i++) {
        cout << Array[i];
        if (i != size - 1) cout << " ";
    }
    cout << endl;
}

void swap(int & a, int & b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

void bubbleSort(int A[], int N)
{
    int count = 0;
    bool flag = true;

    while (flag) {
        flag = false;
        for (int j = N - 1; j > 0; j--) {
            if (A[j] < A[j-1]) {
                count++;
                swap(A[j], A[j-1]);
                flag = true;
            }
        }
    }

    printArray(A, N);
    cout << count << endl;
}

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

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

    bubbleSort(A, N);

    return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n,a,b;
    cin>>n>>a>>b;
    int ans=(n-a+1)*(n-b+1);
    if(ans<0){
        cout<<0<<endl;
    }
    else{
        cout<<ans<<endl;
    }

}

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

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

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

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

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

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

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

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

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

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

int main(){

  ll N, H, W;
  cin >> N >> H >> W;

  cout << (N-H+1) * (N-W+1) << endl;

}


#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,a,b;
	cin >> n >> a >> b;
	if(n == 1){
		cout << "Hello World ";
	}
	else{
		cout << a+b;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  if(n==1) {
   cout<<"Hello World"<<endl;
    return 0;
  }
  int a,b;
  cin>>a>>b;
  cout<<a+b<<endl;
}


#include <bits/stdc++.h>

const int N = 108;

int n;
int a[N], b[N];

int main() {
	int i, mid;
	scanf("%*d%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", a + i);
	if (n == 1) return *a == 1 ? puts("1\n1\n1") : printf("%d\n2\n1 %d\n", *a, *a - 1), 0;
	mid = std::partition(a, a + n, [] (const int x) -> bool {return x % 2;}) - a;
	if (mid > 2) return puts("Impossible"), 0;
	a[n] = *a;
	for (i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? 10 : 32);
	memcpy(b + 1, a + 1, n << 2), ++b[1], --b[n], n -= !b[n];
	printf("%d\n", n);
	for (i = 1; i <= n; ++i) printf("%d%c", b[i], i == n ? 10 : 32);
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN = 100 + 10;

int total, N;
int a[MAXN]= {0};
int st[MAXN]= {0}, ed[MAXN]= {0};
int odd[MAXN]= {0}, ocnt = 0;

int ans[MAXN]= {0}, acnt = 0;

int getnum () {
	int num = 0;
	char ch = getchar ();

	while (! isdigit (ch))
		ch = getchar ();
	while (isdigit (ch))
		num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();

	return num;
}

int main () {
	total = getnum (), N = getnum ();
	for (int i = 1; i <= N; i ++) {
		a[i] = getnum ();
		if (a[i] & 1) odd[++ ocnt] = i;
	}
	if (N == 1) {
		printf ("%d\n", a[1]);
		if (total == 1) puts ("1"), puts ("1");
		else {
			puts ("2");
			printf ("1 %d\n", total - 1);
		}
		return 0;
	}
	if (ocnt > 2) {
		puts ("Impossible");
		return 0;
	}
	if (ocnt >= 1) swap (a[1], a[odd[1]]);
	if (ocnt >= 2) swap (a[N], a[odd[2]]);
	ans[++ acnt] = a[1] + 1;
	for (int i = 2; i < N; i ++) ans[++ acnt] = a[i];
	if (a[N] - 1 > 0) ans[++ acnt] = a[N] - 1;
	for (int i = 1; i <= N; i ++) {
		if (i > 1) putchar (' ');
		printf ("%d", a[i]);
	}
	printf ("\n%d\n", acnt);
	for (int i = 1; i <= acnt; i ++) {
		if (i > 1) putchar (' ');
		printf ("%d", ans[i]);
	}
	puts ("");

	return 0;
}

/*
3 2
2 1
*/

/*
6 1
6
*/

/*
55 10
1 2 3 4 5 6 7 8 9 10
*/


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  if (n <= 2) {
    P(n);
    return 0;
  }
  mp[2] = 1;
  for (int i = 3; i <= n; i++) {
    int tmp = i;
    while (tmp != 1) {
      int flag = 1;
      for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (tmp % itr->first == 0) {
          flag = 0;
          tmp /= itr->first;
          itr->second++;
          break;
        }
      }
      if (flag == 1) {
        mp[tmp] = 1;
        tmp /= tmp;
      }
    }
  }
  ll ans = 1;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ans = (ans * (itr->second + 1)) % mod;
    // cout << itr->first << " => " << itr->second << endl;
  }
  P(ans);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a,ans=1;cin >> a;
    const ll p=1000000007;
    vector<ll> v(a,0);
    for (ll i=1;i<=a;i++){
        int cur=i;
        for (int b=2;b<=i;b++){
            while(cur%b==0){
                cur/=b;
                v[b-1]++;
            }
        }
    }
    for (int i=1;i<a;i++){
        ans=ans*(v[i]+1ll);
        ans%=p;
    }
    cout << ans;
    // D:
    // D:
    // D:
    // D:
    // D:
    // D:
    // D:
    // D:
    // D:
    // D:
    // :D
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

//using namespace __gnu_pbds;
using namespace std ;

typedef pair<int, int> pi ;
//typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const i64 mod = 1000000007LL ;
#define INF 2000000000001LL
#define maxn 200005

/*
     *os.find_by_order(k) -> returns the k'th smallest element (indexing starts from 0)
      os.order_of_key(v)  -> returns how many elements are strictly smaller than v
*/

int Left[2002][2002] , Up[2002][2002] ;
int ones[2002][2002] ;
char s[2005][2005] ;

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

    scanf("%d %d %d",&n,&m,&q) ;

    for(int i=1 ; i<=n; i++) scanf("%s",s[i]+1) ;

    for(int i=1; i<=n ; i++)
    {
        for(int j=1 ; j<=m ; j++)
        {
            if( s[i][j]=='1' ) ones[i][j] = 1 ;
        }
    }

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=m ; j++)
        {
            if( ones[i][j] == 1 && ones[i-1][j] == 1 ) Up[i][j] = 1 ;
            if( ones[i][j] == 1 && ones[i][j-1] == 1 ) Left[i][j] = 1 ;
        }
    }

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=m ; j++)
        {
            Left[i][j] += Left[i][j-1] ;
            Up[i][j] += Up[i][j-1] ;
        }
        for(int j=1 ; j<=m ; j++)
        {
            Left[i][j] += Left[i-1][j] ;
            Up[i][j] += Up[i-1][j] ;
        }
    }

    for(int i=1 ; i<=n ; i++)
    {
        for(int j=1 ; j<=m; j++) ones[i][j] = ones[i][j-1] + ones[i][j] ;
        for(int j=1 ; j<=m; j++) ones[i][j] += ones[i-1][j] ;
    }

    for(int i=1 ; i<=q ; i++)
    {
        int x1 , y1 , x2, y2 ;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2) ;

        int nodes = ones[x2][y2] - ones[x1-1][y2] - ones[x2][y1-1] + ones[x1-1][y1-1] ;
        int edgesHor = Left[x2][y2] - Left[x1-1][y2] - Left[x2][y1] + Left[x1-1][y1] ;
        int edgesVer = Up[x2][y2] - Up[x1][y2] - Up[x2][y1-1] + Up[x1][y1-1] ;

        printf("%d\n",nodes-edgesHor-edgesVer) ;
    }

    return 0 ;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a[100100];
int main() {
	int n, k;
	cin >> n >> k;
	rep(i,n) cin >> a[i];

	sort(a,a+n);

	bool can = true;
	if (a[n-1] < k) can = false;
	int g = a[0];
	rep(i,n) g = __gcd(g,a[i]);
	if (k % g != 0) can = false;

	if (can) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}

#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
   string a,b,c;
   cin>>a>>b>>c;
   int len=a.size();
   int len2=b.size();
   int len3=c.size();
   if(a[len-1]==b[0] && b[len2-1]==c[0] )cout<<"YES\n";
   else cout<<"NO";

}


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

int main() {
  int a , b, c, d;
  cin >> a >> b >> c >> d;
  int s = min(a,b);
  int t = min(c,d);
  cout << s+t << endl;
  return 0;
}

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

int main(){
  int64_t A,B;
  int K;
  cin >> A >> B >> K;
  while(K>0){
    A/=2;
    B+=A;
    K--;
    if(K==0){
      break;
    }
    B/=2;
    A+=B;
    K--;
  }
  cout << A << " " << B << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int gcd(int a,int b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
int main(){
  int n,k,a[100010],i;
  cin >> n >> k;
  int z=0;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(a[i]>=k){
      z=1;
    }
  }
  if(z==0){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if(n==1){
    if(a[0]==k){
      cout << "POSSIBLE" << endl;
    }
    else{
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  int x=gcd(a[0],a[1]);
  for(i=2;i<n;i++){
    x=gcd(x,a[i]);
  }
  if(k%x==0){
    cout << "POSSIBLE" << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,v,m,i;
  map<int,int> m0,m1;
  vector<pair<int,int>> v0,v1;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>v;
    if(i%2==0){
      if(m0.count(v)) m0.at(v)++;
      else m0[v]=1;
    }
    else if(i%2==1){
      if(m1.count(v)) m1.at(v)++;
      else m1[v]=1;
    }
  }
  for(auto z:m0) v0.push_back(make_pair(z.second,z.first));
  sort(v0.begin(),v0.end());
  reverse(v0.begin(),v0.end());
  for(auto z:m1) v1.push_back(make_pair(z.second,z.first));
  sort(v1.begin(),v1.end());
  reverse(v1.begin(),v1.end());
  if(v0.at(0).second!=v1.at(0).second) cout<<n-v0.at(0).first-v1.at(0).first<<endl;
  else if(v0.at(0).first+v1.at(0).first==n) cout<<n/2<<endl;
  else if(v0.size()>1&&v0.size()>1){
    m=max(v0.at(0).first+v1.at(1).first,v0.at(1).first+v1.at(0).first);
    cout<<n-m<<endl;
  }
  else if(v0.size()>1) cout<<n/2-v0.at(1).first<<endl;
  else if(v1.size()>1) cout<<n/2-v1.at(1).first<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> dy = { 0,1,0,-1 };
vector<int> dx = { 1,0,-1,0 };

int main() {

	int h, w; cin >> h >> w;
	vector<vector<char>> c(h + 2, vector<char>(w + 2, 'e'));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c[i][j];
		}
	}
	bool can = true;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			bool tmpCan = false;
			if (c[i][j] == '#') {
				for (int k = 0;  k < 4;  k++) {
					if (c[i + dy[k]][j + dx[k]] == '#') {
						tmpCan = true;
					}
				}
				if (!tmpCan) can = false;
			}
		}
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

ll lcm(ll x, ll y) {
    return x / __gcd(x, y) * y;
}

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  rep(i, 0, N) cin >> A[i];
  long maxa = accumulate(all(A), A[0], [](long x, long y) {return max(x, y);});
  if (maxa < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  long gcd1 = accumulate(all(A), A[0], [](long x, long y) {return __gcd(x, y);});
  long gcd2 = __gcd(gcd1, K);
  if (gcd1 == gcd2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
const int N = 2e6;

int n, m;
int tot = 0, tag = 0, cnt = 0;
int vis[N], b[N], fa[N], num[N], Link[N], dis[N];
struct node { int x, y; };
struct edge { int y, next, v; } e[N*2];
vector < node > a[N];

int read(void)
{
	int s = 0, w = 0; char c = getchar();
	while (c < '0' || c > '9') w |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar();
	return w ? -s : s;
}

int get(int x) {
	if (fa[x] == x) return x;
	return fa[x] = get(fa[x]);
}

void add(int x,int y,int v) {
	e[++tot] = edge{y,Link[x],v};
	Link[x] = tot;
}

void work(int x)
{
	int t = 0;
	tag ++;
	for (int i=0;i<a[x].size();++i)
	{
		int p1 = a[x][i].x, p2 = a[x][i].y;
		if (vis[p1] != tag) b[++t] = p1, vis[p1] = tag;
		if (vis[p2] != tag) b[++t] = p2, vis[p2] = tag;
	}
	for (int i=1;i<=t;++i) fa[b[i]] = b[i];
	for (int i=0;i<a[x].size();++i)
	{
		int p1 = a[x][i].x, p2 = a[x][i].y;
		fa[get(p1)] = get(p2);
	}
	tag ++;
	for (int i=1;i<=t;++i)
	{
		int r = get(b[i]);
		if (vis[r] != tag)
		{
			vis[r] = tag;
			num[r] = ++ cnt;
		}
		add(b[i],num[r],1);
		add(num[r],b[i],1);
	}
	return;
}

int Dijkstra(void)
{
	memset(vis,0,sizeof vis);
	memset(dis,30,sizeof dis);
	dis[1] = 0;
	priority_queue < pair<int,int> > q;
	q.push(make_pair(0,1));
	while (q.size())
	{
		int x = q.top().second; q.pop();
		if (vis[x]) continue; vis[x] = 1;
		if (x == n) return dis[x] / 2;
		for (int i=Link[x];i;i=e[i].next)
		{
			int y = e[i].y, v = e[i].v;
			if (dis[x] + v < dis[y]) {
				dis[y] = dis[x] + v;
				q.push(make_pair(-dis[y],y));
			}
		}
	}
	return -1;
}

int main(void)
{
	n = cnt = read(), m = read();
	for (int i=1;i<=m;++i)
	{
		int x = read(), y = read(), v = read();
		a[v].push_back(node{x,y});
	}
	for (int i=1;i<=1e6;++i)
	    if (a[i].size()) work(i);
	printf("%d", Dijkstra());
	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 vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

struct UnionFind {
  vector<int> parent;
  vector<int> num_node;

  UnionFind(int N) : parent(N), num_node(N, 1) {
    for (int i = 0; i < N; i++) {
      parent[i] = i;
    }
  }

  // 根を求める
  int root(int x) {
    if (parent[x] == x) {
      return x;
    }

    // 経路圧縮
    parent[x] = root(parent[x]);
    return parent[x];
  }

  // 同一判定
  bool is_same(int x, int y) {
    return this->root(x) == this->root(y);
  }

  // 併合
  void unite(int x, int y) {
    x = this->root(x);
    y = this->root(y);

    // すでに一緒ならなにもしない
    if (x == y) {
      return;
    }
    parent[x] = y;
    num_node[y] += num_node[x];
  }

  // 同一グループのノード数
  int size(int x) {
    return num_node[root(x)];
  }
};

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

  ll h, w;
  cin >> h >> w;
  vs s(h);
  rep(i, h) {
    cin >> s[i];
  }

  ll n = h * w;
  UnionFind uf(n);
  vector<vb> visited(h, vb(w));

  rep(i, n) {
    ll y = i / w;
    ll x = i % w;

    if (visited[y][x]) {
      continue;
    }

    queue<P> q;
    q.push(make_pair(y, x));

    while (!q.empty()) {
      auto it = q.front();
      q.pop();

      ll v = it.first * w + it.second;
      uf.unite(i, v);

      ll y = it.first;
      ll x = it.second;

      if (y > 0) {
        if (!visited[y - 1][x] && s[y - 1][x] != s[y][x]) {
          q.push(make_pair(y - 1, x));
          visited[y - 1][x] = true;
        }
      }
      if (y < h - 1) {
        if (!visited[y + 1][x] && s[y + 1][x] != s[y][x]) {
          q.push(make_pair(y + 1, x));
          visited[y + 1][x] = true;
        }
      }

      if (x > 0) {
        if (!visited[y][x - 1] && s[y][x - 1] != s[y][x]) {
          q.push(make_pair(y, x - 1));
          visited[y][x - 1] = true;
        }
      }
      if (x < w - 1) {
        if (!visited[y][x + 1] && s[y][x + 1] != s[y][x]) {
          q.push(make_pair(y, x + 1));
          visited[y][x + 1] = true;
        }
      }
    }
  }

  vector<P> vp(n);

  rep(i, n) {
    ll y = i / w;
    ll x = i % w;
    if (s[y][x] == '.')
      vp[uf.root(i)].first++;
    else
      vp[uf.root(i)].second++;
  }

  ll ans = 0;
  rep(i, n) {
    ans += vp[i].first * vp[i].second;
  }

  cout << ans << endl;

  return 0;
}


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

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

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

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

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

ll dp[105][10];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w,k; cin>>h>>w>>k;
  k--;
  dp[0][0]=1;
  rep(i,h){
    rep(j,w){
      for(ll bit=0; bit<(1<<(w-1)); bit++){
        bool ok=true;
        rep(ki,w-2){
          if(bit>>ki&1 && bit>>(ki+1)&1){
            ok=false;
            break;
          }
        }
        if(!ok) continue;
        ll nj=j;
        if(bit>>j&1) nj=j+1;
        else if(j>0 && bit>>(j-1)&1) nj=j-1;
        dp[i+1][nj]+=dp[i][j];
        dp[i+1][nj]%=MOD;
      }
    }
  }
  cout<<dp[h][k]<<endl;
}

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

Int dp[201][1000001];

void solve()
{
	int n, x;
	cin >> n >> x;
	vector<int> S(N);
	for (int i = 0; i < n; i++) cin >> S[i];
	sort(S.rbegin(), S.rend());

	dp[0][x] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 100000; j++) {
			dp[i + 1][j%S[i]] = (dp[i + 1][j%S[i]] + dp[i][j]) % MOD;
			dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * (n - i - 1)) % MOD;
		}
	}

	Int ans = 0;
	for (int j = 0; j <= 100000; j++) ans = (ans + (j*dp[n][j]%MOD)) % MOD;
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


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

typedef vector<vector<int> > Matrix;
int w,h,xs,ys,xg,yg,n,color;
string res = "NG";
Matrix board(101, vector<int>(101,0));

void write(Matrix &board,int c, int d, int x, int y){
  int width,length;
  if(d == 0){ width = 4; length =2; }
  if(d == 1){ width = 2; length =4; }
  for(int i=0; i<width; ++i){
    for(int j=0; j<length; ++j)
      board[x+i][y+j]=c;
  }
}
void func(Matrix &board,int nx,int ny){
  if(board[nx][ny] == 0){
    res = "NG";
    return;
  }
  if( nx==xg && ny==yg){
    res = "OK";
    return;
  }
  board[nx][ny] = 0;
  if( 0<=nx-1 && color==board[nx-1][ny])
    func(board,nx-1,ny);
  if( 0<=ny-1 && color==board[nx][ny-1])
    func(board,nx,ny-1);
  if( nx+1<=w && color==board[nx+1][ny])
    func(board,nx+1,ny);
  if( ny+1<=h && color==board[nx][ny+1])
    func(board,nx,ny+1);
}

int main(void){
  int c,d,x,y;
  while(cin >> w >> h,w||h){
    if( w==0 && h==0) return 0;
    res = "NG";
    cin >> xs >> ys >> xg >> yg >> n;
    xs--; ys--; xg--; yg--;
    //    Matrix board(w, vector<int>(h,0));
    for(int i=0; i<n; ++i){
      cin >> c >> d >> x >> y;
      --x; --y;
      write(board,c,d,x,y);
    }
    color = board[xs][ys];
    func(board,xs,ys);
    cout << res << endl;
    //    board.clear();
  }
  return 0;
}

#include <iostream>
#include <cstring>
using namespace std;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int w,h,xg,yg,xs,ys,n,fld[101][101];
bool dfs(int x,int y,int c){
	if(c==0||fld[x][y]!=c)return false;
	if(x==xg&&y==yg)return true;
	fld[x][y]=0;
	for(int i=0;i<4;i++)if(dfs(x+dx[i],y+dy[i],c))return true;
	return false;
}
int main(){
	while(cin>>w>>h,w,h){
		cin>>xs>>ys>>xg>>yg>>n;
		for(int i=0;i<n;i++){
			int x,y,cc,d,r,l;
			cin>>cc>>d>>x>>y;
			if(d){r=4;l=2;}else{r=2;l=4;}
			for(int j=x;j<x+l;j++)for(int k=y;k<y+r;k++)fld[j][k]=cc;
		}
		if(dfs(xs,ys,fld[xs][ys]))cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
}


#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  cout << x + (x*x) + (x*x*x);
  return 0;
}

#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

int main()
{
	string s,t;
	cin >> s;
	t = s;
	for (int i = 0; i < s.size(); i++) {
		t[i] = s[s.size() - i-1];
	}
	cout << t << endl;

}


#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[200007];
map<ll,ll> M;

int main(){
  ll N;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    M[A[i]]++;
  }
  sort(A,A+N);
  reverse(A,A+N);
  ll ANS=0;
  rep(i,N){
    rrep(k,31){
      ll j=1<<k;
      if(A[i]>j){
        break;
      }
      if(M.find(j-A[i])!=M.end()){
        if(((j-A[i]!=A[i] && M[j-A[i]]>0) && M[A[i]]>0  )|| (j-A[i]==A[i] &&  M[j-A[i]]>1)){
          M[A[i]]--;
          M[j-A[i]]--;
          ANS++;
          break;
        }
      }
    }
  }
  cout << ANS << endl;
}

#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  vector<bool> used(N, false);
  for (ll i = N - 1; i >= 0; --i) {
    if (used.at(i)) {
      continue;
    }
    used.at(i) = true;
    ll pow2 = 1;
    while (pow2 <= A.at(i)) {
      pow2 *= 2;
    }
    ll need = pow2 - A.at(i);
    ll l = lower_bound(A.begin(), A.end(), need) - A.begin() - 1;
    ll r = upper_bound(A.begin(), A.end(), need) - A.begin();
    r = min(r, i);
    // cout << "nned" << need << endl;
    // cout << l << ' ' << r << endl;
    if (l == r) {
      continue;
    }
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      if (used.at(m)) {
        l = m;
      }
      else {
        r = m;
      }
    }
    // cout << "l" << l << "r" << r << endl;
    if (r == N) {
      continue;
    }
    if (A.at(r) != need) {
      continue;
    }
    if (used.at(r)) {
      continue;
    }
    used.at(r) = true;
    ans += 1;
    // for (ll j = l; j < r; ++j) {
    //   if (!used.at(j)) {
    //     used.at(j) = true;
    //     ans += 1;
    //     break;
    //   }
    // }
  }
  cout << ans << endl;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int Q = 1e9 + 7;

inline void add(int &A , int B) {
    A += B;
    if (A >= Q) A -= Q;
}

map< pair<vector<bool>,bool> , int> h[2];

char str[N];

int main() {
    cin >> str;
    int cur = 0 , nxt = 1;
    h[cur][make_pair(vector<bool>(), false)] = 1;

    for (int i = 0 ; str[i] ; ++ i) {
        h[nxt].clear();
        int L = str[i] - '0' , R = str[i] - '0';
        if (str[i] == '?') L = 0 , R = 1;
        // cout << L << ' ' << R << endl;
        for (auto it : h[cur]) {
            //int s = it.first.first.size() + 1;
            for (int j = L ; j <= R ; ++ j) {
                vector<bool> p = it.first.first;
                p.emplace_back(j);
                int s = p.size();
                if (s >= 3 && !(p[s - 3] == 1 && p[s - 2] == 0 && j == 0)) {
                    int q = j + p[s - 3] + p[s - 2];
                    p.pop_back();
                    p.pop_back();
                    p.pop_back();
                    p.push_back(q >= 2);
                    s -= 2;
                }
                add(h[nxt][make_pair(p , it.first.second || (s > 1 && p[0] == 1 && p[1] == 1))] , it.second);
            }
        }
        swap(cur , nxt);
    }
    int res = 0;
    for (auto &it : h[cur]) {

        /*vector<bool> p = it.first.first;
        for (int i = 0 ; i < p.size() ; ++ i) {
            cout << p[i] << ' ';
            } cout << "|  " << it.first.second << ' ' << it.second << endl;*/

        if (it.first.second || it.first.first.size() == 1 && it.first.first[0]) {
            add(res , it.second);
        }
    }
    cout << res << endl;
}


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const ll MOD=1e9+7;

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

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

  int x=0,y=0,z=0;

  ll ans=1;
  rep(i,n){
    if(A[i]==x && A[i]==y && A[i]==z){
      ans=ans*3%MOD;
      x++;
    }
    else if(A[i]==x && A[i]==y){
      ans=ans*2%MOD;
      x++;
    }
    else if(A[i]==x && A[i]==z){
      ans=ans*2%MOD;
      x++;
    }
    else if(A[i]==y && A[i]==z){
      ans=ans*2%MOD;
      y++;
    }
    else if(A[i]==x) x++;
    else if(A[i]==y) y++;
    else if(A[i]==z) z++;
    else{
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;

  return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

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

int main() {
    int N, A;
    cin >> N;
    ll ans = 1;
    vector<int> cap(3, 0);
    rep(x, N) {
        cin >> A;
        int sam = 0;
        rep(i, 3) if(A == cap[i]) sam++;
        rep(i, 3) {
            if(A == cap[i]) {
                cap[i]++;
                break;
            }
        }
        ans *= sam;
        ans %= MOD;
    }
    cout << ans << endl;
}


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

int main(){
  int r;
  cin >> r;
  if(r < 1200){
    cout << "ABC" << endl;
    return 0;
  }
  if(r < 2800){
    cout << "ARC" << endl;
    return 0;
  }
  if(r>=2800){
    cout << "AGC" << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;

bool is_prime(ll n) {
    if (n==1) return false;
    repr(i,2,int(sqrt(n)+1)) {
        if (n%i==0) return false;
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    ll s=2;
    vector<int> ans;
    int cnt=n;
    while (cnt>0) {
        if (is_prime(s) && s%5==1) {
            ans.push_back(s);
            --cnt;
        }
        ++s;
    }
    rep(i,n) cout << ans[i] << ' ';
    cout << endl;

    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii;
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<int , long long > > sales;
    while(n--){
      int id,code,num;
      cin>>id>>code>>num;
      int i = 0 ;
      for(; i < sales.size();i++){
	if(sales.at(i).first==id){
	  sales.at(i).second += (long long) code * num;
	  break;
	}
      }
      if(i == sales.size()){
	pair<int , long long> worker;
	worker.first = id;
	worker.second = (long long)code * num;
	sales.push_back(worker);
      }

    }
    bool found = false;
    rep(i,sales.size()){
      if(sales.at(i).second >= 1000000){
	found = true;
	cout << sales.at(i).first << endl;
      }
    }
    if(!found)
      cout << "NA" << endl;

  }
}

//Name: Sale Reult
//Level: 1
//Category: やるだけ
//Note:

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

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    map<int,long long> res;
    vector<int> ord;
    for(int i = 0; i < N; ++i) {
        int id, v, c;
        cin >> id >> v >> c;
        res[id] += ((long long)v)*c;
        ord.push_back(id);
    }

    bool exist = false;
    for(int id : ord) {
        if(res[id] >= 1000000) {
            cout << id << endl;
            res[id] = 0;
            exist = true;
        }
    }
    if(!exist) cout << "NA" << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(int argc, char *argv[]){
  int n, m;
  cin >> n >> m;
  vector<vector<lli> > g(n, vector<lli>(n, 1LL<<40));
  int from, to, cost;
  for (int i = 0; i < n; i++) {
    g[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> from >> to >> cost;
    g[from][to] = cost;
  }
  //???????????§?????????
  //???????????????????????£???????????????
  bool neg_cycle = false;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if(g[i][j] == 1LL<<40 &&
           (g[i][k] == 1LL<<40 || g[k][j] == 1LL<<40))continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if(g[i][i] < 0)neg_cycle = true;
  }
  if(neg_cycle){
    std::cout << "NEGATIVE CYCLE" << std::endl;
    return 0;
   }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if(g[i][j] >= 1LL<<40)std::cout << "INF ";
      else std::cout << g[i][j] << " ";
    }
    if(g[i][n - 1] >= 1LL<<40)std::cout << "INF" << std::endl;
    else std::cout << g[i][n - 1] << std::endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using Grid = vector<vector<int>>;
using vi = vector<int>;

int main() {
    int N, Q;
    cin >> N >> Q;
    list<tuple<int, int, int>> eve;
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        eve.emplace_back(s - x, 1, x);
        eve.emplace_back(t - x, -1, x);
    }
    eve.sort();
    set<int> ms;
    rep(i, Q) {
        int p;
        cin >> p;
        while (eve.size() > 0 && get<0>(eve.front()) <= p) {
            if (get<1>(eve.front()) == 1)
                ms.insert(get<2>(eve.front()));
            else
                ms.erase(get<2>(eve.front()));
            eve.pop_front();
        }
        cout << (ms.size() == 0 ? -1 : *(ms.begin())) << endl;
    }
}


#include <iostream>

using namespace std;
int main(){
	int d;
	cin>>d;
	string buf;
	string key="Hoshino";
	string newkey="Hoshina";
	unsigned int p;
getline(cin,buf);
	while(d--){
		getline(cin,buf);
		while((p=buf.find(key,0))!=string::npos){
			buf.replace(p,key.size(),newkey);
		}
		cout<<buf<<endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    getchar();
    while(n!=0){
        string str;
        getline(cin,str);
        for(int i=0;i<str.length();i++){
            if(str[i]=='H' && str[i+1]=='o' && str[i+2]=='s' && str[i+3]=='h' && str[i+4]=='i' && str[i+5]=='n' && str[i+6]=='o'){
                str[i+6]='a';
                i += 6;
            }
        }
        cout<<str<<endl;
        n--;
    }
    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(n) begin(n), end(n)
using ll = long long;
using namespace std;

struct node{
	int data;
	node *l, *r;
};

node *new_node(int in){
	node *ret = new node;
	ret->data = in;
	ret->l = NULL;
	ret->r = NULL;
	return ret;
}

void insert_node(node **root, int in){
	node *add = new_node(in);
	if(*root == NULL){
		*root = add;
		return ;
	}
	node *p = *root, *pp = NULL;
	while(p != NULL){
		pp = p;
		if(add->data < p->data) p = p->l;
		else p = p->r;
	}
	if(add->data < pp->data) pp->l = add;
	else pp->r = add;
	return ;
}

void print_n(node *root, bool mode){
	if(mode == true) cout << " " << root->data;
	if(root->l != NULL) print_n(root->l, mode);
	if(mode == false) cout << " " << root->data;
	if(root->r != NULL) print_n(root->r, mode);
}

void print_node(node *root){
	print_n(root, false);
	cout << endl;
	print_n(root, true);
	cout << endl;
}

void find_node(node *root, int in){
	bool ans = false;
	while(root != NULL){
		if(in == root->data){
			ans = true;
			break;
		}else if(in < root->data){
			root = root->l;
		}else{
			root = root->r;
		}
	}
	if(ans == false) cout << "no" << endl;
	else cout << "yes" << endl;
}

void delete_node(node **root, int in){
	node *p = *root, *pp = NULL;
	while(p != NULL){
		if(p->data == in) break;
		pp = p;
		if(in < p->data) p = p->l;
		else p = p->r;
	}
	if(p->l == NULL && p->r == NULL){
		if(in < pp->data) pp->l = NULL;
		else pp->r = NULL;
		delete p;
		return ;
	}
	if(p->l == NULL){
		if(in < pp->data) pp->l = p->r;
		else pp->r = p->r;
		delete p;
		return;
	}
	if(p->r == NULL){
		if(in < pp->data) pp->l = p->l;
		else pp->r = p->l;
		delete p;
		return;
	}
	node *rl = p->r, *prl = p;
	while(rl->l != NULL){
		prl = rl;
		rl = rl->l;
	}
	if(in < pp->data) pp->l = rl;
	else pp->r = rl;
	if(prl != p)prl->l = rl->r;
	else prl->r = rl->r;
	rl->l = p->l;
	rl->r = p->r;
	delete p;
}

int main(){
	int n;
	cin >> n;
	node *root = NULL;
	rep(i, n){
		string s;
		cin >> s;
		if(s == "print"){
			print_node(root);
		}else if(s == "find"){
			int in;
			cin >> in;
			find_node(root, in);
		}else if(s == "delete"){
			int in;
			cin >> in;
			delete_node(&root, in);
		}else{
			int in;
			cin >> in;
			insert_node(&root, in);
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

ll modinv(ll a) {
    ll m=Mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  ll i,j;
  ll n;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++) cin>>a[i];
  ll sum=0;
  for(i=0;i<n;i++){
      sum=sum^a[i];
  }

      ll tmp=0;
      ll z=1;
      ll q=modinv(2);
      vector<ll> v0(1<<20,1),v1(1<<20,0);
      vector<ll> vz(1<<20,0);

      for(i=0;i<n;i++){
          tmp=tmp^a[i];
          if(tmp==0){
              z++;
              q*=2;
              q%=Mod;
          }
          else {
              v0[tmp]+=v1[tmp]*(z-vz[tmp]);
              v0[tmp]%=Mod;
              v1[tmp]+=v0[tmp];
              v1[tmp]%=Mod;
              vz[tmp]=z;

          }
      }

      if(sum!=0) {
          cout<<v0[sum]<<endl;
      }

      else {
          ll ans=0;
          for(i=0;i<(1<<20);i++) ans+=v1[i];
          cout<<(ans+q)%Mod<<endl;
      }

  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout);
  #endif
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL) ;
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
       int n,r;
       cin>>n>>r;
       int x=0;
       if(n<=9)
       x=100*(10-n);
       cout<<r+x;

    }
}

// 🍪 🍪 🍪

 /*

                   بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
                  لآ اِلَهَ اِلّا اللّهُ مُحَمَّدٌ رَسُوُل اللّهِ
*/

/*
    Auther:   n0oO0o0Ob(None of them)
    from  :   https://n0oo0o0ob.sleek.page/

*/

#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define pb push_back

                                        #define noob n0oO0o0Ob
// ---------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
//----------------------------------
const ld PI = acos((ld)-1);
const int MOD = 1000000007;
//----------------------------------

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int a, b;
    cin >> a >> b;
    int x = 100 *(10-a);
    if(a <= 10) cout << x+b << endl;
    else cout << b << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fio                         \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);                    \
cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d;
    ll sx, sy, tx, ty;
cin>>sx>>sy>>tx>>ty;
    for (i=0;i<tx-sx;i++)
        cout<<'R';

    for (i=0;i<ty-sy;i++)
        cout<<'U';
    for (i=0;i<tx-sx;i++)
        cout<<'L';

    for (i=0;i<ty-sy;i++)
        cout<<'D';
    cout<<'D';
    for (i=0;i<tx-sx+1;i++)
        cout<<'R';

    for (i=0;i<ty-sy+1;i++)
        cout<<'U';
    cout<<'L';
    cout<<'U';
    for (i=0;i<tx-sx+1;i++)
        cout<<'L';

    for (i=0;i<ty-sy+1;i++)
        cout<<'D';

    cout<<'R';

    return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

     rep(i, min(2000, k)){
         vector<int> imos(n+1);
         rep(j, n){
             int s = max(0, j - A[j]), g = min(n, j + A[j] + 1);
             imos[s]++;
             imos[g]--;
         }
         rep(j, n){
             if(j)A[j] = A[j-1]; else A[j] = 0;
             A[j] += imos[j];
         }
     }
     rep(i, n)cout << A[i] << " ";
     cout << ln;
}


#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VI> a(n, VI(n-1));
	rep(i, n) rep(j, n-1){ cin >>a[i][j]; a[i][j]--;}
	rep(i, n) reverse(all(a[i]));
	int ans = 0;
	VI seq(n); iota(all(seq), 0);
	for(int g=0, nxt =1; nxt; g++){
		nxt = 0;
		VI usd(n);
		VI nsq;
		swap(seq, nsq);
		rep(pi, sz(nsq)){
			int i = nsq[pi];
			if(usd[i] !=0 || sz(a[i]) < 1) continue;
			int tcr = a[i].back();
			if(a[tcr].back() == i && usd[tcr]==0){
				usd[i] = usd[tcr] = 1;
				a[tcr].pop_back();
				a[i].pop_back();
				nxt = 1;
				ans = max(ans, g+1);
				seq.push_back(i); seq.push_back(tcr);
			}
		}
		sort(all(seq));
		seq.erase(unique(all(seq)), seq.end());
	}
	rep(i, n) if(sz(a[i])>0) ans =-1;
	cout <<ans <<"\n";
	return 0;

}

// https://atcoder.jp/contests/abc088/tasks/abc088_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#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++)
const int MAX_N=100;

int h, w;
typedef pair<int, int> P;
vector<vector<char> > maze(MAX_N, vector<char>(MAX_N));
int sx, sy, gx, gy;

vector<vector<ll> > d(MAX_N, vector<ll>(MAX_N));

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

ll bfs(){
    queue<P> que;
    // すべての点をINFで初期化
    rep(x, w)
        rep(y, h) d.at(x).at(y) = INF;
    // スタート地点をqueに入れ、その点距離を0とする
    que.push(P(sx,sy));
    d.at(sx).at(sy) = 0;

    // queが空になるまでループ
    while(que.size()){
        //　キューの先頭を取り出す
        P p = que.front();
        que.pop();
        //　取り出してきた状態がゴールならば探索終了
        if(p.first == gx && p.second == gy) break;
        //　４方向をループ
        rep(i, 4){
            int nx = p.first + dx.at(i), ny = p.second + dy.at(i);

            //　移動が可能かどうかの判定とすでに訪れたことがあるかどうかの判定
            if(0 <= nx && nx < w && 0 <= ny && ny < h && maze.at(nx).at(ny) != '#' && d.at(nx).at(ny) == INF){
                //　移動可能ならばキューに追加、点の距離を+1して確定させる
                que.push(P(nx,ny));
                d.at(nx).at(ny) = d.at(p.first).at(p.second) + 1;
            }
        }
    }
    return d.at(gx).at(gy);
}

int main(){
    //　入力に注意すること!
    //　特に座標を-1することを忘れないこと!
    cin >> h >> w;
    sx = 0; sy = 0; gx = w-1; gy = h-1;
    int road = 0;
    rep(y, h){
        rep(x, w){
            cin >> maze.at(x).at(y);
            if(maze.at(x).at(y) == '.') road++;
        }
    }
    //rep(y, h){rep(x, w){cout << maze.at(x).at(y);}cout << "\n";}cout << "---\n";
    ll answer = bfs();
    //rep(y, h){rep(x, w){cout << d.at(x).at(y);}cout << "\n";}cout << "---\n";
    if(answer == INF) cout << -1 << endl;
    else cout << (road - answer - 1) << endl;
    //cout << maze.at(gx).at(gy) << endl;
}


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

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

const int INF = 100000000;
const double PI=acos(-1);

ll dp[10010][2][110];

int main(){
    int K,T;
    cin >> K >> T;
    map<int,int> S;
    rep(i,T) {
        int tmp;
        cin >> tmp;
        S[i]=tmp;
    }
    vector<int> A(1,-1);

    rep(i,K) {
        int idx,idx_max;
        int num,num_max;
        idx = idx_max = -1;
        num = num_max = -1;

        rep(j,T) {
            if (S[j]>num && S[j]>0) {
                idx = j;
                num = S[j];
            }
            if (S[j]>num_max && S[j]>0 && A[i]!=j) {
                idx_max = j;
                num_max = S[j];
            }
        }
        if (idx_max!=-1) {
            A.push_back(idx_max);
            S[idx_max]--;
        }
        else {
            A.push_back(idx);
            S[idx]--;
        }
    }
    int ans = 0;
    rep(i,A.size()-1) {
        if (A[i]==A[i+1]) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int k,t;
  cin >> k >> t;
  vector<int>a(t);
  rep(i,0,t) cin >> a[i];
  sort(a.begin(),a.end());
  if(a[t-1] <= (k+1)/2){
    cout << 0 << endl;
    return 0;
  }
  cout << (a[t-1]-(k+1)/2)*2-1 << endl;
}


#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  int ans = 0;
  //string ans = "No";

  int n, y; cin >> n >> y;

  rep(i, n + 1){
    rep(j, n - i + 1){
      if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
        cout << i << " " << j << " " << (n - i - j) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;

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

// #define USE_CPP11
// #define USE_PRINTF

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

#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif

#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define SPACE " "

typedef long long ll;

const int INF = 1e9 + 10;

using namespace std;

namespace Scanner {
#ifdef USE_PRINTF
  int    nextInt()    { int    d; scanf("%d" , &d); return d; }
  float  nextFloat()  { float  f; scanf("%f" , &f); return f; }
  double nextDouble() { double f; scanf("%lf", &f); return f; }
  string nextString() { string s; scanf("%s" , &s); return s; }
  ll     nextll()     { ll     l; scanf("%ll", &l); return l; }
#else
  int    nextInt()    { int    d; cin >> d; return d; }
  float  nextFloat()  { float  f; cin >> f; return f; }
  double nextDouble() { double f; cin >> f; return f; }
  string nextString() { string s; cin >> s; return s; }
  ll     nextll()     { ll     l; cin >> l; return l; }
#endif

  string getLine() {
    string input;
    getline(cin, input);
    return input;
  }
};

namespace myLibrary {
  vector<string> split(const string& str, char delim) {
    vector<string> ret;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos) {
      ret.push_back(string(str, current, found - current));
      current = found + 1;
    }
    ret.push_back(string(str, current, str.size() - current));
    return ret;
  }

#ifdef USE_CPP11
  ///
  /// higher-order functional
  /// This is something like map in haskell, python, etc.
  /// Sample usage:
  ///   vector<int> a = {1, 2, 3, 4, 5};
  ///   vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
  ///     return n * n;
  ///   });
  /// Result:
  ///   b = 1, 4, 9, 16, 25
  ///
  template<typename T_IN, typename T_OUT, class Functor>
  vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
    vector<T_OUT> ret;
    for (int i = 0; i < src.size(); i++) {
      ret.push_back(func(src[i]));
    }
    return ret;
  }
#endif

};

struct Point {
public:
  int y, x;
  Point(int y, int x): y(y), x(x) { }
  Point() { }
};

/// BEGIN //////////////////////////////////////////////////////////

struct Rect {
public:
  int h, w;
  Rect() { }
  Rect(int h, int w):h(h), w(w) { }
  bool operator==(Rect r) {
    return (this->h == r.h && this->w == r.w);
  }
};

int main() {
  vector<Rect> rect;
  for (int i = 1; i <= 151; i++) {
    for (int j = i + 1; j <= 151; j++) {
      rect.push_back(Rect(i, j));
    }
  }

  sort(rect.begin(), rect.end(), [](Rect a, Rect b) {
    int sq1 = a.h * a.h + a.w * a.w;
    int sq2 = b.h * b.h + b.w * b.w;
    if (sq1 == sq2) {
      return a.h < b.h;
    } else {
      return sq1 < sq2;
    }
  });

  while (true) {
    int h = Scanner::nextInt();
    int w = Scanner::nextInt();
    if (h + w == 0) {
      break;
    }

    vector<Rect>::iterator it = find(rect.begin(), rect.end(), Rect(h, w));

    cout << (it + 1)->h << SPACE << (it + 1)->w << endl;
  }
  return 0;
}

/// END   //////////////////////////////////////////////////////////


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

vector<long long> kosu(1001);

void divisor(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    while(n % i == 0){
      kosu[i]++;
      n /= i;
    }
  }
  if(n != 1){
    kosu[n]++;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N;
  cin >> N;
  for(int i = 1; i <= N; i++){
    divisor(i);
  }
  long long ans = 1;
  for(int i = 0; i < 1001; i++){
    ans *= kosu[i] + 1;
    ans %= 1000000007;
    }
    cout << ans <<endl;
}

#include<iostream>
using namespace std;

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

  int a,b,c;
  a=N/100, b=(N/10)%10, c=N%10;

  if (a == 7 || b == 7 || c == 7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define lld long long int
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
string s;
cin>>s;
int max=0;
if(s[0]=='R')
{
    max++;
}
if(s[1]=='R')
max++;
if(s[2]=='R')
max++;
if(max==2)
{
    if(s[1]!='R')
    cout<<1<<"\n";
    else
    cout<<max<<"\n";
}
else
cout<<max<<"\n";
	return 0;
}

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"

#define fastio      ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
#define TC          int t; cin >> t; for(int tc = 1; tc <= t; tc++)
#define read        freopen("input.txt", "r", stdin);
#define write       freopen("output.txt", "w", stdout);
#define nl          '\n'
#define pii		    pair<int, int>
#define ll 		    long long
#define pb		    push_back
#define eb		    emplace_back
#define all(v)	    v.begin(), v.end()
#define rall(v)	    v.rbegin(), v.rend()
#define d(x)	    cerr << #x << " = " << x << nl

using namespace std;

int main() {
    int ans = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'R') {
            int count = 0;
            while(s[i] == 'R') count++, i++;
            ans = max(ans, count);
        }
    }
    cout << ans << nl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

void solve(int n,int m){
  int a,b;
  bool p[n+5][n+5],ans[n+5];
  rep(i,n+5)rep(j,n+5){p[i][j]=ans[j]=false;}
  rep(i,m){
    cin>>a>>b;
    p[a][b]=p[b][a]=true;
  }
  REP(i,1,n+1){
    REP(j,1,n+1){
      ans[i]+=p[1][i];
      if(p[1][i]==true&&p[i][j]==true)ans[j]=true;
    }
  }
  int cnt=0;
  REP(i,2,n+1)cnt+=ans[i];
  cout<<cnt<<endl;
}

int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    solve(n,m);
  }

  return 0;
}


#include <stdio.h>

int main()
{
  char S[105];
  char T[105];
  scanf("%s", S);
  scanf("%s", T);
  printf("%s%s\n", T, S);
  return 0;
}

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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--)
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  vector<vector<int>> dp(m+1, vector<int>(n+1, -1));
  sort(a.begin(), a.end());
  vector<int> b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  dp[0][0] = 0;
  rep1(i,m) {
    rep(j,n+1) {
      if(j - b[a[i-1]] >= 0) {
	if(dp[i][j - b[a[i-1]]] != -1) {
	  dp[i][j] = max(dp[i][j - b[a[i-1]]] + 1, dp[i-1][j]);
	}
	else dp[i][j] = dp[i-1][j];
      }
      else dp[i][j] = dp[i-1][j];
    }
  }

  // rep(i,m+1) {
  //   rep(j,n+1) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << "\n";
  // }

  int x = m, y = n;
  while(y > 0 ) {
    if(y - b[a[x-1]] >= 0) {
      if( dp[x][y] - 1 == dp[x][y - b[a[x-1]]] ) {
	cout << a[x-1];
	y -= b[a[x-1]];
      }
      else x--;
    }
    else x--;
  }
  cout << "\n";
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e3+7;
ll dp[maxn][maxn];
ll C[maxn][maxn];
ll fac[maxn];
ll inv[maxn][maxn];
ll ivv[maxn];
int n,a,b,c,d;
ll dfs(int cnt,int k)
{
	if(cnt==n) return 1;
	if(k>b) return cnt==n;
	ll &ret=dp[cnt][k];
	if(ret!=-1) return ret;
	ret=0;
	ret=dfs(cnt,k+1);
	for(int i=c;i*k+cnt<=n&&i<=d;i++)
	{
		ret=(ret+dfs(cnt+i*k,k+1)*C[n-cnt][i*k]%mod*fac[i*k]%mod*inv[k][i]%mod*ivv[i]%mod)%mod;
	}
	//dbg(cnt,k,ret);
	return ret;
}
ll invv(ll a,ll b=mod-2)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
int main()
{
	fac[0]=1;
	for(int i=0;i<maxn;i++)
	{
		if(i) fac[i]=fac[i-1]*i%mod;
		C[i][i]=C[i][0]=1;
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	for(int i=1;i<maxn;i++)
	{
		inv[i][0]=1;
		ll tmp=invv(fac[i]);
		ivv[i]=tmp;
		for(int j=1;j<maxn;j++)
			inv[i][j]=inv[i][j-1]*tmp%mod;
	}
	memset(dp,-1,sizeof(dp));
	cin>>n>>a>>b>>c>>d;
	cout<<dfs(0,a)<<endl;
}


#include<bits/stdc++.h>
#define ls (rt<<1)
#define rs ((rt<<1)|1)
#define cmin(a,b) a=min(a,b)
using namespace std;
typedef long long ll;
ll n,Q,A,B;
ll rd()
{
	ll rx=0,fx=1;char c=getchar();
	while(c<48||c>57)
	{
		if(c=='-') fx=-1;
		c=getchar();
	}
	while(c>=48&&c<=57)
	{
		rx=rx*10+c-48;
		c=getchar();
	}
	return rx*fx;
}
const ll N=2e5+50,V=N<<2,inf=1e15;
ll X[N];
struct Segment_tree
{
	ll vmi[V],ami[V],bmi[V],tag[V];
	void cover(ll rt,ll w)
	{
		vmi[rt]+=w;ami[rt]+=w;bmi[rt]+=w;tag[rt]+=w;
	}
	void mdown(ll rt)
	{
		if(tag[rt])
		{
			cover(ls,tag[rt]);cover(rs,tag[rt]);
			tag[rt]=0;
		}
	}
	void mup(ll rt)
	{
		vmi[rt]=min(vmi[ls],vmi[rs]);
		ami[rt]=min(ami[ls],ami[rs]);
		bmi[rt]=min(bmi[ls],bmi[rs]);
	}
	void build(ll rt,ll l,ll r)
	{
		if(l==r)
		{
			vmi[rt]=ami[rt]=bmi[rt]=inf;return ;
		}
		ll mid=(l+r)>>1;
		build(ls,l,mid);build(rs,mid+1,r);
		mup(rt);
	}
	void chg(ll rt,ll l,ll r,ll x,ll w)
	{
		if(l==r)
		{
			vmi[rt]=w;ami[rt]=w-l;bmi[rt]=w+l;
			//printf("U%lld %lld\n",x,w);
			return ;
		}
		ll mid=(l+r)>>1;
		mdown(rt);
		if(mid>=x) chg(ls,l,mid,x,w);
		else chg(rs,mid+1,r,x,w);
		mup(rt);
	}
	ll qry(ll rt,ll l,ll r,ll x,ll y,ll typ)
	{
		if(l>=x&&r<=y)
		{
			if(typ==0) return ami[rt];
			else return bmi[rt];
		}
		ll mid=(l+r)>>1,ras=inf;
		mdown(rt);
		if(mid>=x) cmin(ras,qry(ls,l,mid,x,y,typ));
		if(mid<y) cmin(ras,qry(rs,mid+1,r,x,y,typ));
		return ras;
	}
}sgt;
int main()
{
	ll i,val;
	n=rd();Q=rd();A=rd();B=rd();
	sgt.build(1,1,n);
	sgt.chg(1,1,n,B,0);
	X[0]=A;
	for(i=1;i<=Q;i++) X[i]=rd();
	for(i=1;i<=Q;i++)
	{
		val=min(sgt.qry(1,1,n,1,X[i],0)+X[i],sgt.qry(1,1,n,X[i],n,1)-X[i]);
		//printf("P%lld %lld %lld %lld\n",i,val,sgt.qry(1,1,n,1,X[i],0),sgt.qry(1,1,n,X[i],n,1));
		sgt.cover(1,abs(X[i]-X[i-1]));
		sgt.chg(1,1,n,X[i-1],val);
	}
	printf("%lld",sgt.vmi[1]);
	return 0;
}

#include <iostream>

using namespace std;

const int MAX = 10e5;

int main() {
  int N; cin >> N;
  int dp[MAX];
  for (int i = 0; i < MAX; i++) {
    dp[i] = -1;
  }
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    auto it = lower_bound(dp + MAX - N, dp + MAX, A);
    *--it = A;
  }

  int ans = 0;
  for (int i = 1; i <= MAX; i++) {
    if (dp[MAX - i] == -1) {
      ans = i - 1;
      break;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
vector<long long> divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;

    /*long long N;
    cin >> N;
    vector<long long> res = divisors(N);
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  string s;
  cin >> s;
  if(s.size()==2){
    cout << s << endl;
  }else{
    rep(i,3){
      cout << s[2-i];
    }
    cout << endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int size = s.size();
  if(size==2){
    cout << s << endl;
  }else{
    cout << s.at(2) << s.at(1) <<s.at(0) << endl;
  }
}