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

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

vector<ll> inv,fact,invfact;
void setupCombination(ll n_max,ll mod){
    fact.resize(n_max+1);
    inv.resize(n_max+1);
    invfact.resize(n_max+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    for(ll i=0;i<n_max;i++){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll getCombination(ll n,ll k,ll mod){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}

/*
max 448,000,000
count_map['0']=0;
for(auto x : count_map) {
    string key = x.first;
    ll value = x.second;
}
*/
ll getMod(ll value,ll mod){
    if(value == 0) return 0;
    if(mod==0) return -1;
    value %= mod;
    if(value<0) value += mod;
    return value;
}
int main(){

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

    cin >> N;
    cin >> M;
    cin >> K;

    ll allnum = N*M;
    setupCombination(allnum+10,MOD);
    ll base = getCombination(allnum-2,K-2,MOD);
    base = getMod(base,MOD);

    ll ans = 0;
    for( ll yoko = 0 ; yoko <N ; yoko++ ){
        for( ll tate = 0 ; tate <M ; tate++ ){
            ll count = (N-yoko) * (M-tate);
            if(tate*yoko>0) count *=2;
            ll distance = yoko + tate;
            //cout << distance << " : " << count << endl;
            ll dA = count * distance;
            dA = getMod(dA,MOD);

            ans += dA;
            ans = getMod(ans,MOD);
        }
    }

    ans = ans * base;
    ans = getMod(ans,MOD);
    cout << ans << endl;

}

#include <iostream>
int main(){
    int n, x, t; std::cin >> n >> x >> t;
    std::cout << (n + x - 1) / x * t << '\n';
}


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

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

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

const int N = 1e5+23;

vector<int> g[N], ans;
bool bio[N];
int parent[N];

void dfs(int u) {
  bio[u] = true;
  for (int v: g[u]) {
    if (bio[v]) continue;
    dfs(v);
  }
  ans.push_back(u);
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int u, v, i = 0; i < n-1+m; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i) {
    if (bio[i]) continue;
    dfs(i);
  }
  for (int u: ans)
    for (int v: g[u])
      if (!parent[v])
	parent[v] = u;
  for (int i = 1; i <= n; ++i) printf("%d\n", parent[i]);
}

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

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI A(N-1+M),B(N-1+M);
  rep(i,N-1+M) cin>>A[i]>>B[i];
  VVI X(N,VI(0));
  VI I(N);
  rep(i,N-1+M){
    X[A[i]-1].pb(B[i]-1);
    I[B[i]-1]++;
  }
  int S=0;
  rep(i,N) if(I[i]==0) S=i;
  VI T(0);
  T.pb(S);
  queue<int> Q;
  Q.push(S);
  VI F(N);
  F[S]++;
  while(!Q.empty()){
    int now=Q.front();
    Q.pop();
    rep(i,X[now].size()){
      int nxt=X[now][i];
      if(!F[nxt]){
        I[nxt]--;
        if(!I[nxt]){
          Q.push(nxt);
          T.pb(nxt);
        }
      }
    }
  }
  VI Z(N);
  rep(i,N){
    int now=T[i];
    if(!Z[now]) Z[now]=1;
    rep(j,X[now].size()){
      int nxt=X[now][j];
      Z[nxt]=max(Z[nxt],Z[now]+1);
    }
  }
  VI ans(N);
  rep(i,N){
    rep(j,X[i].size()){
      int nxt=X[i][j];
      if(Z[i]+1==Z[nxt]) ans[nxt]=i+1;
    }
  }
  ans[S]=0;
  rep(i,N) cout<<ans[i]<<endl;
}


#include <stdio.h>

int main(){
    int num, angka1, angka2, angka3;
    scanf("%d", &num);

    angka1 = num/100;
    angka2 = (num - angka1 * 100)/10;
    angka3 = num % (angka1 * 100 + angka2 * 10);
if(angka1 == 7 || angka2 == 7 || angka3 == 7){
    puts("Yes");
} else{
    puts("No");
}
    return 0;
}

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

int f(ll a,ll b)
{
	return (int)max(log10(a),log10(b));
}

int main()
{
	ll N;
	cin>>N;
	int ans=10;
	for(int i=1;i<sqrt(N)+1;i++)
	{
		if(N%i!=0) continue;
		ll k=N/i;
		int v=f(i,k);
		ans=min(ans,v);
	}
	cout<<ans+1<<endl;
	return 0;
}


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

int main(void)
{
	int i, j;
	int n;
	int len;
	char str[1024];

	scanf("%d\n", &n);

	for (j = 0; j < n; j++){
		fgets(str, 1024, stdin);

		len = strlen(str);
		for (i = 0; i < len; i++){
			if (strncmp(&str[i], "Hoshino", 7) == 0){
				strncpy(&str[i], "Hoshina", 7);
			}
		}
		printf("%s", str);
	}

	return (0);
}

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n;
	string str;

	cin >> n;
	cin.ignore();
	while (n > 0){
		getline(cin, str);
		int len = 0;
		while (1){
			len = str.find("Hoshino", len);
			if (len == -1)  break;
			str[len + 6] = 'a';
		}
		cout << str << endl;
		n--;
	}
	return (0);
}


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  int rmin = 2e9, lmax = 0;
  vector<pair<int, int>> lr;
  rep(i, n) {
    int l, r;
    cin >> l >> r;
    r++;
    lr.emplace_back(l, r);
    amin(rmin, r);
    amax(lmax, l);
  }
  int ans = 0;
  {
    int sum = 0;
    sum += max(rmin - lmax, 0);
    int ma = 0;
    rep(i, n) {
      int l, r;
      tie(l, r) = lr[i];
      amax(ma, r - l);
    }
    sum += ma;
    ans = sum;
  }
  {
    sort(all(lr));
    reverse(all(lr));
    int rr = lr[0].second;
    reps(i, n - 1) {
      int l, r;
      tie(l, r) = lr[i];
      amax(ans, max(rmin - l, 0) + max(rr - lmax, 0));
      amin(rr, r);
    }
  }
  cout << ans << endl;
}

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

int n, T;
P a[3300];
int dp[3300][3300];

void solve()
{
	cin >> n >> T;
	REP(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);

	for (int i = 0; i < n; i++) {
		for (int t = 0; t < T; t++) {
			dp[i + 1][t] = max(dp[i + 1][t], dp[i][t]);
			if (t - a[i].first >= 0) dp[i + 1][t] = max(dp[i + 1][t], dp[i][t - a[i].first] + a[i].second);
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, dp[i][T - 1] + a[i].second);
	}

	cout << ans << endl;
}

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


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

int n,m,a[300][300],ans=999;
bool ok[301];

int main(){
    cin>>n>>m;
    rep(i,n)rep(j,m)cin>>a[i][j];
    rep(k,m){
        int x[301]={};
        rep(i,n){
            int j=0;
            while(ok[a[i][j]])j++;
            x[a[i][j]]++;
        }
        int X=1;
        for(int i=1;i<=m;i++){
            if(x[X]<x[i])X=i;
        }
        ans=min(x[X],ans);
        ok[X]=1;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
#define DEBUG5(var0, var1, var2, var3, var4) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG4(var1,var2,var3,var4); }
#define DEBUG6(var0, var1, var2, var3, var4, var5) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG5(var1,var2,var3,var4,var5);}
typedef long long ll;

#define MAX_V 100100
int V;
vector <pair <int,ll> > edge[MAX_V];
vector <pair <int,ll> > Redge[MAX_V];
vector <int> vs;
bool used[MAX_V];
int cmp[MAX_V];
void reverse_edge(){
  rep2(i,1,V+1){//1-indexedにしてます
    rep(j,sz(edge[i])){
      Redge[edge[i][j].fir].pb(mp(i,edge[i][j].sec));
    }
  }
}

void dfs(int now){
  used[now] = true;
  rep(i,sz(edge[now])){
    if(!used[edge[now][i].fir]){
      dfs(edge[now][i].fir);
    }
  }
  vs.pb(now);
}

void rdfs(int now,int k){
  used[now] = true;
  cmp[now] = k;
  rep(i,sz(Redge[now])){
    if(!used[Redge[now][i].fir]){
      rdfs(Redge[now][i].fir,k);
    }
  }
}
int scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  rep2(v,1,V+1){//1-indexed
    if(!used[v]){
      dfs(v);
    }
  }
  memset(used,0,sizeof(used));
  reverse_edge();
  int k = 0;
  for(int i = sz(vs)-1;i >= 0;i--){
    if(!used[vs[i]]){
      k += 1;
      rdfs(vs[i],k);
    }
  }
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> V;
  int E;
  cin >> E;
  rep(i,E){
    int x,y;
    cin >> x >> y;
    x += 1;
    y += 1;
    edge[x].pb(mp(y,1));
  }
  scc();
  int Q;
  cin >> Q;
  rep(i,Q){
    int x,y;
    cin >>  x >> y;
    x += 1;
    y += 1;
    if(cmp[x] == cmp[y]){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }

  return 0;
}

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

#define N 100005

int n, m;

vector<int> to[N];

int dfn[N], low[N], bel[N], tim, cnt;

stack<int> stk;
bitset< N > vis;

void tarjan(int u)
{
	dfn[u] = low[u] = ++tim; stk.push(u); vis.set(u);

	for (auto v : to[u])
	{
		if (!dfn[v])
		{
			tarjan(v);
			low[u] = min(low[u], low[v]);
		}
		else if (vis[v])
			low[u] = min(low[u], dfn[v]);
	}

	if (low[u] == dfn[u])
	{
		int t; ++cnt;
		do
		{
			t = stk.top(); stk.pop();
			bel[t] = cnt; vis.reset(t);
		}
		while (t != u);
	}
}

signed main(void)
{
	cin >> n >> m;

	for (int u, v; m--; )
	{
		cin >> u >> v;
		to[u].push_back(v);
	}

	for (int i = 0; i < n; ++i)
		if (!dfn[i])tarjan(i);

	int q; cin >> q;

	while (q--)
	{
		int x, y;
		cin >> x >> y;
		cout << (bel[x] == bel[y]) << endl;
	}
}


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

int root(vector<int> &r, int a)
{
    if (r[a] == a) return a;
    else return r[a] = root(r, r[a]);
}

int main()
{
    long long N, K, L;
    scanf("%lld%lld%lld", &N, &K, &L);
    vector<int> road, rail;
    for (int i = 0; i <= N; i++) {
        road.push_back(i);
        rail.push_back(i);
    }
    for (int i = 1; i <= K; i++) {
        int p, q;
        scanf("%d%d", &p, &q);
        road[root(road, p)] = root(road, q);
    }
    for (int i = 1; i <= L; i++) {
        int r, s;
        scanf("%d%d", &r, &s);
        rail[root(rail, r)] = root(rail, s);
    }
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= N; i++) {
        mp[make_pair(root(road, i), root(rail, i))]++;
    }
    for (int i = 1; i <= N; i++) {
        printf("%d ", mp[make_pair(root(road, i), root(rail, i))]);
    }
    printf("\n");
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e5 + 3;

int pai[3][T];
int peso[3][T];
vii g[T];
int n,k,l;

void init() {
    for(int i = 0; i < 3; i++)
        for(int j = 0; j <= n; j++) {
            pai[i][j] = j;
            peso[i][j] = 1;
        }
}

int find(int op, int x) {
    return (pai[op][x] == x? x : pai[op][x] = find(op,pai[op][x]));
}

void join(int op, int x, int y) {
    x = find(op,x);
    y = find(op,y);
    if(x == y) return;
    if(peso[op][x] < peso[op][y]) swap(x,y);
    pai[op][y] = x;
    peso[op][x] += peso[op][y];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k >> l;
    init();

    while(k--) {
        int a,b; cin >> a >> b;
        if(find(0,a) != find(0,b)) join(0,a,b);
    }

    while(l--) {
        int a,b; cin >> a >> b;
        if(find(1,a) != find(1,b)) join(1,a,b);
    }

    for(int i = 1; i <= n; i++)
        g[find(0,i)].eb(find(1,i),i);

    for(int i = 1; i <= n; i++) {
        sort(g[i].begin(), g[i].end());
        for(int j = 1; j < g[i].size(); j++)
            if(g[i][j].fi == g[i][j-1].fi)
                join(2,g[i][j].se,g[i][j-1].se);
    }

    for(int i = 1; i <= n; i++) cout << peso[2][find(2,i)] << " ";
    cout << endl;

    return 0;
}


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

bool check(int a,int b,int c)
{
    if((a+b)>c && (c+b)>a && (a+c)>b)
        return true;
    return false;
}

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    int n;
    cin>>n;
    map<ll int,int> mp;
    ll int a;
    int l,ct=0;
    for(l=0;l<n;l++)
    {
        cin>>a;
        mp[a]++;
    }

    if(mp.size()<3)
    {
        cout<<0;
        return 0;
    }

    for(auto i=mp.begin();next(next(i))!=mp.end();i++)
    {
        for(auto j=next(i);next(j)!=mp.end();j++)
        {
            for(auto k=next(j);k!=mp.end();k++)
            {
                if(check(i->first,j->first,k->first))
                    ct+=(i->second*j->second*k->second);
            }
        }
    }

    cout<<ct;
    return 0;
}

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

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

  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L.at(i);

  int total = 0;

  if(N < 3) cout << "0" << endl;
  else
  {
    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.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i))
          {
            continue;
          }
          if(L.at(i) + L.at(j) > L.at(k) && L.at(i) + L.at(k) > L.at(j) && L.at(j) + L.at(k) > L.at(i))
          {
            total++;
          }
        }
      }
    }
    cout << total << endl;
  }
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isLeep(int n){
    if((n%4==0 && n%100!=0) || n%400==0){
        return true;
    }
    else return false;
}

int main() {
    int a[5]={};
    char ch;
    while(cin>>a[0]>>ch>>a[1]>>ch>>a[2]>>ch>>a[3]>>ch>>a[4]){
        sort(a,a+5);
        if( (a[0]==a[1] && a[1]==a[2] && a[2]==a[3]) || (a[1]==a[2] && a[2]==a[3] && a[3]==a[4]) )cout<<"four card"<<endl;
        else if( (a[0]==a[1] && a[1]==a[2] && a[3]==a[4]) || (a[0]==a[1] && a[2]==a[3] && a[3]==a[4]) )cout<<"full house"<<endl;
        else if( (a[0]+1==a[1] && a[1]+1==a[2] && a[2]+1==a[3] && a[3]+1==a[4]) || (a[0]==1 && a[1]==10 && a[2]==11 && a[3]==12 && a[4]==13) )cout<<"straight"<<endl;
        else if( (a[0]==a[1] && a[1]==a[2]) || (a[1]==a[2] && a[2]==a[3]) || (a[2]==a[3] && a[3]==a[4]) )cout<<"three card"<<endl;
        else if( (a[0]==a[1] && (a[2]==a[3] || a[3]==a[4] )) || (a[1]==a[2] && a[3]==a[4]) )cout<<"two pair"<<endl;
        else if( a[0]==a[1] || a[1]==a[2] || a[2]==a[3] || a[3]==a[4] )cout<<"one pair"<<endl;
        else cout<<"null"<<endl;
    }

    return 0;
}

#include <cstdio>
#include <vector>
using namespace std;
int main() {
	int n,num;
	while (scanf("%d",&n)&&n!=0) {
		vector<int> ice(10,0);
		for (int i=0; i<n; i++) {
			scanf("%d",&num);
			ice[num]++;
		}
		for (int i=0; i<10; i++) {
			if (ice[i]==0) {
				printf("-");
			} else {
				for (int j=0; j<ice[i]; j++) printf("*");
			}
			printf("\n");
		}
	}
}


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

int main(void){
    string str;
    while(getline(cin, str)){
        for(int i=0; i<26; i++){
            for(int j=0; j<str.size(); j++){
                if(str[j]!=' ' && str[j]!='.'){
                    str[j]++;
                    if(str[j]>'z') str[j]-=26;
                }
            }
            if(str.find("the")!=string::npos){
                cout<<str<<endl;
                break;
            }else if(str.find("this")!=string::npos){
                cout<<str<<endl;
                break;
            }else if(str.find("that")!=string::npos){
                cout<<str<<endl;
                break;
            }
        }
    }
}

#include<iostream>
#include<iomanip>
#include<memory>
#include<array>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int chipher( string& s )
{
  for ( auto& c : s )
    {
      if ( c >= 'a' && c <= 'y' )
        ++c;
      else if ( c == 'z' )
        c = 'a';
    }
  return 0;
}

int main()
{

  string x;

  while( getline(cin, x) )
    {
      for ( int i = 0; i < 26; ++i )
        {
          if ( x.find( "the" ) != string::npos )
            cout << x << endl;
          else if ( x.find( "this" ) != string::npos )
            cout << x << endl;
          else if ( x.find( "that" ) != string::npos )
            cout << x << endl;
          chipher( x );
        }
    }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    char X[202020];
    scanf("%s", X);
    int l = strlen(X);

    // 2. 'T' が 来たら, stack から 'S' を 取り除く.
    stack<char> st;
    rep(i, l){
        char c = X[i];
        if(st.empty()){
            st.push(c);
            continue;
        }
        char t = st.top();
        if(c == 'T' && t == 'S') st.pop();
        else                     st.push(c);
    }

    // 3. 出力.
    printf("%d\n", st.size());
    return 0;

}

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

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    reverse(s.begin(), s.end());
    ve<int> b(n+1);
    rep(i,n) b[i] = s[i] - '0';
    b[n] = 0;
    rep(i,n){
        if(b[i] >= 6 || (b[i] == 5 && b[i+1] >= 5)){
            b[i] = 10 - b[i];
            b[i+1]++;
        }
    }
    ll ans = 0;
    rep(i,n+1) ans += b[i];
    cout << ans << endl;
    return 0;
}


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

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

int main() {
  ll N,M;
  cin>>N>>M;
  vector<ll> mo(N);
  for(ll i = 0LL; i < N; i++) {
    ll x;
    cin>>x;
    if(i==0LL) mo[i]=x%M;
    else mo[i]=(mo[i-1]+x)%M;
  }
  sort(mo.begin(),mo.end());
  ll ans = 0LL;
  ll k = 0LL;
  for(ll i = 0LL; i < N;i++){
    k++;
    if(i==N-1LL||mo[i]!=mo[i+1LL]){
      if(mo[i]==0LL)ans+=(k+k*(k-1LL)/2LL);
      else ans+=(k*(k-1LL)/2LL);
      k=0LL;
    }
  }
  cout<<ans<<endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
    cin >> n >> m; map<int, int> mp;
    mp[0]++;
    rep(i, n) {
        cin >> x; z += x; z %= m;
        sum += mp[z];
        mp[z]++;
    }cout << sum << endl;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	vector<int> in(n,0);
	vector<int> used(n,0);
	int d[101001]={};
	int ans=0;
	FOR(i,0,n){
		cin>>a[i];
		a[i]--;
		if(i==0){
			if(a[i]!=0){
				ans++;
				a[i]=0;
			}
			continue;
		}
		//g[i].PB(a[i]);
		in[a[i]]++;
	}
	queue<int> q;
	used[0]=1;
	FOR(i,1,n){
		if(in[i]==0)q.push(i);
	}
	while (q.size()) {
		int nw=q.front();
		q.pop();
		int nd=d[nw];
		//cerr<<nw<<" "<<nd<<endl;
		if(used[nw])continue;
		used[nw]=1;
		if(nd>=k-1&&a[nw]!=0){
			ans++;
		}else{
			if(a[nw]!=0)d[a[nw]]=max(d[a[nw]],nd+1);
		}
		in[a[nw]]--;
		if(in[a[nw]]==0)q.push(a[nw]);

	}

	cout<<ans<<endl;

	return 0;
}

#include <stdio.h>

int main() {
    int n, row, col;
    scanf("%d", &row);
    scanf("%d", &col);
    scanf("%d", &n);

    int temp;
    int count = 0;

    if (row > col) {
        temp = row;
    } else {
        temp = col;
    }

    for (int i = 0; i < n; i = i + temp) {
        count++;
    }

    printf("%d\n", count);

    return 0;
}


#include <iostream>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

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

  for (int i = 0; i < Q; ++i) {
    long long q, arg0, arg1;
    cin >> q >> arg0 >> arg1;
    if (q == 0) {
      t.add(arg0, arg1);
    } else {
      cout << t.sum(arg0, arg1) << endl;
    }
  }
  return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=200005;
int n,E1,E2;
struct DSU
{
	int rt[MAXN];
	void init(){for(int i=1;i<=n;i++)rt[i]=i;}
	int findrt(int x){return rt[x]==x?rt[x]:rt[x]=findrt(rt[x]);}
	void merge(int x,int y){rt[findrt(x)]=findrt(y);}
}A,B;
map<int,int> mp[MAXN];
int main()
{
	n=read();E1=read();E2=read();
	A.init();B.init();
	for(int i=1;i<=E1;i++)
	{
		int x=read(),y=read();
		A.merge(x,y);
	}
	for(int i=1;i<=E2;i++)
	{
		int x=read(),y=read();
		B.merge(x,y);
	}
	for(int i=1;i<=n;i++)mp[A.findrt(i)][B.findrt(i)]++;
	for(int i=1;i<=n;i++)pr1(mp[A.findrt(i)][B.findrt(i)]);puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define int ll

main(){
	int a,b,c;

	cin >> a >> b >> c;

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

	return 0;
}

#include <iostream>
using namespace std;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  cout << ((c-a)*(b-c)>0?"Yes":"No") << endl;
  return 0;
}


#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;

bool rec(int n, vector<int>& num, vector<bool>& isPlus) {
  // ベースケース
  if (n == (int) isPlus.size()) {
    int ans = num[0];
    rep(i, (int) isPlus.size()) {
      if (isPlus[i]) {
        ans += num[i + 1];
      } else {
        ans -= num[i + 1];
      }
    }

    if (ans == 7) {
      cout << num[0];
      rep(i, (int) isPlus.size()) {
        if (isPlus[i]) {
          cout << '+' << num[i + 1];
        } else {
          cout << '-' << num[i + 1];
        }
      }
      cout << "=7" << endl;
      return true;
    }

    return false;
  }

  // 再帰ステップ
  isPlus[n] = true;
  if (rec(n + 1, num, isPlus)) return true;
  isPlus[n] = false;
  if (rec(n + 1, num, isPlus)) return true;

  return false;
}

int main(void) {
  int ABCD;
  cin >> ABCD;
  vector<int> num(4);
  rep(i, 4) {
    num[i] = ABCD % 10;
    ABCD /= 10;
  }

  reverse(num.begin(), num.end());

  vector<bool> isPlus(3, true);
  rec(0, num, isPlus);

  return 0;
}

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

class Baseball {
private:
	int out;
	int runner;
	int score;

public:
	//constructor
	Baseball() {
		out = 0;
		runner = 0;
		score = 0;
	}

	//getter
	int getOut() { return out; }
	int getRunner() { return runner; }
	int getScore() { return score; }
	//input OUT
	void execOut() { ++out; }
	//input HIT
	void execHit() {
		if(runner == 3)++score;
		else ++runner;
	}
	//input HOMERUN
	void execHomerun() {
		score += runner + 1;
		runner = 0;
	}

};

int main(){
	int dataSetNum;
	std::cin >> dataSetNum;

	std::vector< Baseball > baseball;
	baseball.resize(dataSetNum);

	for(int i = 0; i < dataSetNum; ++i){

		while(baseball[i].getOut() != 3){
			//input
			std::string tmp;
			std::cin >> tmp;

			if(tmp == "OUT")baseball[i].execOut();
			else if(tmp == "HIT")baseball[i].execHit();
			else if(tmp == "HOMERUN")baseball[i].execHomerun();
		}

	}
	//output
	std::for_each(baseball.begin(), baseball.end(),
    [](Baseball x) { std::cout << x.getScore() << std::endl; } );

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 998244353

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

ll dp[2020][2020];
ll sum;
int K, N;

void init()
{
	cin >> K >> N;
	rep(i, K) {
		dp[N-1][i] = 1;
	}
	rrep(i, N-1) {
		ll a = 0;
		rrep(j, K) {
			a += dp[i+1][j];
			a %= MOD;
			dp[i][j] = a;
		}
	}
	rep(i, K) {
		sum += dp[0][i];
		sum %= MOD;
	}
}

struct comb {
#define MOD_COMB MOD
	vector<ll> fact;
	vector<ll> facti;
	comb(int n) {
		init(n);
	}
	void init(int n) {
		fact.resize(n);
		facti.resize(n);
		fact[0] = 1;
		for (int i = 1; i < n; i++) {
			fact[i] = fact[i-1] * i % MOD_COMB;
		}
		facti[n-1] = po(fact[n-1], MOD_COMB - 2);
		for (int i = n-2; i >= 0; i--) {
			facti[i] = facti[i+1] * (i + 1) % MOD_COMB;
		}
	}
	ll nCr(int a, int b) {
		return (fact[a] * facti[b] % MOD_COMB) * facti[a-b] % MOD_COMB;
	}
private:
	ll po(ll next, int cnt) {
		ll res = 1;
		if (cnt == 0) return 1;
		if (cnt & 1) res = res * next % MOD_COMB;
		return res * po(next * next % MOD_COMB, cnt >> 1) % MOD_COMB;
	}
};

void solve()
{
	vector<ll> res;
	comb co(2020);
	if (K == 1) {
		cout << 0 << endl;
		return;
	}
	int i = 0;
	reps(cnt, 3, K+3) {
		ll hugo = 1;
		ll ans = 0;
		rep(j, i+1) {
			ans += hugo * co.nCr(i+1, j+1) * dp[j*2+1][0];
			ans %= MOD;
			hugo *= -1;
		}
		res.PB(ans);
		res.PB(ans);
		cnt++;
		i++;
	}
	if (K%2) res.pop_back();
	rep(i, res.size()) {
		cout << (sum - res[i] + MOD) % MOD << endl;
	}
	rrep(i, res.size()-1) {
		cout << (sum - res[i] + MOD) % MOD << endl;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
const int md=998244353;
const int mx=4005;
int n,k;
ll exp(ll b, ll n){
	ll res = 1;
	for(;n;n>>=1,(b*=b)%=md)if(n&1)(res*=b)%=md;
	return res;
}
ll fact[mx]={1},invf[mx];
inline void init(int n){
	for(int i=1;i<=n;i++) fact[i]=(fact[i-1]*i)%md;
	invf[n]=exp(fact[n],md-2);
	for(int i=n;i>0;i--) invf[i-1]=(invf[i]*i)%md;
}
inline ll comb(int a,int b){return fact[a]*invf[a-b]%md *invf[b]%md;}
inline ll nkcom(int n,int k){return comb(n+k-1,n);}
inline ll calc(int n,int k,int t){
	ll ret=0;
	rep(i,t+1) ret=(ret+nkcom(n-i,k-t*2+i)*comb(t,i)%md*exp(2,i))%md;
	return ret;
}
int main(){
	scanf("%d%d",&k,&n);
	init(k+n);
	for(int i=1;i<2*k;i++){
		int t=min(i,2*k-i);
		printf("%lld\n",t&1 ?(calc(n-1,k-1,t/2)+calc(n,k-1,t/2))%md:calc(n,k,t/2));
	}
}


#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;

    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    if(a[0]>0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=0;
    rep(i,1,n){
        if(a[i]>a[i-1]+1){
            cout<<-1<<endl;
            return 0;
        }
        else if(a[i]<a[i-1]+1){
            ans+=a[i-1];
        }
    }
    ans+=a[n-1];
    cout<<ans<<endl;
}

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

int S[1000000], cnt = 0;

int sor(int n, int g){
	do{

		g = (g - 1) / 3;
		for(int i = g;i < n;i++){
			int j = i - g, v = S[i];
			while(j >= 0 && v < S[j]){
				//printf("*%d*", j);
				S[j + g] = S[j];
				j -= g, cnt++;
			}
			S[j + g] = v;
		}
	}while(g != 1);
	return 0;
}

int main(){
	int g = 1, n, num = 0;
	scanf("%d", &n);
	for(int i= 0;i < n;i++)scanf("%d", &S[i]);
	while(g <= n)g = g * 3 + 1, num++;
	printf("%d\n", num);
	for(int i= g;i != 1;){
		if(i != g)printf(" ");
		i = (i - 1) / 3;
		printf("%d", i);
	}
	puts("");
	sor(n, g);
	printf("%d\n", cnt);
	for(int i= 0;i < n;i++)printf("%d\n", S[i]);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	ll n,t,x; cin>>n>>t;
	ll px=-1,ans=0;
	for(ll i=0;i<n;i++){
		cin>>x;
		ans+=t;
		if(px!=-1) ans-=max((ll)0,px-x+t);
		px=x;
	}
	cout<<ans;
}

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

bool Less(const string& a, const string& b) {
  if (a.size() != b.size()) return a.size() < b.size();
  return a < b;
}

int main() {
  const vector<int> cost = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  in(int, n, m);

  vector<int> a(m);
  rep(i, m) cin >> a[i];

  vector<string> dp(n + 1);
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int k = i - cost[a[j]];
      if (k < 0 || dp[k] == "" && k != 0) continue;
      string d = char('0' + a[j]) + dp[k];
      if (Less(dp[i], d)) dp[i] = d;
    }
  }
  out(dp[n]);
}


#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{

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

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

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

signed main() {
	int n; cin >> n;
	cin.ignore();
	while (n--) {
		string s;
		getline(cin, s);
		for (int i = 0; i + 6 < s.size(); i++) {
			if (s.substr(i, 7) == "Hoshino")s[i + 6] = 'a';
		}
		cout << s << endl;
	}
	return 0;
}


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

int main() {
  string x, y, z;
  bool s = false;
  bool t = false;
  cin >> x >> y >> z;
  if(x[x.size()-1] == y[0]){s = true;}
  if(y[y.size()-1] == z[0]){t = true;}
  if(s*t == 1){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
}

#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int m, nin, nax;
int p[202];

bool input(){
  cin>>m>>nin>>nax;
  REP(i, m)cin>>p[i];
  return m;
}

void solve(){
  int s=0, b=0;
  FOR(i, nin-1, nax) {
    if(p[i]-p[i+1]>=s){
      b=i+1;
      s=p[i]-p[i+1];
    }
  }
  cout<<b<<endl;
}

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

  while (input()){
      solve();
  }

  return 0;
}


#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

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

  ll n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  if(a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }
  rep(i,n-1){
    if(a[i]+1<a[i+1]){
      cout << -1 << endl;
      return 0;
    }
  }
  ll cnt=0;
  rep(i,n-1){
    if(a[i+1]==a[i]+1)cnt++;
    else cnt+=a[i+1];
  }
  cout << cnt << endl;

}

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

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


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

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

// code starts
#define MOD 1000000007

int main()
{
  int h,w,k;cin>>h>>w>>k;
  vector<vector<ll>> dp(h+1,vector<ll>(w,0));
  dp[0][0]=1;
  int i,j,l;
  for(i=1;i<=h;i++)
  {
    for(j=0;j<(1<<(w-1));j++)
    {
      bool warp=false;
      for(l=0;l<w-2;l++)
      {
        if((j&(1<<l))&&(j&(1<<(l+1))))warp=true;
      }
      if(warp)continue;
      for(l=0;l<w;l++)
      {
        bool con=false;
        if(l>0&&(j&(1<<(l-1))))
        {
          dp[i][l]+=dp[i-1][l-1];
          dp[i][l]%=MOD;
          con=true;
        }
        if(l<w-1&&(j&(1<<l)))
        {
          dp[i][l]+=dp[i-1][l+1];
          dp[i][l]%=MOD;
          con=true;
        }
        if(!con)
        {
          dp[i][l]+=dp[i-1][l];
          dp[i][l]%=MOD;
        }
      }
    }
  }
  cout<<dp[h][k-1]<<endl;
}

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

const int MOD = 1e9 + 7;
int H, W, K;
vector<int> fib;
ll ans;

void input() {
    cin >> H >> W >> K;
}

int solve(int n) {
    if (n < 0) return 1;
    return fib[n];
}

int main() {
    input();
    fib = vector<int>(W);
    fib[0] = 1;
    fib[1] = 2;
    for (int i = 2; i < W; i++) fib[i] = fib[i-1] + fib[i-2];
    vector<ll> w1, w2;
    w1 = vector<ll>(W, 0);
    w1[0] = 1;
    rep(i, H) {
        w2 = vector<ll>(W, 0);
        for (int j = 0; j < W; j++) {
            if (j > 0) w2[j-1] = (w2[j-1] + w1[j] * solve(j-2) * solve(W-j-2)) % MOD;
            w2[j] = (w2[j] + w1[j] * solve(j-1) * solve(W-j-2)) % MOD;
            if (j < W - 1) w2[j+1] = (w2[j+1] + w1[j] * solve(j-1) * solve(W-j-3)) % MOD;
        }
        w1 = w2;
    }
    cout << w1[K-1] << endl;
}


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

typedef pair<string, string> P;

P next_word(string sentence) {
  if (sentence.empty()) return make_pair(string(""), string(""));
  if (sentence[0] == ' ' || sentence[0] == '.') {
    return make_pair("", sentence.substr(1));
  } else {
    P recur = next_word(sentence.substr(1));
    return make_pair(sentence[0] + recur.first, recur.second);
  }
}

bool acceptable(string sentence) {
  P p = next_word(sentence);

  while (! p.first.empty() ) {
    if (p.first == "this" || p.first == "the" || p.first == "that")
      return true;

    p = next_word(p.second);
  }
  return false;
}

char slip(char c) {
  if (c < 'a' || 'z' < c) return c;

  string alphabet = "abcdefghijklmnopqrstuvwxyza";
  int index = (int)(c - 'a');
  return alphabet[index + 1];
}

char slip(char c, int n) {
  for (int i = 0; i < n; i++)
    c = slip(c);

  return c;
}

string slip(string code, int n) {
  string val;
  for (int i = 0, len = code.length(); i < len; i++)
    val += slip(code[i], n);

  return val;
}

string decode(string code) {
  for (int i = 1; i < 27; i++) {
    string sentence = slip(code, i);
    if (acceptable(sentence))
      return sentence;
  }

  return "";
}

int main() {
  string code;
  while ( getline(cin, code) )
    cout << decode(code) << endl;
}

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string stro, str;
  while(getline(cin, stro)){
    for(int i = 0; i < 26; i++){
      str = stro;
      for(int j = 0; j < stro.length(); j++){
	if(str[j] >= 'a' && str[j] <= 'z')
	  if(str[j] + i > 'z')
	    str[j] += i - 26;
	  else
	    str[j] += i;
      }
      if(str.find("the") != string::npos || str.find("this") != string::npos || str.find("that") != string::npos)
	cout << str << endl;
    }
  }
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll k;
	cin>>k;
	vector<ll> vl;
	string s = "~abcdefghijklmnopqrstuvwxyz";
	if(k<=26)
	{
		cout<<s[k]<<endl;
		return 0;
	}
	while(k>=26)
	{
		ll yu = k%26;
		k/=26;
		if(yu == 0)
		{
			yu = 26;
			k--;
		}
		vl.pb(yu);
	}
	if(k>0)
		vl.pb(k);
	reverse(all(vl));
	FOR(i,0,vl.size())
	{
		if(vl[i]>0)cout<<s[vl[i]];
		else cout<<"z";
	}
	cout<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

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

int main() {
  fast();
  string s;
  cin >> s;
  int ans = mxN;
  for (int i = 0; i < s.length() - 2; i++) {
    int diff = abs(
        ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0')) - 753);
    ans = min(ans, diff);
  }
  cout << ans;

  return 0;
}


#include<iostream>

using namespace std;

int main(){
  int n, q, count = 0;
  cin >> n;
  long int S[n];
  for(int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  while(q--){
    long int T;
    cin >> T;
    int i = n;
    while(i--){
      if(S[i] == T){
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

#include<iostream>
using namespace std;
#include<stdio.h>

class dice {
        private:
                int temp_t;
                int temp_e;
                int temp_s;
                int temp_b;
                int temp_w;
                int temp_n;
        public:
                int top;
                int east;
                int south;
                int bottom;
                int west;
                int north;

                dice(int _top, int _east, int _south, int _bottom, int _west, int _north);
                void roll(char dir);
                ~dice();
};

dice::dice(int _top, int _east, int _south, int _bottom, int _west, int _north){
        top = _top;
        east = _east;
        south = _south;
        bottom = _bottom;
        west = _west;
        north = _north;
}

void dice::roll(char dir){
        switch (dir){
                case 'N':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_t;
                        bottom = temp_n;
                        south = temp_b;
                        top = temp_s;
                        break;
                case 'S':
                        temp_n = north;
                        temp_t = top;
                        temp_s = south;
                        temp_b = bottom;
                        north = temp_b;
                        bottom = temp_s;
                        south = temp_t;
                        top = temp_n;
                        break;
                case 'E':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_t;
                        bottom = temp_e;
                        west = temp_b;
                        top = temp_w;
                        break;
                case 'W':
                        temp_e = east;
                        temp_t = top;
                        temp_w = west;
                        temp_b = bottom;
                        east = temp_b;
                        bottom = temp_w;
                        west = temp_t;
                        top = temp_e;
                        break;
                default:
                        cout << "Unknown Roll Command. Quit." << endl;
                        break;
        }
}

dice::~dice(){}

int main(){
        char ch;
        int N, T, E, W, B, S;
        cin >> T >> S >> E >> W >> N >> B;
        scanf("%c", &ch);
        dice diceA(T, E, S, B, W, N);
        for(int i = 0; i < 100; i++) {
                scanf("%c", &ch);
                if(ch == '\n') break;
                diceA.roll(ch);
        }
        cout << diceA.top << endl;
}


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

using namespace std;
int a[200005], b[200005];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = n; i >= 1; --i) {
        scanf("%d", &b[i]);
    }
    bool flag = true;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == b[i]) {
            flag = false;
            for (int j = 1; j <= n; ++j) {
                if (b[j] != a[i] && b[i] != a[j]) {
                    swap(b[j], b[i]);
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                break;
            }
        }
    }
    if (flag) {
        printf("Yes\n");
        for (int i = 1; i <= n; ++i) {
            printf("%d ", b[i]);
        }
    } else {
        printf("No\n");
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

typedef long long Int;

const Int INF = 1e18;

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

    vector<Int> dp0(N, -INF), dp1(N, -INF);

    dp0[0] = 0;
    dp1[0] = A[0];
    dp0[1] = max(A[0], A[1]);

    for(int i = 2; i<N; i++) {
        if (i % 2 == 1) {
            dp0[i] = max(dp1[i-1], A[i]+dp0[i-2]);
        }
        else {
            dp0[i] = max(dp0[i-1], A[i] + dp0[i-2]);
            dp1[i] = A[i] + dp1[i-2];
        }
    }

    cout << dp0[N-1] << endl;
}


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

class Fruit {
  public:
    string name;
    double efficiency;
    Fruit(string _name, double _efficiency):
      name(_name),
      efficiency(_efficiency) {
    }
};

int main() {
  int N;
  while(cin >> N, N) {
    vector<Fruit> fruits;
    for(int n = 0; n < N; ++n) {
      string name;
      cin >> name;
      int seedCost;
      cin >> seedCost;
      int aTime = 0;
      int aFromLeafTime = 0;
      for(int i = 0; i < 5; ++i) {
        int t;
        cin >> t;
        aTime += t;
        if(i > 2) aFromLeafTime += t;
      }
      int nfruit;
      cin >> nfruit;
      int aFruitPrice;
      cin >> aFruitPrice;
      int ngrow;
      cin >> ngrow;
      int tTime;
      tTime = aTime + aFromLeafTime * (ngrow - 1);
      int price;
      price = aFruitPrice * nfruit * ngrow;
      int income;
      income = price - seedCost;
      double efficiency;
      efficiency = (double)income / (double)tTime;
      Fruit fruit(name, efficiency);
      fruits.push_back(fruit);
    }
    sort(fruits.begin(), fruits.end(), [](Fruit left, Fruit right) {
      if(left.efficiency == right.efficiency) return left.name < right.name;
      return left.efficiency > right.efficiency;
    });
    for(int i = 0; i < N; ++i) cout << fruits[i].name << endl; //cout << fruits[i].name << " " << fruits[i].efficiency << endl;
    cout << '#' << endl;
  }
  return 0;
}

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

struct CROPS{
  string name;
  double total;

};

int main(){
  int i,j,n;
  double p,a,b,c,d,e,f,s,m,efficient;
  CROPS crop[51];
   while(1){
    cin >> n;
     if(n==0)break;
    for(i = 0; i < n; i++){
      cin >> crop[i].name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      efficient=(f*s*m-p)/(a+b+c+(d+e)*m);
      crop[i].total=efficient;
    }

    for(i = 0; i < n; i++){
      for(j = 0; j < n-1; j++){
	if(crop[j].total < crop[j+1].total){
	  swap(crop[j],crop[j+1]);
	}
      }
    }

    for(i = 0; i < n; i++){
      for(j = 0; j < n-1; j++){
	if(crop[j].total == crop[j+1].total && crop[j].name>crop[j+1].name){
	  swap(crop[j],crop[j+1]);
	}
      }
    }

    for(i = 0; i < n; i++){
      cout << crop[i].name << endl;
    }

    cout << "#" << endl;
     }
  return 0;
}


#include<stdio.h>
main(){
  int i,d,s;
  while(scanf("%d",&d)!=EOF){
    s=0;
    for(i=0;i<600/d;i++){
      s+=(d*((d*i)*(d*i)));
    }
    printf("%d\n",s);
  }
  return 0;
}

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

int main(void){

	int n;
	while (cin >> n, n){
		vector<int> dp(n + 5);

		dp[0] = 1;
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;
		for (int i = 4; i <= n; i++){
			dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
		}

		cout << (((dp[n] + 9) / 10) + 364) / 365 << endl;

	}

	return 0;
}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int mp[22][22];

int main(){
	int N,M;
	int x[]={0,1,0,-1};
	int y[]={1,0,-1,0};
	while(cin>>N){
		if(N==0)break;
		CLR(mp);
		REP(i,N){
			int tx,ty;
			cin>>tx>>ty;
			mp[tx][ty]++;
		}
		cin>>M;

		int nx=10,ny=10;
		int res=0;
		REP(k,M){

			char d;int l;
			cin>>d>>l;
			int rx,ry;
			if(d=='N'){
				rx=x[0]*l;
				ry=y[0]*l;
			}else if(d=='E'){
				rx=x[1]*l;
				ry=y[1]*l;
			}else if(d=='S'){
				rx=x[2]*l;
				ry=y[2]*l;
			}else{
				rx=x[3]*l;
				ry=y[3]*l;
			}
			if(rx<0||ry<0){
				for(int i=0;i>=rx;i--)for(int j=0;j>=ry;j--){
					if(mp[nx+i][ny+j]!=0){
						mp[nx+i][ny+j]=0;
						//cout<<"!"<<nx+i<<" "<<ny+j<<endl;
						res++;
					}
				}
			}else{
				for(int i=0;i<=rx;i++)for(int j=0;j<=ry;j++){
					if(mp[nx+i][ny+j]!=0){
						mp[nx+i][ny+j]=0;
						//cout<<"!"<<nx+i<<" "<<ny+j<<endl;
						res++;
					}
				}
			}
			nx+=rx;ny+=ry;
		}
		if(res==N)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

#include<stdio.h>
int main(void)
{
  for(;;){
    int houkosu={0};
    int comkosu={0};
    int hou[21][21]={{0},{0}};
    int zahyo[21][21]={{0},{0}};
    int mypox={10};
    int mypoy={10};
    int x={0},y={0};
    int i={0},j={0};
    char dire={0};
    int dis={0};
    int hantei={0};
    char dir[31]={0};
    int di[31]={0};

    scanf("%d",&houkosu);
    if(houkosu==0)
      break;

    for(i=0;i<houkosu;i++){
      scanf("%d %d",&x,&y);
      hou[x][y]=1;
    }

    scanf("%d",&comkosu);

    hou[10][10]=0;
    for(i=0;i<2*comkosu;i++){
      scanf("%c",&dire);
      dir[i/2]=dire;
      scanf("%d",&dis);
      di[(i-1)/2]=dis;
    }

    for(i=0;i<comkosu;i++){

      if(dir[i]=='N'){
        for(j=mypoy+1;j<=mypoy+di[i];j++){
          if(hou[mypox][j]==1)
            hou[mypox][j]=0;
        }
        mypoy+=di[i];
      }else if(dir[i]=='S'){
        for(j=mypoy-1;j>=mypoy-di[i];j--){
          if(hou[mypox][j]==1)
            hou[mypox][j]=0;
        }
        mypoy-=di[i];
      }else if(dir[i]=='E'){
        for(j=mypox+1;j<=mypox+di[i];j++){
          if(hou[j][mypoy]==1)
            hou[j][mypoy]=0;
        }
        mypox+=di[i];
      }else{
        for(j=mypox-1;j>=mypox-di[i];j--){
          if(hou[j][mypoy]==1)
            hou[j][mypoy]=0;
        }
        mypox-=di[i];
      }
    }

    for(i=0;i<21;i++){
      for(j=0;j<21;j++){
        if(hou[i][j]!=0)
          hantei=1;
      }
    }

    if(hantei==0)
      puts("Yes");
    else
      puts("No");

  }
  return 0;
}


#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

int main(){FIN

    ll n; string s;
    cin>>n>>s;
    ll ans=mod;
    vll ws(1,0); vll es(1,0);
    ll cnt=0;
    FOR(i,1,n-1){

        if(s[i-1]=='W') cnt++;
        ws.push_back(cnt);
    }
    cnt=0;
    FORR(i,n-2,0){

        if(s[i+1]=='E') cnt++;
        es.push_back(cnt);
    }
    reverse(ALL(es));
    // REP(i,n){
    //     cout<<ws[i]<<endl;
    // }
    REP(i,n){
        ans = min(ans, es[i]+ws[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;

int a, b, ans;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    for (int i = 0; i < 2; ++i) {
        if (a > b) {
            ans += a;
            --a;
        } else {
            ans += b;
            --b;
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int d=(H2-H1)*60+(M2-M1);
	cout << d-K << endl;

	return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		std::vector<int> num;
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (; x; x /= 10) {
			num.push_back(x % 10);
		}
		while (!num.empty()) {
			putchar(num.back() ^ '0');
			num.pop_back();
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

void solve() {
	int h1, m1, h2, m2, k;
	read(h1), read(m1), read(h2), read(m2), read(k);
	int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
	print(std::max(t2 - t1 - k, 0));
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n>>m)
    {
        a=b=0;
        bool ar[n+5];
        rep(i,n+5)ar[i]=0;
        map<LL,LL>mp;
        while(m--)
        {
            cin>>p>>st;
            if(ar[p])continue;
            if(st=="AC") a++,ar[p]=1;
            else mp[p]++;
        }
        for(auto it=mp.B;it!=mp.E;it++)
        {
            if(ar[it->fi])b+=it->se;
        }
        cout<<a<<sp<<b<<en;
    }
    return 0;
}

#include<algorithm>
using namespace std;

#define MAXN 100000

int AC[MAXN] = {};
int WA[MAXN] = {};

int main()
{
    int ACCount = 0;
    int WACount = 0;
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m; i++)
    {
        int curNum;
        char first, second;
        scanf("%d %c%c", &curNum, &first, &second);
        if(AC[curNum - 1] != 0)
        {
            continue;
        }
        if(first == 'A')
        {
            AC[curNum - 1] = 1;
            WACount += WA[curNum - 1];
            ACCount += 1;
        }
        else
        {
            WA[curNum - 1] += 1;
        }
    }
    printf("%d %d",ACCount, WACount);
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

/*
転倒数を求める
O(NlogN)
*/
int inversion_number(vector<int>dat){
    //座標圧縮
    vector<int>vs;
    for(int i=0;i<dat.size();i++)vs.push_back(dat[i]);
    sort(vs.begin(),vs.end());
    vs.erase(unique(vs.begin(),vs.end()),vs.end());
    for(int i=0;i<dat.size();i++)
        dat[i]=lower_bound(vs.begin(),vs.end(),dat[i])-vs.begin();
    /*
    BIT
    0-indexedで扱う
    点kにxを加算するクエリ、区間[0,x]の和を求めるクエリがO(logN)でできる
    */
    struct binary_indexed_tree{
        vector<int>dat;
        void init(int n){dat=vector<int>(n+1);}
        binary_indexed_tree(int n):dat(n+1){}
        binary_indexed_tree(){}

        void add(int k,int x){
            for(k++;k<dat.size();k+=k&-k)dat[k]+=x;
        }
        int sum(int k){
            int ret=0;
            for(k++;k;k-=k&-k)ret+=dat[k];
            return ret;
        }
    }bit(vs.size());

    int ret=0;
    for(int i=0;i<dat.size();i++){
        ret+=i-bit.sum(dat[i]);
        bit.add(dat[i],1);
    }
    return ret;
}

int N;
int A[100000][3];

signed main(){
    scanf("%lld",&N);
    rep(j,3)rep(i,N)scanf("%lld",&A[i][j]),A[i][j]--;

    vector<int>X[2];
    int x[2]={};
    rep(i,N){
        if(A[i][0]%3)reverse(A[i],A[i]+3),x[i&1]++;
        if(A[i][0]+1!=A[i][1]||A[i][1]+1!=A[i][2]||((A[i][0]/3)&1)!=(i&1)){
            puts("No");
            return 0;
        }
        X[i&1].pb(A[i][0]/3);
    }

    rep(i,2)x[i^1]+=inversion_number(X[i]);
    puts((x[0]%2||x[1]%2)?"No":"Yes");
    return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
short d[22][22][11] ={};
int ans = 100;

void dfs(i_i p, int t) {
    if(t > 10) return;
    rep(i,4){
        i_i m = p;
        if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) continue;
        while(1) {
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 0) break;
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 4) {
                ans = min(ans,t);
                break;
            }
            if(d[m.first+dx[i]][m.second+dy[i]][t] == 2) {
                rep(j,22) {
                    rep(k,22) {
                        d[j][k][t+1] = d[j][k][t];
                    }
                }
                d[m.first+dx[i]][m.second+dy[i]][t+1] = 1;
                dfs(make_pair(m.first,m.second),t+1);
                break;
            } else {
                m.first += dx[i], m.second += dy[i];
            }
        }
    }
}

int main() {
    while(1) {
        int w,h;
        i_i s;
        ans = 100;
        memset(d,0,sizeof(d));
        cin >> w >> h;
        if(w==0) break;
        FOR(j,1,h+1) {
            FOR(i,1,w+1) {
                cin >> d[i][j][1];
                if(d[i][j][1] == 2){s = make_pair(i,j); d[i][j][1] = 0; }
                d[i][j][1] += 1;
            }
        }
        dfs(s,1);
        ans == 100? cout << -1 << endl:cout << ans << endl;
    }
    return 0;
    }

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

  int MAX = max(A, B), MIN = min(A, B);
  if (MAX == 1) {
    cout << "1 2\n.#" << BR;
    return 0;
  }
  string S = ".#";
  if (MAX == A) S = "#.";

  int H = 90, W = 80;
  vector<vector<ll>> cells(H, vector<ll>(W , 0));

  int h = 1, w = 1;
  while(MAX > 1) {
    cells[h][w] = 1;
    if (w + 2 < W) {
      w += 2;
    } else {
      h += 3;
      w = 1;
    }
    MAX--;
  }

  if (MIN > 1) rep(i, h + 2, H) rep0(j, W) cells[i][j] = 1;
  else cells[H - 1][W - 1] = 1;

  h += 3;
  w = 1;
  MIN--;
  while(MIN > 0) {
    cells[h][w] = 0;
    if (w + 2 < W) {
      w += 2;
    } else {
      h += 3;
      w = 1;
    }
    MIN--;
  }

  cout << H << SP << W << BR;
  rep0(i, H) {
    rep0(j, W) {
      cout << S[cells[i][j]];
    }
    cout << BR;
  }

  return 0;
}


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

int main() {
  int r;
  int g;
  int x;

  cin >> r;
  cin >> g;

  x = 2*g - r;

  cout << x << endl;
}

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

int main() {
  int R, G;
  cin >> R >> G;
  cout << G - R + G << endl;
}


#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	map<char,ll> M;
	for(auto& x:S) M[x]++;
	ll N=S.size();
	ll A=N*(N-1LL)/2LL;
	for(auto& x:M){
		A -= x.second*(x.second-1LL)/2LL;
	}
	out(A+1LL);
	return 0;
}

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

int main()
{
	int num,i,j,x,y,z;

	char a[20],b[20],c[20];
	scanf("%s %s %s",a,b,c);

	x = strlen(a);
	y = strlen(b);
	z = strlen(c);

	if(a[x-1] == b[0] && b[y-1] == c[0]) cout << "YES";
	else cout << "NO";

}


#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int rome(char g) {
	switch (g) {
	case 'I':return 1;
	case 'V':return 5;
	case 'X':return 10;
	case 'L':return 50;
	case 'C':return 100;
	case 'D':return 500;
	case 'M':return 1000;
	default:return -1;
	}
}
int main() {
	string s;
	while (cin >> s) {
		int sum = 0;
		int i;
		for (i = 0; i < s.length() -1; i++) {
			if (rome(s[i]) < rome(s[i + 1])) {
				sum += rome(s[i + 1]) - rome(s[i]);
				i++;
				//cout << "sum += " << rome(s[i + 1]) - rome(s[i]) << "  ";
			}
			else {
				sum += rome(s[i]);
				//cout << "sum += " << rome(s[i]) << "  ";
			}
			//cout << "sum is " << sum << endl;
		}
		if (i == s.length() - 1)sum += rome(s[i]);
		cout << sum << endl;
	}
	return 0;
}

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

signed main(){
  string s; cin >> s;
  int n = s.size();
  for(int i = 0; i < n - 1; i++){
    if(s[i] == s[i + 1]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    if(i < n - 2 && s[i] == s[i + 2]){
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}


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

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a-b+1<<endl;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

template<typename T>
T gcd(T a, T b){
	if (a%b == 0)		return(b);
   else	return(gcd(b, a%b));
}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll A, B;
	cin >> A >> B;
	ll upper = gcd<ll>(A, B);
	vector<ll>	D = divisor(upper);
	vector<ll>	J;

	FOR(i, 0, D.size() - 1)
	{
		if (binary_search(range(J), D.at(i)))
			continue;
		FOR(j, i + 1, D.size())
		{
			if (binary_search(range(J), D.at(j)))
				continue;
			if (gcd<ll>(D.at(i), D.at(j)) != 1)
			{
				J.push_back(D.at(j));
				sort(range(J));
			}
		}
	}

	cout << D.size() - J.size() << endl;

	return 0;
}


///////////////////////////////////////////////////////////////////////////
// /*Dis = size of the program || TLE. */
/*
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
*/
// #pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops") /* D = Too many loops */

#include <sys/time.h>  // for CLOCKS_PER_SEC

#include <ctime>     // for clock
#include <iostream>  // for operator<<, ostream, istream, basic_ostream
#include <unordered_set>
using namespace std;
#define endl '\n'
typedef long long ll;

//////////////////////////////////////////////////////////////////////////
/* Custom function starts here */

/* Custom function ends here: */
//////////////////////////////////////////////////////////////////////////////

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

  /* MAIN Code STARTS here: */
  unordered_set<long long int> ss;
  unordered_set<long long int> dup;
  long n;
  cin >> n;
  for (long i = 0; i < n; i++) {
    ll num;
    cin >> num;
    if (ss.find(num) != ss.end()) {
      dup.insert(num);
    } else {
      ss.insert(num);
    }
  }
  if (dup.empty() == true) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  /* MAIN Code ENDS here: */
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

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

int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(arr.begin(),arr.end());
	for(int i=1; i<arr.size(); i++){
		if(arr[i-1]==arr[i]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	double i, j, k, l;
	cin >> i >> j >> k >> l;
	cout << fixed << setprecision(8);
	cout << (double)sqrt(pow(i - k, 2.0) + pow(j - l, 2.0)) << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp  make_pair
#define pb  push_back
#define endl "\n"
#define rep(i,a,n) for(int i=a;i<n;i++)
const int mod = 1e9 + 7;
void solve() {
	int n, x, t;
	cin >> n >> x >> t;
	int s = 0, c = 0;
	while (s < n) {
		s += x;
		c++;
	}
	cout << c*t;
}
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    if(A <= B){
        for(ll i = A; i <= B; i++){
            if(i == C){
                cout << "Yes";
                return 0;
            }
        }
    }else{
        for(ll i = A; i >= B; i--){
            if(i == C){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a < c && b > c) || (a > c && b < c)) puts("Yes");
	else puts("No");
	return 0;
}


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

int main(){
	int n;
	while(cin >> n, n){
		n++;
		vector<int> t(n), v(n);
		t[0] = 0;
		for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}
		cout << *max_element(t.begin()+1, t.end()) << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;
int n , now = 0;
int saiki(int now){
	if( now == n )
		return 1;
	if( now > n )
		return 0;
	int res = 0;
	res += saiki(now+1)+saiki(now+2)+saiki(now+3);
	return res;
}
int main(){
	while(1){
		int x=0;
		cin >> n;
		if( n==0 ) break;
		int count = saiki(0);
		int co = count / 10;
		if( count%10 > 0 )
			co ++;
		x = co / 365 ;
		if(co%365>0)
			x ++;
		cout << x << endl;
	}
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool flag = false;
  ll m = INF;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      flag = true;
    }
    if (a[i] < 0) cnt++;
    m = min(m, abs(a[i]));
  }

  if (flag || cnt % 2 == 0) {
    ll num = 0;
    for (ll i = 0; i < n; i++) {
      num += abs(a[i]);
    }
    cout << num << endl;
    return 0;
  } else {
    ll num = 0;
    for (ll i = 0; i < n; i++) {
      num += abs(a[i]);
    }
    num -= 2 * m;
    cout << num << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;   cin >> n;
    vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    rep(i, n+1) rep(j, 2) dp[i][j] = -LINF;
    dp[0][0] = 0;
    rep(i, n){
        dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
        dp[i+1][1] = max(dp[i][1]+a[i], dp[i][0]-a[i]);
    }
    cout << dp[n][0] << endl;
}


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

int main(){
    ll N;
    cin >> N;
    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    string S = "";
    while(N!=0){
        if(N%2==0){
            if(N<0){
                N*=(-1);
                N/=2;
            }else{
                N/=2;
                N*=(-1);
            }
            S+='0';
            continue;
        }
        if(N<0){
            N*=(-1);
            N+=1;
            N/=2;
        }else{
            N/=2;
            N*=(-1);
        }
        S+='1';
    }
    reverse(S.begin(),S.end());
    cout << S << endl;
    return 0;
}

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N=3e5+30,M=524288;
const int MAX=2e9;
const long long Mod=1e9+7;
int trans[8][2]={{2,1},{4,3},{6,5},{3,3},{7,1},{2,1},{2,2},{4,4}};
long long dp[N][8];
char s[N];
int n;
int main(){
    //freopen("problem.in","r",stdin);
    //freopen("problem.out","w",stdout);
    scanf("%s",s+1);
    n=strlen(s+1);
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<8;j++){
            if(s[i+1]!='0'){
                dp[i+1][trans[j][1]]+=dp[i][j];
                dp[i+1][trans[j][1]]%=Mod;
            }
            if(s[i+1]!='1'){
                dp[i+1][trans[j][0]]+=dp[i][j];
                dp[i+1][trans[j][0]]%=Mod;
            }
        }
    }
    printf("%lld\n",(dp[n][1]+dp[n][3])%Mod);
    return 0;
}


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

char s[10000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> s;
	int n = strlen(s);
	for (int i = 0; i < n - 8; i++) cout << s[i];
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll dp[2][102];

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

	string s;
  cin>>s;
  ll n=s.size();
  string ans = s.substr(0,n-8);
  cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,i; cin >> n >> i;
    int ans = 1;
    if(n%i == 0) ans = 0;
    cout << ans << endl;
}

/*16D8103008D 西村　悠輝　ALDS10C*/

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

string X, Y;
int v[1001][1001];

int  dp(string X, string Y) {
	int n = X.size();
	int m = Y.size();

	for (int i = 0; i <= n; i++) {
		v[i][0] = i;											///０のテーブル
		for (int j = 0; j <= m; j++) {
			v[0][j] = j;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (X[i-1] == Y[j-1]) {

				v[i][j]= v[i-1][j-1];
			}
			else {
				int y = min(v[i][j - 1] + 1, v[i - 1][j] + 1);
				if (y > v[i - 1][j - 1] + 1) {
					v[i][j] = v[i - 1][j - 1] + 1;
				}else{
					v[i][j] = y;
				}
			}
		}
	}
	return v[n][m];
}

int main(void)
{

	cin >> X >> Y;
	int ans = dp(X, Y);
	cout << ans << endl;

}
/*
acac
acm
2
*/


/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string s;
	cin>>s;
	if(s=="SUN")cout<<7;
	else if(s=="MON")cout<<6;
	else if(s=="TUE")cout<<5;
	else if(s=="WED")cout<<4;
	else if(s=="THU")cout<<3;
	else if(s=="FRI")cout<<2;
	else if(s=="SAT")cout<<1;

}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pi 2*acos(0.0)

int main(void)
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    // cout.tie(0);
  set<ll>s;

  int n;
  cin>>n;
  bool flag = true;
  while(n--)
  {
      ll x;
      cin>>x;
      if(s.count(x)>0)
      {
          flag = false;
      }
      s.insert(x);
  }
  if(flag)
  {
      cout<<"YES"<<endl;
  }
  else
  {
      cout<<"NO"<<endl;
  }
}


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

#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(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    string S; cin >> S;
    vector<int> alpha(26,0);
    REP(i,S.size()){
        alpha[S[i]-'a']++;
    }
    for (char a='a'; a<='z';a++){
        if(alpha[a-'a']==0){
            cout << a << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  string A;
  cin >> A;
  map<char, ll> z;
  for (int i=0; i<(int)A.size(); i++) {
    if (z.count(A[i])) z[A[i]]++;
    else z[A[i]] = 1;
  }
  ll num = 0;
  for (auto p: z) {
    auto value = p.second;
    num += value*(value-1)/2;
  }
  cout << (ll)A.size()*(A.size()-1)/2-num+1 << endl;
  return 0;
}


#include<iostream>
using namespace std;
int main ()
{
    int n, a, p, k;
    cin >> n;
    a = n / 100;
    k = a * 100 + a * 10 + a;
    p = (a + 1) * 100 + (a + 1) * 10 + a + 1;
    if(n <= k)
        cout << k;
    else
        cout << p;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw				"\n"
int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s;
	ll a,b;
	cin>>a>>b;
	cin>>s;
	l=s.size();
	if(s[a]=='-')x=1;
	for(ll i=0;i<l;i++){
		if(i==a)continue;
		if(!(s[i]>='0'&&s[i]<='9'))return cout<<"No",0;
	}
	if(x==1)cout<<"Yes";
	else cout<<"No";
}


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

//conbinatin (2002,2) =

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

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

#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(int n){
    cout << "Yes" << endl;
}

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

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

int main() {
    ll n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
    cout << cel(n,min({a,b,c,d,e})) + 4LL << endl;
}


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

int main()
{
  int x;
  std::cin >> x;
  std::cout << int(pow(x, 3)) << std::endl;
  return 0;
}

#include <iostream>
using namespace std;

int main(){
	int	x;
	cin >> x;
	cout << x * x * x << endl;
	return 0;
}