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

const int N = 110000;

vector<int> con[N];
int vis[N];

bool dfs(int u, int col) {
	vis[u] = col;
	for (int v : con[u]) {
		if (vis[v] && 3 - col != vis[v]) return false;
		if (!vis[v] && !dfs(v, 3 - col)) return false;
	}
	return true;
}

int main() {

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

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		con[u].push_back(v), con[v].push_back(u);
	}

	if (!dfs(1, 1)) cout << (long long)n * (n - 1) / 2 - m << "\n";
	else {
		int cnt = 0;
		for (int i = 1; i <= n; i++) cnt += vis[i] == 1;
		cout << (long long)cnt * (n - cnt) - m << "\n";
	}

	return 0;
}

#include <bits/stdc++.h>

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

vector<ll> bfs(int n, vector<vector<int>> &g) {

    vector<ll> costs(n, INF);
    costs[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to  : g[from]) {
            if (costs[to] != INF) continue;
            costs[to] = costs[from] + 1;
            q.push(to);
        }
    }
    return costs;
}

bool bfs2(int n, vector<vector<int>> &g) {
    vector<ll> costs(n, INF);
    costs[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {

        int from = q.front();
        q.pop();
        for (int to  : g[from]) {

            ll current_cost = costs[to];
            ll next_cost = costs[from] + 1;

            if (current_cost != INF) {
                if (current_cost % 2 != next_cost % 2) return false;
                continue;
            }
            costs[to] = next_cost;
            q.push(to);
        }
    }
    return true;
}

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

    vector<P> v(m);
    for (P &p : v) cin >> p.first >> p.second, p.first--, p.second--;

    vector<vector<int>> g(n);
    for (P p: v) g[p.first].push_back(p.second);
    for (P p: v) g[p.second].push_back(p.first);

    vector<ll> costs = bfs(n, g);
    bool is_2 = bfs2(n, g);

    if (is_2) {
        ll a = 0;
        for (ll c : costs) if (c % 2 == 0) a++;
        ll b = n - a;
        ll all = a * b;
        ll ans = all - m;
        cout << ans << endl;
        ret();
    }

    ll all = ll(n) * (n - 1) / 2;
    ll ans = all - m;
    cout << ans << endl;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    vector<lint> zero(60);
    vector<lint> one(60);

    int n;cin>>n;
    lint x,tmp,ans=0;
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=0;j<60;j++){
            tmp=x%2;
            if(tmp==0)zero[j]++;
            else one[j]++;
            x/=2;
        }
    }
    const int mod=1000000007;
    tmp=1;
    for(int i=0;i<60;i++){
        ans+=(zero[i]*one[i]%mod)*tmp;
        ans%=mod;
        tmp=tmp*2%mod;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = x * x % mod;
	if(e&1) x = x * a % mod;
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	cin >> N >> M;
	cat tot = 1, dif = 0, fac_inv = 1, mod = 998244353;
	for(int i = 1; i < N; i++) {
		tot = tot * (3*M+i) % mod;
		fac_inv = fac_inv * i % mod;
	}
	vector<cat> prod_m1(N+3*M+1, 0), prod_m2(N+3*M+1, 0);
	prod_m1[0] = fac_inv;
	prod_m2[0] = fac_inv * pw(N-1, mod-2, mod) % mod;
	for(int i = 0; i < M; i++) {
		prod_m1[i+1] = prod_m1[i] * (i+N) % mod * pw(i+1, mod-2, mod) % mod;
		prod_m2[i+1] = prod_m2[i] * (i+N-1) % mod * pw(i+1, mod-2, mod) % mod;
	}
	for(int i = 0; i < M; i++) dif = (dif + prod_m2[i]) % mod;
	dif = dif * N % mod * (N-1) % mod;
	vector<cat> C(N+1, 0); // C(N, i)
	C[0] = 1;
	for(int i = 1; i <= N; i++) C[i] = C[i-1] * pw(i, mod-2, mod) % mod * (N-i+1) % mod;
	for(int i = M+1; i <= min(3*M, N); i++) if((M-i)%2 == 0)
		dif = (dif + prod_m1[(3*M-i)/2] * C[i]) % mod;
	cat ans = (tot - dif) * pw(fac_inv, mod-2, mod) % mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
int main() {
  int A, B;
  cin >> A >> B;
  int Xa, Xb, Xc;
  int co = 0;
  rep2(i, A, B) {
    Xa = i % 10;
    Xb = (i - Xa) % 100 / 10;
    Xc = (i - Xa - Xb*10) % 1000 / 100;
    if(Xa * 10001 + Xb * 1010 + Xc * 100 == i) {
      co++;
    }
  }
  cout << co << endl;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

const int N=500;
bool isprime[1000010];
vector<ll> ps;
ll res[N][N];
int di[]={-1,0,1,0};
int dj[]={0,1,0,-1};

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

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

  repl(i,2,1000000)isprime[i]=true;
  repl(i,2,1000000){
    if(isprime[i]){
      ps.push_back(i);
      for(ll j=i*2;j<1000000;j+=i)isprime[j]=false;
    }
  }

  while(ps.size()>1000)ps.pop_back();

    rep(i,N)rep(j,N)res[i][j]=1;
    for(ll s=0;s<2*N-1;s+=2){
      rep(i,N){
        ll j=s-i;
        if(j>=N||j<0)continue;
        res[i][j]*=ps[s/2];
      }
      rep(i,N){
        ll s2=s-N+2;
        ll j=i-s2;
        if(j>=N||j<0)continue;
        res[i][j]*=ps[N+(s/2)];
      }
    }

    rep(i,N)rep(j,N){
      if(res[i][j]==1){
        ll lc=1;
        rep(dir,4){
          int ni=i+di[dir],nj=j+dj[dir];
          if(ni<0||ni>=N||nj<0||nj>=N)continue;
          lc=lcm(lc,res[ni][nj]);
        }
        res[i][j]=lc+1;
      }
    }

  int n;
  cin>>n;
  rep(i,n){
    rep(j,n){
      cout<<res[i][j]<<" ";
    }
    cout<<endl;
  }

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n, cnt = 2;
long long res[507][507];
map<int, int>a, b;
int nxt()
{
	while (1)
	{
		bool ok = 1;
		for (int i = 2; i * i <= cnt && ok; i++)
			if (cnt % i == 0)ok = 0;
		if (ok)return cnt++;
		cnt++;
	}
	return 0;
}
long long gcd(long long a, long long b)
{
	if (!b)return a;
	return gcd(b, a % b);
}
long long lcm(long long a, long long b)
{
	if (!a || !b)return 0;
	return a / gcd(a, b) * b;
}
int main()
{
	cin >> n;
	if (n == 2) {
		printf("4 7\n23 10\n");
		return 0;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			res[i][j] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (((i + j) & 1) && !a[i + j])
				a[i + j] = nxt();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (((i + j) & 1) && !b[i - j])
				b[i - j] = nxt();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if ((i + j) & 1)
			{
				res[i][j] = 1LL * a[i + j] * b[i - j];
				res[i - 1][j] = lcm(res[i - 1][j], res[i][j]);
				res[i][j - 1] = lcm(res[i][j - 1], res[i][j]);
				res[i + 1][j] = lcm(res[i + 1][j], res[i][j]);
				res[i][j + 1] = lcm(res[i][j + 1], res[i][j]);
			}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (!((i + j) & 1))
				res[i][j]++;
	for (int i = 1; i <= n; i++, putchar('\n'))
		for (int j = 1; j <= n; j++)
			printf("%lld ", res[i][j]);
	return 0;
}


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

const ll C = 1000000007;

int main(){
    ll x;
    cin >> x;

    ll n = x / 11;
    n *= 2;
    ll m = x % 11;
    if (m > 6) {
        n += 2;
    }
    if(m > 0 && m <= 6) {
        n++;
    }
    cout << n << endl;
}


#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define N 1100005
using namespace std;

typedef long long ll;

ll n, ans, kac, a[N], pre[N], dp[N], fen[N], of[N];
vector < int > g[N];

ll fe(ll a, ll us){
	if(us <= 1)
		return (us)?a:1ll;
	ll t = fe(a, us/2);
	return (us&1)?(t*t%mod)*a%mod : t*t%mod;
}

void up(int x, int y){
	for(; x < N; x += x&-x)
		fen[x] += y;
}

int qu(int x){
	int ans = 0;
	for(; x > 0; x -= x&-x)
		ans += fen[x];
	return ans;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++){
		scanf("%lld",a + i);
		pre[i] = pre[i - 1]^a[i];
		g[pre[i]].pb(i);
		if(!pre[i])
			up(i, 1);
	}
	if(pre[n] != 0){
		ll sif = 1;
		ll bir = 0;
		for(int i = 1; i <= n; i++){
			if(pre[i] == pre[n])
				bir = (bir + sif)%mod;
			else if(pre[i] == 0)
				sif = (sif + bir)%mod;
		}
		printf("%lld\n", sif);
		return 0;
	}
	kac = (int)g[pre[n]].size();
	ans = (ans + fe(2, kac - 1))%mod;

	// cout << ans << endl;

	for(int i = 1; i < N; i++){
		if(g[i].empty())
			continue;
		int u = (int)g[i].size(), ek = 1;
		of[0] = dp[0] = 1;
		// cout << i << " " << u << endl << " -> " << g[i][0] << " ";
		for(int j = 1; j < u; j++){
			int ara = qu(g[i][j]) - qu(g[i][j - 1]);
			dp[j] = (dp[j - 1] - 1 + of[j - 1]*ara%mod + 1)%mod;
			of[j] = (of[j - 1] + dp[j])%mod;
			// cout << "(" << ara << ") " << g[i][j] << " - " << dp[j] << " ";
		}
		ans = (ans + of[u - 1])%mod;
		// cout << " = " << of[u - 1] << endl;
	}

	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
std::vector<int> dpa(1234567,0),dpb(1234567,1),memo(1234567,0);
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int now=0,zco=0;
  for(int i=0;i<N;i++){
    now^=v[i];
    if(now==0)zco++;
    else{
      dpb[now]+=dpa[now]*(zco-memo[now]);dpb[now]%=MOD;
      dpa[now]+=dpb[now];dpa[now]%=MOD;
      memo[now]=zco;
    }
  }
  if(now)cout<<dpb[now]<<endl;
  else{
    int ans=0;
    for(int i=0;i<1234567;i++)ans+=dpa[i];
    cout<<(ans+pw(2,zco-1))%MOD<<endl;
  }
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll x = 1;
    while(x*x<=n){
        x++;
    }
    cout << (x-1)*(x-1) << endl;

    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int N;
   cin>>N;
   for(int i=40000;i>=1;i--)
   {
       if(i*i<=N)
       {
           cout<<i*i<<endl;
           break;
       }
   }
}


// Problem : A - Painting
// Contest : AtCoder - Keyence Programming Contest 2020
// URL : https://atcoder.jp/contests/keyence2020/tasks/keyence2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,m,x;
    cin>>n>>m>>x;
    if(n < m) swap(n,m);
    cout<<(n+x-1)/n<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

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

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

  double ans;
  if(d==0){
    ans = (m-1)/n;
  }else{
    ans = 2*(n-d)/(n*n) * (m-1);
  }
  printf("%0.10f\n",ans);
}


#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define re register
#define LL long long
// #define MOD 1000000007
#define MAXN 6005
using namespace std;
const int ST=6002;
LL n,ans,MOD,dp[MAXN][MAXN<<1];
LL rd(){
	LL x=0,tp=1;char c;c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
int add(int a,int b){return (a+b>=MOD)?(a+b-MOD):a+b;}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("shit.out","w",stdout);
	n=rd()*3,MOD=rd();
	dp[0][ST]=1;
	for(int i=0;i<n;i++){
		for(int j=-i;j<=i;j++){
			dp[i+1][ST+j+1]=add(dp[i+1][ST+j+1],dp[i][ST+j]);
			dp[i+2][ST+j-1]=add(dp[i+2][ST+j-1],dp[i][ST+j]*(i+1)%MOD);
			dp[i+3][ST+j]=add(dp[i+3][ST+j],dp[i][ST+j]*(i+1)%MOD*(i+2)%MOD);
		}
	}
	for(int i=0;i<=n;i++)ans=add(ans,dp[n][ST+i]);
	printf("%lld\n",ans);
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}


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

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

  string ans;
  int L = A + B, R = C + D;
  if (L > R) {
    ans = "Left";
  } else if (L == R) {
    ans = "Balanced";
  } else {
    ans = "Right";
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>

#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a=-2,b;
    cin>>n;b=n;
    string s;
    while(n!=0){
        if((n%a)<0){s+=(2+(n%a))+'0';n/=a;n+=1;}
        else {s+=(n%a)+'0';n/=a;}
    }
    reverse(s.begin(),s.end());
    if(b!=0)cout<<s<<endl;
    else cout<<0<<endl;
}


#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	rep(i,(1<<3)){
		int num = (s[0] - '0');
		rep(j,3){
			if(i>>j & 1){
				num += (s[j+1] - '0');
			}
			else{
				num -= (s[j+1] - '0');
			}
		}
		if(num == 7){
			cout << s[0] << ((i>>0 & 1) ? "+" : "-");
			cout << s[1] << ((i>>1 & 1) ? "+" : "-");
			cout << s[2] << ((i>>2 & 1) ? "+" : "-");
			cout << s[3] << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    int n;
    cin >> n;
    int ans = (n / 500) * 1000;
    n %= 500;
    ans += (n / 5) * 5;
    cnl(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


#include<iostream>
using namespace std;
int s[10004];
int cnt,n;
void find(int s[],int num)
{
	for(int i=0;i<n;i++)
	{
		if(s[i]==num)
		{
			cnt++;
			break;
		}
	}
}
int main()
{
	cin>>n;
	for(int k=0;k<n;k++)
	{
		cin>>s[k];
	}
	int q;
	cin>>q;
	while(q--)
	{
		int nn;
		cin>>nn;
		find(s,nn);

	}
	cout<<cnt<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n ;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >>  a[i];
    }
    long long int sum=0;
    for (int i = 0; i < n; i++){
        sum += a[i];
    }
    long long int min = *min_element(a.begin(), a.end());
    long long int max = *max_element(a.begin(), a.end());

    printf("%ld %ld %lld\n", min, max, sum);
}


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

using Int = std::int64_t;

constexpr Int MOD = 1e9 + 7;

int main() {
	Int N, X;
	std::cin >> N >> X;

	std::vector<Int> S(N);
	for (auto&& e : S)
		std::cin >> e;

	std::sort(S.begin(), S.end());

	// dp[i][x] := 最初が x のときに i 個目まで見たときの総和
	std::vector<std::vector<Int>> dp(N + 1, std::vector<Int>(X + 1));
	for (Int x = 0; x < X + 1; ++x)
		dp[0][x] = x;

	for (Int i = 1; i < N + 1; ++i) {
		for (Int x = 0; x < X + 1; ++x) {
			// 前に挿入
			dp[i][x] += dp[i - 1][x % S[i - 1]];
			dp[i][x] %= MOD;
			// 後ろに挿入
			dp[i][x] += (i - 1) * dp[i - 1][x];
			dp[i][x] %= MOD;
		}
	}

	std::cout << dp[N][X] << std::endl;
}

#include<bits/stdc++.h>
#define	INF	0x3f3f3f3f
#define	LL	long long
#define	MAXN	210
#define	MAXS	100010
#define	mod	1000000007
using namespace std;
int n, x, w[MAXN];
int f[MAXN][MAXS];

template <typename T> void chkmin(T &x, T y){x = min(x, y);}
template <typename T> void chkmax(T &x, T y){x = max(x, y);}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

void update(int &x, const int &y){x = (x + y >= mod) ? (x + y - mod) : (x + y);}
int mul(const int &x, const int &y){return 1ll * x * y % mod;}
int inc(const int &x, const int &y){return (x + y >= mod) ? (x + y - mod) : (x + y);}

int main(){
	read(n), read(x);
	for (int i = 1; i <= n; ++i)
		read(w[i]);
	sort(w + 1, w + 1 + n);
	for (int i = 0; i <= x; ++i)
		f[0][i] = i;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= x; ++j){
			if (!f[i - 1][j]) continue;
			update(f[i][j], mul(f[i - 1][j], i - 1));
			if (w[i] > j) {
				for (int t = 0; j + t <= x; t += w[i])
					update(f[i][j + t], f[i - 1][j]);
			}
		}
	printf("%d\n", f[n][x]);
	return 0;
}


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

int EditDistance(string s1,string s2){
    int n=s1.size();
    int m=s2.size();
    int dp[n+1][m+1];

    for(int i=0;i<n+1;i++){
        dp[i][0]=i;
    }
    for (int j=0;j<m+1;j++){
        dp[0][j]=j;
    }

    for (int i=1;i<n+1;i++){
        for (int j=1;j<m+1;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=min( min(dp[i-1][j] +1, dp[i][j-1]+1) , dp[i-1][j-1]);
            }else{
                dp[i][j]=min( min(dp[i-1][j] +1, dp[i][j-1]+1) , dp[i-1][j-1]+1);
            }
        }
    }
    return dp[n][m];
}

int main(){
    string s1,s2;
    cin >> s1 >> s2;

    cout << EditDistance(s1,s2) << endl;
}

#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

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

    int a, b;
    cin >> a >> b;

    int ans = 0;
    forn(i, a, b+1) {
        string s = to_string(i);
        string r = s;
        reverse(r.begin(), r.end());
        ans += s==r;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 100010
#define int ll

int N,L,Q;
int A[maxn];
vi adj[maxn];

int twok[maxn][100],depth[maxn];

void twokdecomp(int x,int p){
	twok[x][0] = p;
	for (int i=1;i<=18;i++){ //i <= logmaxn
		if (twok[x][i-1] == -1) break;
		twok[x][i] = twok[twok[x][i-1]][i-1];
	}
	for (auto i: adj[x]){
		if (i != p){
			depth[i] = depth[x] + 1;
			twokdecomp(i,x);
		}
	}
}

int kth_parent(int x,int k){

	for (int i=0;i<=18;i++){
		if (k&(1<<i)){
			x = twok[x][i];
		}
		if (x==-1) break;
	}
	return x;

}

int32_t main(){
	fast;

	cin>>N;
	FOR(i,1,N) cin>>A[i];

	cin>>L>>Q;

	FOR(i,1,N-1){

		int idx = upper_bound(A+1,A+N+1,A[i] + L) - A;

		idx--;

		if (i == idx) continue;
		adj[i].pb(idx);
		adj[idx].pb(i);

	}

	mem(twok,-1);

	twokdecomp(N,-1);

	FOR(i,0,Q-1){
		int a,b; cin>>a>>b;
		if (a > b) swap(a,b);

		int l=0,r=depth[a]+10;

		while (l + 1 < r){

			int mid = (l+r)/2;
			//cout<<mid<<' '<<kth_parent(a,mid)<<'\n';

			if (kth_parent(a,mid) == -1) r = mid;
			else if (kth_parent(a,mid) > b) r = mid;
			else l = mid;
		}

		while (kth_parent(a,l) < b){
			l++;
		}
		cout<<l<<'\n';

	}

}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1000010;
int n;
int a[N];
int L, q, ans, lst;
int dp[N][21];
int pow[21];
int main() {
	memset(dp, 0x3f, sizeof(dp));
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	scanf("%d", &L);
	scanf("%d", &q);
	pow[0] = 1;
	lst = 1;
	for (int i = 1; i <= n; i++) {
		while (a[i] > a[lst] + L) {
			dp[lst++][0] = i - 1;
		}
	}
	for (int j = 1; j <= 20; j++) {
		pow[j] = pow[j - 1] << 1;
		for (int i = 1; i <= n; i++) {
			if (dp[i][j - 1] < 0x3f3f3f3f) dp[i][j] = dp[dp[i][j - 1]][j - 1];
		}
	}
	while (q--) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		ans = 0;
		for (int i = 20; i >= 0; i--) {
			if (dp[x][i] < y) {
				x = dp[x][i];
				ans += pow[i];
			}
		}
		printf("%d\n", ans + 1);
	}
	return 0;
}


#include<iostream>
using namespace std;
static const int INF = 0x7fffffff;
static const int MAXN = 101;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, M[MAXN][MAXN];

int prim()
{
	int node, minn;  //记录当前状态权值最小的边和对应的节点
	int d[MAXN], p[MAXN], color[MAXN]; //最小边权，父节点，访问状态
	/*初始化*/
	for (int i = 0; i < n; i++)
	{
		d[i] = INF;
		p[i] = -1;
		color[i] = WHITE;
	}
	d[0] = 0;  //初始节点加入MST
	while (true)
	{
		node = -1;
		minn = INF;
		for (int i = 0; i < n; i++)
		{
			if (d[i] < minn && color[i] != BLACK)
			{
				minn = d[i];
				node = i;
			}
		}
		if (node == -1)	break; //图遍历完毕，没有可以新加入MST的节点
		color[node] = BLACK;   //把新节点加入MST

		/*更新状态*/
		for (int i = 0; i < n; i++)
		{
			if (color[i] != BLACK && M[node][i] < INF)
			{
				if (d[i] > M[node][i])
				{
					d[i] = M[node][i];
					p[i] = node;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] != -1)	sum += M[i][p[i]];  //求MST每条边的权和
	}
	return sum;
}

int main()
{
	int tmp;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> tmp;
			M[i][j] = (tmp == -1 ) ? INF : tmp;
		}
	}
	cout << prim() <<endl;
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
  int n;
  string line;
  cin >> n;
  getline(cin, line);
  while(n--){
    int p;
    getline(cin, line);
    while((p = line.find("Hoshino")) != -1){
      line[p+6] = 'a';
    }
    cout << line << endl;
  }
  return 0;
}


#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;
    vector<int> A;
    A.emplace_back(1e9 + 100);
    while(N--) {
        int a; cin >> a;
        if(a <= *(A.end()-1)) A.emplace_back(a);
        else {

            int ok = int(A.size());
            int ng = -1;
            while(abs(ok - ng) > 1) {
                int x = (ok + ng) / 2;
                if(A.at(x) < a) ok = x;
                else ng = x;
            }
            A.at(ok) = a;
        }
    }
    cout << A.size() - 1 << endl;
    return 0;
}

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

// 参考資料：https://hiramekun.hatenablog.com/entry/2019/07/21/082628

#define N 100000
#define INF ((1<<31)-1)

multiset<int> setMaxNum;       // 色ごとに仕分けされた集合の最大値を格納

int main() {
    // 入力
    int n;
    vector<int> a;
    cin >> n;
    for (int i = 0; i < n; i++){
        int aTmp;
        cin >> aTmp;
        a.push_back(aTmp);
    }

    //
    for (int i = 0; i < n; i++){
        auto itr = setMaxNum.lower_bound(a[i]);
        if (itr != setMaxNum.begin()){          // 入力値 a[i] より小さい setMaxNum がある場合、その集合と同じ色で塗れる
            setMaxNum.erase(--itr);             // 同じ色で塗られてる集合の最大値が変わるため、元の最大値を削除する
        }
        setMaxNum.insert(a[i]);
    }

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

    return 0;
}


#include <stdio.h>

int main() {
	char kaping[14];
	scanf("%s", kaping);
	kaping[3] = '8';
	printf("%s", kaping);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    ll cur = 0;
    ll now = -2;
    vector<ll> v;
    if(N==0)v.push_back(0);
    while(N != 0){
        if(N % now == 0){
            v.push_back(0);
        }else{
            v.push_back(1);
            N--;
        }
        N /= -2;
    }
    reverse(v.begin(),v.end());
    rep(i,v.size()){
        cout << v[i];
    }
    cout << endl;
}

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define rg register
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
const int maxn=2010,mod=1e9+7,N=4e6;
int n,m,f[maxn][maxn],fac[maxn*maxn],inv[maxn*maxn];
int mul(int x,int y){return 1ll*x*y-1ll*x*y/mod*mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int del(int x,int y){return x-y<0?x-y+mod:x-y;}
int mi(int a,int b){int ans=1;while(b){if(b&1)ans=mul(ans,a);b>>=1,a=mul(a,a);}return ans;}
void prepare(){
    fac[0]=inv[0]=1;
    for(rg int i=1;i<=N;i++)fac[i]=mul(fac[i-1],i);
    inv[N]=mi(fac[N],mod-2);
    for(rg int i=N-1;i;i--)inv[i]=mul(inv[i+1],i+1);
}
int C(int n,int m){return mul(fac[n],mul(inv[m],inv[n-m]));}
int main(){
    read(n),read(m),prepare();
    if(m==1)return printf("1\n"),0;
    for(rg int i=1;i<=n;i++){
	f[i][0]=1;
	for(rg int j=1;j<=i;j++)
	    f[i][j]=add(f[i-1][j],mul(mul(f[i][j-1],n-j+1),C(n*m-(j-1)*(m-1)-i-1,m-2)));
    }
    printf("%d\n",f[n][n]);
}


#include <bits/stdc++.h>
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;
const int INF_N = 1e+9;
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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

vec memo(1005);
queue<int> v[1005];

void solve() {
    int N; cin >> N;
    auto tmemo = memo;
    rep1(i, N){
        rep(j, N-1){
            int a; cin >> a;
            v[i].push(a);
        }
    }
    int res = 0;
    while(1){
        bool f = false;
        memo = tmemo;
        rep1(i, N){
            if(v[i].empty()) continue;
            int tmp = v[i].front();
            if(memo[i] || memo[tmp]) continue;
            if(v[tmp].front() == i){
                f = true;
                v[i].pop(); v[tmp].pop();
                memo[i] = memo[tmp] = 1;
            }
        }
        if(!f) break;
        res++;
    }
    rep1(i, N){
        if(!v[i].empty()){
            cout << -1 << endl;
            return;
        }
    }
    cout << res << endl;
}

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

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> as(n);
    int sum = 0;
    for (auto& a : as)
    {
        cin >> a;
        sum += a;
    }
    int min_diff = numeric_limits<int>::max();
    int min_index = -1;
    for (int i = 0; i < n; i++)
    {
        auto diff = abs(sum - as[i] * n);
        if (min_diff > diff)
        {
            min_diff = diff;
            min_index = i;
        }
    }
    cout << min_index << endl;
}


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

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

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

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

  for(long i = 1; i <= n; i++) {
    if(i % 3 == 0 || i % 5 == 0) continue;
    sum += i;
  }

  cout << sum << endl;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ans;
int f[25][25];
int w,h,sx,sy,gx,gy;
void dfs(int x,int y,int turn)
{
	if(turn>10||turn>=ans)return;
	for(int i=y+1;i<w;i++)
	{
		if(x==gx&&i==gy)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[x][i]==1)
		{
			if(i==y+1)break;
			f[x][i]=0;
			dfs(x,i-1,turn+1);
			f[x][i]=1;
			break;
		}
	}
	for(int i=y-1;i>=0;i--)
	{
		if(x==gx&&i==gy)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[x][i]==1)
		{
			if(i==y-1)break;
			f[x][i]=0;
			dfs(x,i+1,turn+1);
			f[x][i]=1;
			break;
		}
	}
	for(int i=x+1;i<h;i++)
	{
		if(gx==i&&gy==y)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[i][y]==1)
		{
			if(i==x+1)break;
			f[i][y]=0;
			dfs(i-1,y,turn+1);
			f[i][y]=1;
			break;
		}
	}
	for(int i=x-1;i>=0;i--)
	{
		if(gx==i&&gy==y)
		{
			ans=min(ans,turn);
			return;
		}
		if(f[i][y]==1)
		{
			if(i==x-1)break;
			f[i][y]=0;
			dfs(i+1,y,turn+1);
			f[i][y]=1;
			break;
		}
	}
	return;
}
int main()
{
	while(1)
	{
		ans=100;
		memset(f,0,sizeof(f));
		scanf("%d %d",&w,&h);
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				scanf("%d",&f[i][j]);
				if(f[i][j]==2)
				{
					sx=i;sy=j;
					f[i][j]=0;
				}
				if(f[i][j]==3)
				{
					gx=i;gy=j;
					f[i][j]=0;
				}
			}
		}
		dfs(sx,sy,1);
		if(ans==100)printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}

// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};

main {
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    auto a = vectors(h, w, 0LL);
    cin >> a;
    int si, sj;
    rep(i, h) rep(j, w) if (a[i][j] == 2) si = i, sj = j;
    function<int(int, int, int)> dfs = [&](int i, int j, int c) {
      if (c == 10) return INF;
      int mini = INF;
      rep(k, 4) {
        int ni = i + di[k], nj = j + dj[k];
        if (ni < 0 || nj < 0 || ni >= h || nj >= w || a[ni][nj] == 1) continue;
        while (0 <= ni && ni < h && 0 <= nj && nj < w) {
          if (a[ni][nj] == 3) {
            cmin(mini, c + 1);
            break;
          }
          if (a[ni][nj] == 1) {
            a[ni][nj] = 0;
            cmin(mini, dfs(ni - di[k], nj - dj[k], c + 1));
            a[ni][nj] = 1;
            break;
          }
          ni += di[k], nj += dj[k];
        }
      }
      return mini;
    };
    int ans = dfs(si, sj, 0);
    cout << (ans == INF ? -1 : 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 ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

void func(ll* x,ll* y){
  *x -= (*x%2);
  *x /= 2;
  *y += *x;
}

int main(){
  ll A,B;
  int K;
  cin >> A>>B>>K;
  bool turn_A = true;
  REP(i,K){
    if(turn_A){func(&A,&B);}
    else{func(&B,&A);}
    turn_A = !turn_A;
  }
  printf("%d %d\n",A,B);
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int tk = a, ao = b;
  for (int i = 0; i < k; ++i) {
    if (i % 2 == 0) {
      if (tk & 1) {
        tk--;
      }
      ao += tk / 2;
      tk /= 2;
    } else {
      if (ao & 1) {
        ao--;
      }
      tk += ao / 2;
      ao /= 2;
    }
  }
  cout << tk << " " << ao << endl;
  return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	if(N%K == 0){

		printf("0\n");

	}else{

		printf("1\n");
	}

	return 0;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	cout << min(1, a % b) << "\n";

	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.length(); i = i + w)cout << s.at(i);
	cout << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<bool> prime(222220,true);
  for(int i=2; i<=222220; ++i) for(ll j=(ll)i*i; j<=222220; j += i){
    prime[j] = false;
  }
  vector<int> ans(n);
  int num = 0;
  for(int i=11; i<=55555; i += 5){
    if(!prime.at(i)) continue;
    ans[num] = i;
    ++num;
    if(num == n) break;
  }
  for(int i=0; i<n; ++i){
    if(i != n-1)cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }
}


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

bool CheckPayable(int x, vector<int> D){
  // x中にDが含まれていなければtrue,含まれていればfalse
  while(x>0){
    for(int i=0;i<D.size();i++){
      if(x%10 == D[i])return false;
    }
    x /= 10;
  }
  return true;
}

int main(){
  int N,K;
  cin >> N >> K;
  // N < 10000なので全列挙でもイケる？
  vector<int> D(K);
  rep(i,K)cin >> D[i];

  int ans = N;
  while(true){
    if(CheckPayable(ans, D)){
      cout << ans << endl;
      break;
    }
    ans++;
  }

}

/*
1:条件から支払い可能な数字を列挙してN以上であれば出力する
2:Nから支払額を1ずつ大きくして支払い可能であれば出力する全列挙
1の組み合わせのCpp実装むずそうなので2の方針で

数字の支払い可能か如何をどうやって判別しよう
*/

#include<stdio.h>
int main (){
	int ha;
	int wa;
	int na;
	int hasil;

	scanf("%d", &ha);
	scanf("%d", &wa);
	scanf("%d", &na);

	if(ha>=wa){
        if(na%ha == 0) {
            hasil = na/ha;
        } else {
            hasil = na/ha+1;
        }
    } else {
        if(na%wa == 0) {
            hasil = na/wa;
        } else {
            hasil = na/wa+1;
        }
    }
    printf("%d", hasil);
	return 0;
}


// ref: https://img.atcoder.jp/arc093/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

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

    int K=50;
    int A, B; cin >> A >> B; --A; --B;
    vector<string> vS(100);
    for(int i=0; i<K;   ++i){ vS[i] = string(100, '#'); }
    for(int i=K; i<2*K; ++i){ vS[i] = string(100, '.'); }

    int cnt=0;
    for(int i=0; i<K-1; i+=2){
        if(cnt >= A){ break; }
        for(int si=0; si<2*K; si+=2){
            if(cnt >= A){ break; }

            vS[i][si] = '.'; ++cnt;
        }
    }
    cnt=0;
    for(int i=K+1; i<2*K; i+=2){
        if(cnt >= B){ break; }
        for(int si=0; si<2*K; si+=2){
            if(cnt >= B){ break; }

            vS[i][si] = '#'; ++cnt;
        }
    }

    cout << 2*K << ' ' << 2*K << endl;
    for(int i=0; i<2*K; ++i){
        cout << vS[i] << endl;
    }

    return 0;
}

#include <iostream>
#include <algorithm>

#define MAXN 100
#define WHITE 0
#define BLACK 1

using namespace std;

int D[MAXN][MAXN];

bool judge ( int color, int i, int j)
{
  if ( i-1 >= 0 && j-1 >= 0 && D[i-1][j-1] == color ) return false;
  if ( i-1 >= 0 && D[i-1][j] == color ) return false;
  if ( i-1 >= 0 && j+1 < MAXN && D[i-1][j+1] == color ) return false;
  if ( i+1 < MAXN && j-1 >= 0 && D[i+1][j-1] == color ) return false;
  if ( i+1 < MAXN && D[i+1][j] == color ) return false;
  if ( i+1 < MAXN && j+1 < MAXN && D[i+1][j+1] == color ) return false;
  if ( j-1 >= 0 && D[i][j-1] == color ) return false;
  if ( j+1 < MAXN && D[i][j+1] == color ) return false;

  return true;
}

int main()
{
  int A,B;
  int cnt;

  cin >> A >>B;

  for ( int i = 0; i < 50; ++i ) {
    for ( int j = 0; j < MAXN; ++j ) D[i][j] = BLACK;
  }

  cnt = 1;
  for ( int i = 0; i < 49; ++i ) {
    for ( int j = 0; j < MAXN; ++j ) {
      if ( cnt == A ) break;
      if ( judge(WHITE, i,j) ) {
        D[i][j] = WHITE;
        ++cnt;
      }
    }
  }

  cnt = 1;
  for ( int i = 51; i < MAXN; ++i ) {
    for ( int j = 0; j < MAXN; ++j ) {
      if ( cnt == B ) break;
      if ( judge(1, i, j) ) {
        D[i][j] = 1;
        ++cnt;
      }
    }
  }

  cout << " " << MAXN << " " << MAXN <<"\n";
  for ( int i = 0; i < MAXN; ++i ) {
    for ( int j = 0; j < MAXN; ++j ) {
      if ( D[i][j] ) cout << '#';
      else cout << '.';
    }
    cout << "\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    cout<<((e-a<=k)?"Yay!":":(")<<endl;
}

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

using namespace std;

int main() {
	int antennas[5];
	for (int i = 0; i < 5; i++) cin >> antennas[i];
	int k;
	cin >> k;
	string ans = "Yay!";
	for (int i = 0; i < 4; i++) {
		for (int j = i + 1; j < 5; j++) {
			if (antennas[j] - antennas[i] > k) ans = ":(";
		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    vector<string> a = {"hi","hihi","hihihi","hihihihi","hihihihihi"};
    string s;
    cin >> s;
    rep(i, sz(a)){
        if(a[i] == s){
            print("Yes");
            return 0;
        }
    }
    print("No");

}

//queue<pint>().swap(q); キュー内を全て削除
//priority_queue<ll, vector<ll>, greater<ll> > que;
//auto dp=make_v<int>(4,h,w);
//vector<vector<ll>> g;
//g.assign(n, vector<ll>()); g.resize(n);でも大丈夫っぽい
//fill_v(dp,0);
//int n;
//cin >> n;
//vector<int> test(n);
//cins(all(test));
//array_output(all(test));
// Yes(true);

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();

    bool ok = true;
    if (n % 2) ok = false;
    else {
        REP(i, n) {
            if (i % 2) {
                if (s[i] != 'i')
                    ok = false;
            } else {
                if (s[i] != 'h')
                    ok = false;
            }
        }
    }

    if (ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}


#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

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

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

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using lint128 = __int128_t;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void assert_NO(T condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
template<class T> inline void assert_No(T condition){ if(!condition){ cout << "No" << endl; exit(0); } }
template<class T> inline void assert_minus_1(T condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int at(lint x, int k){ return (x >> k) & 1; }
random_device rnd;
#define rep(i, n) for(int i = 0; i < n; i++)

int N;
lint M;

lint dp[6020][4020];

lint decide(int now, int c_minus_b){
    if(now == N * 3){
        return c_minus_b >= 0;
    }
    if(now > N * 3){
        return 0;
    }
    if(c_minus_b > N){
        c_minus_b = N;
    }
    if(c_minus_b < -N){
        return 0;
    }
    if(dp[now][c_minus_b + 2010] != -1){
        return dp[now][c_minus_b + 2010];
    }
    lint ans = 0;
    ans += decide(now + 3, c_minus_b) * (now + 1) % M * (now + 2) % M;
    ans += decide(now + 2, c_minus_b - 1) * (now + 1) % M;
    ans += decide(now + 1, c_minus_b + 1);
    return dp[now][c_minus_b + 2010] = ans % M;
}

int main(){
    cin >> N >> M;
    memset(dp, -1, sizeof(dp));
    cout << decide(0, 0) << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    ll a[2*n];a[0]=0;
    ll b[2];rep(i,0,1)b[i]=0;
    b[0]++;
    rep(i,1,2*n-1){
        if(s[i]==s[i-1]){
            a[i]=1-a[i-1];
        }else{
            a[i]=a[i-1];
        }
        b[a[i]]++;
    }

    if(b[0]!=n || s[0]=='W' || s[2*n-1]=='W'){
        cout<<0<<endl;
        return 0;
    }

    ll sum=0;
    ll ans=1;
    rep(i,1,n){
        ans=mod(ans*i);
    }
    rep(i,0,2*n-1){
        //cout<<a[i];
        if(a[i]==0){
            sum++;
        }else{
            ans=mod(ans*sum);
            sum--;
        }
    }
    cout<<ans<<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)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--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;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

signed main()
{
    int N; cin >> N;
    string S; cin >> S;
    const int mod = 1e9 + 7;

    int l = 0;

    ll ans = 1;

    rep(i, N*2) {
        if (S[i] == 'B') {
            if (l % 2 == 0) {
                l++;
            } else {
                ans *= l;
                ans %= mod;
                l--;
            }
        } else {
            if (l % 2 == 0) {
                ans *= l;
                ans %= mod;
                l--;
            } else {
                l++;
            }
        }
    }

    if (l > 0) {
        puts("0");
        return 0;
    }

    rep(i, N) {
        ans *= i + 1;
        ans %= mod;
    }

    cout << ans << endl;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi s(m), c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    vi q(n, -1);
    rep(i, m) {
        if (q[s[i]]!=-1 && q[s[i]]!=c[i]) {
            cout << -1 << endl;
            return 0;
        }
        else q[s[i]] = c[i];
    }
    if (n>1 && q[0]==0) {
        cout << -1 << endl;
        return 0;
    }
    int b = 1, e = 10;
    rep(i, n-1) {
        b *= 10; e *= 10;
    }
    if (n == 1) b = 0;
    for (int i=b; i<e; ++i) {
        int i2 = i;
        bool ok = true;
        repr(j, n) {
            if (q[j]!=-1 && i2%10!=q[j]) ok = false;
            i2 /= 10;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,maxi=0,f=0,mini=INF;
    ll sum=0;
    string str,sub;
    ll h,w;
    ll m;
    cin>>n>>m;
    if(m==0){
        if(n==1){
            cout<<0<<endl;
        }else if(n==2){
            cout<<10<<endl;
        }else{
            cout<<100<<endl;
        }
        return 0;
    }
    vector<pair<ll,ll>> s(m);

    rep(i,m){
        cin>>a>>b;
        s[i]=make_pair(a,b);
    }
    f=0;
    sort(s.begin(),s.end());
    sum=0;
            if(s[0].first==1) {
                //sum-=100;
                if(s[0].second==0&&n!=1) f=1;

                sum+=100*s[0].second;
            }
            if(s[0].first==2){
                //if(s[0].second==0&&n==2) f=1;

                sum+=10*s[0].second;
               // sum-=10;
            }
            if(s[0].first==3){
                //sum-=1;
                sum+=1*s[0].second;
            }
    for(ll i=1;i<m;i++){
        if(s[i-1].first==s[i].first&&s[i-1].second!=s[i].second) f=1;
        else if(s[i-1].first==s[i].first&&s[i-1].second==s[i].second) continue;
        else{
            if(s[i].first==1) {
               // sum-=100;
               if(s[i].second==0&&n!=1) f=1;
                sum+=100*s[i].second;
            }
            if(s[i].first==2) {
               // sum-=10;
                sum+=10*s[i].second;
            }
            if(s[i].first==3) {
              //  sum--;
                sum+=1*s[i].second;
            }
        }
    }
    if(n==1&&sum!=0) sum/=100;
    if(n==2&&sum!=0) sum/=10;
    if(n==3&&sum!=0&&sum<100) sum+=100;
    if(n==2&&sum<10) sum+=10;
    if(f!=1&&sum==0&&n==1){
        cout<<0<<endl;
        return 0;
    }

    if(f==1){
        cout<<"-1"<<endl;
    }else{
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  vc S;

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

  while(N != 0){
    if(N % (-2) == 0){
      S.push_back('0');
    } else{
      S.push_back('1');
      N--;
    }

    N /= -2;
  }

  rep_inv(i, S.size() - 1, -1) cout << S[i];

  cout << "\n";

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int B;
  cin>>A>>B;
  int i=0;
  int j=B-A;
  int sum=0;
  int C=A;
  while(i<=j){
    A=C;
    int a=A%10;//A=12345の時5
    A/=10;//A=1234
    int b=A%10;
    A/=10;//A=123
    A/=10;//A=12
    int d=A%10;
    A/=10;//A=1
    int e=A;
    if(a==e&&b==d){
      sum+=1;
    }
    C++;
    i++;
  }
  cout<<sum<<endl;

}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  cout<<((a-1)/111+1)*111<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

int main(){
    ll N,K;
    cin>>N>>K;
    if(N%K==0)cout<<0;
    else cout<<1;

    return 0;
}

#include <bits/stdc++.h>

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

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

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

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

using ll = long long;

using namespace std;

bool ok(const string& s) {
  if (s[0] != 'A') {
    return false;
  }
  if (count(s.begin() + 2, s.end() - 1, 'C') != 1) {
    return false;
  }
  int lower = 0;
  for (char c : s) if (islower(c)) ++lower;
  return lower == s.size() - 2;
}

int main() {
  in(string, s);
  out(ok(s) ? "AC" : "WA");
}


#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<int>prices(N);
		for (int i = 0; i < N; ++i) {
			cin >> prices[i];
		}
		sort(prices.begin(), prices.end(), greater<int>());
		int ans=0,num = 0;
		for (int i = 0; i < N; ++i) {
			num++;
			if (num == M) {
				num = 0;
			}
			else {
				ans += prices[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,x,a[105],ans=0;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(x>a[i] && i!=n-1){
            ans++;
            x-=a[i];
        }
        else if(a[i]==x){
            ans++;
            x-=a[i];
        }
    }
    cout<<ans<<endl;
    return(0);
}


#include "bits/stdc++.h"
using namespace std;
template<typename Itr>
auto partition2(const Itr first, const Itr last){
  auto i=first;
  for(auto j=first; j!=last; ++j){
    if(*j<=*last){
      iter_swap(i, j);
      ++i;
    }
  }
  iter_swap(i, last);
  return i;
}
int32_t main(){
  size_t n; cin>>n;
  vector<uint32_t> a(n); for(auto&& e:a) cin>>e;
  const auto last=--end(a);
  auto mid=partition2(begin(a), last);
  for(auto i=begin(a); i!=mid; ++i) cout<<*i<<' ';
  cout<<'['<<*mid<<"] ";
  for(auto i=next(mid); i!=last; ++i) cout<<*i<<' ';
  cout<<*last<<'\n';
}

#include <iostream>
#define MAX 100001
using namespace std;

void Partition(int A[], int n, int& l) // l is the last index of smaller part
{
    int x = A[n-1];
    for (int i = 0; i < n-1; ++i)
    {
        if (A[i] <= x)
        {
            swap(A[i], A[l+1]);
            l++;
        }
    }
    l++;
    swap(A[l], A[n-1]);
}

int main()
{
    int n, A[MAX];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
    int l = -1;
    Partition(A, n, l);

    for (int i = 0; i < n; ++i)
    {
        if (i == l) printf("[%d]", A[i]);
        else printf("%d", A[i]);
        if (i != n-1) printf(" ");
        else printf("\n");
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

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

    bool m = regex_match(S, regex("(hi)+"));
    cout << (m?"Yes":"No") << endl;
}

#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    if(S.length() % 2 == 0){
        for(int i=0;i<S.length();i=i+2){
            if(S[i] == 'h' && S[i+1] == 'i'){
                continue;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else{
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N,K;cin>>N>>K;
    if(N%K==0){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int N,K;
   cin>>N>>K;
   cout<<(N+K-1)/K-N/K<<endl;
return 0;}


#include <iostream>
using namespace std;

int main()
{
  int n;
  int a, b, c;

  cin >> n;
  if (n == 2){
    cin >> a >> b;
    if (a > b){
      int c = a;
      a = b;
      b = c;
    }
    for (int i = 1; i <= a; i++){
      if (a % i == 0 && b % i == 0){
        cout << i << "\n";
      }
    }
    return 0;
  }

  cin >> a >> b >> c;
  if (c < b){
    int d = c;
    c = b;
    b = d;
  }
  if (b < a){
    int d = a;
    a = b;
    b = d;
  }
  if (c < b){
    int d = c;
    c = b;
    b = d;
  }
  for (int i = 1; i <= a; i++){
    if (a % i == 0 && b % i == 0 && c % i == 0){
      cout << i << endl;
    }
  }

  return 0;
}

#include<iostream>
using namespace std;

int main() {
  int n;
  int data[3] = {0, 0, 0};

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

  for ( int i  = 1; i <= 100000000; i++) {
    if ( data[0] % i == 0 && data[1] % i == 0 && data[2] % i == 0 ) {
      cout << i << endl;
    }
  }

  return (0);
}


#include<iostream>

#define INF 5000000

using namespace std;
const int V=120;
int map[V][V]={INF};
int dis[V];
bool used[V];

int dijkstra(int s,int e){
	fill(dis,dis+V,INF);
	fill(used,used+V,false);
	dis[s]=0;
	while(true){
		int v=-1;
		for(int u=0;u<V;u++){
			if(!used[u] && (v==-1 || dis[u]<dis[v]))v=u;
		}
		if(v==-1)break;
		used[v]=true;
		for(int u=0;u<V;u++){
			dis[u]=min(dis[v]+map[v][u],dis[u]);
		}
	}
	if(dis[e]!=INF)return dis[e];
	else return -1;
}

int main(){
	int N,K;
	while(cin>>N>>K && N && K){
		fill((int*)map,(int*)map+V*V,INF);
		for(int loop=0;loop<K;loop++){
			int check;
			cin>>check;
			if(check==0){
				int s,e;
				cin>>s>>e;
				cout<<dijkstra(s,e)<<endl;
			}
			else {
				int c,d,e;
				cin>>c>>d>>e;
				map[c][d]=map[d][c]=min(map[c][d],e);
			}
		}
	}
}

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

using namespace std;

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

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

int i,j;
int a[105][105];
int used[105][105];
int h,w;

void search(int y,int x,int c){
  if(x<0 || y<0 || y>=h || x>=w || a[y][x]!=c)return;
  if(used[y][x])return;
  used[y][x]++;
  int i;
  int dx[4]={-1,0,1,0};
  int dy[4]={0,-1,0,1};
  rep(i,4)
    search(y+dy[i],x+dx[i],c);
  return;
}

int main(void) {
  while(1){
    cin>>w>>h;
    if(h==0 && w==0)break;
    rep(i,h)rep(j,w)used[i][j]=0;
    int xs,ys,xg,yg,n;
    cin>>xs>>ys;
    xs--;ys--;
    cin>>xg>>yg;
    xg--;yg--;
    cin>>n;
    rep(i,n){
      int c,d,x,y;
      cin>>c>>d>>x>>y;
      x--;y--;
      int p[8]={0,0,0,0,1,1,1,1};
      int q[8]={0,1,2,3,0,1,2,3};
      if(d)
	rep(j,8)
	  a[y+q[j]][x+p[j]]=c;
      else
	rep(j,8)
	  a[y+p[j]][x+q[j]]=c;
    }
    if(a[ys][xs]==0){
      cout<<"NG"<<endl;
      continue;
    }
    search(ys,xs,a[ys][xs]);//dfs
    if(used[yg][xg])
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}


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

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    s = ' ' +  s; // 文字列を1オリジンで考える
    n++;
    vector<int> dp(n); // sの先頭からi文字目(1<=i<=n)までに含まれるACの数を記録する配列
    rep(i, n) {
        if (i == 0 || i == 1) dp[i] == 0;
        else if (s[i-1] == 'A' && s[i] == 'C') dp[i] = dp[i-1] + 1;
        else dp[i] = dp[i-1];
        // cout << dp[i] << " ";
    }
    cout << endl;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        // int cnt = 0;
        // for (int i = l; i <= r - 1; i++) {
        //     if (s[i] == 'A' && s[i+1] == 'C') cnt++;
        // }
        // cout << cnt << endl;
        cout << dp[r] - dp[l] << endl;
    }
}

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

const int N=100100;
int a[N],n,f[N][30],L,Q;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	cin>>L>>Q;
	for(int i=1;i<=n;++i)f[i][0]=upper_bound(a+1,a+n+1,a[i]+L)-a-1;
	for(int i=1;i<=20;++i)
		for(int j=1;j<=n;++j)f[j][i]=f[f[j][i-1]][i-1];
	for(;Q --> 0;){
		int l,r;cin>>l>>r;
		if(l>r)swap(l,r);
		int ans=1;
		for(int i=20;~i;--i)
			if(f[l][i]<r)l=f[l][i],ans+=1<<i;
		cout<<ans<<'\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5500+5,M=1500,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int sx,sy,ex,ey;
int main(){
	cin>>sx>>sy>>ex>>ey;
	for(int i=0;i<ey-sy;i++)	putchar('U');
	for(int i=0;i<ex-sx;i++) putchar('R');
	for(int i=0;i<ey-sy;i++)	putchar('D');
	for(int i=0;i<ex-sx;i++) putchar('L');
	putchar('L');
	for(int i=0;i<=ey-sy;i++)	putchar('U');
	for(int i=0;i<=ex-sx;i++) putchar('R');
	putchar('D');
	putchar('R');
	for(int i=0;i<=ey-sy;i++)	putchar('D');
	for(int i=0;i<=ex-sx;i++) putchar('L');
	putchar('U');
	return 0;
}

#include <iostream>

using namespace std;

int main (void) {
  int G[101][101] = {0}, sum[101] = {0}, rank[101] = {0};
  int a, b, c, d;
  int n;

  cin >> n;

  for(int i = 1; i <= n*(n-1)/2; i++) {
    cin >> a >> b >> c >> d;
    if(c < d) {
      G[a][b] = 0; G[b][a] = 3;
    } else if(c == d) {
      G[a][b] = 1; G[b][a] = 1;
    } else {
      G[a][b] = 3; G[b][a] = 0;
    }
  }

  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      if (i == j) continue;
      sum[i] += G[i][j];
    }
  }

  //cout << sum[0] << " " << sum[1] << " " << sum[2] << " " << sum[3] << endl;

  int daburi = 1;

  // rankの出し方は俺が考えたアルゴリズムじゃない
  for(int i = 1; i <= n; i++) {
    rank[i] = 1;
    for(int j = 1; j <= n; j++) {
      if(sum[i] < sum[j]) rank[i]++;
    }
  }

  for(int i = 1; i <= n; i++) {
    cout << rank[i] << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2020;
const int mod = 1e9 + 7;

using namespace std;

int ans(int res)
{
        cout << res << "\n";
        exit(0);
}

int main()
{
        ios_base::sync_with_stdio(0);

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

        int x, y;
        cin >> x >> y;
        if(x <= y){
                if(y <= 0) ans(y - x);
                if(x <= -y) ans(-y - x + 1);
                if(x < 0) ans(y + x + 1);
                ans(y - x);
        } else if(-x <= y){
                x = -x;
                if(y <= 0) ans(y - x + 1);
                if(x <= -y) ans(-y - x + 2);
                if(x < 0) ans(y + x + 2);
                ans(y - x + 1);
        } else{
                int res = 0;
                if(x < 0){
                        res = 1;
                        x = -x;
                }
                res += -y - x;
                res += 1;
                ans(res);
        }
}

#include <stdio.h>

int main() {
	int h,w,n;
	scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);
	int ctr = 0;
	int total = 0;
	while (n > total){
		if(w >= h){
			total += w;
			ctr++;
		}else if(h > w){
			total += h;
			ctr++;
		}
	}
	printf("%d\n",ctr);

	return 0;
}


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

using namespace std;

int main() {
    string line;
    while(cin >> line) {
        for(int i = 0; i < line.size(); ++i)
            if(line[i] == ',') line[i] = ' ';
        istringstream is(line);
        vector<int> ls(10);
        int v1, v2;
        for(int i = 0; i < 10; ++i) is >> ls[i];
        is >> v1 >> v2;
        int len = accumulate(ls.begin(), ls.end(), 0);
        int pos = v1*len/(v1+v2);
        int mod = v1*len%(v1+v2);
        int acc = 0;
        for(int i = 0; i < 10; ++i) {
            acc += ls[i];
            if(acc >= pos) {
                if(acc > pos || (acc == pos && mod == 0)) cout << i+1 << endl;
                else cout << i+2 << endl;
                break;
            }
        }
    }
    return 0;
}

// 問題: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0034
#include <iostream>
#include <vector>

bool input(std::vector<int> & l, int & v1, int & v2)
{
	char comma;
	if (!(std::cin >> l[0])) return false;
	for (int i = 1; i < 10; i++) {
		std::cin >> comma >> l[i];
	}
	std::cin >> comma >> v1 >> comma >> v2;
	return true;
}
int sum_of_length(std::vector<int> l) // 全体の道のり(距離)
{
	int sum = 0;
	for (std::vector<int>::size_type i = 0; i < l.size(); i++) {
		sum += l[i];
	}
	return sum;
}
double left_length(int v1, int v2, std::vector<int> l)
{
	// 全体の道のり.(ふたつの列車の走る合計の距離)
	int    distance = sum_of_length(l);
	// ふたつの列車がすれ違った時の時間(=走る時間はふたつの列車共同じ)
	double hour     = static_cast<double>(distance) / (v1 + v2);
	// 左の列車がどれくらいの距離を走ったか
	return v1 * hour;
}
int get_sect(std::vector<int> l, const double left_length)
{
	int sum = 0;
	for (std::vector<int>::size_type i = 0; i < l.size(); i++) {
		sum += l[i];
		if (left_length <= sum) return i + 1;
	}
	return -1;
}
int main()
{
	int              v1, v2;    // 左からの列車の速さ, 右からの列車の速さ
	std::vector<int> l(10, 0); // 各区間の距離x10
	while (input(l, v1, v2)) {
		std::cout << get_sect(l, left_length(v1, v2, l)) << std::endl;
	}
}


#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll c(ll a,ll b)
{
  if(a==0)return b==0?1:0;

if(b>a)return 0;

  ll val=1;
ll fac=1;
for(int i=1;i<=b;i++)fac*=i;
for(int i=a;i>=a-b+1;i--)val*=i;

  return val/fac;

}

ll f(ll n)
{
  ll ans=1LL;
  while(ans<=n)ans<<=1;

return ans;
}

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

ll n,k;
cin>>n>>k;
ll ans=0;
if(n%k)ans=1;

cout<<ans<<"\n";

return 0;

}


#include<bits/stdc++.h>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    int Max = 1, Min = n;
    Srep(m){
        int l,r;
        cin >> l >> r;
        Max = max(l,Max);
        Min = min(r,Min);
    }
  	if(Min - Max < 0) ans = 0;
  	else ans = Min - Max + 1;
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> sum(n), b(n);
    rep(i,n){
        ll ai, bi;
        cin >> ai >> bi;
        sum[i] = ai + bi;
        b[i] = bi;
    }
    sort(rall(sum));
    ll sumAB = 0, sumB = 0;
    rep(i,n){
        if (i % 2  == 0) sumAB += sum[i];
        sumB += b[i];
    }
    cout << sumAB-sumB << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e15;
const int MAX_N=1<<18;

int m;
ll dat[2][2*MAX_N-1];

void init(int m_){
	m=1;
	while(m<m_) m*=2;
	for(int i=0; i<2*m-1; i++){
		dat[0][i]=INF;
		dat[1][i]=INF;
	}
}

void update(int i, int k, ll a){
	k+=m-1;
	dat[i][k]=a;
	while(k>0){
		k=(k-1)/2;
		dat[i][k]=min(dat[i][k*2+1], dat[i][k*2+2]);
	}
}

ll query(int i, int a, int b, int k, int l, int r){
	if(r<=a || b<=l) return INF;
	if(a<=l && r<=b){
		return dat[i][k];
	}else{
		ll vl=query(i, a, b, k*2+1, l, (l+r)/2);
		ll vr=query(i, a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
}

int main()
{
	int n, q, a, b;
	cin>>n>>q>>a>>b;
	a--; b--;
	init(n);
	ll dp[200001];
	fill(dp, dp+n, INF);
	int x[200001];
	for(int i=0; i<q; i++){
		cin>>x[i];
		x[i]--;
	}
	if(q==1){
		cout<<min(abs(x[0]-b), abs(x[0]-a))<<endl;
		return 0;
	}
	dp[a]=min(dp[a], (ll)abs(x[0]-b));
	dp[b]=min(dp[b], (ll)abs(x[0]-a));
	update(0, a, dp[a]-a);
	update(1, a, dp[a]+a);
	update(0, b, dp[b]-b);
	update(1, b, dp[b]+b);
	for(int i=1; i<q; i++){
		ll mn=query(0, 0, x[i]+1, 0, 0, m)+(ll)x[i]-(ll)abs(x[i]-x[i-1]);
		mn=min(query(1, x[i], n, 0, 0, m)-(ll)x[i]-(ll)abs(x[i]-x[i-1]), mn);
		dp[x[i-1]]=min(dp[x[i-1]], mn);
		update(0, x[i-1], dp[x[i-1]]-x[i-1]);
		update(1, x[i-1], dp[x[i-1]]+x[i-1]);
	}
	ll s=0;
	for(int i=1; i<q; i++) s+=(ll)abs(x[i]-x[i-1]);
	ll ans=INF;
	for(int i=0; i<n; i++){
		ans=min(ans, dp[i]+s);
	}
	cout<<ans<<endl;
	return 0;
}

//
//  main.cpp
//  DPu
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using P=pair<int,int>;
using ll = long long;
ll dp[1<<16]={};
ll cost[1<<16]={};
int main(int argc, const char * argv[]) {
    int n;
    cin >>n;
    ll a[n][n];
    rep(i,n) rep(j,n) cin>>a[i][j];

    for (int s=1; s<(1<<n); s++) {
        for (int i=0; i<n; i++) {
            if((s>>i)%2==0) continue;
            for (int j=i+1;j<n; j++) {
                if((s>>j)%2==0)continue;
                cost[s]+=a[i][j];
            }
        }
    }
    for (int s=1; s<(1<<n); s++) { // 全集合
       for (int t=(1<<n)-1; t>=0; --t) { // 集合Sの部分集合T
           t&=s;    // 部分集合tの全列挙の方法、処理はこの下に書く
                    // https://primenumber.hatenadiary.jp/entry/2016/12/01/000000
           dp[s]=max(dp[s],dp[s-t]+cost[t]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

ll e[mx], w[mx];
int main() {
    FIO;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
        if(s[i] == 'W') {
            cnt++;
        }
        w[i+1] = cnt;
    }

     cnt = 0;
    for (ll i = n - 1; i >= 0; i--) {
        if(s[i] == 'E') {
            cnt++;
        }
        e[i+1] = cnt;
    }

    ll ans = INT_MAX;
    for (ll i = 1; i <= n; i++) {
        ans = min(ans, w[i-1]+e[i+1]);
    }

    cout << ans << endl;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	string k;
	cin>>k;
	int d;
	cin>>d;
	//dp[0][0]=1;
	vector< vector<int> >dp(d,vector<int>(2));
	dp[0][0]=1;
//	dp[0][1]=1;
	int n=k.length();
	for(int i=0;i<n;i++)
	{
	//	cout<<"s";
		vector< vector<int> >new_dp(d,vector<int>(2));
		for(int sum=0;sum<d;sum++)
		{
			//cout<<"x";
			for(bool j:{false,true})
			{
				for(int digit=0;digit<10;digit++)
				{
					if(digit>k[i]-'0'&& !j)
					{
						break;
					}
					new_dp[(sum+digit)%d][j||(digit< k[i]-'0')]=(new_dp[(sum+digit)%d][j||(digit< k[i]-'0')]+dp[sum][j])%mod;

				}
			}
		}
		dp=new_dp;
	}
	int ans=(dp[0][false]+dp[0][true])%mod;
	ans--;
	if(ans==-1)
	{ans=mod-1;
	}
	cout<<ans;
	return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=2e9;
    for(int i=0;i<n;i++){
        int cnt=0;
        while(a[i]%2==0){
            cnt++;
            a[i]/=2;
        }
        ans=min(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}

#include <vector>
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int m = 1e9;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m = min(__builtin_ctz(a), m);
    }
    cout << m << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

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

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

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

int main() {
  ll n,k; cin>>n>>k;
  cout << n-k+1 << endl;

  return 0;
}

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

int main(){
    int N,K;
    cin>>N>>K;
    int X;
    X = N-(K-1);
    cout<<X<<endl;

}


#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll calc(ll x){
    ll res = 1;
    while(x%2 == 0){
        x /= 2;
        res *= 2;
    }
    while(x%5 == 0){
        x /= 5;
        res *= 5;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<P, ll> mp;
    rep(i,n){
        string s;
        cin >> s;
        ll a = 0, b = 1;
        bool f = false;
        for(char c : s){
            if(c == '.'){
                f = true;
                continue;
            }
            a = a * 10 + (c - '0');
            if(f) b *= 10;
        }
        ll g = gcd(a, b);
        a /= g;
        a = calc(a);
        b /= g;
        b = calc(b);
        ++mp[P(a, b)];
    }
    vector<P> v;
    v.reserve(mp.size());
    for(auto& p : mp){
        v.push_back(p.first);
    }
    int sz = v.size();
    ll ans = 0;
    rep(i,sz){
        P p1 = v[i];
        rep(j,i+1){
            P p2 = v[j];
            if(p2.first % p1.second == 0 && p1.first % p2.second == 0){
                ll tmp = mp[p1] * mp[p2];
                if(i == j){
                    tmp -= mp[p1];
                    tmp /= 2;
                }
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  ll N;
  cin>>N;
  vector
Sup;
  vector
Sdown;
  rep(i,N){
  	string s;
  	cin>>s;
    ll total=0,mini=0;
    rep(j,s.size()){
      if(s[j]=='('){total++;}
      else{total--;}
      mini=min(mini,total);
    }
    if(total>=0){Sup.push_back(P(mini,total));}
    else{Sdown.push_back(P(mini-total,-total));}
  }
  sort(Sup.begin(),Sup.end());
  reverse(Sup.begin(),Sup.end());

  sort(Sdown.begin(),Sdown.end());
  reverse(Sdown.begin(),Sdown.end());

  int flag=0;
  ll sum1=0;
  ll sum2=0;
  rep(i,Sup.size()){
  	if(Sup[i].first<0&&sum1+Sup[i].first<0){flag=1;}
  	else{sum1+=Sup[i].second;}
    if(sum1<0){flag=1;}
  }
  rep(i,Sdown.size()){
  	if(Sdown[i].first<0&&sum2+Sdown[i].first<0){flag=1;}
  	else{sum2+=Sdown[i].second;}
    if(sum2<0){flag=1;}
  }
  if(sum1!=sum2){flag=1;}
  if(flag==1){cout<<"No";}
  if(flag==0){cout<<"Yes";}
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  ll A[N],B[N];
  // A[i] S[i]の最小値
  // B[i] S[i]の値

  REP(i,N){
    A[i]=0;
    B[i]=0;
  }

  string S[N];
  REP(i,N) cin>>S[i];

  REP(i,N){
    ll cnt=0;
    REP(j,S[i].size()){
      if(S[i].at(j)=='(') cnt++;
      else cnt--;
      chmin(A[i],cnt);
    }
    B[i]=cnt;
  }

  vector<pair<int,int>> L,LL,LLL;
  bool CAN=true;

  REP(i,N){
    if(B[i]>0){
      if(A[i]>=0ll) L.PB(MP(A[i],B[i]));
      else LL.PB(MP(A[i],B[i]));
    }
    else LLL.PB(MP(B[i]-A[i],A[i]));
  }

  SORT(L);
  REVERSE(L);
  SORT(LL);
  REVERSE(LL);
  SORT(LLL);
  REVERSE(LLL);

  REP(i,L.size()){
    if(ans+L[i].first<0) CAN=false;
    ans+=L[i].second;
  }

  REP(i,LL.size()){
    if(ans+LL[i].first<0) CAN=false;
    ans+=LL[i].second;
  }

  REP(i,LLL.size()){
    if(ans+LLL[i].second<0) CAN=false;
    ans+=LLL[i].first+LLL[i].second;
  }

  if(ans!=0) CAN=false;
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

void abc_164a();

void abc_165a();

void abc_166a();

void abc_167a();

void abc_168a();

void abc_169();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  //abc_163a();
  //abc_164a();
  //abc_165a();
  //abc_166a();
  //abc_167a();
  //abc_168a();
  abc_169();

}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

void abc_164a()
{
  int s, w;
  cin >> s >> w;

  if (s <= w) cout << "unsafe\n";
  else cout << "safe\n";
}

void abc_165a()
{
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = a; i <= b; ++i)
  {
    if (i % k == 0)
    {
      cout << "OK\n";
      return;
    }
  }

  cout << "NG\n";
}

void abc_166a()
{
  string s;
  cin >> s;

  if (s == "ABC") cout << "ARC\n";
  if (s == "ARC") cout << "ABC\n";

}

void abc_167a()
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] != t[i])
    {
      cout << "No\n";
      return;
    }
  }

  if ('a' <= t[t.size() - 1] && t[t.size() - 1] <= 'z') cout << "Yes\n";
  else cout << "No\n";

}

void abc_168a()
{
  string s;
  cin >> s;

  if (s[s.size() - 1] == '3') cout << "bon\n";
  else if (s[s.size() - 1] == '0' ||
    s[s.size() - 1] == '1' ||
    s[s.size() - 1] == '6' ||
    s[s.size() - 1] == '8') cout << "pon\n";
  else cout << "hon\n";
}

void abc_169()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << "\n";
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}


#include<stdio.h>

int main(){
    int x,y = 0;

    scanf("%d", &x);

    y = x * x * x;

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

    return 0;
}

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

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

int main()
{
    int64_t n;
    string s = "";

    cin >> n;

    while(n!=0)
    {
        n--;
        s += 'a' + n % 26;
        n /= 26;
    }

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

    cout << s << endl;

}