#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}

#define DUMPOUT cerr

void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    int q; cin>>q;
    rep(timpo, q){
        int k; cin>>k;
        int d=0,m=0,dm=0,ans=0;
        rep(i,n){
            if(i-k>=0){
                if(s[i-k]=='D') dm -= m, d--;
                if(s[i-k]=='M') m--;
            }
            if(s[i]=='D') d++;
            if(s[i] == 'M'){
                m++;
                dm += d;
            }
            if(s[i] == 'C') ans += dm;
        }
        cout<<ans<<endl;
    }
}

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

int main(){
  while(1){
  int m,l,r;
  cin>>m>>l>>r;
  if(!m&&!l&&!r)break;

  int a[300];
  for(int i=0;i<m;i++)cin>>a[i];

  sort(a,a+m);
  reverse(a,a+m);
  int gap=0,n;
  for(int i=l-1;i<r;i++)
    if(a[i]-a[i+1]>=gap)n=i,gap=a[i]-a[i+1];

  cout <<n+1<<endl;
  }
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long Mod = 998244353, F[10100], InvF[10100], po[10100];
long long Pow(long long a, long long b) {
	long long r = 1;
	while (b) {
		if (b & 1)r = r*a%Mod;
		a = a*a%Mod; b >>= 1;
	}
	return r;
}
long long Comb(int a, int b) {
	if (a >= b&&b >= 0)return F[a] * InvF[b] % Mod*InvF[a - b] % Mod;
	return 0;
}
long long Get(int a, int b) {
	return Comb(a + b - 1, b);
}
long long Go(int n, int p, int c) {
	if (n == 0)return 1;
	int i;
	long long r = 0;
	for (i = 0; i <= p; i++) {
		if (n < i)continue;
		r = (r + Get(i + c, n - i) * Comb(p,i)%Mod * po[i]) % Mod;
	}
	return r;
}
int main() {
	int i, n, K;
	scanf("%d%d", &K,&n);
	F[0] = InvF[0] =po[0] = 1;
	for (i = 1; i <= 10000; i++) {
		F[i] = F[i - 1] * i%Mod;
		InvF[i] = Pow(F[i], Mod - 2);
		po[i] = po[i - 1] * 2 % Mod;
	}
	for (i = 2; i <= K + K; i++) {
		if (i % 2 == 0) {
			long long t = min(i - 1, K + K + 1 - i);
			printf("%lld\n",(Go(n, t / 2, K - t) + Go(n - 1, t / 2, K - t)) % Mod);
		}
		else {
			long long t = min(i - 1, K + K + 1 - i);
			printf("%lld\n",Go(n, t / 2, K - t));
		}
	}

}

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrt(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	ll n, start;	cin >> n >> start;
	vector<ll> x(n);
	vector<ll> p(n);
	rep(i, n)	cin >> x[i] >> p[i];
	vector<ll> pos;
	int s = 0, t = n - 1;
	while (x[s]<start && start<x[t]) {
		if (p[s] < p[t]) {
			pos.push_back(x[s]);
			p[t] += p[s];
			s++;
		}
		else {
			pos.push_back(x[t]);
			p[s] += p[t];
			t--;
		}
	}
	while (s != t) {
		if (x[s] < start)	pos.push_back(x[s++]);
		else	pos.push_back(x[t--]);
	}
	pos.push_back(x[s]);
	ll cur = start, ret = 0;
	rrep(i, pos.size()) {
		ret += labs(pos[i] - cur);
		cur = pos[i];
	}
	cout << ret << endl;
	return 0;
}


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

int main()
{
    int a, b, c;
    string res;

    cin >> a >> b >> c;
    if(a == b && c != a)
        res = "Yes";
    else if(a == c && b != a)
        res = "Yes";
    else if(b == c && a != b)
        res = "Yes";
    else res = "No";

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

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll p,ll n){
   ll result=1;
   while(n!=0){
   if(n%2==0){
    n/=2;
    p*=p;
   }
   else{
    n--;
    result=result*p;
   }
   }
    return result;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   ll n,t,a,b,c,d;
   ll mod =1e9+7;
   string s1,s2;
   stack<ll>stck1;
   stack<ll>stck2;

   set<ll>st;
   cin>>a>>b>>c;
   st.insert(a);
   st.insert(b);
   st.insert(c);

   if(st.size()==2){
    cout<<"Yes"<<endl;
   }
   else{
    cout<<"No"<<endl;
   }
}


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

int main()
{
    vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string d;
    cin >> d;
    cout << 7 - distance(days.begin(), find(days.begin(), days.end(), d)) << endl;
    return 0;
}

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;

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

    ll n;
    cin >> n;
    string s="";
    while(n){
        n--;
        s+=('a'+(n+25/26)%26);
        n/=26;
    }
    reverse(all(s));
    print(s);
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <list>
#include <iomanip>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

Int fact_mod(Int n, Int mod) {
    Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}

// 繰り返し二乗法 (modの世界での累乗)
Int mod_pow(Int x, Int n, Int mod) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 組み合わせ nCr を求める
Int combination_mod(Int n, Int r, Int mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    Int a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    Int b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

int main() {
    //COMinit();
    IOS;
    prec;
    Int a,b,c,d,n,m,k,x,y=0,ans=0;
    string str,s="",t,u;
    cin>>s;
    if(s.length()==2)cout<<s;
    else{
        cout<<s[2]<<s[1]<<s[0];
    }

    cout<<endl;
    return 0;
}

#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if (s.size()%2){
        cout<<s[2]<<s[1]<<s[0];
    }
    else{
        cout<<s;
    }

}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);

    rep(i,n){
        cin>>p[i];
        p[i]++;
    }
    vector<int> s(n+1,0);
    rep(i,n) s[i+1]=s[i]+p[i];

    int tmp=0;
    rep(i,n){
        tmp=max(tmp,s[min(n,i+k)]-s[i]);
    }

    double ans=tmp/2.0;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

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

using ll = long long;
#define dbg(x) cerr << "[" #x << " : " << x << "]\n";
const int mod = (int)1e9+7;

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int p[210000];
    for(int i = 0; i < n; i++) scanf("%d", &p[i]);
    double ans = 0;
    double s = 0;
    int mx = 0;
    for(int i = 0; i < k; i++) s += (p[i]+1)/2.0;
    ans = s;
    for(int i = k; i < n; i++ ) {
        s -= (p[i-k]+1)/2.0;
        s += (p[i]+1)/2.0;
        ans = max(ans, s);
    }
    printf("%lf\n", ans);
}


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

int main() {
    int n, k;
    int ans = 1;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        ans = min(ans*2, ans+k);
    }
    cout << ans << endl;
}

/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __
.' ____ \ [  |      (_)                [  |
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |,
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/

*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[4], e, f;

  REP(i, 4) cin >> a[i];
  cin >> e >> f;
  sort(a, a + 4);
  print(a[3] + a[2] + a[1] + max(e, f));

  return (0);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    ll X;
    cin >> X;
    ll tmp = X / 11;
    if(X - 11 * tmp == 0) cout << 2 * tmp << endl;
    else if (X - 11 * tmp <= 6) cout << 2 * tmp + 1 << endl;
    else cout << 2 * tmp + 2 << endl;
}

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

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

	vector<bool> v(55555 + 1);
	for (int i = 2; i < v.size(); i++) {
		if (!v.at(i)) {
			for (int j = i * 2; j < v.size(); j += i) {
				v.at(j) = true;
			}
		}
	}

	vector<int> a;
	for (int i = 2; i < v.size(); i++) {
		if (!v.at(i)) {
			if (i % 5 == 1) a.push_back(i);
		}
	}

	for (int i = 0; i < N; i++) {
		if (i) cout << ' ';
		cout << a.at(i);
	}
	cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll calc(ll &m, ll p) {
    ll ret = 1;
    m += p;
    if (m >= 10) {
        ret++;
        m = (m / 10) + (m % 10);
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll M;
    cin >> M;
    ll ans = 0;
    vector<ll> v(M);
    REP(i, M) {
        ll d, c;
        cin >> d >> c;

        vector<ll> u;
        while (c > 1) {
            if (c % 2 == 1)
                u.push_back(d);
            c /= 2;
            ans += c;
            d = d + d;
            if (d >= 10) {
                d = (d / 10) + (d % 10);
                ans += c;
            }
        }
        u.push_back(d);
        ll n = u[0];
        REP(j, u.size() - 1) {
            ans += calc(n, u[j + 1]);
        }
        v[i] = n;
    }

    ll m = v[0];
    REP(i, M - 1) {
        ans += calc(m, v[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll m; cin>>m;
    vector<LP> dc(m); cin>>dc;

    ll d = 0;
    rep(i, m) d += dc[i].se;

    ll s = 0;
    rep(i, m) s += dc[i].fi * dc[i].se;

    ll ans = d - 1 + (s - 1) / 9;
    cout<<ans<<endl;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double x = (double)(x2 - x1) * (double)(x2 - x1);
    double y = (double)(y2 - y1) * (double)(y2 - y1);
    cout << fixed << setprecision(6) << (double)sqrt(x+y) << endl;
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cout << fixed << setprecision(10);
  double a,b;
  cin >> a >> b;
  complex<double> c = {a,b};
  cin >> a >> b;
  complex<double> d = {a,b};
  cout << abs(c-d) << endl;
}


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

int H, W;
int A[82][82], B[82][82];
bool dp[82][82][25610];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    dp[0][0][A[0][0]-B[0][0]+ofs] = true;
    dp[0][0][B[0][0]-A[0][0]+ofs] = true;

    rep(i, H) rep(j, W) {
        if (i>0) rep(k, 25610) {
            if (!dp[i-1][j][k]) continue;
            int nk = k+A[i][j]-B[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
            nk = k+B[i][j]-A[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
        }
        if (j>0) rep(k, 25610) {
            if (!dp[i][j-1][k]) continue;
            int nk = k+A[i][j]-B[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
            nk = k+B[i][j]-A[i][j];
            if (0<=nk && nk<25610) dp[i][j][nk] = true;
        }
    }

    int ans = 1000000;
    rep(i, 25610) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-ofs));
    cout << ans << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, h) rep(j, w) cin >> s[i][j];

  bool able = true;
  int di[] = {1, 0, -1, 0};
  int dj[] = {0, 1, 0, -1};
  rep(i, h) rep(j, w) {
    if (s[i][j] == '.') continue;
    bool is_dot = true;
    rep(k, 4) {
      int ni = i + di[k];
      int nj = j + dj[k];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') is_dot = false;
    }
    if (is_dot) able = false;
  }
  if (able) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


#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(){
  int n; cin>>n;
  string s,t; cin>>s>>t;
  int ans=2*n;
  for(int i=0; i<n; i++){
    int s_index=n-1-i;
    int now_ans=2*n-(i+1);
    bool flag=1;
    for(int t_index=0; t_index<=i; t_index++){
      if(t[t_index]!=s[s_index])flag=0;
      s_index++;
    }
    if(flag){
      ans=now_ans;
    }
  }
  cout<<ans<<endl;
}

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N, M;
    cin >> N >> M;

    vector<bool> used(N);
    vector<pair<int, int>> arenas;

    for (int i = 0; i < M; i++) {
        int left = i + 1;
        int right = N - i;
        if (N % 2 == 0 && left * 2 * 2 > N) {
            left++;
        }
        arenas.push_back(make_pair(left, right));
    }

    for (int i = 0; i < M; i++) {
        int left = arenas[i].first;
        int right = arenas[i].second;
        printf("%d %d\n", left, right);
    }

    return 0;
}


#if 0
2019.12.08

不妨设 n > 1 。

如果所有 a[i] 都是奇数，那么先手操作后会有一个偶数，约分后仍然有唯一偶数，
此时后手一定可以对唯一偶数操作，所有数成为奇数，约分后同样如此，
直到所有数都为 1 ，仍然没有偶数，那么当 a[i] 全是奇数时先手必败。

更一般的，假设 n 足够大奇数足够多，如果有偶数个偶数，
先手操作后有奇数个偶数，后手一定可以对偶数操作使得状态还原至奇数个偶数，
也就是说有奇数个偶数时先手必胜，反之先手必败。

特别的是，如果有偶数个偶数且奇数唯一且该奇数大于 1 ，
此时先手对唯一奇数操作后，所有数都是偶数，
此时一定可以约分，并且约分后的结果是难以推断的。
由于这种情况一定可以约分，那么所有数至少缩小一半，也就是最多进行 O(logn) 次，
每次碰到这种情况暴力约分即可，直到转为上述可以直接判断的情况。
#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; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
int a[maxn];

bool game(int n) {
	if(n == 1) return a[1] > 1;

	int even = 0;
	for(int i = 1; i <= n; i ++)
		if(!(a[i] & 1))
			++ even;

	if(even & 1) return 1;
	if(even != n - 1) return 0;

	for(int i = 1; i <= n; i ++)
		if(a[i] & 1) {
			if(a[i] == 1) return 0;
			-- a[i];
		}

	int gcd = a[1];
	for(int i = 2; i <= n; i ++)
		gcd = std::__gcd(gcd, a[i]);

	for(int i = 1; i <= n; i ++)
		a[i] /= gcd;

	return !game(n);
}

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++)
		read(a[i]);

	puts(game(n) ? "First" : "Second");
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 120000;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int n,a[N];
void print(int x){
	printf("%s",x==1?"First":"Second");exit(0);
}
int main() {
	read(n);rep(i,1,n)read(a[i]);
	int now=1;
	while(1){
		int cnt=0,flag=1;
		rep(i,1,n)cnt+=!(a[i]&1),flag&=a[i]==1;
		if(flag)print(3-now);
		if(cnt&1)print(now);
		if(n-cnt!=1)print(3-now);
		rep(i,1,n)if(a[i]&1){if(a[i]==1)print(3-now);a[i]--;}
		int g=0;rep(i,1,n)g=gcd(g,a[i]);
		rep(i,1,n)a[i]/=g;now=3-now;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

struct Edge {
    int from;
    int to;
    int cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const Edge& edge) const {
        return this->cost < edge.cost;
    }
    bool operator>(const Edge& edge) const {
        return this->cost > edge.cost;
    }
};

class UnionFind {
public:
    vector<int> parent;
    vector<int> setSize;

    UnionFind(unsigned int size) {
        parent.resize(size + 1);
        iota(parent.begin(), parent.end(), 0);
        setSize.resize(size + 1, 1);
    }

    // x??¨y???????????????????±??????????
    bool isSameSet(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    // x??¨y????±??????????????????????
    void unionSet(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) { return; }

        parent[x] = y;
        setSize[y] += setSize[x];
    }

private:
    // ??¨??????????±???????
    int findRoot(int x) {
        if (parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = findRoot(parent[x]);
        }
    }
};

/**
 * ??°?????????????°???¨?????¨????±??????????O(|E| log|V|)
 * @param num_of_node ???????????°
 * @param edges?????¨?????????????????°????????????u -> v??¨v -> u??????????????\??????
 * @return
 */
long long kruskal(unsigned int num_of_node, vector<Edge> edges) {
    sort(edges.begin(), edges.end());

    UnionFind uf(num_of_node);

    long long ans = 0;
    for (Edge e : edges) {
        if (!uf.isSameSet(e.from, e.to)) {
            uf.unionSet(e.from, e.to);
            ans += e.cost;
        }
    }
    return ans;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;

    vector<Edge> edges;
    FOR(i, 0, E) {
        int s, t, w;
        cin >> s >> t >> w;
        edges.emplace_back(Edge(s, t, w));
        edges.emplace_back(Edge(t, s, w));
    }

    cout << kruskal(V, edges) << endl;

    return 0;
}

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

class UnionFind{ //連結判定
private:
    std::vector<int> parent; //parent[i] = parent of node i
    std::vector<int> rank;
    std::vector<int> size;
public:
    //constructor
    UnionFind(int N){
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    //initialize
    void init(int N){
        parent.clear();
        rank.clear();
        size.clear();
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]); //親が自分自身になるまで再帰を呼び出す & 経路圧縮
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return; //ノードa, bがすでに連結しているとき
        //次数の大きい方を親として連結
        if(rank[rootA] < rank[rootB]){
            size[rootB] += size[rootA];
            parent[rootA] = rootB;
        }
        else{
            size[rootA] += size[rootB];
            parent[rootB] = rootA;
            if(rank[rootA] == rank[rootB]) rank[rootA]++;
        }
    }
    bool same(int a, int b){
        return root(a) == root(b); //ノードa, bが同じ木に属するかどうか
    }
    int get_size(int a){
        return size[root(a)];
    }
};

int main()
{
    using P = std::pair<int, int>;

    int N, K, L;
    std::cin >> N >> K >> L;
    std::vector<P> route(K), rail(L);
    for(int i=0; i<K; i++){
        scanf(" %d %d", &(route[i].first), &(route[i].second));
        route[i].first--; route[i].second--;
    }
    for(int i=0; i<L; i++){
        scanf(" %d %d", &(rail[i].first), &(rail[i].second));
        rail[i].first--; rail[i].second--;
    }

    UnionFind uf_route(N), uf_rail(N);
    for(int i=0; i<K; i++){
        int u = route[i].first, v = route[i].second;
        uf_route.unite(u, v);
    }
    for(int i=0; i<L; i++){
        int u = rail[i].first, v = rail[i].second;
        uf_rail.unite(u, v);
    }

    std::vector<std::pair<P, int> > root;
    for(int i=0; i<N; i++){
        int a = uf_route.root(i), b = uf_rail.root(i);
        root.push_back(std::pair<P, int>(P(a, b), i));
    }
    std::sort(root.begin(), root.end());
    std::vector<int> tmp, count(N);
    for(int i=0; i<N; i++){
        tmp.push_back(root[i].second);
        if(i == N-1 || (i != N-1 && root[i].first != root[i+1].first)){
            int M = tmp.size();
            while(!tmp.empty()){
                count[tmp.back()] = M;
                tmp.pop_back();
            }
        }
    }

    for(int i=0; i<N; i++){
        printf("%d ", count[i]);
    }
    printf("\n");
}


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

bool isprime(int x) {
  if (x < 2) return false;
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return false;
  return true;
}

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 2; v.size() < n; ++i)
    if (isprime(i) && i % 5 == 1) v.push_back(i);
  for (int i = 0; i < n; ++i) {
    cout << v[i];
    if (i == n - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

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


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

int main(){
   int n, k;
   cin>>n>>k;
   vector<int> p(n);
   rep(i, n) cin>>p[i];

   vector<int> ki2(n);
   rep(i, n) ki2[i]=(p[i]+1);

   int sum=0;
   rep(i, k) sum+=ki2[i];
   int mx=0;
   for(int i=0; i+k-1<n; i++){
      mx=max(mx, sum);
      if(i+k<n) sum+= -ki2[i] +ki2[i+k];
   }

   double ans=(double)mx/2;
   cout<<std::setprecision(15)<<ans<<endl;
   return 0;
}

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

int main(void){
    int N;
    double ans=0;
    std::cin >> N;
    std::vector<int> P(N);
    std::vector<std::vector<int>> C(N, std::vector<int>(2));
    for (int i = 0; i < N; ++i){
        std::cin >> C[i][0] >> C[i][1];
        P.at(i) = i;
    }

    do {
        for (int i = 0; i < N - 1; ++i){
            ans += std::sqrt((C[P[i + 1]][0] - C[P[i]][0])*(C[P[i + 1]][0] - C[P[i]][0]) + (C[P[i + 1]][1] - C[P[i]][1])*(C[P[i + 1]][1] - C[P[i]][1]));
        }
    } while (std::next_permutation(P.begin(), P.end()));

    for(int i = 2; i <= N; ++i){
        ans /= i;
    }

    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {
vector<string> vec{"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  cin>>S;
  for(ll i=0;i<7;i++) {
    if(S==vec[i]) {
cout<<7-i<<endl;
    }
  }
}


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

int arr[100005 << 2], value[100005], n, q;

void updata(int a, int b, int x, int k = 0, int l = 0, int r = (1 << 17)){
	if (b <= l || r <= a)return;
	if (a <= l && r <= b){
		arr[k] = max(arr[k], x);
		return;
	}
	int m = (l + r) / 2;
	updata(a, b, x, k * 2 + 1, l, m);
	updata(a, b, x, k * 2 + 2, m, r);
}

int query(int x){
	x += (1 << 17) - 1;
	int res = arr[x];
	while (x){
		x = (x - 1) / 2;
		res = max(res, arr[x]);
	}
	return res;
}

int main()
{
	value[0] = 2147483647;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= q; ++i){
		int ch, a, b;
		scanf("%d", &ch);
		if (ch){
			scanf("%d", &a);
			printf("%d\n", value[query(a)]);
		}else{
			scanf("%d%d%d", &a, &b, &value[i]);
			++b;
			updata(a, b, i);
		}
	}
	return 0;
}

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

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  auto f = [](ll a, ll b){return a+b;};
  auto g = [](ll a, ll b, int l){return b == INF ? a : b*l;};
  auto h = [&](ll a, ll b) {return b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n,f,g,h,0,INF);
  rep(i,n) lst.set(i,((ll)1<<31)-1);
  lst.build();
  vector<ll> ans;
  rep(i,q) {
    int t;
    cin >> t;
    if(t == 0) {
      int l, r; ll x;
      cin >> l >> r >> x;
      lst.update(l,r+1,x);
    } else {
      int p;
      cin >> p;
      ans.push_back(lst.query(p,p+1));
    }
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

struct Person{
  ll id,d;
  vector<ll> friends;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n >> m && n && m){
    vector<ll> p[n+1];
    ll a, b;
    rep(i,m){
      cin >> a >> b;
      p[a].pb(b);
      p[b].pb(a);
    }
    set<ll> s;
    s.insert(1);
    rep(i,p[1].size()){
      s.insert(p[1][i]);
      for(auto N : p[p[1][i]]){
        s.insert(N);
      }
    }
    cout << s.size()-1<<endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

int main()
{
	while (true)
	{
		int count = 0;
		int n, m;
		int x = 10, y = 10;
		bool table[21][21] = {};

		cin >> n;
		if (n == 0) return 0;
		for (int i = 0; i < n; i++)
		{
			int X, Y;
			cin >> X >> Y;
			table[X][Y] = true;
		}

		cin >> m;
		for (int i = 0; i < m; i++)
		{
			char d;
			int p;
			cin >> d >> p;

			while (p--)
			{
				if (d == 'N') y++;
				if (d == 'E') x++;
				if (d == 'S') y--;
				if (d == 'W') x--;
				if (table[x][y]) count++;
				table[x][y] = false;
			}
		}

		if (count == n)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  int ans = -1;
  for(int i = 1;i*i<=n;i++)
    ans = max(ans,i*i);

  cout << ans << endl;

  return 0;
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	ll n;
	ll i;
	cin >> n;
	i=0;
	while((i+1)*(i+1)<=n) i++;
	cout << i*i;

	return 0;
}


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

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  int answer;
  answer = min(min(P+Q,Q+R),R+P);
  cout << answer << endl;
}

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

using namespace std;

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

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  int s = A + B + C + D;
  s -= min(min(A, B), min(C, D));
  cout << s + max(E, F) << "\n";
  return 0;
}


#include <stdio.h>

int main(){
	int y,m,d;
	scanf("%d/%d/%d" ,&y,&m,&d);
	printf("2018/%02d/%02d" ,m,d);
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iomanip>

int main(void) {

	//long double x = 0.1234567890;
	//std::cout << x << std::endl;

	//test??¨
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	double x1, y1, x2, y2;
	std::cin >> x1 >> y1 >> x2 >> y2;

	long double ans = sqrtl(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0));

	std::cout << std::fixed << std::setprecision(8) << ans << std::endl;
}


#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n,m,d;
    scanf("%ld %ld %ld", &n, &m, &d);
    long k;
    if(d == 0){
        k = n;
    }
    else{
        k = 2 * (n - d);
    }
    k = k * (m - 1);
    double dAns = double(k)/double(n * n);
    printf("%.10lf", dAns);
    return 0;
}

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

int main() {
	ll n, m, d;
	cin >> n >> m >> d;
	cout << fixed << setprecision(20);
	double ans = 0;
	for (int i = 0; i < m - 1; i++) {
		ans += (double)((double)(2 * n - 2 * d) / n) / n;
	}
	if (d == 0)ans *= 0.5;
	cout << ans << endl;
}


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main() {
	string t;
	while(getline(cin,t)) {
		for(int i = 0; i < 26; i++) {
			for(int j = 0; j < t.size(); j++) {
				if(t[j] == ' ' || t[j] == '.') continue;
				t[j] += 1;
				if(t[j] > 'z') t[j] -= 26;
			}
			if(t.find("the") != string::npos || t.find("that") != string::npos || t.find("this") != string::npos) {
				cout << t << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main() {
  char s[100];
  while (fgets(s, sizeof(s), stdin)) {
    while (1) {
      for (int i = 0; s[i] != '\0'; i++) {
        if (s[i] >= 'a' && s[i] < 'z') s[i]++;
        else if (s[i] == 'z') s[i] = 'a';
        else if (s[i] == '\n') s[i] = '\0';
      }
      if (strstr(s, "the") || strstr(s, "this") || strstr(s, "that")) break;
    }
    puts(s);
  }
}


#include<bits/stdc++.h>
using namespace std;
void gofail(){
	cout<<"No\n";
	exit(0);
}
const int N=100100;
int a[N],b[N],c[N],sum[3*N],sum1,sum2,n;
void add(int x){for(;x;x-=x&-x)sum[x]^=1;}
int qry(int x){int ans=0;for(;x<=3*n;x+=x&-x)ans^=sum[x];return ans;}
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];
	for(int i=1;i<=n;++i)cin>>b[i];
	for(int i=1;i<=n;++i)cin>>c[i];
	for(int i=1;i<=n;++i){
		if(a[i]<b[i]){
			if(a[i]+1!=b[i])gofail();
			if(b[i]+1!=c[i])gofail();
			if(c[i]%3)gofail();
			a[i]=a[i]/3+1;b[i]=0;
		}else{
			if(a[i]-1!=b[i])gofail();
			if(b[i]-1!=c[i])gofail();
			if(a[i]%3)gofail();
			a[i]=a[i]/3;b[i]=1;
		}
		if((a[i]^i)&1)gofail();
		if(i&1)sum2^=b[i];
		else sum1^=b[i];
	}
	for(int i=1;i<=n;i+=2){
		sum1^=qry(a[i]);
		add(a[i]);
	}
	memset(sum,0,sizeof sum);
	for(int i=2;i<=n;i+=2){
		sum2^=qry(a[i]);
		add(a[i]);
	}
	if(sum1||sum2)gofail();
	cout<<"Yes\n";
	return 0;
}


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

int main(){
	int N, R;
	cin >> N >> R;
	if(N>=10) {
		cout << R << endl;
		return 0;
	}
	else {
		cout << R + 100 * (10 - N) << endl;
		return 0;
	}
}

#include<stdio.h>
int main(){
	int n, r, t;
	scanf("%d %d", &n, &r);
	t = 100 * (10 - n);
	if(n<10){
		printf("%d\n", r+t);
	}
	else{
		printf("%d\n", r);
	}
	return 0;
}


#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

const int N = 100005;

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

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

pair<int,pair<int,int>>c[N];
int par[N],siz[N];

int find(int x){
    while(par[x]!=x){
        x=par[x];
    }
    return x;
}

void un(int a,int b){
    a=find(a);
    b=find(b);
    if(siz[a]<siz[b]){
        par[a]=par[b];
        siz[b]+=siz[a];
    }
    else{
        par[b]=par[a];
        siz[a]+=siz[b];
    }
}

int main(){
    IOS

    int n;
    cin>>n;
    FOR(i,1,n+1){
        par[i]=i;
        siz[i]=1;
        c[i].F=i;
        cin>>c[i].S.F>>c[i].S.S;
    }

    vector<pair<int,pair<int,int>>>v;

    sort(c+1,c+n+1,cmp1);

    FOR(i,1,n){
        v.pb(mp(c[i+1].S.F-c[i].S.F,mp(c[i].F,c[i+1].F)));
    }
    sort(c+1,c+n+1,cmp2);
    FOR(i,1,n){
        v.pb(mp(c[i+1].S.S-c[i].S.S,mp(c[i].F,c[i+1].F)));
    }
    sort(all(v));

    int cnt=0;
    int i=0;
    ll ans=0;
    while(cnt<n-1){
        int x=find(v[i].S.F),y=find(v[i].S.S);
        if(x==y){
            i++;
            continue;
        }
        un(x,y);
        ans+=v[i].F;
        i++;
        cnt++;
    }
    cout<<ans;

    cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
    return 0;
}

#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 MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
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<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
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;}

////////// Union-Find木 //////////

struct UnionFind{
  vector<int> par,siz;						//par[i]:iの親の番号
  UnionFind(int N):par(N),siz(N,1ll){		//最初は全てが根であるとして初期化
    for(int i=0; i<N; i++) par[i]=i;
  }

  int root(int x){						//データxが属する木の根
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }

  void unite(int x,int y){				//xとyの木を併合
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(siz[rx]<siz[ry]) swap(rx,ry);
    siz[rx]+=siz[ry];
    par[ry]=rx;
  }

  bool same(int x,int y){				//x,yが属する木が同じならtrueを返す
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }

  int size(int x){
    return siz[root(x)];
  }
};

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

int main(){
  ll N;
  cin>>N;
  ll X[N],Y[N];
  REP(i,N) cin>>X[i]>>Y[i];

  vector<pair<ll,ll>> GX,GY;
  REP(i,N) GX.PB(MP(X[i],i)),GY.PB(MP(Y[i],i));
  SORT(GX),SORT(GY);

  Graph G(N);
  REP(i,N-1){
    G[GX[i].second].PB(Edge(GX[i+1].second,GX[i+1].first-GX[i].first));
    G[GX[i+1].second].PB(Edge(GX[i].second,GX[i+1].first-GX[i].first));
    G[GY[i].second].PB(Edge(GY[i+1].second,GY[i+1].first-GY[i].first));
    G[GY[i+1].second].PB(Edge(GY[i].second,GY[i+1].first-GY[i].first));
  }

  vector<tuple<ll,ll,ll>> L;
  REP(i,N){
    FORE(j,G[i]){
      L.emplace_back(j.second,j.first,i);
    }
  }
  SORT(L);

  UnionFind U(N);
  ll ans=0,cnt=0;
  REP(i,(ll)L.size()){
    if(!U.same(get<1>(L[i]),get<2>(L[i]))){
      U.unite(get<1>(L[i]),get<2>(L[i]));
      ans+=get<0>(L[i]);
      cnt++;
    }
    if(cnt==N-1){
      cout<<ans<<endl;
      return 0;
    }
  }

  return 0;
}


// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=1000+10;
const int mod=1e9+7;
int qpow(int a,int b) { int c=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
	return c;
}

int n,a,b,c,d,dp[N][N];

int fac[N],ifac[N];
void init(int n) {
	fac[0]=1;
	for (int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for (int i=n;i;--i) ifac[i-1]=1ll*ifac[i]*i%mod;
}
int C(int n,int m) { return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod; }

int main() {
	init(1000);
	n=read(),a=read(),b=read(),c=read(),d=read();
	for (int i=0;i<=b;++i) dp[0][i]=1;
	for (int i=1;i<=n;++i)
		for (int j=a;j<=b;++j) {
			dp[i][j]=dp[i][j-1];
			for (int k=c;k<=d;++k) {
				if (i-j*k<0) break;
				dp[i][j]=(dp[i][j]+1ll*dp[i-j*k][j-1]*C(n-i+j*k,j*k)%mod
						 *fac[j*k]%mod*ifac[k]%mod*qpow(ifac[j],k))%mod;
			}
		}
	printf("%d\n",dp[n][b]);
	return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll MOD = 1000000007;
const int SIZE = 1010;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<SIZE;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll Combination (int a,int b) {
    if(a<b) return 0;
    return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
ll dp[1010][1010];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  make();
  FOR(i,0,1010) dp[i][0] = 1;
  FOR(i,a,b+1) {
    FOR(j,0,n+1) {
      if(dp[i][j] == 0) continue;
      if(j != 0) (dp[i+1][j] += dp[i][j]) %= MOD;
      ll p = 1;
      for(int k = 1; k <= d && j + i * k <= n; k++) {
        p = (((p * Combination(n - j - i * (k - 1), i) % MOD) * inv[k]) % MOD) % MOD;
        if(k >= c) (dp[i+1][j+i*k] += (dp[i][j] * p) % MOD) %= MOD;
      }
    }
  }
  cout << dp[b+1][n] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,int_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set_pair tree<pair<int,int>,int_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define M1 100000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <int>())
#define F first
#define S second

bool comp(pair <ll,ll> &p1,pair <ll,ll> &p2){

if(p1.F<p2.F)
	return 1;
if(p1.F==p2.F){
	return p1.S>p2.S;
}
return 0;

}

int main(){

    FAST
//	PRECISE

ll n;
cin>>n;
ll z=0;
ll L=0,LL=0;
ll R=M,LR=0;
ll MA=0;
ve <pair <ll,ll> > dummy;
FOR(i,0,n){
	ll x,y;
	cin>>x>>y;
	y++;
	R=min(R,y);
	if(R==y)
		LR=max(LR,y-x);

	L=max(L,x);
	if(L==x)
		LL=max(LL,y-x);
	dummy.pb({x,y});
	MA=max(MA,y-x);
}
ll ans=max(z,R-L)+MA;

ve <pair <ll,ll> > v;
FOR(i,0,n){
	ll a1=max(z,dummy[i].S-L);
	ll a2=max(z,R-dummy[i].F);
	v.pb({a1,a2});
}
sort(v.begin(),v.end(),comp);
ll cm=LR;
FOR(i,0,v.size()){

	ll lans=0;
	ll a1=v[i].F;
	lans=a1+cm;
	ans=max(ans,lans);
	cm=min(cm,v[i].S);

}
ans=max(ans,cm+LL);
cout<<ans;

return 0;
 }

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi frist
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=200005;
int a[N],c[N],n,K;

int main(){
	read(n),read(K);
	rep(i,1,n){
		read(a[i]);
	}
	rep(k,1,K){
		memset(c,0,sizeof c);
		rep(i,1,n){
			int l=max(1,i-a[i]);
			int r=min(n,i+a[i]);
			c[l]++,c[r+1]--;
		}
		int flag=0;
		rep(i,1,n){
			c[i]+=c[i-1];
			a[i]=c[i];
			if(a[i]<n){
				flag=1;
			}
		}
		if(!flag){
			break;
		}
	}
	rep(i,1,n){
		printf("%d%c",a[i]," \n"[i==n]);
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> left(n,0),right(n,0);

    left[0] = 0;
    if(s[0] == 'W')left[0]++;
    reps(i,1,n){
        left[i] = left[i-1];
        if(s[i] == 'W')left[i]++;
    }

    right[n-1] = 0;
    if(s[n-1] == 'E')right[n-1]++;
    for(int j = n-2;j >= 0; j--){
        right[j] = right[j+1];
        if(s[j] == 'E') right[j]++;
    }

    // rep(i,n) cout << left[i] << endl;
    // cout << endl;
    // rep(i,n) cout << right[i] << endl;
    // cout << endl;

    int ans = right[1];
    ans = min(ans,left[n-1]);

    rep(i,n-1){
        ans = min(ans,right[i+2] + left[i]);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> W(n, 0);
    vector<int> E(n, 0);

    string s;
    cin>>s;

    if(s[0] == 'W'){
        W[0]++;
    }
    if(s[0] == 'E'){
        E[0]++;
    }

    for(int i=1; i<n; i++){
        if(s[i] == 'W'){
            W[i] = W[i-1] + 1;
        }else{
            W[i] = W[i-1];
        }
        if(s[i] == 'E'){
            E[i] = E[i-1] + 1;
        }else{
            E[i] = E[i-1];
        }
    }

    int ans = E[n-1] - E[0];
    for(int i=1; i<n; i++){
        ans = min(ans, E[n-1]-E[i] + W[i-1]);
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int N = 4e6 + 10, M = 2e3 + 10, MOD = 1e9 + 7;
int fac[N], inv[N], dp[M][M], ps[M][M];

int sum(int a, int b) {return (a + b) % MOD;}
int mul(int a, int b) {return (a * b) % MOD;}
int Pow(int a, int b)
{
    int res = 1;
    for (; b; b>>=1, a = mul(a, a)) if (b & 1) res = mul(res, a);
    return res;
}

int C(int n, int k)
{
    if (k < 0 || n < 0 || k > n) return 0;
    return mul(fac[n], mul(inv[k], inv[n - k]));
}

int32_t main()
{
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);
    inv[N - 1] = Pow(fac[N - 1], MOD - 2);
    for (int i = N - 2; i >= 0; i--) inv[i] = mul(inv[i + 1], i + 1);
    int n, k; cin >> n >> k;
    if (k == 1) return cout << "1\n", 0;
    ps[1][1] = dp[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i][1] = mul(ps[i - 1][1], C(i * k - 2, k - 2));
        for (int j = 2; j <= i; j++) {
            dp[i][j] = mul(ps[i - 1][j - 1], C(i * k - j - 1, k - 2));
        }
        for (int j = i; j >= 1; j--) ps[i][j] = sum(ps[i][j + 1], dp[i][j]);
    }
    cout << mul(ps[n][1], fac[n]) << "\n";
}

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

const int MAXN = 3000;
const int MAXM = MAXN*MAXN;
const int MOD = int(1E9) + 7;

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=1LL*b*b%MOD)
		if( i & 1 ) ret = 1LL*ret*b%MOD;
	return ret;
}

int fct[MAXM + 5], ifct[MAXM + 5];
int comb(int n, int m) {
	return 1LL*fct[n]*ifct[m]%MOD*ifct[n-m]%MOD;
}
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXM;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[MAXM] = pow_mod(fct[MAXM], MOD - 2);
	for(int i=MAXM-1;i>=0;i--)
		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;
}

int f[MAXN + 5][MAXN + 5];

int main() {
	init();
	int N, K; scanf("%d%d", &N, &K);
	if( K == 1 ) {
		puts("1");
		return 0;
	}
	for(int i=1;i<=N;i++) f[1][i] = 1;
	for(int i=2;i<=N;i++) {
		for(int j=1;j<=i;j++) {
			int m = (K - 1)*(i - 1) + j, n = K - 2;
			f[i][j] = 1LL*f[i-1][j]*comb(n+m-1, n)%MOD;
		}
		for(int j=1;j<=N;j++)
			f[i][j] = (f[i][j] + f[i][j-1]) % MOD;
	}
	printf("%lld\n", 1LL*f[N][N]*fct[N]%MOD);
}


#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	ll a,b,m;
	cin>>a>>b>>m;
	ll x[a],y[b],mins1=100005,mins2=100005;
	for(int i=0;i<a;i++){
		cin>>x[i];
		mins1=min(mins1,x[i]);
	}
	for(int i=0;i<b;i++){
		cin>>y[i];
		mins2=min(mins2,y[i]);
	}
	ll mins=mins1+mins2;
	for(int i=0;i<m;i++){
		ll d,e,f,now;
		cin>>d>>e>>f;
		now=x[d-1]+y[e-1]-f;
		mins=min(now,mins);
	}
	cout<<mins;
}

#include <bits/stdc++.h>

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

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

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

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

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

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

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

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

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

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

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

const int N = 100005;

int n, m, q, a[N], b[N];

void solve() {
	read(n), read(m), read(q);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	for (int i = 1; i <= m; ++i) {
		read(b[i]);
	}
	int ans = *std::min_element(a + 1, a + 1 + n) + *std::min_element(b + 1, b + 1 + m);
	for (int i = 1; i <= q; ++i) {
		int x, y, c;
		read(x), read(y), read(c);
		ans = std::min(ans, a[x] + b[y] - c);
	}
	print(ans);
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int numa[1000000], numb[1000000];
int main(){
    int n; cin >> n;
    vector<int> a, b;
    int x, y;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
        numa[x]++;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> y;
        b.push_back(y);
        numb[y]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if(numa[i]+numb[i] > n) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    for (int i = 1; i <= n; i++)
    {
        numa[i] += numa[i-1];
        numb[i] += numb[i-1];
    }
    int shift=0;
    for (int i = 1; i <= n; i++)
    {
        shift = max(shift, numa[i] - numb[i-1]);
    }
    for(int i = 0; i < n; i++){
        cout << b.at((i+n-shift)%n) << " ";
    }
    puts("");
}

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

int main() {
  int N;
  cin >> N;
  vector A(N, 0), B(N, 0);
  for (auto &a : A) cin >> a;
  for (auto &a : B) cin >> a;

  auto f = [&]() {
    for (int i = N - 1; i >= 0; i--) {
      if (A.at(i) == B.at(i)) return false;
    }
    cout << "Yes" << "\n";
    for (auto ans : B) cout << ans << "\n";
    return true;
  };

  reverse(B.begin(), B.end());
  if (f()) return 0;
  reverse(B.begin(), B.end());

  rotate(B.begin(), B.begin() + (N / 2), B.end());
  if (f()) return 0;
  cout << "No" << "\n";
}


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

int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int>a(n);
    vector<int>b(m);
    rep(i,n)cin>>a[i];
    rep(i,m) cin>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(max(a[n-1],x)<min(b[0],y))cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

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

int main() {
 int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a+b)>(c+d)) {
    cout << "Left" << endl;
  }
  else if ((a+b)<(c+d)){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }

 return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long
#define lli long long int

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

int dignum(ll n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int main(){

  ll N;
  cin >> N;

  int ans = dignum(N); // 最大の桁数を求めて億

  for (ll A = 1; A*A <= N; A++) { // Aを1からNまで、A*Aつまり√Aで求める。Nが100ならAは1〜10になる
    if(N%A != 0) continue; // NがAで割り切れない場合は飛ばす
    ll B = N/A;

    int cur = max(dignum(A), dignum(B)); // 関数F（AとBの大きい桁数を保存する)

    ans = min(ans, cur); // 最小の値を求める
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  string s; cin >> s;
  int check[26] = {};
  for(int i = 0; i < s.size(); i++){
    int t = s[i]-'a';
    check[t] = 1;
  }
  for(int i = 0; i < 26; i++){
    if(check[i] == 0) {
      char ans = 'a' + i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int k, sum=0;
	vector<int> v1(3);
	for(int i=0;i<3;i++)
	{
	    cin>>v1[i];
	}
		cin>>k;
	sort(v1.begin(),v1.end());
	for(int i=1;i<=k;i++){
	v1[2]=v1[2]*2;}
	for(int i=0;i<3;i++)
	{
	    sum+=v1[i];
	}
    cout<<sum<<"\n";
	return 0;
}

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

int main()
{
 vector<int>v;
 int a,b,c,k;
 cin >> a >> b >> c >> k;
 v.push_back(a);
 v.push_back(b);
 v.push_back(c);
 int sum = 0;
 while(k--)
 {
     sort(v.begin(),v.end());
     v[2]*=2;

 }

 sum = v[0] + v[1] + v[2];
 cout << sum << endl;

}


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

int read(){
    int s = 0,ne = 1; char c = getchar();
    while(c < '0' || c > '9') ne = c == '-' ? -1 : 1, c = getchar();
    while(c >= '0' && c <= '9') s = (s << 1) + (s << 3) + c - '0', c = getchar();
    return s * ne;
}

double n, x; int t;

int main()
{
    // freopen("_in.in", "r", stdin);
    n = read(), x = read(), t = read();
    printf("%d", (int)ceil(n / x) * t);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <utility>
#include <queue>
#define INF 1000000007

using namespace std;
typedef long long int ll;

int main(){
    vector<int> dp(31,0);
    dp[0]=1;
    dp[1]=1;
    dp[2]=2;
    for (int i=3; i<31; i++) {
        dp[i] = dp[i-1]+dp[i-2]+dp[i-3];
    }
    for (;;) {
        int n;
        cin >> n;
        if(n==0) break;
        int ans = dp[n]/(10*365)+1;
        cout << ans <<endl;
    }
}


//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =5e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int n,q;
int c[MAXN],ans[MAXN],rt,pos[MAXN],sum,a[MAXN];
struct node{
	int l,r,index;
	/*bool operator <(const node& o)const
    {
        if(pos[l]==pos[o.l]) return r<o.r;
        return pos[l]<pos[o.l];
    }*/
}need[MAXN];
int cmp(node f,node s)
{
	if(pos[f.l]==pos[s.l])
	   return f.r<s.r;
	else return f.l<s.l;
}
void add(int x)
{
	a[c[x]]++;
	if(a[c[x]]==1) sum++;
}
void del(int x)
{
	a[c[x]]--;
	if(a[c[x]]==0) sum--;
}
int main()
{
	scanf("%d %d",&n,&q);
	rt=sqrt(1.0*n);
	for(int i=1;i<=n;i++)
	{
	    scanf("%d",&c[i]);
	    pos[i]=i/rt;
	}
	for(int i=1;i<=q;i++)
	{
		scanf("%d %d",&need[i].l,&need[i].r);
		need[i].index=i;
	}
	sort(need+1,need+1+q,cmp);
	int l=1,r=0;
	for(int i=1;i<=q;i++)
	{
		while(l<need[i].l)
		{
			del(l);
			l++;
		}
		while(l>need[i].l)
		{
			l--;
			add(l);
		}
		while(r<need[i].r)
		{
			r++;
			add(r);
		}
		while(r>need[i].r)
		{
			del(r);
			r--;
		}
		ans[need[i].index]=sum;
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}

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

void compute(vector<vector<int> > & cost,vector<vector<int> > & best,
			 vector<int> & A,int s,int e){
	int minc = 0;
	int mink = -1;
	for(int k=s+1;k<=e;++k){
		if (cost[s][k-1] < 0){
			compute(cost,best,A,s,k-1);
		}
		if (cost[k][e] < 0) {
			compute(cost,best,A,k,e);
		}
		int c = cost[s][k-1] + A[s]*A[k]*A[e+1] + cost[k][e];
		if (mink < 0 || c < minc) {
			minc = c;
			mink = k;
		}
	}
	cost[s][e] = minc;
	best[s][e] = mink;
}

int main(){
	vector<vector<int> > cost,best;
	vector<int> A;
	int n;
	cin >> n;
	A.resize(n+1);
	for(int i=0;i<n;++i) {
		int r,c;
		cin >> r >> c;
		if (i==0){
			A[0] = r;
		}
		if (A[i] != r){ cout << "error";return (0);}
		A[i+1] = c;
	}
	cost.resize(n);
	best.resize(n);
	for(int i=0;i<n;++i){
		cost[i].resize(n);
		best[i].resize(n);
		for(unsigned j=0;j<cost[i].size();++j){
			cost[i][j] = -1;
			best[i][j] = -1;
		}
		cost[i][i]=0;
		best[i][i]=i;
	}
	compute(cost,best,A,0,n-1);
	cout << cost[0][n-1] << std::endl;
	return 0;
}


#include <bits/stdc++.h>
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const ll INF = 1e18;
const int MOD = 1000000007;
// const int MOD = 998244353;

ll dp[200005][5];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   int k = 1 + n % 2;
   rep(i, 0, n + 1) rep(j, 0, k + 1) dp[i][j] = -INF;
   dp[0][0] = 0;
   rep(i, 0, n) {
      rep(j, 0, k + 1) {
         chmax(dp[i + 1][j + 1], dp[i][j]);
         ll now = dp[i][j];
         if ((i + j) % 2 == 0) now += a[i];
         chmax(dp[i + 1][j], now);
      }
   }
   ll ans = dp[n][k];
   cout << ans << endl;
   return 0;
}

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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<vector<long>> d(n + 1, vector<long>(5, LLONG_MIN));
    d[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 5; j++) {
            int k = (i + 1) / 2 - j;
            if (k < 0) continue;
            {
                // don't take i-th
                int ii = i - 1;
                int jj = (ii + 1) / 2 - k;
                if (jj >= 0 && jj < 5) {
                    if (d[ii][jj] != LLONG_MIN) {
                        d[i][j] = max(d[i][j], d[ii][jj]);
                    }
                }
            }
            if (k > 0) {
                // take i-th, don't take i-1-th
                int ii = i == 1 ? 0 : i - 2;
                int jj = (ii + 1) / 2 - (k - 1);
                if (jj >= 0 && jj < 5) {
                    if (d[ii][jj] != LLONG_MIN) {
                        d[i][j] = max(d[i][j], d[ii][jj] + a[i - 1]);
                    }
                }
            }
        }
    }
    int k = n / 2;
    int j = (n + 1) / 2 - k;
    cout << d[n][j];

    return 0;
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  vecll2(dp, h+1, w+2);
  dp[0][1]=1;
  vecll num={1,2,3,5,8,13,21};
  rep(i,h){
    REP(j,1,w+1){
      ll p = max(0ll, j-2-1);
      ll q = max(0ll, w-(j+1));
      dp[i+1][j] += dp[i][j-1]*num[p]*num[q];
      dp[i+1][j] %= MOD;

      p = max(0ll, j-1-1);
      dp[i+1][j] += dp[i][j]*num[p]*num[q];
      dp[i+1][j] %= MOD;

      q = max(0ll, w-(j+2));
      dp[i+1][j] += dp[i][j+1]*num[p]*num[q];
      dp[i+1][j] %= MOD;
    }
  }

  prt(dp[h][k]);
}

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

int main(){
    int H,W,k;
    ll ans;
    cin>>H>>W>>k;
    num[0][0]=1;
    bool f=true;
    for(int i=1;i<8;i++) num[0][i]=0;
    for(int h=1;h<=H;h++){
        for(int w=0;w<(1<<(W-1))-1;w++){
            for(int i=0;i<W-1;i++){
                if(w>>i & 1  &&  w>>(i+1) & 1) f=false;
            }
            if(f){
                int v[]={0,1,2,3,4,5,6,7};
                for(int i=0;i<W-1;i++){
                    if(w>>i & 1){
                        v[W-1-i]--;
                        v[W-1-i-1]++;
                    }
                }
                for(int i=0;i<8;i++){
                    num[h][i]+=num[h-1][v[i]];
                    num[h][i]%=MOD;
                }
            }
            f=true;
        }
    }
    if(W==1){
        ans=1;
    }else{
        ans=num[H][k-1];
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

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

ll check(set<P> &s){
    ll last = -INF * 2, res = INF;
    for(P p : s){
        if(p.se){
            chmin(res, p.fi - last);
        }else{
            last = p.fi;
        }
    }
    return res;
}

int main() {
    const ll t2 = 200000;
    typedef vector<vector<set<P> > > mats;
    map<char, int> ctoi = {{'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}};
    cin>>N;
    vec x(N), y(N), u(N);
    //0 : up
    mats memo(6, vector<set<P>>(400001));
    rep(i,N) {
        char c;
        cin>>x[i]>>y[i]>>c;
        u[i] = ctoi[c];
        if(u[i] < 2){
            memo[u[i]][u[i] ? y[i] : x[i]].emplace(u[i] ? x[i] : y[i], 0);
            memo[u[i] + 2][y[i] - x[i] + t2].emplace(y[i] + x[i], 0);
        }else{
            memo[u[i] - 2][u[i] - 2 ? y[i] : x[i]].emplace(u[i] - 2 ? x[i] : y[i], 1);
            memo[5 - u[i]][y[i] - x[i] + t2].emplace(y[i] + x[i], 1);
        }
        if(u[i] == 0){
            memo[4][y[i] + x[i]].emplace(y[i] - x[i], 0);
        }else if(u[i] == 1){
            memo[4][y[i] + x[i]].emplace(y[i] - x[i], 1);
        }else if(u[i] == 2){
            memo[5][y[i] + x[i]].emplace(y[i] - x[i], 1);
        }else{
            memo[5][y[i] + x[i]].emplace(y[i] - x[i], 0);
        }
    }
    ll res = INF;
    rep(i,6){
        rep(j, 400001){
            chmin(res, check(memo[i][j]));
        }
    }
    if(res == INF) cout<<"SAFE"<<endl;
    else cout<<res * 5<<endl;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll H, W;
    cin >> H >> W;
    vll A(H), B(H);
    rep(i, H) cin >> A[i] >> B[i];

    map<int, int> m;
    rep(i, W) m[i] = 0;
    multiset<int> ms;
    rep(i, W) ms.insert(0);
    vll ans(H, 0);
    rep(i, H){
        int a = A[i]-1;
        int b = B[i]-1;
        auto lb = m.lower_bound(a);
        auto ub = m.upper_bound(b);
        if(lb!=m.end() && lb!=ub){
            --ub;
            auto it = lb;
            int k = ub->first;
            int v = ub->second;
            while(it!=m.end() && it->first!=k){
                int v = it->second;
                ms.erase(ms.find(v));
                it = m.erase(it);
            }
            if(b<W-1 && m.count(b+1)==0){
                m[b+1] = v+b-k+1;
                ms.insert(v+b-k+1);
            }
            m.erase(k);
            ms.erase(ms.find(v));
        }
        if(ms.empty()) ans[i] = -1;
        else ans[i] = *ms.begin() + i + 1;
    }
    rep(i, H) cout << ans[i] << endl;
}


#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  string T;
  char c = 'W';
  for (int i = 0; i < N * 2; i++){
    if (S[i] != c){
      T += 'L';
      c = 'B' + 'W' - c;
    } else {
      T += 'R';
      c = 'B' + 'W' - c;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N * 2; i++){
    if (T[i] == 'L'){
      cnt++;
    }
  }
  if (cnt != N){
    cout << 0 << endl;
  } else {
    int L = 0;
    long long ans = 1;
    for (int i = 0; i < N * 2; i++){
      if (T[i] == 'L'){
        L++;
      } else {
        ans *= L;
        ans %= MOD;
        L--;
      }
    }
    for (int i = 1; i <= N; i++){
      ans *= i;
      ans %= MOD;;
    }
    cout << ans << endl;
  }
}

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
string s;
bool b[200010];
signed main() {
	cin >> n >> s;
	if (s[0] == 'W' || s.back() == 'W') {
		cout << 0 << endl;
		return 0;
	}
	REP(i, 2 * n - 1) {
		if (s[i - 1] == s[i] && !b[i - 1])b[i] = true;
		if (s[i - 1] != s[i] && b[i - 1])b[i] = true;
	}
	if (!b[2 * n - 1]) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 1, cnt = 0;
	rep(i, 2 * n) {
		if (b[i]) {
			ans *= cnt;
			ans %= mod;
			cnt--;
		}
		else cnt++;
	}
	if (cnt) {
		cout << 0 << endl;
		return 0;
	}
	REP(i, n) {
		ans *= i;
		ans %= mod;
	}
	cout << ans << endl;
}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

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

template <typename T>
T abs(T x) {return (x < 0) ? -x : x;}

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

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string S;
	int K;
	cin >> S >> K;
	S += '0';
	int L = S.length(), n1 = 0, N = 0;
	vector<int> A;
	for(int i = 0, cur = 0; i < L; i++) {
		if(S[i] == '0') {
			A.push_back(cur);
			N++;
			cur = 0;
		}
		else n1++, cur++;
	}
	K = min(K, n1);
	reverse(begin(A), end(A));
	cat mod = 998244353;
	vector< vector< vector<cat> > > cnt(N+1, vector< vector<cat> >(K+1, vector<cat>(K+1, 0)));
	cnt[0][0][0] = 1;
	for(int i = 0; i < N; i++) {
		// increase/keep A[i]
		for(int k = 0; k <= K; k++) {
			cnt[i+1][k][k] = cnt[i][k][k];
			for(int j = k-1; j >= 0; j--) cnt[i+1][j][k] = cnt[i+1][j+1][k] + cnt[i][j][k];
		}
		// decrease A[i]
		for(int j = 0; j <= K; j++)
			for(int l = 1; l <= A[i]; l++)
				for(int k = j; k <= K-l; k++) cnt[i+1][j+l][k+l] += cnt[i][j][k];
		for(int j = 0; j <= K; j++) for(int k = j; k <= K; k++) cnt[i+1][j][k] %= mod;
	}
	cat ans = 0;
	for(int i = 0; i <= K; i++) ans += cnt[N][0][i];
	ans %= mod;
	cout << ans << "\n";
}

#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const int MAX_N = 300;

int dp[MAX_N+1][MAX_N+1][MAX_N+1];

const int MOD = 998244353;
int madd(int lhs,int rhs){
    int tmp = lhs+rhs;
    return tmp>=MOD ? tmp-MOD : tmp;
}
int main(){
    string s;
    cin>>s;
    int K;
    cin>>K;
    int n = s.size();
    vector<int> pack(n+1);
    int sum = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='0') sum++;
        else pack[sum]++;
    }
    if(sum==n){
        cout<<1<<endl;
        return 0;
    }

    dp[0][0][min(K,n)]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=n;k++){
                if(dp[i][j][k]==0) continue;

                for(int x=0;x<pack[i];x++){
                    if(j-(pack[i]-x)>=0) dp[i+1][j-(pack[i]-x)][k] = madd(dp[i+1][j-(pack[i]-x)][k],dp[i][j][k]);
                }

                for(int x=pack[i];j+x-pack[i]<=n && k-(x-pack[i])>=0;x++){
                    dp[i+1][j+(x-pack[i])][k-(x-pack[i])] = madd(dp[i+1][j+(x-pack[i])][k-(x-pack[i])],dp[i][j][k]);
                }
            }
        }
    }

    int res = 0;
    int pos = n;
    for(int k=0;k<=n;k++){
        res = madd(res,dp[pos][0][k]);
    }
    cout<<res<<endl;

    return 0;
}


#include<iostream>

using namespace std;

#define NMAX 20

int main(){

	int M,N,l;
	int x[NMAX],y[NMAX];
	char d;
	bool ok[21][21];

	while(1){

		cin>>N;

		if(N==0) break;

		for(int i=0;i<N;i++){
			cin>>x[i]>>y[i];
		}

		cin>>M;
		int nx=10,ny=10;
		for(int i=0;i<21;i++){
			for(int j=0;j<21;j++){
				ok[i][j]=false;
			}
		}
		ok[10][10]=true;
		for(int i=0;i<M;i++){
			cin>>d>>l;
			for(int j=0;j<l;j++){
				if(d=='N') ny++;
				if(d=='S') ny--;
				if(d=='W') nx--;
				if(d=='E') nx++;
				ok[ny][nx]=true;
			}
		}
		bool f=true;
		for(int i=0;i<N;i++){
			if(!ok[y[i]][x[i]]) f=false;
		}
		if(f) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
struct edge { int to, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int n, m, a1, a2, a3, a4, q;
int main() {
	while(cin >> m >> n, n | m) {
		vector<vector<edge> > G1(n), G2(n);
		for(int i = 0; i < m; i++) {
			cin >> a1 >> a2 >> a3 >> a4; a1--, a2--;
			G1[a1].push_back(edge{a2, a3});
			G1[a2].push_back(edge{a1, a3});
			G2[a1].push_back(edge{a2, a4});
			G2[a2].push_back(edge{a1, a4});
		}
		cin >> q;
		while(q--) {
			cin >> a1 >> a2 >> a3; a1--, a2--;
			if(a3 == 0) {
				priority_queue<edge> que; que.push(edge{a1, 0});
				vector<int> d(n, 999999999); d[a1] = 0;
				while(!que.empty()) {
					int u = que.top().to; que.pop();
					for(edge e: G1[u]) {
						if(d[e.to] > d[u] + e.cost) {
							d[e.to] = d[u] + e.cost;
							que.push(edge{e.to, -d[e.to]});
						}
					}
				}
				cout << d[a2] << endl;
			}
			else {
				priority_queue<edge> que; que.push(edge{a1, 0});
				vector<int> d(n, 999999999); d[a1] = 0;
				while(!que.empty()) {
					int u = que.top().to; que.pop();
					for(edge e: G2[u]) {
						if(d[e.to] > d[u] + e.cost) {
							d[e.to] = d[u] + e.cost;
							que.push(edge{e.to, -d[e.to]});
						}
					}
				}
				cout << d[a2] << endl;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n")
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n+1) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_arr2(x,n,m) ____; cout<<#x<<":\n"; rep(i,0,n) rep(j,0,m) cout<<#x<<"["<<(i)<<"]["<<(j)<<"]= "<<x[i][j]<<((j==m)?"\n\n":"    ")
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=1e5+5;
int n,ans=0,a[N],k; bool v[N]; int f[N][20],id[N],p[N],dep[N]; vi V[N];

int G(int x,int k) {
	per(i,0,20) if (k>>i&1) x=f[x][i];
	return x;
}

void dfs(int x,int d) {
	v[x]=1; if (dep[x]==-1) dep[x]=d;
	for (auto y:V[x]) if (!v[y]) dfs(y,d+1);
}

bool cmp(int x,int y) {
	return dep[x]>dep[y];
}

int main() {
//	file_put();

	scanf("%d%d",&n,&k);
	rep(i,1,n+1) scanf("%d",&a[i]);
	ans=(a[1]!=1),a[1]=1;
	rep(i,2,n+1) V[a[i]].pb(i);
	memset(dep,-1,sizeof(dep));
	dfs(1,0); memset(v,0,sizeof(v));
	if (k>=n-1) return 0*printf("%d\n",ans);
	rep(i,1,n+1) f[i][0]=a[i];
	rep(i,1,20) rep(j,1,n+1) f[j][i]=f[f[j][i-1]][i-1];
	rep(i,1,n+1) p[i]=G(i,k-1),id[i]=i;
	sort(id+1,id+n+1,cmp);
	rep(i,1,n+1) {
		if (dep[id[i]]<=k) break;
		if (v[id[i]]) continue;
		if (a[p[id[i]]]==1) continue;
		ans++;
		dfs(p[id[i]],0);
//		debug_arr(dep,n);
	}
	printf("%d\n",ans);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<class T> void chmax(T&x, T y){if(x < y) x = y;}
int N, K;
vector<int> G[100010];
int ans;

int dfs(int v, int p){
    int mx = 1;
    for(auto u : G[v]){
        chmax(mx, dfs(u, v) + 1);
    }
    if(mx == K && p > 1) mx = 0, ans++;
    return mx;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        int p;
        cin >> p;
        if(i == 1) ans += (p == 1 ? 0 : 1);
        else G[p].push_back(i);
    }
    dfs(1, 0);
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;

int main(){
    while(1){
        int m, nmin, nmax;
        cin >> m >> nmin >> nmax;
        if(m == 0 && nmin == 0 && nmax == 0)break;

        int p[100002];  // 1-origin
        for(int i = 1; i <= m; i++){
            cin >> p[i];
        }

        int gap = 0, ans;
        for(int i = nmin; i <= nmax; i++){
            if(p[i] - p[i + 1] >= gap){
                gap = p[i] - p[i + 1];
                ans = i;
            }
        }

        cout << ans << endl;
        //cout << gap << endl;
    }

    return 0;
}

#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);

	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);

	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);

	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);

	return ret;

}

int number(State &begin){
	int ret =0;

	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}

ll n,ans;

void tansaku(int k,int s,set<int> f){

	if(s==0&&k==0)
		ans++;
	else if(s<=0||k<=0){
		return;
	}
	else{
	for(int i=1;i<=n;i++){
		if(f.count(i)==0){
			f.insert(i);
		 tansaku(k-1,s-i,f);
		}
	}
	}

}

int main(void){

	ll m,a,b;

	while(cin>>m>>a>>b,m!=0||a!=0||b!=0){

		vector<ll> t(m);
		ll ma=0,j=0;
		for(int i=0;i<m;i++){
			cin>>t[i];
		}
		sort(t.begin(),t.end());

		int k=0;
		for(int i=a;i<=b;i++){
			//cout<<t[t.size()-i]<<" "<<t[t.size()-1-i]<<endl;
			if(ma<=t[t.size()-i]-t[t.size()-i-1]){
				ma=t[t.size()-i]-t[t.size()-i-1];
				k=i;
			}
		}
	cout<<k<<endl;
	}

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

string s;
ll c[26];

int main(){
    cin >> s;
    for(auto &e : s) c[e-'a']++;
    ll ans = s.size() * (s.size()-1) / 2;
    for(int i=0;i<26;i++){
        ans -= c[i] * (c[i]-1) / 2;
    }
    cout << ans+1 << endl;
    return 0;
}

/*Lower_Rating*/
/*AGC040 B*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define LL long long
#define MAXN 800000
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 2000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,mn,id;
struct Seg{
	int l,r;
}p[MAXN+5];
bool cmp(Seg s1,Seg s2){
	if(s1.l==s2.l)return s1.r<s2.r;
	return  s1.l<s2.l;
}
int bin(int l1,int r1,int l2,int r2){
	return max(min(r1,r2)-max(l1,l2)+1,0);
}
int main()
{
	n=read();mn=INF;
	for(int i=1;i<=n;i++)
		p[i].l=read(),p[i].r=read();
    sort(p+1,p+n+1,cmp);
	int l1=p[1].l,r1=p[1].r,l2=p[2].l,r2=p[2].r;
	for(int i=2;i<=n;i++){
		int val1=max(r2-l2+1,0)+bin(l1,r1,p[i].l,p[i].r);
		int val2=max(r1-l1+1,0)+bin(l2,r2,p[i].l,p[i].r);
        int val3=max(p[i].r-p[i].l+1,0)+bin(l1,r1,l2,r2);
		if(val1>=val2&&val1>=val3){
			l1=max(l1,p[i].l);
			r1=min(r1,p[i].r);
		}else if(val2>=val1&&val2>=val3){
			l2=max(l2,p[i].l);
			r2=min(r2,p[i].r);
		}else{
            l1=max(l1,l2);
			r1=min(r1,r2);
            l2=p[i].l,r2=p[i].r;
        }
	}
	printf("%d",max(r1-l1+1,0)+max(r2-l2+1,0));
}


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

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
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,K;
    cin >>N >> K;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    if(A.back()<K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll g = A[0];

    for(int i=1;i<N;i++){
        g = gcd(g,A[i]);
    }
    if(K%g ==0){
        cout <<"POSSIBLE" << endl;
    }else{
        cout <<"IMPOSSIBLE" << endl;
    }
    return 0;
}

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

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

  string s = "";
  string buf(w+2, '.');
  s += buf;
  for (int i = 0; i < h; i++) {
    string si;
    cin >> si;
    s += "." + si + ".";
  }
  s += buf;

  for (int i = 1; i < h+1; i++) {
    for (int j = 1; j < w+1; j++) {
      if (s.at(i*(w+2)+j) == '#') {
        char sij_up = s.at((i-1)*(w+2)+j);
        char sij_down = s.at((i+1)*(w+2)+j);
        char sij_right = s.at(i*(w+2)+j+1);
        char sij_left = s.at(i*(w+2)+j-1);
        if (sij_up == '.' && sij_down == '.' && sij_right == '.' && sij_left == '.') {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Yes" << endl;
}