#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 110;

int a[MAXN];
int js[MAXN];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int cnt = 0;
	int n = ri;
	int m = ri;
	if(m == 1) {
		if(n == 1) {
			cout << 1 << endl;
			cout << 1 << endl;
			cout << 1 << endl;
		} else {
			cout << n << endl;
			cout << 2 << endl;
			cout << 1 << ' ' << n - 1 << endl;
		}
	}
	else {
		for(int i = 1; i <= m; i++) {
			a[i] = ri;
			if(a[i] & 1)
				js[cnt++] = i;
		}
		if(cnt > 2) puts("Impossible");
		else {
			if(js[0] && js[0] != 1) swap(a[1], a[js[0]]);
			if(js[1] && js[1] != m) swap(a[m], a[js[1]]);
			for(int i = 1; i <= m; i++) printf("%d ", a[i]); puts("");
			a[1]++, a[m]--;
			if(!a[m]) --m;
			printf("%d\n", m);
			for(int i = 1; i <= m; i++) printf("%d ", a[i]); puts("");
		}
	}
	return 0;
}

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

using namespace std;

typedef long long llint;
typedef pair < int, int> pii;
typedef pair < llint, llint> pll;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int n,a[N],nep,ind;
llint sum = 0;

int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%d",a+i);
        if(a[i]&1) {nep++;ind=i;}
        sum += (llint)a[i];
    }
    for(int koji = 1;;koji = !koji){
        int allgcd = a[0];
        for(int i = 1;i<n;i++)
            allgcd = __gcd(a[i], allgcd);
        int nw = 0,ind = 0, jed = 0;
        llint nsum = -n;
        for(int i = 0;i<n;i++){
            a[i] /= allgcd;
            nsum += a[i];
            if(a[i] == 1) jed++;
            if(a[i]&1) {nw++;ind = i;}
        }
        if(nsum%2 == 1){
            if(koji) printf("First\n");
            else printf("Second");
            break;
        }
        else if(nw == 1 && !jed){
            a[ind]--;
            continue;
        }
        else{
            if(!koji) printf("First\n");
            else printf("Second");
            break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e6+5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<vector<ll>> cnt(64, vector<ll>(30));
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		ll temp = 0;
		int len = s.size(), tens = 0;
		bool flag = false;
		for (int j = 0; j < len; j++) {
			if (s[j] != '.') {
				temp *= 10;
				temp += s[j] - '0';
				if (flag) tens++;
			}
			else flag = true;

		}

		for (int i = 0; i < 9 - tens; i++)temp *= 10;
		//cout << "temp=" << temp << endl;
		int two = 0, five = 0;
		while (temp % 2 == 0) {
			two++, temp /= 2;
		}
		while (temp % 5 == 0) {
			five++, temp /= 5;
		}
		cnt[two][five]++;
		//cout << "two=" << two << " five=" << five << endl;
	}

	ll ans = 0;
	for (int i = 0; i < 64; i++) {
		for (int j = 0; j < 30; j++) {
			for (int a = max(0,18 - i); a < 64; a++) {
				for (int b = max(0,18 - j); b < 30; b++) {
					ans += cnt[i][j] * (cnt[a][b] + (i == a && j == b ? -1 : 0));
					//if (cnt[i][j] > 0 && cnt[a][b])
						//cout << "i=" << i << " j=" << j << " a=" << a << " b=" << b << " ans=" << ans << endl;
				}
			}

		}
	}
	cout << ans / 2 << endl;

}

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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<string> isu(N);

	ll L = 0;
	ll R = N;
	std::cout << L << std::endl;
	cin >> isu[L];
	if (isu[L] == "Vacant") return 0;

	while (abs(R-L) > -1)
	{
		ll mid = (R+L)/2;
		std::cout << mid << std::endl;
		cin >> isu[mid];
		if (isu[mid] == "Vacant") return 0;

		if ((mid - L) & 1)
		{
			if (isu[mid] == isu[L])
			{
				R = mid;
			}
			else
			{
				L = mid;
			}
		}
		else
		{
			if (isu[mid] == isu[L])
			{
				L = mid;
			}
			else
			{
				R = mid;
			}
		}

	}
	std::cout << L << std::endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;
const int N = 2e5+5;

vector<ll>ans,veca,vecb;
vector<int>adj[N];
vector<double>aka;
vector<pair<int,double>>dp[N];
vector<bool>vis;

void init(int n){
    ans.clear();veca.clear();aka.clear();vis.clear();ans.resize(n);
    vecb.clear(),vecb.resize(n);veca.resize(n);vis.resize(n);
    for (int i = 0; i <n; i++) {
        vis[i]=0;
    }
    for (int i = 0; i<=n; i++) {
        adj[i].clear();
    }
    for (int i = 0; i <=n; i++) {
        dp[i].clear();
    }
    for (int i = 0; i < n; i++) {
        ans[i]=0;
    }
}

int check(int a,int b,int c){
    int res=0;
    if(a+b>c) res=1;
    return res;

}
bool valid(int a,int b,int c){
    if((a<b)&&(b<c)) return 0;
    return 1;
}
void solve(){
    int n,flag=0;
    cin>>n;
    init(n);
    for (int i = 0; i <n; i++) {
        cin>>veca[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if(!valid(i,j,k)){
                    set<int>st;vector<int>vec;
                    st.insert(veca[i]);st.insert(veca[j]);st.insert(veca[k]);
                    vec.push_back(veca[i]);vec.push_back(veca[j]);vec.push_back(veca[k]);
                    if(st.size()==3){
                        sort(vec.begin(),vec.end());
                        flag+=check(vec[0],vec[1],vec[2]);
                    }
                }
            }
        }
    }
    cout<<flag<<"\n";

}

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }

    return 0;
}

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

int main(){
    int N, count;
    cin >> N;
    count = 0;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                if((abs(vec.at(i) - vec.at(j)) < vec.at(k) && vec.at(k) < vec.at(i) + vec.at(j)) && vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k)&& vec.at(k) != vec.at(i))
                count++;
        }

     }

	}
  cout << count << endl;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ;
  cin >> n ;
  string s , t  ;
  cin >> s >> t ;
  deque<char> S , T ;
  rep(i,n){
    S.push_back(s.at(i)) ;
    T.push_back(t.at(i));
  }
  if(s == t ) {
    cout << s.size() <<endl ;
    return 0 ;
  }

  int ans = 2 * n ;

  rep(i,n){
    S.pop_front();
    T.pop_back();

    if( S == T){
      ans = S.size() + 2*(i+1) ;
      cout <<  ans <<endl ;
      return 0 ;
    }
  }

}

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

	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		string subs = s.substr(i, n - i); //後半を抽出
		string subt = t.substr(0, n - i); //前半を抽出
		if (subs == subt) //抽出した部分がもし重複したら
			cnt = max(cnt, n - i); //重複部分がながければ長いほど最小になるので、長いものをキープ
	}
	cout << 2 * n - cnt << endl; //最大のときは2n。2nから一番長い重複を引く
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 200000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int cost[101][101];
bool used[101];
int d[101];
int n,k;
void dijkstra(int s)
{
	fill(d,d+101,INF);
	fill(used,used+101,false);
	d[s]=0;
	for(;;)
	{
		int v=-1;
		for(int u=1;u<=n;u++)
		{
			if(!(used[u])&&(v==-1||d[u]<d[v]))
			{
				v=u;
			}
		}
		if(v==-1)break;
		used[v]=true;
		for(int u=1;u<=n;u++)
		{
			d[u]=min(d[u],d[v]+cost[v][u]);
		}
	}
	return ;
}
int main()
{
	while(1)
	{
		for(int i=0;i<101;i++)
		{
			for(int j=0;j<101;j++)
			{
				cost[i][j]=INF;
			}
		}
		cin >> n >> k;
		if(n==0&&k==0)break;
		for(int i=0;i<k;i++)
		{
			int type;
			cin >> type;
			if(type)
			{
				int a,b,co;
				cin >> a >> b >> co;
				cost[a][b]=min(cost[a][b],co);
				cost[b][a]=min(cost[b][a],co);
			}
			else
			{
				int a,b;
				cin >> a >> b;
				dijkstra(a);
				if(d[b]==INF)
				{
					cout << -1 << endl;
				}
				else
				{
					cout << d[b] << endl;
				}
			}
		}
	}
	return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
#define bit(n, k) ((n) >> (k) & 1)
const int MOD = (int)1e9 + 7;
template<class T> void add(T &a, T b) { (a += (b % MOD + MOD) % MOD) %= MOD; }

int main() {
    int h, w; cin >> h >> w;
    int K; cin >> K; K--;
    vector<vector<int>> num(w, vector<int>(w));
    for (int mask = 0; mask < 1 << (w - 1); mask++) {
        bool ok = true;
        for (int i = 0; i + 1 < w - 1; i++) {
            if (bit(mask, i) && bit(mask, i + 1)) ok = false;
        }
        if (!ok) continue;
        vector<int> p(w);
        iota(p.begin(), p.end(), 0);
        for (int i = 0; i < w - 1; i++) if (bit(mask, i)) swap(p[i], p[i + 1]);
        for (int i = 0; i < w; i++) num[i][p[i]]++;
    }
    vector<vector<long long>> dp(h + 1, vector<long long>(w));
    dp[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) for (int k = 0; k < w; k++) {
            add(dp[i + 1][k], dp[i][j] * num[j][k]);
        }
    }
    cout << dp[h][K] << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (long) 1e9 + 7;

int main(){

    int n;
    long cnt = 0, r = 0, g = 0, b = 0;
    cin >> n;

    string s;
    cin >> s;

    vector<int> v(n,0);
    rep(i,n){
        if(s[i] == 'R'){
            v[i] = 0;
            r++;
        } else if(s[i] == 'G'){
            v[i] = 1;
            g++;
        } else if(s[i] == 'B'){
            v[i] = 2;
            b++;
        }
    }

    for(int i = 1; i < n - 1; i++){
        int a = min(i, n - 1 - i);

        for(int j = 1; j <= a; j++){
            if(v[i] != v[i-j] && v[i] != v[i+j] && v[i-j] != v[i+j]) cnt++;
        }
    }

    long ans = r * g * b - cnt;

    cout << ans << "\n";

    return 0;
}


#include<stdio.h>
#include<stdio.h>
#include<bits/stdc++.h>
#include<vector>
#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
using namespace std;
void a1(){
    int i, len = 3;
    char str[] = "abc";
    for(i=0;i<len;i++){
        printf("%c\n",str[2-i]);
    }
    return;
}

int length(char str[5]){
    int cut=0;
    while(*(str+cut)!='\0'){
        cut++;
    }
    return cut;
}

void a2(){
    char a[4][5]={"ab","cdef","g","hij"};
    int i;
    for(i=0; i<4; i++){
        printf("%d\n",length(a[i]));
    }
    return;
}

void a3(){
    char str[4];
    strcpy(str,"abc");
    printf("%s\n",str);
    return;
}

void a4(){
    char a[7]="saitou",b[7] = "suzuki";
    int i;

    for(i=0;i<7;i++){
        int k = a[i]-b[i];
        if(k > 0){
            printf("%c",a[i]);
        }else if(k < 0){
            printf("%c",b[i]);
        }else{
            printf("0");
        }
    }
    printf("\n");
    return;
}

void a5(){
    char *a[3];
    int n,i,j,cut = 0;
    for(i=0;i<3;i++){
        scanf("%d",&n);
        a[i]=(char *)malloc((n+1)*sizeof(char));
        scanf("%s",a[i]);
    }
    for(i=0;i<3;i++){
        for(j=0;j<strlen(a[i]);j++){
            if(a[i][j]=='P'||a[i][j]=='p'){
                cut++;
            }
        }
    }
    printf(">> %d\n",cut);
    for(i=0;i<3;i++){
        free(a[i]);
    }
}

void y(){
    int n,m;
    vector<int> v,v2;
    while(1){
    cin >> n >> m;
    v.clear();v2.clear();
    if(n==0&&m==0)break;
    v.push_back(0);
    rep(i,0,n){
        int x;cin >> x;
        v.push_back(x);
    }
    rep(i,0,v.size()){
        rep(j,0,v.size()){
            v2.push_back(v[i]+v[j]);
        }
    }
    v2.erase(unique(v2.begin(),v2.end()),v2.end());
    sort(v2.begin(),v2.end());
    int ans=0,k=0;
    //cout << v2.size() << " a " <<  endl;
    bool a=false;
    for(int j=v2.size()-1;j>=0;j--){
        rep(i,k,v2.size()){
            k=i;
            if(v2[i]+v2[j]>m){
                //if(i==(j-1))a=true;
                break;
            }
        ans=max(ans,v2[i]+v2[j]);
        //    cout << an << " a " << endl;
        }
        if(k>j)break;
    }
    cout << ans << endl;
    }
    return;
}

signed main(){
    y();
    return 0;
}

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

int m, n, p[1001], pp[1001*1001];

int main(){
    while( true ){
        cin >> n >> m;
        if( m == 0 && n == 0 ) break;
        for(int i = 0; i < n; i++){
            cin >> p[i];
        }
        p[n] = 0;
        n++;
        for(int i = 0; i < n*n; i++){
            pp[i] = p[i/n] + p[i%n];
        }
        sort(pp, pp + n*n);
        int cand = 0;
        int j = n*n-1;
        for(int i = 0; i <= j; i++){
            while( j >= 0 && pp[i] + pp[j] > m ) j--;
            if(j >= 0){
                cand = max(cand, pp[i] + pp[j]);
            }
        }
        cout << cand << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 40;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN], a[MAXN], b[MAXN];
int n, dp[MAXN][MAXN]; ll ans;
void work(int pos, int la, int lb) {
	if (pos == n) {
		memset(dp, 0, sizeof(dp)), dp[n][la] = 1;
		for (int i = n; i >= 1; i--)
		for (int j = max(0, i - lb), k = i - j; j <= la && j <= i; j++, k--) {
			if (s[i] == a[j]) dp[i - 1][j - 1] += dp[i][j];
			if (s[i] == b[k]) dp[i - 1][j] += dp[i][j];
		}
		ans += dp[0][0];
		return;
	}
	a[la + 1] = s[pos];
	work(pos - 1, la + 1, lb);
	b[lb + 1] = s[pos];
	work(pos - 1, la, lb + 1);
}
int main() {
	read(n), scanf("%s", s + 1);
	work(n * 2, 0, 0);
	writeln(ans);
	return 0;
}

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    string s; cin>>s;
    string head = s.substr(0, n);
    string tail = s.substr(n, n);
    reverse(tail.begin(), tail.end());

    map<pair<string, string>, ll> head_paint, tail_paint;
    for(int bit=0; bit<(1<<n); bit++){
        string ha, hb, ta, tb;
        for(int i=0; i<n; i++){
            if(bit & (1 << i)){
                ha += head[i];
                ta += tail[i];
            }
            else{
                hb += head[i];
                tb += tail[i];
            }
        }

        reverse(hb.begin(), hb.end());
        reverse(tb.begin(), tb.end());

        head_paint[make_pair(ha, hb)]++;
        tail_paint[make_pair(ta, tb)]++;
    }

    ll ans = 0;
    for(auto i : head_paint){
        ans += i.second * tail_paint[make_pair(i.first.first, i.first.second)];
    }

    cout << ans << endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 123;

int a[N];

void solve() {
  int k, t; scanf("%d%d", &k, &t);
  for (int i = 0; i < t; ++i) scanf("%d", a+i);
  if (t == 1) {
    printf("%d", a[0]-1);
    return;
  }
  sort(a, a+t);
  int spare = 1;
  int prev = 0;
  for (int i = 0; i < t-1; ++i) {
    if (i && a[i] == a[i-1]) continue;
    spare += (a[i]-prev)*(t-i-2);
    a[t-1] -= (a[i]-prev);
    prev = a[i];
  }
  printf("%d", max(a[t-1]-spare, 0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

  rep(i, n) {
    auto itr = lower_bound(d.rbegin(), d.rend(), a[i]);
    if (itr == d.rbegin())
      d.push_back(a[i]);
    else
      *--itr = a[i];
  }
  cout << d.size() << endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    if(n < 3 || n > 10000) return -1;
    for(int i = 1 ;i <= n ; i ++){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i ;
            continue;
        }else if(x % 10 == 3){
            cout << " " << i ;
            continue;
        }else{
            while(x > 0){
                x = round(x/10);
                if(x % 10 == 3){
                    cout << " " << i ;
                    break;
                }
            }
            continue;
        }
    }
    cout << endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    s = s.substr(0, s.size()-8);

    cout << s << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

#define MAX_N 200001

long long par2[MAX_N]; // 親
long long rankuf2[MAX_N]; // 木の深さ
// n要素で初期化
void init2(long long n) {
	for (long long i = 0; i < n; i++) {
		par2[i] = i;
    rankuf2[i] = 0;
	}
}
// 木の根を求める
long long find2(long long x) {
	if (par2[x] == x) {
		return x;
	} else {
		return par2[x] = find2(par2[x]);
	}
}
// xとyの属する集合を併合
void unite2(long long x, long long y) {
	x = find2(x);
	y = find2(y);
	if (x == y) return;
	if (rankuf2[x] < rankuf2[y]) {
		par2[x] = y;
	} else {
		par2[y] = x;
		if (rankuf2[x] == rankuf2[y]) rankuf2[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same2(long long x, long long y) {
	return find2(x) == find2(y);
}

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}
// xとyの属する集合を併合
void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){
	long long K;
	long long N;
	long long L;
	scanf("%lld",&N);
	scanf("%lld",&K);
	init(N+1);
	init2(N+1);
	vector<long long> q(K-1+1);
	vector<long long> p(K-1+1);
	scanf("%lld",&L);
	vector<long long> r(L-1+1);
	vector<long long> s(L-1+1);
	for(int i = 0 ; i <= K-1 ; i++){
		scanf("%lld",&p[i]);
		scanf("%lld",&q[i]);
		unite(p[i]-1, q[i]-1);
	}
	for(int i = 0 ; i <= L-1 ; i++){
		scanf("%lld",&r[i]);
		scanf("%lld",&s[i]);
		unite2(r[i]-1, s[i]-1);
	}
	map<P, ll> m;
	rep(i, N) {
		m[P(find(i), find2(i))]++;
	}
	ll cnt = 0;
	rep(i, N-1) {
		cout << m[P(find(i), find2(i))] << " ";
	}
	cout << m[P(find(N-1), find2(N-1))] << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

#include <vector>
using namespace std;

/* Union-Find-Tree */
/* 必ず要素数をコンストラクタに入れること */
template <class T = long long>
class Union_Find {
  using size_type = std::size_t;
  using _Tp = T;
public:

  vector<_Tp> par;
  vector<_Tp> rnk;

  // 親の根を返す。値の変更は認めない。
  const _Tp & operator[] (size_type child) {
    find(child);
    return par[child];
  }

  Union_Find (_Tp n) {
    par.resize(n), rnk.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
    }
  }

  // 木の根を求める
  _Tp find(_Tp x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  // xとyの属する集合を併合
  void merge(_Tp x, _Tp y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(_Tp x, _Tp y) {
    return find(x) == find(y);
  }
};

int main() {
  int n,k,l;
  cin >> n >> k >> l;
  Union_Find<long long> uf_road(n+1), uf_train(n+1);

  int r,s;
  rep(i,k) {
    cin >> r >> s;
    uf_road.merge(r, s);
  }

  rep(i,l) {
    cin >> r >> s;
    uf_train.merge(r, s);
  }

  vector<pair<int,int> > com;
  map<pair<int,int>, int> mp;

  for (int i = 1; i <= n; ++i) {
    int a, b;
    a = uf_road[i];
    b = uf_train[i];
    com.push_back(make_pair(a,b));
    mp[make_pair(a,b)] += 1;
  }

  for (int i = 0; i < n; ++i) {
    cout << mp[com[i]] << " ";
  }

  END;
}


#include<bits/stdc++.h>
using namespace std;
static const int64_t INF=100000000000000;
int main(){
  int N;cin>>N;
  vector<tuple<int64_t,int64_t,int64_t>>A(N);
  for(int i=0;i<N;i++){
  int64_t h,p;cin>>h>>p;
    tuple<int64_t,int64_t,int64_t>q(h+p,h,p);
    A.at(i)=q;
  }sort(A.begin(),A.end());
  vector<pair<int64_t,int64_t>>B(N);
  for(int i=0;i<N;i++){
  int64_t h=get<1>(A.at(i));
    int64_t p=get<2>(A.at(i));
    pair<int64_t,int64_t>q(h,p);
    B.at(i)=q;
  }vector<vector<int64_t>>dp(1+N,vector<int64_t>(1+N,INF));
  for(int i=0;i<=N;i++)dp[i][0]=0;
  for(int i=1;i<=N;i++)
    for(int j=1;j<=N;j++){
      int64_t h=B[i-1].first;
      int64_t p=B[i-1].second;
    if(dp[i][j-1]!=INF){
    if(dp[i-1][j-1]<=h)
      dp[i][j]=min(dp[i-1][j-1]+p,dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];

    }
    }int64_t ans=0;
  for(int j=N;0<=j;j--)
    if(dp[N][j]!=INF){ans=j;break;}
  cout<<ans<<endl;
  return 0;
}

#include<algorithm>
#include<iostream>
#include<cstdio>
typedef long long ll;
using namespace std;
struct Node{
	int h,p;
}a[5005];
int n;
ll f[5005][5005];
bool cmp(Node a,Node b){
	return a.h+a.p<b.h+b.p;
}
int main(){
	ios::sync_with_stdio(false);
	int i,j;
	cin>>n;
	fill(f[0],f[0]+n+1,2e9+1);
	for(i=1;i<=n;i++)
		cin>>a[i].h>>a[i].p;
	sort(a+1,a+n+1,cmp);
	f[0][0]=0;
	for(i=1;i<=n;i++)
		for(j=0;j<=n;j++){
			f[i][j]=f[i-1][j];
			if(j&&f[i-1][j-1]<=a[i].h)
				f[i][j]=min(f[i][j],f[i-1][j-1]+a[i].p);
		}
	for(i=n;i>=0;i--)
		if(f[n][i]<=2e9)
			break;
	cout<<i;
	return 0;
}


#include <iostream>

using namespace std;

void solve()
{
	int x;
	cin >> x;
	cout << x * x * x << endl;
}

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

#include <stdio.h>
long long n, a, b;
int main() {
	scanf("%lld", &n);
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			a = i;
			b = n / i;
		}
	}
	a = 0;
	while (b) {
		b /= 10;
		a++;
	}
	printf("%lld\n", a);
}


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

int main() {
  string s;
  cin >> s;
  int i, j;
  for (i = 0; i < (1 << 3); i++) {
    bitset<3> a(i);
    int sum = s.at(0) - '0';
    for (j = 0; j < 3; j++) {
      if (a.test(j) == 1) { sum += s.at(j + 1) - '0'; }
      else { sum -= s.at(j + 1) - '0'; }
    }
    if (sum == 7) { break; }
  }
  bitset<3> a(i);
  cout << s.at(0);
  for (j = 0; j < 3; j++) {
    if (a.test(j) == 1) { cout << "+"; }
    else { cout << "-"; }
    cout << s.at(j + 1);
  }
  cout << "=7" << endl;
}


#include <iostream>
#include <algorithm>
#include <cstring>

#define rep(X, Y) for( int X = 0; X < Y; ++X )

int n, m;
int N[1001], M[1001];
int cnt[1001];

int main(){
	memset( cnt, 0, sizeof(cnt) );

	std::cin >> n >> m;

	rep( i, n ) std::cin >> N[i];

	rep( i, m ) std::cin >> M[i];

	rep( i, m ) rep( l, n ) if( N[l] <= M[i] ){
		cnt[l]++;
		break;
	}

	std::cout << std::max_element( cnt, cnt + n ) - cnt + 1 << std::endl;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100];
int main()
{
    ll n;
    cin>>n;
    memset(a,0,sizeof(a));
    for(ll i=1;i<=50;i++)
    {
        a[i]=(49+n/50);
    }
    ll m=n%50;
    for(ll i=1;i<=50;i++)
    {
        a[i]=a[i]-m;
    }
    for(ll i=1;i<=m;i++)
    {
        a[i]+=50;
    }
    cout<<50<<endl;
    for(ll i=1;i<=49;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<a[50]<<endl;
}

#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 50;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll k;
    cin >> k;
    cout << N << endl;
    for(int i = 0; i < N; i++) {
        if(i < N - 1 - (k - 1) % N) {
            cout << (k - 1) / N + i << " ";
        } else if(i == N - 1) {
            cout << (k - 1) / N + N << " ";
        } else {
            cout << (k - 1) / N + N - 1 << " ";
        }
    }
    cout << endl;
    return 0;
}


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

template <typename _Tp> inline _Tp read(_Tp&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();return x;
}

int n,m,tot,a[105];

int main(){
	read(n),read(m);
	for(rg int i=1;i<=m;i++)read(a[i]),tot+=(a[i]&1);
	if(tot>2){puts("Impossible");return 0;}
	if(tot){
		bool flag=0;
		for(rg int i=1;i<m;i++)
			if(a[i]&1)
				if(flag)swap(a[i],a[m]);
				else flag=1,swap(a[i],a[1]);
	}
	if(m==1){
		if(a[1]==1){puts("1\n1\n1");return 0;}
		printf("%d\n",a[1]);puts("2");
		printf("1 %d\n",a[1]-1);
		return 0;
	}
	for(rg int i=1;i<=m;i++)printf("%d ",a[i]);
	if(a[m]==1){
		printf("\n%d\n",m-1);
		printf("%d\n",a[1]+1);
		for(rg int i=2;i<m;i++)printf("%d ",a[i]);
	}
	else {
		printf("\n%d\n",m);
		printf("%d\n",a[1]+1);
		for(rg int i=2;i<m;i++)printf("%d ",a[i]);
		printf("%d\n",a[m]-1);
	}return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
// const ll N = ;

ll a, b, temp;

ll factorize(ll x) {
    ll ret = 1;
    for(ll i = 2; i * i <= x; i++) {
        if(x % i == 0) {
            ret++;
            while(x % i == 0) x /= i;
        }
    }
    if(x > 1) ret++;
    return ret;
}

void solve() {
    cin >> a >> b;
    temp = __gcd(a, b);
    cout << factorize(temp) << "\n";
}

int main() {

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

    solve();

}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;

    cin >> n;

    switch (n)
    {
    case 1:
        cout << "Hello World" << endl;
        break;

    default:
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
        break;
    }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

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

    string ans="";

    ll n,m;
    cin >> n;
    m = n;

    while(m>0){
        m--;
        char s = 'a'+ m%26;
        ans.push_back(s);
        m /= 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;

    return 0;
}


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

int f(int x)
{
	return x * x;
}

int main(void)
{
	int n;

	while(cin >> n){
		int s = 0;

		for(int i = 1; i * n < 600; i++)
			s += f(i * n) * n;

		cout << s << endl;
	}

	return 0;
}

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

int main(){
    stack<char> str;
    char c;
    while(1){
        scanf("%c",&c);
        if(c=='\n'||c==EOF) break;
        str.push(c);
    }
    while(!str.empty()){
        printf("%c",str.top());
        str.pop();
    }
    printf("\n");
    return 0;
}


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<int>v(n + 1, 0), Q; rep(i, 1, n + 1)cin >> v[i];
		rep(i, 0, n + 1) {
			rep(j, i, n + 1) {

				if (v[i] + v[j] <= m)Q.push_back(v[i] + v[j]);
			}
		}
		sort(all(Q));
		dumpc(Q);
		int ans(0);
		rep(i, 0, Q.size()) {
			int l = 0, r = Q.size();
			while (r - l > 1) {
				int mid = (l + r) / 2;
				if (Q[mid] > m - Q[i])r = mid;
				else l = mid;
			}
			if (Q[i] + Q[l] <= m)ans = max(ans, Q[i] + Q[l]);
			dump(ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int n, m;
  while(1){
    scanf("%d%d", &n, &m);
    if(n == 0 && m == 0)return 0;
    int res = 0, tmp;
    vector<int> points, points2;
    for(int i = 0;i < n;i++){
      scanf("%d", &tmp);
      points.push_back(tmp);
    }
    vector<int>::iterator it1,it2;
    for(it1 = points.begin();it1 != points.end();it1++){
      points2.push_back(*it1);
      for(it2 = points.begin();it2 != points.end();it2++){
	if(*it1 + *it2 <= m)points2.push_back(*it1 + *it2);
      }
    }
    sort(points2.begin(),points2.end());
    for(it1 = points2.begin();it1 != points2.end();it1++){
      it2 = upper_bound(points2.begin(), points2.end(), m - *it1);
      if(it2 == points2.begin())continue;
      it2--;
      res = max(res, *it1 + *it2);
    }
    printf("%d\n",res);
  }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,k,x[maxn];
const int inf=0x3f3f3f3f;
long long a,b,now;
int topp,topn;
long long ans;
int main(){
	cin>>n>>k;
	ans=inf;
	for(int i=1;i<=n;i++){
		cin>>x[i];
	}
	for(int i=1;i+k-1<=n;i++){
		a=min(abs(x[i]),abs(x[i+k-1]));
		b=x[i+k-1]-x[i];
		ans=min(ans,a+b);
	}
	cout<<ans;
}

#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

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

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> x(n); cin >> x;
    ll inf = 1000000000, ans = inf;
    rep(i, n-k+1){
        ll a = x[i], b = x[i+k-1];
        if(a < 0 && b < 0) ans = min(ans, abs(a));
        else if(a > 0 && b > 0) ans = min(ans, b);
        else{
            if(abs(a) < abs(b)) ans = min(ans, abs(a)*2 + abs(b));
            else ans = min(ans, abs(a) + abs(b)*2);
        }
    }
    cout << ans << endl;

    return 0;
}


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

const int N = 5e5+15;
const int mod = 1e9+7;
const int M = (1<<22);
int A[N];

int add(int x,int y) {
    return (x+y)%mod;
}
int mul(int x,int y) {
    return (ll)x*y%mod;
}

int dp[M];
int sum[M],X[M];

void solve() {
    int n;
    scanf("%d",&n);
    int g = 0;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        g^= A[i];
    }
    int c = 0;
    int ret = 0;
    ++dp[0];
    if(g>0) {
        for(int i=0;i<n-1;++i) {
            c^= A[i];
            if(c==0) {
                ret = add(ret,dp[g]);
                int u = dp[g];
                dp[0] = add(dp[0],u);
            } else if(c==g) {
                int u = dp[0];
                dp[g] = add(dp[g],u);
            }
        }
        ret = add(ret,1);
    } else {
        int k = 0;
        for(int i=0;i<n-1;++i) {
            c^= A[i];
            if(c==0) {
                ret= add(ret,dp[0]);
                dp[0] = add(dp[0],dp[0]);
                ++k;
            } else {
                int x = k - sum[c];
                sum[c] = k;
                int v = mul(x,X[c]);
                dp[c] = add(dp[c],v);
                X[c] = add(1,add(X[c],dp[c]));
                ret = add(1,add(ret,dp[c]));
            }
        }
        ret = add(ret,1);
    }
    printf("%d\n", ret);
}

int main(){
    //freopen("input.txt","r",stdin);
    solve();
}

#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset>
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}
LL modinv(LL a, LL m){
	LL x,y;
	gcdex(a,m,x,y);
	if(x<0){
		x+=m;
	} else if(x>=m){
		x-=m;
	}
	return x;
}
const int M=1e9+7;
LL cm[1001][1001];
LL dp[1001][1001];
LL rev[1001];
int main() {
	for(int i=0;i<1001;i++){
		cm[i][0]=1;
		for(int j=1;j<=i;j++){
			cm[i][j]=(cm[i-1][j-1]+cm[i-1][j])%M;
		}
	}
	for(int i=1;i<1001;i++){
		rev[i]=modinv(i,M);
	}

	int N,A,B,C,D;
	scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);
	dp[0][A-1]=1;
	for(int i=0;i<=N;i++){
		for(int j=A;j<=B;j++){
			dp[i][j]+=dp[i][j-1];
			LL c=1;
			LL r=i;
			for(int k=1;k<=D;k++){
				c*=cm[r][j]*rev[k]%M;
				c%=M;
				r-=j;
				if(r<0)break;
				if(C<=k){
					dp[i][j]+=c*dp[r][j-1]%M;
					dp[i][j]%=M;
				}
			}
		}
	}
	printf("%lld\n",dp[N][B]);

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int minus = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    if(A.at(i) < 0) {
      minus++;
    }
  }
  if(minus % 2 == 0) {
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
      ans += abs(A.at(i));
    }
    cout << ans << endl;
  }
  else {
    // 絶対値が一番小さいものをaとする
    int64_t a = 1000000000;
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
      if(abs(A.at(i)) < a) {
        a = abs(A.at(i));
      }
      ans += abs(A.at(i));
    }
    ans -= 2 * a;
    cout << ans << endl;
  }
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        sum += a[i];
    }

    ll ans = sum;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] < 0) {
            a[i] *= -1;
            a[i+1] *= -1;
            sum += 2 * a[i];
            sum += 2 * a[i+1];
        }
        ans = max(sum, ans);
    }

    for (int i = n; i >= 1; i--) {
        if (a[i] < 0) {
            a[i] *= -1;
            a[i-1] *= -1;
            sum += 2 * a[i];
            sum += 2 * a[i-1];
        }
        ans = max(sum, ans);
    }

    printf("%lld\n", ans);

}


#include<stdio.h>
#include<algorithm>

using namespace std;

int partition(int array[], int p, int r) {
  int x = array[r];
  int i = p - 1;
  for(int j = p; j < r; j++) {
    if(array[j] <= x) {
      i++;
      swap(array[i], array[j]);
    }
  }
  swap(array[i + 1], array[r]);

  return i + 1;
}

int main(void) {
  int n;
  int array[100000];

  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }

  int index = partition(array, 0, n - 1);

  for(int i = 0; i < n; i++) {
    if(i > 0) {
      printf(" ");
    }

    if(i == index) {
      printf("[%d]", array[i]);
    }
    else {
      printf("%d", array[i]);
    }
  }
  printf("\n");
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

signed main(){
    int N,p[100]={0},r[100];

    cin>>N;
    rep(i,N*(N-1)/2){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;b--;
        if(c>d)p[a]+=3;
        else if(c<d)p[b]+=3;
        else{
            p[a]++;p[b]++;
        }
    }

    vector<pint>vec(N);
    rep(i,N)vec[i]=pint(p[i],i);
    sort(all(vec));reverse(all(vec));

    int tmp=0;
    rep(i,N){
        if(i&&vec[i-1].first!=vec[i].first)tmp=i;
        r[vec[i].second]=tmp;
    }

    rep(i,N)cout<<r[i]+1<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <math.h>
using namespace std;

int main(void){
    int N,X;
    cin >> N >> X;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    int ans=0;
    for(int i=0;i<N;i++){
        if(i==N-1){
            if(A[i]==X){
                ans++;
            }
            X-=X;
        }
        if(A[i]<=X){
            X -= A[i];
            ans++;
        }else{
            cout << ans << endl;
            return 0;
        }
    }
	return 0;
}

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

int main() {
  int k,t;
  cin >> k >> t;
  int ma=0;
  rep(i,t){
    int u;
    cin >> u;
    ma=max(ma,u);
  }
  if(ma>(k*1)/2){
    cout << k-1-(k-ma)*2 << endl;
  }
  else cout << 0 << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

signed main() {
  int N;
  string s;
  cin >> N >> s;

  vector<int> vec(N, INF);
  int x[] = {0, 0, 1, 1};
  int y[] = {0, 1, 0, 1};
  REP(_, 4){
    vec[0] = x[_];
    vec[1] = y[_];
    FOR(i, 1, N-1){
      // hituzi
      if(vec[i] == 1){
        if(s[i] == 'o') vec[i+1] = vec[i-1];
        else vec[i+1] = 1-vec[i-1];
      }else{
        if(s[i] == 'x') vec[i+1] = vec[i-1];
        else vec[i+1] = 1-vec[i-1];
      }
    }
    int ans = 0;
    if(vec[N-1] == 1){
      if(s[N-1] == 'o' && vec[N-2] == vec[0]) ans++;
      if(s[N-1] == 'x' && vec[N-2] != vec[0]) ans++;
    }else{
      if(s[N-1] == 'x' && vec[N-2] == vec[0]) ans++;
      if(s[N-1] == 'o' && vec[N-2] != vec[0]) ans++;
    }
    if(vec[0] == 1){
      if(s[0] == 'o' && vec[N-1] == vec[1]) ans++;
      if(s[0] == 'x' && vec[N-1] != vec[1]) ans++;
    }else{
      if(s[0] == 'x' && vec[N-1] == vec[1]) ans++;
      if(s[0] == 'o' && vec[N-1] != vec[1]) ans++;
    }
    if(ans == 2){
      REP(i, N){
        if(vec[i]) cout << "S";
        else cout << "W";
      }
      cout << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main() {
string s;
cin>>s;
int a=0;
int b=0;
int n=s.size();
int c[n]={};
char w;
int p=0;
if(n!=26){
for(int i=0; i<n; i++){
c[i]=s.at(i)-'a'+1;}
sort(c,c+n);
for(int i=0; i<n; i++){
if(c[i]!=i+1){
a=i;
p++;
break;
}}
if(p==0){
a=n;}
char q=a+'a';
s+=q;
cout<<s<<endl;}
else{
for(int i=0; i<n; i++){
c[i]=s.at(i)-'a';}
for(int i=0; i<n; i++){
if(c[n-2-i]<c[n-1-i]){
a=n-1-i;
b=1;
break;}}
if(b!=1){
cout<<-1<<endl;}
else{
b=10000;
for(int k=a; k<n; k++){
if(c[a-1]<c[k]){
b=min(b,c[k]);}
}
w=b+'a';
for(int i=0; i<a-1; i++){
cout<<s.at(i);}
cout<<w<<endl;}}}


#include <bits/stdc++.h>

using namespace std;

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

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string field[12];
bool b[12][12];

int f(int x, int y){
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	for(int i=0; i< 4; i++){
		int nx = x+dx[i], ny=y+dy[i];
		if(!(0 <= nx && nx < 12 && 0 <= ny && ny < 12)) continue;
		if(field[nx][ny] == '1' && b[nx][ny]){
			b[nx][ny] = false;
			f(nx, ny);
		}
	}
}

int main(){
	while(cin >> field[0]){
		int ret = 0;
		for(int i=0; i <12; i++) for(int j=0; j < 12;j++) b[i][j] = true;
		for(int i=1; i< 12; i++) cin >> field[i];
		for(int i=0; i<12; i++){
			for(int j=0; j < 12; j++){
				if(field[i][j] == '1' && b[i][j]){
					b[i][j] = false;
					f(i, j);
					ret++;
				}
			}
		}
		cout << ret << endl;
	}
}

#include <stdio.h>

int par[12 * 12]; // 島の座標の個数

void init(int n)
{
    for (int i = 0; i < n; i++){
        par[i] = i; // i 番目の頂点のグループは最初は i
    }
}

int find(int x)
{
    if (par[x] == x){
        return (x);
    }
    return (par[x] = find(par[x]));
}

void merge(int x, int y)
{
    x = find(x);
    y = find(y);

    if (x != y){
        par[y] = x;
    }
}

int same(int x, int y)
{
    return (find(x) == find(y));
}

int main(void)
{
    int i, j;
    int num;
    int groups[12 * 12];
    char island[13][13];

    while (1){

        //色々初期化
        num = 0;
        init(12 * 12);
        for (i = 0; i < 12 * 12; i++){
            groups[i] = 0;
        }
        for (i = 0; i < 13; i++){
            for (j = 0; j < 13; j++){
                island[i][j] = 0;
            }
        }

        //入力
        for (i = 0; i < 12; i++){
            if (scanf("%s", island[i]) == EOF){
                return (0);
            }
        }

        for (i = 0; i < 12; i++){
            for (j = 0; j < 12; j++){
                //001
                //001
                //...みたいな繋がり方
                if (island[i][j] == '1' && island[i + 1][j] == '1'){
                    merge(i * 12 + j, (i + 1) * 12 + j);
                }
                //011
                //...みたいな繋がり方
                if (island[i][j] == '1' && island[i][j + 1] == '1'){
                    merge(i * 12 + j, i * 12 + j + 1);
                }
            }
        }

        for (i = 0; i < 12; i++){
            for (j = 0; j < 12; j++){
                if (island[i][j] == '1'){
                    groups[find(i * 12 + j)] = 1;
                }
            }
        }

        for (i = 0; i < 12 * 12; i++){
            num += groups[i];
        }

        printf("%d\n", num);
    }

    return (0);
}


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

int main(){
    int x,y;
    cin>>x>>y;
    int ans=2e9;
    if(y>=x)ans=min(ans,y-x);
    x=-x;
    if(y>=x)ans=min(ans,y-x+1);
    x=-x,y=-y;
    if(y>=x)ans=min(ans,y-x+1);
    x=-x;
    if(y>=x)ans=min(ans,y-x+2);
    cout<<ans<<endl;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int x,y;
  cin >> x >> y;

  int ans=0;
  if(x==y)  ans=0;
  else if(x==0){
    if(y<0) ans++;
    ans+=abs(y);
  }
  else if(y==0){
    if(x>0) ans++;
    ans+=abs(x);
  }
  else if(x<y){
    if(x<0 && 0<y) ans=1+abs(y-abs(x));
    else  ans=abs(y-x);
  }
  else if(y<x){
    if(0<y){
      ans++;
      ans+=1+abs(y-abs(x));
    }
    else if(y<0 && 0<x){
      ans++;
      ans+=abs(abs(y)-x);
    }
    else if(x<0){
      ans++;
      x=-x;
      ans++;
      ans+=abs(abs(y)-x);
    }
  }
  cout << ans << endl;

  return 0;
}


//  Created by Vignesh Manoharan

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vi> vvi;

const int INF = 1000000000;
const ll LINF = 1e17;
const double PI =3.141592653589793238;
#pragma unused(INF,PI,LINF)
#define F(i,a,n) for(int i=(a);i<(n);i++)

template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){
    for(int i=0;i<(t).size();i++)s<<t[i]<<((i<(t).size()-1)?" ":"");return s; }
template<typename T> ostream& operator<<(ostream &s,set<T> t){for(T x:t) s<<x<<" ";return s; }
template<typename T> istream& operator>>(istream &s,vector<T> &t){
    for(int _i=0;_i<t.size();_i++) s>>t[_i];return s; }

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<vector<ii>> graph;

vector<int> dist;
void dijkstra(int s){
    dist[s]=0;
    priority_queue<ii,vector<ii>,greater<ii>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()){
        ii front=pq.top();pq.pop();
        int d=front.first,u=front.second;
        if(d==dist[u]){
            for(auto p:graph[u]){
                int v=p.first,w=p.second;
                if(dist[u]+w<dist[v]){
                    dist[v]=dist[u]+w;
                    pq.push(make_pair(dist[v], v));
                }
            }
        }
    }
}
int main(int argc, const char * argv[]) {
#ifdef local_test
    //    input
    //    freopen("input","w",stdout);
    //    cout<<"1 \n 100 10 \n";
     freopen("input","r",stdin);
     freopen("output","w",stdout);
#endif
    int n,m;
    cin>>n>>m;
    int r;
    cin>>r;
    graph=vector<vector<ii>>(n, vector<ii>());
    dist=vi(n,INF);
    F(i,0,m){
        int s,t,d;
        cin>>s>>t>>d;
        graph[s].pb(mp(t,d));
//        graph[t].pb(mp(s,d));
    }
    dijkstra(r);
    for(int d:dist) if(d<INF) cout<<d<<"\n"; else cout<<"INF\n";
}

#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <sstream>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << os.str();                            \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

int n, m;
string S, T;
int dp[1010][1010];

signed main()
{
    //cin >> n >> m;
    cin >> S >> T;
    n = S.length();
    m = T.length();

    S = '-' + S;
    T = '-' + T;

    REP(i,m+1) dp[0][i] = i;
    REP(i,n+1) dp[i][0] = i;

    for (int i=1; i<n+1; i++) {
        for (int j=1; j<m+1; j++) {
            if (S[i] == T[j]) {
                dp[i][j] = min(dp[i-1][j-1], min(dp[i][j-1] + 1, dp[i-1][j] + 1));
            } else {
                dp[i][j] = min(dp[i-1][j-1] + 1, min(dp[i][j-1] + 1, dp[i-1][j] + 1));
            }
        }
    }

    cout << dp[n][m] << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int ans = 9999;
  for(int i = 0; i < s.size()-2; i++){
    string a;
    for(int j = i; j < 3 + i; j++)
      a.push_back(s.at(j));
    //cout << a << endl;
    ans = min(ans,abs(stoi(a)-753));
    a.erase(a.begin(),a.end());

  }
  cout << ans;
}

#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	string s;
	cin>>s;
	int d,mins=1000;
	for(int i=0;i<(s.size()-2);i++){
		d=((s[i]-'0')*100)+((s[i+1]-'0')*10)+(s[i+2]-'0');
		mins=min(mins,(abs(d-753)));
	}
	cout<<mins;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 5;

int n, a[4][N];

int inv[2], flip[2];
int label[N];

void add_col(vector <int> v, int id)
{
    if(abs(v[2] - v[0]) != 2 || abs(v[1] - v[0]) != 1 || v[1] % 3 < 2)
    {
        cout << "No" << endl;
        exit(0);
    }

    int parity = !(v[1] & 1);
    if(v[0] > v[2])
        flip[parity]++;

    label[(v[1] + 1) / 3] = id;
    if(id & 1 != parity)
    {
        cout << "No" << endl;
        exit(0);
    }
}

bool vis[N];
int comp_sz;
void DFS(int v)
{
    vis[v] = true;
    comp_sz++;
    if(!vis[label[v]])
        DFS(label[v]);
}

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

    int n;
    cin >> n;
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= n; j++)
            cin >> a[i][j];

    for(int j = 1; j <= n; j++)
    {
        vector <int> v = {a[1][j], a[2][j], a[3][j]};
        add_col(v, j);
    }

    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            comp_sz = 0;
            DFS(i);
            inv[i & 1] += (comp_sz - 1);
        }
    }

    inv[0] &= 1;
    inv[1] &= 1;
    flip[0] &= 1;
    flip[1] &= 1;
    if(inv[0] != flip[1] || inv[1] != flip[0])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int n; cin >> n;
    vector<vector<int>> graph(n);
    rp(i, 0, n) {
        rp(j, 0, n-1) {
            int a; scanf("%d", &a); a--;
            graph.at(i).emplace_back(a);
        }
    }

    vector<int> prog(n);
    set<int> s;
    rp(i, 0, n) s.insert(i);
    int day = 0;
    while(!s.empty()) {
        set<int> next_s;
        for(auto x: s){
            int y = graph.at(x).at(prog.at(x));
            if(x == graph.at(y).at(prog.at(y))) {
                if(prog.at(x) < n-2) next_s.insert(x);
                if(prog.at(y) < n-2) next_s.insert(y);
            }
        }

        for(auto x: next_s) {
            // printf("%d ", x);
            prog.at(x) ++;
        }
        // printf("\n");
        day++;
        s = next_s;
    }
    rp(i, 0, n) {
        if(prog.at(i) < n-2) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
    return 0;
}


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

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

  if (s == "SAT")
    cout << 1;
  else if (s == "MON")
    cout << 6;
  else if (s == "TUE")
    cout << 5;
  else if (s == "WED")
    cout << 4;
  else if (s == "THU")
    cout << 3;
  else if (s == "FRI")
    cout << 2;
  else if (s == "SUN")
    cout << 7;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;

int main() {
  ll x;
  cin >> x;
  ll ans = 0;

  ll n = x / 11;
  ans += n*2;
  x -= n*11;

  if(x == 0){}
  else if(x <= 6){ans += 1;}
  else{ans += 2;}

  cout << ans << endl;

}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void solve() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < n; i++) {
    int f = 0;
    for (int j = 0; i + j < n; j++) {
      if (a[j + i] != b[j]) {
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << n + i << '\n';
      return;
    }
  }
  cout << n + n << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    string t;
    cin >> t;
    int max_length = 0;
    for (int i = 1; i <= N; i++){
        if (s.substr(N - i, i) == t.substr(0, i)) max_length = i;
    }
    cout << 2 * N - max_length << endl;
}


// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s, t;
  cin >> s >> t;
  cout << t << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t+s << endl;
}


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

using lint = long long;

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

bool solve(int N, std::vector<lint>& A) {
    lint sum = std::accumulate(A.begin(), A.end(), 0LL);

    // Nが偶数の場合、和の偶奇がそのまま勝敗になる
    if (N % 2 == 0) return sum % 2 != 0;

    // Nが奇数の場合も、和が偶数なら絶対勝てる
    if (sum % 2 == 0) return true;

    // 奇数を前に持っていく
    std::sort(A.begin(), A.end(), [](int a, int b) { return a % 2 > b % 2; });
    // 奇数が複数個ある、あるいは唯一の奇数が1(減らせない)なら負け
    if (A[0] == 1 || (A[1] & 1) != 0) return false;

    // そうでなければ、唯一の奇数を減らしてシミュレート
    --A[0];
    int g = accumulate(A.begin(), A.end(), 0LL, gcd<lint>);  // 全体のgcdを取る
    for (auto& a : A) a /= g;
    return !solve(N, A);
}

int main() {
    int N;
    std::cin >> N;
    std::vector<lint> A(N);
    for (auto& a : A) std::cin >> a;

    std::cout << (solve(N, A) ? "First" : "Second") << std::endl;
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=100005;
long long n;
long long a[MAXN];
long long gcd(long long a,long long b)
{
	return b==0?a:gcd(b,a%b);
}
void pr(long long x)
{
	if(x==1)
		printf("First\n");
	else
		printf("Second\n");
	exit(0);
}
void dfs(long long x)
{
	long long s=0;
	for(long long i=1;i<=n;i++)
		s+=a[i]-1;
	if(s&1)
		pr(x^1);
	long long cnt=0;
	for(long long i=1;i<=n;i++)
		if(a[i]&1)
			cnt++;
	for(long long i=1;i<=n;i++)
		if(a[i]==1)
			cnt=903;
	if(cnt!=1)
		pr(x);
	for(long long i=1;i<=n;i++)
		if(a[i]&1)
		{
			a[i]--;
			break;
		}
	long long G=0;
	for(long long i=1;i<=n;i++)
		G=gcd(G,a[i]);
	for(long long i=1;i<=n;i++)
		a[i]/=G;
	dfs(x^1);
}
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	dfs(0);
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;

	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t 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 maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  string s;
  cin >> s;
  int op = 0;

  for(int i=0;i<=7;i++){
    string equStr = "";
    equStr += s[0];
    int ans = s[0]-'0';
    for(int j=0;j<3;j++){
      if((i>>j)%2==0){
        equStr += "+";
        ans += s[j+1]-'0';
      }
      else{
        equStr += "-";
        ans -= s[j+1]-'0';
      }
      equStr += s[j+1];
    }
    if(ans==7){
      cout << equStr << "=7" << endl;
      return 0;
    }
  }

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool prime[10001];
    memset(prime,0,sizeof(prime));
    for(int i=2;i<sqrt(10001);i++){
        if(!prime[i])for(int j=i*2;j<10005;j+=i)prime[j]=1;
    }
    int n;
    while(cin>>n,n){
        for(int i=n;i>2;i--){
            if(!prime[i]&&!prime[i-2]){
                cout<<i-2<<" "<<i<<endl;
                break;
            }
        }
    }
}


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

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  vector<vector<int>> d(h, vector<int>(w, -1));
  queue<P> que;
  rep(i, h) rep(j, w) {
    if (a[i][j] == '.') continue;
    d[i][j] = 0;
    que.push(make_pair(i, j));
  }

  while (que.size()) {
    P p = que.front();
    que.pop();
    rep(i, 4) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (d[nx][ny] != -1) continue;
      d[nx][ny] = d[p.first][p.second] + 1;
      que.push(make_pair(nx, ny));
    }
  }

  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, d[i][j]);
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

const int dx[] = { 1,-1,0,0 }, dy[] = { 0,0,1,-1 };
int time_ = 0;
int H, W;
bool cont = false;
vector<vector<char>> a;
queue<Pos> remq;
queue<Pos> nxtq;
int main() {
    cin >> H >> W;
    a = vector<vector<char>>(W + 1, vector<char>(H + 1));
    rep11(y, H) rep11(x, W) {
        cin >> a[x][y];
        if (a[x][y] == '#') nxtq.push(Pos{ x, y });
    }
    while (0 < nxtq.size()) {
        remq = queue<Pos>(nxtq);
        nxtq = queue<Pos>();
        cont = false;
        while (0 < remq.size()) {
            Pos ref = remq.front();
            remq.pop();
            rep(i, 4) {
                Pos chk = Pos{ ref.x + dx[i], ref.y + dy[i] };
                if (chk.x <= 0 || chk.x > W || chk.y <= 0 || chk.y > H) continue;
                if (a[chk.x][chk.y] == '.') {
                    a[chk.x][chk.y] = '#';
                    nxtq.push(Pos{ chk.x, chk.y });
                    cont = true;
                }
            }
        }
        if (cont) time_++;
    }
    cout << time_ << endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}

ll const N=(ll)2e5+11;
ll const LG=(ll)log2(N)+1;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;

      vll a(5);
      n=5;
      cin>>m;
      ll tt=1e15;
      for(i=0;i<5;i++){
              cin>>a[i];
              tt=min(tt,a[i]);
      }
      ll ans=0;
      for(i=n-1;i>=0;i--){
              if(a[i]==tt){
                      ans=ceil1(m,tt);
                      ans+=n-1;
              }
      }
      cout<<ans<<endl;

}
int main(){
        FS;

        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        for(ll tc=1;tc<=q;tc++){
                // cout<<"Case #"<<tc<<": ";
                solve();
        }
        return 0;
}

ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;

        if(m%2==0)return pow1((n*n)%mod,m/2,mod);

    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(5);
  rep(i,5) cin >> vec.at(i);
  sort(vec.begin(),vec.end());
  ll ans = 0;
  if (n % vec.at(0) > 0) ans++;
  ans += n / vec.at(0) + 4;
  cout << ans << endl;
}


#include<bits/stdc++.h>

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}

 ll a,b,c,s,t,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll cnt;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>a;

	vector<int> f(a);

	REP(i,a) cin>>f[i];

	for(x=0;x<a-2;x++){
		for(y=x+1;y<a-1;y++){
	for(z=y+1;z<a;z++) {
		if(f[x]>f[y] && f[x]>f[z] && f[x]-f[y]-f[z]<0 && f[y]!=f[z]) cnt++;
		else if(f[y]>f[x] && f[y]>f[z] && f[y]-f[x]-f[z]<0 && f[x]!=f[z]) cnt++;
		else if(f[z]>f[y] && f[z]>f[x] && f[z]-f[y]-f[x]<0 && f[x]!=f[y]) cnt++;
	}
}
	}

	cout<<cnt;

	return 0;

}

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> scores(n, vector<ll>(n));
	rep(i, n) {
		rep(j, n) {
			cin >> scores[i][j];
		}
	}
	vector<ll> dp(1LL << n, 0);
	rep(i, 1LL << n) {
		ll add = 0;
		for (ll j = 0; j < n; j++) {
			for (ll k = 0; k < j; k++) {
				if (i & (1LL << j)) {
					if (i & (1LL << k)) {
						dp[i] += scores[j][k];
					}
				}
			}
		}
	}
	for (ll i = 0; i < 1LL << n;i++) {
		ll u = dp[i];
		for (ll j = i; j > 0; j = ((j-1) & i)) {
			u = max(u, dp[j] + dp[(i ^ j)]);
		}
		dp[i] = u;
	}
	cout << dp[(1LL << n) - 1] << endl;
	return 0;
}


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

int main() {
  string A,B,C; cin >> A >> B >> C;
  int a,b,c;
  a = A.size();
  b = B.size();
  c = C.size();
  char s,t,u,v;
  s = A.at(a-1);
  t = B.at(0);
  u = B.at(b-1);
  v = C.at(0);
  if (s == t && v == u){
    cout << "YES";
  }
  else cout << "NO";
}

#include <iostream>
#include <numeric>

using namespace std;

const string YES = "POSSIBLE";
const string NO = "IMPOSSIBLE";

int main() {
  int N, K, M{}, D{}, A;
  cin >> N >> K;
  while (cin >> A) {
    M = max(M, A);
    if (D) D = gcd(D, A);
    else D = A;
  }
  cout << (K <= M && (M - K) % D == 0 ? YES : NO) << endl;
}


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

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

using namespace std;

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

char f(char c,int n)
{
//	cout << c << ' ';
	REP(i,n)
	{
		if(c == 'a')
			c = 'Z';
		else if(c == 'A')
			c = 'z';
		else
			c--;
	}
//	cout << c << endl;
	return c;
}

int main()
{
	int n;

	while(cin >> n,n)
	{
		iv v;
		REP(i,n)
		{
			int tmp;
			cin >> tmp;
			v.PB(tmp);
		}

		string str;
		cin >> str;

		REP(i,str.size())
		{
			str[i] = f(str[i],v[i%n]);
		}

		cout << str << endl;
	}

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define maxn 1000100
#define mod 1000000007
using namespace std;
char a[maxn];
int n,q,k;
ll ans=0;
void sol(){
	ans=0;
	ll d=0,dm=0,m=0;
	for(int i=0;i<n;i++){
		if(i>=k){
			if(a[i-k]=='D'){
				dm-=m;
				d--;
			}
			if(a[i-k]=='M') m--;
		}
		if(a[i]=='C') ans+=dm;
		if(a[i]=='D') d++;
		if(a[i]=='M') dm+=d,m++;
	}
}
int main(){
	scanf("%d",&n);
	scanf("%s",a);
	scanf("%d",&q);
	while(q--){
		scanf("%d",&k);
		sol();
		printf("%lld\n",ans);
	}
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i<n; i++){
        cin >> a[i];
    }
    for (int i = n-1; i>=1; i--){
        cout << a[i] << " ";
    }
    cout <<a[0]<< endl;

}

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

int main() {
    int c;
    cin >> c;
    int *a = new int[c];
    for (int cc = 0; cc < c; cc++) {
        cin >> a[cc];
    }

    string str;
    for (int cc = c - 1; cc >= 0; cc--) {
        str += to_string(a[cc]) + " ";
    }
    str.erase(str.length() - 1);
    cout << str << endl;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n;
    cin >> n;
    ll ans = (n/500) * 1000 + (n % 500) - n % 5;
    cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    int ans = 0;
    while (x > 4)
    {
        if (x - 500 >= 0)
        {
            x -= 500;
            ans += 1000;
        }
        else
        {
            if (x - 5 >= 0)
            {
                x -= 5;
                ans += 5;
            }
        }
    }

    cout << ans;
}


//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

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

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)

//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;

typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
//typedef vector<vll > vvll;
tdv(string, vs)

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

    vi x(N),y(N),P(N);
    double num=N;
    repi0(i, N){
        if(i!=0){
            num*=i;
        }
        P[i]=i;
        cin>>x[i]>>y[i];
    }
    double sum=0;
    do{
        double len=0;
        repi0(i, N-1){
            int dx=x[P[i]]-x[P[i+1]],dy=y[P[i]]-y[P[i+1]];
            len+=sqrt(dx*dx+dy*dy);
        }
        sum+=len;
    }while (next_permutation(P.begin(), P.end()));
    cout<<fixed<<setprecision(10)<<sum/num<<endl;

    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;

double len(int x1,int x2, int y1,int y2){
    double res;
    double x=x1-x2;
    double y=y1-y2;
    res=pow(x*x+y*y,0.5);
    return res;
}

int main(){
    int n;
    cin>>n;
    int x[n],y[n];
    double ans=0;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i];
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=len(x[i],x[j],y[i],y[j])*2.0/n;
        }
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}


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

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

string s[410];
bool seen[410][410];
int h, w;
ll cnt_w, cnt_b;

void bfs(int sx, int sy){
    queue<pair<int,int>> que;
    que.push({sx,sy});
    while(!que.empty()){
        pair<int,int> p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;

        if (s[y][x] == '#') cnt_b++;
        else if (s[y][x] == '.') cnt_w++;
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
            else if (seen[ny][nx]) continue;
            else if (s[ny][nx] != s[y][x]) {
                seen[ny][nx] = true;
                que.push({nx,ny});
            }
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    ll ans = 0;

    rep(y, h) rep(x, w){
        cnt_w = 0, cnt_b = 0;
        if(seen[y][x]) continue;
        seen[y][x] = true;
        bfs(x, y);
        ans += cnt_w * cnt_b;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<double> v(N);
	for (int i = 0; i < N ; ++i)
		cin >> v[i];

	double roll = 0;
	for (int i = 0; i < K; ++ i)
		roll += 0.5 * (1. + v[i]);

	double maxima = roll;

	for (int i = 0; i < v.size() - K; ++i)
	{
		// cout << "subtract " << i << " " << v[i] << " add " << i + K << " " << v[i + K] << "\n";
	       	roll = roll + 0.5 * (1 + v[i + K]) - 0.5 * (1 + v[i]);
		maxima = max(maxima, roll);
	}
	printf("%.12f", maxima);

	return 0;
}


#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> A(N);
	map<int,int> cnt;
	rep(i,N){
		cin>>A[i];
		cnt[A[i]]++;
	}
	sort(all(A));
	int ans = 0;
	for(int i = N-1; i>= 0; --i){
		if(cnt[A[i]] < 1)continue;
		--cnt[A[i]];
		int need = pow(2LL, (int)log2(A[i])+1) - A[i];
		// printf("%d,%d\n", A[i], need);
		if(cnt[need] > 0){
			++ans;
			--cnt[need];
		}
	}
	cout<<ans<<endl;
}

// int main(){
// 	int N; cin>>N;
// 	vector<ll> A(N);
// 	map<ll,ll> hash;
// 	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> Q;
// 	rep(i,N){cin>>A[i]; hash[A[i]]++;}
// 	rep(i,N){
// 		ll cand = 0;
// 		ll t = 2;
// 		while(t < 1000000100){
// 			if(hash.count(t - A[i]) == 1){
// 				if(A[i] == t-A[i]){
// 					if(hash[A[i]] >= 2){++cand;}
// 				}else{
// 					++cand;
// 				}
// 			}
// 			t *= 2;
// 		}
// 		if(cand != 0){
// 			Q.push(make_pair(cand, i));
// 		}
// 	}
// 	// while(!Q.empty()){
// 	// 	cout<<Q.top().second<<" has "<<Q.top().first<<endl;
// 	// 	Q.pop();
// 	// }
// 	// return 0;
// 	ll ans = 0;
// 	while(!Q.empty()){
// 		ll e = A[Q.top().second];
// 		Q.pop();
// 		if(hash[e] <= 0)continue;
// 		ll t = 2;
// 		while(t < 1000000100){
// 			if(hash[t-e] > 0){
// 				++ans;
// 				--hash[t-e];
// 				--hash[e];
// 				break;
// 			}
// 			t *= 2;
// 		}
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

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

int main(){
    int n;
    cin>>n;
    vector<ll> c(100005);
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        c[d]++;
        if(i==0&&d!=0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=0;
    if(c[0]==1) ans=1;
    for(int i=1;i<n;i++){
        for(int j=0;j<c[i];j++){
            ans*=c[i-1];
            ans%=998244353;
        }
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <string>
using namespace std;
typedef struct{
	string id;
	long long sales;
} staff;

int main(void)
{
	long long n;
	while(cin>>n){
		if(!n) break;
		staff staff1[4001];
		int pt = 0;
		for(int i=0; i< n; i++){
			string id;
			cin >> id;
			long long price;
			int bnum;
			cin >> price >> bnum;
			int m=-1;
			for(int j=0;j < i; j++){
				if(id==staff1[j].id){
					pt++;
					m=j;
					break;
				}
			}
			if(m==-1){
				staff1[i-pt].id = id;
				staff1[i-pt].sales = price * bnum;
			}else{
				staff1[m].sales += price * bnum;
			}
		}
		int count = 0;
		for(int i=0; i < n-pt; i++){
			if(staff1[i].sales >= 1000000){
				count++;
				cout << staff1[i].id << endl;
			}
		}
		if(!count) cout << "NA" << endl;
	}

	return 0;
}

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

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

	while(n != 0){
		vector < pair<long long, long long> > v(n);
		int order[n];
		int num = 0;
		for (int i = 0; i < n; ++i){
			long long id, p, q;
			cin >> id >> p >> q;
			v[i] = make_pair(id, p * q);
			order[i] = id;
		}

		sort(v.begin(), v.end());
		int c = 1;

		for (int i = 0; i < n - 1; ++i){
			if(v[i].first != v[i+1].first){
				c++;
			}
		}

		vector < pair<long long, long long> > sum(c);
		int k = 0;
		for (int i = 0; i < c; ++i){
			sum[i] = make_pair(0, 0);
		}

		long long s = 0;
		for (int i = 0; i < n ; ++i){
			s += v[i].second;
			if(i < n - 1){
				if(v[i].first != v[i+1].first){
					sum[k] = make_pair(v[i].first, s);
					s = 0;
					k++;
				}
			}else{
				sum[k] = make_pair(v[i].first, s);
			}
		}

		int ids[c];
		for (int i = 0; i < c; ++i){
			if(sum[i].second >= 1000000){
				ids[num] = sum[i].first;
				num++;
			}
		}

		for(int i = 0; i < n; i++){
			for(int j = 0; j < num; j++){
				if(order[i] == ids[j]){
					cout << order[i] << endl;
					ids[j] = -10000;
				}
			}
		}

		if(num == 0){
			cout << "NA" << endl;
		}

		cin >> n;
	}

	return 0;
}


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

int main(){

    int n;cin>>n;
    vv faclist(19, vi (19, 0));

    rep(i,n){
        double a;cin>>a;
        ll anum = a*1e9+0.5;

        //llとして読み込み, 2と5の冪を計算
        int fac2 = -9, fac5 = -9;

        while( fac2<10 && anum%2 == 0 ){
            fac2++;
            anum /= 2;
        }

        while( fac5<10 && anum%5 == 0 ){
            fac5++;
            anum /= 5;
        }

        faclist[min(18,fac2+9)][min(18,fac5+9)]++;
    }

    //個数累積のリストを作る
    vv acclist = faclist;

    rep(i,19){
        for(int j=17; j>=0; j--){
            acclist[i][j] += acclist[i][j+1];
        }
    }
    rep(j,19){
        for(int i=17; i>=0; i--){
            acclist[i][j] += acclist[i+1][j];
        }
    }

    ll ans = 0;

    rep(i,19)rep(j,19){
        if(!faclist[i][j])continue;

        if(i>8 && j>8)ans += faclist[i][j] * (acclist[18-i][18-j]-1);
        else ans += faclist[i][j] * acclist[18-i][18-j];
    }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}
typedef double db;

const int N = 200010;
int n;
ll val[N];
int n2[N], n5[N], num[20][20];
int main() {
  db tmp;
  read(n);
  rep (i, 1, n) {
    scanf("%lf",&tmp);
    val[i] = (ll)(tmp * 1e9 + 0.5);
  }
  rep (i, 1, n) {
    while (val[i] % 2 == 0)
      ++ n2[i], val[i] /= 2;
    while (val[i] % 5 == 0)
      ++ n5[i], val[i] /= 5;
  }
  ll ans = 0;
  int mx2 = 0, mx5 = 0;
  rep (i, 1, n) {
    rep (a, 0, mx2) rep (b, 0, mx5) {
      if (a + n2[i] >= 18 && b + n5[i] >= 18)
        ans += num[a][b];
    }
    n2[i] = min(n2[i], 18);
    n5[i] = min(n5[i], 18);
    mx2 = max(n2[i], mx2);
    mx5 = max(n5[i], mx5);
    ++ num[n2[i]][n5[i]];
  }
  cout << ans << endl;
  return 0;
}


#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define ld double
#define inf 2001
#define infm inf*inf
#define mod ((ll)1e9+7)
#define INF (int)(1e9)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

ll getinv(ll x){
	ll k=mod-2,ans=1;
	while (k){
		if (k&1){
			ans=ans*x%mod;
		}
		x=x*x%mod;
		k/=2;
	}
	return ans;
}

ll fact[infm],invf[infm];

void prework(int N){
	fact[0]=1;
	for (int i=1;i<=N;i++){
		fact[i]=fact[i-1]*i%mod;
	}
	invf[N]=getinv(fact[N]);
	for (int i=N-1;i>=0;i--){
		invf[i]=invf[i+1]*(i+1)%mod;
	}
	return;
}

ll C(int x,int y){
	return fact[x]*invf[y]%mod*invf[x-y]%mod;
}

ll cal(int x,int y){
	return C(x+y,x);
}

int n,K;
int f[inf][inf];

int main(){
	rd(n) rd(K)
	if (K==1){
		puts("1");
		return 0;
	}
	prework(n*K);
	f[0][0]=1;
	for (int i=1;i<=n;i++){
		ll sum=0;
		for (int j=i;j>=1;j--){
			sum=(sum+f[i-1][j-1])%mod;
			f[i][j]=sum*cal((i-1)*K-j+1,K-2)%mod;
		}
	}
	ll ans=0;
	for (int i=0;i<=n;i++){
		ans=(ans+f[n][i])%mod;
	}
	printf("%lld\n",ans*fact[n]%mod);
	return 0;
}

// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Segment Tree
template <typename Operator>
struct SegmentTree {
    Operator OP;
    using NodeType = decltype(OP.NodeE);
    int length;
    vector<NodeType> node;
    SegmentTree (int N) {
        length = 1;
        while (length < N) length <<= 1;
        node.assign(length << 1, OP.NodeE);
    }
    SegmentTree (vector<NodeType> &vec) {
        length = 1;
        while (length < sz(vec)) length <<= 1;
        node.assign(2 * length, OP.NodeE);
        rep(i, sz(vec)) node[i + length] = vec[i];
        for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
    }
    void update(int idx, NodeType val) {
        idx += length;
        node[idx] = OP.change(node[idx], val);
        while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
    }
    NodeType get(int l, int r) {
        l += length;
        r += length;
        NodeType vl = OP.NodeE, vr = OP.NodeE;
        while (r > l) {
            if (l & 1) vl = OP.func(vl, node[l++]);
            if (r & 1) vr = OP.func(node[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return OP.func(vl, vr);
    }
};
struct RMQ {
    using NodeType = pair<int, int>;
    NodeType NodeE = pair<int, int>(-1, -1);
    NodeType change(NodeType x, NodeType y) {return y;}
    NodeType func(NodeType x, NodeType y) {return max(x, y);}
};

// Main
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {cin >> a[i]; --a[i];}

    int ans = 0;
    if (a[0] != 0) {++ans; a[0] = 0;}

    vector<vector<int>> g(n);
    rep(i, 1, n) {g[a[i]].push_back(i);}
    vector<int> d(n, 0);
    auto dfs = [&](auto f, int v, int par) -> void {
        for (int u: g[v]) {
            if (u == par) continue;
            d[u] = d[v] + 1;
            f(f, u, v);
        }
    };
    dfs(dfs, 0, -1);
    SegmentTree<RMQ> st(n);
    rep(i, n) st.update(i, pair<int, int>(d[i], i));

    while (true) {
        pair<int, int> p = st.get(0, n);
        if (p.first <= k) break;
        int now = p.second;
        rep(i, k - 1) now = a[now];
        d[now] = 1;
        auto dfs2 = [&](auto f, int v, int par) -> void {
            st.update(v, pair<int, int>(d[v], v));
            for (int u: g[v]) {
                if (u == par || d[u] == 1) continue;
                d[u] = d[v] + 1;
                f(f, u, v);
            }
        };
        dfs2(dfs2, now, -1);
        ++ans;
    }
    cout << ans << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define bgn begin()
#define sz size()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()
#define ff first.first
#define fs first.second

signed main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  V<int> X(n);
  fo(i,n){
    cin >> X[i];
  }
  V<int> Y(m);
  fo(i,m){
    cin >> Y[i];
  }
  Sort(X);
  Sort(Y);

  int Max_x = X[n-1];
  int Min_y = Y[0];

  bool can = 0;
  for(int i = x+1; i <= y; i++){
    if(Max_x < i && Min_y >= i){
      can = 1;
      break;
    }
  }
  if(can)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}