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

int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> a(n+2);
  a[0] = 0;
  a[n+2] = 0;
  rep(i, n) cin >> a[i+1];
  rep(i, n+1) sum += abs(a[i] - a[i+1]);
  rep(i, n){
    cout << sum + abs(a[i] - a[i+2]) - abs(a[i] - a[i+1]) - abs(a[i+1] - a[i+2])<< endl;
  }
}

//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#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>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main() {
	lint n; cin >> n;
	lint ans = 0;
	lint cnt = 0;
	lint minn = INF;
	for (int i = 0; i < n; i++) {
		lint x; cin >> x;
		if (x < 0) cnt++;
		ans += abs(x);
		minn = min(minn, abs(x));
	}
	if (cnt % 2 == 0) printf("%lld\n", ans);
	else printf("%lld\n", ans - minn * 2);

	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 fi first
#define se second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int dp[311][311][311];
string s;

int solve(int l, int r, int k)
{
	if(k<0) return -int(1e9);
	if(l>r) return 0;
	if(dp[l][r][k]>=0) return dp[l][r][k];
	if(l==r) return 1;
	int ans = max(solve(l,r-1,k),solve(l+1,r,k));
	ans=max(ans,solve(l+1,r-1,k-(s[l]!=s[r]))+2);
	return (dp[l][r][k]=ans);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>s; int k; cin>>k;
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,int(s.length())-1,k)<<'\n';
}

#include <bits/stdc++.h>
#define cal(x,y) (x=x>y?x:y)
using namespace std;
const int N=350;
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
int f[N][N][N],n,k;
char s[N];
int main(){
    scanf("%s%d",s+1,&k);
    n=strlen(s+1);
    int ans=0;
    for (int i=1; i<=n; ++i)
	for (int j=n; j>=i; --j)
	    for (int l=k; ~l; --l){
		cal(f[i+1][j][l],f[i][j][l]);
		cal(f[i][j-1][l],f[i][j][l]);
		cal(f[i+1][j-1][l],f[i][j][l]+(s[i]==s[j]));
		if (l) cal(f[i+1][j-1][l-1],f[i][j][l]+1);
	    }
    for (int i=1; i<=n; ++i)
	for (int j=0; j<=k; ++j){
	cal(ans,f[i+1][i-1][j]*2-1);
	cal(ans,f[i+1][i][j]*2);
    }
    cout<<ans;
    return 0;
}


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

const double pi = acos(-1);

pair <double, double> rotate(int x, int y, int degree, double d) {
   double theta = (2 * pi / 360) * degree;
   double x_ = x * cos (theta) - y * sin(theta);
   double y_ = x * sin (theta) + y * cos(theta);
   x_ *= d;
   y_ *= d;
   return {x_, y_};
}

const double eps = 1e-3;

int near(double x) {
   for(int i = (int)(x - 2); i < (int)(x + 2); i++) {
      if(abs(i - x) < eps) {
         return i;
      }
   }
   return 0;
}
void solve() {
   string s;
   int a, b;
   cin >> a >> b >> s;

   bool ok = true;
   ok &= s[a] == '-';
   for(int i = 0; i < s.length(); i++) {
      if(i == a)
         continue;
      else ok &= s[i] >= '0' && s[i] <= '9';
   }
   cout << (ok?"Yes":"No") << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   }
   return 0;
}

#include <stdio.h>
#include <string.h>
int main ()
{
	int A, B;
	scanf ("%d %d", &A, &B);
	getchar ();
	char S[A+B+2] = {};
	scanf ("%s", &S);
	int len = strlen(S);
	int flag = 0;
	for (int i = 0; i < len; i++)
	{
		if (48 <= S[i] && S[i] <= 57)
		{
			continue;
		}
		else if (48 > S[i] || S[i] > 57)
		{
			if ( i == A)
			{
				flag = 1;
				continue;
			}
			else if ( i != A)
			{
				flag = 0;
				break;
			}
		}
	}
	flag ? printf("Yes\n") : printf("No\n");
return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int check(char str);
int counter(int res,char *str);
int main(){
    char str[128]={0};
    while(~scanf("%s",str)){

        /*宣言*/
        int ans = 0,bef = 0;
        int cnt = 1;
        int len = strlen(str);
        int x;
        bool f = false;
        /*宣言終了*/

        reverse(str,str+len);
        rep(i,len){
            x = check(str[i]);
            if(!f){
                bef = x;
                f = true;
                continue;
                cnt++;
            }
            if(bef == x){
                cnt++;
            }
            else if(bef < x){
                ans += cnt*bef;
                cnt = 1;
                bef = x;
            }
            else{
                int coun = counter(i,str);
                ans += (bef*cnt) - (coun*x);
                cnt = 1;
                f = false;
                i += coun-1;
            }
        }
        if(x == bef)ans += cnt*bef;
        printf("%d\n",ans);
    }
	return 0;
}
int check(char str){
    if(str == 'I')return 1;
    if(str == 'V')return 5;
    if(str == 'X')return 10;
    if(str == 'L')return 50;
    if(str == 'C')return 100;
    if(str == 'D')return 500;
    if(str == 'M')return 1000;
}
int counter(int res , char *str){
    int cnt = 1;
    for(int i = res; str[i] != str[res] ; i++){
        cnt++;
    }
    return cnt;
}

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

using namespace std;

int main()
{
	char* ara = "IVXLCDM";
	int num[] = { 1, 5, 10, 50, 100, 500, 1000 };

	char buf[101];
	while (scanf("%s\n", buf) != EOF)
	{
		int len = strlen(buf);
		int n[100];
		for (int i = 0; i < len; ++i)
		{
			for (int j = 0; j < 7; ++j)
			{
				if (buf[i] == ara[j])
				{
					n[i] = num[j];
					break;
				}
			}
		}
		for (int i = 0; i < len-1; ++i)
			n[i] *= n[i] < n[i+1] ? -1 : 1;

		int res = 0;
		for (int i = 0; i < len; ++i)
			res += n[i];

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

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE

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

   #endif

   string str;
   cin>>str;
   set<char> s;
   for(int i=0;i<str.length();i++)
   {
      s.insert(str[i]);
   }
   if(s.size()==26)
    cout<<"None";
  else
  { int i=0;

    for(auto it=s.begin();it!=s.end();it++,i++)
    {

        if(*it!=(97+i))
        {

            cout<<(char)(97+i);
            return 0;
        }
    }
    if(s.size()<26)
    {
        cout<<char(97+s.size());
    }
  }

 return 0;
}

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

char s1[inf],s2[inf];
int q[inf*2],head=inf,tail=inf-1;

int main(){
	int n;
	rd(n)
	scanf("%s%s",&s1,&s2);
	q[++tail]=n+1;
	int pos=n+1,cnt=0,ans=0;
	for (int i=n;i>=1;i--){
		int tmp=pos;
		while (pos>0 && (pos>i || s1[pos-1]!=s2[i-1])){
			pos--;
		}
		if (pos==0){
			puts("-1");
			return 0;
		}
		if (tmp==pos){
			while (head<=tail && q[tail]-cnt>=i){
				tail--;
			}
			q[++tail]=i+cnt;
		}
		else{
			cnt++;
			if (i!=pos){
				ans=max(ans,tail-head+1);
				q[--head]=pos+cnt;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    int n,t,a,b;
    in(n);
    vector2d(int,vec,n,n,-1);
    rep(i,n){
        in(t);
        while(t--){
            in(a,b);
            vec[i][a-1]=b;
        }
    }
    int maxv=0,flag=1;
    for(int i=0;i<(1<<n);i++){
        bitset<15> table(i);
        flag=1;
        rep(k,n){
            if(table.test(k)){
                for(int j=0;j<n;j++){
                    if(vec[k][j]==-1)continue;
                    if(vec[k][j]!=table.test(j)){
                        flag=0;
                        goto skip;
                    }
                }
            }
        }
        skip:
        if(flag)maxv=max(maxv,(int)table.count());
    }
    out(maxv);
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <complex>
#include <cassert>
#include <cstring>
#include <functional>
#include <bitset>
#include <climits>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define cmn(x,y) x=min(x,y)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(vector<T>& v) : sz((int)v.size()){
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n, make_pair(numeric_limits<T>::max(), sz));
        for(int i = 0; i < sz; i++){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+n] = make_pair(a, k);
        k += n;
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        for(int i = 0; i < sz; i++){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};

int n;
ll d;
ll saiki(segtree<ll>& sg, int a,int b){
    //cerr << a << " " << b << endl;
    if(b==a+1)return 0;
    auto p = sg.query(a,b);
    ll s = p.first;
    ll ans = 0;
    int ind = p.second;
    if(ind-1>=a){
        ll xx = sg.query(ind-1,ind).first;
        ans += s+d+xx;
        sg.update(ind-1,min(xx,s+d));
        ans += saiki(sg,a,ind);
    }
    if(ind+1<b){
        ll xx = sg.query(ind+1,ind+2).first;
        ans += s+d+xx;
        sg.update(ind+1,min(xx,s+d));
        ans += saiki(sg,ind+1,b);
    }
    return ans;
}

int main(){
    cin >> n >> d;
    vector<ll>v(n+1);
    rep(i,n)cin >> v[i];
    segtree<ll> sg(v);
    ll ans = saiki(sg,0,n);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<long long int,long long int> mp;
int main(){
    int n;
    long long int m;
    cin >> n >> m;
    long long int a[n];
    long long int sum =0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
        sum %= m;
        mp[sum]++;
    }
    long long int ans=0;
    for(auto u:mp){
        if(u.first==0LL)ans += u.second;
        ans += u.second*(u.second-1)/2;
    }
    cout << ans << endl;
}

#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 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 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 N, M;
  cin >> N >> M;
  vll A(N + 1);
  mll m;
  rep(i, N + 1) {
    if (i == 0) {
      A[i] = 0;
      m[0]++;
      continue;
    }
    ll a;
    cin >> a;
    A[i] = A[i - 1] + a;
    m[A[i] % M]++;
  }

  ll ans = 0;
  rep(i, N + 1) {
    ans += m[A[i] % M] - 1;
  }
  ans /= 2;
  ANS;
  return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<bool> v(26);
	for (int i = 0; i < S.size(); i++) {
		char ch = S.at(i);
		int n = (int)ch - 97;
		v.at(n) = 1;
	}

	string ans = "None";
	for (int i = 0; i < 26; i++) {
		if (v.at(i) == 0) {
			ans = (char)i + 97;
			break;
		}
	}

	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
string t;
char ch;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>t;
sort(t.begin(),t.end());
if(t.size()==1&&t[0]=='a') {
        cout << "None";
        return 0;
    }
set <char> s;
for(long long  i=0;i<t.size();i++){
    s.insert(t[i]);
}

for(char i='a';i<='z';i++){
    if(s.count(i)==true)continue;
    else{
        cout<<i;
        return 0;
    }}
cout<<"None";
return 0;}


//#pragma GCC oplmize(2)
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=1e7+5;
const int mod=998244353;
const double pi=acos(-1.0);
const double eps = 1e-8;
char s[maxn];
int a[maxn],len;
ll sum;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    scs(s);
    len=strlen(s+1);
    for(int i=1;i<=len;i++){
        a[i]=s[len-i+1]-'0';
    }
    for(int i=1;i<=len+1;i++){
        if(a[i]==10){
            a[i]-=10;
            a[i+1]++;
        }
        if(a[i]>5){
            sum+=(10-a[i]);
            a[i+1]++;
        }
        else if(a[i]<5){
            sum+=a[i];
        }
        else{
            sum+=5;
            if(a[i+1]>=5){
                a[i+1]++;
            }
        }
    }
    pr(sum);
    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e6+2;
string s;
int n, dp[N][2], ssum[N];

int main()
{
  fastio;
  cin >> s; reverse(all(s));
  int n = s.size(); s = '#' + s;
  for (int i = n; i > 0; i--) ssum[i] = ssum[i + 1] + (9 - (s[i] - '0'));
  dp[0][0] = dp[0][1] = 0;
  int mn = ssum[1];
  for (int i = 1; i <= n; i++){
    dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + (s[i] - '0');
    dp[i][1] = mn - ssum[i + 1] + 2;
    mn = min(mn, dp[i][0] + ssum[i + 1]);
    mn = min(mn, dp[i][1] + ssum[i + 1]);
  }
  cout << min(dp[n][0], dp[n][1]);
  return 0;
}


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

int n,d;
long long v[20],maxv[30];

long long qpow(int x,int y){
    long long ans=1;
    while(y){
        if(y&1)ans*=x;
        y>>=1,x*=x;
    }
    return ans;
}

long long dfs(long long x,int p){
    if(p==n)return (x==d);
    if(d<x-maxv[p]||d>x+maxv[p])return 0;
    long long ans=0;
    for(int i=-9;i<=9;i++){
        if(p)ans+=dfs(x+v[p]*i,p+1)*(10-abs(i));
        else if(i^9)ans+=dfs(x+v[p]*i,p+1)*(i>=0?9-i:10+i);
    }
    return ans;
}

int main(){
    scanf("%d",&d);
    long long ans=0;
    for(int i=1;i<=18;i++){
        memset(maxv,0,sizeof(maxv));
        n=i+1>>1;
        for(int j=0;j<n;j++)v[j]=qpow(10,i-j)-qpow(10,j);
        for(int j=0;j<n;j++)
        for(int k=j;k<n;k++)maxv[j]+=v[k]*9;
        ans+=dfs(0,0)*(i&1?1:10);
    }
    printf("%lld\n",ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll=long long ;

int D;

int res = 0;
ll pw[19];
int digit[19];

void dfs(int high, int low, ll dif, ll way, bool carry) {
    if (high < low) {
        if (dif == D) res += way;
    } else if(high == low) {
        dfs(high-1, low+1, dif, way*10, 0);
    } else {
        int d = digit[low] + carry; carry = 0;
        if (d == 10) d = 0, carry = 1;
        dfs(high-1, low+1, dif + (pw[low] - pw[high])*d, way*(10-d-(low==0 && d==0)), carry);
        if (d > 0) {
            dfs(high-1, low+1, dif + (pw[low] - pw[high])*(d-10), way*(d - (low==0)), 1);
        }
    }
}

void solve() {
    cin >> D;
    pw[0] = 1;
    for (int i = 1; i <= 18; i++) {
        pw[i] = 10*pw[i-1];
    }
    ll x = D;
    for (int i = 0; i <= 18; i++) {
        digit[i] = x%10;
        x/=10;
    }
    for (int len = 1; len <= 18; len++) {
        dfs(len-1, 0, 0, 1, 0);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << 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 N;
  cin >> N;
  int mi = N + 1;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int P;
    cin >> P;
    ans += P <= mi;
    mi = min(mi, P);
  }
  cout << ans << "\n";
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define M 1000000007

signed main(){

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

	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int val=1;
	int cnt=0;
	int ans[n+1]={0};
	for(int i=n-1;i>=0;i--){
		if(a[i]==val){
			cnt++;
			ans[val]=1;
			while(ans[val]==1){
				val++;
			}
		}
		ans[a[i]]=1;
	}
	cout << cnt << endl;
}


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

using namespace std;

int main() {
  int n, v;
  cin >> n;
  vector<vector<int>> V(2, vector<int>(100001));
  for (int i = 0; i != n; ++i) {
    cin >> v;
    ++V[i % 2][v];
  }

  vector<vector<int>> I(2, vector<int>(100001));
  for (auto i : {0, 1}) {
    iota(begin(I[i]), end(I[i]), 1);
    partial_sort(begin(I[i]), begin(I[i]) + 2, end(I[i]),
                 [&](int a, int b) { return V[i][a] > V[i][b]; });
  }
  auto ans = n - ((I[0][0] != I[1][0]) ? V[0][I[0][0]] + V[1][I[1][0]]
                                       : max(V[0][I[0][0]] + V[1][I[1][1]],
                                             V[0][I[0][1]] + V[1][I[1][0]]));
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    map<int,int> a, b;
    rep(i,n) {
        int v;
        cin >> v;
        if (i%2) a[v]++;
        else b[v]++;
    }
    priority_queue<P> ap, bp;
    for (auto p : a) {
        ap.emplace(p.second, p.first);
    }
    for (auto p : b) {
        bp.emplace(p.second, p.first);
    }
    vector<P> x, y;
    int cnt = 2;
    while (!ap.empty() && cnt > 0) {
        auto p = ap.top();
        ap.pop();
        x.push_back(p);
        cnt--;
    }
    cnt = 2;
    while (!bp.empty() && cnt > 0) {
        auto p = bp.top();
        bp.pop();
        y.push_back(p);
        cnt--;
    }
    int ans = INF;
    rep(i,x.size())rep(j,y.size()) {
        int now = 0;
        if (x[i].second == y[j].second) {
            now = n/2 + n/2 - max(x[i].first, y[j].first);
        }
        else {
            now = n - x[i].first - y[j].first;
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n+1);
    rep(i,n) cin >> a[i+1];
    rep(i,n) a[i+1] += a[i];
    map<ll,ll> cnt;
    vector<ll> mod;
    rep(i,n+1){
        cnt[a[i]%m]++;
        mod.push_back(a[i]%m);
    }
    SORT(mod);
    mod.erase(unique(all(mod)),mod.end());
    ll ans = 0;
    for(ll i:mod){
        ans += cnt[i]*(cnt[i]-1)/2;
    }
    PRINT(ans);
}

#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

int main() {
  Cinint(n);
  Cinstring(s);
  int64_t count = 0;
  int64_t Rcount = 0;
  int64_t Gcount = 0;
  int64_t Bcount = 0;
  rep(i, n) {
    if (s.at(i) == 'R') {
      Rcount++;
    }
    else if (s.at(i) == 'G') {
      Gcount++;
    }
    else {
      Bcount++;
    }
  }
  count = Rcount*Gcount*Bcount;
  rep(i, n-2) {
    for (int j = i+1; j < n-1; j++) {
      int sa = j-i;
      int k = j+sa;
      if (k <= n-1) {
        if (s.at(i) == 'R') {
          if (s.at(j) == 'G') {
            if (s.at(k) == 'B') {
              count--;
            }
          }
          else if (s.at(j) == 'B') {
            if (s.at(k) == 'G') {
              count--;
            }
          }
        }
        else if (s.at(i) == 'G') {
          if (s.at(j) == 'B') {
            if (s.at(k) == 'R') {
              count--;
            }
          }
          else if (s.at(j) == 'R') {
            if (s.at(k) == 'B') {
              count--;
            }
          }
        }
        else {
          if (s.at(j) == 'R') {
            if (s.at(k) == 'G') {
              count--;
            }
          }
          else if (s.at(j) == 'G') {
            if (s.at(k) == 'R') {
              count--;
            }
          }
        }
      }
    }
  }
  cout << count << endl;
}


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

int main() {
    int a,b,c,d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cout << min(a,b)+min(c,d) <<endl;
}

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

int main() {
  int a, b, c, d;
  int sum = 0;
  for (int i = 0; i < 4; i++) {
    cin >> a >> b >> c >> d;
  }
  sum += (a < b) ? a : b;
  sum += (c < d) ? c : d;
  cout << sum << endl;
  return 0;
}


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

int main() {
    ll m;
    std::cin >> m;
    ll dsum = 0;
    ll sum = 0;
    for (int i = 0; i < m; i++) {
        ll d,c;
        std::cin >> d>>c;
        dsum += c;
        sum += d*c;
    }

    std::cout << dsum-1+(sum-1)/9 << std::endl;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 500030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    998244353;
ll n;
vector<pair<ll,ll> > vp;
ll pre[N],suf[N];
bool comp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	return p1.fi<p2.fi||(p1.fi==p2.fi&&p1.se<p2.se);
}
int main()
{
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
   cin>>n;
   for(ll i=0;i<n;i++)
   {
	ll x,y;
	cin>>x>>y;
	vp.emplace_back(x,y);
   }
   sort(vp.begin(),vp.end(),comp);

   ll x1=vp[0].fi;
   ll y1=vp[0].se;
   pre[0]=max(0ll,y1-x1+1);
   for(ll i=1;i<n;i++)
   {
   	x1=max(x1,vp[i].fi);
   	y1=min(y1,vp[i].se);
   	pre[i]=max(0ll,y1-x1+1);
   }
   x1=vp[n-1].fi;
   y1=vp[n-1].se;
   suf[n-1]=max(suf[n-1],y1-x1+1);
   for(ll i=n-2;i>=0;i--)
   {
   	x1=max(x1,vp[i].fi);
   	y1=min(y1,vp[i].se);
   	suf[i]=max(suf[i],y1-x1+1);
   }
   ll ans=0;
   for(ll i=0;i<n-1;i++)
   {
   	if(pre[i]+suf[i+1]>ans)
   	ans=pre[i]+suf[i+1];
  // 	cout<<pre[i]<<" "<<suf[i+1]<<endl;
   }
   ll xx=vp[n-1].fi;

    y1;ll y2;
   ll mn=1e9+6;
   for(int i=0;i<n;i++)
   {
   	if(vp[i].se<mn)
   	{
   		mn=vp[i].se;
   		y1=i;
	   }
   }
   mn=1e9+2;
   for(int i=0;i<n;i++)
   {
   	if(i!=y1)
   	if(vp[i].se<mn)
   	{
   		mn=vp[i].se;
   		y2=i;
	   }
   }

	for(ll i=1;i<n-1;i++)
	{
		ll y;
		if(i!=y1)
		y=vp[y1].se;
		else
		y=vp[y2].se;

		ans=max(ans,vp[i].se-vp[i].fi+1+max(0ll,y-xx+1));
	//	cout<<xx<<" "<<y<<endl;
	}
   cout<<ans;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){

  int N, M;
  cin >> N;
  vector<string> vec1(N);
  for (int i=0; i<N; i++){
    cin >> vec1.at(i);
  }
  cin >> M;
  vector<string> vec2(M);
  for (int i=0; i<M; i++){
    cin >> vec2.at(i);
  }

  int max=0;
  for (int i=0; i<N; i++){
    int sum=0;
    for (int j=0; j<N; j++){
      if (vec1.at(i)==vec1.at(j)){
        sum++;
      }
    }
    for (int k=0; k<M; k++){
      if (vec1.at(i)==vec2.at(k)){
        sum--;
      }
    }
    if (sum>max){
      swap(sum, max);
    }
  }

  cout << max << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  rep(i,n){
    if(a[i]==b[i]&&b[i]==c[i]){
      continue;
    }
    else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
      ans += 2;
    }
    else{
      ans++;
    }
  }
  print(ans);
}


#include <iostream>
#include <string>

using namespace std;

void process_command(istream &istr, string &str);
void my_print(const string &str, int a, int b);
void my_reverse(string &str, int a, int b);
void my_replace(string &str, int a, int b, string &p);

int main(){
    string str;
    cin >> str;
    int q;
    cin >> q;
    for(int i = 0; i != q; ++i){
        process_command(cin, str);
    }
}

void process_command(istream &istr, string &str){
    string command;
    istr >> command;
    if (command == "print"){
        int a, b;
        istr >> a >> b;
        my_print(str, a, b);
    }else if (command == "reverse"){
        int a, b;
        istr >> a >> b;
        my_reverse(str, a, b);
    }else if (command == "replace"){
        int a, b;
        string p;
        istr >> a >> b >> p;
        my_replace(str, a, b, p);
    }else {
        cout << "Unexpected command encountered! " << command << endl;
    }

}
void my_print(const string &str, int a, int b){
    cout << str.substr(a, b - a + 1) << endl;
}

void my_reverse(string &str, int a, int b){
    while(a < b){
        auto tmp = str[a];
        str[a] = str[b];
        str[b] = tmp;
        ++a;
        --b;
    }
}

void my_replace(string &str, int a, int b, string &p){
    str.replace(a, b - a + 1, p);
}

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vector<char> >tmp;
vector<vector<int> >scr;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int>d(m);
		vector<vi >cost(m,vector<int>(m));
		vector<vi >tim(m,vector<int>(m));
		vector<bool>used(m);
		rep(i,m)rep(j,m){cost[i][j]=inf;tim[i][j]=inf;}
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			a--;b--;
			cost[a][b]=cost[b][a]=c;
			tim[a][b]=tim[b][a]=d;
		}
		cin>>n;
		rep(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			rep(j,m)d[j]=inf;
			rep(j,m)used[j]=false;
			if(c){
				d[a]=0;
				while(1){
					int v=-1;
					rep(j,m)if(!used[j]&&(v==-1||d[v]>d[j]))v=j;
					if(v==-1)break;
					used[v]=true;
					rep(j,m)d[j]=min(d[j],d[v]+tim[v][j]);
				}
			}else{
				d[a]=0;
				while(1){
					int v=-1;
					rep(j,m)if(!used[j]&&(v==-1||d[v]>d[j]))v=j;
					if(v==-1)break;
					used[v]=true;
					rep(j,m)d[j]=min(d[j],d[v]+cost[v][j]);
				}
			}
			cout<<d[b]<<endl;
		}
	}
}


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

int main(){

 string a,b,c;
 cin >> a >> b >> c;

 int A, B, C;
  A = a.size()-1;
  B = b.size()-1;
  C = c.size()-1;

  if(a.at(A)==b.at(0)&& b.at(B)==c.at(0))
 	cout << "YES" <<endl;
  else
    cout <<"NO" <<endl;
}

#include <stdio.h>

int main(){
	char arr[355];
	scanf("%[^\n]", &arr);
	int test = 1;
	for(int i=0;arr[i]!='\0';i++){
		if(arr[i]==' '&&arr[i-1]!=arr[i+1]){
			test=0;
			break;
		}
	}
	if(test==1){
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
vector<int> adj[MAXN];
int power(int x, int y, int p = mod){
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = (res*x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modFact(int n, int p = mod)
{
    if (n >= p)
        return 0;

    int result = 1;
    for (int i = 1; i <= n; i++)
        result = (result * i) % p;

    return result;
}
int32_t main(){
    SPEED;
    SPEED;
    string s;
    cin >> s;
    map<char, int> fre;
    for(char c : s){
        fre[c]++;
    }
    int cnt = 0;
    if(s[0] == 'A'){
        int yes = 0;
        for(int i = 2; i < len(s) - 1; ++i){
            if(s[i] == 'C') yes++;
        }
        if(yes == 1){
            for(char c: s){
                if(c >= 97 && c <= 122) cnt++;
            }
            if(cnt + 2 == len(s)) cout << "AC";
            else cout << "WA";
        }
        else cout << "WA" ;
    }
    else cout << "WA" ;
}
// check indices of loop
// check for overflow

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> S;
    smatch ssmm;
    if(regex_search(S,ssmm,regex("^A[a-z]+C[a-z]+$")))
    {
        cout << "AC";
        return 0;
    }
    cout << "WA";

    return 0;
}


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

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

    if(s.length() == 3) reverse(s.begin(),s.end());
    cout << s << endl;
    return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;

    return 0;
}


#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{~0UL};
    for(unsigned long i{0}, pa{~0UL}, a; i < N; ++i){
        cin >> a;
        if(pa + 1 < a)return 0 & puts("-1");
        if(pa + 1 == a)++ans;
        else ans += a;
        pa = a;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  bool ok = true;
  if(a[0] != 0) ok = false;
  rep(i, n - 1) if(a[i] + 1 < a[i + 1]) ok = false;
  if(!ok) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  rep(i, n - 1) {
    if(a[i + 1] - 1 == a[i])
      ans++;
    else
      ans += a[i + 1];
  }
  cout << ans << endl;
}


#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 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();
  string a, b, c;
  cin >> a >> b >> c;

  if (a.back() == b[0] && b.back() == c[0]) {
    COUT("YES");
  } else {
    COUT("NO");
  }
  return 0;
}

#include <stdio.h>
#include <string.h>

int main() {
	char a[15];
	char b[15];
	char c[15];
	scanf("%s %s %s", a, b, c);

	if(a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}


#include <stdio.h>

int main (){
	char huruf1[249];
	char huruf2[249];

	scanf("%s %s", huruf1 , huruf2);
	printf("%s%s", huruf2 , huruf1);

	return 0;
}

#include<bits/stdc++.h>

using namespace std;
#define Pi acos(-1)
#define _terminated return 0
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define booster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<long> > v2l;

const int mod = 1e+5;
const int mx = 2e+5;
const ll inf = 1e18;

void upper_bubble_sort(){
     int i,j,temp,number_of_input;
     int array[100];
     cin >> number_of_input;
     for(i=0; i<number_of_input; i++)
         cin >> array[i];
         for(i=0; i<number_of_input; i++){
             for(j=0; j<(number_of_input-i-1); j++){
               if(array[j] > array[j+1]){
                 temp = array[j];
                 array[j] = array[j+1];
                 array[j+1] = temp;
                }
              }
         }
    for(i=0; i<number_of_input; i++)
      cout << array[i] << endl;
}
void bst(void){
          int low,high,mid,keynum,num,array[100];
          cin >> keynum;
          low = 1;
	         high = num;
         	do{
		        mid = (low + high) / 2;
		         if(keynum < array[mid])
			         high = mid - 1;
		         else if (keynum > array[mid])
			         low = mid + 1;
	         }
          while (keynum != array[mid] && low <= high);
	        if(keynum == array[mid]){
            cout << "number located at " << mid +1 << endl;}
         else
           no;
}

void solvio(void){
     string s,t;
     cin >> s >> t;
     cout << t << s << endl;
}

int main(){
    booster;
    solvio();
    _terminated;
}


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

int main(){
  long long n, a[10000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cout << *min_element( a, a + n) << " "
       << *max_element( a, a + n) << " "
       << accumulate( a, a + n, 0LL) << endl;
}

#include<iostream>
using namespace std;

int main(){
	int n;
	int ai, min, max;
	long long sum = 0;
	cin >> n;

	min = 1000000;
	max = -1000000;
	while (n--){
		cin >> ai;
		sum += ai;
		if (max < ai) max = ai;
		if (min > ai) min = ai;
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  while(cin>>n>>k,n||k) {
    int cost[n][n]; FOR(i,0,n) FOR(j,0,n) cost[i][j] = 1e9;
    FOR(i,0,k) {
      int x; cin >> x;
      if(x == 0) {
        int d[n]; FOR(i,0,n) d[i] = 1e9;
        bool used[n]; CLR(used);
        // ??????????????????
        int a, b; cin >> a >> b;
        a--;b--;
        d[a] = 0;
        while(1) {
          int v = -1;
          for(int u = 0; u < n; u++) {
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
          }
          if(v == -1) break;
          used[v] = true;
          for(int u = 0; u < n; u++) {
            d[u] = min(d[u], d[v] + cost[v][u]);
          }
        }
        if(d[b] >= 1e9) d[b] = -1;
        cout << d[b] << endl;
      } else {
        int c, d, e; cin >> c >> d >> e;
        c--;d--;
        cost[c][d] = min(cost[c][d], e);
        cost[d][c] = min(cost[d][c], e);
      }
    }
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
//#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 200005  //check the limits, man
const ll INF = 1e12;
int par[N],lev[N],tot[N];
void makeset(int n)
{
    fill(par,par+n,-1);
    fill(lev,lev+n,0);
    fill(tot,tot+n,1);
    return;
}
int findset(int x)
{
    int y=x;
    while(par[y]>=0)
        y=par[y];
    if(x!=y)
        par[x]=y;
    return y;
}
void combine(int a,int b)
{
    a=findset(a);
    b=findset(b);
    if(a!=b)
    {
        if(lev[a]<lev[b])
            par[a]=b,tot[b]+=tot[a];
        else if(lev[a]>lev[b])
            par[b]=a,tot[a]+=tot[b];
        else
            lev[b]++,par[a]=b,tot[b]+=tot[a];
    }
    return ;
}
vvi ad(N);
int ar[N];
bool vis[N];
int K;
void dfs(int s)
{
    int i,a,x=ad[s].size();
    vis[s]=1;
    ar[K++]=s;
    rep(i,x)
    {
        a=ad[s][i];
        if(!vis[a])
            dfs(a);
    }
}
int main()
{
    int n,x,y,i,j,a,b;
    in(n);
    in2(x,y);
    while(x--)
    {
        in2(a,b);
        a--,b--;
        ad[a].pb(b);
        ad[b].pb(a);
    }
    makeset(n);
    while(y--)
    {
        in2(a,b);
        combine(a-1,b-1);
    }
    vi v(n);
    vii temp;
    rep(i,n)
    {
        if(!vis[i])
        {
            K=0;
            dfs(i);
            temp.clear();
            rep(j,K)
            {
                a=ar[j];
                b=findset(a);
                temp.pb(b,a);
            }
            sort(all(temp));
            j=0;
            while(j<K)
            {
                a=j;
                while(a<K && temp[j].F==temp[a].F)
                    a++;
                lp(b,j,a)
                    v[temp[b].S]=a-j;
                j=a;
            }
        }
    }
    dbg(v,i,n);
}

#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int f1[N],f2[N];
map <pair <int ,int > ,int > ans;
inline int getrt(int x,int *f){
	return f[x]==x?x:f[x]=getrt(f[x],f);
}
inline void merge(int x,int y,int*f){
	if (getrt(x,f)!=getrt(y,f))
		f[getrt(x,f)]=y;
}
int main (){
	int n,m,k;scanf ("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++) f1[i]=f2[i]=i;
	for (int i=1,u,v;i<=m;i++)
		scanf ("%d%d",&u,&v),merge(u,v,f1);
	for (int i=1,u,v;i<=k;i++)
		scanf ("%d%d",&u,&v),merge(u,v,f2);
	for (int i=1;i<=n;i++)
		ans[make_pair(getrt(i,f1),getrt(i,f2))]++;
	for (int i=1;i<=n;i++)
		printf ("%d ",ans[make_pair(getrt(i,f1),getrt(i,f2))]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N;
    cin>>N;
    int P=N;
    int S;
    bool a=true;
    while(a==true){
        if(N==0){
            a=false;
        }
        else{
            S+=N%10;
            N-=N%10;
            N/=10;
        }
    }
    if(P%S==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007

int main() {
	ll ans = 0;
	ll tmp = 0;
	ll n;
	cin >> n;
	string s = "";
	if(n==0) cout << 0 << endl;
	else {
		while(tmp != n){
			//cout << s.size() << " " << tmp << " " << s << endl;
			if(abs(n-tmp)%((ll)1<<(s.size()+1))==0) s = "0" + s;
			else {
				tmp += (ll)pow(-1, s.size()) * ((ll)1<<s.size());
				s = "1" + s;
			}
		}
		cout << s << endl;
	}
}


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

int main(){
  int n;
  string st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin >>n;

  while(n!=0){
    string s;
    vector<int>key;
    string ans = "";

    for(int i = 0; i<n;i++){
      int x;
      cin >>x;
      key.push_back(x);
    }
    cin >>s;
    int ind = 0;
    for (int i = 0; i<(int)s.size(); i++){
      char c;
      for (int j = 0; j < (int)st.size();j++){
        if(s[i] == st[j]){
          if(j - key[ind] < 0)c = st[j - key[ind] + 52];
          else c =  st[j - key[ind]];
        }
      }
      ans = ans + c;
      ind++;
      if(ind >= (int)key.size()){
        ind = 0;
      }
    }
    cout <<ans<<endl;
    key.clear();
    cin >>n;
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int l[N], r[N];

int main(){
  fastIO;
  int n;
  cin >> n;
  int lmx = 0, rmn = (int)1e9 + 1;
  for(int i = 0 ; i < n; i ++ ){
    cin >> l[i] >> r[i];
    lmx = max(lmx, l[i]);
    rmn = min(rmn, r[i]);
  }
  vector<pii> shits;
  for(int i = 0 ; i < n; i ++ ){
    shits.push_back(mp(rmn - l[i] + 1,r[i] - lmx + 1));
  }
  sort(shits.begin(), shits.end());
  int low = (int)1e9 + 1;
  int ans = 0;
  for(int i = 0 ; i < n; i ++ ){
    ans = max(ans, (r[i] - l[i] + 1) + max(rmn-lmx+1,0));
  }
  for(int i = 0 ; i + 1 < n; i ++ ){
    low = min(low, shits[i].se);
    ans = max(ans, max(0,low) + max(0,shits[i + 1].fi));
  }
  ans = max(ans, max(0,shits[0].fi) + max(0,shits[n-1].fi));
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  int N, Q;
  while (N = in(), Q = in(), N || Q){
    int bkt[128] = {};
    for (int i = 0; i < N; i++){
      for (int x = in(); x--;){
        bkt[in()]++;
      }
    }
    int maxi = 0;
    for (int i = 1; i < 128; i++){
      if (bkt[i] >= Q && bkt[maxi] < bkt[i]){
        maxi = i;
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

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

using namespace std;

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

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

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

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

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

  while(true){
	int N, M; cin >> N >> M;
	if(N == M && M == 0) break;
	int day[101], mx = 0;
	fill(day, day+101, 0);
	REP(i,N){
	  int m, d;
	  cin >> m;
	  REP(j,m){
		cin >> d;
		mx = max(mx, ++day[d]);
	  }
	}
	if(mx < M) cout << 0 << endl;
	else{
	  REP(i,101)
		if(day[i] == mx){
		  cout << i << endl;
		  break;
		}
	}
  }

  return 0;
}


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

int main(){
  int w[10], k[10];
  for(int i = 0;i < 10;i++)scanf("%d",w + i);
  for(int i = 0;i < 10;i++)scanf("%d",k + i);
  sort(w,w + 10);
  sort(k,k + 10);
  printf("%d %d\n",w[9] + w[8] + w[7], k[9] + k[8] + k[7]);
  return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  int wc[10], wsum=0, kc[10], ksum=0;

  for(int i = 0 ; i < 10 ; i++) {
    cin >> wc[i];
  }
  for(int i = 0 ; i < 10 ; i++) {
    cin >> kc[i];
  }
  sort(wc, wc+10);
  sort(kc, kc+10);

  for(int i = 9 ; i > 6 ; i--) {
    wsum += wc[i];
    ksum += kc[i];
  }
  cout << wsum << ' ' << ksum << endl;
  return 0;
}


#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

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;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

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

  return res;

}

int main(){
  ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e;
  ll mintime = min({a,b,c,d,e});

  cout << 4 + (n + mintime-1)/mintime << endl;

}

#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

//ceil(n/m)
int int_ceil(int n, int m)
{
	if (n % m == 0) return n / m;
	return n / m + 1;
}

signed main()
{
	int N;
	int A[5];
	cin >> N;
	REP(i, 5) cin >> A[i];

	int cur = N;
	for (int i = 0; i < 5; i++)
	{
		cur = min(cur, A[i]);
	}

	int n = int_ceil(N, cur);
	cout << n + 4 << endl;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a/g * b; //prevent overflow
}

/////////////////////////  END OF TEMPLATE /////////////////////////////////////////

vp adj[100001];

bool visited[100001];
vll dist(100001);
void dfs(int k)
{
    visited[k] = 1;
    for(auto u : adj[k])
    {
        if(!visited[u.first])
        {
            dist[u.first] = dist[k] + u.second;
            dfs(u.first);
        }

    }

}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n-1; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].pb({b, c});
        adj[b].pb({a, c});
    }

    int q, k;
    cin >> q >> k;
    dfs(k);
    while(q--)
    {
        int x, y;
        cin >> x >> y;
        cout << dist[x] + dist[y] << endl;
    }
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

struct edge{
  ll to, cost;
};

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> A(N-1,vector<ll>(3));
  vector<vector<edge>> vec(N,vector<edge> ());
  REP(i, N-1){
    REP(j, 3){
      cin >> A.at(i).at(j);
    }
    A.at(i).at(0)--;
    A.at(i).at(1)--;
    edge e1 = {A.at(i).at(1),A.at(i).at(2)};
    edge e2 = {A.at(i).at(0),A.at(i).at(2)};
    vec.at(A.at(i).at(0)).push_back(e1);
    vec.at(A.at(i).at(1)).push_back(e2);
  }

  ll Q,K;
  cin >> Q >> K;
  K--;

  queue<ll> que;
  vector<ll> dist(N,-1);
  que.push(K);
  dist[K]=0;
  while(!que.empty()){
    ll v = que.front();
    que.pop();
    for(auto e:vec.at(v)){
      ll nv = e.to;
      ll ncost = e.cost;
      if(dist[nv]!=-1) continue;

      dist[nv]=dist[v]+ncost;
      que.push(nv);
    }
  }

  vector<ll> ans(Q);
  REP(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;
    y--;
    ans.at(i)=dist[x]+dist[y];
  }

  REP(i,Q){
    cout << ans.at(i) << endl;
  }
}


    #include <bits/stdc++.h>
    using namespace std;
    #define all(x) (x).begin(), (x).end()
    #define SZ(X) ((int)(X).size())
    #define endl "\n";
    int main()
    {
    	ios::sync_with_stdio(0);
    	cin.tie(0);
    	// freopen("input.txt", "r", stdin);
    	// freopen("output.txt", "w", stdout);
    	string s,a;
    	cin>>s;
    	set<char> t(all(s));
    	a = "abcdefghijklmnopqrstuvwxyz";

    	for (auto c:a)
    	{
    		auto pos =t.find(c);
    		if(pos==t.end()){
    			cout<<c;
    			return 0;
    		}

    	}
    cout<<"None";

       return 0;
    }

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

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

    set<char> c;
    for(int i=0;i<26;i++){
        c.insert((char)('a'+i));
    }

    bool ans=true;
    for(int i=0;i<s.size();i++){
        if(c.count(s[i]))c.erase(s[i]);
        if(c.empty())ans=false;
    }

    if(ans){
        auto it = c.begin();
        cout << *it << endl;
    }
    else cout << "None" << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int l[200000] = {0};

int main() {
    int N;
    map<int, int> d;

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

    for(int i=0;i<N;i++) {
        auto itr = d.find(l[i]);
        if(itr != d.end()) {
            d[l[i]]++;
        }
        else {
            d[l[i]] = 1;
        }
    }

    int ans = 0;
    for(auto i=d.rbegin();i!=d.rend();i++) {
        while(i->second > 0) {
            int isFinished = 0;
            for(int j=0;j<32;j++) {
                int v = pow(2, j) - i->first;
                if (i->first < v) {
                    break;
                }
                if (d.find(v)!=d.end()) {
                    if ((v!=i->first && d[v]>=1) || (v==i->first && d[v]>=2)) {
                        i->second--;
                        d[v]--;
                        ans++;
                        isFinished = 1;
                        break;
                    }
                }
            }
            if(isFinished==0) {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#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 (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    unordered_map<ll, int> c;
    rep(i, n) c[A[i]] = 0;
    rep(i, n) c[A[i]]++;

    int sum = 0;
    for (auto kv: c) {
        if (kv.second % 2 == 1)
            sum++;
    }

    put(sum);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, v[100000];
P a[100001], b[100001];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> v[i];
	REP(i, 100001) a[i] = b[i] = P{0, i};
	REP(i, n/2) ++a[v[i*2]].F;
	REP(i, n/2) ++b[v[i*2+1]].F;
	sort(a, a+100001); reverse(a, a+100001);
	sort(b, b+100001); reverse(b, b+100001);
	if (a[0].S == b[0].S) cout << min(n - a[0].F - b[1].F, n - b[0].F - a[1].F) << endl;
	else cout << (n - a[0].F - b[0].F) << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int n, tmp;
	cin >> n;
	map<int, int> odd, even;
	rep(i, n) {
		cin >> tmp;
		if (i % 2 == 0)	even[tmp]++;
		else odd[tmp]++;
	}
	P oddMax, evenMax;
	oddMax = make_pair(-1, -1);
	evenMax = make_pair(-1, -1);
	int oddOthers, evenOthers;
	oddOthers = evenOthers = 0;
	for (auto a : odd) {
		if (oddMax.second < a.second)	oddMax = a;
	}
	for (auto a : even) {
		if (evenMax.second < a.second)	evenMax = a;
	}

	int ans = iINF;
	if (oddMax.first == evenMax.first) {
		int tmpAns = 0;
		int tmpOdd, tmpEven;
		tmpOdd = tmpEven = 0;
		for (auto a : odd) {
			if (a.first == oddMax.first) continue;
			tmpOdd += a.second;
		}
		for (auto a : even) {
			if (a.first == evenMax.first) continue;
			tmpEven += a.second;
		}

		tmpAns = tmpOdd;
		P tmpEvenMax = make_pair(-1, -1);
		for (auto a : even) {
			if (a.first == evenMax.first) continue;
			if (tmpEvenMax.second < a.second)	tmpEvenMax = a;
		}
		int tmptmpEven = 0;
		for (auto a : even) {
			if (a.first == tmpEvenMax.first) continue;
			tmptmpEven += a.second;
		}
		tmpAns += tmptmpEven;
		ans = min(ans, tmpAns);

		tmpAns = tmpEven;
		P tmpOddMax = make_pair(-1, -1);
		for (auto a : odd) {
			if (a.first == oddMax.first) continue;
			if (tmpOddMax.second < a.second)	tmpOddMax = a;
		}
		int tmptmpOdd = 0;
		for (auto a : odd) {
			if (a.first == tmpOddMax.first) continue;
			tmptmpOdd += a.second;
		}
		tmpAns += tmptmpOdd;
		ans = min(ans, tmpAns);
	}
	else {
		ans = 0;
		for (auto a : odd) {
			if (a.first == oddMax.first) continue;
			ans += a.second;
		}
		for (auto a : even) {
			if (a.first == evenMax.first) continue;
			ans += a.second;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  int N,L;
  cin>>N>>L;
  int data[N];
  int m=1000,sum=0;
  rep(i,N){
      data[i]=L+i;
      m=min(m,abs(data[i]));
      sum+=data[i];
  }
  bool exist=false;
  rep(i,N){
      if(m==data[i]){
          exist=true;
          break;
      }
  }
  int ans;
  if(exist==true){
      ans=sum-m;
  }
  else{
      ans=sum+m;
  }

  cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n)
{
	// Corner cases
	if (n <= 1)
		return 1;
	if (n <= 3)
		return 2;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0)
		return 1;

	for (int i = 5; i * i <= n; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return 1;

	return 2;
}

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007;
    return res; }

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

ll findlcm(ll arr[], int n)
{

    ll ans = arr[0];

    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}

int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,l;
        cin>>n>>l;
        ll k=l-1;
        ll sum=((n*(n+1))/2)+n*k;
        //cout<<sum<<" ";
        for(ll i=1;i<=n;i++)
        {
            if(i==-k)
            {
                cout<<sum;
                exit(0);
            }

        }
        if(k>=0)
        {
            cout<<sum-k-1;
        }
        else
        {
            cout<<sum-n-k;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 1001000
#define inf INT_MAX
inline int read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
int n;
char a[N],b[N];
int pos[N],Ans,cnt,ans[N];
bool Chtholly=true;
int main()
{
    //freopen("game.in","r",stdin);
    //freopen("game.out","w",stdout);
    n=read();
    scanf("%s%s",a+1,b+1);
    int len=1;
    //while(a[len]==b[len])
    //for(int i=1;i<=n+10;i++) cout<<a[i]<<endl;
    while(a[len]==b[len]&&len<=n) len++;
    if(len==n+1) return puts("0"),0;
    int front=n+1,rear=n;
    int k=n+1;
    while(n)
    {
        int j=n;
        while(b[j-1]==b[n]&&j>=1) j--;
        k=min(k,j);
        while(a[k]!=b[n]&&k>=1) k--;
        if(!k) {Chtholly=false;break;}
        while(front<=rear&&pos[rear]-cnt>n) rear--;
        cnt++;
        front--;
        pos[front]=k+cnt;
        ans[front]=cnt;
        Ans=max(Ans,cnt-ans[rear]+1);
        n=j-1;
    }
    if(!Chtholly) {puts("-1");return 0;}
    printf("%d\n",Ans);
    return 0;
}

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

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

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

int main(){
    int K,T; cin >> K >> T;
    int a[T];
    for(int i=0;i<T;i++){
        cin >> a[i];
    }
    sort(a,a+T);
    int sum=0;
    for(int i=0;i<T-1;i++){
        sum+=a[i];
    }
    int ans=max(a[T-1]-1-sum,0);
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//c
int main(){

    int n, k;cin >> n >> k;
    vector<vector<int>> a(51, vector<int>(n));
    rep(i, n) cin >> a[0][i];

    rep(i, k){

        vector<int> memo(n+1);

        rep(j, n){
            int min, max;
            min=j-a[i][j];
            max=j+1+a[i][j];
            if(min<0) min=0;
            if(max>n) max=n;
            memo[min]++;
            memo[max]--;
        }

        int cnt=0;

        rep(j, n){
            cnt+=memo[j];
            a[i+1][j]=cnt;
        }

        bool fin=true;

        rep(j, n){
            if(a[i][j]!=a[i+1][j]) fin=false;
        }

        if(fin){
            k=i+1;
            break;
        }

    }

    rep(j, n-1){
        cout << a[k][j] << " ";
    }
    cout << a[k][n-1] << endl;

    return 0;

}

#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

i32 a[200000];

auto main() -> i32 {
	i32 n, k;
	scanf("%d%d", &n, &k);
	for (i32 i = 0; i < n; i += 1) {
		scanf("%d", a + i);
	}
	i32 b[200001];
	for (i32 step = 0; step < std::min(64, k); step += 1) {
		std::fill(b, b + n + 1, 0);
		for (i32 i = 0; i < n; i += 1) {
			b[std::max(0, i - a[i])] += 1;
			b[std::min(n, i + a[i] + 1)] -= 1;
		}
		a[0] = b[0];
		for (i32 i = 1; i < n; i += 1) {
			b[i] += b[i - 1];
			a[i] = b[i];
		}
	}
	for (i32 i = 0; i < n; i += 1) {
		printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	}
	return 0;
}


#ifndef _WIN32
#include<iostream>
#endif

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

#define FOR(i,bg,ed) for(int i = (bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
struct cww {
	cww() {
		ios::sync_with_stdio(false);
		cin.tie(0);
	}
}star;
template<typename T>
istream & operator>> (istream &is, vector<T>&v) {
	for (auto &it : v)is>> it;
	return is;
}
char f(char c) {
	if (c == 'a')return 'Z';
	if (c == 'A')return 'z';
	return c - 1;
}
int main() {
	int n;
	while (cin >> n, n) {
		vector<int> k(n);
		cin >> k;
		string s;
		cin >> s;
		int id = 0;
		for (auto &c : s) {
			REP(i,k[id]) {
				c = f(c);
			}
			id++;
			id %= n;

		}
		cout << s << endl;
	}

	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};

int main(){
    int n;
    while(cin>>n,n){
        int a[100];for(int i=0;i<n;i++)cin>>a[i];
        char str[128];cin>>str;
        for(int i=0;str[i];i++){
            int val=(isupper(str[i])?tolower(str[i])-'a'+26:str[i]-'a');
            int next=val-a[i%n];
            next=(next+52)%52;
            if(next>25)next=toupper('a'+next-26)-'a';
            printf("%c",'a'+next);
        }
        puts("");
    }
    return 0;
}


#include <cstdio>
#include <cstring>

const int mod = 1e9 + 7;
const int MAXN = 3e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}

int f[MAXN][3][3];
char S[MAXN];
int N;

int add( int &x, const int y ) { return x = ( x + y >= mod ? x + y - mod : x + y ); }

int main()
{
	scanf( "%s", S + 1 );
	f[0][0][0] = 1, N = strlen( S + 1 );
	for( int i = 0 ; i < N ; i ++ )
		for( int j = 0 ; j < 3 ; j ++ )
			for( int k = 0 ; k < 3 ; k ++ )
				if( f[i][j][k] )
				{
					if( S[i + 1] ^ '1' ) add( f[i + 1][j][k == 2 ? 1 : k + 1], f[i][j][k] );
					if( S[i + 1] ^ '0' )
					{
						if( k ) add( f[i + 1][j][k - 1], f[i][j][k] );
						else add( f[i + 1][MIN( j + 1, 2 )][k], f[i][j][k] );
					}
				}
	write( add( f[N][1][0], add( f[N][2][0], add( f[N][2][1], f[N][2][2] ) ) ) ), putchar( '\n' );
	return 0;
}


#include <iostream>
int main(){
    int a, b, x, i, n;
    long long int s = 0;
    a=-1000000;//MAX
    b=1000000;//min
    std::cin >> n;
    for(i=0;i<n;i++){
        std::cin >> x;
        s += x;
        if(x > a) a = x;
        if(x < b) b = x;
    }
    std::cout << b << " " << a << " " << s << std::endl;
    return 0;
}

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

int main(){
    vector<int> a(2);
    int k;
    cin >> a[0] >> a[1] >> k;

    int times = 0;
    int side = 0;
    while(1){
        if(a[side] % 2 == 1) a[side] -= 1;
        a[side] /= 2;
        a[(side+1)%2] += a[side];
        side += 1;
        side %= 2;
        times += 1;
        if(times == k) break;
    }

    cout << a[0] << " " << a[1] << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int n;	cin>>n;
	vector<pair<int,int>>odd(100000);
	vector<pair<int,int>>even(100000);
	set<int>kind;
	rep(i,0,n){
		int v;
		cin>>v;
		kind.insert(v);
		if(i%2==0){
			even[v].first++;
			even[v].second=v;
		}
		else{
			odd[v].first++;
			odd[v].second=v;
		}
	}
	sort(all(even));
	reverse(all(even));
	sort(all(odd));
	reverse(all(odd));
	int ans;
	if(kind.size()==1){
		ans=n/2;
	}
	else{
		ans=100000;
		if(odd[0].second!=even[0].second)	ans=min(ans,n-odd[0].first-even[0].first);
		if(odd[0].second!=even[1].second)	ans=min(ans,n-odd[0].first-even[1].first);
		if(odd[1].second!=even[0].second)	ans=min(ans,n-odd[1].first-even[0].first);
		if(odd[1].second!=even[1].second)	ans=min(ans,n-odd[1].first-even[1].first);
	}
	cout<<ans<<endl;
	return 0;
}

#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end()
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;
const ll mod = 1000000007;

bool cmp(pair<int,int> a,pair<int,int> b){
    return a.S > b.S;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    ll i,n;
    cin>>n;
    ll ar[n];
    For(i,0,n) cin>>ar[i];
    map<ll,ll> oc0, oc1;
    pair<ll,ll> mx10 = {-1,0},mx11 = {-1,0},mx20 = {-1,0},mx21 = {-1,0};
    for(ll a = 0; a < n;a += 2){
        oc0[ar[a]] += 1;
    }
    for(ll a = 1; a < n;a += 2){
        oc1[ar[a]] += 1;
    }
    vector<pair<ll,ll> > vec0,vec1;
    for(auto itr = oc0.begin(); itr != oc0.end(); ++itr){
        vec0.pb(*itr);
    }
    for(auto itr = oc1.begin(); itr != oc1.end(); ++itr){
        vec1.pb(*itr);
    }
    sort(vec0.begin(),vec0.end(),cmp);
    sort(vec1.begin(),vec1.end(),cmp);
    mx10 = vec0[0];
    mx11 = vec1[0];
    if(vec0.size()>1) mx20 = vec0[1];
    if(vec1.size()>1) mx21 = vec1[1];
    //for(auto k: vec0) cout<<k.F sp<<k.S el;
    //for(auto k: vec1) cout<<k.F sp<<k.S el;
    if(mx11.F != mx10.F){
        int a = mx10.S, b = mx11.S;
        cout<<n - (a + b);
    }
    else{
        int x;
        x = max((mx10.S + mx21.S),(mx11.S + mx20.S));
        cout<< n - x;
    }
    return 0;
}


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

int n,m,vis[maxn];

ll ans[maxn],a[maxn],k,cnt,q[maxn],pos[maxn];

template <class T>
void read(T &x){
	char s=getchar();int f=0;x=0;
	while(s<'0'||s>'9'){if(s=='-') f=1;s=getchar();}
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=getchar();
	x=f?-x:x;
}

int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		pos[i]=1ll*i;
	}
	read(m);read(k);
	for(int i=n;i>=1;i--) a[i]=a[i]-a[i-1];
	for(int i=1,x;i<=m;i++){
		read(x);
		swap(pos[x],pos[x+1]);
	}
	for(int i=1;i<=n;i++){
		ll p=i;cnt=0;
		if(vis[i]) continue;
		q[++cnt]=p;
		vis[p]=1;
		p=pos[p];
		while(p!=i){
			q[++cnt]=p;
			vis[p]=1;
			p=pos[p];
		}
		for(int j=1;j<=cnt;j++) ans[q[j]]=a[q[(j+k-1)%cnt+1]];
	}
	for(int i=1;i<=n;i++){
		ans[i]+=ans[i-1];
		printf("%lld.0\n",ans[i]);
	}
	return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int a[N];
    a[0] = 1;
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == 'C' && s[i - 1] == 'A')
        {
            a[i] = a[i - 1] + 1;
        }
        else
        {
            a[i] = a[i - 1];
        }
    }
    int l, r;
    rep(i, q)
    {
        cin >> l >> r;
        cout << a[r - 1] - a[l - 1] << endl;
    }
    return 0;
}


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

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

  if (N == 1){
    cout << 1 << endl;
    return 0;
  }

  vector<int>A(N);
  vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2)));

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    for (int j = 0; j < A.at(i); j++) {
      for (int k = 0; k < 2; k++) {
        cin >> data.at(i).at(j).at(k);
      }
    }
  }

  int Max = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 15); tmp++) {
    bitset<15> s(tmp);  // 最大20個なので20ビットのビット列として扱う

    if (N < 15 && s.test(N)) {
      break;
    }
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int count = 0;
    int honest = 0;

    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        honest++;
        for (int j = 0; j < A.at(i); j++) {
          int B = data.at(i).at(j).at(0) - 1;
          if (s.test(B)){
            if (data.at(i).at(j).at(1) == 0){
              count++;
            }
          }
          else {
            if (data.at(i).at(j).at(1) == 1){
              count++;
            }
          }
        }
      }
    }
    if (count == 0){
      if (honest > Max){
        Max = honest;
      }
    }
  }

  cout << Max << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, ans = 0;
    cin >> n;
    vector<pii> A[n];
    rep(i, n) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            A[i].push_back({x, y});
        }
    }
    rep(bit, 1 << n) {
        rep(i, n) {
            if ((bit >> i & 1) == 0) continue;
            rep(j, A[i].size()) {
                int x, y;
                tie(x, y) = A[i][j];
                if ((bit >> x & 1) != y) {
                    goto end;
                }
            }
        }
        chmax(ans, __builtin_popcount(bit));
        end:;
    }
    cout << ans << endl;
}

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


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

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

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

int main() {
  int ans=0,N,X,T;
  cin >> N >> X >> T;

  if(N%X){
    ans = (N/X+1)*T;
  }else{
    ans = (N/X)*T;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
    int x,y;
    cin >> x >> y;
    if (x == 1 && y == 1) {
        cout << 1000000 << endl;
    } else {
        cout << (max(0,4-x)+max(0,4-y))*100000 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;

    if (B == 1) {
        cout << 0 << endl;
        return 0;
    }

    int output = 1;
    int socket = A;
    while (1) {
        if (socket >= B) break;
        socket--;
        socket += A;
        output++;
    }

    cout << output << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int K,T;
  cin >> K >> T;
  int a[T];
  for (int i = 0; i < T; i++) {
    cin >> a[i];
  }
  sort(a,a+T);
  reverse(a,a+T);
  int ma = max(0,a[0] - (K - a[0]));
  int ans = max(0,ma-1);
  cout << ans << endl;
  return 0;
}

#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

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

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

    if(T==1) {
        cout << K-1 << endl;
        return 0;
    }

    sort(A.rbegin(), A.rend());
    int64_t ret = A[0];
    int64_t sum = 0;
    rep(i, A.size()-1) {
        sum += A[i+1];
    }
    if(ret-sum-1 <= 0) {
        ret = 0;
    } else {
        ret = ret-sum-1;
    }
    cout << ret << endl;
    return 0;
}


#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 211;
const ll INF = 5e16;
const ll P = 1e9 + 7;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {

	/*
		最小的用掉后答案就不会变了。
		设 f[i][0/1] 表示做了 i 次，
		最小的被用掉/没被用掉的答案。

		枚举 s[n] 在什么时候被用掉。
		对于每个 pos, 其他有 (n - 1)! 种排列
		方式。
		但只有前 pos - 1 个会对答案造成贡献，
		所以考虑怎么选择这前 pos - 1 个。
		每次操作就是把 X % s[i]

		前面的思路都是对的！就是不会设计状态了。

		设 f[i][j] 表示做了 i 次，当前数为 j 。
		f[i][j % a[i]] = f[i - 1][j] * (n - i + 1)
	*/

	const ll M = 100011;

	ll n, X, Ans, s[N], f[N][M];

	inline void Add ( ll &a, ll b ) { (a += b) >= P && (a -= P); }

	int main() {
		n = read(), X = read();
		For ( i, 1, n ) s[i] = read();
		sort(s + 1, s + n + 1, greater <ll> ());

		f[0][X] = 1;
		For ( i, 1, n ) For ( j, 0, X )
			(f[i][j % s[i]] += f[i - 1][j]) %= P,
			(f[i][j] += f[i - 1][j] * (n - i)) %= P;
		For ( i, 1, X ) Add(Ans, f[n][i] * i % P);
		return wln(Ans), 0;
	}

}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/

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

const int MAX = 3000005;
const int MOD = 998244353;

long long fac[MAX]; //i!%MOD=fac[i]
long long finv[MAX]; //pow(i!,-1)%MOD=finv[i]
long long inv[MAX]; //pow(i,-1)%MOD=inv[i]

// テーブルを作る前処理
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;
}

int main(int argc, char const *argv[])
{
	COMinit();
	int n,m;
	cin>>n>>m;
	long long ans=COM(3*m+n-1,n-1);
	for (int i = 2*m+1; i <= 3*m; ++i)
	{
		ans-=(long long)n*COM(3*m+n-2-i,n-2)%MOD;
		ans%=MOD;
	}
	for (int i = 0; i < m; ++i)
	{
		ans-=COM(n-1+i,n-1)*COM(n,3*m-2*i)%MOD;
		ans%=MOD;
	}
	ans+=MOD;
	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}


///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

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

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
map<int,pi>yo;
 main()

{
    fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        yo[x]=(mp(y,0));
    }
    f(i,1,n)
    {
        int x,y;
        cin>>x>>y;
        yo[x]=(mp(y,1));
    }
    int ses=0;
    set<int>s;
    set<int>::iterator it;
    for(auto z:yo)
    {
        int x=z.fi;
        int typ=z.si.si;
        int y=z.si.fi;
        if(typ==0)
        {
            s.insert(y);
        }
        else
        {
           if(s.empty())continue;
           it=s.upper_bound(y);
           if(it==s.begin())continue;
           it--;
           s.erase(it);
           ses++;

        }
    }
    cout<<ses<<"\n";
    return 0;

}

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Dinic{
    int V;
    vector<int> level, used;
    vector<vector<edge>> G;
    Dinic(int N){
        V = N;
        used.resize(V, 0);
        level.resize(V, -1);
        G.resize(V);
    }
    void add(int u, int v, int c){
        edge e1 = {v, c, (int)G[v].size()};
        G[u].push_back(e1);
        edge e2 = {u, 0, (int)G[u].size() - 1};
        G[v].push_back(e2);
    }
    void bfs(int s){
        level.assign(V, -1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(edge e: G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int s, int t, int f){
        if(s == t) return f;
        for(int &i = used[s]; i < (int)G[s].size(); i++){
            edge &e = G[s][i];
            if(e.cap > 0 && level[e.to] > level[s]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int solve(int s, int t){
        int flow = 0;
        int INF = 1e9;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            used.assign(V, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
};

int main(){
    int N;
    cin >> N;
    Dinic Ford(2 * N + 2);
    int can[N][N];//can[i][j] = 1でペアが作れる
    vector<int> a(N), b(N), c(N), d(N);
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < N; i++) cin >> c[i] >> d[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] < c[j] && b[i] < d[j]) can[i][j] = 1;
            else can[i][j] = 0;
        }
    }
    for(int i = 0; i < N; i++){
        Ford.add(2 * N, i, 1);
        Ford.add(N + i, 2 * N + 1, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(can[i][j]) Ford.add(i, N + j, 1);
        }
    }
    int ans = Ford.solve(2 * N, 2 * N + 1);
    cout << ans << endl;
}