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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  string S;
  cin>>S;
  reverse(S.begin(),S.end());
  int l = S.size();
  int ans = 0;
  int over = 0;
  for(int i = 0; i < l; i++){
    int t = S[i]-'0';
    t+=over;
    over = 0;
    if(t>=10) {
      t-=10;
      over = 1;
    }
    if(t<=4) ans += t;
    if(t==5){
      int s;
      if(i!=l-1) s = S[i+1]-'0';
      if(i==l-1||s<=4) ans+=t;
      else if(s>=5) {
        ans+=(10-t);
        over=1;
      }
    }
    if(t>=6) {
      ans += (10-t);
      over = 1;
    }
    if(i==l-1&&over!=0) ans+=over;
  }
  cout<<ans<<endl;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

vector<int> tpsort(vector<vector<int>>& G) {
    int V = G.size();
    vector<int> sorted_vertices;
    queue<int> que;
    vector<int> indegree(V);
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            indegree[G[i][j]]++;
        }
    }
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }
    while (que.empty() == false) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        sorted_vertices.push_back(v);
    }
    return sorted_vertices;
}

struct Point
{
    double x;
    double y;
};

struct LineSegment
{
    Point start;
    Point end;
};

double tenkyori(const LineSegment& line, const Point& point)
{
    double x0 = point.x, y0 = point.y;
    double x1 = line.start.x, y1 = line.start.y;
    double x2 = line.end.x, y2 = line.end.y;

    double a = x2 - x1;
    double b = y2 - y1;
    double a2 = a * a;
    double b2 = b * b;
    double r2 = a2 + b2;
    double tt = -(a * (x1 - x0) + b * (y1 - y0));

    if (tt < 0)
        return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
    else if (tt > r2)
        return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));

    double f1 = a * (y1 - y0) - b * (x1 - x0);
    return sqrt((f1 * f1) / r2);
}

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    ll nans = 100000;
    for (int i = 0; i < s.size(); i++) {
        ll u = (ll)(s[i] - '0');
        ll as = ans;
        ll ns = nans;
        ans =min(as+u,ns+u+1);
        nans = min(as+10-u,ns+9-u);
    }
    cout << min(ans,nans+1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef double db;
typedef pair<int, int> pii;typedef pair<ll, ll> pll;
typedef pair<int,ll> pil;typedef pair<ll,int> pli;
#define Fi first
#define Se second
#define _Out(a)	cerr<<#a<<" = "<<(a)<<endl
const int INF = 0x3f3f3f3f, MAXN = 1e6 + 50;
const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 998244353;
const db Pi = acos(-1), EPS = 1e-6;
void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);}
inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;}
inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;}
inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;}
inline int sign(db x){return x<-EPS ? -1:x>EPS;}
inline int dbcmp(db l,db r){return sign(l - r);}
namespace Fast_IO{ //orz laofu
    const int MAXL((1 << 18) + 1);int iof, iotp;
    char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55];
    char Getchar(){
        if (ioiS == ioiT){
            ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++);
        }else return (*ioiS++);
    }
    void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;}
    void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();}
    inline int read(){
        int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    inline long long read_ll(){
        long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof;
    }
    void Getstr(char *s, int &l){
        for(ioc=Getchar();ioc==' '||ioc=='\n'||ioc=='\t';)ioc=Getchar();
        if(ioc==EOF)Write(),exit(0);
        for(l=0;!(ioc==' '||ioc=='\n'||ioc=='\t'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0;
    }
    template <class Int>void Print(Int x, char ch = '\0'){
        if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10;
        while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch);
    }
    void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);}
} // namespace Fast_IO
using namespace Fast_IO;

vector<int>pos[MAXN];
pii cnt[MAXN];
int ccnt[MAXN];
int ans[MAXN];
bool cmp(pii l,pii r){return l.first>r.first;}
void work()
{
    int n=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        pos[x].push_back(i);
        cnt[x].first++;
        cnt[i].second=i;
    }
    for(int i=1;i<=n;i++)
    {
        int x=read();
        cnt[x].first++;
        ccnt[x]++;
    }
    int nowat=1;
    sort(cnt+1,cnt+1+n,cmp);
    srand(time(0));
    if(cnt[1].first>n)
    {
        printf("No\n");return ;
    }
    random_shuffle(cnt+1,cnt+1+n);
    int zcnt=0;
    for(int i=1;i<=n;i++)
    {
        int QAQ=cnt[i].second;
        if(cnt[nowat].second==QAQ)nowat++;
        if(nowat>n)nowat=1;

        while(ccnt[QAQ])
        {
            while(pos[cnt[nowat].second].size()==0||cnt[nowat].second==QAQ)
            {

                nowat++;if(nowat>n)nowat=1;
            }
            ans[pos[cnt[nowat].second].back()]=QAQ;
            pos[cnt[nowat].second].pop_back();
            ccnt[QAQ]--;
        }
    }
    printf("Yes\n");
    for(int i=1;i<=n;i++)printf("%d ",ans[i]);

}

int main()
{
    //std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //int T=read();for(int cas=1;cas<=T;cas++)
    //int T;scanf("%d",&T);for(int i=1;i<=T;i++)
    work();
    // Write();
}

/**
1 1
4 0 1
4 0 1000000

*/

// g++ -std=c++11 test.cpp && ./a.out
// g++ -std=c++11 test.cpp && cat test.txt | ./a.out

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>

using namespace std;

#define INF (1<<29)
#define SZ(X) ((int)(X).size())
#define PRINT(A) {for (auto it=A.begin(); it != A.end(); ++it) {cout << *it << ' ';} cout << endl;}
#define SUM(A) accumulate(A.begin(), A.end(), 0)
#define MAX(A) *max_element(A.begin(), A.end())
#define BIT_LENGTH(N) floor(log2(N)) + 1
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define RREP(I, N) for (int I = N-1; I >= 0 ; --I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RREPP(I, A, B) for (int I = A; I > (B); --I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
typedef vector<int> VI;
typedef map<int, int> MII;
typedef set<int> SI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;

void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }

const double PI = acos(-1);
const int MAX_SIZE = 2*1e5+1;
VI A_indexes[MAX_SIZE];

int main() {
    int N;
    _R(N);
    // cout << N << endl;
    VI C(N+1, 0);
    VI A;
    REP(i, N) {
        int a;
        _R(a);
        A.push_back(a);
        C[a] += 1;
    }
    VI B;
    REP(i, N) {
        int b;
        _R(b);
        B.push_back(b);
        C[b] += 1;
    }

    REP(i, N+1) {
        if (C[i] > N) {
            puts("No");
            return 0;
        }
    }

    reverse(B.begin(), B.end());
    int swap_index = 0;
    REP(i, N) {
        if (A[i] == B[i]) {
            while (A[i] == A[swap_index] || B[i] == B[swap_index]) {
                swap_index += 1;
            }
            swap(B[swap_index], B[i]);
            swap_index += 1;
        }
    }
    puts("Yes");
    PRINT(B);

    return 0;
}


#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>
using namespace std;

int main() {
  string S;
  cin >> S;
  S[3] = '8';

  cout << S << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	string s; cin>>s;
	int len=s.length();
	map <char,int> mp;
	map <char,int> pp;
	int st=-1,en=-1;
	for(int i=0;i<len;i++)
	{
	    mp[s[i]]++;
	    if(mp[s[i]]==1) pp[s[i]]=i;
	    else
	    {
	        if( i-pp[s[i]] <= 2 )
	        {
	            st=pp[s[i]]+1; en=i+1;
	            break;
	        }
	        pp[s[i]]=i;
	    }
	}
	cout<<st<<' '<<en;

	return 0;
}


#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int i;
    long double sum=0;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum+=a[i];
    }
    const long double eps=1e-12;
    long double min=HUGE_VAL;
    int mini=0;
    sum/=n;
    for(i=0; i<n; i++) {
        double tmp=fabs(a[i]-sum);
        if(tmp<min-eps) {
            min=tmp;
            mini=i;
        }
    }
    printf("%d\n", mini);

    return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,m;
  string s[200],t[200];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> s[i];
  cin >> m;
  for(int i = 0; i < m; i++)
    cin >> t[i];

  int sum = 0;
  for(int i = 0; i < n; i++) {
    int cnt = 1;
    for(int j = i+1; j < n; j++)
      if(s[i] == s[j]) cnt++;
    for(int j = 0; j < m; j++)
      if(s[i] == t[j]) cnt--;
    sum = max(sum, cnt);
  }

  cout << sum << endl;
}


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

int main() {
  ll n;
  cin >> n;
  vector<string> s(3);
  for(ll i=0;i<3;i++) {
    cin >> s[i];
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    set<char> ss;
    for(ll j=0;j<3;j++) {
      ss.insert(s[j][i]);
    }
    ans+=ss.size()-1;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    string a, b, c; cin >> a >> b >> c;
    int ans = 0;
    rep(i,n) {
        set<char> st;
        for (string s : vector<string>{a,b,c}) {
            st.insert(s[i]);
        }
        if (st.size() == 2) ans += 1;
        if (st.size() == 3) ans += 2;
    }
    cout << ans << endl;
}


#include<stdio.h>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
P s[101];
int r[100];
int main(){
	int n;
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)s[i]=P(0,i);
	for(i=0;i<n*(n-1)/2;i++){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		a--;b--;
		if(c>d)s[a].first+=3;
		if(c<d)s[b].first+=3;
		if(c==d){
			s[a].first+=1;
			s[b].first+=1;
		}
	}
	s[n]=P(-1,-1);
	sort(s,s+n);
	reverse(s,s+n);
	int p=0;
	int pr=0;
	while(p<n){
		r[s[p].second]=pr;
		while(s[p].first==s[p+1].first){
			p++;
			r[s[p].second]=pr;
		}
		p++;
		pr=p;
	}
	for(i=0;i<n;i++)printf("%d\n",r[i]+1);
	return 0;
}

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

int main(){
  int teamn = 0;
  cin >> teamn;
  vector<int> point(teamn,0);
  vector<int> run(teamn,0);
  vector<int> plist;
  vector<int> rank(teamn,1);
  int fteam1,fteam2;
  int point1,point2;
  for(int n = 0;n<(teamn*(teamn-1))/2;n++){
    cin >> fteam1 >> fteam2;
    cin >> point1 >> point2;
    fteam1 -= 1;
    fteam2 -= 1;
    if(point1 > point2){
      point[fteam1] += 3;
    }else
    if(point1 == point2){
      point[fteam1] += 1;
      point[fteam2] += 1;
    }else
    if(point1 < point2){
      point[fteam2] += 3;
    }
  }
  for(int g = 0;g<point.size();g++){
    run[g] = point[g];
  }
  sort(run.begin(),run.end(),greater<int>());
  //for(int n = 0;n<run.size();n++){
  //  if(run[n] != run[n+1]){
  //    plist.push_back(run[n]);
  //  }
  //}
  for(int n = 0;n<run.size();n++){
    for(int g = 0;g<point.size();g++){
      if(n == 0 && run[n] == point[g]){
        rank[g] = n;
      }
      if(run[n] == point[g] && n != 0){
        if(run[n] != run[n-1]){
          rank[g] = n;
        }
      }
    }
  }
  for(int n = 0;n<rank.size();n++){
    cout << rank[n]+1 << endl;
  }
  return 0;
}


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

int main(){
    ll N, x; cin >> N >> x;
    ll ans = 0;
    ll prev; cin >> prev;
    for (int i = 1; i < N; i++){
        ll num; cin >> num;
        ll sum = prev + num;
        if(sum<=x){
            prev = num;
            continue;
        }

        ans += sum-x;
        if(sum-x > num) num = 0;
        else num = num - (sum - x);

        prev = num;
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
   ll n, x;
   cin >> n >> x;
   vector<long long> candy;
   while(n--)
   {
       int a;
       cin >> a;
       candy.pb(a);
   }
   ll ans = 0;
   for(int i = 1; i < candy.size(); i++)
   {
       if(i == 1)
       {
           if(candy[i-1] > x)
           {
               ans += candy[i-1] - x;
               candy[i-1] = x;
           }
       }

       if(candy[i-1] + candy[i] > x)
       {
           ans += candy[i-1] + candy[i] - x;
           candy[i] -= candy[i-1] + candy[i] - x;
       }
   }
   cout << ans << endl;
   return 0;
}


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

ll Ep(int x, int y){
  if(y == 1) return x;
  ll r = Ep(x,y/2);
  if(y%2 == 1) return r *r%MOD *x%MOD;
  else return r *r%MOD;
}

int main(){
  int n, x;
  cin >> n;
  cin >> x;
  if(x != 0){
    cout << 0 << endl;
    return 0;
  }
  map<int, int> mp;
  for(int i=1; i<n; ++i){
    cin >> x;
    if(x == 0){
      cout << 0 << endl;
      return 0;
    }
    ++mp[x];
  }
  ll ans = 1;
  for(auto p: mp){
    if(p.first == 1) continue;
    ans *= Ep(mp[p.first-1], p.second);
    ans %= MOD;
  }
  cout << ans << endl;
}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  long long D[100000],num[100000];
  int judge=0;
  for(int i=0;i<N;i++){
   cin>>D[i];
   num[i]=0;
  }
  if(D[0]==0){
  sort(D,D+N);
  for(int i=0;i<N;i++){
    if(judge==D[i]) judge++;
    num[D[i]]++;
  }
  if(judge!=D[N-1]+1||num[0]>1) cout<<0<<endl;
  else{
    long long answer=1;
    for(int i=1;i<judge;i++){
      for(int j=0;j<num[i];j++) answer=(answer*num[i-1])%998244353;
    }
    cout<<answer<<endl;
  }
  }
  else cout<<0<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
const ll MAX = 8;

string S[MAX];
ll x[8] = {1, 1, 1, 0, -1, -1, -1, 0};
ll y[8] = {1, 0, -1, -1, -1, 0, 1, 1};

bool dfs() {
    vector<vector<bool>> U(MAX, vector<bool>(MAX, true));
    ll cnt = 0;
    REP(h, MAX) {
        REP(w, MAX) {
            if (S[h][w] == '.')
                continue;
            cnt++;
            REP(i, 8) {
                ll mul = 0;
                while (true) {
                    ll nx = x[i] * mul + h, ny = y[i] * mul + w;
                    if (nx < 0 || ny < 0 || nx >= MAX || ny >= MAX)
                        break;
                    U[nx][ny] = false;
                    mul++;
                }
            }
        }
    }

    if (cnt == 8) {
        REP(h, MAX) {
            cout << S[h] << endl;
        }
        return true;
    }

    REP(h, MAX) {
        REP(w, MAX) {
            if (!U[h][w])
                continue;
            S[h][w] = 'Q';
            if (dfs())
                return true;
            S[h][w] = '.';
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, MAX) {
        string s = "";
        REP(j, MAX) {
            s.push_back('.');
        }
        S[i] = s;
    }
    ll N;
    cin >> N;
    REP(i, N) {
        pll p;
        cin >> p.first >> p.second;
        S[p.first][p.second] = 'Q';
    }

    dfs();

    return 0;
}

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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
pii p[100005];
int x[100005], y[100005];
int r[100005];
int root(int a){
    return r[a] == a?a:(r[a]=root(r[a]));
}
void merge(int a, int b){
    a = root(a), b = root(b);
    if(a != b) r[a] = b;
}
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &x[i], &y[i]);
        p[i] = pii(x[i], i);
        r[i] = i;
    }
    sort(p+1, p+1+n);
    vector<pipii> edges;
    for(int i=2;i<=n;i++) edges.eb(pipii(p[i].fi-p[i-1].fi, pii(p[i].se, p[i-1].se)));
    sort(all(edges));
    for(int i=1;i<=n;i++) p[i] = pii(y[i], i);
    sort(p+1, p+1+n);
    for(int i=2;i<=n;i++) edges.eb(pipii(p[i].fi-p[i-1].fi, pii(p[i].se, p[i-1].se)));
    sort(all(edges));
    int ans = 0;
    for(int i=0;i<sz(edges);i++){
        if(root(edges[i].se.fi) != root(edges[i].se.se)){
            merge(edges[i].se.fi, edges[i].se.se);
            ans += edges[i].fi;
        }
    }
    printf("%d\n", ans);
}


#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

struct Dice {
	Dice() {}
	~Dice() {}

	void get() {
		for (int i = 0; i < 6; i++) {
			cin >> d[i];
		}
	}
	void roll(char c) {
		int t = d[0];
		switch (c) {
		case 'N':
			d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = t;
			break;
		case 'S':
			d[0] = d[4]; d[4] = d[5]; d[5] = d[1]; d[1] = t;
			break;
		case 'W':
			d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = t;
			break;
		case 'E':
			d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = t;
			break;
		default:
			break;
		}
	}
	int top() { return d[0]; }
	int d[6];
};

int main() {
	Dice d;
	d.get();
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		d.roll(s[i]);
	}
	cout << d.top() << endl;
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int er=0;
  int ans=s.size();
  rep(i,s.size()){
    if(s[i]=='S') er++;
    if(s[i]=='T' && er!=0){
      er--; ans-=2;
    }
  }
  cout<<ans<<endl;
}


#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    string s, t; cin >> s >> t;
    rev(i, N+1) {
        rep(j, i) {
            if (s.at(N - i + j) != t.at(j))break;
            if (j == i-1) {
                cout << N *2-i << endl;
                return 0;
            }
        }
    }
    cout << N * 2 << 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);
}

int solve() {
  int a, b, c; scanf("%d%d%d", &a, &b, &c);
  int h[10] = {};
  ++h[a]; ++h[b]; ++h[c];
  for (int i = 1; i < 10; ++i) if (h[i] == 2) return !printf("Yes");
  return !printf("No");
}

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


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

  int p[n];
  rep(i,n) cin >> p[i];

  int min = 1e9;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(p[i] <= min){
      min = p[i];
      ans++;
    }
  }

  cout << ans << endl;

}

    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>

    using namespace std;
    using namespace __gnu_pbds;

    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>

    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)

    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;

    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;

/*.....................................................................................................................*/

    const ll mod=(ll)1e9+ 7;

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

    long long binpow(long long x, long long p)
    {
        if (p == 0) {return 1;}
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}

    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)2e6+2 ,  inf   =   1e18;

/*......................................................................................................................*/

signed main()
{
    fast;
    int n,ans=0;
    cin>>n;
    vector<long double>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    map<pair<int,int>,int>cnt;
    for(int i=0;i<n;i++)
    {
        long double y=a[i];
        y*=1000000000;
        ll x=round(y);
        pair<int,int>p;
        while(x%2==0)
        {
            x/=2;
            p.first++;
        }
        while(x%5==0)
        {
            x/=5;
            p.second++;
        }
        cnt[p]++;
    }
    for(auto x:cnt)
    {
        for(auto y:cnt)
        {
            if((x.first.first+y.first.first>=18))
            {
                if(x.first.second+y.first.second>=18)
                {
                    if(x<y)
                    {
                        ans+=(x.second*y.second);
                    }
                    else if(x==y)
                    {
                        ans+=(x.second*(x.second-1))/2;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=1000005;
const int mod=998244353;
int fac[maxn],facinv[maxn];
inline int powmod(int a,int b){
	int res=1;for(;b;b>>=1){
		if(b&1)res=1ll*res*a%mod;a=1ll*a*a%mod;
	}return res;
}
inline int C(int n,int m){
	if(n<0||m<0||n<m)return 0;
	return 1ll*fac[n]*facinv[m]%mod*facinv[n-m]%mod;
}
inline void prprpr(){
	fac[0]=1;
	rep(i,1,1000000)fac[i]=1ll*fac[i-1]*i%mod;
	facinv[1000000]=powmod(fac[1000000],mod-2);
	per(i,999999,0)facinv[i]=1ll*facinv[i+1]*(i+1)%mod;
}
int n,m;
int main(){
	read(n);read(m);prprpr();
	if(n<m)swap(n,m);//cout<<facinv[1000000]<<endl;
	int ans=n;//cout<<C(2,1)<<endl;
	int d=powmod(C(n+m,n),mod-2);
	rep(i,1,m){
		ans=(ans+1ll*C(2*i-1,i)*C(n+m-2*i,n-i)%mod*d%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

long long mod = 1000000007;

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

    long long sum = 0;
    long long acc = 0;
    for (int i = 0; i < n; ++i) {
        sum = (sum + (a[i] * acc)) % mod;
        /* acc += (a[i] % mod); */
        acc = (acc + a[i]) % mod;
    }
    cout << sum % mod << "\n";
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, a, b, count = 0, pointX = 0, pointY = 0;
	cin >> n;
	do {
		cin >> a >> b;
		if (a > b) {
			pointX += (a + b);
		}
		else if (a < b) {
			pointY += (a + b);
		}
		else {
			pointX += a;
			pointY += b;
		}
		count++;
		if (count == n) {
			cout << pointX << " " << pointY << endl;
			pointX = pointY = count = 0;
			cin >> n;
		}
	} while (n != 0);
	return 0;
}


//Radhe Radhe
#include<bits/stdc++.h>//157B
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll i,j,n;
    cin>>n;
   // ll a[n];
    ll x,cnt=0,sum=0,mini=INT_MAX;
    for(i=0; i<n; i++){
        cin>>x;
        if(x<0) cnt++;
        mini=min(mini,abs(x));
        sum+=abs(x);
    }
    if(cnt%2)
    sum-=(2*mini);
    cout<<sum<<endl;
    return 0;
}

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

int N = 0, M = 0;
int points[1001];
int scores[1002001];

bool check(int a, int c){
    if(a >= (N + 2) * (N + 1) / 2 - 1){
        return true;
    }
    return (scores[a] <= c && scores[a + 1] > c);
}

int search2(int a, int b, int c){
    int pib = a + b - b / 2;
    if(check(pib, c)){
        return pib;
    }else if(scores[pib] < c){
        return search2(pib, b / 2, c);
    }else{
        return search2(a, b / 2, c);
    }
}

int main(){
    for(;;){
        for(int i = 0; i < 1001; i++){
            points[i] = 0;
        }
        for(int i = 0; i < 1002001; i++){
            scores[i] = 0;
        }
        if(cin >> N){
            if(N == 0){
                break;
            }
            cin >> M;
            for(int i = 1; i <= N; i++){
                cin >> points[i];
            }
            for(int i = 0; i <= N; i++){
                for(int j = i; j <= N; j++){
                    scores[(2 * N - i + 1) * i / 2 + j] = points[i] + points[j];
                }
            }
            int mxsco = 0;
            sort(scores, scores + ((N + 2) * (N + 1)) / 2);
            for(int i = 0; i < (N + 2) * (N + 1) / 2; i++){
                if(scores[i] > M){
                    break;
                }
                int nosco = scores[i] + scores[search2(0, (N + 2) * (N + 1) / 2, M - scores[i])];
                if(nosco >= mxsco &&  nosco <= M){
                    mxsco = nosco;
                }
            }
            cout << mxsco << endl;
        }else{
            break;
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n, m;
  while((n = getInt()) + (m = getInt())){
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = getInt();
    sort(v.rbegin(), v.rend());
    REP(i,n) if(i % m != (m - 1))
      ans += v[i];
    print(ans);
  }
  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n, m;
	while(cin >> n >> m && n)
	{
		vint p(n);
		rep(i, n)
			cin >> p[i];

		sort(ALL(p));

		int res = accumulate(ALL(p), 0);
		rep(i, n)
			res -= ((i + 1) % m== 0) * p[n - i - 1];

		cout << res << endl;
	}
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

// edit
int N;
vector<ll> A;

vector<vector<ll>> dp;
vector<vector<bool>> vis;

ll dfs(int n, int c) {
    if (vis[n][c]) return dp[n][c];
    if (n == 0) {
        if (c <= 1) {
            return 0;
        } else {
            return -LINF;
        }
    }
    if (n == 1) {
        if (c == 0) {
            return A[0];
        } else if (c <= 2) {
            return 0;
        } else {
            return -LINF;
        }
    }

    vis[n][c] = true;

    ll &ret = dp[n][c];
    ret = dfs(n - 2, c) + A[n - 1];
    if (c >= 1) {
        chmax(ret, dfs(n - 1, c - 1));
    }

    return ret;
}

void solve() {
    cin >> N;
    A.resize(N);
    REP(i, N) cin >> A[i];

    dp.resize(N + 1, vector<ll>(3));
    vis.resize(N + 1, vector<bool>(3));

    ll ans = dfs(N, 1 + (N + 0) % 2);
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

  array<vector<int>, 26> p;
  for (int i = 0; i < s.size(); ++i) {
    p[s[i] - 'a'].push_back(i);
  }

  int l = -1, r = -1;
  for (int i = 0; i < p.size() && l < 0; ++i) {
    for (int j = 1; j < p[i].size() && l < 0; ++j) {
      if (p[i][j] - p[i][j - 1] <= 2) {
        l = p[i][j - 1] + 1;
        r = p[i][j] + 1;
      }
    }
  }

  cout << l << ' ' << r << '\n';
  return 0;
}


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

using namespace std;

int main() {
	int n, k;
	while (cin >> n >> k, n + k) {
		vector<int> card(n);
		for (int i = 0; i < n; ++i) cin >> card[i];
		sort(card.begin(), card.end());
		set<int> cnt;
		do {
			int tmp = 0;
			for (int i = 0; i < k; ++i)
				tmp = tmp * (card[i] >= 10 ? 100 : 10) + card[i];
			cnt.insert(tmp);
		} while (next_permutation(card.begin(), card.end()));
		cout << cnt.size() << endl;
	}

	return 0;
}

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

int f(int n){
	if(n==0) return 1;
	else return 10*f(n-1);
}

int main(){

	int n,k;
	while(1){

		cin >> n >> k;
		if(n==0 && k==0) break;

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

		if(k==2){
			vector<int>u;
			rep(i,n){
				rep(j,n){
				  if(i!=j){
					  vector<int>v;
					  if(card[i]/10!=0) v.push_back(card[i]/10);
					                    v.push_back(card[i]%10);
					  if(card[j]/10!=0) v.push_back(card[j]/10);
										v.push_back(card[j]%10);

					  int s=v.size(); int p=0;
					  rep(i,s) p+=v[i]*f(s-1-i);
					  u.push_back(p);
					  v.clear();
				   }
				}
			}

			sort(u.begin(),u.end());
			vector<int>::iterator it=unique(u.begin(),u.end());
			u.erase(it,u.end());

			cout << u.size() << endl;

			u.clear();
		}

		if(k==3){
			vector<int>u;
			rep(i,n){
				rep(j,n){
					rep(k,n){
				  if(i!=j && i!=k && j!=k){
					  vector<int>v;
					  if(card[i]/10!=0) v.push_back(card[i]/10);
					                    v.push_back(card[i]%10);
					  if(card[j]/10!=0) v.push_back(card[j]/10);
										v.push_back(card[j]%10);
					  if(card[k]/10!=0) v.push_back(card[k]/10);
										v.push_back(card[k]%10);

					  int s=v.size(); int p=0;
					  rep(i,s) p+=v[i]*f(s-1-i);
					  u.push_back(p);
					  v.clear();
				   }
				}
			}
		}
			sort(u.begin(),u.end());
			vector<int>::iterator it=unique(u.begin(),u.end());
			u.erase(it,u.end());

			cout << u.size() << endl;

			u.clear();
		}

		if(k==4){
			vector<int>u;
			rep(i,n){
				rep(j,n){
					rep(k,n){
						rep(l,n){
				  if(i!=j && i!=k && i!=l && j!=k && j!=l && k!=l){
					  vector<int>v;
					  if(card[i]/10!=0) v.push_back(card[i]/10);
					                    v.push_back(card[i]%10);
					  if(card[j]/10!=0) v.push_back(card[j]/10);
										v.push_back(card[j]%10);
					  if(card[k]/10!=0) v.push_back(card[k]/10);
										v.push_back(card[k]%10);
					  if(card[l]/10!=0) v.push_back(card[l]/10);
										v.push_back(card[l]%10);

					  int s=v.size(); int p=0;
					  rep(i,s) p+=v[i]*f(s-1-i);
					  u.push_back(p);
					  v.clear();
				   }
				}
			}
		}
	}
			sort(u.begin(),u.end());
			vector<int>::iterator it=unique(u.begin(),u.end());
			u.erase(it,u.end());

			cout << u.size() << endl;

			u.clear();
		}

	}

	return 0;
}


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

int main() {
	int n;
	while (cin >> n, n) {
		int g[10];
		memset(g, 0, sizeof(g));
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			g[x]++;
		}
		for (int i = 0; i < 10; i++) {
			if (g[i] == 0) cout << '-' << endl;
			else {
				cout << string(g[i], '*') << endl;
			}
		}
	}
	return 0;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, string> pds;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

bool cmp(pds a, pds b) {
	return (a.first == b.first) ? (a.second < b.second) : (a.first > b.first);
}

int main() {
	for (int N; cin >> N&&N;) {
		vector<pds> p;
		for (int i = 0; i < N; i++) {
			string L; int P, A, B, C, D, E, F, S, M;
			cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			int Q = (S*F)*M;
			double cp = (double)(Q - P) / (A + B + C + (D + E)*M);
			p.push_back(pds(cp, L));
		}
		sort(p.begin(), p.end(), cmp);
		for (int i = 0; i < p.size(); i++) {
			cout << p[i].second /*<< " " << p[i].first*/ << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
const int N = 2e5+5,mod = 1e9+7;
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
int n,m,k,ans,fac[N],ifac[N];
it C(int n,int m){return mul(mul(ifac[n-m],ifac[m]),fac[n]);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m),read(k),fac[0]=1;
	for(ri i=1;i<=n*m;++i) fac[i]=mul(fac[i-1],i);
	ifac[n*m]=qpow(fac[n*m],mod-2,mod);
	for(ri i=n*m-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	for(ri i=1;i<=n-1;++i) inc(ans,mul(mul(mul(m,m),n-i),i));
	for(ri i=1;i<=m-1;++i) inc(ans,mul(mul(mul(n,n),m-i),i));
	print(mul(ans,C(n*m-2,k-2)));
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int mod=1e9+7;
int inv[200005],finv[200005],f[200005];
void C(){
	f[0]=1;finv[0]=1;finv[1]=1;f[1]=1;inv[1]=1;
	FOR(i,2,200000){
		f[i]=f[i-1]*i%mod;
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m,k;
	cin>>n>>m>>k;
	C();
	int sum,ans=0,t=n*m;
	FOR(i,1,n){
		FOR(j,1,m){
			sum=0;
			int t1=i-1,t2=j-1;
			sum=sum+t1*(t1+1)/2%mod*m+t2*(t2+1)/2%mod*n;sum=sum%mod;
			t1=n-t1-1;t2=m-t2-1;
			sum=sum+t1*(t1+1)/2%mod*m+t2*(t2+1)/2%mod*n;sum=sum%mod;
			sum=sum*inv[t-1]%mod*f[t-1]%mod*finv[t-k]%mod*finv[k-2]%mod;
			ans=(ans+sum)%mod;
		}
	}
	cout<<ans*inv[2]%mod;
	RE 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll D, G;
  cin >> D >> G;
  G /= 100;

  ll max_p = 300000;
  vll dp(max_p, INF);
  dp[0] = 0;
  rep(i, D + 1) {
    if (i == 0) continue;
    ll p, c;
    cin >> p >> c;
    c /= 100;

    vll next = dp;
    rep(j, p + 1) {
      if (p == 0) continue;
      rep(k, max_p) {
        ll ni = k + i * j;
        if (ni >= max_p) continue;
        if (j == p) ni += c;
        next[ni] = min(next[ni], dp[k] + j);
      }
    }
    dp = next;
  }

  ll ans = INF;
  rep2(i, G, max_p) {
    ans = min(ans, dp[i]);
  }
  ANS;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int p[11];
int c[11];

int main() {
	int d, g;
	cin >> d >> g;
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int i = 0; i < (1 << d); i++) {
		int tmp = 0;
		long sum = 0;
		for (int j = 0; j < d; j++) {
			if (i & (1 << j)) {
				tmp += p[j];
				sum += 100 * (j + 1) * p[j] + c[j];
			}
		}
		for (int j = d - 1; j >= 0 && sum < g; j--) {
			if (!(i & (1 << j))) {
				for (int l = 1; l <= p[j] && sum < g; l++) {
					tmp++;
					sum += 100 * (j + 1);
				}
			}
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF=1LL << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> dan(35,0);
    vector<int> dp(35,0);
    int N;
    for(int i=0;i<35;i++){
        int tmp;
        cin>>tmp;
        if(tmp==0){
            N=i;
            break;
        }
        dan[i]=tmp;
    }
    dp[0]=1;
    for(int i=1;i<31;i++){
        dp[i]+=dp[i-1];
        if(i>1)dp[i]+=dp[i-2];
        if(i>2)dp[i]+=dp[i-3];
    }
    for(int i=0;i<N;i++){
        int tmp=dp[dan[i]]/3650;
        if(dp[dan[i]]%3650!=0) tmp++;
        cout << tmp <<endl;
    }

    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int a[31]={1,1,2};
  int n;
  loop(i,3,31)a[i]=a[i-1]+a[i-2]+a[i-3];
  while(cin>>n,n)cout<<(a[n]-1)/365/10+1<<endl;

}


#include <iostream>
using namespace std;
int main(){
    int n;
    while (cin >> n){
        if(n==0)
            break;
        int x,y;
        int a=0;
        int b=0;
        for(int i=0;i<n;i++){
            cin >> x >> y;
            if(x>y)
                a+=x+y;
            if(x<y)
                b+=x+y;
            if(x==y){
                a+=x;
                b+=y;
            }
        }
        cout << a << " " << b << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
 	bool ac[100010]={};
	ll wa[100010]={};
int main() {
	ll n,k;
	cin>>n>>k;

	for(ll i=0;i<k;i++){
		ll x;string s;
		cin>>x>>s;x--;
		if(s=="AC"){
			ac[x]=true;
		}
		else{
			if(ac[x]!=true){
				wa[x]++;
			}
		}
	}
		ll cnt1=0;
		ll cnt2=0;
		for(ll i=0;i<n;i++){
			if(ac[i]){
				cnt1++;
				cnt2+=wa[i];
			}
		}
		cout << cnt1<<" "<<cnt2;
	// your code goes here
	return 0;
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#define rep(i,n) for (int i = 0; i < n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define per1(i,n) for (int i = n; i >= 1; --i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
// if(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W)
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

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

    ll n,m,v,p; cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    // debug(a);

    int lo = -1, hi = n - 1;
    while(hi - lo > 1) {
        int mid = (lo + hi) / 2;
        vector<ll> b;
        rep(i, n) {
            if(i != mid) {
                b.push_back(a[i]);
            }
        }
        reverse(all(b));

        ll base = a[mid] + m;
        ll ok = 0;

        bool ng = 0;
        rep(i, b.size()) {
            if(i < p - 1) ok += m;
            else if(base >= b[i]) ok += min(m, base - b[i]);
            else ng = 1;
        }

        // debug(mid, base, ok, b);

        if(ng || ok < (m * (v - 1))) {
            lo = mid;
        } else {
            hi = mid;
        }
    }

    cout << n - hi << endl;
}

/**
*    author:  souzai32
*    created: 12.08.2020 23:03:31
**/

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

int main() {

    int n;
    cin >> n;
    int a=(n+1)/2,b=n/2;
    vector<int> v(n),o(a),e(b);
    rep(i,n) cin >> v.at(i);
    rep(i,a) o.at(i)=v.at(2*i);
    rep(i,b) e.at(i)=v.at(2*i+1);

    // rep(i,a) cout << o.at(i) << endl;
    // rep(i,b) cout << e.at(i) << endl;

    sort(o.begin(),o.end());
    sort(e.begin(),e.end());

    int count=1;
    int on,en,co1=0,co2=0,ce1=0,ce2=0;

    rep(i,a){
        if(i==0) continue;
        else if(o.at(i)==o.at(i-1)) count++;
        else if(o.at(i)!=o.at(i-1)){
            if(count>=co1){
                co2=co1;
                co1=count;
                on=o.at(i-1);
            }
            else if(count>=co2){
                co2=count;
            }
            count=1;
        }
        if(i==a-1){
            if(count>=co1){
                co2=co1;
                co1=count;
                on=o.at(i);
            }
            else if(count>=co2){
                co2=count;
            }
            count=1;
        }
    }
    rep(i,b){
        if(i==0) continue;
        else if(e.at(i)==e.at(i-1)) count++;
        else if(e.at(i)!=e.at(i-1)){
            if(count>=ce1){
                ce2=ce1;
                ce1=count;
                en=e.at(i-1);
            }
            else if(count>=ce2){
                ce2=count;
            }
            count=1;
        }
        if(i==b-1){
            if(count>=ce1){
                ce2=ce1;
                ce1=count;
                en=e.at(i);
            }
            else if(count>=ce2){
                ce2=count;
            }
            count=1;
        }
    }

    int ans;
    if(on==en) ans=min(n-ce1-co2,n-co1-ce2);
    else ans=n-ce1-co1;

    // cout << co1 << ' ' << co2 << ' ' << ce1 << ' ' << ce2 << endl;
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

vector<int> Z_algorithm(vector<ll> S) {
	int c = 0, n = S.size();
	vector<int> Z(n, 0);
	for (int i = 1; i < n; i++) {
		int l = i - c;
		if (i + Z[l] < c + Z[c]) {
			Z[i] = Z[l];
		} else {
			int j = max(0, c + Z[c] - i);
			while (i + j < n && S[j] == S[i + j])j++;
			Z[i] = j;
			c = i;
		}
	}
	Z[0] = n;
	return Z;
}

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

  vector<ll> axor(n),bxor(n);
  rep(i,n){ axor[i]=a[i]^a[i+1]; } axor[n-1]=a[n-1]^a[0];
  rep(i,n){ bxor[i]=b[i]^b[i+1]; } bxor[n-1]=b[n-1]^b[0];
  auto tmp = bxor;
  rep(j,2)rep(i,n) tmp.emplace_back(axor[i]);

  vector<pair<int,ll>> kx;
  auto res = Z_algorithm(tmp);
  for(int i=n; i<n*2; i++)if(res[i]>=n){
    kx.push_back({i-n,b[0]^a[i-n]});
  }

  sort(kx.begin(),kx.end());
  for(auto ans:kx){
    cout << ans.F << " " << ans.S << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <set>
# include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n; cin>>n;
    vector<ll> v(n);
    REP(i,n)cin>>v[i];
    sort(ALL(v));
    vector<ll> sides;
    vector<ll> list;
    map<ll,ll> mp;
    REP(i,n){
        ll a=v[i];
        if(mp.find(a)!=mp.end()){
            mp.at(a)++;
            list.push_back(a);
        }else{
            mp.insert(make_pair(a,1));
        }
    }
    REP(i,SIZE(list)){
        ll s=list[i];
        while(mp.at(s)/=2){
            sides.push_back(s);
        }
    }
    ll ans;
    if(SIZE(sides)<2){
        ans=0;
    }else{
        sort(ALL(sides),greater<>());
        ans=sides[0]*sides[1];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	char judge='a';
	int numa=a.size();
	int numb=b.size();
	int numc=c.size();
	bool fin=true;
	while(fin){
		if(judge=='a'){
			if(numa==0){
				fin=false;
			}
			if(numa>0){
				judge=a.at(a.size()-numa);
				numa--;
			}
		}
		if(judge=='b'){
			if(numb==0) fin=false;
			if(numb>0){
				judge=b.at(b.size()-numb);
				numb--;
			}
		}
		if(judge=='c'){
			if(numc==0) fin=false;
			if(numc>0){
				judge=c.at(c.size()-numc);
				numc--;
			}
		}
	}
	if(judge=='a') cout << "A" << endl;
	if(judge=='b') cout << "B" << endl;
	if(judge=='c') cout << "C" << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

queue<char>q[3];

void scan(int n)
{
	char c;
	while((c=getchar() )!='\n')
		{
			q[n].push(c);
		}
}
int main()
{
    fast;

    scan(0);
    scan(1);
    scan(2);

	ll k=0;
	while(!q[k].empty())
	{
		char c=q[k].front();
		q[k].pop();

		k=c-'a';
	}

  cout<<char(k +'A');

}


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

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

    string s;
    cin>>s;

    string ans;
    for (char c: s)
        if (c == 'S')   ans += c;
        else if (ans.size() && ans.back() =='S')    ans.pop_back();
        else ans += c;
    cout<<ans.size()<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a)
#define DEBUG(x)
#define DEBUGS(v)
#endif
/* clang-format on */

int main() {
  string x;
  ll ans = 0;
  cin >> x;
  ll s = 0, t = 0;
  REP(i, x.size()) {
    if (x[i] == 'S')
      s++;
    else if (s > 0)
      s--;
    else
      ans++;
  }
  ans += s;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
//#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  101LL
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,flag=0;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    string s;
    cin >> s;
    if(s=="SUN") cout << 7;
    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=="SAT") cout << 1;
    }
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,true,sizeof(P));
    //P[0] = false;
    //P[1]= false;
    for(int i=1;i<=n;i++) P[i] = i;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(P[j]==j)
                    P[j]=i;
            }
        }
    }

}

#include<stdio.h>
#include<stdlib.h>
#define ll long long

const int Inf=1e9+10;
ll jiu[19];

int gi(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9' && ch>='0'){sum=sum*10+ch-'0';ch=getchar();}
	return sum*f;
}

int d;
ll ans;

ll sm[20];

void dfs(int i,int n,ll N,ll revN,ll cif){
	if(i>n){
		if(revN-N==d){
			ans++;
		}
		return;
	}
	ll maxd=revN*sm[n-i+1]+1-N-sm[n-i+1];
	ll mind=revN*sm[n-i+1]+jiu[n-i+1]-(jiu[n-i+1]*sm[i-1]+N);
	if(N && revN-N+maxd<d)return;
	if(N && revN-N+mind>d)return;
	for(int j=9;j>=(i==n)?1:0;j--)
		dfs(i+1,n,N+j*cif,revN*10+j,cif*10);
}

int main(){
	int i,j,k,n,m;
	scanf("%d",&d);
	if(d%9){
		puts("0");
		return 0;
	}
	d/=9;
	ll len=1,ini=0;
	for(i=1;i<=18;i++)
		sm[i]=sm[i-1]*10;
	for(i=1;i<=17;i++){
		ll tmp=1,D=d;
		ini=ini*10+1;
		ll base=ini,lten=len,rten=1;
		for(int j=0;j<=(i>>1);j++){
			tmp*=10-abs(D%(rten*10)/rten)-(!j?1:0);
			D-=base*(D%(rten*10)/rten);
			base-=lten+rten;
			lten/=10;
			rten*=10;
		}
		len*=10;
		if(!D)ans+=tmp;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

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

	string s;
	cin >> s;
	if(s.length() == 2) {
		if(s[0] == s[1]) cout << "1 2" << endl;
		else cout << "-1 -1" << endl;
		return 0;
	} else {
		for(int i = 0; i < s.length() - 2; i++) {
			if(s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
				cout << i + 1 << " " << i + 3 << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define data_type int
#define endl "\n"

int  main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    data_type x1=-2,y1=-2,n;
    bool check=0;
    string str;
    cin>>str;
    n=str.size();
    for(int i=0; i<n-1; i++)
        {
            if(str[i]==str[i+1])
                {
                    x1=i,y1=i+1;
                    check=1;
                    break;
                }

        }

    if(!check)
        {
            for(int i=1; i<n-1; i++)
                {
                    if(str[i-1]==str[i+1])
                        {
                            x1=i-1,y1=i+1;
                            check=1;
                            break;
                        }

                }
        }

    cout<<x1+1<<" "<<y1+1<<endl;

    return 0;
}


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

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

  rep(i, h - 1) rep(j, w) {
    if (a[i][j] % 2 == 1) {
      ans.push_back({i + 1, j + 1, i + 2, j + 1});
      // cout << i + 1 << " " << j + 1 << " " << i + 2 << " " << j + 1 << endl;
      a[i][j]--;
      a[i + 1][j]++;
    }
  }
  rep(i, w - 1) {
    if (a[h - 1][i] % 2 == 1) {
      ans.push_back({h, i + 1, h, i + 2});
      // cout << h - 1 << " " << i + 1 << " " << h - 1 << " " << i + 2 << endl;
      a[h - 1][i]--;
      a[h - 1][i + 1]++;
    }
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) rep(j, 4) printf("%d%c", ans[i][j], (j == 3 ? '\n' : ' '));
  // rep(i, h) rep(j, w)
  //     fprintf(stderr, "%d%c", a[i][j], (j == w - 1 ? '\n' : ' '));
  return 0;
}


#include <bits/stdc++.h>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    string s;
    cin >> s;
    cout << "2018" + s.substr(4) << endl;
}
int main(void)
{
    solve();
}

#include <stdio.h>

int main (){
	int year, month, day;
	scanf ("%d/%d/%d", &year, &month, &day);
	year = 2018;
	printf ("%d/%02d/%02d\n", year, month, day);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   map<int,int> M;
   vector<int> A(N);
   for (int i = 0; i < N; i++)
   {
      cin >> A[i];
      M[A[i]]++;
   }
   sort(A.begin(),A.end());
   A.erase(unique(A.begin(),A.end()),A.end());
   int size = A.size();
   int ind = size-1;
   long long ans=0;
   for(long long offset = (1LL<<31); offset > 1; offset /=2){
      while(ind>=0&&A[ind]*2>=offset){
         int cur = A[ind];
         int partner = offset-A[ind];
         if(cur == partner){
            int pair= M[cur]/2;
            ans += pair;
            M[cur]-= pair*2;
         }
         else{
            int pair= min(M[cur],M[partner]);
            ans += pair;
            M[cur]-=pair;
            M[partner]-=pair;
         }
         ind--;
      }
   }
   cout << ans << endl;
   return 0;
}


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

// Eratosthenes
vector<int> eratTable;

vector<ll> eratosthenes(ll n) {
    eratTable.assign(n + 1, 1);
    eratTable[0] = 0;
    eratTable[1] = 0;
    for (ll i = 2; i <= n; i++) {
        if (eratTable[i] == 1) {
            for (ll j = 2; i * j <= n; j++) {
                eratTable[i * j] = 0;
            }
        }
    }

    vector<ll> primes;
    rep(i, eratTable.size()) {
        if (eratTable[i] >= 1) {
            primes.push_back(i);
        }
    }

    return primes;
}

bool check(const vector<ll>& a) {
    for (ll i = 0; i < a.size() - 4; i++) {
        for (ll j = i + 1; j < a.size() - 3; j++) {
            for (ll k = j + 1; k < a.size() - 2; k++) {
                for (ll l = k + 1; l < a.size() - 1; l++) {
                    for (ll m = l + 1; m < a.size(); m++) {
                        ll v = a[i] + a[j] + a[k] + a[l] + a[m];
                        // 1なら素数
                        if (eratTable[v] == 1) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}

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

    vector<ll> res;

    auto primes = eratosthenes(55555);

    rep (i, primes.size()) {
        if (primes[i] % 5 == 1) {
            res.push_back(primes[i]);
        }
    }

    rep(i, n) cout << res[i] << (i == n - 1 ? "" : " ");
    cout << endl;
}

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

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

bool isplime(int p){
	if(p==1) return false;
	for(int i=2;i<p;i++) {
		if(p%i==0) return false;
	}
	return true;
}

int main() {
	int n; cin >> n;
	for(int i=31;i<=55555;i+=30) {
		if(isplime(i)) {
			if(i!=31) cout << " ";
			cout << i;
			n--;
		}
		if(n==0) break;
	}
	cout << endl;
}


//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){

    int A,B,C,D;

    cin>>A>>B>>C>>D;

    int AB=A+B;
    int CD=C+D;

    if(AB>CD) cout<<"Left"<<endl;
    else if(AB<CD) cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
}

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

int main()
{
   int a,b,c;
   int min,max=0;
   cin>>a>>b>>c;

   if(a<=b)
   {
       min = a;
       max = b;
   }

   else
   {
     min = b;
     max = a;

   }

   if(c>min && c<max)
   cout<<"Yes"<<endl;

   else
   {
     cout<<"No"<<endl;
   }

   return 0;

}


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

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

  int pow;
  int limit = N;

  for (int i = 0; i < N; i++){
    pow = 1;

    for (int j = 0; j < i; j++){
      pow *= 2;
    }

    if (K < pow){
      limit = i;
      break;
    }
  }

  int total = 1;

  for (int i = 0; i < limit; i++){
    total *= 2;
  }

  for (int i = 0; i < N - limit; i++){
    total += K;
  }

  cout << total << endl;
}

#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	int n, k, score = 1;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		if( score < k )
			score += score;
		else
			score += k;
	cout << score;
}


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

ll a[310][310];
bool ok[310];
ll ans = LINF;

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n) rep(j, m) cin >> a[i][j], a[i][j]--;

    rep(i, 310) ok[i] = 1;

    rep(i, m){
        int selected[310] = {};
        rep(j, n){
            rep(k, m){
                if (ok[a[j][k]]) {
                    selected[a[j][k]]++;
                    break;
                }
            }
        }
        ll mx = 0, idx = -1;
        rep(j, m){
            if(selected[j] == 0) continue;
            if(selected[j] > mx){
                mx = selected[j];
                idx = j;
            }
        }
        ans = min(ans, mx);
        ok[idx] = 0;
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  int H,W,i,j,a;scanf("%d%d",&H,&W);
  bool odd[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%d",&a);
      odd[i][j] = a&1;
    }
  }
  bool coin = false;vector<pair<pair<int,int>,pair<int,int>>> v;
  i = 0;j = 0;int ni,nj;
  while(true){
    if((!(i&1)) && j+1 == W){
      ni = i+1;nj = j;
    }
    else if(i&1 && j == 0){
      ni = i+1;nj = j;
    }
    else if(!(i&1)){
      ni = i;nj = j+1;
    }
    else{
      ni = i;nj = j-1;
    }
    if(ni == H) break;
    if(odd[i][j]){
      if(coin == false){
        coin = true;
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
      else{
        coin = false;
      }
    }
    else{
      if(coin == true){
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
    }
    i = ni;j = nj;
  }
  printf("%d\n",v.size());
  for(i=0;i<v.size();i++) printf("%d %d %d %d\n",v[i].first.first+1,v[i].first.second+1,v[i].second.first+1,v[i].second.second+1);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    for(int d; cin >> d; ){
        int ans = 0;
        for(int dd = d; dd <= 600 - d; dd += d)
          ans += d * dd * dd;
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
	int d, ans, n;
	while(cin >> d){
		ans = pow(d, 3);
		n = 600 / d - 1;
		ans *= n*(n+1)*(2*n+1) / 6;
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, a[N];
array <ll, 2> p[N], s[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif

	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int j = 1;
	ll pref = a[1], cur = a[1];
	for (int i = 2; i <= n; i++) {
		pref += a[i];
		while (abs(cur + a[j + 1] - (pref - cur - a[j + 1])) < abs(cur - (pref - cur)))
			cur += a[++j];
		p[i] = {cur, pref - cur};
		if (p[i][0] > p[i][1]) swap(p[i][0], p[i][1]);
	}
	ll suf = a[n];
	cur = a[n], j = n;
	for (int i = n - 1; i >= 1; i--) {
		suf += a[i];
		while (abs(cur + a[j - 1] - (suf - cur - a[j - 1])) < abs(cur - (suf - cur)))
			cur += a[--j];
		s[i] = {cur, suf - cur};
		if (s[i][0] > s[i][1]) swap(s[i][0], s[i][1]);
	}
	ll ans = 1e9 + 123;
	for (int i = 2; i <= n - 2; i++)
		ans = min(ans, max(p[i][1], s[i + 1][1]) - min(p[i][0], s[i + 1][0]));
	cout << ans;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+2, 0);
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    int sum = 0;
    for(int i=0;i<N+1;i++){
        sum += abs(A[i+1] - A[i]);
    }
    for(int i=1;i<N+1;i++){
        auto res = sum;
        res -= abs(A[i+1] - A[i]);
        res -= abs(A[i] - A[i-1]);
        res += abs(A[i+1] - A[i-1]);
        cout << res << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if((a<=c&&c<=b)||(b<=c&&c<=a)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B, ll C) {
  bool pred = (A-C) * (C-B) > 0;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    ll now = 0;
    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0 && m / i >= n) {
            now = max(now, (ll)i);
        }
        if (m % i == 0 && m / (m / i) >= n) {
            now = max(now, (ll)m / i);
        }
    }
    cout << now << endl;
}

#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << (B == 1 ? 0 : (B - 2) / (A - 1) + 1) << '\n';
  return 0;
}


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

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

  if(R >=2800){
    cout << "AGC" << endl ;
  }
  else if(R >=1200 && R < 2800){
    cout << "ARC" << endl ;
  }
  else {
    cout << "ABC" << endl ;
  }
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

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

    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<pair<int,int>> v[100010];
ll dist[100010];
const ll INF=1e10;
vector<set<int>> s(100010);

void dijkstra(){
  priority_queue<pair<ll,int>> PQ;
  //priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
  for(int i=0;i<=100005;i++) dist[i]=INF;
  PQ.push(make_pair(0,1));
  dist[1]=0;

  while(!PQ.empty()){
    pair<ll,int> f=PQ.top();
    PQ.pop();
    int t=f.second;

    if(dist[t]<-f.first) continue;

    for(int i=0;i<v[t].size();i++){
      pair<int,int> u=v[t][i];
      ll c=0;
      if(s[t].count(u.second)==0) c++;

      if(dist[u.first]>dist[t]+c){
        s[u.first].clear();
        s[u.first].insert(u.second);
        dist[u.first]=dist[t]+c;
        PQ.push(make_pair(-dist[u.first],u.first));
      }else if(dist[u.first]==dist[t]+c){
        if(s[u.first].count(u.second)==0){
          s[u.first].insert(u.second);
          //PQ.push(make_pair(dist[u.first],u.first));
        }
        //s[u.first].insert(u.second);
      }
      //cout<<u.first<<" "<<u.second<<" "<<dist[u.first]<<endl;
    }
  }

  return;
}

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

  for(int i=0;i<m;i++){
    int p,q,c;
    scanf("%d %d %d",&p,&q,&c);
    v[p].push_back(make_pair(q,c));
    v[q].push_back(make_pair(p,c));
  }

  dijkstra();

  //for(int i=0;i<n;i++) cout<<i+1<<" "<<dist[i+1]<<endl;

  if(dist[n]==INF) cout<<-1<<endl;
  else cout<<dist[n]<<endl;

  return 0;
}

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

int main(){
  int n, q;
  cin >> n >> q;
  vector<int> A(n);
  copy_n(istream_iterator<int>(cin), n, A.begin());

  atcoder::fenwick_tree<int64_t> fw(n);
  for (int i = 0; i < n; i++)
    fw.add(i, A[i]);
  for (int i = 0; i < q; i++){
  	int a, l, r;
    cin >> a >> l >> r;
    if (a == 0)
      fw.add(l, r);
    else
      cout << fw.sum(l, r) << endl;
  }

}


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

int main(){
  ll n;
  cin >> n;
  string s;
  while(n>0){
    int r = n%26;
    char c;
    if(r>0) c = 'a' + r - 1;
    else c = 'z';
    s += c;
    n /= 26;
    if(r==0) n--;
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
  return 0;
}

#include <stdio.h>

#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long

int main() {
	LL llMax = 1000000000000001, llN;
	scanf("%lld", &llN);
	//a = 97
	int iChar[20], iCnt = 0;
	llN--;
	while (iCnt < 20) {
		iChar[iCnt++] = llN % 26;
		if (llN < 26)
			break;
		llN -= (iChar[iCnt - 1] + 1);
		llN /= 26;
		//printf("%lld\n", llN);
	}
	while (iCnt-- > 0) {
		printf("%c", (char)(iChar[iCnt] + 97));
	}

	return 0;
}


//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int sum=0;double ave=0;
    for(int i=0;i<n;i++)sum+=a[i];
    ave=(double)sum/n;

    double minm=INF;
    int ans=0;
    for(int i=0;i<n;i++){
        if(minm>abs(a[i]-ave)){
            minm=abs(a[i]-ave);
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
    for(int i=0;i<n;i++){
        if(abs(a[i]-ave)==minm){
            cout<<i<<endl;
            return 0;
        }
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

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

int main() {
    set<ll> num;
    ll t = 1;
    while(t<ll(1e9)+5){
        t*=2;
        num.insert(t);
    }
    ll N;
    cin >> N;
    map<ll,ll> mp;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        mp[A[i]]++;
    }
    sort(A.rbegin(),A.rend());
    ll ans =0;
    for(int i=0;i<N;i++){
        if(mp[A[i]] ==0){
            continue;
        }
        ll n = A[i];
        ll t = *num.upper_bound(n);
        t-=n;
        mp[n]--;
        if(mp.find(t) == mp.end()|| mp[t] ==0){
            continue;
        }
        ans++;
        mp[t]--;
    }

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 bool seen[10000][10000];
 char S[10000][10000];
 int dx[4] = {1, -1, 0, 0};
 int dy[4] = {0, 0, 1, -1};
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;

        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));

    }
     if (n != 1)
        {
            res.push_back(make_pair(n, 1));
        }
        return res;

}
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }

    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);

}
int main() {
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);

    for(int i = 0; i < N; i++) cin >> t[i];

    ll ans = 0;

    for(int i = 0; i < N - 1; i++) {
        if(t[i] + T <= t[i + 1]) ans += T;
        else {
            ans += (t[i + 1] - t[i]);
        }
    }
    ans += T;

    cout << ans << endl;

 return 0;
}

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

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

	long long X = 0;
	long long preT = 0;
	cin >> preT;
	for (int i = 0; i < N - 1; ++i) {
		int t; cin >> t;
		if (preT + T < t) {
			X += T;
		}
		else {
			X += (t - preT);
		}

		preT = t;
	}

	cout << X + T << endl;

	return 0;
}


#if 0
2020.03.22

如果已知 A ，考虑 P 会长什么样。
对于一个 A[i] ，划分为若干极大的以左端点为最大值的区间，称为块。
一个显而易见的性质是一个块一定连续出现在 P 中。
进一步可以得到把所有块按左端点升序后拼接起来就能得到 P 。

那么问题就是统计有多少排列 P 能够被划分为若干块，这些块能够构成 A 。
首先块长不能超过 3 ，其次块长为 2 的块数不能超过块长为 1 的块数，
后者保证了这些块能够组成长为 3 的序列 A 。

接着考虑确定了 P 是由什么样的块构成的，统计 P 的方案数。
具体地，设 P 由 k 个块组成，第 i 个块的大小为 b[i] ，b 的前缀和为 s 。
那么满足这个分块方式的 P 有 n!/prod(s) 。

证明：
考虑从左到右确定排列 P 的相对权值，把块的最大值定在块的右端点。
不考虑块限制时第 i 个位置有 i 种选数方案，考虑块限制，事实上块限制只会影响到块的右端点，
这些点在选数时必须选当前最大值，那么用 n! 除掉这些点的位置乘积即可。

于是可以对于分母进行 DP ，设 f[i][j] 表示当前块长和为 i ，块长为 1 与块长为 2 的块数差为 j ，
这种情况下的分母的和，转移枚举最后一个块的大小即可。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 6005;
ll f[maxn][maxn << 1];
ll inv[maxn];

int main () {
	int n = read * 3, mod = read;

	inv[1] = 1;
	for (int i = 2; i <= n; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	f[0][maxn + 0] = 1;
	f[1][maxn + 1] = inv[1];
	f[2][maxn + 2] = inv[2];
	f[2][maxn - 1] = inv[2];
	for (int s = 3; s <= n; s ++)
		for (int i = maxn - s; i <= maxn + s; i ++)
			f[s][i] = (f[s - 1][i - 1] + f[s - 3][i] + f[s - 2][i + 1]) * inv[s] % mod;

	ll ans = 0;
	for (int i = maxn; i <= maxn + n; i ++)
		ans += f[n][i];
	ans %= mod;
	for (int i = 1; i <= n; i ++)
		(ans *= i) %= mod;
	printf("%lld\n", ans);
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n,m;
int mul(int a,int b){
  return a * b % m;
}
void add(int &a,int b){
  a += b;
  if(a >= m)
    a -= m;
}
int po2(int a){
  return (a-2) * (a - 1) % m;
}
// int odw3 = 1;
// int po3(int a){
//   return a * (a - 1) % m * (a - 2) % m * odw3 % m;
// }
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  vector<int> zost(3 * n + 1);
//   while(odw3 % 3 != 0)odw3 += m;
//   odw3 /= 3;
  zost[3*n] = 1;
  int res = 0;
  R(_,n+1){
    debug(zost);
    R(i,SZ(zost))add(res, zost[i]);
    debug(res);
    if(_ == n)break;

    for(int i = 3 * n - 1; i >= 0; i--){
      add(zost[i], zost[i + 1]);
    }

    vector<int> ak(3 * n + 1);
    R(i,SZ(zost)){
      if(i >= 2)add(ak[i - 2], mul(i-1, zost[i]));
      if(i >= 3)add(ak[i - 3], mul(po2(i), zost[i]));
    }
    swap(ak, zost);
  }

  cout << res << "\n";
}