#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n > 0) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
perm pm(1 << 22);

ll dp[2001];
ll rdp[2002];
ll nex[2001];

void solve() {
	int n, k; cin >> n >> k;
	if (k == 1) {
		cout << 1 << endl; return;
	}
	dp[1] = 1;
	for (int i = 2; i < 2002; i++)rdp[i] = 1;
	rep1(i, n - 1) {
		for (int j = 1; j <= i + 1; j++) {
			int num = i * k - (j - 1);
			nex[j] = (rdp[i + 1] - rdp[j - 1])*pm.comb(num + k - 2, num);
			nex[j] = (nex[j] % mod + mod) % mod;
		}
		for (int j = 1; j <= i + 1; j++) {
			dp[j] = nex[j];
			rdp[j + 1] = (rdp[j] + dp[j]) % mod;
		}
	}
	ll ans = rdp[n + 1];
	rep1(i, n)ans = ans * i%mod;
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(12);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	//stop
	return 0;
}

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

int read(){
	int x=0; char c=getchar(); int flag=1;
	while(!isdigit(c)) { if(c=='-') flag=-1; c=getchar(); }
	while(isdigit(c)) { x=((x+(x<<2))<<1)+(c^48); c=getchar(); }
	return x*flag;
}

const int mod=1e9+7;

int n,k;
int dp[2005][2005];//i个白球，j种颜色

int fac[4000005],Inv[4000005];

int C(int n,int m){
	if(m<0||n<m) return 0;
    return 1ll*(1ll*fac[n]*Inv[m]%mod)*Inv[n-m]%mod;
}

void exgcd(int a,int b,int &x,int &y){
    if(b==0) { x=1; y=0; return ; }
    exgcd(b,a%b,y,x); y-=a/b*x;
}

int inv(int a){
    int x=0,y=0;
    exgcd(a,mod,x,y);
    return (x%mod+mod)%mod;
}

signed main(){
	fac[0]=1;
	for(int i=1;i<=4000000;i++) fac[i]=1ll*fac[i-1]*i%mod;
	Inv[4000000]=inv(fac[4000000]);
	for(int i=3999999;i>=0;i--) Inv[i]=1ll*Inv[i+1]*(i+1)%mod;

    n=read(),k=read();
    if(k==1) { puts("1"); return 0; }
	dp[0][0]=1;

    for(int i=1;i<=n;i++){
	    dp[i][0]=1;
		for(int j=1;j<=i;j++){
			dp[i][j]=(dp[i-1][j]+1ll*(1ll*dp[i][j-1]*C(n*k-(j-1)*(k-1)-i-1,k-2))%mod*(n-j+1)%mod)%mod;
		}
	}

	printf("%d\n",dp[n][n]);
    return 0;
}


#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, k;
	std::cin >> n >> k;
	int mx = 0, g = 0;
	while(n--) {
		int x;
		std::cin >> x;
		g = gcd(g, x);
		mx = std::max(mx, x);
	}
	std::cout << (k % g == 0 && k <= mx ? "POSSIBLE\n" : "IMPOSSIBLE\n");
}

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

typedef long long ll;

main()
{
    int a, b, sum, c = 1;
    cin >> a >> b;
    sum = a;
    if(b == 1){
        cout << 0;
    }
    else if(b <= a){
        cout << 1;
    }
    else{
        while(1){
            sum = sum + (a - 1);
            c++;
            if(sum >= b){
                break;
            }
        }
        cout << c;
    }

}

///promy_pompom
//hello world


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define ZERO_IQ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x, y) cerr<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define debug2(x, y, z) cerr<<(#x)<<" " <<(#y)<<" " <<(#z)<<" is " << (x) <<" "<< (y) <<" "<<(z) << endl
#define watch(x) cerr<<(#x)<<" is " << (x) << endl

const int N = 2e5 + 10;
typedef long long ll;

ll dp[N];

int main() {
    ll n;
    cin >> n;
    vector<ll> v;
    vector<ll> summ(n + 1);
    for (int i = 1; i <= n; i++) {
        ll q;
        cin >> q;
        v.push_back(q);
        if (i % 2 == 1) {
            if (i == 1)summ[i] = q;
            else
                summ[i] = summ[i - 2] + q;
        }
    }
    dp[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (i % 2 == 1) {
            dp[i] = max(dp[i - 2] + v[i - 1], dp[i - 1]);
        } else
            dp[i] = max(dp[i - 2] + v[i - 1], summ[i-1]);
    }
    cout << dp[n];
    return 0;
}

#include <bits/stdc++.h>

#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;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	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;

int n, k;

int main() {
	read(n), read(k);
	print(n - k + 1);
}


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

int S[100],R[100];
main(){
	int N,i=0,a,b,c,d;
	vector<pair<int,int> >v;
	scanf("%d",&N);
	for(;i<N*(N-1)/2;i++){scanf("%d%d%d%d",&a,&b,&c,&d);if(c==d)c=d=1;else if(c>d)c=3,d=0;else c=0,d=3;S[a-1]+=c,S[b-1]+=d;}
	for(i=0;i<N;i++)v.push_back(make_pair(S[i],i));
	sort(v.begin(),v.end(),greater<pair<int,int> >());
	for(R[v[0].second]=1,a=0,i=1;i<N;i++){if(v[i].first<v[a].first)a=i;R[v[i].second]=a+1;}
	for(i=0;i<N;i++)printf("%d\n",R[i]);
}

#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }

string ret[7] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};

int main() {
	vci t(5); char c;

	while (cin>>t[0]>>c>>t[1]>>c>>t[2]>>c>>t[3]>>c>>t[4]) {
		int ans = 0;

		vci v(13, 0);
		for_(i, 0, (int)t.sz) v[t[i]-1]++;

		int cnt = 0;

		// 0, 1, 2
		for_(i, 0, 13) if (v[i]==2) cnt++;
		ans = cnt;

		// 3
		cnt = 0;
		for_(i, 0, 13) if (v[i]==3) cnt++;
		if (cnt) ans = 3;

		// 4
		for_(i, 0, 10) {
			cnt = 0;
			for_(j, 0, 5) {
				if (v[(i+j)%13]==1) cnt++;
			}
			if (cnt==5) ans = 4;
		}

		// 5
		cnt = 0; int cnt2 = 0;
		for_(i, 0, 13) {
			if (v[i]==2) cnt++;
			if (v[i]==3) cnt2++;
		}
		if (cnt2==1 && cnt==1) ans = 5;

		cnt = 0;
		for_(i, 0, 13) if (v[i]==4) cnt++;
		if (cnt) ans = 6;

		cout << ret[ans] << endl;
	}

	return 0;
}


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

int h[6];

int sq(int n){
    return n*n;
}

int find( int n , int s = 0 ){
    int count = 0, m = -1, mm = 0;
    for(int i = s; i < 6; i++){
        if( m == h[i] ){
            count++;
        }else{
            if( count == n ){
                mm = m;
                break;
            }
            m = h[i];
            count = 1;
        }
    }
    return mm;
}

int main(){
    while( scanf("%d,%d,%d,%d,%d",
                 h, h+1, h+2, h+3, h+4) != EOF ){
        sort(h, h+5);
        if( find(4) ) puts("four card");
        else if( find(3)*find(2) &&
                 find(3) != find(2) ) puts("full house");
        else if( (h[1]-h[0])*(h[2]-h[1])*(h[3]-h[2])*(h[4]-h[3]) == 1 ||
                 (h[0] == 1 && h[1] == 10 && h[2] == 11 &&
                  h[3] == 12 && h[4] == 13) ){
            puts("straight");
        }else if( find(3) ){
            puts("three card");
        }else if( find(2)*find(2,2) && find(2) != find(2,2) ){
            puts("two pair");
        }else if( find(2) ){
            puts("one pair");
        }else{
            puts("null");
        }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int solve(int N, int P) {
	int p = P;
	vector<int> have(N, 0);
	int turn = 0;
	while (1) {
		if (p > 0) {
			--p;
			if (++have[turn] == P) return turn;
		}
		else {
			swap(p, have[turn]);
		}
		turn = (turn + 1) % N;
	}
}

int main() {
	int N, P;
	while (cin >> N >> P, N || P) {
		cout << solve(N, P) << endl;
	}
}


#include <cstdio>

int matrix[12][12];
int n;

int main() {
  while(scanf("%d", &n) != EOF, n) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	scanf("%d", &matrix[i][j]);
      }
    }

    // output
    for (int i=0; i<n; i++) {
      int sum = 0;
      for (int j=0; j<n; j++) {
	sum += matrix[i][j];
	printf("%5d", matrix[i][j]);
      }
      matrix[i][n] = sum;
      printf("%5d\n", sum);
    }

    for (int j=0; j<=n; j++) {
      int sum = 0;
      for (int k=0; k<n; k++) {
	sum += matrix[k][j];
      }
      printf("%5d", sum);
    }
    printf("\n");
  }
}

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

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

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

int main(){
    int N; cin >> N;
    ll m = INF;
    int count = 0;
    ll res = 0ll;

    rp(i, 0, N) {
        ll a; cin >> a;
        if(a < 0) count ++;
        a = abs(a);
        chmin(m, a);
        res += a;
    }
    if(count % 2) res -= 2 * m;
    cout << res << endl;
    return 0;
}


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

// int main(){
// 	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// 	int tc;
// 	cin >> tc;
// 	while(tc--){
// 		string s;
// 		cin >> s;
// 		int count_0 = 0, count_1 = 0;
// 		for(char ch : s)
// 			count_0 += 1 - ch + '0', count_1 += ch - '0';
// 		int ans = min(count_0, count_1);
// 		int c0 = 0, c1 = 0, n = s.size();
// 		for(int i = 0; i < n - 1; i++){
// 			c0 += 1 - s[i] + '0', c1 += s[i] - '0';
// 			ans = min(ans, c0 + count_1 - c1);
// 			ans = min(ans, c1 + count_0 - c0);
// 		}
// 		cout << ans << '\n';
// 	}
// }
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

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

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n;
	cin >> n;
	vector<string> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	vector<pair<int, int> > balances, negative_balances;
	for(int i = 0; i < n; i++){
		int tot = 0, mn = 0;
		for(auto j : v[i]){
			if(j == '(')
				tot++;
			else tot--;
			mn = min(mn, tot);
		}
		if(tot < 0)
			negative_balances.push_back({tot - mn, -tot});
		else
			balances.push_back({-mn, tot});
	}
	sort(all(balances));
	sort(all(negative_balances));
	reverse(all(negative_balances));
	int mn_neg_sum = 0, cur_neg_sum = 0;
	for(auto i : negative_balances){
		mn_neg_sum = max(mn_neg_sum, cur_neg_sum + i.first + i.second);
		cur_neg_sum += i.second;
	}
	int mn_seen = 0;
	for(auto i : balances)
		if(i.first > mn_seen){
			cout << "No" << endl;
			return 0;
		}
		else mn_seen += i.second;
	if(mn_seen != cur_neg_sum || mn_seen < mn_neg_sum){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1e6 + 5;
int n;
char s[mxn];
int bg[mxn], ln[mxn];
int a[mxn], b[mxn];
int id[mxn];

bool comp(int x, int y) {
	return min(-a[x], -a[x] + b[x] - a[y]) > min(-a[y], -a[y] + b[y] - a[x]);
}

void NO() {
	puts("No");
	exit(0);
}

int main() {
	scanf("%d", &n);
	rep(i, n) {
		scanf("%s", s + bg[i]);
		ln[i] = strlen(s + bg[i]);
		rep(j, ln[i]) {
			if (s[bg[i] + j] == '(') {
				++ b[i];
			} else {
				if (b[i]) -- b[i];
				else ++ a[i];
			}
		}
		bg[i + 1] = bg[i] + ln[i];
		id[i] = i;
	}
	sort(id, id + n, comp);
	int A = 0;
	rep(xx, n) {
		int i = id[xx];
		A -= a[i];
		if (A < 0) NO();
		A += b[i];
	}
	if (A != 0) NO();
	puts("Yes");
	return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int a,b;
int c[1001000],r[1001000];
int main()
{
  int n,m;
  cin>>n>>m;
  REP(i,n)
  {
  	cin>>a;
  	if(r[a])
  	{
		cout<<0<<endl;
		return 0;
	}
  	r[a]=1;
  }
  REP(i,m)
  {
  	cin>>b;
  	if(c[b])
  	{
		cout<<0<<endl;
		return 0;
	}
  	c[b]=1;
  }
  ll nowr=0,nowc=0,ans=1;
  for(int i=n*m;i>=1;i--)
  {
  	if(r[i])
  	  nowr++;
  	if(c[i])
  	  nowc++;
	if(c[i]||r[i])
	{
	  if(c[i]&&!r[i])
	    ans*=nowr%mod;
	  if(r[i]&&!c[i])
	    ans*=nowc%mod;
    }
    else
    {
	  ans*=(nowc*nowr-(n*m-i))%mod;
	}
	ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin>>n;
    vl beki;
    multiset<ll> A;
    beki.push_back(1);
    rep(i,40){
        beki.push_back(beki.back()*2);
    }
    rep(i,n){
        cin>>x;
        A.insert(x);
    }

    while(!A.empty()){
        auto ite=A.end();
        ite--;
        x=*ite;
      	A.erase(ite);
        k=upper_bound(all(beki),x*2)-beki.begin()-1;
        if(!A.empty()&&A.count(beki[k]-x)>0){
            auto ite2=A.lower_bound(beki[k]-x);
            A.erase(ite2);
            ans++;
        }
    }
    cout<<ans<<endl;
}


#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--)
#define pb push_back

int main(){

    // 1. 入力情報.
    char c[2020];
    int w;
    scanf("%s %d", c, &w);

    // 2. 文字を連結.
    string ans = "";
    int l = strlen(c);
    rep(i, l) if(i % w == 0) ans.pb(c[i]);

    // 3. 出力.
    printf("%s\n", ans.c_str());
    return 0;

}

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

int main(){
    string s;
    cin>>s;
    int w;
    cin>>w;
    for(int i = 0;i<s.size();i++){
        if(i%w==0){
            cout<<s.at(i);
        }
    }

}


#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 1000000000000000;
    rep(i,5){
        ll m;
        cin >> m;
        ans = min(ans,m);
    }
    cout << (n+ans-1)/ans + 4 << endl;

    return 0;
}

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

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

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

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

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

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

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

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

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

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

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

}
int main(){
        FS;

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

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

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

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

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


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

    int lmax = *max_element(all(l));
    int rmin = *min_element(all(r));
    put(max(0, rmin - lmax + 1));

    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){

  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//cout<<""<<endl;
int main(){
 int N;cin>>N;
  vector<PR> R(N),B(N);
  rep(i,N){
    int a,b;cin>>a>>b;
    PR p =make_pair(b,a);
    R[i]=p;
  }
  rep(i,N){
    int a,b;cin>>a>>b;
    PR p =make_pair(a,b);
    B[i]=p;
  }
  sort(all(R));
  reverse(all(R));

  vb han(N);
  rep(i,N)han[i]=false;
  for(int i=0;i<N;i++){
    int k=10000,ind=1000;

    rep(j,N){
     if(han[j])continue;
     if(R[i].first<B[j].second){
        if(R[i].second<B[j].first){
          if(k>B[j].first){
            k=B[j].first;
            ind=j;
          }
        }
      }
    }
    if(ind!=1000)han[ind]=true;
  }
  int cnt=0;
  rep(i,N){
   if(han[i])cnt++;
  }
  cout<<cnt<<endl;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 55, LG = 17, MOD = 1e9+7;
const int SQ = 320;
const long double EPS = 1e-7;
int cnt = 0;
vector<string> store[11];
void bt(string s = "", int sum = 0){
  if(sum > 7)return;
  store[sum].pb(s);
  f(i,0,7){
    s.pb('0' + i);
    bt(s,sum+i+1);
    s.pop_back();
  }
}
const int M = 10;
int trie[N*N*N][M];
int go[N*N*N][M];
int mrk[N*N*N], f[N*N*N];
int ptr = 1;
void BFS(){

  queue<int> q;
	for(int i = 0; i < M; i++)
		if(trie[0][i])
			q.push(trie[0][i]), f[trie[0][i]] = 0;
	for(int i = 0; i < M; i++) go[0][i] = trie[0][i];
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i = 0; i < M; i++) {
			if(trie[x][i]) {
				int y = trie[x][i];
				f[y] = f[x];
				while(f[y] && !trie[f[y]][i])
					f[y] = f[f[y]];
				if(trie[f[y]][i]) f[y] = trie[f[y]][i];
				q.push(y);
			}
			if(trie[x][i]) go[x][i] = trie[x][i];
			else go[x][i] = go[f[x]][i];
		}
	}

}
void ins(string x){
  int cur = 0;
  for(int i = 0; i < x.size(); i++){
      if(!trie[cur][x[i]-'0'])
        trie[cur][x[i]-'0'] = ptr++;
      cur = trie[cur][x[i]-'0'];
  }
  mrk[cur] = true;
}
int dp[N][N*N*N][2];
int n, x, y, z;
int solve(int idx, int state, bool f){
  f|=mrk[state];
  if(idx == n)
    return f;
  int &ret = dp[idx][state][f];
  if(~ret)
    return ret;
  ret = 0;
  f(j,0,10){
    ret += solve(idx+1,go[state][j], f);
    if(ret>=MOD)ret-=MOD;
  }
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  bt();

  cin >> n >> x >> y >> z;

  for(auto X : store[x])
    for(auto Y : store[y])
      for(auto Z : store[z])if(X.size()+Y.size()+Z.size()<=n)
        ins(X+Y+Z);
  BFS();
  memset(dp,-1,sizeof dp);
  cout << solve(0,0,0) << '\n';

  return 0;
}

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
constexpr int MOD = 1e9 + 7;

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

int n, x, y, z;

// v が x y z となっているか
bool check(const vector<int> &v)
{
    int sz = v.size();
    if (sz < 3)
        return false;
    vector<int> sum(sz + 1, 0);
    for (int i = 0; i < sz; i++)
    {
        sum[i + 1] = sum[i] + v[i];
    }
    bool f = false;
    for (int k = 0; k <= sz - 3; k++)
    {
        for (int i = k + 1; i <= sz - 2; i++)
        {
            for (int j = i + 1; j <= sz - 1; j++)
            {
                if (sum[i] - sum[k] == x && sum[j] - sum[i] == y && sum[sz] - sum[j] == z)
                    f = true;
            }
        }
    }
    return f;
}

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

    cin >> n >> x >> y >> z;
    int sum = x + y + z;
    // dp[i][j] := i 番目迄見て, 直近(の符号)が j であり, 575 を含まないものの数
    vector<vector<ll>> dp(n + 1, vector<ll>(1 << sum, 0));
    // valid[i][j] := 直近が i の時に j を置けるか
    vector<vector<int>> valid(1 << sum, vector<int>(11, 0));
    for (int i = 0; i < (1 << sum); i++)
    {
        vector<int> num;
        int v = 0;
        for (int j = sum - 1; j >= 0; j--)
        {
            if ((i >> j) & 1)
            {
                if (v)
                    num.push_back(v);
                v = 1;
            }
            else
            {
                if (v)
                    v++;
            }
        }
        if (v)
            num.push_back(v);
        for (int j = 1; j <= 10; j++)
        {
            vector<int> num2 = num;
            num2.emplace_back(j);
            valid[i][j] = !check(num2);
        }
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < (1 << sum); j++)
        {
            for (int k = 1; k <= 10; k++)
            {
                if (!valid[j][k])
                    continue;
                int mask = ((((j << k) & ((1 << sum) - 1)) | (1 << (k - 1)))) & ((1 << sum) - 1);
                dp[i + 1][mask] += dp[i][j];
                dp[i + 1][mask] %= MOD;
            }
        }
    }
    ll ret = 0;
    for (int i = 0; i < (1 << sum); i++)
        ret = (ret + dp[n][i]) % MOD;
    cout << (mypow((ll)10, (ll)n) + MOD - ret) % MOD << endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	cin>>n;
	vi d(n);
	int f,l,sf,sl;
	rep(i,0,n*(n-1)/2){
		cin>>f>>l>>sf>>sl;
		f--;
		l--;
		if(sf<sl){
			d[l]+=3;
		}else if(sf>sl){
			d[f]+=3;
		}else{
			d[l]++;
			d[f]++;
		}
	}
	vi e=d;
	sort(all(e));
	rep(i,0,n){
		int res=upper_bound(all(e),d[i])-e.begin();
		o(n+1-res);
	}
}

// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  map<int, int> C_ODD, C_EVEN;
  loop(i,0,n) {
    if (i&1) C_ODD[A[i]]++;
    else C_EVEN[A[i]]++;
  }
  vector<int> R_ODD(2), R_EVEN(2);
  {
    int max_ = 0;
    for (auto &m: C_ODD) if (max_ < m.second) { max_ = m.second; R_ODD[0] = m.first; }
  }
  {
    int max_ = 0;
    for (auto &m: C_EVEN) if (max_ < m.second) { max_ = m.second; R_EVEN[0] = m.first; }
  }
  {
    int max_ = 0;
    for (auto &m: C_ODD) {
      if (R_ODD[0] == m.first) continue;
      if (max_ < m.second) { max_ = m.second; R_ODD[1] = m.first; }
    }
  }
  {
    int max_ = 0;
    for (auto &m: C_EVEN) {
      if (R_EVEN[0] == m.first) continue;
      if (max_ < m.second) { max_ = m.second; R_EVEN[1] = m.first; }
    }
  }

  if (R_ODD[0] != R_EVEN[0]) {
    cout << (n/2 - C_ODD[R_ODD[0]]) + (n/2 - C_EVEN[R_EVEN[0]]) << endl;
    return 0;
  }
  if (R_ODD[0] == R_EVEN[0]) {
    ll cost1 =  (n/2 - C_ODD[R_ODD[1]]) + (n/2 - C_EVEN[R_EVEN[0]]);
    ll cost2 =  (n/2 - C_ODD[R_ODD[0]]) + (n/2 - C_EVEN[R_EVEN[1]]);
    cout << min(cost1, cost2) << endl;
    return 0;
  }
  return 0;
}


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

#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int arr[200001];
int main()
{
    fast_io;
    int n;
    cin >> n;
    set <int> s;
    for(int i =0 ; i < n; i++)
    {
        int x;
        cin >> x;
        s.insert(x);
    }
    if(n == s.size())
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
}

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
    int n;
    cin>>n;
  vi v1(n);
    loop(i,0,n)
    {
        cin>>v1[i];
    }
    int ans = 0,k1 = INT_MAX;
    loop(i,0,n)
    {
       if(k1>v1[i])
       {
           k1 = v1[i];
           ans++;
       }
    }
    cout<<ans<<endl;
    return 0;
}


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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};

int main(){
	int n,m;cin>>n>>m;
	Fact fac(3*m+n);
	ll ans=0;
	for(int s=m%2;s<=min(n,m);s+=2){
		ll a=fac.nCr(n,s);
		ll b=fac.nCr((3*m-s)/2+n-1,n-1);
		if((3*m-s)/2>=m)(b+=MOD-fac.nCr((3*m-s)/2-m+n-1,n-1)*s%MOD)%=MOD;
		if((3*m-s)/2>=m+1)(b+=MOD-fac.nCr((3*m-s)/2-m-1+n-1,n-1)*(n-s)%MOD)%=MOD;
		(ans+=a*b)%=MOD;
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define pw(x) (1LL<<(x))
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 3;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
#define DIE EVAL({cout << -1 << '\n'; exit(0);})
//------------------------------------------------------------------------------------------------------

LL K;

int main() {
    cin >> K;
    LL x = K % 50;
    LL m = (K-x)/50 + 49;
    cout << 50 << '\n';
    REP(i, 50-x) cout << (m-x) << ' ';
    REP(i, x) cout << (m+51-x) << ' ';
    cout << '\n';
}

#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a)
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a(5);
	trav(i,a)i=in();
	int ans=0;
	for(auto i:a)ans=max(ans,(n-1)/i);
	cout<<ans+5;

}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll n,a,b;
    while(sf("%lld %lld %lld",&n,&a,&b)==3)
    {
        ll ara[n+5];
        for(int i=0;i<n;i++)sf("%lld",&ara[i]);

        ll ans=0;
        for(int i=0;i<n-1;i++)
        {
            ll dis=ara[i+1]-ara[i];
            if(dis*a<=b)ans+=(dis*a);
            else ans+=b;
        }
        pf("%lld\n",ans);
    }
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int a;
  cin >> a;
  int vmax = a;
  int g = a;
  for (int i = 1; i < n; ++i) {
    cin >> a;
    g = __gcd(g, a);
    vmax = max(a, vmax);
  }
  cout << (k / g * g == k && k <= vmax ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define maxn 101
#define Max 10000
using namespace std;
int n,ans=0;
int map[maxn][maxn];

//struct edge
//{
//	int u;
//	int w;
//	edge(int u=0,int w=Max):u(u),w(w){}
//	bool operator <???(const node& rhs) const
//	{
//		return w>rhs.w;
//	}
//};

void prim()
{
	int d[maxn];
	bool vis[maxn];
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;++i)
	{
		d[i]=Max;
		vis[i]=0;
	}
	d[1]=0;
	while(1)
	{
		int MIN=Max;
		int u=-1;
		for(int i=1;i<=n;++i)
			if(MIN>d[i]&&!vis[i])
			{
				MIN=d[i];
				u=i;
			}
		if(u==-1) break;
		vis[u]=1;
		ans+=d[u];
		for(int i=1;i<=n;++i)
		{
			if(!vis[i] && map[u][i]!=Max)
			  if(d[i]>map[u][i])
			  	d[i]=map[u][i];
		}
	}
	return;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	  for(int j=1;j<=n;++j)
	  {
	  	int x;
	  	scanf("%d",&x);
	  	if(x!=-1)
	  	  map[i][j]=x;
	  	else
	  	  map[i][j]=Max;
	  }
	prim();
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int>v;
  int answer=0;
  for(int i = 0 ; i< 2*n ;i++){
    int k;
    cin>>k;
    v.push_back(k);
  }
  sort(v.begin(),v.end());
  for(int i = 0 ; i < 2*n ; i+=2){
    answer+=min(v.at(i),v.at(i+1));
  }
  cout<<answer<<endl;
return 0;
}


#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int d;
    int s;

    while(cin>>d){
        s=0;
        for(int i=1;i<=(600/d)-1;i++){
            s=s+d*(d*i)*(d*i);
        }
            cout<<s<<endl;
    }

}

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

int d, s;

int main() {
	while (scanf("%d",&d) != EOF) {
		s = 0;
		for (int i = d; i <= 600-d; i += d) s += i*i*d;
		printf("%d\n",s);
	}
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,a[N],ji,ou,pos,now,gcd;
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
inline void yes() {if (now) printf("First\n");else printf("Second\n");exit(0);}
inline void no() {if (now) printf("Second\n");else printf("First\n");exit(0);}
inline int GCD(int x,int y)
{
	if (!y) return x;
	if (x<y) return GCD(y,x);
	return GCD(y,x%y);
}
inline void solve()
{
	ou=0,ji=0;
	FOR(i,1,n) ji+=(a[i]&1),ou+=(!(a[i]&1));
	if (!ou) no();
	if (ou&1) yes();
	if (!ji) no();
	if (ji>1) no();
	FOR(i,1,n) if (a[i]&1) {pos=i;break;}
	if (a[pos]==1) no();
	a[pos]--;
	gcd=a[1];
	FOR(i,2,n) gcd=GCD(gcd,a[i]);
	FOR(i,1,n) a[i]/=gcd;
	now^=1;
	solve();
	return;
}
int main()
{
	now=1;
	n=read();
	FOR(i,1,n) a[i]=read();
	solve();
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i=0;i<tx-sx;i++) cout << 'R';
    for(int i=0;i<ty-sy;i++) cout << 'U';
    for(int i=0;i<tx-sx;i++) cout << 'L';
    for(int i=0;i<ty-sy;i++) cout << 'D';
    for(int i=0;i<1;i++) cout << 'D';
    for(int i=0;i<tx-sx+1;i++) cout << 'R';
    for(int i=0;i<ty-sy+1;i++) cout << 'U';
    for(int i=0;i<1;i++) cout << 'L';
    for(int i=0;i<1;i++) cout << 'U';
    for(int i=0;i<tx-sx+1;i++) cout << 'L';
    for(int i=0;i<ty-sy+1;i++) cout << 'D';
    for(int i=0;i<1;i++) cout << 'R';
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,H,W; cin>>N>>H>>W;
    cout<<(N-H+1)*(N-W+1)<<"\n";
    return 0;
}

#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <vector>;
using namespace std;

int main() {

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

	int m = d / s;
	if (d % s != 0) m++;

	if (m <= t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int x,y,tx,ty;
    cin>>x>>y>>tx>>ty;
    int n=abs(x-tx);
    int m=abs(y-ty);
    cout<<string(n,'R')<<string(m,'U');
    cout<<string(n,'L')<<string(m,'D');
    cout<<'L'<<string(m+1,'U')<<string(n+1,'R')<<'D';
    cout<<'R'<<string(m+1,'D')<<string(n+1,'L')<<'U';
    cout<<endl;

    return 0;
}

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

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int ans[301];
int item[1010][3], R[1010];

int main()
{
    while (true) {
        int a = in(), b = in(), c = in();

        if (a == 0) return 0;

        fill_n(ans, a+b+c+1, 2);

        int N = in();

        rep(i, N) {
            rep(j, 3) item[i][j] = in() - 1;
            R[i] = in();

            if (R[i]) {
                rep(j, 3) ans[item[i][j]] = 1;
            }
        }

        rep(i, N) {
            int cnt = 0;
            rep(j, 3) cnt += ans[item[i][j]] == 1;

            if (cnt == 2) {
                rep(j, 3) if (ans[item[i][j]] != 1) ans[item[i][j]] = 0;
            }
        }

        rep(i, a+b+c) printf("%d\n", ans[i]);
    }
}


#include <iostream>
#include <math.h>
#include <cstdlib>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;

pair <int,int> T_z[500100], T_or[500100];
int T_l[500100], T_najb[500100], tree[1048576], sts[500100];

bool comparison(const pair<int,int> &a,const pair<int,int> &b){
    return ((a.first>b.first)||((a.first==b.first)&&(a.second>b.second)));
}
void wstaw(int x, int indx, int drz[])
{
    drz[indx]=x;
    while (indx!=1)
    {
        indx/=2; drz[indx]=drz[indx*2]+drz[indx*2+1];
    }
}
int suma_prz(int l, int p, int drz[])
{
    if (l==p) return drz[l];
    if (l/2==p/2) return drz[l/2];
    int res=drz[l]+drz[p];
    if (l%2==0) res+=drz[l+1];
    if (p%2==1) res+=drz[p-1];
    while (l/2/2!=p/2/2)
    {
        l/=2; p/=2;
        if (l%2==0) res+=drz[l+1];
        if (p%2==1) res+=drz[p-1];
    }
    return res;
}
int su_bin(int p1, int p2, int poc, int kon,  pair <int,int> T_wys[])
{
    int res, sr;
    while (poc<=kon)
    {
    sr=(poc+kon)/2;
    if (T_wys[sr].first<p1) {res=sr; kon=sr-1; continue;}
    if ((T_wys[sr].first==p1)&&(T_wys[sr].second<=p2)) {res=sr; kon=sr-1; continue;}
    poc=sr+1;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, q; cin>>n>>q;
    for (int i=0;i<n;i++) cin>>T_l[i];
    for (int i=0;i<q;i++)
    {
    cin>>T_z[i].first>>T_z[i].second;
    T_or[i].first=T_z[i].first; T_or[i].second=T_z[i].second;
    }
    sort(T_z, T_z+q, comparison);
    int pot;
    for (int i=1;;i=i*2)
    {
        if (i>=n) { pot=i; break; }
    }
    int kt_q=0; bool prz=false;
    for (int i=n-1;i>=0;i--)
    {
       if (prz) break;
       if (T_najb[T_l[i]]!=0) wstaw(0, pot+T_najb[T_l[i]], tree);
       wstaw(1, pot+i, tree);
       T_najb[T_l[i]]=i;
       while (T_z[kt_q].first==i+1)
       {
           sts[kt_q]=suma_prz(T_z[kt_q].first+pot-1, T_z[kt_q].second+pot-1, tree);
           kt_q++;
           if (kt_q==q)  {prz=true; break;}
       }
    }
    for (int i=0;i<kt_q;i++)
    {
        cout<<sts[su_bin(T_or[i].first,T_or[i].second, 0, kt_q, T_z)]<<"\n";
    }

}

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

template<typename T>
class BIT{
    public:
        vector<T> x_list;
        ll n;

        BIT(ll n=1, T fill_value=0): n(n){
            x_list.resize(n+1);
            fill(x_list.begin(), x_list.end(), fill_value);
        }

        void add(ll idx, T v){
            for(ll x=idx; x<= n;x += (x & -x)){
                x_list[x] += v;
            }
        }

        ll get_sum(ll idx){
            T v = 0;
            for(ll x=idx;x>0;x-=(x & -x)){
                v += x_list[x];
            }
            return v;
        }
};

void Main(){
    ll N, Q, c, l, r;
    cin >> N >> Q;
    vector<ll> as(N);
    vector<vector<pll>> qs(N);
    // vector<pll> qs_org(Q);
    vector<ll> ans(Q);
    rep(i, N){
        cin >> as[i];
    }

    rep(i, Q){
        cin >> l >> r;
        -- l;
        -- r;
        qs[r].emplace_back(l, i);
        // qs_org[i] = make_pair(r, l);
    }

    // sort(qs.begin(), qs.end());

    map<ll,ll> color_best;
    // ll now_r = qs[0].first;

    BIT<ll> bitree(N, 0);

    rep(i, N){
        // if(color_best[as[i]]<=i){
            // continue;
        // }
        if(color_best.find(as[i])!=color_best.end() ){
            if(color_best[as[i]]<i){
                bitree.add(color_best[as[i]]+1, -1);
                bitree.add(i+1, 1);
                color_best[as[i]] = i;
            }
        }else{
            bitree.add(i+1, 1);
            color_best[as[i]] = i;
        }
        if(qs[i].size() == 0){
            continue;
        }
        for(auto q:qs[i]){
            ans[q.second] = bitree.get_sum(i+1) - bitree.get_sum(q.first);
        }
    }
    rep(i, Q){
        cout << ans[i] <<endl;
    }

}

int main(){
    Main();
}


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

int main(){
  int n,m;
  bool f[500][500];
  bool ans[500];
  int a,b;

  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    for(int i=0;i<n;i++){
      ans[i] = false;
      for(int j=0;j<n;j++)f[i][j] = false;
    }

    while(m--){
      cin >> a >> b;
      a--;
      b--;
      f[a][b] = true;
      f[b][a] = true;
      if(!a)ans[b] = true;
      if(!b)ans[a] = true;
    }

    for(int i=0;i<n;i++)
      if(f[0][i])
	for(int j=0;j<n;j++)ans[j] |= f[i][j];

    cout << count(ans+1,ans+n,true) << endl;
  }
}

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

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> p(n);
        for(int i=0; i<n; ++i)
            cin >> p[i];
        sort(p.rbegin(), p.rend());

        for(int i=m-1; i<n; i+=m)
            p[i] = 0;
        cout << accumulate(p.begin(), p.end(), 0) << endl;
    }
}


#include<iostream>
using namespace std;

int main(){
	int n=1;
	int a = 0;
	int f = 0;
	int quest[10000] = { 1 };
	double ans[10000];
	int checkc = 0;
	int i = 4;
	double check[3] = { 1, 2, 4 };

	do{
		cin >> quest[a];
		a++;
	} while (quest[a-1] != 0);
	while (a > f+1){
		switch (quest[f]){
		case 1:
			ans[f] = 1;
			break;
		case 2:
			ans[f] = 2;
			break;
		case 3:
			ans[f] = 4;
			break;
		default:
			while (quest[f] >= i){
				ans[f] = check[0] + check[1] + check[2];
				i++;
				check[0] = check[1];
				check[1] = check[2];
				check[2] = ans[f];
			}
		}

		ans[f] = ans[f] / 3650;
		checkc = (int)(ans[f]);

		if (ans[f] > (double)(checkc)){
			checkc++;
		}
		if (ans[f] != 0){
			cout << checkc << endl;
		}
		else{
			cout << endl;
		}
		f++;
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T, typename U>
void print1(T Array, U size) {
  for (int i = 0; i < size; i++) {
    cout << Array[i] << " ";
  }
  cout << endl;
}

template<typename T>
void print(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

int n;

int rec(int stage) {
  if (stage == 0) {
    return 1;
  }

  int ans = 0;

  for (int i = 1; i <= 3; i++) {
    if (stage - i < 0) continue;
    ans += rec(stage - i);
  }

  return ans;
}

signed main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    int t = (rec(n) + 3650 - 1) / 3650;
    cout << t << endl;
  }

  return 0;
}


#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main ()
{

long long x;
cin >> x;

long long happiness=0;
long long a,b,c;

a=x/500;
b=x%500;
c=b/5;

cout << a*1000+c*5 << endl;

	return 0;
}

#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl;
}


#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,K; cin >> N >> K;
	cout << N-K+1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;cin>>a>>b;
    if (a==b)cout<<a*2;
    else cout <<max(a,b)*2-1<<endl;
}


#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;
char c[55][55];
bool visited[55][55];
int d[55][55];
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
queue<P> Q;

int main()
{
	int H,W;
	cin >> H >> W;
	int cntW = 0;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> c[i][j];
			if (c[i][j] == '.') cntW++;
		}
	}
	rep(i,55)
	{
		rep(j,55)
		{
			d[i][j] = 1e8;
		}
	}
	d[0][0] = 0;
	Q.push(P(0,0));
	while(!Q.empty())
	{
		P q = Q.front();
		int f = q.first, s = q.second;
		Q.pop();
		if (visited[f][s]) continue;
		visited[f][s] = true;
		rep(i,4)
		{
			int xx = f+dx[i], yy = s+dy[i];
			if (xx >= 0 && xx < H && yy >= 0 && yy < W && c[xx][yy] == '.')
			{
				d[xx][yy] = min(d[xx][yy],d[f][s]+1);
				Q.push(P(xx,yy));
			}
		}
	}
	/*
	rep(i,H)
	{
		rep(j,W)
		{
			cout << d[i][j] << " ";
		}
		cout << endl;
	}
	*/
	if (d[H-1][W-1] == 1e8) cout << -1 << endl;
	else cout << cntW - d[H-1][W-1] - 1 << 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;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

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

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

struct BIT{
  int N;
  int bit[1000010];
  void add(int a,int w){
    for(int x = a; x < N; x+=(x&-x)) bit[x]+=w;
  }
  int sum(int a){
    int ret = 0;
    for ( int x = a; x > 0;x-=(x&-x)) ret += bit[x];
    return ret;
  }
};

int main() {
  ll N;
  string S;
  cin>>N>>S;
  int Q;
  cin>>Q;
  vector<int> D,M,C;
  vector<vector<ll>> cnt(N+1,vector<ll>(3,0));
  rep(i,N){
    if(S[i]=='D') {
      D.push_back(i);
      cnt[i+1][0]++;
    }
    if(S[i]=='M') {
      M.push_back(i);
      cnt[i+1][1]++;
    }
    if(S[i]=='C') {
      C.push_back(i);
      cnt[i+1][2]++;
    }
  }
  rep(i,N){
    rep(j,3){
      cnt[i+1][j]+=cnt[i][j];
    }
  }
  vector<ll> DMcnt(N+1,0);
  rep(i,N){
    if(S[i]=='M') DMcnt[i+1]+=cnt[i+1][0];
  }
  rep(i,N) DMcnt[i+1]+=DMcnt[i];
  rep(i,Q){
    int k;
    cin>>k;
    ll ans = 0;
    for(auto x:C){
      ll p = DMcnt[x+1]-DMcnt[max(0,x-k+1)]-cnt[max(0,x-k+1)][0]*(cnt[x+1][1]-cnt[max(0,x-k+1)][1]);
      ans += p;
    }
    cout<<ans<<endl;
  }
}


#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
typedef long long ll;
typedef pair<int,int> pii;
const int N = 5e5 + 7;
//--------head---------
struct Edge {
	int u, v, c;
	void in() {
		cin >> u >> v >> c;
	}
} E[N];
int n, m, tot;
map<pii, int> R;
map<pii, int>::iterator it;
vector<pii> e[N];
void ins(int u, int c) {
	pii p = mp(u, c);
	if (R.find(p) == R.end())
		R[p] = ++tot;
}
void addEdge(int u, int v, int c) {
	int x = R[mp(u, c)], y = R[mp(v, c)];
	e[x].pb(mp(v, 0)), e[x].pb(mp(y, 0));
}
bool vis[N];
int dis[N];
priority_queue<pii> que;
int solve() {
	rep(i, 0, tot + 1)
		vis[i] = false, dis[i] = -1;
	que.push(mp(0, 1));
	while (!que.empty()) {
		int u = que.top().second, d = -que.top().first;
		que.pop();
		if (vis[u])
			continue;
		dis[u] = d, vis[u] = true;
		rep(i, 0, sz(e[u])) {
			int v = e[u][i].first, w = e[u][i].second;
			if (!vis[v])
				que.push(mp(-(d + w), v));
		}
	}
	int ans = dis[n];
	rep(i, 0, sz(e[n])) {
		int v = e[n][i].first;
		if (~dis[v] && (ans == -1 || dis[v] < ans))
			ans = dis[v];
	}
	return ans;
}
int main() {
	cin >> n >> m;
	tot = n;
	rep(i, 0, m) {
		E[i].in();
		ins(E[i].u, E[i].c), ins(E[i].v, E[i].c);
	}
	for (it = R.begin(); it != R.end(); ++it) {
		pii p = it->first;
		int v = it->second;
		e[p.first].pb(mp(v, 1));
	}
	rep(i, 0, m) {
		int u, v, c;
		u = E[i].u, v = E[i].v, c = E[i].c;
		addEdge(u, v, c), addEdge(v, u, c);
	}
	cout << solve() << endl;
	return 0;
}

// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
vector<int> kind[100001];
vector<P> edge[100001];
int fw[100001];

template <typename T>
struct Graph_ {
  int n;
  vector<vector<pair<int, T> > > edge;
  vector<T> dis;
  Graph_(int ns) {
    n = ns;
    edge.resize(n);
    dis.resize(n);
  }
  void dijkstra(int s){
    dijkstra(s, 0);
  }
  T dijkstra(int s, int t){
    // initialize
    fill(dis.begin(), dis.end(), -1);
    vector<bool> used;
    used.resize(n);
    fill(used.begin(), used.end(), false);
    dis[s] = 0;
    // dijkstra
    priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > q;
    q.push(make_pair(0, s));
    while(!q.empty()){
      pair<T, int> p = q.top(); q.pop();
      int at = p.second;
      T distance = p.first;
      if(used[at])continue;
      used[at] = true;
      for(auto itr = edge[at].begin(); itr != edge[at].end(); ++itr){
        int to = (*itr).first;
        T cost = (*itr).second;
        if(used[to])continue;
        if(dis[to] == -1 || dis[to] > distance + cost){
          q.push(make_pair(distance + cost, to));
          dis[to] = distance + cost;
        }
      }
    }
    return dis[t];
  }
  void adde(int at, int to, T cost){
    edge[at].push_back(make_pair(to, cost));
  }
  [[deprecated("This function takes O(edge[at].size()).")]]
  void remove(int at, int to){
    int index = -1;
    for(int i = 0; i < edge[at].size(); i++){
      if(edge[at][i].first == to){
        index = i;
        break;
      }
    }
    edge[at].erase(edge[at].begin() + index);
  }
};

typedef struct Graph_<int> GraphI;
typedef struct Graph_<ll> GraphL;

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  rep(i, m){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    kind[a].pb(c);
    kind[b].pb(c);
    edge[a].pb(mk(b, c));
    edge[b].pb(mk(a, c));
  }
  map<P, int> ind;
  int curr = 0;
  rep(i, n){
    fw[i] = curr;
    curr++;
    kind[i].erase(unique(kind[i].begin(), kind[i].end()), kind[i].end());
    rep(j, kind[i].size()){
      ind[mk(i, kind[i][j])] = curr;
      curr++;
    }
  }
  GraphI graphi(curr+3);
  rep(i, n){
    rep(j, edge[i].size()){
      int at = ind[mk(i, edge[i][j].second)];
      int to = ind[edge[i][j]];
      graphi.adde(at, to, 0);
    }
    int cost = 1;
    if(kind[i].size() < 2 || i == 0 || i == n - 1){
      cost = 0;
    }
    rep(j, kind[i].size()){
      graphi.adde(fw[i], ind[mk(i, kind[i][j])], cost);
      graphi.adde(ind[mk(i, kind[i][j])], fw[i], cost);
    }
  }
  int res = graphi.dijkstra(fw[0], fw[n-1]);
  if(res == -1)cout << res << endl;
  else{
    cout << res/2 + 1 << endl;
  }
	return 0;
}


#include<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=998244353;
const int N=2e5+5;

int main(){
    int N, u, v; cin >> N >> u >> v;
    u--, v--;
    vector<vi> G(N);
    for(int i=0; i<N-1; i++){
        int A, B; cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<vi> dist(2, vi(N, -1));
    for(int i=0; i<2; i++){
        queue<int> que;
        que.push(v+(u-v)*i);
        dist[i][v+(u-v)*i]=0;
        while(!que.empty()){
            int p=que.front();
            que.pop();
            for(auto &np : G[p]){
                if(dist[i][np] != -1) continue;
                dist[i][np]=dist[i][p]+1;
                que.push(np);
            }
        }
    }
    int res=0;
    for(int i=0; i<N; i++){
        if(dist[0][i] > dist[1][i]) res=max(res, dist[0][i]);
    }
    res--;
    cout << res << endl;
    return 0;
}

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

vector<int>adj[100003],leaf;
int par[100003],depth[100005],sparse[100005][20],root=0,lz=0;

int lca(int p,int q)
{

    int a,b,c,d,lp,i,j;

    if(depth[p]<depth[q])
    {
        c=p; p=q; q=c;
    }

    for(j=19;j>=0;j--)
    {
         if((depth[p]-(1 << j))>=depth[q])
         {
             p=sparse[p][j];  if(depth[p]==depth[q])break;
         }
    }

    if(p==q){ return p; }
    else
    {
         for(j=19;j>=0;j--)
         {
             if(sparse[p][j]!=0 && sparse[p][j]!=sparse[q][j])
             {

                 p=sparse[p][j]; q=sparse[q][j];

                 if(par[p]==par[q])break;
             }

         }

         return par[p];
    }

}

void dfs(int src)
{
    int sz=adj[src].size();

    if(sz==1 && src!=root){   leaf.push_back(src);  lz++;   }

    for(int lp=0;lp<sz;lp++)
    {
        int u=adj[src][lp];

        if(u!=root && par[u]==0)
        {
            par[u]=src; sparse[u][0]=src; depth[u]=depth[src]+1;
            dfs(u);

        }

    }

}

int main()
{

    int n,m,a,b,i,j,u,v,ans,z,x,y,fr,sc,tr,w;
    scanf("%d %d %d",&n,&u,&v);

    for(i=1;i<=n-1;i++)
    {
        scanf("%d %d",&a,&b);
        adj[a].push_back(b); if(root==0){  if(adj[a].size()==2)root=a;  }
        adj[b].push_back(a); if(root==0){  if(adj[b].size()==2)root=b;  }

    }

    if(n==2)printf("0\n");
    else
    {
       dfs(root);

       for(j=1;j<=19;j++)
       {
           for(i=1;i<=n;i++)
           {
               if(sparse[i][j-1]!=0)
               {
                   sparse[i][j]=sparse[sparse[i][j-1]][j-1];
               }
           }
       }

       m=lca(u,v);

       ans=(depth[v]-depth[m])+(depth[u]-depth[m]); ans=ans-1;

       for(i=0;i<lz;i++)
       {
           y=leaf[i]; m=lca(u,y); w=lca(v,y);

           fr=(depth[u]-depth[m])+(depth[y]-depth[m]);
           sc=(depth[v]-depth[w])+(depth[y]-depth[w]);

           if(fr<sc)
           {
               if(sc-1>ans)ans=sc-1;
           }

       }

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

    }

    return 0;
}


#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

struct unionfind{
  private:
  int maxN;
  vector<int> par,treesize;
  public:unionfind(int N) :maxN(N),par(N),treesize(N,1){
    for(int i=0;i<maxN;++i)par[i]=i;
  }
  int root(int x){
    while(par[x]!=x){
      x=par[x]=par[par[x]];
    }
    return x;
  }
  bool unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return false;
    if(treesize[x]>treesize[y])swap(x,y);
    par[x]=y;
    treesize[y]+=treesize[x];
    return true;
  }
  bool parcheck(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return treesize[root(x)];
  }
  void clear(){
    treesize.assign(maxN,1);
    for(int i=0;i<maxN;++i)par[i]=i;
  }
};

int main(){
  startupcpp();
  ll i,N,M,cnt=0,ans=0;
  cin>>N>>M;
  vector<int> a(M),b(M);
  map<int,int> mp;
  rep(i,M){
    cin>>a[i]>>b[i];
    mp[a[i]]+=mp[b[i]];
  }
  for(auto& x:mp)x.second=cnt++;
  ans=N*N-cnt*cnt;
  N=cnt;
  unionfind ut(N*2);
  rep(i,M){
    a[i]=mp[a[i]];
    b[i]=mp[b[i]];
    ut.unite(a[i],b[i]+N);
    ut.unite(a[i]+N,b[i]);
  }
  mp.clear();
  rep(i,N){
    mp[ut.root(i)]|=ut.parcheck(i,i+N);
  }
  cnt=0;
  for(auto& x:mp)cnt+=!x.second;
  print(ans+(mp.size()-cnt/2)*(mp.size()-cnt/2)+cnt*cnt/4);
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int n, m;
int c0;

int st[MN];
int bi_comp, bi_v;
int nbi_comp, nbi_v;
vi g[MN];

int sz;

bool dfs(int v, int c) {
	st[v] = c;
	++sz;

	bool flg = true;

	for (int to : g[v]) {
		if (st[to] == -1) {
			if (!dfs(to, c ^ 1)) {
				flg = false;
			}
		} else {
			if (st[to] == c) {
				flg = false;
			}
		}
	}

	return flg;
}

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

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}

	memset(st, -1, sizeof(st));

	rep(i, n) {
		if (st[i] == -1) {
			if (g[i].size() == 0) {
				++c0;
			} else {
				sz = 0;
				bool res = dfs(i, 0);

				if (res) {
					++bi_comp;
					bi_v += sz;
				} else {
					++nbi_comp;
					nbi_v += sz;
				}
			}
		}
	}

	ll ret = (ll)n * n - (ll)(n - c0) * (n - c0) + (ll)bi_comp * bi_comp * 2 + 2LL * nbi_comp * bi_comp + (ll)nbi_comp * nbi_comp;

	cout << ret << endl;
	return 0;
}


	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	typedef long long LL;
	#define ld long double
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define INFINITE 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i];
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	#define precision(a) cout<<fixed<<setprecision(a);
	#define INF (1e18+5)
	#define inf (1e9+5)
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	// 8-directions
	//int dx[]={1,1,1,0,0,-1,-1,-1};
	//int dy[]={-1,0,1,-1,1,-1,0,1};
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	int begtime = clock();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}

	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}

	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		string a;
		cin>>a;
		ll ans=0;
		if(a[0]=='R'&&a[1]=='R'&&a[2]=='R')
		{
			cout<<3<<endl;
		}
		else if((a[0]=='R'&&a[1]=='R')||(a[1]=='R'&&a[2]=='R'))
		{
			cout<<2<<endl;
		}
		else if(a[0]=='R'||a[1]=='R'||a[2]=='R')
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
	}
	int main()
	{
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		#ifndef ONLINE_JUDGE
    		cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    		#endif
		return 0;
	}

#include<stdio.h>
#include<string.h>
#include<iostream>
#include <fstream>
#include<iostream>
#include <sstream>
#include<string>
#include <list>

using namespace std;
const int M = 1003;
const int INIT = (M*M + 1);
int C[M][M];// = { 0 };

int countmatchstring(const char* p1, const char*p2, int length1, int length2,int x, int y, int i, int j,int cost)
{
	int w = (i - 1 > j - 1) ? i - 1 : j - 1;
	if (p1[x + i] == p2[y + j])
	{
		x = x + i;
		y = y + j;
		if (x == length1 - 1 && y == length2 - 1)
		{
			C[x][y] = 0;
			return w;
		}
		if (x == length1 - 1 || y == length2 - 1)
		{
			while (1);
		}
		C[x][y] = countmatchstring(p1, p2, length1, length2, x, y, 1, 1, w + cost);
		return w + C[x][y];

	}
	if (C[x + i][y + j] == INIT)
	{
		int c1 = INIT, c2 = INIT,c3 = INIT;
		if (x + i + 1 < length1)
		{
			for (int p = 1; x + i + p < length1; ++p)
			{
				if (p1[x + i + p] == p2[y + j])
				{
					c1 = countmatchstring(p1, p2, length1, length2, x, y, i + p, j, cost);
					break;
				}
			}
		}
		if (y + j + 1 < length2)
		{
			for (int q = 1; y + j + q < length2; ++q)
			{
				if (p1[x + i] == p2[y + j + q])
				{
					c2 = countmatchstring(p1, p2, length1, length2, x, y, i, j + q, cost);
					break;
				}
			}
		}
		if ((x + i + 1 < length1) && (y + j + 1 < length2))
		{
			c3 = countmatchstring(p1, p2, length1, length2, x, y, i + 1, j + 1, cost);
		}
		int c = (c1 < c2 ? c1 : c2);
		c = (c < c3 ? c : c3);
		C[x + i][y + j] = c;
	}
	return C[x + i][y + j];
}

int main(){
	std::istream & c_in = cin;
	for (int i = 0; i < M; ++i){
		for (int j = 0; j < M; ++j){
			C[i][j] = INIT;
		}
	}
	string s1, s2;
	getline(c_in, s1);
	getline(c_in, s2);
	s1 = "A" + s1 + "B";
	s2 = "A" + s2 + "B";
	const char* p1 = s1.c_str();
	const char* p2 = s2.c_str();
	countmatchstring(p1, p2, s1.length(), s2.length(),0, 0, 1,1,0);
	printf("%d\n", C[1][1]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()
#define MOD 1000000007
#define mod 998244353

int rw[100010];
vector<int> W[100010];

int main(){
	for (int i = 0;i < 100010;i++)rw[i] = -1;
	ll N, L;
	cin >> N;
	vector<ll> X(N);
	for (int i = 0;i < N;i++)
		cin >> X[i];
	cin >> L;
	for (int j = 0;j < N;j++) {
		if (rw[j] >= 0)continue;
		for (int i = j;i < N;) {
			W[j].push_back(i);
			if (rw[i] >= 0)break;
			rw[i] = j;
			auto it = upper_bound(all(X), X[i] + L);
			it--;
			i = it - X.begin();
		}
	}

	//for (int i = 0;i < N;i++)cout << rw[i] << " ";

	ll Q, a, b, c, d, ans = 0;
	cin >> Q;
	for (int i = 0;i < Q;i++) {
		ans = 0;
		cin >> a >> b;
		if (a > b)swap(a, b);
		a--;b--;
		c = rw[a];
		while (1) {
			auto it = W[c].end();
			it--;
			d = *it;
			if (d >= b)break;
			ans += it - find(all(W[c]), a);
			//cout << ans << endl;
			a = d;
			c = rw[a];
		}
		auto it1 = find(all(W[c]), a);
		auto it2 = lower_bound(all(W[c]), b);
		ans += it2 - it1;
		cout << ans << endl;
	}
}

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

int n, l, q;
vector<int> arr;

vector<vector<int>> table;

void preprocess() {
    int curr = 1;
    int i = 1;
    while(i <= n) {
        if(curr == n+1) {
            table[i][0] = curr - 1;
            i ++;
            continue;
        }
        while(curr <= n && (arr[curr] - arr[i]) <= l) {
            curr ++;
        }
        table[i][0] = curr - 1;
        i ++;
    }
    for(int i = n; i > 0; i --) {
        for(int j = 1; j < 30; j ++) {
            int mid = table[i][j-1];
            if(mid != -1) {
                table[i][j] = table[mid][j-1];
            }
        }
    }
}

int query(int l, int r) {
    if(l > r) swap(l, r);
    int ans = 0;
    for(int j = 29; j >= 0; j --) {
        int pw = 1LL << j;
        if(table[l][j] == -1) continue;
        if(arr[table[l][j]] < arr[r]) {
            l = table[l][j];
            ans += pw;
        }
    }
    ++ans;
    return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    arr.assign(n + 1, 0);
    table.assign(n+1, vector<int>(30, -1));
    for(int i = 1; i <= n; i ++) cin >> arr[i];
    cin >> l >> q;
    preprocess();
    // t(table);
    while(q --) {
        int low, high; cin >> low >> high;
        int ans = query(low, high);
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int K,X; cin >> K >> X;
    int a=X-K+1;
    if(K==1){
        cout << X << endl;
        return 0;
    }
    for(int i=a;i<X+K;i++){
        cout << i << " ";
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
(H,W)
(i,j)
1行ずつよまなきゃ
ああ、そういうことか
OXXXO
XXXXO
1
2になるのか
OXXXOXXOX
XXXOXXXXO
これはない

2e5)^2は無理
ええ・・・BITなら無理・・・
12345678
OOOXXXOO (1,1) (7,1) 4-6
OXXXXXXO (1,2) (8,2) 2-7
XXXXOOOO (5,7) (8,3) 1-4
OOOOOXXX (5,8) (9,3)みたいな

OOOXXXXX 4-8
XXOOOOOO 1-2
最高効率と手前保存しておくとか？

管理むずい

W通り保持・・・
12345678 //(スタート位置、今いるW）
OOOXXXOO {(1,1),(2,2),(3,3),(7,7),(8,8)} //0+1 {0,0,0,0,0}
OXXXXXXO {(1,1),(8,8)} //0+2 {0,0}
XXXXOOOO {(1,5),(8,8)} //0+3 {4,0}
OOOOOXXX {(1,5)} //(5-1)+4 {4}

mapとmultiset...
mapにlower_bound？
おしりから見ていくとか

(今いる位置、スタート位置）か。

・setにpair
set<pair<ll,ll>> S;
S.lower_bound({a,b});
a優先でb順に並んでる。

・eraseした後のitr
S.erase(itr);
itr++;
eraseした後ポインタの場所変わっちゃうので1つ先がとれるとは限らない。

S.erase(itr++);
erase処理前の移動でちゃんと1つ先がとれる。

おぎゃあああああああああああ

OOXX
XXOO
XXOO
OOOX
XXXO
XXXX
XXXO

最後消えてないじゃん
*/

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll H,W; cin>>H>>W;
  set<pair<ll, ll>> POS;
  multiset<ll> SC;
  rep(i, H){
    ll a, b, ans=0; cin>>a>>b;
    if (i == 0){
      for(ll j=1; j<a; j++){
        POS.insert({j, j});
        SC.insert(0);
      }
      for(ll j=b+1; j<=W; j++){
        POS.insert({j, j});
        SC.insert(0);
      }
    }
    else{
      auto itr1 = POS.lower_bound({a, -1});
      ll v1, v2;
      bool del = false;
      while(itr1 != POS.end() && itr1->first <= b){
        v1 = itr1->first;
        v2 = itr1->second;
        SC.erase(SC.find(v1 - v2));
        POS.erase(itr1++);
        del = true;
      }
      if (del && b < W && itr1->first != b+1){
        POS.insert({b+1, v2});
        SC.insert(b+1 - v2);
      }
    }
    if (SC.size() == 0){
      cout << -1 << endl;
      continue;
    }
    ans = *SC.begin();
    cout << ans + i + 1 << endl;

/*
cout<<"i:"<<i<<" SC.size():" << SC.size() << " POS.size():" << POS.size() << endl;
cout<<"SC:";
auto itr = SC.begin();
while (itr != SC.end()){
  cout<<*itr<<" ";
  itr++;
}
cout<<"POS:";
auto pitr = POS.begin();
while (pitr != POS.end()){
  cout<<"("<< pitr->first<<", "<<pitr->second<<") ";
  pitr++;
}
cout<<endl;
*/

  }
}


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

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

    pair<ll, ll> p[n];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
        ans += 0 - p[i].second;
    }

    ll q[n];
    for(int i = 0; i < n; i++){
        q[i] = p[i].first + p[i].second;
    }

    sort(q, q + n, greater<ll>());

    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            ans += q[i];
        }
    }

    cout << ans << endl;
}

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

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

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N;
	getint(N);

	std::vector<std::pair<LLONG, LLONG>> plates(N);
	for (int i = 0; i < N; i++) {
		getint(plates[i].first, plates[i].second);
	}

	std::sort(plates.begin(), plates.end(),
		[](const std::pair<LLONG, LLONG>& a, const std::pair<LLONG, LLONG>& b) {
		return (a.first + a.second) > (b.first + b.second);
	});

	bool tkhs = true;
	std::vector<std::pair<LLONG, LLONG>> tk, ao;
	for (int i = 0; i < N; i++) {
		if (tkhs) {
			tk.push_back(plates[i]);
			tkhs = false;
		}
		else {
			ao.push_back(plates[i]);
			tkhs = true;
		}
	}

	LLONG tkSum = 0;
	for (auto it = tk.begin(); it != tk.end(); it++) {
		tkSum += it->first;
	}
	LLONG aoSum = 0;
	for (auto it = ao.begin(); it != ao.end(); it++) {
		aoSum += it->second;
	}

	printf("%lld\n", tkSum - aoSum);
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  long x;
  cin >> x;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
  long count = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + a.at(i + 1) > x) {
      long count_plus = min(a.at(i) + a.at(i + 1) - x, a.at(i + 1));
      count += count_plus;
      a.at(i + 1) -= count_plus;
      if (a.at(i + 1) == 0) {
        long count_plus = a.at(i) - x;
        count += count_plus;
        a.at(i) -= count_plus;
      }
    }
  }
  cout << count << endl;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp

int n;
int A[100005];
int cnt;

static int par(int p, int r) {
    int i = p - 1;
    int x = A[r];
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(A[j], A[i]);
        }
    }
    swap(A[r], A[i+1]);
    return i+1;
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    int q = par(0, n-1);

    REP(i, n) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a, b, res;
int main(){
  cin >> a >> b;
  res = max(a+a-1, b+b-1);
  res = max(res, a+b);
  cout << res;
}

#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n,k;
int ans=1;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	while(n--) ans+=min(ans,k);
	cout<<ans;
	re 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {

  int N;
  cin>>N;

  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());

  int ans=0;

  int sum=1;

  for(int i=0;i<N;i++){
    if(A[i]==A[i+1]){
      sum++;
    }
    else{
      if(sum%2==1){
        ans++;
      }
      sum=1;
    }
  }

  cout<<ans<<endl;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  map<int, int> m;
  REP(i, N) {
    if(m[A[i]]) m.erase(A[i]);
    else m[A[i]]++;
  }
  cout << m.size() << endl;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    // 10x + 5y + z = Y
    // x + y + z = N
    // 9x + 4y = Y - N
    int n, yy;
    cin >> n >> yy;
    yy /= 1000;
    int x = -1, y = -1, z = -1;
    for (int i = 0; 4 * i <= yy - n; i++) {
        int t = yy - n - 4 * i;
        if (t >= 0 && t % 9 == 0 && n - t / 9 - i >= 0) {
            x = t / 9;
            y = i;
            z = n - x - y;
            break;
        }
    }
    cout << x << " " << y << " " << z << endl;
}

// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    const int sum_a = accumulate(a.begin(), a.end(), 0LL);
    if (x == sum_a) {
        cout << n << endl;
    } else if (x > sum_a) {
        cout << n - 1 << endl;
    } else {
        for (int i = 0; i < n; i++) {
            if (x >= a[i]) {
                x -= a[i];
            } else {
                cout << i << endl;
                break;
            }
        }
    }
}

// aが小さい子からちょうどお菓子を配るのが最適


#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
  char str[1000], cmd[7], p[1000];
  int a, b, q;
  string OUT;
  scanf("%s", str);
  string STR = str;
  scanf("%d", &q);
  for(int i = 0; i < q; i++){
    scanf("%s %d %d", cmd, &a, &b);
    string CMD = cmd;
    if(CMD == "replace"){
      scanf("%s", p);
      string P = p;
      STR.replace(a, b - a + 1, P);
    }
    else if(CMD == "reverse"){
      string R;
      for(int j = b; j >= a; j--){
	R += STR[j];
      }
      STR.replace(a, b - a + 1, R);
    }
    else if(CMD == "print"){
      for(int k = a; k <= b; k++){
	OUT += STR[k];
      }
      OUT += "\n";
    }
  }
  char* out;
  out = (char*)malloc(OUT.length() + 1);
  sprintf(out, "%s", OUT.c_str());
  printf("%s", out);
  free(out);
  return 0;
}

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
  string str;
  string pri;
  string rev;
  string p;
  string oreder;
  int q;
  int i;
  int a;
  int b;
  int j;
  int k;

  cin >> str >> q;

  for(k=0;k<q;k++)
  {
    cin >> oreder;
    if(oreder=="print")
    {
      cin >> a >> b;

      pri=str.substr(a,(b-a+1));

      cout << pri <<"\n";
      continue;
    }

    if(oreder=="reverse")
    {
      cin >> a >> b;
      rev=str.substr(a,(b-a+1));
      for(i=a,j=(b-a);i<=b;i++,j--)
      {
        str[i]=rev[j];
      }
      continue;
    }

    if(oreder=="replace")
    {
      cin >> a >> b >> p;

      for(i=a,j=0;i<=b;i++,j++)
      {
        str[i]=p[j];
      }
      continue;
    }

  }
}