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

map<int, map<int, int> > dp1;
map<int, map<int, int> > dp2;
int mo=1000000007;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    int x[n+5];
    int y[m+5];
    int dpx[n+5];
    int dpy[m+5];
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int j=0;j<m;j++)
        cin>>y[j];
    sort(x,x+n);
    int mo=1000000007;
    int sx=0,sy=0;
    for(int i=1;i<n;i++)
        sx=(sx + (((((x[i]-x[i-1])*i)%mo)*(n-i))%mo) )%mo;
    sort(y,y+m);
    for(int i=1;i<m;i++)
        sy=(sy + (((((y[i]-y[i-1])*i)%mo)*(m-i))%mo) )%mo;

    //cout<<sx<<" "<<sy<<" ";
    cout<<(sx*sy)%mo;
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

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

const ll LINF = 2e18;
const int INF = 1e9;

double e(ll x) {
  ll sum = x * (x + 1) / 2;
  return (double)sum / (double)x;
}

void solve(ll N, ll K, std::vector<ll> p) {
  vector<ll> acc(N + 1);
  acc.at(0) = 0;
  rep(i, N) acc.at(i + 1) = acc.at(i) + p.at(i);

  ll idx = -1;
  ll mx = -1;

  rep(i, N - K + 1) {
    ll s = acc.at(i + K) - acc.at(i);
    if (s > mx) {
      mx = s;
      idx = i;
    }
  }

  double ans = 0.0;
  FOR(i, idx, idx + K) { ans += e(p.at(i)); }

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, K, std::move(p));
  return 0;
}


#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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

const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;

long long int N,x,a[200200]={},b[200200],res=0,now=0;
string str[20][20];
bool used[200200]={};
int main(){
    cout << fixed << setprecision(18);

    cin>>N>>x;
    for(long long int i = 1; i <= N; i++){
        cin>>a[i];
    }
    for(long long int i = 1; i <= N; i++){
        if(a[i]+a[i-1]>x){
            res+=a[i]+a[i-1]-x;
            a[i]-=a[i]+a[i-1]-x;
        }
    }
    cout<<res<<endl;
}

#include<iostream>
using namespace std;
int main(){
  while(1){
    int n,m,b,c,cnt=0,a[101]={};
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++){
      cin>>b;
      for(int j=0;j<b;j++){
	cin>>c;
	a[c]++;
      }
    }
    int x=0,max=0;
    for(int i=0;i<101;i++){
      if(max<a[i]&&m<=a[i]){
	max=a[i];
	x=i;
      }
    }
    cout<<x<<endl;
  }
  return 0;
}


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

using namespace std;

const long long MOD = (long long)1e9 + 7;

int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> x(n), y(m);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < m; i++){
        cin >> y[i];
    }
    long long a = 0, b = 0;
    for(int i = 1; i < n; i++){
        a += i * x[i] - (n - i) * x[i - 1];
        if(a < 0){
            a += MOD * (long long)((abs(a) + MOD - 1) / MOD);
        }
        a %= MOD;
    }
    for(int i = 1; i < m; i++){
        b += i * y[i] - (m - i) * y[i - 1];
        if(b < 0){
            b += MOD * (long long)((abs(b) + MOD - 1) / MOD);
        }
        b %= MOD;
    }
    cout << (a * b) % MOD << endl;
    return 0;
}

/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll >
#define dt cout<<"HERE\n";
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second
#define sz size
#define len length

const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}

const ll N =5e5+5;

void solve(){
	ll n,m;
	cin>>n>>m;
	ll arr[n], brr[m],crr[n],drr[m];
	for ( int i=0;i<n;i++)
		cin>>arr[i];
	for ( int j=0;j<m;j++)
		cin>>brr[j];
	for ( int i=1;i<n;i++){
		crr[i]=arr[i]-arr[i-1];
	}
	for ( int i=1;i<m;i++)
		drr[i]=brr[i]-brr[i-1];
	for ( int i=2;i<n;i++)
		crr[i]=(crr[i]*i+crr[i-1])%mod;
	for ( int i=2;i<m;i++)
		drr[i]=(drr[i]*i+drr[i-1])%mod;
	ll tot1=0,tot2=0,ans=0;
	for ( int i=1;i<n;i++)
		tot1=tot1+crr[i];
	for ( int j=1;j<m;j++)
		tot2=tot2+drr[j];
	tot2=tot2%mod;
	tot1=tot1%mod;
	ans=(tot1*tot2)%mod;
	cout<<ans<<'\n';

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	// #ifndef
	// 	freopen( "INPUT.txt", "r" , stdin);
	// 	freopen( "OUTPUT.txt","w", stdout);
	// #endif

	int t=1;

	//cin>>t;

	for ( int i=1;i<=t;i++){
   // 	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

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

    vector<int> v(n);

    loop(i,n){
        cin >> v[i];
    }

    ll result = 0;

    // i個の宝石を取る
    loop(i,min(n,k)+1){
        // j個だけ左から取る
        loop(j,i+1){
            vector<int> minusJewel = {};
            ll tmp = 0;
            loop(l,j){
                tmp += v[l];
                if(v[l] < 0)minusJewel.push_back(v[l]);
            }
            loop(l,i-j){
                tmp += v[n-1-l];
                if(v[n-l-1] < 0)minusJewel.push_back(v[n-l-1]);
            }
            sort(minusJewel.begin(),minusJewel.end());
            ll minusNum = minusJewel.size();

            loop(l,min(k-i, minusNum)){
                tmp -= minusJewel[l];
            }

            result = max(tmp, result);
        }
    }

    cout << result << endl;
}

// 2020-07-15 23:13:36
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

vector<int> vs;
int dp[55][55][105];
int rec(int l, int r, int k) {
  if(dp[l][r][k] >= 0) return dp[l][r][k];
  chmax(dp[l][r][k], 0);
  if(l == r) return dp[l][r][k];
  if(k >= 1) {
    chmax(dp[l][r][k], rec(l+1, r, k-1) + vs[l]);
    chmax(dp[l][r][k], rec(l, r-1, k-1) + vs[r-1]);
  }
  if(k >= 2) {
    chmax(dp[l][r][k], rec(l+1, r, k-2));
    chmax(dp[l][r][k], rec(l, r-1, k-2));
  }
  return dp[l][r][k];
}
void answer() {
  int n, k;
  cin >> n >> k;
  vs.resize(n);
  rep(i, n) cin >> vs[i];
  repc(i, n) repc(j, n) repc(ki, k) dp[i][j][ki] = -1;
  cout << rec(0, n, k) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
bool betemp(string sleft, string sright, int left, int right){
  if(sleft==sright){
    return (right-left)%2 == 1;
  }else{
    return (right-left)%2 == 0;
  }
}
void solve(int N){
  string vct = "Vacant";
  string sleft, sright, str;
  int left=0, right=N/2;
  cout << left << endl;
  cin >> sleft;
  if(sleft==vct) return ;
  cout << right << endl;
  cin >> sright;
  if(sright==vct) return ;
  if(!betemp(sleft, sright, left, right)){
    swap(sleft, sright), left = right, right = N;
  }
  while(left+1<right){
    int mid = (left+right)/2;
    cout << mid << endl;
    cin >> str;
    if(str==vct) return;
    if(betemp(sleft, str, left, mid)){
      sright = str, right = mid;
    }else{
      left = mid, sleft = str;
    }
  }
}
int main(){
  int N;
  while(cin>>N) solve(N);
  return 0;
}

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

int main(){
  ll N,M;
  cin >> N >> M;
  if(M%2==0){
    rep(i,M/2){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
  }else{
    rep(i,M/2){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
    cout << M/2+1 << " " << M/2+2 << endl;
  }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b;
}

#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

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

int main()
{
int arr[3];
cin>>arr[0]>>arr[1]>>arr[2];
cout<<arr[2]<<" " <<arr[0]<<" "<<arr[1]<<endl;

 return 0;
}


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

#define Inv(x) QPow(x,Mod-2);

const int maxN=2005;
const int maxM=maxN*maxN;
const int Mod=1e9+7;

int n,K;
int Fc[maxM],Ifc[maxM];
int F[maxN][maxN];

int QPow(int x,int cnt);
int C(int n,int m);
int main(){
    Fc[0]=Ifc[0]=1;for (int i=1;i<maxM;i++) Fc[i]=1ll*Fc[i-1]*i%Mod;
    Ifc[maxM-1]=Inv(Fc[maxM-1]);for (int i=maxM-2;i>=1;i--) Ifc[i]=1ll*Ifc[i+1]*(i+1)%Mod;

    scanf("%d%d",&n,&K);
    if (K==1){
	puts("1");return 0;
    }

    F[0][0]=1;
    for (int i=1;i<=n;i++)
	for (int j=n;j>=0;j--){
	    if (j<=i&&j>=0) F[i][j]=1ll*F[i-1][j-1]*C(i*K-j-1,K-2)%Mod;
	    F[i][j]=(F[i][j]+F[i][j+1])%Mod;
	}
    /*
    for (int i=0;i<=n;i++){
	for (int j=0;j<=n;j++) cout<<F[i][j]<<" ";
	cout<<endl;
    }//*/
    int Ans=1ll*F[n][0]*Fc[n]%Mod;
    printf("%d\n",Ans);return 0;
}
int QPow(int x,int cnt){
    int ret=1;
    while (cnt){
	if (cnt&1) ret=1ll*ret*x%Mod;
	x=1ll*x*x%Mod;cnt>>=1;
    }
    return ret;
}
int C(int n,int m){
    if (n<0||m<0||n<m) return 0;
    return 1ll*Fc[n]*Ifc[m]%Mod*Ifc[n-m]%Mod;
}

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int main(){
    int L,R;
    cin>>L>>R;
    ll x=2000000000;
    if(R-L+1>=2019){
        cout<<0<<endl;
    }
    else{
        ll w=0;
        for(ll i=L;i<R;i++){
            for(ll j=L+1;j<=R;j++){
                ll a=i%2019;
                ll b=j%2019;
                x=min(x,a*b%2019);
            }
        }
        cout<<x<<endl;
    }
    return 0;
}


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

int main() {
  string a,b;
  cin>>a>>b;
  cout<<b<<a;
}

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

using namespace std;
int main()
{
    int a,b,c,temp=0,temp2=0;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;

    return 0;
}


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

using namespace std;

const double eps=1e-10;

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

class rect{
public:
	int h,w,d2;
	rect(int _h,int _w){h=_h; w=_w; d2=h*h+w*w;}
	bool operator<(const rect& r) const{
		return d2<r.d2 || d2==r.d2 && h<r.h;
	}

};

int main()
{

	vector< rect > vr;
	for(int h=1;h<=150;h++){
		for(int w=h+1;w<=150;w++) vr.push_back(rect(h,w));
	}
	sort(vr.begin(),vr.end());

	int h,w;
	while(cin>>h>>w,h){

		rect r(h,w);
		for(int i=0;i<vr.size();i++){
			if(r<vr[i]){
				cout<<vr[i].h<<" "<<vr[i].w<<endl;
				break;
			}
		}

	}

	return 0;
}

#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	int h,w,s;
	while(true){
	cin>>h>>w;
	if(h==0&&w==0)
		break;
	bool t=true;
	s=h*h+w*w;
	h++;
	while(true){
		if(h*h>=s-h*h)
			break;
		if(s==h*h+(int)sqrt((double)s-h*h+0.0)*(int)sqrt((double)s-h*h+0.0)){
			t=false;
			break;
		}
		h++;
	}
	s++;
	if(t==true){
	while(true){
		h=1;
		while(true){
		if(h*h>=s-h*h)
			break;
		if(s==h*h+((int)sqrt((double)s-h*h+0.0)*(int)sqrt((double)s-h*h+0.0))){
			t=false;
			break;
		}
		h++;
		}
		if(t==false)
			break;
		s++;
	}
	}
	cout<<h<<" "<<(int)sqrt((double)s-h*h+0.0)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define loop(times) for(int i=0;i<(times);i++)

using namespace std;

int main() {
    while(1<2){
    int n;
    long long max;
    cin>>n;
    if(n==0)break;
    int a[n];
    int s[n];

    loop(n)cin>>a[i];
    max=a[0];
    s[0]=a[0];

    loop(n)s[i+1]=s[i]+a[i+1];
    for(int k=0;k<n;k++){
     loop(n-k){
         if(max<=s[k+i]-s[k-1])max=s[k+i]-s[k-1];
    }
    }
    cout<<max<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=2e5+50;
vec l(N),r(N);
vec a(N);

ll cal(ll x) {
  if(x<3) {
    return 0;
  }
  return max({l[x-1],r[x-1],cal(x-2)+a[x]});
}

int main() {
  ll n;
  cin >> n;
  for(ll i=1;i<=n;i++) cin >> a[i];
  for(ll i=2;i<=n;i+=2) {
    l[i]=l[i-2]+a[i-1];
    r[i]=max(r[i-2],l[i-2])+a[i];
  }
  if(n%2) {
    cout << cal(n) << endl;
  }
  else {
    cout << max(l[n],r[n]) << endl;
  }
}


#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<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
    string s;
    cin >> s;
    int l = s.length();
    if(s[0]!='A'){
        cout << "WA\n";
        return 0;
    }
    int i, cnt = 0;
    for(i=1; i<l; i++){
        if(isupper(s[i])){
            if(i==1 || i==l-1 || s[i]!='C'){
                cout << "WA\n";
                return 0;
            }
            cnt++;
        }
    }
    if(cnt==1) cout << "AC\n";
    else cout << "WA\n";
    return 0;
}


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

constexpr int64_t MAX_LEN = 200000;
set<int64_t> up[MAX_LEN + 1], right_st[MAX_LEN + 1], down[MAX_LEN + 1], left_st[MAX_LEN + 1];
set<int64_t> downs[MAX_LEN * 2 + 1], lefts[MAX_LEN * 2 + 1];

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> X(N), Y(N), dir_num(N);
    vector<char> U(N);

    map<char, int64_t> dirChar2dirNum = {
            { 'U', 0 },
            { 'R', 1 },
            { 'D', 2 },
            { 'L', 3 }
    };

    for (int64_t i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> U[i];
        dir_num[i] = dirChar2dirNum[U[i]];
    }

    int64_t ans = LLONG_MAX;

    //まず正面衝突があるか調べる
    for (int64_t i = 0; i < N; i++) {
        if (U[i] == 'U') {
            up[X[i]].insert(Y[i]);
        } else if (U[i] == 'R') {
            right_st[Y[i]].insert(X[i]);
        } else if (U[i] == 'D') {
            down[X[i]].insert(Y[i]);
        } else if (U[i] == 'L') {
            left_st[Y[i]].insert(X[i]);
        }
    }

    //下向きの一番大きい位置と,上向きの一番小さい位置を比べて交差するかを検証
    for (int64_t x = 0; x <= MAX_LEN; x++) {
        if (down[x].empty() || up[x].empty()) {
            continue;
        }

        for (int64_t up_p : up[x]) {
            //これより大きいのがあれば一番近いやつを見る
            auto itr = down[x].lower_bound(up_p);
            if (itr != down[x].end()) {
                ans = min(ans, 5 * (*itr - up_p));
            }
        }
    }

    for (int64_t y = 0; y <= MAX_LEN; y++) {
        if (left_st[y].empty() || right_st[y].empty()) {
            continue;
        }

        for (int64_t right_p : right_st[y]) {
            auto itr = left_st[y].lower_bound(right_p);
            if (itr != left_st[y].end()) {
                ans = min(ans, 5 * (*itr - right_p));
            }
        }
    }

    //90度での衝突を調べる
    for (int64_t j = 0; j < 4; j++) {
        //downとleftの衝突だけを調べる
        //x + yが一致しているものがぶつかりそう
        for (int64_t xy = 0; xy <= MAX_LEN * 2; xy++) {
            downs[xy].clear();
            lefts[xy].clear();
        }

        for (int64_t i = 0; i < N; i++) {
            if (dir_num[i] == dirChar2dirNum['D']) {
                downs[X[i] + Y[i]].insert(Y[i]);
            } else if (dir_num[i] == dirChar2dirNum['L']) {
                lefts[X[i] + Y[i]].insert(Y[i]);
            }
        }

        //
        for (int64_t xy = 0; xy <= MAX_LEN * 2; xy++) {
            for (int64_t left_p : lefts[xy]) {
                auto itr = downs[xy].lower_bound(left_p);
                if (itr != downs[xy].end()) {
                    ans = min(ans, 10 * (*itr - left_p));
                }
            }
        }

        //90度回転
        for (uint64_t i = 0; i < X.size(); i++) {
            swap(X[i], Y[i]);
            Y[i] = MAX_LEN - Y[i];
            (++dir_num[i]) %= 4;
        }
    }

    if (ans == LLONG_MAX) {
        cout << "SAFE" << endl;
    } else {
        cout << ans << endl;
    }
}

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

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

using ll = long long;

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

template<class T>struct dijkstra{//T=int or ll
  struct Node{
    vector<T> edges_to;
    vector<T> edges_cost;
    bool done;
    T cost=-1;
  };
  vector<Node> graph;
  void init(T N){
    graph.resize(N);
  }
  void add(T from, T to, T cost){
    graph[from].edges_to.push_back(to);
    graph[from].edges_cost.push_back(cost);
  }
  void shortest(T start){
    priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> d;
    d.push(make_pair(0,start));
    while(!d.empty()){
      pair<T,T> p = d.top();
      d.pop();
      Node &point = graph[p.second];
      if(point.done) continue;
      point.done = true;
      point.cost = p.first;
      for(T i = 0; i < (T)point.edges_to.size(); i++){
        if(graph[point.edges_to[i]].done)continue;
        d.push(make_pair(point.cost+point.edges_cost[i],point.edges_to[i]));
      }
    }
  }
};

int main() {
  ll N;
  cin>>N;
  dijkstra<ll> D;
  D.init(N);
  for(ll i = 0; i < N-1; i++) {
    ll x,y,z;
    cin>>x>>y>>z;
    D.add(x-1,y-1,z);
    D.add(y-1,x-1,z);
  }
  ll Q,K;
  cin>>Q>>K;
  D.shortest(K-1);
  for(ll i = 0; i < Q; i++){
    ll x,y;
    cin>>x>>y;
    cout<<D.graph[x-1].cost+D.graph[y-1].cost<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
int const MX = 2e5 + 2, MOD = 1e9 + 7;

int main()
{
    int t = 1;
//    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int l[101];
        for(int i = 0; i < n; i++){
            cin>>l[i];
        }
        int cnt = 0;
        for(int i = 0; i < n - 2; i++){
            for(int j = i + 1; j < n-1; j++){
                for(int k = j + 1; k < n; k++){
                    if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
                    if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[k] + l[j] > l[i]) cnt++;
                }
            }
        }
        cout<<cnt;
    }
}

#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll N, l;
    sll(N);
    // vector<ll> ls(N, 0);
    map<ll, ll> counter;
    rep(i, N){
        sll(l);
        counter[l] ++;
    }

    ll ans = 0;
    for(auto p1:counter){
        for(auto p2:counter){
            if(p1.first >= p2.first){
                continue;
            }
            for(auto p3:counter){
                if(p1.first >= p3.first){
                    continue;
                }else if(p2.first >= p3.first){
                    continue;
                }

                if(p3.first >= p1.first + p2.first){
                    continue;
                }

                ans += (p1.second * p2.second * p3.second);

            }
        }
    }

    cout << ans <<endl;
}

int main(){
    Main();
}


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

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n + max(h, w)-1) / max(h, w) << endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include<set>
using namespace std;
long long int mpown(long long int m, int n);
long long int bign=1000000007;
int bitCount(int bits);

int main()
{
    long long int n,m,k;
    cin >> n >> m >> k;
    // vector<vector<long long int>> comb(n*m,vector<long long int>(k-1,0));
    // vector<long long int> comb(max(n,m));
    long long int comb = 1;
    if(k!=2){
    vector<long long int> inv(k-1);
    inv.at(1)=1;
    // cout << "a"<<endl;
    for(int i=2;i<k-1;i++){
        inv.at(i) = bign-inv.at(bign%i)*(bign/i)%bign;
    }

    for(int i=1;i<=k-2;i++){
        comb = (((comb*(n*m-2-i+1))%bign)*inv.at(i))%bign;
    }
    }
    long long int ans=0;
    long long int temp=0;
    // comb.at(0).at(0)=1;
    // for(long long int i=1;i<n*m-1;i++){
    //     for(long long int j=0;j<=min(k-2,i);j++){
    //         // cout << "a " << endl;
    //         comb.at(i).at(j)=(j>0? (comb.at(i-1).at(j-1)+comb.at(i-1).at(j))%bign:comb.at(i-1).at(j));
    //         // cout << i << "," << j << "," << comb.at(i).at(j) << endl;
    //     }
    // }

    for(int d=1;d<=n-1;d++){

        temp = ((((((comb*d)%bign)*m)%bign)*m)%bign)*(n-d);
        temp %= bign;
        ans=(ans+temp)%bign;
    }
    for(int d=1;d<=m-1;d++){
        temp = ((((((comb*d)%bign)*n)%bign)*n)%bign)*(m-d);
        temp %= bign;
        ans=(ans+temp)%bign;
    }
    cout << ans << endl;

    return 0;
}

int bitCount(int bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); //  2bitごとに計算
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); //  4bitごとに計算
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); //  8bitごとに計算
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); //  16ビットごとに計算
    return (bits & 0x0000ffff) + (bits >> 16);             //  32ビット分を計算
}
long long int mpown(long long int m, int n)
{
    if (n == 0)
        return 1;
    else if (n == 1)
        return m;
    else
    {
        long long int temp = mpown(m, n / 2);
        return temp * temp * (n & 1 ? m : 1);
    }
}


//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int last [26];
    for(int i=0;i<26;i++)last[i]=-11;
    for(int i=0;i<s.length();i++){
        if(i-last[s[i]-'a']<3){
            cout<<last[s[i]-'a']+1<<" "<<i+1<<"\n";
            return 0;
        }
        last[s[i]-'a']=i;

    }
    cout<<"-1 -1\n";
}

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

int main(void) {
    int R;
    cin >> R;
    if(R < 1200) {
        cout << "ABC\n";
    } else if(R<2800) {
        cout << "ARC\n";
    } else {
        cout << "AGC\n";
    }
    return 0;
}


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl

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

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }

int main()
{
    string S;
    cin >> S;
    for(int i = 0; S.size() > i; i++){
        if(S.at(i) == 'A' && S.at(i + 1) == 'C') {
        cout << "Yes" << endl;
        return 0;
        }
        }

        cout << "No" << endl;

    }

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

int main() {

//long long a,b;
//int *num=new int[4];
//char *s=new char[3];
string s;
cin >> s;

if (s.find("AC") != std::string::npos) {
   cout << "Yes" << "\n";
}else
cout << "No" << "\n";

}


#include <iostream>
#include <string>
using i64 = long long;

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;

    i64 cnt[3] {};
    for (auto c : s) cnt[c == 'R' ? 0 : c == 'G' ? 1 : 2]++;

    i64 ret = cnt[0] * cnt[1] * cnt[2];
    for (int i = 0; i < n; i++) for (int j = 1; i - j >= 0 && i + j < n; j++) {
        if (s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j]) ret--;
    }

    std::cout << ret << std::endl;

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n, i = 3, tmp;
	cin >> n;

	while (i <= n) {
		if (i % 3 == 0) {
			cout << ' '<< i ;
		}
		else{
			for (tmp = i; tmp != 0; tmp /= 10) {
				if (tmp % 10 == 3) {
					cout << ' '<< i ;
					break;
				}
			}
		}
		i++;
	}
	cout << endl;
    return 0;
}

#include<stdio.h>
#include<string.h>
int main(void) {
	int a[10000],n,b=0,i,x,d=3;
	char r[10000];
	char s[10000];
	scanf("%d", &n);
	sprintf(s, "%d", d);
	for(i = 1; i <= n; i++) {
		sprintf(r,"%d", i);
		if (i % 3 == 0) {
			a[b] = i;
			b++;
		}
		else if (strstr(r,s) != NULL) {
			a[b] = i;
			b++;
	}

	}
	for (x = 0; x < b; x++) {
		if (x == 0) {
			printf(" ");
	}
		printf("%d",a[x]);
		if (x == b - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

//根は片が入ってないやつ

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> to(n); //to[a]=b a->b
    vector<vector<int>> from(n);
    vector<bool> pre(n,1);
    rep(i,n+m-1){
        int a,b; cin >> a >> b;
        a--; b--;
        to[a].pb(b);
        from[b].pb(a);
        pre[b]=0;
    }
    int res[n];
    int st;
    rep(i,n){
        if(pre[i]){
            res[i]=-1;
            st=i;
            break;
        }
    }
    queue<int> q;
    vector<bool> visit(n,0);
    visit[st]=1;
    q.push(st);
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(auto u:to[v]){
            if(visit[u]) continue;
            bool ok=1; //pre(u)=v?
            for(auto w:from[u]){
                if(!visit[w] || res[w]==v) ok=0;
            }
            if(ok){
                visit[u]=1;
                q.push(u);
                res[u]=v;
            }
        }
    }
    rep(i,n){
        cout << res[i]+1 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> ls[100000];
int cost[100000];
int main(){
	int v,e,r;	cin>>v>>e>>r;
	for(int i=0;i<e;i++){
		int s,t,d;	cin>>s>>t>>d;
		ls[s].push_back(make_pair(t,d));
	}
	for(int i=0;i<100000;i++)	cost[i]=INT_MAX;
	cost[r]=0;
	priority_queue<pair<int,int>> pq;
	pq.push(make_pair(0,r));
	while(!pq.empty()){
		auto cur=pq.top();	pq.pop();
		int dist=-cur.first,now=cur.second;
		if(dist>cost[now])	continue;
		for(int i=0;i<(int)ls[now].size();i++){
			int to=ls[now][i].first,d=ls[now][i].second;
			if(dist+d<cost[to]){
				cost[to]=dist+d;
				pq.push(make_pair(-cost[to],to));
			}
		}
	}
	for(int i=0;i<v;i++){
		if(cost[i]==INT_MAX)	cout<<"INF"<<endl;
		else 	cout<<cost[i]<<endl;
	}
	return 0;
}


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

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

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

#define long long long

long sol(long);

int main(){
	long a=0;
	cin>>a;
	cout<<sol(a)<<endl;
	return 0;
}

long pow10(long a){
	if(a<0)return 0;
	long r=1,c=10;
	while(a>0){
		if(a&1)r*=c;
		c*=c;
		a>>=1;
	}
	return r;
}

long will[50];

long dfs(long d,long pos,long n,long ned){
	if(abs(d-ned)>pow10(n-pos+1)-pow10((n+1)/2)-pow10(n/2)+pow10(pos-1))return 0;
	if(pos>(n+1)/2)return ned==d;
	long ans=0;
	for(will[pos]=-9;will[pos]<=9;will[pos]++){
		if(pos==1&&will[pos]==9)continue;
		if(pos==n/2+1&&will[pos]!=0)continue;
		if(will[pos]>=0)ans+=(9-will[pos]+(pos!=1))*dfs(d+(pow10(n-pos)-pow10(pos-1))*will[pos],pos+1,n,ned);
		else ans+=(10+will[pos])*dfs(d+(pow10(n-pos)-pow10(pos-1))*will[pos],pos+1,n,ned);
	}
	will[pos]=0;
	return ans;
}

long sol(long d){
	if(d%9)return 0;
	long ans=0;
	for(long i=2;pow10((i+1)/2)-pow10((i-1)/2)<=d;i++)
		ans+=dfs(0,1,i,d);
	return ans;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	reverse(all(a));
	reverse(all(b));
	reverse(all(c));

	char now = 'a';
	while (true)
	{
		if (now == 'a')
		{
			if(a.size() == 0){
				cout << "A" << endl;
				return 0;
			}
			now = a.back();
			a.pop_back();
		}
		if(now == 'b'){
			if(b.size() == 0){
				cout << "B" << endl;
				return 0;
			}
			now = b.back();
			b.pop_back();
		}
		if(now == 'c'){
			if(c.size() == 0){
				cout << "C" << endl;
				return 0;
			}
			now = c.back();
			c.pop_back();
		}
	}

	return 0;
}

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

int main(){
    vector<queue<char>> s(3);
    for(int ix=0;ix<3;ix++){
        string tmp;
        cin >> tmp;
        for(int ixx=0;ixx<tmp.size();ixx++) s.at(ix).push(tmp.at(ixx));
    }
    char card;
    int turnplayer = 0;
    while(!s.at(turnplayer).empty()){
        card = s.at(turnplayer).front();
        s.at(turnplayer).pop();
        turnplayer = card - 'a';
    }
    if(turnplayer == 0) cout << "A" << endl;
    if(turnplayer == 1) cout << "B" << endl;
    if(turnplayer == 2) cout << "C" << endl;
}


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

bool solve() {
    int M, Nmin, Nmax;
    cin >> M >> Nmin >> Nmax;
    if (M == 0 && Nmin == 0 && Nmax == 0) {
        return false;
    }
    int p[200];
    for (int j = 0; j < M; j++) {
        cin >> p[j];
    }

    int ind = Nmin-1;
    for (int j = Nmin; j < Nmax; ++j) {
        if (p[j]-p[j+1] >= p[ind]-p[ind+1]) {
            ind = j;
        }
    }
    cout << ind+1 << endl;
    return true;
}

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

#include <bits/stdc++.h>

using namespace std;

int main(){

  long long int n, a, b;
  cin>>n>>a>>b;

  long long int x[n];
  for(int i=0; i<n; i++) cin>>x[i];

  long long int walk_max=b/a;
  long long int tired=0;

  for(int i=0; i<n-1; i++){
    if(x[i+1]-x[i]>walk_max) tired+=b;
    else if(x[i+1]-x[i]<=walk_max){
      tired+=a*(x[i+1]-x[i]);
    }
  }

  cout<<tired<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, X;
vector <ll> b, l, r;

ll calc(int day, int a){
	return (a <= b[day] ? l[day] : r[day]) * (a - b[day]);
}
ll sum(int day, int len){
	if(len <= b[day]) return len * l[day];
	return b[day] * l[day] + (len - b[day]) * r[day];
}
ll calc(ll h){
	int q = h / X;
	int r = h % X;
	vector <pair <ll, int> > c;
	for(int i = 0 ; i < n ; i++){
		c.emplace_back(sum(i, X), i);
	}
	sort(c.rbegin(), c.rend());
	ll s = 0;
	for(int i = 0 ; i < q ; i++){
		s += c[i].first;
	}
	if(r == 0) return s;
	ll ret = 0;
	for(int i = 0 ; i < q ; i++){
		ret = max(ret, s - sum(c[i].second, X) + sum(c[i].second, r) + sum(c[q].second, X));
	}
	for(int i = q ; i < n ; i++){
		ret = max(ret, s + sum(c[i].second, r));
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> X;
	b.resize(n);
	l.resize(n);
	r.resize(n);
	for(int i = 0 ; i < n ; i++){
		cin >> b[i] >> l[i] >> r[i];
	}
	ll D = 0;
	for(int i = 0 ; i < n ; i++){
		D += calc(i, 0);
	}
	ll l = 0, r = 1LL * n * X;
	while(l <= r){
		ll mid = (l + r) / 2;
		if(D + calc(mid) >= 0) r = mid - 1;
		else l = mid + 1;
	}
	cout << l << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,u,v,w;
ll bismarck[(1<<15)][15],e[15][15],sum[(1<<15)];
int main()
{
	cin>>n>>m;
	while(m--)
	{
		cin>>u>>v>>w;
		u--,v--;
		e[u][v]=e[v][u]=w;
	}
	for(int i=0;i<1<<n;i++)
	{
		for(int j=0;j<n;j++){
		if((i>>j)&1)
		{
            for(int k=j+1;k<n;k++)
		    if((i>>k)&1) sum[i]+=e[j][k];
		}
		bismarck[i][j]=-1e18;}
	}
	bismarck[1][0]=0;
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		if((i>>j)&1)
		{
			int l=i^(1<<j);
			for(int k=0;k<n;k++)
			if((i>>k)&1&&e[j][k]) bismarck[i][j]=max(bismarck[i][j],bismarck[l][k]+e[k][j]);
			for(int k=l;k>0;k=(k-1)&l) bismarck[i][j]=max(bismarck[i][j],bismarck[i^k][j]+sum[k^(1<<j)]);
		}
	}
	cout<<sum[(1<<n)-1]-bismarck[(1<<n)-1][n-1];
}


#include<iostream>
#include<algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;
signed main(){
  ll n,m,xsum=0,ysum=0,ans=0;
  cin >> n >> m;
  ll tx[n],ty[m],x[n],y[m];
  for(ll i=0;i<n;i++){
    cin >> tx[i];
  }
  for(ll i=0;i<m;i++){
    cin >> ty[i];
  }
  sort(tx,tx+n);
  sort(ty,ty+m);
  n--; m--;
  for(ll i=0;i<n;i++){
    x[i]=tx[i+1]-tx[i];
    x[i]%=MOD;
  }
  for(ll i=0;i<m;i++){
    y[i]=ty[i+1]-ty[i];
    y[i]%=MOD;
  }
  for(ll i=0;i<n;i++){
    if(i==0||i==n-1){
      xsum+=x[i]*n;
    }else{
      xsum+=((((i+1)*(n-i))%MOD)*x[i])%MOD;
    }
    xsum%=MOD;
  }
  for(ll i=0;i<m;i++){
    if(i==0||i==m-1){
      ysum+=y[i]*m;
    }else{
      ysum+=((((i+1)*(m-i))%MOD)*y[i])%MOD;
    }
    ysum%=MOD;
  }
  ans = xsum*ysum;
  ans%=MOD;
  cout << ans<<endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
signed main(){
  int n,m,x1,y1;
  cin>>n>>m>>x1;
  int ans1=0,ans2=0;
  for(int i=0;i<n-1;i++){
    int x2;
    cin>>x2;
    ans1=(ans1+(x2-x1)*(i+1)%mod*(n-1-i)%mod)%mod;
    x1=x2;
  }
  cin>>y1;
  for(int i=0;i<m-1;i++){
    int y2;
    cin>>y2;
    ans2=(ans2+(y2-y1)*(i+1)%mod*(m-1-i)%mod)%mod;
    y1=y2;
  }
  cout<<ans1*ans2%mod;
}


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

int main() {
  string S;
  cin>>S;
  int N=S.size();
  if(S=="zyxwvutsrqponmlkjihgfedcba"){
    cout<<"-1"<<endl;
  }
  else if(N==26){
    vector<char> v(26);
    for(int i=0;i<26;i++){
      v[i]=S[i];
    }
    next_permutation(begin(v),end(v));
    for(int i=0;i<26;i++){
      cout<<v[i];
      if(v[i]!=S[i]){
        cout<<endl;
        break;
      }
    }
  }
  else{
    for(int j=0;j<26;j++){
      char a='a'+j;
      int X=0;
      for(int i=0;i<N;i++){
        if(S[i]==a){
          X++;
          break;
        }
      }
      if(X==0){
        cout<<S<<a<<endl;
        break;
      }
    }
  }

}

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

signed main(){

  string s,t;
  cin>>s;
  t = s;
  vector<int> alp(26);
  for(auto c:s)alp[c-'a']++;

  string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzz";
  auto chmin = [](auto& a,auto b){if(a>b)a=b;};
  while(1){
    for(int i=0;i<26;++i)if(alp[i]==0){
      string tmp = s;
      tmp += ('a'+i);
      if(t<tmp){
        chmin(ans,tmp);
      }
    }
    if(s.empty())break;
    alp[s.back()-'a']--;
    s.pop_back();
  }
  cout<<(ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzz"?"-1":ans)<<endl;

}


#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

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

    template <typename T>
    struct fenwick
    {
        int n;
        std::vector<T> f;
        fenwick(int n) : n(n), f(n + 1) {}

        T query(int p)
        {
            T ret = 0;
            for (++p; p > 0; p -= p & -p)
                ret += f[p];
            return ret;
        }

        void update(int p, T x)
        {
            for (++p; p <= n; p += p & -p)
                f[p] += x;
        }

    };

    template <typename T>
    using BIT = fenwick<T>;
}

#include <experimental/optional>

#include <tuple>

namespace asl
{
    typedef long long i64;

}

#include <random>

#include <utility>

#define endl '\n'

using namespace std;
using namespace asl;

void solve()
{
    int n, q;
    cin >> n >> q;

    vec<int> val(n);
    cin >> val;

    BIT<i64> bit(n);

    for (int i = 0; i < n; ++i)
        bit.update(i, val[i]);

    while (q--)
    {
        int t;
        cin >> t;

        if (t == 0)
        {
            int p, x;
            cin >> p >> x;
            bit.update(p, x);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << bit.query(r - 1) - bit.query(l - 1) << endl;
        }
    }
}

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

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <atcoder/all>
using ll=long long;
using namespace std;
using namespace atcoder;

int main(){
    int N,Q;
    cin>>N>>Q;
    fenwick_tree<ll> fw(N);
    ll a;
    for(int i=0;i<N;i++){
        cin>>a;
        fw.add(i,a);
    }

    int q,x,y;
    for(int i=0;i<Q;i++){
        cin>>q>>x>>y;
        if(q){
            cout<<fw.sum(x,y)<<endl;
        }else{
            fw.add(x,y);
        }
    }

    return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  int cnt = 0;
  for (int i = A; i <= B; ++i) {
    string s = to_string(i);
    int n = s.size();
    bool ok = true;
    for (int i = 0; i < n/2; ++i) {
      if (s[i] != s[n-i-1]) {
        ok = false;
        break;
      }
    }
    if (ok) ++cnt;
  }
  cout << cnt << endl;
}

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

int main(){
  int A,B;
  int a=0;

  cin >> A >> B;

  for(int i=A;i<=B;i++){
    if((i%10==i/10000)&&((i/10)%10==(i/1000)%10)){
      a++;
    }
    else {}
  }

  cout << a <<endl;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> l(2 * n);
    rep(i, 2 * n) {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for(int i = 0; i < 2 * n; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

#include<stdio.h>
#include<algorithm>
#define reg register
#define ri reg int
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define nrep(i, x, y) for(ri i = x; i >= y; --i)
#define DEBUG 1
#define ll long long
#define max(i, j) (i) > (j) ? (i) : (j)
#define min(i, j) (i) < (j) ? (i) : (j)
struct IO {
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
	char buf[MAXSIZE], *p1, *p2;
	char pbuf[MAXSIZE], *pp;
	#if DEBUG
	#else
		IO() : p1(buf), p2(buf), pp(pbuf) {}
		~IO() {
			fwrite(pbuf, 1, pp - pbuf, stdout);
		}
	#endif
	inline char gc() {
		#if DEBUG
    		return getchar();
		#endif
    	if(p1 == p2)
			p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    	return p1 == p2 ? ' ' : *p1++;
	}
	inline bool blank(char ch) {
    	return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
	}
	template <class T>
	inline void read(T &x) {
    	register double tmp = 1;
    	register bool sign = 0;
    	x = 0;
    	register char ch = gc();
    	for(; !isdigit(ch); ch = gc())
    		if(ch == '-') sign = 1;
    	for(; isdigit(ch); ch = gc())
			x = x * 10 + (ch - '0');
    	if(ch == '.')
			for(ch = gc(); isdigit(ch); ch = gc())
        		tmp /= 10.0, x += tmp * (ch - '0');
    	if(sign) x = -x;
	}
	inline void read(char *s) {
		register char ch = gc();
		for(; blank(ch); ch = gc());
		for(; !blank(ch); ch = gc())
			*s++ = ch;
    	*s = 0;
	}
	inline void read(char &c) {
    	for(c = gc(); blank(c); c = gc());
	}
	inline void push(const char &c) {
		#if DEBUG
    		putchar(c);
		#else
    		if(pp - pbuf == MAXSIZE) {
				fwrite(pbuf, 1, MAXSIZE, stdout);
				pp = pbuf;
			}
    		*pp++ = c;
		#endif
	}
	template <class T>
	inline void write(T x) {
    	if(x < 0) {
			x = -x;
			push('-');
		}
    	static T sta[35];
    	T top = 0;
    	do{
			sta[top++] = x % 10;
			x /= 10;
    	}while(x);
    	while(top)
			push(sta[--top] + '0');
	}
	template <class T>
	inline void write(T x, char lastChar) {
    	write(x);
		push(lastChar);
	}
} io;
int a[110], n, ans;
int main() {
	io.read(n);
	rep(i, 1, n * 2) io.read(a[i]);
	std::sort(a + 1, a + 2 * n + 1);
	rep(i, 1, n) ans += a[2 * i - 1];
	io.write(ans);
}


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

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

    string s;
    unsigned long long int n;
    cin>>n;
    cin>>s;
    if(n>=s.size())
        cout<<s;
    else{
        s.erase(s.begin()+n,s.end());
        s.append("...");
        cout<<s;
    }
}

#include <iostream>
using namespace std;

int main() {
    //入力を受け取る
    int D, T, S;
    cin >> D >> T >> S;

    //高橋君の移動時間を計算する
    int dist = S * T;

    //Dとdistの大小関係に応じて出力をする
    if (dist >= D) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

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

  ll sum = n*(n-1)/2 + l*n;

  ll ms = inf;
  for (int i=0; i<n; i++) {
    if (abs(ms) > abs(i+l)) ms = i+l;
  }
  cout << sum - ms << "\n";

  return 0;
}

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

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

  int a[n];
  int all = 0;
  for(int i = 1; i <= n; i++){
    a[i] = l + i - 1;
    all += a[i];
  }

  int minu = 0,maxmin = 2000000;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if(j != i){
        minu += a[j];
      }//if
    }//for
    if(abs(minu - all) < abs(maxmin - all)){
      maxmin = minu;
    }
    minu = 0;
  }

  cout << maxmin << endl;

}


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

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

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

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  rep(i,c/2){
    if(a%2==1){
      a--;
    }
    b+=(a/2);
    a/=2;
    if(b%2==1){
      b--;
    }
    a+=(b/2);
    b/=2;
  }
  if(c%2==1){
    if(a%2==1){
      a--;
    }
    b+=(a/2);
    a/=2;
  }
  cout << a << " " << b << endl;
}

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

const ll INF = 1LL << 60;

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

    for (int i = 1; i <= K; i++) {
        if (i % 2 == 1) {
            // 高橋
            if (A % 2 == 1) {
                A--;
            }
            ll tmp = A / 2;
            B += tmp;
            A -= tmp;
        } else {
            // 青木
            if (B % 2 == 1) {
                B--;
            }
            ll tmp = B / 2;
            A += tmp;
            B -= tmp;
        }
    }

    cout << A << " " << B << endl;;
}


#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int w;
    cin>>s>>w;
    for (int i=0;i+w<=s.size();i+=w) {
        cout<<s[i];
    }
    if (s.size()%w!=0) {
        reverse(s.begin(),s.end());
        string tmp=s.substr(0,s.size()%w);
        cout<<tmp[tmp.size()-1];
    }
    cout<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	int n;
	cin>>str>>n;
	string adj;
	int at = 0;
	while(at < str.size())
	{
		adj.push_back(str[at]);
		at+=n;
	}
	cout<<adj<<endl;
	return 0;
}


#include <stdio.h>

int main(){

    long long n, sum = 0;
    scanf("%lld", &n);
    for(long long i = 1 ; i <= n ; i++){
    	if(i%3 != 0 && i%5 != 0){
    		sum+=i;
		}
	}
    printf("%lld\n", sum);

    return 0;
}

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

int n;
int a[N];
string S,X,Y;
map<pair<string,string>,LL>mp;
LL ans;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	cin>>S;
	X=S.substr(0,n);
	Y=S.substr(n,n);
	reverse(Y.begin(),Y.end());
	for (int i=0;i<1<<n;i++){
		int res=i;
		string s1="",s2="";
		for (int j=0;j<n;j++){
			if (res%2==0) s1+=X[j];
			  else s2+=X[j];
			res/=2;
		}
		mp[make_pair(s1,s2)]++;
	}
	for (int i=0;i<1<<n;i++){
		int res=i;
		string s1="",s2="";
		for (int j=0;j<n;j++){
			if (res%2==0) s1+=Y[j];
			  else s2+=Y[j];
			res/=2;
		}
		ans+=mp[make_pair(s1,s2)];
	}
	printf("%lld\n",ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N;
    cin>>N;
    vector <ll> ans;
//    N--;
    while(N){
        ll rest=(N-1)%26;
        N--;
        N/=26;
        ans.push_back(rest);
    }
    ll len=ans.size();
    for(ll i=len-1;i>=0;i--){
        char c='a'+ans[i];
        cout<<c;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
const long long INF = 1LL <<60;
void func(long long x){
  if(x==0){
    cout<<"a";
  }
  else if(x==1){
    cout<<"b";
  }
  else if(x==2){
    cout<<"c";
  }
  else if(x==3){
    cout<<"d";
  }
  else if(x==4){
    cout<<"e";
  }
  else if(x==5){
    cout<<"f";
  }
  else if(x==6){
    cout<<"g";
  }
  else if(x==7){
    cout<<"h";
  }
  else if(x==8){
    cout<<"i";
  }
  else if(x==9){
    cout<<"j";
  }
  else if(x==10){
    cout<<"k";
  }
  else if(x==11){
    cout<<"l";
  }
  else if(x==12){
    cout<<"m";
  }
  else if(x==13){
    cout<<"n";
  }
  else if(x==14){
    cout<<"o";
  }
  else if(x==15){
    cout<<"p";
  }
  else if(x==16){
    cout<<"q";
  }
  else if(x==17){
    cout<<"r";
  }
  else if(x==18){
    cout<<"s";
  }
  else if(x==19){
    cout<<"t";
  }
  else if(x==20){
    cout<<"u";
  }
  else if(x==21){
    cout<<"v";
  }
  else if(x==22){
    cout<<"w";
  }
  else if(x==23){
    cout<<"x";
  }
  else if(x==24){
    cout<<"y";
  }
  else{
    cout<<"z";
  }
}

int main(void){
  long long  i,j;
  long long tmp=0;
  long long res;
  long k;
  cin>>k;
  long long base[13];
  long long order[13];

  base[0]=1;
  order[0]=0;

  for(i=1;i<13;i++){
    base[i]=pow(26,i);
    order[i]=order[i-1]+base[i];
    if(k<order[i]){
      break;
    }
    else if(k==order[i]){
      for(;i>0;i--){
        cout<<"z";
      }
      cout<<endl;
      return 0;
    }
  }

  tmp=k-order[i-1]-1;

  for(i=i-1;i>=0;i--){
    res=tmp/base[i];
    if(i==0){
      func(res);
    }
    else{
      func(res);
    }
    tmp=tmp%base[i];
  }

  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n, m; cin >> n >> m;
    if (n % m == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n,r;cin >> n >> r;
    if(n>=10)
    {
        cout << r << endl;
        return 0;
    }else
    {
        cout << r+100*(10-n) << endl;
    }

}


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

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

  int hund, ten, one, ans;
  for (int i=n ; ; i++){
    hund = i/100;
    ten = (i-hund*100)/10;
    one = i-hund*100-ten*10;
    if (hund == ten && ten == one){
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}

#include<bits/stdc++.h>

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fwd(i,a,n) for(int i=a;i<=n;i++)
#define bak(i,a,n) for(int i=a;i>=n;i--)
#define all(v) v.begin(),v.end()
#define pb push_back
#define lop '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll mod1=998244353;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ull gcd(ull x,ull y){
   if(y==0)return x;
   return gcd(y,x%y);
}
//                                         EXTENDED_EUCLID
vector<ll>extended_Euclid(ll a,ll b){
    vector<ll>v(3);
    if(b==0){
        v[0]=a;v[1]=1;v[2]=0;
        return v;
    }
    else{
         vector<ll>v1 = extended_Euclid(b,a%b);    //recursive call
         v[0]=v1[0];
         v[1]=v1[2];
         v[2]=v1[1]-(a/b)*v1[2];
         return v;
    }
}
                                          // DFS ( number of connected components  )
//vector<vector<ll> >adj(200001);
//bool visited[200001];
/*ll dfs(int x,int c){                         // x - > node      c - > number of edges in the component
    if(visited[x])return c;
    else{
        visited[x]=true;
        int y=c;
        for(int i=0;i<adj[x].size();i++){
            if(!visited[adj[x][i]]){
                c+=1;
                int d=dfs(adj[x][i],y);
                c+=d;
            }
        }
        return c;
    }
}
*/
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
                               // Binary Search
/*
ll bin_search(ll y){
  while(lo<hi){
    x=lo+(hi-lo)/2;
    if(condition){
            .....
    }
    else{
                  // increase lo or decrease hi suitably
            }
   }
}
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        string s;
        cin>>s;
        if(s[0]==s[1] && s[0]==s[2])cout<<s<<endl;
        else{
            if(s[1]>s[0]){
                char x=s[0];
                x++;
                cout<<x<<x<<x<<endl;
            }
            else{
                if(s[1]==s[0]){
                if(s[2]<s[1])cout<<s[0]<<s[0]<<s[0]<<endl;
                else{
                    char x=s[0];
                    x++;
                    cout<<x<<x<<x<<endl;
                }
                }
                else{
                    cout<<s[0]<<s[0]<<s[0]<<endl;
                }
            }
        }
    }

}
/* Be careful about integer ranges;
   Check the corner cases before submitting.
*/


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, k = 0, ans = 0;
	string s;
	cin >> s;
	vector<vector<ll>> dp(s.size() + 1, vector<ll>(2, 0));
	dp[0][1] = 1;
	rep(i, s.size()) {
		int n = s[i] - '0';
		dp[i + 1][0] = min(dp[i][0] + n, dp[i][1] + 10 - n);
		dp[i + 1][1] = min(dp[i][0] + n + 1, dp[i][1] + 10 - n - 1);
	}
	cout << dp[s.size()][0] << "\n";
	return 0;
}

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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  string S;
  cin >> S;
  ll ans = 0;
  int N = S.size();
  bool flag = false;
  REPR(i, N-1){
    int d = S[i] - '0';
    if(flag) d++;
    flag = false;
    if(d < 5){
      ans += d;
    }
    else if(d > 5){
      ans += 10 - d;
      flag = true;
    }
    else{
      if(i != 0 && S[i-1] >= '5'){
        ans += d;
        flag = true;
      }
      else{
        ans += d;
      }
    }
  }
  if(flag) ans++;
  cout << ans << endl;
  return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,hang[8],lie[8],zuo[15],you[15];//标记行，列，斜下，斜上
int book[8][8];//控制输出
void print()
{

    for(int i=0; i<8; i++)
    {
        for(int j=0; j<8; j++)
        {
            if(book[i][j])
            {
                if(hang[i]!=j)
                    return ;
            }
        }
    }
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            if(hang[i]==j)
                printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}
void dfs(int x)
{
    if(x==8)//判断输出
    {
        print();//输出后直接返回
        return ;
    }
    for(int i=0; i<8; i++)
    {
        if(lie[i]==1||zuo[i+x]==1||you[x-i+8-1]==1)
        {
            continue;
        }
        hang[x]=i;
        lie[i]=zuo[i+x]=you[x-i+8-1]=1;//标记列，斜下，斜上
        dfs(x+1);//往下递归
        hang[x]=lie[i]=zuo[x+i]=you[x-i+8-1]=-1;//取消标记
    }
    return ;
}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(hang,-1,sizeof(hang));
        memset(lie,-1,sizeof(lie));
        memset(zuo,-1,sizeof(zuo));
        memset(you,-1,sizeof(you));
        memset(book,0,sizeof(book));
        int a,b;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&a,&b);
            book[a][b]=1;
        }
        dfs(0);
    }
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>

#define int long long
#define dotimes(i, n) for (int i : range(n))

using namespace std;

class range {
  class iterator {
    int i, s;
  public:
    iterator(int i, int s): i(i), s(s) {}
    int& operator*() {
      return i;
    }
    void operator++() {
      i += s;
    }
    bool operator!=(iterator const& that) {
      return i < that.i;
    }
  };
  iterator b, e;
public:
  range(int e): b({0, 1}), e({e, 1}) {}
  range(int b, int e): b({b, 1}), e({e, 1}) {}
  range(int b, int e, int s): b({b, s}), e({e, s}) {}
  iterator begin() {
    return b;
  }
  iterator end() {
    return e;
  }
};

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

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

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

signed main() {
  const int k = rint();
  int rf[8] = {}, p[8 - k];
  bool cf[8] = {};
  dotimes(i, k) {
    int r = rint();
    int c = rint();
    rf[r] = c + 1;
    cf[c] = true;
  }
  for (int i = 0, j = 0, c = 0; i < 8; i++)
    if (!rf[i]) {
      while (cf[c])
        c++;
      p[j++] = ++c;
    }
  int a[8];
  for (;; next_permutation(p, p + 8 - k)) {
    for (int i = 0, j = 0; i < 8; i++)
      a[i] = rf[i] ? rf[i] : p[j++];
    dotimes(i, 8)
      dotimes(j, i)
        if (abs(a[j] - a[i]) == abs(j - i))
          goto failed;
    break;
  failed:
    ;
  }
  dotimes(i, 8) {
    dotimes(j, 8)
      putchar(a[i] == j + 1 ? 'Q' : '.');
    putchar('\n');
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);

    int d,t,s;
    cin >> d >> t >> s;

    if((((d%s) == 0) ? (d/s) : ((d+(s-(d%s)))/s)) > t){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

#include<iostream>

using namespace std;

int main(void)
{
	int D,S,T;
	cin>>D>>T>>S;

	int s=T*S;
	if(s>=D){
		cout<<"Yes";
	} else{
		cout<<"No";
	}

	return 0;
}


// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<int> eratosthenes(const int &n) {
  vector<int> v(n);
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < n; i++) {
    if (v[i]) {
      for (int j = i * 2; j < n; j += i) {
        v[j] = false;
      }
    }
  }
  return v;
}

void solve() {
  int n;
  while (cin >> n, n) {
    vi v = eratosthenes(n + 1);
    vi w;
    rep(i, v.size()) if (v[i]) w.pb(i);
    reverse(all(w));
    loop(i, 1, w.size()) {
      if (w[i - 1] == w[i] + 2) {
        cout << w[i] << ' ' << w[i - 1] << endl;
        break;
      }
    }
  }
}

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

int main(){
  int h,w;
  int i,j;
  int flag;
  while(cin>>h>>w,h|w){
    int taikaku;
    int tmph=1111,tmpw=1111;
    taikaku=h*h+w*w;
    flag=false;
    for(i=1;i<150;i++){
      for(j=1;j<150;j++){
	//if(i==4&&j==8) cout<<"a"<<endl;
	if(i>=j||(i==h&&j==w)) continue;
	if(i*i+j*j==taikaku) {
	  if(h<i){
	    tmph=i;
	    tmpw=j;
	    flag=true;
	    break;
	  }
	}
	else if(i*i+j*j>taikaku&&i*i+j*j<tmph*tmph+tmpw*tmpw) {
	  tmph=i;
	  tmpw=j;
	}
      }
      if(flag) break;
    }
    cout<<tmph<<" "<<tmpw<<endl;
  }
  return 0;
}


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

int main()
{

	int n = 1;
	std::cin >> n;

	while (n)
	{
		std::vector<int32_t> num_list{};

		while (n--)
		{
			int tmp = 0;
			std::cin >> tmp;
			num_list.push_back(tmp);
		}

		std::vector<int32_t> comfarm_list{};
		std::vector<int32_t> sum_list{};
		for( auto num : num_list )
		{
			for (auto& sum : sum_list)
			{
				if (num < 0)
				{
					comfarm_list.push_back(sum);
				}
				sum += num;
			}
			sum_list.push_back(num);
		}

		for (auto sum : sum_list)
		{
			comfarm_list.push_back(sum);
		}

		int32_t max_sum = *( std::max_element(comfarm_list.begin(),comfarm_list.end()) );
		std::cout << max_sum << std::endl;

		std::cin >> n;
	}

	return 0;
}

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

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

    int max_so_far = 0;
    int max_ending_here = 0;

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        max_ending_here = max(max_ending_here + curr, 0);
        max_so_far = max(max_so_far, max_ending_here);
    }

    if (max_so_far == 0) {
        max_so_far = *max_element(a.begin(), a.end());
    }
    return max_so_far;
}

int main(int argc, char* argv[])
{
    //freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    while (n != 0) {
        int ans = do_stuff(n);
        printf("%d\n", ans);
        scanf("%d", &n);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

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

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC005A();

#if 1
int main()
{
	AGC005A();
	fflush(stdout);
	return 0;
}
#endif

static void AGC005A()
{
	std::string orgs;
	std::cin >> orgs;

	int sCount = 0, eraseCount = 0;
	int len = orgs.length();
	for (int i = 0; i < len; i++) {
		if (orgs[i] == 'S') {
			sCount++;
		}
		else {
			if (sCount) {
				sCount--;
				eraseCount += 2;
			}
		}
	}
	printf("%d\n", len - eraseCount);
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int c = 0;
  rep(i, s.size()) {
    if (s[i] == 'T') ++c;
    else --c;
    ans = max(ans, 2 * c);
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i = (s);i<(int)(n);i++)

int main(){
    int n , k;
    cin >> n >> k;
    int s , t;
    s = k + n;
    t = k - n + 1;
    rep2(i,t,s)cout << i << " " ;
}

#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;

int main(){
    int n,y;
    cin>>n>>y;
    int ans[]={-1,-1,-1};
    bool f=true;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+j<=n){
                int k=n-i-j;
                int val=i*10000+j*5000+1000*k;
                if(val==y){
                    ans[0]=i;
                    ans[1]=j;
                    ans[2]=k;
                    f=false;
                    break;
                }
            }
        }
        if(!f) break;
    }
    cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<endl;

}


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

// ref : https://atcoder.jp/contests/jsc2019-qual/submissions/16521703

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    char c = 'W';
    rep(i, 2 * n){
        if (s[i] != c){
            t += 'L';
            if (c == 'W') c = 'B';
            else c = 'W';
        }
        else {
            t += 'R';
            if (c == 'W') c = 'B';
            else c = 'W';
        }
    }

   int cnt = 0;
    rep(i, 2 * n) cnt += (t[i] == 'L');
    if (cnt != n) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    ll l = 0;
    rep(i, 2 * n){
        if (t[i] == 'L'){
            l++;
        }
        else {
            ans *= l;
            ans %= MOD;
            l--;
        }
    }

    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    constexpr ModFact() : fact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
    }
};

ModFact<100000, ll, MOD> fact;

ll N, M, ans = 1;
int tmp, cnt = 0;
constexpr ll th = 1LL<<45;
char S[200000];

int main() {
    scanf("%lld\n", &N);
    M = N << 1;
    fread_unlocked(S, 1, M, stdin);
	for(size_t i = 0; i < M;) {
		tmp = (S[i++]=='B') + cnt;
		if(tmp&1) cnt++;
		else {
            ans *= cnt;
            if(ans > th) ans %= MOD;
            if(--cnt < 0) break;
        }
	}
    ans = cnt == 0 ? ((ans % MOD) * fact.fact[N]) % MOD : 0;
    printf("%lld\n", ans);
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi v(n);
  rep(i,n) cin>>v[i];
  sort(all(v));
  for(i=1;i<=v[0];i++){
    int c=0;
    rep(j,n)if(v[j]%i==0)c++;
    if(n==c)cout<<i<<endl;
  }
}

#include <cstdio>

int n,a[3];

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

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}
	int g;
	if(n == 2){
		g = gdb(a[0],a[1]);
	}
	else{
		g = gdb(gdb(a[0],a[1]),a[2]);
	}
	for(int i = 1; i <= g/2; i++){
		if(g % i == 0){
			printf("%d\n",i);
		}
	}
	printf("%d\n",g);

	return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{

    lint h, w, a, b;

    scanf("%lld", &h);
    scanf("%lld", &w);
    scanf("%lld", &a);
    scanf("%lld", &b);

    for (int i = 0; i < h; ++i)
    {
        if (i < h - b)
            printf("%s\n", (std::string((w - a), '1') + std::string(a, '0')).c_str());
        else
            printf("%s\n", (std::string((w - a), '0') + std::string(a, '1')).c_str());
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ulli unsigned long long int
#define ld long double
#define endl "\n"
using namespace std;

void solve() {
    int a, b, m;
    cin >> a >> b >> m;

    vector<int> price_a(a);
    vector<int> price_b(b);

    int min_a = INT_MAX;
    for (int& x: price_a) {
        cin >> x;
        min_a = min(min_a, x);
    }
    int min_b = INT_MAX;
    for (int& x: price_b) {
        cin >> x;
        min_b = min(min_b, x);
    }

    int ans = min_a + min_b;

    int x, y ,z;
    for (int i = 0; i < m; i++) {
        cin >> x >> y >> z;
        ans = min((price_a[x-1] + price_b[y-1] - z), ans);
    }

    cout << ans << endl;

}

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

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

    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}


#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++)
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {
		int base[3];
		int cnt = 0;
		int out = 0;
		rep(i123, 3) { base[i123] = 0; }
		while (true) {
			string thistime;
			cin >> thistime;
			if (thistime == "HIT") {
				cnt += base[2];
				base[2] = base[1];
				base[1] = base[0];
				base[0]=1;
			}
			else if (thistime == "OUT") {
				out++;
				if (out == 3) { break; }
			}
			else {
				cnt += base[2] + base[1] + base[0] + 1;
				base[2] = base[1] = base[0] = 0;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using i64 = long long;
using f64 = double;
using pll = pair<i64, i64>;
using pii = pair<int, int>;
using ptx = pair<f64, f64>;

i64 mp[256];

int main() {
#ifdef HOME
    freopen("agc019b.in", "r", stdin);
    freopen("agc019b.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string str;
    cin >> str;
    for (auto i: str)
        mp[i]+= 1;

    i64 ans = str.size() * (str.size() - 1) / 2;
    for (char ch = 'a'; ch <= 'z'; ++ch)
        ans-= mp[ch] * (mp[ch] - 1) / 2;

    cout << 1 + ans << endl;

    return 0;
}


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

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int N, M, X, Y;
    io.read(N, M, X, Y);
    vector<int> x(N);
    vector<int> y(M);
    for(int i = 0; i < N; i++){
        io.read(x[i]);
    }
    for(int i = 0; i < M; i++){
        io.read(y[i]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if(X < Y && x.back() < y.front() && X < y.front() && x.back() < Y) cout << "No War";
    else cout << "War";
    return 0;
}

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

int main(void)
{
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    int mx = *max_element(x.begin(), x.end());
    int mn = *min_element(y.begin(), y.end());
    string ans = "War";
    for (int z = -99; z <= 100; z++)
    {
        if (X < z && z <= Y && mx < z && z <= mn)
            ans = "No War";
    }
    cout << ans << endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s) {
    vector<long long> dist(g.size(), INF);
    using Pi = pair<long long, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
    while (!que.empty()) {
        long long cost; int u; tie(cost, u) = que.top(); que.pop();
        if (dist[u] < cost) continue;
        for (auto &e: g[u]) {
            int v; long long nc; tie(v, nc) = e;
            if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v);
        }
    }
    return dist;
}

int main() {
    int n, k;
    while (cin >> n >> k, n) {
        Graph g(n);
        while (k--) {
            int com; cin >> com;
            if (com == 0) {
                int a, b; cin >> a >> b; a--, b--;
                auto res = dijkstra(g, a)[b];
                cout << (res == INF ? -1 : res) << endl;
            } else if (com == 1) {
                int c, d, e; cin >> c >> d >> e; c--, d--;
                g[c].emplace_back(d, e);
                g[d].emplace_back(c, e);
            }
        }
    }
    return 0;
}

#include<stdio.h>
#define INF 100000001
int n,m;
int i,j,k;
int t[100][100];
int r,a,b,c;
bool used[100];
int d[100];
int ans;

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

int solve(int a,int b){
	int v;
	while(1){
		v=-1;
		for(k=0;k<n;k++)if(!used[k]&&(v==-1||d[k]<d[v]))v=k;
		if(d[v]==INF||v==-1)break;
		used[v]=true;
		for(k=0;k<n;k++){
			if(t[v][k]!=INF)d[k]=min(d[k],d[v]+t[v][k]);
		}
	}
	return d[b];
}
int main(){
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0&&m==0)return 0;
		for(i=0;i<n;i++)for(j=0;j<n;j++)t[i][j]=INF;
		for(i=0;i<m;i++){
			scanf("%d",&r);
			if(r==1){
				scanf("%d %d %d",&a,&b,&c);
				t[a-1][b-1]=min(t[a-1][b-1],c);
				t[b-1][a-1]=min(t[b-1][a-1],c);
			}
			if(r==0){
				scanf("%d %d",&a,&b);
				for(j=0;j<n;j++){
					used[j]=false;
					d[j]=INF;
				}
				d[a-1]=0;
				ans=solve(a-1,b-1);
				if(ans==INF)printf("-1\n");
				else printf("%d\n",ans);
			}
		}
	}
}


#include <bits/stdc++.h>
#define l first
#define r second
using namespace std;
typedef pair<int, int> ii;

ii p[100005];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> p[i].l >> p[i].r;
	int l = 0, r = 1e9;
	int x, y;
	for (int i = 0; i < N; ++i) {
		if (p[i].l > l) {
			l = p[i].l;
			x = i;
		}
		if (p[i].r < r) {
			r = p[i].r;
			y = i;
		}
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(max(p[i].r - p[i].l + 1, 0), ans);
	}
	ans += max(r - l + 1, 0);
	if (x == y) {
		cout << ans << '\n';
		return 0;
	}

	sort(p, p + N, [](const ii& a, const ii& b) { return a.r < b.r || (a.r == b.r && a.l > b.l); });
	int s = 0;
	for (int i = 0; i < N - 1; ++i) {
		s = max(p[i].l, s);
		ans = max(max(r - s + 1, 0) + max(p[i + 1].r - l + 1, 0), ans);
	}
	cout << ans << '\n';
}

#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> poly;
#define pb push_back
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline ll readl() {
  ll ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline int Read(char*s) {
  int tp=0;
  char ch=gc();
  while(!isdigit(ch)&&!isalpha(ch)) ch=gc();
  while(isdigit(ch)||isalpha(ch)) s[++tp]=ch,ch=gc();
  return tp;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
  inline int sqr(int a) { return mul(a,a); }
  inline int cub(int a) { return (ll)a*a%mod*a%mod; }
}
using namespace modular;
template<typename T> inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T> inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T> inline T gcd(T a,T b) { T t;while(b)t=a,a=b,b=t-t/a*a;return a; }
template<typename T> inline T Abs(T x) { return x<0?-x:x; }
inline int rd() { return rand()|(rand()<<15); }
const int N=5e5+5;
int n,pre[N],suf[N];
pii a[N];
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read();
  for(ri i=1;i<=n;++i) a[i].fi=read(),a[i].se=read();
  sort(a+1,a+n+1);
  pre[0]=0x3f3f3f3f,suf[n]=0x3f3f3f3f;
  for(ri i=1;i<n;++i) pre[i]=min(pre[i-1],a[i].se);
  for(ri i=n-1;i;--i) suf[i]=min(suf[i+1],a[i].se);
  int res=0;
  for(ri mn,r1,r2,t,i=1;i<n;++i) {
    r1=a[i].se,r2=min(max(suf[i+1],a[n].fi-1),a[n].se);
    t=(r1-a[i].fi+1)+(r2-a[n].fi+1);
    mn=pre[i-1];
    ckmax(res,t-max(0,min(r1-max(a[i].fi-1,mn),r2-max(a[n].fi-1,mn))));
  }
  cout<<res;
  return 0;
}


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

long long N, M, K;
long long res = 0;

// mod. m での a の逆元 a^{-1} を計算する
long long Modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long ModComb(long long n, long long a, long long mod){
  long long i = 0;
  long long res = 1;
  while(a > 0){
    res *= ((n-i) * Modinv(a, MOD)) % MOD;
    res %= MOD;
    --a; ++i;
  }

  return res;
}

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

  long long MC = ModComb(N * M - 2, K - 2, MOD);

  for(int d = 1; d < N; d++)
    res = ((d * ((((N-d) * M * M) * MC) % MOD)) % MOD + res) % MOD;

  for(int d = 1; d < M; d++)
    res = ((d * ((((M-d) * N * N) * MC) % MOD)) % MOD + res) % MOD;

  cout << res << 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;
using P = pair<int, int>;

int const MOD = 998244353;

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

int main() {
    ll N;
    cin >> N;
    ll MAX = 0;
    vector<ll> D(N, 0);
    rep(i, N) {
        ll d;
        cin >> d;

        if ((i == 0 && d != 0) || (i != 0 && d == 0)) {
            cout << 0 << endl;
            return 0;
        }

        MAX = max(MAX, d);
        ++D[d];
    }

    ll ans = 1;
    rep(i, MAX + 1) {
        if (i == 0) continue;

        if (D[i] == 0) {
            ans = 0;
            break;
        }

        ans = (ans * modpow(D[i - 1], D[i])) % MOD;
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
using namespace std;
typedef long long ll;
int N;
map<ll, int> h;
vector<ll> v;
string s;
pair<ll, ll> frac[200100];
ll cnt[110][110];

pair<ll, ll> getFrac(string &s) {
  ll x = 0, y = 1;
  bool dec = false;
  for(int i=0;i<s.size();++i) {
    if(s[i] == '.') {
      dec = true;
      continue;
    }
    x = x*10 + (s[i] - '0');
    if(dec) y = y*10;
  }
  ll d = __gcd(x, y);
  x /= d; y /= d;
  if(!h[y]) {
    h[y] = 1;
    v.pb(y);
  }
  return mp(x, y);
}

int main() {
  cin>>N;
  ll ret = 0;
  for(int i=0;i<N;++i) {
    cin>>s;
    frac[i] = getFrac(s);
  }
  sort(v.begin(), v.end());
  for(int i=0;i<v.size();++i) h[v[i]] = i;
  for(int i=0;i<N;++i) {
    ll a = frac[i].fs, b = frac[i].sc;
    for(int j=0;j<v.size();++j) {
      if(a % v[j] == 0) {
        ret += cnt[h[b]][j];
      }
    }
    for(int j=0;j<v.size();++j) {
      if(a % v[j] == 0) {
        ++cnt[j][h[b]];
      }
    }
  }
  cout<<ret<<"\n";
}