#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

int main()
{
	IOS;
	int x,y,z,t1,t2,t3;
	cin>>x>>y>>z>>t1>>t2>>t3;
	int t_ele=abs(z-x)*t2+ 3*t3 + abs(x-y)*t2;
	//t_ele = min(t_ele,abs(z-x)*t1 + 3*t3 + abs(z-y)*t2);
	int t_foot=abs(x-y)*t1;
	cout<<t_ele<<" "<<t_foot<<endl;
	if(t_foot< t_ele)
		cout<<"NO";
	else
		cout<<"YES";
}


/*
"IF U BELIEVE WHY NOT!!"
                       --Cristiano Ronaldo
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli M=998244353;
#define INF 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
lli n,k,m;
lli z,q,u,a1,l,r,ax,cx,ay,by,cy,ql,qr,d,x,y;
lli w[300007];
//unordered_map<pair<ll,lli>,lli> mp;
map<lli,lli> dp;
lli ma=0;
lli pa=0;
string v[20000000];
lli cn=0;
void solve(lli cnt,string s,char j)
{
   if(cnt==k+1)
   {
       s+=j;
       v[cn++]=s;
       return;
   }
   else if(cnt>1)
   {
       s+=j;
   }
   for(int i=1;i<=k;i++)
   {
       char ch=(char)(i+48);
       solve(cnt+1,s,ch);
   }
}
bool cmp(ll a,ll b)
{
    if(a.first==b.first)
    return a.second<b.second;
    return a.first<b.first;
}
lli me(lli x,lli n,lli M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return me((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*me((x*x)%M,(n-1)/2,M))%M;

}
bool fl=true;
bool fl1;
unordered_map<lli,lli> vis;
bool solve1(string a)
{
    lli res=0;
  for(lli i=0;i<k;++i){
    lli iter=k+2;
    lli indx=i;
    while(iter--){
      if(a[indx]=='1'){
        res++;
        break;
      }
      indx=a[indx]-49;
    }
  }
  return res==k;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
int main()
{
m=1e9+7;
cin>>n>>k;
char ch=(char)(48);
solve(1,"\0",ch);
lli tot=0;
for(int j=0;j<cn;j++)
{
    fl=solve1(v[j]);
    if(fl)
    {

        tot++;
    }

}
tot=(tot%m*me((n-k),(n-k),m)%m)%m;
cout<<tot;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,m,k;
	cin>>n>>m>>k;
	long long int x=1,y=1;
	if(k<=(n-1))
	{
		x=x+k;

	}
	else if(k>=(n-1) && k<=(m-1))
	{
		x=n;
		y=y+k-(n-1);

	}
	else
	{
		k=k-(n-1+m-1);
		long long int temp;
		temp=(m-2)+1;
		long long int tim=0;
		tim=k/temp;
		x=n-tim;
		if(tim%2==0)
		{
		y=m;
		}
		else
		{
			y=2;
		}
		long long int l;
		l=k%tim;

		if(l>=1)
		{
			x=x-1;
			l=l-1;
			if(tim%2==0)
			{

			while(l--)
			{
				y--;
			}
		}
		else
		{
			while(l--)
			{
				y++;
			}
		}
		}

	}
	cout<<x<<" "<<y;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[100001];

int main()
{

	int t;
	cin >> t;
	while(t--){
		ll n,  A , B , x , y , z;

		cin >> n >> A >> B >> x >> y >> z;
		priority_queue<int>q;

		for(int i = 0 ; i < n ; i++ ){
			int p;
			cin >> p ;
			q.push(p);
		}
		ll bb = z - B;

		if(bb<=0){
			cout<<"RIP"<<endl;
			continue;
		}
		ll w = 0;
		if(bb <= y){
			w = 0;
		}
		else if((bb % y) == 0){
			w = bb/y-1;
		}
		else{
			w = bb/y;
		}
		ll aa = z - A;
		ll cum = x*w;
		//cout<<bb<<" "<<cum<<" "<<aa<<endl;
		if(aa >= cum)
		{
			aa -= cum;
			// cout<<aa<<endl;
			int count = 0;
			while(!q.empty()){
				int tp = q.top();
				// cout<<tp<<" "<<q.size()<<endl;
				q.pop();

				aa -= tp;

				if(tp/2 != 0)
					q.push(tp/2);
				count++;
				if(aa<=0){
					break;
				}

			}
			if(q.empty()){
				if(aa <= 0){
					cout<<count<<endl;
				}
				else{
					cout<<"RIP"<<endl;
				}
			}
			else{
				cout<<count<<endl;
			}

		}
		else{
			cout<<"0"<<endl;
			continue;
		}
	}

}


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

long long w, cnt, a[2][8];
set<long long> s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    s.insert(0);
    cin >> w;
    for(int i = 0; i < 8; ++i) {
        cin >> cnt;
        if(cnt == 0) continue;
        long long j = 0;
        while(2 * j + 1 <= cnt) {
            j = 2 * j + 1;
        }
        a[0][i] = j;
        a[1][i] = cnt - a[0][i];
        j = 0;
        do {
            if(j == 0) j = 1;
            else j *= 2;
            for(set<long long>::iterator it = (--s.end()); ; --it) {
                if((*it) + j * (i + 1) <= w) s.insert((*it) + j * (i + 1));
                if(it == s.begin()) break;
            }
        } while(j != (a[0][i] + 1) / 2);
        for(set<long long>::iterator it = (--s.end()); ; --it) {
            if((*it) + a[1][i] * (i + 1) <= w) {
                s.insert((*it) + a[1][i] * (i + 1));
            }
            if(it == s.begin()) break;
        }
    }
    cout << *(--s.end()) << endl;
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

const int N = 253456;

int i, j, k;

map<pair<unsigned long long, int>, unsigned long long> f;
vector<pair<unsigned long long,int> > u;
vector<unsigned long long> acc;
unsigned long long solve(unsigned long long w, int x){
	if(x == -1) return 0;
	// if(w >= acc[x]) return w - acc[x];
	auto it = f.find(make_pair(w, x));
	if(it != f.end()) return it->second;
	unsigned long long ans = solve(w, x - 1);
	for(int i = 1; i <= u[x].second; i++){
		unsigned long long v = u[x].first * i;
		if(v <= w){
			ans = max(ans, v + solve(w - v, x - 1));
		}
	}
	return f[make_pair(w,x)]=ans;
}
int main(){
	unsigned long long w; scanf("%llu", &w);
	map<unsigned long long, unsigned long long> g;
	for(i = 1; i <= 8; i++){
		unsigned long long x; scanf("%llu", &x);
		g[i] = x;
	}
	while(!g.empty()){
		auto [pt, qt] = *g.begin(); g.erase(g.begin());
		if(qt == 0) continue;
		if(qt <= 2) u.push_back(pair(pt, qt));
		else {
			if(qt%2){
				u.push_back(pair(pt, 1));
				g[pt*2] += qt/2;
			} else {
				u.push_back(pair(pt, 2));
				g[pt*2] += (qt-2)/2;
			}
		}
	}
	unsigned long long ac = 0;
	for(auto [pt, qt] : u) {
		ac += pt * qt;
		acc.push_back(ac);
	}
	cout << solve(w, int(u.size()) - 1) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std ;
const int MOD = 1e9 + 7 ;
long long answer , power [100000] ;
int x , y , helpn ;
int main()
{
	power[0] = 1 ;
	for (int i = 1 ; i < 100000 ; i ++ )	power [i] = ( power [i - 1 ] * 2 ) % MOD ;
	cin >> x >> y ;
	if ( y % x != 0 )
	{
		cout << 0 ;
		return 0 ;
	}
	y /= x ;
	answer = power[y - 1] ;
	//cerr << answer << '*' << endl ;
	for (int i = 2 ; i <= y ; i ++ )
	{
		if ( y % i == 0 )
		{
			//cerr << y << "  devisable by :  " << i << endl ;
			for (int k = 2 ; k < i ; k ++ )
			{
				if ( ! ( i % k ) )	answer ++ ;
			}
			answer -= power[ ( y / i ) - 1 ] ;
			answer += MOD ;
			answer %= MOD ;
		}
	}
	cout << answer ;
	return 0 ;
}


#include <iostream>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int dp[509][25009], N;

void solve() {
	int B = min(N, 500);

	dp[0][0] = 1;
	for (int i = 0; i < B; i++) {
		for (int j = 0; j < B * 500; j++) {
			if (dp[i][j] == 0) continue;
			dp[i + 1][j + 1] = 1;
			dp[i + 1][j + 5] = 1;
			dp[i + 1][j + 10] = 1;
			dp[i + 1][j + 50] = 1;
		}
	}
}

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

	if (N <= 500) {
		int sum = 0;
		for (int i = 0; i <= 50 * N; i++) sum += dp[N][i];
		cout << sum << endl;
	}
	else {
		cout << 49LL * N - 247LL << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

const string kPrefix = "IAO'";
const ll kStart = 1989;
const ll kBuben = 100000;

inline ll to_ll(const string& x) {
  ll res = 0;
  for (char c : x) {
    res = (10 * res) + (c - '0');
  }
  return res;
}

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

  map<string, string> reses;

  for (ll year = kStart; year <= 10 * kBuben; year++) {
    auto s = to_string(year);
    for (int i = 1; i <= s.size(); i++) {
      string suf = s.substr(s.size() - i);
      if (reses.count(suf) == 0) {
        if (year > kBuben && i != s.size()) {
          assert(s == "1" + suf);
        }
        reses[suf] = s;
        break;
      }
    }
  }

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    name = name.substr(kPrefix.size());
    auto res = reses.find(name);
    if (res == reses.end()) {
      if (name[0] == '0')
        name = "1" + name;
      cout << name << "\n";
    } else {
      cout << res->second << "\n";
    }
  }

  return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
   int n,x,y;
  while(scanf("%d%d%d",&n,&x,&y))
    {
        int flag=1;
        if(n%2==0)
        {
            int k=n/2;
            if(x==k || x==k+1)
                flag=0;
            if(y==k || y==k+1)
             flag=0;
        }
        else flag=0;
        if(flag)
            printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}


#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long n, m, a, b, money = 0;
	cin >> n >> m >> a >> b;

	if (n%m == 0)
	{
		cout << money;
	}
	else
	{
	while (n%m != 0)
	{

			if (n < m)
			{
				money = money + b;
				n--;
			}
			else
			{
				if (n > m)
				{
					money = money + a;
					++n;
				}
			}

			if (n % m == 0)
			{
				cout << money;
			}

	}

	}
}


//Besmellah
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<fstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define X first
#define Y second
#define pb push_back
#define SQR(x) ((x) * (x))
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define FOREACH(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define FOR(i, a, n) for(__typeof(n) i = (a); i <= (n); i++)
#define FORD(i, n, a) for(__typeof(n) i = (n); i >= (a); i--)
#define INF (1000 * 1000 * 1000)
#define MAXN 21

double dp[MAXN][1 << MAXN], ans, l, r;
int n;

struct Light
{
	double x, y;
	double alpha;
	Light(double _x = 0, double _y = 0, double _alpha = 0)
	{
		x = _x;
		y = _y;
		alpha = _alpha;
	}
} p[MAXN];

double calc(int idx, double s)
{
	double beta = p[idx].alpha - atan2(p[idx].x - s, p[idx].y);
	return p[idx].x + tan(beta) * p[idx].y;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> l >> r;
	FOR (i, 0, n - 1)
	{
		cin >> p[i].x >> p[i].y >> p[i].alpha;
		p[i].alpha *= M_PI / 180.0;
	}
	FOR (mask, 0, (1 << n) - 1)
		FOR (i, 0, n - 1)
		{
			double tmp = l;
			if (mask & (1 << i))
			{
				int mask2 = mask - (1 << i);
				FOR (j, 0, n - 1)
					if (mask2 & (1 << j))
						tmp = max(tmp, calc(i, dp[j][mask2]));
				if (!mask2)
					tmp = max(tmp, calc(i, l));
			}
			dp[i][mask] = tmp;
			ans = max(ans, dp[i][mask] - l);
		}
	cout.precision(9);
	cout << fixed << min(ans, r - l) << endl;
	return 0;
}


#include <iostream>

using namespace std;

typedef pair<int, int> pos;

int gcd(int a, int b)
{
    if (a >= b) {
        if (a%b == 0)
            return b;
        else
            return gcd(b, a%b);
    } else {
        if (b%a == 0)
            return a;
        else
            return gcd(a, b%a);
    }
}

pos simplify(pos a) {
	if (a.first == 0 && a.second != 0) {
		a.second = 1;
		return a;
	} else if (a.first != 0 && a.second == 0) {
		a.first = 1;
		return a;
	} else if (a.first < 0 && a.second < 0) {
		a.first = -a.first;
		a.second = -a.second;
	}

	while(true) {
		int ggcd = gcd(a.first, a.second);
		if (ggcd == 1) break;
		a.first /= ggcd;
		a.second /= ggcd;
	}

	return a;
}

int main() {
	pos a, b, c;
	bool ans = false;

	cin >> a.first >> a.second >> b.first >> b.second >> c.first >> c.second;

	pos ab, bc;
	ab.first = a.first - b.first;
	ab.second = a.second - b.second;

	bc.first = b.first - c.first;
	bc.second = b.second - c.second;

	if (simplify(ab) == simplify(bc)) {
		ans = false;
	} else {
		ans = true;
	}

	cout << (ans ? "Yes" : "No") << endl;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const int MAXN = 50;

pair<bool, ll> ispot(ll x){
    ll e = 0;
    while(!(x%2)){x /= 2; e++;}
    return make_pair(x == 1, e);
}

int n;
ll P[MAXN], DOS[MAXN];
vector<ll> X;
pair<bool, ll> E;

bool test(ll K){
    //printf("Probaremos armar %lld conjuntos.\n", K);
    vector<ll> V = X, U;
    forn(i, MAXN)forr(j, K, P[i])V.pb(DOS[i]);
    if(V.size() > P[0])return false;
    ll M = K; forn(i, MAXN){forr(j, P[i+1], min(P[i], K))U.pb(DOS[i+1]);}
    sort(U.begin(), U.end()); sort(V.begin(), V.end());
    /*printf("Para eso tenemos los extras:\n ");
    forn(i, V.size())printf(" %lld", V[i]); puts("");
    printf("Para eso tenemos los pilares:\n ");
    forn(i, V.size())printf(" %lld", U[i]); puts("");*/
    while(U.size() && V.size()){
        if(V.back() <= U.back())U.pop_back(), V.pop_back();
        else break;
    }
    return V.empty();
}

int main(){
	DOS[0] = 1;
	forr(i, 1, 50)DOS[i] = DOS[i-1]*2;
	while(cin >> n){
        forn(i, MAXN) P[i] = 0; X.clear();
        forn(i, n){
            ll x; scanf("%lld", &x); E = ispot(x);
            if(E.ff)P[E.ss]++; else X.pb(x);
        }
        ll M = P[0]; forn(i, MAXN){while(P[i] > M){X.pb(DOS[i]); P[i]--;} M = P[i];}
        /*printf("Arrancamos con:\nV:");
        forn(i, X.size())printf(" %lld", X[i]);puts("");
        forn(i, 10)printf("%lld: %lld, ", DOS[i], P[i]);puts("");*/
        ll L = 0, r = P[0]+1, m, R = P[0];
        while(r - L > 1){
            m = (L + r)/2;
            if(test(m))r = m;
            else L = m;
        }
        if(R - L)forr(i, L, R){if(i > L)printf(" "); printf("%lld", i+1);}
        else printf("-1");
        puts("");
	}
	return 0;
}


#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <stack>
#include <iostream>
#include <fstream>

#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;

using namespace std;

const int MAXN = 300001;

int c2[MAXN];

const int M = 60;

ll a[MAXN];

void no() {
	cout << -1 << endl;
	exit(0);
}

int pc[MAXN];

int getp2(ll x) {
	ll c = 1;
	int pw = 0;
	while (c < x) c *= 2, pw++;
	if (c == x) return pw;
	else return -1;
}

vector <ll> bad;
vector <ll> finishes;
vector <ll> nonp2;
vector <ll> nbad;
vector <ll> nfinishes;

bool check( vector<ll> bad, vector<ll> finishes) {
	sort(bad.begin(), bad.end());
	if (finishes.size() < bad.size()) return false;
	for (int i = 0; i < bad.size(); i++) {
		if (bad[i] >= 2 * finishes[finishes.size() - bad.size() + i]) return false;
	}
	return true;
}

void print(int l, int r) {
	for (int i = l; i <= r; i++)
		cout << i << " ";
	cout << endl;
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(20);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int p2 = getp2(a[i]);
		if (p2 != -1) pc[p2]++;
		else bad.push_back(a[i]), nonp2.push_back(a[i]);
	}
	int cur = pc[0];
	for (int i = 1; i < M; i++) {
		if (pc[i] > cur) {
			for (int j = cur; j < pc[i]; j++) {
				bad.push_back(1ll << i);
			}
		}
		while (cur > pc[i]) {
			finishes.push_back(1ll << (i - 1));
			cur--;
		}
	}

	int lg = 0, rg = finishes.size() + 1;
	while (lg < rg) {
		int md = (lg + rg) / 2;
		int rm = finishes.size() - md;
		nbad = bad;
		nfinishes.clear();
		for (int i = 0; i < rm; i++) {
			for (ll j = 1; j <= finishes[i]; j++) {
				nbad.push_back(j);
			}
		}
		for (int i = rm; i < finishes.size(); i++) nfinishes.push_back(finishes[i]);
		if (check(nbad, nfinishes)) rg = md;
		else lg = md + 1;
	}

	if (lg <= finishes.size()) {
		print(lg, finishes.size());
	} else {
		cout << -1 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef unsigned long long int ull ;

using namespace std;

const int M=1e9+7;
const char nl = '\n';

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int n , k;
	cin >> n >> k;
	char a[n] ;
	int pos1 ;
	int pos2 ;
	for (int i = 0 ; i < n ; i++){
	    cin >>a[i] ;
	    if (a[i] == 'T')
	        pos1 = i ;
	    if ( a[i] == 'G')
	        pos2 = i ;
	}
	if (pos2 > pos1)
	    swap (pos1,pos2) ;
	while(pos2 < n){
	    if (a[pos2+k] == '.')
	        pos2+= k ;

	    if (pos2 + k == pos1){
	        cout <<"YES";
	        break;
	    }

	    if (a[pos2 + k] == '#'){
	        cout <<"NO";
	        break;
	    }
	}

	    return 0;
}


/* in the name of god */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;

#define F first
#define S second
#define debug(x) cout << #x << " : " << x << endl

const int maxn = 1e8 + 10;

long long dp[maxn];

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

	#ifndef ONLINE_JUDGE
		freopen("H:/Codes/input.txt", "r", stdin);
		freopen("H:/Codes/output.txt", "w", stdout);
	#endif

	int n;
	vector<int> arr;
	cin >> n;
	// debug(10);
	for (int i = 2; i < maxn; i++) {
		// debug(i);
		int cnt = 0, t = i;
		while (i % 5 == 0) i /= 5, cnt++;
		i = t;
		dp[i] = dp[i - 1] + cnt;
	}
	// for (int i = 0; i < maxn; i++)
	// debug(10);
	for (int i = 1; i < maxn && dp[i] <= n; i++) if (dp[i] == n) arr.push_back(i);
	cout << arr.size() << endl;
	for (int i : arr) cout << i << ' ';
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld double
#define sf(x) sort(x.begin(),x.end(),func);
#define s(x) sort(x.begin(),x.end())
#define pb push_back
#define set(v, val) memset(v, val, sizeof(v));
#define rs(v) { s(v) ; r(v) ; }
#define all(v) v.begin(),v.end()
#define r(v) { reverse(all(v)) ; }
#define mod 1000000007
#define inf LONG_MAX
#define ninf LONG_MIN
#define mp make_pair
#define F first
#define S second
using namespace std;
ll is[5000005];
double cp[5000005];
double pp[5000005];
ll check(ll n)
{
    vector < ll > v;
    while(n)
    {
        v.pb(n%10);
        n /= 10;
    }
    ll j = v.size()-1;
    for(ll i=0;i<v.size()/2;i++)
    {
        if(v[i]!=v[j])
        {
            return 0;
        }
        j--;
    }
    return 1;
}
int main()
{
    ll c = 0;
    cp[1]=0;
    double p,q;
    cin>>p>>q;
    for(ll i=2;i<10000005;i++)
    {
        if(is[i]==0)
        {
            c++;
            for(ll j=i*i;j<10000005;j+=i)
            {
                is[j]=1;
            }
        }
        cp[i]=c;
    }
    c = 0;
    for(ll i=1;i<10000005;i++)
    {
        if(check(i))
        {
            c++;
        }
        pp[i]=c;
    }
    double d = p/q;
    for(ll i=10000004;i>=1;i--)
    {
        if(cp[i]*q<=pp[i]*p)
        {
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<"Palindromic tree is better than splay tree\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int M = sqrt(1e11) + 4;

ll n, k, l, r, ans = -1;

void calcA(ll t, bool flag = false) {
    for (ll a = 0; a <= n; ++a) {
        ll gt = t / (a + n);
        for (int j = -1; j <= 1; ++j) {
            ll g = gt + j;
            if (g < 0) {
                continue;
            }
            ll ato = t - r - n * g - a * g;
            if (ato < 0 || ato > a || ato > r || (n - r) < a - ato || (flag && ato == 0)) {
                continue;
            }

            ans = max(ans, a);
        }
    }
}

void calcG(ll t, bool flag = false) {
    for (ll g = 0; g < M; ++g) {
        ll tg = t - n * g - r;
        if (tg < 0) {
            continue;
        }
        ll ag = tg / g;
        for (int j = -2; j <= 1; ++j) {
            ll a = ag + j;
            ll ato = tg - a * g;
            if (ato < 0 || ato > a || ato > r || (n - r) < a - ato || (flag && ato == 0)) {
                continue;
            }
            ans = max(ans, a);
        }
    }
}

void calcA() {
    calcA(k);
    calcA(k + 1, true);
}

void calcG() {
    calcG(k);
    calcG(k + 1, true);
}

void solve() {
    cin >> n >> l >> r >> k;
    l--, r--;
    r = (r - l + n) % n + 1;

    if (n < M) {
        calcA();
    } else {
        calcG();
    }

    cout << ans;
}

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

    solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 111, mod = 998244353;

char s[N];
int dig[N], n;

int gcd(int x, int y) {
  return x ? gcd(y % x, x) : y;
}

map<pair<int, int>, int> dp[2][2][10][10];

void add(int & var, int val) {
  var += val;
  if (var >= mod)
    var -= mod;
}
int to1[10], to2[10];

long long solve(int x, int y) {
  memset(dp, 0, sizeof dp);
  int c = 0, b = 1;
  memset(to1, 0, sizeof to1);
  memset(to2, 0, sizeof to2);
  for (int i = 1; i * y < 10; ++i) {
    to1[i * x] = 1 << (i-1);
    to2[i * y] = 1 << (i-1);
  }
  for (int lebih = 0; lebih < 2; ++lebih) {
    for (int l = 0; l < 10; ++l) {
      for (int r = 0; r < 10; ++r) {
        dp[c][lebih][l][r].clear();
      }
    }
  }
  dp[c][0][0][0][{0, 0}] = 1;
  for (int i = 0; i < n; ++i) {
    swap(c, b);
    for (int lebih = 0; lebih < 2; ++lebih) {
      for (int l = 0; l < 10; ++l) {
        for (int r = 0; r < 10; ++r) {
          dp[c][lebih][l][r].clear();
        }
      }
    }
    for (int lebih = 0; lebih < 2; ++lebih) {
      for (int l = 0; l < 10; ++l) {
        for (int r = 0; r < 10; ++r) {
          for (auto it : dp[b][lebih][l][r]) {
            int now = it.second;
            int maska = it.first.first, maskb = it.first.second;
            if (now == 0) continue;
            for (int k = 0; k < 10; ++k) {
              int ll = l + x * k, rr = r + y * k;
              int dl = ll % 10, dr = rr % 10;
              ll /= 10; rr /= 10;
              int more = 0;
              if (dr > dig[i])
                more = 1;
              else if (dr == dig[i])
                more = lebih;
              int mmaska = maska, mmaskb = maskb;
              if (mmaska != -1) {
                if (dl > 0 && (dl % x) == 0)
                  mmaska |= 1 << (dl/x);
                if (dr > 0 && (dr % y) == 0)
                  mmaskb |= 1 << (dr/y);
              }
              add(dp[c][more][ll][rr][{mmaska, mmaskb}], now);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (auto it : dp[c][0][0][0]) {
    auto mask = it.first;
    if (mask.first & mask.second)
      add(ans, it.second);
  }
  return ans;
}

int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i)
    dig[n-1-i] = s[i]-'0';
  dig[n] = 0;
  long long ans = 0;
  for (int x = 1; x <= 9; ++x) {
    for (int y = x; y <= 9; ++y) {
      if (gcd(x, y) != 1) continue;
      long long res = solve(x, y);
      ans = (ans + res) % mod;
      if (x != y)
        ans = (ans + res) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
   int n,k,c=0,i,a;
   cin>>n>>k;
   vector<pair<int,int>>v(k);
   for(i=0;i<n/k;i++)
   {v[i].first=0;
   v[i].second=0;}
   int j=0;
   while(j<n)
   {
       for(i=0;i<k;i++)
       {
           cin>>a;
           if(a%2==0)
           v[i].first+=1;
           else
           v[i].second+=1;
       }
     j+=i;
   }

   for(i=0;i<k;i++)
   {
       c+=min(v[i].first,v[i].second);
   }
   cout<<c;

}


#include <bits/stdc++.h>
#define MAXN 1000000
#define pb push_back
using namespace std;
int vx,vy,flag;
char a;
int A[9][9];
struct node
{
    int x,y,t;
}temp;
queue <node> q;
void bfs()
{
    node temq,exp;
    while(!q.empty())
    {
        temq=q.front();
        q.pop();
        if (temq.x<0 || temq.y<0 || temq.x>8 || temq.y>8)
            continue;
        if (temq.t==80)
            continue;
        if (temq.x==vx && temq.y==vy)
        {
            flag=1;
            break;
        }
        if (A[temq.x+temq.t-1][temq.y]==-1)
            continue;
        exp=temq;
        exp.t+=1;
        exp.x-=1;
        q.push(exp);
        exp.x+=2;
        q.push(exp);
        exp.x-=1;
        exp.y-=1;
        q.push(exp);
        exp.y+=2;
        q.push(exp);
    }
    return;
}
int main()
{
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            scanf(" %c",&a);
            if (a=='.')
                A[i][j]=0;
            if (a=='A')
            {
                A[i][j]=0;
                vx=i;
                vy=j;
            }
            if (a=='M')
            {
                A[i][j]=0;
                temp.x=i;
                temp.y=j;
            }
            if (a=='S')
                A[i][j]=-1;
        }
    }
    temp.t=0;
    q.push(temp);
    bfs();
    if (flag)
        printf("WIN");
    else
        printf("LOSE");
        //~ for (int i = 0; i < 8; i++)
        //~ {
            //~ for (int j = 0; j < 8; j++)
            //~ {
                //~ printf("%4d",A[i][j]);
            //~ }
            //~ printf("\n");
        //~ }
        //~

}
/*
.......A

........

........

........

........

........

........

M.......
*/


#include <bits/stdc++.h>
#include <unistd.h>
#define inf 1000000007
#define INF 1000000000000000007LL
#define endl cout<<'\n'
#define endr cerr<<'\n'
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define bit bitset<N>
#define pii pair<int,int>
#define pdd pair<double,double>
#define vi vector<int>
#define vd vector<double>
#define vll vector<long long>
#define vpii vector< pair<int,int> >
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i, n) for(int i=1; i<=(n); ++i)
#define pv(x) cerr<<#x<<": "<<x<<'\n'
#define ps(x) cerr<<#x<<": ";for(auto q:(x)){cerr<<q<<" ";}cerr<<'\n'
#define pa(x, xs) cerr<<#x<<": ";for(int q=0; q<xs; ++q){cerr<<x[q]<<" ";}cerr<<'\n'
#define pal(x, xs) cerr<<'\n'<<#x<<":\n";for(int q=0; q<xs; ++q){cerr<<q<<": "<<x[q]<<'\n';}cerr<<'\n'
#define ppii(x, xs) cerr<<'\n'<<#x<<":\n";for(int q=0; q<xs; ++q){cerr<<q<<": "<<x[q].first<<" "<<x[q].second<<'\n';}cerr<<'\n'
#define pm(x, xn, xm) cerr<<'\n'<<#x<<":\n";for(int qa=0; qa<xn; ++qa){for(int qb=0; qb<xm; ++qb){cerr<<setw(5)<<x[qa][qb]<<" ";}cerr<<'\n';}cerr<<'\n'
using namespace std;
#define N 1000007
#define int long long
//#define double long double
#define cerr if(0)cout

int n, h, m, digh=0, digm=0, rst=0;
vi h7, m7, nowh, nowm;

bool convert()
{
  while (h)
  {
    h7.pb(h%7);
    h /= 7;
    ++digh;

    if (digh>7) return 0;
  }
  reverse(all(h7));

  while (m)
  {
    m7.pb(m%7);
    m /= 7;
    ++digm;

    if (digm>7) return 0;
  }
  reverse(all(m7));

if (digm+digh > 7) return 0;
return 1;
}

bool check_m()
{
  rep(i, digm)
  {
    if (nowm[i] != m7[i]) return 0;
  }

return 1;
}

bool check_h()
{
  rep(i, digh)
  {
    if (nowh[i] != h7[i]) return 0;
  }

return 1;
}

bool check_unique()
{
  bit vis=0;

  for (auto j: nowh)
  {
    if (vis[j]) return 0;
    vis[j] = 1;
  }

  for (auto j: nowm)
  {
    if (vis[j]) return 0;
    vis[j] = 1;
  }

return 1;
}

void shift_h()
{
  for (int i=digh-1; i>0; --i)
  {
    if (nowh[i] > 6)
    {
      nowh[i] = 0;
      ++nowh[i-1];
    }
    else break;
  }

  if (check_h() && check_m())
  {
    rst += check_unique();
    cout<<rst; exit(0);
  }
}

void shift_m()
{
  for (int i=digm-1; i>0; --i)
  {
    if (nowm[i] > 6)
    {
      nowm[i] = 0;
      ++nowm[i-1];
    }
    else break;
  }

  if (check_h() && check_m())
  {
    rst += check_unique();
    cout<<rst; exit(0);
  }

  if (check_m())
  {
    rst += check_unique();
    rep(i, digm) nowm[i] = 0;
    ++nowh[digh-1];

    shift_h();
  }
}

void iterate()
{
  rep(q, digh) nowh.pb(0);
  rep(q, digm) nowm.pb(0);

  while (true)
  {
    ++nowm[digm-1];
    shift_m();

    rst += check_unique();

    ps(nowm); ps(nowh);
    pv(rst);endr;
  }

cout<<rst;
}

void solve()
{
  cin>>h>>m;
  --h; --m;

  if (!convert()) {cout<<"0"; return;}

  ps(h7);
  ps(m7);

  iterate();
}

int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//cout<<fixed<<setprecision(10);

  solve();

return 0;
}


#include<vector>
#include<cstring>
#include<cstdio>

using namespace std;

int a, b, k;
long long res = 0;
int primos[100000];
int tam = 0;
bool esPrimo[1000000001];

long long mcd (long long a, long long b){
    if (b == 0) return a;
    return mcd(b,a%b);
}

long long mcm(long long a, long long b){
    return (a*b)/mcd(a,b);
}

void rec(int ct, int pos, long long act){
    if (primos[pos] == k){
        if (ct == 0) return;
        act = mcm(act,k);
        long long tmp = (b/act)-((a-1)/act);
        if (ct%2 == 0){
            res+=tmp;
        }
        else{
            res-=tmp;
        }
        return;
    }
    rec(ct+1,pos+1,mcm(act,primos[pos]));
    rec(ct,pos+1,act);
}

void criba(){
    esPrimo[0] = esPrimo[1] = false;
    for (int i = 2; i <= k; i++){
        if (!esPrimo[i]) continue;
        primos[tam] = i;
        tam++;
        for (int j = i+i; j <= k; j+=i){
            esPrimo[j] = false;
        }
    }
}

int main(){
    scanf("%d %d %d", &a, &b, &k);
    memset(esPrimo,true,sizeof(esPrimo));
    criba();
    if (!esPrimo[k]) printf("0\n");
    else if (b < k) printf("0\n");
    else if (b < k*k and a < k) printf("0\n");
    else if (k == 2){
        long long tmp = (b/k)-((a-1)/k);
        printf("%lli\n", tmp);
    }
    else{
        res = (b/k)-((a-1)/k);
        rec(0,0,1);
        printf("%lli\n", res);
    }
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int n; char inp[105];
int main(void) {
	scanf("%d %s", &n, inp);
	for (int i = 0; i < n; i++) {
		if (inp[i] == inp[i + 1] && inp[i] != '?') {
			return printf("No\n");
		}
	}
	for (int i = 0; i < n; i++) {
		if (inp[i] != '?' && inp[i + 3] != '?' && inp[i] != inp[i + 3] && inp[i + 1] == inp[i + 2] && inp[i + 1] == '?') {
			inp[i + 1] = inp[i + 2] = 'x';
		}
		if (inp[i] != '?' && inp[i + 2] != '?' && inp[i + 2] != inp[i] && inp[i + 1] == '?') {
			inp[i + 1] = 'x';
		}
	}
	for (int i = 0; i < n; i++) {
		if (inp[i] == '?') return !printf("Yes\n");
	}
	printf("No\n");
}


#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
    char s[2];
    char a[2];
    int n;

    while(scanf("%s",s))
    {
        cin>>n;
        char A=s[0];
        char B=s[1];
        if(n==1)
        {
            getchar();
            scanf("%s",a);
            sort(a,a+2);
            if(a[0]==A&&a[1]==B)
                cout<<"YES"<<endl;
            continue;
        }
        int flag1=0;
        int flag2=0;
        for(int i=1;i<=n;i++)
        {
            getchar();
            scanf("%s",a);
           // cout<<"a="<<a[0]<<" "<<a[1]<<endl;
            if(a[0]==B)
                flag1=1;
            if(A==a[1])
                flag2=1;
        }
       // cout<<flag1<<" "<<flag2<<endl;
        if(flag1&&flag2)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


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

int main()
{
    int n,i,j,k;
    int a,b,c,d,e,f,res=0;
    cin >> n;
    cin >> a >> b >> c >> d >> e >> f ;
    for(i=a;i<=b;i++)
    {
        for(j=c;j<=d;j++)
        {
            for(k=e;k<=f;k++)
            {
                res=i+j+k;
                if(res==n)
                {printf("%d %d %d\n",i,j,k);
                exit(-1);
                }
            }
        }
    }

    return 0;
}


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

int main()
{
    int n,i,j,m,c,a,f=0;
    cin >> n>>m;
    vector<int>bk;
    vector<int>fr;
    for(i=1;i<=n;i++)
    {
        if(f==0)
        {
            if(i==m)
            {
                f=1;
            }
            else
            {
                bk.push_back(i);
            }
        }
        else if(f==1)
        {
             fr.push_back(i);
        }

    }
    if(bk.size()>fr.size())
    {
        if(bk.size()>1){
        cout<<bk[bk.size()-1];
        }
        else cout<<m;
    }
    else if(bk.size()<fr.size()){
            if(fr.size()>1){
        cout<<fr[0];
            }
            else
            {
                cout<<m;
            }
    }
    else{
        if(bk.size()==0 || bk.size()==1)
        {
            cout<<m;
        }
        else{
            cout<<fr[0];
        }
    }
}


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

int A[22];

int main() {
    int n, a, b, ans = 0; scanf("%d%d%d",&n,&a,&b);
    for(int i=0; i<n; i++) scanf("%d",&A[i]);
    for(int i=0; i<n; i++) {
        if(A[i] == 0 && A[n-i-1] == 1) return printf("-1");
        if(A[i] == 2 && A[n-i-1] == 2) ans += (a < b) ? a : b;
        else if(A[i] == 2) {
            if(A[n-i-1] == 0) ans += a;
            if(A[n-i-1] == 1) ans += b;
        }
    }
    printf("%d",ans);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <cctype>
char str[210];

int main()
{
	while(scanf("%s", str) != EOF)
	{
		char *p = str;
		int flag = 0;
		while(*(p+2))
		{
			int k = 0;
			while(p[k+2] && (p[k] != 'W' || p[k+1] != 'U' || p[k+2] != 'B')) k++;
			if(k)
			{
				if(flag) printf(" ");
				for(int i = 0; i < k; i++) printf("%c", p[i]);
				flag = 1; p+=k;
				continue;
			}
			else p+=3;
		}
		if(*p) printf(" %s", p);
		printf("\n");
		memset(str, 0, sizeof(str));
	}
	return 0;
}


#include <bits/stdc++.h>

#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define zrep(i,b) for(int i = 0; i <int(b); i++)
#define nzrep(i,b) for(int i = int(b); i <0; i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define circ_inc(i, n) (i + 1) % int(n)
#define circ_dec(i, n) (i + int(n) - 1) % int(n)
#define round(x) (int)((double)int(x) + 0.5)
#define println(x) cout << x << '\n'
#define F first
#define S second
#define INF 1000000000
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define modulo 1000000007
#define PI 3.141592653589793
#define tc int t; cin>>t; while(t--)

const int N = 1e5 + 5;
const double eps = 1e-6;

using namespace std;

typedef vector<int>::iterator vit;
typedef vector<long>::iterator vlit;
typedef vector<long long>::iterator vllit;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<string, int> msi;
typedef istringstream iss;

int main()

{
	fastio;

    double a,b,c,d,e,r;
    cin>>a>>b>>c>>d;

    int ans = 42 ;

    r = b-a;
    if(c == b+r && d == c+r) {
        ans = d+r;

    }

    r = b/a;
    if(c == b*r && d == c*r ) {
        e = d*r;
        if(abs(e-floor(e) <= eps))
            cout<<e<<endl;
    }

    cout<<ans<<endl;

    return 0;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string.h>
#include <limits.h>
#include <cfloat>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mem(flag) memset(flag,0,sizeof(flag))
#define Mem(flag) memset(flag,-1,sizeof(flag))
#define read(a) a=getInt()
#define En printf("\n")
#define P(a) printf("%d ",a)
#define Pn(a) printf("%d\n",a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define rep(flag, a, b) for (int flag = (a); flag <= (b); ++flag)
#define Rep(flag, a, b) for (int flag = (a); flag >= (b); --flag)

const int MAX = 200;
int trie[MAX][28],cnt;
pair<int, char> pa[MAX]; int dep[MAX];
bool isTer[MAX];

int con[MAX][28];

void insert(char *s) {
    int len=strlen(s),cur=0;
    for(int i=0;i<len;i++) {
        if(trie[cur][s[i]-'A']!=-1) cur=trie[cur][s[i]-'A'];
        else {
            trie[cur][s[i]-'A']=cnt++;
            dep[cnt - 1] = dep[cur] + 1;
            pa[cnt - 1] = {cur, s[i]};
            if (i == len - 1) isTer[cnt - 1] = 1;
            cur=cnt - 1;
        }
    }
}

int find(char *s) {
    int len = strlen(s), cur = 0;
    for (int i = 0; i < len; i++) {
        if (trie[cur][s[i] - 'A'] == -1) return -1;
        else cur = trie[cur][s[i] - 'A'];
    }
    return cur;
}

char buff[20][20];
const int MOD = 1000000009;
int dp[1002][1002][105];
int n, m;
char zm[4] = {'A', 'C', 'G', 'T'};
char tmp[200];
int tn;
int main() {
    scanf("%d%d", &n, &m);
    cnt = 1, Mem(trie), pa[0] = {-1, -1}, dep[0] = 0, mem(isTer);
    for (int i = 0; i < m; i++) scanf("%s", buff[i]), insert(buff[i]);
    for (int i = 0; i < cnt; i++) {
        stack<char> S;
        int t1 = i;
        while (t1 != 0) {
            S.push(pa[t1].second);
            t1 = pa[t1].first;
        }
        tn = 0;
        while (!S.empty()) {
            tmp[tn++] = S.top();
            S.pop();
        }
        for (int j = 0; j < 4; j++) {
            tmp[tn] = zm[j], tmp[tn + 1] = 0;
            for (int pp = 0; pp <= tn + 1; pp++) {
                int st = find(tmp + pp);
                if (st != -1) {
                    con[i][zm[j] - 'A'] = st;
                    break;
                }
            }
        }
    }
    mem(dp);
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int pos = 0; pos < cnt; pos++) {
                auto ele = dp[i][j][pos];
                if (ele) {
                    for (int sel = 0; sel < 4; sel++) {
                        int newpos = con[pos][zm[sel] - 'A'];
                        int fg;
                        if (dep[newpos] >= i + 1 - j && isTer[newpos] == 1) fg = i + 1;
                        else fg = j;
                        auto &ele1 = dp[i + 1][fg][newpos];
                        ele1 = (ele1 + ele) % MOD;
                    }
                }
            }
        }
    }
    //for (int i = 0; i < n; i++) {
        //for (int j = 0; j <= i; j++) {
            //for (int pos = 0; pos < cnt; pos++) {
                //printf("(%d %d %d) = %d\n", i, j, pos, dp[i][j][pos]);
            //}
        //}
    //}
    int ans = 0;
    for (int pos = 0; pos < cnt; pos++) {
        ans = (ans + dp[n][n][pos]) % MOD;
    }
    Pn(ans);
    return 0;
}


#include <bits/stdc++.h>
#define NN 111111
int coa[NN],cob[NN];
using namespace std;

int main() {
	int i,j,r,k,l,x,t,a,b,da,db;
//freopen("1.in", "r", stdin);
	//freopen("1.out", "w", stdout);
	while(scanf("%d%d%d%d%d%d",&x,&t,&a,&b,&da,&db)==6){
		l=1;r=1;coa[0]=a;cob[0]=b;
		while(a-l*da!=0)
			{	coa[l]=a-l*da;l++;}
		while(a-r*db!=0){
				cob[r]=b-r*db;r++;
			}
		k=0;
		for(i=0;i<t;i++){
			if(coa[i]==0)continue;
			for(j=i+1;j<t;j++){
				if(cob[j==0])continue;
				if(coa[i]+cob[j]==x||cob[i]+coa[j]==x){
					printf("YES\n");k=1;
				}
			}
		}
		if(k==0)printf("NO\n");
	}
	return 0;
}


                              //ABHISHEK AGRAWAL,BIT mesra//
                      //Newbie......You have to be odd to be no. ONE :)//
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define vs vector <string>
#define vc vector <char>
#define vii vector<int>
#define vll vector<ll>
#define sll set<ll>
#define pii pair<int,int>
#define plc pair<ll,char>
#define tlll tuple<ll,ll,ll>
#define mt make_tuple
#define vpll vector<pair<ll,ll>>
#define vpii vector<pair<int,int>>
#define vtll vector<tuple<ll,ll,ll>>
#define vvll vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mcl map<char,ll>
#define msl map<string,ll>
#define mod (ll) 1000000007
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;read(t);while(t--)
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define loopab(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reada(a,n) loop(i,n) cin>>a[i];
#define reada1(a,n) loop1(i,n) cin>>a[i];
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clzll(n)
#define leastindexwithone(n)  __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
//if we need to devide any given number in powers of term the power of max term
#define answer(n) ceil(log2(n+1))
 ll q,n;ll sum,ans;
ll gcd(ll a, ll b){if (b==0){return a;} return gcd(b,a%b);}
ll powe(ll a,ll b){ll res=1;while(b>0){if(b%2 ==1){res=(res*a);}a=(a*a);b/=2;} return res;}
ll power(ll a,ll b,ll M){a%=M;ll res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;}
ll extendedEuclid(ll A,ll B,ll &x,ll &y){
    if(B == 0) {
        x = 1;
        y = 0;
        return A;
    }
    else {
        ll x1 , y1;
        ll gcd = extendedEuclid(B,A%B,x1,y1);
        y = x1-(A/B)*y1;
        x = y1;
        return gcd;
    }
}
ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=M;} return x;}
vector<bool>sieve(1000020,true);
void Sieve(){
 sieve[0]=false;
 sieve[1]=false;
 for(ll i=2;i*i<=1000020;i++){
  if(sieve[i]==true){
   for(ll j=i*i;j<1000020;j+=i)
    sieve[j]=false;
  }
 }
}
// ll sieve_spf[1000010];
// ll n1=1000000;
// void Sieve_spf(){
//  loop(i,n1) sieve_spf[i]=i;
//   sieve_spf[0]=-1;
//   sieve_spf[1]=1;
//   for(int i=2;i<n1;i+=2) sieve_spf[i]=2;
//   for(ll i=3;i<n1;i+=2){
//     if(sieve_spf[i]==i){
//       for(ll j=(i*i);j<n1;j+=i){
//         if(sieve_spf[j]==j) sieve_spf[j]=i;
//       }
//     }
//   }
// }
// #ifdef TESTING
// #define DEBUG fprintf(stderr, "====TESTING====\n")
// #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
// #define debug(...) fprintf(stderr, __VA_ARGS__)
// #else
// #define DEBUG
// #define VALUE(x)
// #define debug(...)
// #endif
// bool isUpcase(char c){
//     if(c >= 'A'&&c <= 'Z') return true;
//     5,5,else return false;
// }
// bool islowcase(char c){
//     if(c >= 'a'&&c <= 'z') return true;
//     else return false;
// }
const int nax=3e5+5;
ll fact[nax];
void F(){
 fact[0]=1;
 for(int i=1;i<nax;i++){
  fact[i]=fact[i-1]*i;
  fact[i]%=mod;
 }
}
ll nCr(ll n,ll r,ll M){
 if(n<r)return 0;
 return (((fact[n]*mi(fact[r],M))%M)*mi(fact[n-r]%M,M))%M;
}
// ll nCr(ll n,ll r){
//  ll res=1;
//  for(int i=0;i<r;i++){
//   res*=(n-i);
//  }
//  return res/fact[r];
// }
void the_happiest_place_on_earth()
{
    flash;
  #ifdef ENABLE_FILE_IO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
}
// bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
//  return (a.f<b.f||a.f==b.f&&a.s<b.s);
// }
ll mul(ll a,ll b){
 return ((a%mod)*(b%mod))%mod;
}
ll add(ll a,ll b){
 return ((a%mod)+(b%mod))%mod;
}
const int N=200040;ll a[N],b[N],c[N],dis[N],Size[N],par[N],color[N];
// int get(int a){return (a==par[a])?a:get(par[a]);}
// void Union(int a,int b){
//   a=get(a);
//   b=get(b);
//   if(a!=b){
//     if(Size[b]>Size[a]) swap(a,b);
//       par[b]=a;
//       Size[a]+=Size[b];
//   }
// }
vpll g[N];
ll dp[5005][5005];
void testcase(){
  cin>>n;
  loop1(i,n) cin>>a[i];
  ll fre[101]={0};
  loop1(i,n) fre[a[i]]++;
  int d=0,ma=0;
  loop1(i,100) if(fre[i]>ma){ma=fre[i];d=i;}
  if(fre[d]==2){cout<<n<<"\n";return;}
  ll mat[100][n+1];
  loop1(i,100){
    if(i==d||fre[i]==0) continue;
    loop1(j,n){
      if(a[j]==d) mat[i][j]=1;
      else if(a[j]==i) mat[i][j]=-1;
      else mat[i][j]=0;
    }
  }
  ans=0;
  loop1(i,100){
    if(i==d||fre[i]==0) continue;
    ll presum[n+1];
    sum=0;
    loop1(j,n){
      sum+=mat[i][j];
      if(sum==0) ans=max(ans,(ll)(j));
      else if(presum[sum]!=0) ans=max(ans,j-presum[sum]);
      else presum[sum]=j;
    }
  }
  cout<<ans;
  return;
}
int main(){
  //the_happiest_place_on_earth();
  // //Today's thought: Push yourself,because no one else is going to do it for you.
  // //Things are not always #000000 and #FFFFFF
  // //START OF PROGRAM LOGIC
  // //g++ -o a BB.cpp -DENABLE_FILE_IO;./a
  //g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a
  //F();
  q=1;//int t=0;
  //cin>>q;
  while(q--){
    //cout<<"Case #"<<++t<<": ";
    //solve();
    testcase();
  }
  // cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  // //END OF PROGRAM LOGIC

	return 0;
}
/*
######  ###### #     # ####### #     # ##### #     #    #    ####### ####### ######
#     # #      ##    # #     # ##   ##   #   ##    #   # #      #    #     # #     #
#     # #      # #   # #     # # # # #   #   # #   #  #   #     #    #     # #     #
#     # #####  #  #  # #     # #  #  #   #   #  #  # #     #    #    #     # ######
#     # #      #   # # #     # #     #   #   #   # # #######    #    #     # #   #
#     # #      #    ## #     # #     #   #   #    ## #     #    #    #     # #    #
######  ###### #     # ####### #     # ##### #     # #     #    #    ####### #     #
*/


#include<iostream>
using namespace std;
int p,a,b,a1,b1,minn=0;
int plate[1000]={0};
void dfs(int step)
{
	bool flag=false;
	if(step==p+1)
	{
		int tmp=2147483647;
		for(int i=1;i<=p;i++)
		{
			tmp=min(tmp,plate[i]);
		}
		minn=max(minn,tmp);
		return;
	}
	for(int i=1;i<=a1;i++)
	{
		flag=true;
		a1-=i;
		plate[step]=i;
		dfs(step+1);
		plate[step]=0;
		a1+=i;
	}
	for(int i=1;i<=b1;i++)
	{
		flag=true;
		b1-=i;
		plate[step]=i;
		dfs(step+1);
		plate[step]=0;
		b1+=i;
	}
	if(!flag)
	{
		return;
	}
}
int main()
{
	cin>>p>>a>>b;
	a1=a;
	b1=b;
	dfs(1);
	cout<<minn<<endl;
	return 0;
}


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

using namespace std;

vector<int>v;

int main () {
    long long int n;
    cin >> n;
    do {
        int c = n%10;
        v.push_back(c);
        n-=c;
        n/=10;
    } while ( n != 0 );
    int wsk = v.size()-1;
    while ( v[wsk] == 9 )
        wsk--;
    for ( int i = 0; i < v.size()-(v.size()-wsk); i++ )
        v[i] = min ( v[i], 9-v[i] );
    long long int wynik = 0;
    long long int p = 1;
    for ( int i = 0; i < v.size(); i++ ) {
        wynik+=v[i]*p;
        p*=10;
    }
    if ( wynik == 0 )
        wynik+=9;
    cout << wynik << endl;
}


         //Bismillahir Rahmanir Rahim
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	vector<int>v;
    int a,b,c,d,sum(0),in,ans;
    for(int i=0;i<4;i++) //3 14 36 53
    {
    	cin>>in;
    	v.push_back(in);
    	//ans += v[i];
    }

    sort(v.begin(),v.end());

    if(v[0]+v[3]==v[2]+v[1])
    {
    	cout<<"YES"<<endl;
    }
    else
    {
    	cout<<"NO"<<endl;
    }
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string t;
    string s;
    cin>>t;
    cin>>s;
    for(int i=0;i<t.length();)
    {
        for(int j=s.length()-1;j>=0;)
        {
            if(t.at(i)==s.at(j))
            {
                i++,j--;
                continue;
            }
            else
            {
                cout<<"NO\n";
                exit(j);
            }
        }
        cout<<"YES\n";
    }
    return 0;
}


//****author RKN
//DATE 5/2/2020 5.15 AM

// ***************DREAM IS NOT THAT YOU SEE WHILE SLEEPING BUT IT IS WHAT DONT LET YOU SLEEP************//

///////////////////////    machayenge......sala hoga apne se bhi ek din    ///////////////////////////////////////////////////////////

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

/////////////////////////////   %   variable  %   //////////////////////////////////////////////////////////////

#define ll long long
#define pb push_back
#define pof pop_front
#define f1 first
#define N 100001
#define M 10000001
#define s2 second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pr pair<ll,ll>
#define all(x) x.begin(),x.end()
#define loop(start,end,inc) for(int i=start;i<=end;i+=inc)
typedef std::vector<std::vector<int>> vec2d;
#define pr1 pair<ll,pair<ll,ll>>
#define prm pair<ll,map<ll,ll>>
int dir1[8]={1,-1,0,0,-1,1,-1,1};
int dir2[8]={0,0,-1,1,-1,1,1,-1};
#define en "\n"
ll MAX=1000000007;
vector<ll>prime(1001);
vector<ll>getprm;
ll power(ll a,ll b)
{
       if(b == 0)
       return 1;
       auto q= power( a, b/2 );
       q = (q * q) % MAX;
       if ( b%2 == 0)
       return q%MAX;
       else
       return (q * a) % MAX;
}

ll modinv ( ll val )
{
       return power ( val, MAX-2 );
}

void primecalc()
{
       fill(all(prime),1);
       prime[0]=0;prime[1]=0;
       for(int i=2;i<=1000;i++)
       {
              if(prime[i])
              {
                     //cout<<i<<" ";
                     getprm.pb(i);
                     for(int j=i+i;j<=1000;j+=i)
                     prime[j]=0;
              }
       }
}

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

int main()
{
    ll n,m;
    cin>>n>>m;
    unordered_map<ll,ll>mpi,mpj;
    int i=2,j=3,cnti=2,cntj=2;n--;m--;
    while(n && m)
    {
        if(i<=j)
        {
        if(mpj[cnti*2])
        {cnti++;continue;}
        i=cnti*2;mpi[i]=1;cnti++;n--;
        }
        else
        {
        if(mpi[cntj*3])
        {cntj++;continue;}
        j=cntj*3;mpj[j]=1;cntj++;m--;
        }
      //  cout<<i<<" "<<j<<endl;
    }
    while(n)
    {
        if(mpj[cnti*2])
        {cnti++;continue;}
        i=cnti*2;cnti++;n--;
    }
    while(m)
    {
        if(mpi[cntj*2])
        {cntj++;continue;}
        j=cntj*3;cntj++;m--;
    }
//    cout<<i<<" "<<j<<endl;
    cout<<max(i,j);
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long int n, m;
    cin >> n >> m;
    long long a = ( (n - m) + (n%m)*2 ) * (n/m) / 2;
    long long b = (n-m+1)*(n-m)/2;
    cout << a << ' ' << b << '\n';
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	float hour,min, h;
	char c;
	while(1){
	cin>>hour>>c>>min;
	h=hour*30+min/2;
	cout<<h<<" "<<min*6<<endl;}
	return 0;
}


/*input
1 2 1
*/

#include <bits/stdc++.h>
#define endl '\n';
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

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

const int oo = 1e9 + 7;
const int mod = 1e9 + 7;

int pw (int a,int p,int mod ) {
    int res=1%mod,x=a%mod;
    while (p) {
        if (p&1) res=(res*x)%mod;
        x=(x*x)%mod; p>>=1;
    }
    return res;
}

int C(int k, int n) {
    int a=1, b=1, c=1;
    for(int i=1;i<=n;i++) a=(a*i)%(mod);

    for(int i=1;i<=k;i++) b=(b*i)%(mod);

    for(int i=1;i<=(n-k);i++) c=(c*i)%(mod);

    b=pw(b,mod-2,mod);
    c=pw(c,mod-2,mod);
    a=(a*b)%mod;
    a=(a*c)%mod;
    return a;
}

signed main(){
	ios_base::sync_with_stdio(0);
	int f, w, h, okcnt = 0, total = 0;
	// freopen(".inp","r",stdin);
	// freopen(".out","w",stdout);
	cin >> f >> w >> h; ++h;
	int iw = w / h;
	if(!w){
		if(f <= 1) cout << 1;
		else cout << 0;
		return 0;
	}

	for(int i=1;i<=iw;i++){
		int n = w - i * h;
		int add = C(i - 1,n + i - 1);
		int mul = 0;
		if(f >= i - 1 && i > 1) mul += C(i - 2, f - 1);
		if(f >= i) mul += 2 * C(i - 1, f - 1);
		if(f >= i + 1) mul += C(i, f - 1);
		mul %= mod;
		okcnt = (okcnt + add * mul) % mod;
	}
	for(int i=1;i<=w;i++){
		int n = w - i;
		int add = C(i - 1,n + i - 1);
		int mul = 0;
		if(f >= i - 1 && i > 1) mul += C(i - 2, f - 1);
		if(f >= i) mul += 2 * C(i - 1, f - 1);
		if(f >= i + 1) mul += C(i, f - 1);
		mul %= mod;
		total = (total + (add * mul)) % mod;
	}

	cout << okcnt * pw(total, mod - 2ll, mod) % mod;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long s3[1000]={0},n,m,k=0,l=0,s1=1;
double i,p;
int main () {
    cin>>n>>m>>s1>>k;
    p=m;
while (abs(l-m)>n){
    i++;
    l=l+s1;
    m=m-k;
}
p=(p-n)/((s1+k));
cout<<fixed<<setprecision(10)<<p;
return 0;
}


#include <bits/stdc++.h>
#define INF 0x3F3F3F3F
using namespace std;
/*
int main()
{
    int cases,max,num,num2,res=0;
    cin>>cases>>max;
    cin>>num;
    for(int i=1; i<cases;i++)
    {
        cin>>num2;
        if(abs(num-num2)>max) res++;
        else num=num2;
    }
    cout<<res<<endl;
    return 0;
}*/
int n,k,a,b;
bool visited[100000];
int val[100000];
int DP(int num)
{
    if(num==1) return 0;
    int &best = val[num];
    if (visited[num]) return best;
    visited[num] = true;
    if(num%k==0) return min(DP(num-1)+a,DP(num/k)+b);
    else return DP(num-1)+a;
}
int main()
{
    cin>>n>>k>>a>>b;
    if(n==1)
        cout<<min(a,b)<<endl;
    else
        cout<<DP(n)<<endl;
    return 0;
}
///FASTINPUT
/*
inline int getchar_unlocked() { return getchar(); }
inline void fastInput(int &n){
    char ch;
    int sign = 1;
    while(ch = getchar_unlocked(), isspace(ch)) {

    };
    n = 0;
    if(ch == '-')
        sign = -1;
    else n = ch - '0';
    while(ch = getchar_unlocked(), isdigit(ch))
        n = (n << 3) + (n << 1) + ch - '0';
    n *= sign;
}
*/
    //freopen("C:/Users/Isaac/Desktop/in.txt","r",stdin);
    //freopen("C:/Users/Isaac/Desktop/out.txt","w",stdout);


#include <bits/stdc++.h>

using namespace std;

int main(){

   char tableCard[2];
   cin>>tableCard[0]>> tableCard[1];
   char tempCard[2];
   int i=0;

   while(i<5){
        cin>> tempCard[0] >>tempCard[1];

        if(tempCard[0] == tableCard[0] || tempCard[1] == tableCard[1]){
           cout << "YES";
        }
   }

   if(i<5){
       cout << "NO";
   }

   return 0;
}


#include <bits/stdc++.h>
using namespace std;
char a[20][50],b[20][40];
string d[20];
int s1[20],s2[20],num[20];
map <string,int> M;
int id;
char boss[]="BERLAND";
int score[10];
int gol[10],mis[10];

bool ok(int y,int x){

	set <int> st;
	for(int i=1;i<=4;i++) st.insert(i);
	st.erase(id);
	// score
	int nn=0;
	for(int i=1;i<=4;i++) {
		if(i==id) continue;
		if(score[id]>score[i]) nn++,st.erase(i);
	}
	if(nn>=2) return 1;

	int mm=0;
	for(int i=1;i<=4;i++) {
		if(i==id) continue;
		if(score[id]<score[i]) mm++,st.erase(i);
	}
	if(mm>=2) return 0;
	// delta
	if(mm==1){
		auto it=st.begin();
		while(it!=st.end()){
			if(gol[*it]-mis[*it]>gol[id]-mis[id]) return 0;
			if(gol[*it]-mis[*it]<gol[id]-mis[id]) {
				st.erase(it);
				if(st.empty()) return 1;
				it=st.begin();
			}
			else it++;
		}
		if(st.empty()) return 1;
		it=st.begin();
		while(it!=st.end()){
			if(gol[*it]>gol[id]) return 0;
			if(gol[*it]<gol[id]) {
				st.erase(it);
				if(st.empty()) return 1;
				it=st.begin();
			}
			else it++;
		}
		if(st.empty()) return 1;
		it=st.begin();
		while(it!=st.end()){
			if(st.empty()) return 1;
			auto it=st.begin();
			if(*it<id) return 0;
			if(*it>id) {
				st.erase(it);
				if(st.empty()) return 1;
				it=st.begin();
			}
			else it++;
		}
	}

	int N=0;
	auto it=st.begin();
	while(it!=st.end()){
		if(st.empty()) return 1;
		if(gol[*it]-mis[*it]>gol[id]-mis[id]) {
			if(N) return 0;
			st.erase(it);
			N++;
			if(st.empty()) return 1;
			it=st.begin();
			continue;
		}
		if(gol[*it]-mis[*it]<gol[id]-mis[id]) {
			st.erase(it);
			if(st.empty()) return 1;
			it=st.begin();
		}
		else it++;
	}
	it=st.begin();
	while(it!=st.end()){
		if(st.empty()) return 1;
		if(gol[*it]>gol[id]) {
			if(N) return 0;
			st.erase(it);
			N++;
			if(st.empty()) return 1;
			it=st.begin();
			continue;
		}
		if(gol[*it]<gol[id]) {
			st.erase(it);
			if(st.empty()) return 1;
			it=st.begin();
		}
		else it++;
	}
	it=st.begin();
	while(it!=st.end()){
		if(st.empty()) return 1;
		auto it=st.begin();
		if(*it<id) {
			if(N) return 0;
			N++;
			st.erase(it);
			if(st.empty()) return 1;
			it=st.begin();
			continue;
		}
		if(*it<id) st.erase(it);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	for(int i=1;i<=5;i++){
		scanf("%s %s %d:%d",a+i,b+i,s1+i,s2+i);
//		cerr<<s1[i]<<' '<<s2[i]<<endl;
		d[i*2-1]=a[i];
		d[i*2]=b[i];
	}
	int cnt=10;
	sort(d+1,d+cnt+1);
	cnt=unique(d+1,d+cnt+1)-d-1;
	for(int i=1;i<=cnt;i++) M[d[i]]=i;
	id=M[boss];
	for(int i=1;i<=5;i++){
		num[M[a[i]]]++;
		num[M[b[i]]]++;
		if(s1[i]>s2[i]){
			score[M[a[i]]]+=3;
		}
		else if(s1[i]<s2[i]){
			score[M[b[i]]]+=3;
		}
		else {
			score[M[b[i]]]++;
			score[M[a[i]]]++;
		}
		gol[M[a[i]]]+=s1[i];
		mis[M[a[i]]]+=s2[i];
		gol[M[b[i]]]+=s2[i];
		mis[M[b[i]]]+=s1[i];
	}
	int ppp;
	for(int i=1;i<=4;i++){
		if(i==id) continue;
		if(num[i]<3) ppp=i;
	}
	int fl=1;
	int del=1000;
	int ansx=1000,ansy=1000;
	score[id]+=3;
	for(int i=0;i<300;i++){
		for(int j=i+1;j<=300;j++){
			gol[id]+=j;gol[ppp]+=i;
			mis[id]+=i;mis[ppp]+=j;

			if(ok(i,j)){
				fl=0;
				if(del>j-i){
					del=j-i;
					ansx=j;ansy=i;
				}
			}
			gol[id]-=j;gol[ppp]-=i;
			mis[id]-=i;mis[ppp]-=j;
		}
	}
	if(fl) puts("IMPOSSIBLE");
	else printf("%d:%d\n",ansx,ansy);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
    int64_t n, k, y, p = 0;
    vector <int64_t> a;
    int64_t *t = new int64_t;
    cin >> n >> k;
    for (y = 0; y < n; ++y) {
        cin >> *t;
        if (*t <= k)
            a.push_back(*t);
    } delete t;
    sort(a.begin(), a.end());
    if (k == 0) {
        if (a.size() == 0 || a[0] != 0)
            cout << k << endl;
        else if (a[0] == 0)
            cout << k + 1 << endl;
        return 0;
    } if (a[0] != 0) {
        if (k == 0) {
            cout << k << endl;
            return 0;
        }else if (a.size() > 1) {
            if (k >= 0 && k <= a[1]) {
                cout << k - 1 << endl;
                return 0;
            }else {
                p += a[1];
            }
        }else if (a.size() == 1) {
            if (k < a[0]) {
                cout << k - 1 << endl;
            }else if (k == a[0]) {
                cout << k << endl;
            }else {
                cout << k - 1 << endl;
            } return 0;
        }
    } for (y = 1; y < a.size() - 1; ++y) {
        if (a[y] == k) {
            cout << p + 1 << endl;
            return 0;
        }
        if (a[y] != a[y + 1] - 1) {
            if (k >= a[y] && k <= a[y + 1]) {
                cout << k - a[y] - 1 << endl;
                return 0;
            }else {
                p += a[y + 1] - a[y] - 1;
            }
        }
    } if (k > a[a.size() - 1])
        cout << k - a[a.size() - 1] - 1 << endl;
    else if (k == a[a.size() - 1])
        cout << p + 1 << endl;
    return 0;
}


#include<bits/stdc++.h>
#include<set>
#include<iostream>
using namespace std;
   typedef vector< int > vi;
   typedef vector< vi > vvi;
   typedef pair<int, int> pairs;
int main()
{

    vvi Tablero; // En este tablero guardamos los cuadros coloreados
    set<pairs> s;
    vector<pairs> v;
    int n,x,y,c,segundos,i;
    segundos=0;
    cin>>n>>x>>y>>c;
    pairs a1 = make_pair(x, y);
    s.insert(a1);
    vvi k(n, vi(n)); // (nxn)
        while(s.size()<c )
        {
            i=0;
         for (auto elem : s)
	    {
		v.push_back(make_pair(elem.first,elem.second));

	    }

        for(int j=0;j<v.size();j++){

         //   cout<<v[j].first<<v[j].second<<"Este es el "<<j+1<<"\n";
           if(v[j].first+1<=n)
            {
            s.insert(make_pair(v[j].first+1,v[j].second));}

            if(v[j].first-1>=1)
            {
	        s.insert(make_pair(v[j].first-1,v[j].second));}
	          if(v[j].second+1<=n){
	        s.insert(make_pair(v[j].first,v[j].second+1));
	          }
	       if(v[j].second-1>=1)

            { s.insert(make_pair(v[j].first,v[j].second-1));}
	        }

	    v.clear();
        //cout<<s.size()<<" "<<segundos<<"\n";
        segundos+=1;
        }
    cout<<segundos;
return 0;
}


#include<cstdio>
#include<cstring>
#ifndef ONLINE_JUDGE
const int maxn = 10;
#else
const int maxn = 3*100000+10;
#endif
int u[maxn*2],v[maxn*2],head[maxn],next[maxn];
int out[maxn];
int n,m;
void dfs(int x)
{
	int c0 = 0;
	for(int i = head[x]; i != -1; i = next[i])
	{
		if(out[v[i]] == out[x] ) c0++;
	}
	if(c0 > 1)
	{
		out[x] ^= 1;
		for(int i = head[x]; i!=-1; i = next[i])
			dfs(v[i]);
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	memset(head,-1,sizeof(head));
	for(int i = 0 ; i < m; i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		next[i] = head[u[i]], head[u[i]] = i;
		u[i+n] = v[i], v[i+n] = u[i];
		next[i+n] = head[v[i]] , head[v[i]] = i+n;
	}

	memset(out,0,sizeof(out));
	for(int i = 1; i <= n; i++)
		dfs(i);
	for(int i = 1; i <= n; i++)
		printf("%d",out[i]);
	return 0;
}


#include <iostream>
#include<cmath>
#include <sstream>
using namespace std;
long long int val[10]={6,2,5,5,4,5,6,3,7,6};
long long int ans=0;
void func(string str)
{
    for(int i=0;i<str.length();i++)
    {
        ans+=val[str[i]-'0'];
        //cout<<str[i]<<" "<<val[str[i]-'0']<<endl;
    }
}
int main()
{
    long long int a,b;
    std::string str;
    std::stringstream out;
    cin>>a>>b;
    for(long long int i=a;i<=b;i++)
    {
        //str="";
        //cout<<i<<endl;
        out << i;
        str = out.str();
    }
    func(str);
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define sz(a) (int)a.size()

using namespace std;
using ll = long long;

const int N = 7002;

int n;
ll a[N], b[N];
bool chk[N];
set<int> ad[N];

int main() {
    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)
        for (int j = 1; j <= n; ++j) {
            ll tmp = a[i] & a[j];
            if (a[i] > tmp) ad[i].insert(j);
        }
    int cur = n;
    while (true) {
        vector<int> v;
        v.clear();
        for (int i = 1; i <= n; ++i) if (!chk[i])
            if (sz(ad[i]) == cur - 1)
                v.push_back(i);
        if (v.empty()) break;
        for (int u : v) chk[u] = true, --cur;
        for (int i = 1; i <= n; ++i) if (!chk[i]) {
            for (int u : v) {
                set<int>::iterator it = ad[i].find(u);
                if (it != ad[i].end()) ad[i].erase(it);
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) if (!chk[i]) ans += b[i];
    cout << ans << "\n";
    return 0;
}


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

int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    int candies[4];
    int sum=0;
    bool exist=false;
    int maxv=0;
    for(int i=0;i<4;i++){
        cin>>candies[i];
        sum+=candies[i];
        if(maxv<candies[i]) maxv=candies[i];
    }
    if(sum%2==0){
    if(sum-maxv==sum/2) exist=true;
    for(int i=1;i<3;i++){
        if(candies[0]+candies[i]==sum/2) exist=true;
    }
    }
    if(exist) cout<<"YES";
    else cout<<"NO";
    return 0 ;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REV(i,a,b) for(int i=(a);i>=(b);i--)
#define mp make_pair
#define pb push_back
#define oo 1e9
#define eps 1e-9
#define PI 3.14159265358979323846264338327950
#define MAX 2001
#define sz(v) (int)v.size()
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define mem(s,v) memset(s,v,sizeof(s))
#define ppc(x) __builtin_popcount((x))
#define iter(it,s) for (__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
struct line {
	int x1, y1, x2, y2;
};
int main() {
#ifndef ONLINE_JUDGE
	freopen("test.in", "rt", stdin);
	//	freopen("o.txt", "wt", stdout);
#endif
	ios::sync_with_stdio(false);
	vector<line> x(2), y(2);
	int x1, y1, x2, y2, lenX = -1, lenY = -1, l, lx = 0, ly = 0;

	FOR(i , 0 , 4)
	{
		cin >> x1 >> y1 >> x2 >> y2;
		if ((x1 != x2 && y1 != y2) || (x1 == x2 && y1 == y2)) {
			cout << "NO" << endl;
			return 0;
		}
		x1 == x2 ? l = abs(y1 - y2) : l = abs(x1 - x2);
		if (lenX == -1 && x1 == x2)
			lenX = l;
		if (lenY == -1 && y1 == y2)
			lenY = l;
		if (x1 == x2 && l != lenX) {
			cout << "NO" << endl;
			return 0;
		}
		if (y1 == y2 && l != lenY) {
			cout << "NO" << endl;
			return 0;
		}
		line ln = { x1, y1, x2, y2 };
		x1 == x2 ? x[lx++] = ln : y[ly++] = ln;
	}
	bool gd = true;
	FOR(i , 0 , 2)
	{
		int cnt = 0;
		FOR(j , 0 , 2)
		{
			if (x[i].x1 == y[j].x1 && x[i].y1 == x[i].y1)
				cnt++;
			if (x[i].x1 == y[j].x2 && x[i].y1 == x[i].y2)
				cnt++;
			if (x[i].x2 == y[j].x1 && x[i].y2 == x[i].y1)
				cnt++;
			if (x[i].x2 == y[j].x2 && x[i].y2 == x[i].y2)
				cnt++;
		}
		if (cnt != 2)
			gd = false;
	}
	if (x[0].x1 == x[1].x1 && x[0].y1 == x[1].y1)
		gd = false;

	if (x[0].x1 == x[1].x2 && x[0].y1 == x[1].y2)
		gd = false;

	if (x[0].x2 == x[1].x1 && x[0].y2 == x[1].y1)
		gd = false;

	if (x[0].x2 == x[1].x2 && x[0].y2 == x[1].y2)
		gd = false;

	if (y[0].x1 == y[1].x1 && y[0].y1 == y[1].y1)
		gd = false;

	if (y[0].x1 == y[1].x2 && y[0].y1 == y[1].y2)
		gd = false;

	if (y[0].x2 == y[1].x1 && y[0].y2 == y[1].y1)
		gd = false;

	if (y[0].x2 == y[1].x2 && y[0].y2 == y[1].y2)
		gd = false;
	gd ? cout << "YES" : cout << "NO";

	return 0;
}


#include <iostream>
using namespace std;

int main(){
   char m[9];
   for(int i=0;i<9;i++)
    cin>>m[i];
    for(int i=0;i<4;i++)
        if(m[i] != m[8-i]){
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<"YES"<<endl;
        return 1;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i=0; i<n; i++)cin  >> arr[i];
    sort(arr, arr+n);
    int d=arr[n-1]-arr[0];
    while(d%2==0)
    {
        d=d/2;
    }
    bool c=0;
    for(int i=0; i<n-1; i++)
    {
        if((arr[n-1]-arr[i])%d!=0)
        {
            cout << -1;
            c=1;
            break;
        }
    }
    if(c==0)cout << d;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long i,j,k,l,m,n,p;//,arr[1000];
    unsigned long long l1,r1,l2,r2;
    cin>>l1>>r1>>l2>>r2>>k;
    if(l2>r1||l1>r2){cout<<0;return 0;}
    if(l1<=l2&&r2<=r1){
        if(k>=l2&&r2>=k)
        {
            cout<<r2-l2;return 0;
        }
        cout<<r2-l2+1;return 0;
    }
    if(l1<=l2&&r2>=r1)
    {
        if(l2<=k&&r1>=k)
        {
            cout<<r1-l2;return 0;
        }
        cout<<r1-l2+1;return 0;
    }
    if(l>=l2&&r2<=r1)
    {
        if(l1<=k&&r2>=k)
        {
            cout<<r2-l1;return 0;
        }
        cout<<r2-l1+1;return 0;
    }
    if(l2<=l1&&r1<=r2)
    {
        if(l1<=k&&r1>=k)
        {
            cout<<r1-l1;return 0;
        }cout<<r1-l1+1;return 0;
    }

}


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

int power(int a,int b){
    int res=1;a%=M;
    while(b){
        if(b&1)res=res*a%M;
        a=a*a%M;b>>=1;
    }
    return res;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,m,k;
    cin>>n>>m>>k;
    m = power(m,M-2);
    vector<int> fact(k+1,1);
    for(int i=1;i<=k;++i)
        fact[i]=i*fact[i-1]%M;
    auto ncd = [&](int d){
        if(n<d)return 0LL;
        int res=1;
        for(int i=n;i>=n-d+1;--i){
            res = res*i%M;
        }
        return res*power(fact[d],M-2)%M;
    };
    auto dci = [&](int i,int d){
        return fact[d]*power(fact[d-i]*fact[i]%M,M-2)%M;
    };
    auto ways = [&](int d){
        int res=0;
        int cnt = 1;
        for(int i=d;i>=0;--i){
            res = (res+cnt*power(i,k)%M*dci(i,d)%M+M)%M;
            cnt = -cnt;
        }
        return res;
    };
    int ans=0;
    for(int d=1;d<=k;++d){
        int tmp = power(m,d)*ncd(d)%M;
        tmp = (tmp*ways(d)%M);
        ans =(ans+tmp+M)%M;
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long LL;
const int mod = 1e9 + 7;

template<typename T> T gcd(T a,T b) { if(a==0) return 0; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N = 1e4+5;

int32_t main(){
    IOS;

    int h[2],m[2];

    for(int i=0;i<2;i++)
        scanf("%d:%d", h[i],m[i]);

    h[0]-=h[1];
    m[0]-=m[1];

    if(m[0]<0)
        m[0]+=60;

    if(h[0]<0)
        h[0]+=24;

    printf("%02d:%02d", h[0], m[0]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define lli long long int
lli num[5]={1,2,3,4,5},n,arr[5],combinations[150][10],totalCombination = 0,grid[10][10];
bool visited[5] = {false};
void build(lli pos)
{
	lli i,j,k,l;
	if(pos>=n)
	{
		// cout<<"combination "<<endl;
		for(i=0;i<n;i++)
		{
			// cout<<arr[i]<<" ";
			combinations[totalCombination][i] = arr[i];
		}
		totalCombination++;
		// cout<<endl<<" totalCombination : "<<totalCombination<<endl;
		return;
	}

	for(i=0;i<n;i++)
	{
		if(!visited[i])
		{
			visited[i] = true;
			arr[pos] = num[i];
			build(pos+1);
			visited[i] = false;
		}
	}
}
lli getScore(lli arr[])
{
	lli i,j,k,l,m,score=0;
	/*cout<<"Calculating score for "<<endl;
	for(i=0;i<5;i++)
		cout<<arr[i]<<" ";
	cout<<endl;*/

	for(i=0;i<5;i++)
	{
		for(j=i;j<4;j+=2)
		{
			lli st1 = arr[j], st2 = arr[j+1];
			score += (grid[st1][st2] + grid[st2][st1]);
			// cout<<"calculating score for "<<st1<<" "<<st2<<endl;
		}
	}
	return score;
}
int main()
{
	lli i,j,k,l,m,a,b,c,d,x,y,z,p,q,targetedFreq,score;
	n = 5;
	build(0);
	/*cout<<"combinations "<<endl;
	for(i=0;i<totalCombination;i++)
	{
		for(j=0;j<5;j++)
			cout<<combinations[i][j]<<" ";
		cout<<endl;
	}*/
	while(true)
	{
		for(i=1;i<=5;i++)
			for(j=1;j<=5;j++)
				cin>>grid[i][j];
		lli maxScore = 0;
		for(i=0;i<totalCombination;i++)
		{
			score = getScore(combinations[i]);
			// cout<<"score : "<<score<<endl;
			maxScore = max(maxScore,score);
		}
		cout<<maxScore<<endl;

	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<stack>
using namespace std;
#define MAXN 1010
#define MAXM 11
#define INF 1000000000
#define MOD 1000000007
#define eps 1e-8
#define ll long long
ll f[MAXN][MAXM][MAXN];
ll ine[MAXM];
int n,d;
ll mod;
ll ans=0;
ll C(ll x,ll y){
	ll re=1;
	int i;
	for(i=x-y+1;i<=x;i++){
		(re*=i%mod)%=mod;
	}
	for(i=1;i<=y;i++){
		(re*=ine[i])%=mod;
	}
	return re;
}
int main(){
	int i,j,k,l;
	scanf("%d%d%lld",&n,&d,&mod);
	if(n<=2){
		printf("1\n");
		return 0;
	}
	ine[0]=ine[1]=1;
	for(i=2;i<=10;i++){
		ine[i]=(mod-mod/i)*ine[mod%i]%mod;
	}
	for(i=0;i<=n;i++){
		f[1][0][i]=1;
		f[1][d-1][i]=1;
	}
	for(i=2;i<=n;i++){
		for(j=1;j<=d&&j<i;j++){
			for(k=1;k<=n;k++){
				for(l=0;l<=j&&l*k<i;l++){
					(f[i][j][k]+=f[i-l*k][j-l][k-1]*C(f[k][d-1][k-1]+l-1,l)%mod)%=mod;
				}
			}
		}
	}
	if(n&1){
		ans=f[n][d][n/2];
	}else{
		ans=(f[n][d][n/2-1]+C(f[n/2][d-1][n/2-1]+1,2))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

/*
180 3 434448163

*/


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 998244353;

ll pow(ll a, ll b, ll mod) {
	if (b == 0) return 1;
	if (b == 1) return a % mod;
	a %= mod;
	if (!(b & 1)) return pow((a * a) % mod, b >> 1, mod) % mod;
	if (b & 1) return a * pow(a, b - 1, mod) % mod;
	return 1;
}
ll inv(int i) {
	return pow(i, mod - 2, mod) % mod;
}

int main() {
	int n, m;
	cin >> n >> m;
	ll res = m + 1;
	for (int i = 2; i <= n; i++) {
		ll tmp = m * inv(i);
		tmp %= mod;
		res  += tmp;
		res %= mod;
	}
	ll tmp = n * inv(m + 1);
	tmp %= mod;
	tmp++;
	res *= tmp;
	res %= mod;
	res = (res + mod) % mod;
	cout << res << endl;
	return 0;
}


#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<windows.h>
#define pi acos(-1)
#define E 2.71828
#define mp make_pair
#define pb push_back
#define sz(s) s.length()
#define sb substr
#define mi(x) memset((int)(x),0,sizeof((x)))
#define ms(x) memset((string)(x),"",sizeof(x))
#define mc(x) memset((char)(x),'\0',sizeof(x))
#define for0(i,n) for(int i=0;i<(int)(n);i++)
#define maxn 1e9
#define eps 1e-9
#define eightqueen 92
#define cint %d
#define clong %lld
#define cchar %c
#define cstring %s
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
struct wint:vector<int>
{
    wint(int n=0)
    {
        push_back(n);
        check();
    }
    wint& check()
    {
        while(!empty()&&!back())pop_back();
        if(empty())return *this;
        for(int i=1; i<size(); ++i)
        {
            (*this)[i]+=(*this)[i-1]/10;
            (*this)[i-1]%=10;
        }
        while(back()>=10)
        {
            push_back(back()/10);
            (*this)[size()-2]%=10;
        }
        return *this;
    }
};
istream& operator>>(istream &is,wint &n)
{
    string s;
    is>>s;
    n.clear();
    for(int i=s.size()-1; i>=0; --i)n.push_back(s[i]-'0');
    return is;
}
ostream& operator<<(ostream &os,const wint &n)
{
    if(n.empty())os<<0;
    for(int i=n.size()-1; i>=0; --i)os<<n[i];
    return os;
}
bool operator!=(const wint &a,const wint &b)
{
    if(a.size()!=b.size())return 1;
    for(int i=a.size()-1; i>=0; --i)
        if(a[i]!=b[i])return 1;
    return 0;
}
bool operator==(const wint &a,const wint &b)
{
    return !(a!=b);
}
bool operator<(const wint &a,const wint &b)
{
    if(a.size()!=b.size())return a.size()<b.size();
    for(int i=a.size()-1; i>=0; --i)
        if(a[i]!=b[i])return a[i]<b[i];
    return 0;
}
bool operator>(const wint &a,const wint &b)
{
    return b<a;
}
bool operator<=(const wint &a,const wint &b)
{
    return !(a>b);
}
bool operator>=(const wint &a,const wint &b)
{
    return !(a<b);
}
wint& operator+=(wint &a,const wint &b)
{
    if(a.size()<b.size())a.resize(b.size());
    for(int i=0; i!=b.size(); ++i)a[i]+=b[i];
    return a.check();
}
wint operator+(wint a,const wint &b)
{
    return a+=b;
}
wint& operator-=(wint &a,wint b)
{
    if(a<b)swap(a,b);
    for(int i=0; i!=b.size(); a[i]-=b[i],++i)
        if(a[i]<b[i])
        {
            int j=i+1;
            while(!a[j])++j;
            while(j>i)
            {
                --a[j];
                a[--j]+=10;
            }
        }
    return a.check();
}
wint operator-(wint a,const wint &b)
{
    return a-=b;
}
wint operator*(const wint &a,const wint &b)
{
    wint n;
    n.assign(a.size()+b.size()-1,0);
    for(int i=0; i!=a.size(); ++i)
        for(int j=0; j!=b.size(); ++j)
            n[i+j]+=a[i]*b[j];
    return n.check();
}
wint& operator*=(wint &a,const wint &b)
{
    return a=a*b;
}
wint divmod(wint &a,const wint &b)
{
    wint ans;
    for(int t=a.size()-b.size(); a>=b; --t)
    {
        wint d;
        d.assign(t+1,0);
        d.back()=1;
        wint c=b*d;
        while(a>=c)
        {
            a-=c;
            ans+=d;
        }
    }
    return ans;
}
wint operator/(wint a,const wint &b)
{
    return divmod(a,b);
}
wint& operator/=(wint &a,const wint &b)
{
    return a=a/b;
}
wint& operator%=(wint &a,const wint &b)
{
    divmod(a,b);
    return a;
}
wint operator%(wint a,const wint &b)
{
    return a%=b;
}
wint pow(const wint &n,const wint &k)
{
    if(k.empty())return 1;
    if(k==2)return n*n;
    if(k.back()%2)return n*pow(n,k-1);
    return pow(pow(n,k/2),2);
}
int absi(int x)
{
	if(x>=0)
		return x;
	return -x;
}
double pod(double x,double n)
{
	for(int i=0;i<n;i++)
		x*=x;
	return x;
}
int main(int argc,char **argv)
{
	string s,t;
	ll num[10],mini=0x3f3f3f3f;
	cin>>s>>t;
	for0(i,sz(s))
	{
		ll ex=(ll)(s[i]-'0');
		num[ex]++;
		if(ex==true&&ex<mini)
		mini=ex;
	}
	string kkk="";
	if(mini!=0x3f3f3f3f)
	{
		kkk+=(char)(mini+'0');
		num[mini]--;
	}
	for0(i,10)
		while(num[i]>0)
		{
			kkk+=(char)(i+'0');
			num[i]--;
		}
		cout<<(kkk==t?"OK":"WRONG_ANSWER");
	return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> visited(n,0);
	int num1=m;
	int num2=m;
	int x=0;
	int y=n-1;
	while(num1>0){
		visited[x]=1;
		visited[y]=1;
		x++;
		y--;
		num1--;
	}
	int count=0;
	for(int i=0;i<n;i++){
		if(visited[i]==0){
			count++;
		}
	}
	for(int i=0;i<n;i++){
		visited[i]=0;
	}
	int a = 0;
	int b = 1;
	while(num2>0){
		visited[a]=1;
		visited[b]=1;
		num2--;
		a++;
		b++;
	}
	int count2=0;
	for(int i=0;i<n;i++){
		if(visited[i]==0){
			count2++;
		}
	}
	cout << count << ' ' << count2;
	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<math.h>
#include<iomanip>

using namespace std ;

int main ()
{
    long long n , m , k , x , y , i , j , l , maxi = 0 , mini = 0 , sergei = 0 , b ;
    cin >> n >> m >> k >> x >> y ;
    l = k - m*n , i = l / ((n-1)*m) , j = l % ((n-1)*m) , b = k % (m*n);

    if (m*n == k){mini = maxi = sergei = 1 ;}

    else if (m*n > k){mini = 0 , maxi = 1 ;
    if (m*(x-1)+y >= b){sergei = 1;}}

    else if (m*n < k && k < m*n*2-m-1){maxi = 2 , mini = sergei = 1;
    if (m*(n-x-1)+y >= b){sergei += 1;}}

    else {
        if (i % 2 != 0 && j == 0){maxi = i + 1 , mini = maxi / 2 ;
        if (x == 1){sergei = mini + 1;}else if (x == n){sergei = mini ;}else {sergei = maxi;}}

        else if (i % 2 != 0 && j != 0){
                maxi = i + 1 , mini = maxi / 2 ;
            if (j <= m){if (x == 1 && y <= j){sergei = mini * 2;}}
            else if (j-(m*(n-1)) > 0 && j-(m*(n-1)) <= m){
                if (y <= j-(m*(n-1)) && x == n){sergei = mini +1 ;}
                if (j-(m*(n-1)) == m){mini += 1;}}
            else if (j > m && j < (n-1)*m+1 ){
                if((x-1)*m+y <= j){sergei = maxi + 1;}maxi += 1;}}
        else if (i % 2 == 0 && j == 0){maxi = i + 1 , mini = maxi / 2 + 1;
            if (x == 1 || x == n){sergei = mini ;}else{sergei = maxi ;}}

        else if (i % 2 == 0 && j != 0){maxi = i + 1 , mini = maxi / 2 + 1 ;
            if (j <= m){if (x == n && y >= j){sergei = mini + 1;}}
            else if (j-(m*(n-1)) > 0 && j-(m*(n-1)) <= m){
                if (y <= j-(m*(n-1)) && x == 1){sergei = mini +1 ;}
                if (j-(m*(n-1)) == m){mini += 1;}}
            else if (j > m && j < (n-1)*m+1 ){
                if((n-x-1)*m+y <= j){sergei = maxi + 1;}maxi += 1;}}
        }

    cout << maxi << " " << mini << " " << sergei ;

}


// Codeforces Task 1096G - Lucky Tickets

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

// return a % b (positive value)
ll mod(ll a, ll m) {
	return ((a % m) + m) % m;
}

// returns d = gcd(a,b); finds x,y such that d = ax + by
int extended_euclid(int a, int b, int &x, int &y) {
	int xx = y = 0;
	int yy = x = 1;
	while(b) {
		int q = a / b;
		int t = b;
		b = a % b;
		a = t;
		t = xx;
		xx = x - q * xx;
		x = t;
		t = yy;
		yy = y - q * yy;
		y = t;
	}
	return a;
}

// computes b such that ab = 1 (mod n), returns -1 on failure
int mod_inverse(int a, int n) {
	int x, y;
	int d = extended_euclid(a, n, x, y);
	if(d > 1) return -1;
	return mod(x, n);
}

// return a^b mod m
ll powmod(ll a, ll b, ll m) {
	ll res = 1;
	while(b > 0)
		if(b & 1)
			res = (res * a) % m, --b;
		else
			a = (a * a) % m, b >>= 1;
	return res % m;
}

const int MOD = 998244353;
const int root = 565042129;
const int root_1 = 950391366;
const int root_pw = 1 << 20;

void fft(vector<int> & a, bool invert) {
	int n = a.size();

	for(int i = 1, j = 0; i < n; i++) {
		int bit = n >> 1;
		for(; j & bit; bit >>= 1)
			j ^= bit;
		j ^= bit;

		if(i < j)
			swap(a[i], a[j]);
	}

	for(int len = 2; len <= n; len <<= 1) {
		int wlen = invert ? root_1 : root;
		for(int i = len; i < root_pw; i <<= 1)
			wlen = (int)(1LL * wlen * wlen % MOD);

		for(int i = 0; i < n; i += len) {
			int w = 1;
			for(int j = 0; j < len / 2; j++) {
				int u = a[i + j], v = (int)(1LL * a[i + j + len / 2] * w % MOD);
				a[i + j] = u + v < MOD ? u + v : u + v - MOD;
				a[i + j + len / 2] = u - v >= 0 ? u - v : u - v + MOD;
				w = (int)(1LL * w * wlen % MOD);
			}
		}
	}

	if(invert) {
		int n_1 = mod_inverse(n, MOD); // modular inverse
		for(int & x : a)
			x = (int)(1LL * x * n_1 % MOD);
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	int n, k;
	cin >> n >> k;
	vector <int> f(m, 0);

	for(int i = 0; i < k; ++i) {
		int d;
		cin >> d;
		f[d]++;
	}
	n /= 2;

	fft(f, false);

	for(int i = 0; i < m; ++i) {
		f[i] = powmod(f[i], n, 998244353);
	}
	fft(f, true);
	ll result = 0;
	for(auto x : f) {
		result += ((ll)x) * x;
		result %= 998244353;
	}
	cout << result << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define done cin.tie(0);std::ios::sync_with_stdio(false);
#define forit(i, a) for ( __typeof( (a).begin() ) i = (a).begin(); i != (a).end(); i++ )
#define mp make_pair
#define pb push_back
#define clr(a,n) memset(a,n,sizeof(a))
#define all(c) c.begin(), c.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i, n) for(int i=n-1;i>=0;i--)
#define popone(a) __builtin_popcount(a)
#define popzero(a) __builtin_ctz(a)
#define PI = 2.0*acos(0.0)
#define mod 1000000007
#define pi 3.14159265359
//ll gcd (ll x,ll y){if(y==0)return x;return gcd(y,x%y);}
//ll lcm(ll a,ll b){return a/gcd(a,b) * b;}
//bool power2(int x){return (x && !(x & (x - 1)));}
//ll largest_power(ll n){n = n| (n>>1);n= n| (n>>2);n = n| (n>>4);n = n| (n>>8);return (n+1)>>1;}
//bool cmp(pair<int,int>x,pair<int,int>y)
//{if (x.second==y.second) return x.first<y.first;return x.second>y.second;}
//int dx[] = {-1, -1, 1, 1, -2, -2, 2, 2 };
//int dy[] = {2, -2, 2, -2, 1, -1, 1, -1 };
//int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
//int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
//int dx[]= {1, -1, 0, 0};
//int dy[]= {0, 0, 1, -1};
vector<ll>vec;
ll n,k;
void solve()
{
    for(ll i=1;i<=1e9;i++)
        vec.pb(k*i);
}
int main()
{
    done
    cin>>n>>k;
    solve();
    cout<<*upper_bound(all(vec),n)<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
char str[110];
int main(){
	cin>>n>>str;
	int t=n;
	vector<int>v;
	while(t>0){
		v.push_back(t);
		t=((t+1)/2);
	}
	reverse(v.begin(), v.end());
	for(int t:v){
		reverse(str,str+t);
	}
	printf("%s",str);
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long long int s=0,n;
    cin>>n;
    for(long long int i=n;i>0;i-=2)
    {
        if(i==n)
            s+=n;
        else
            s=s+2*i;
    }
    if(s%2==0)
        cout<<2;
    else
        cout<<1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()

{
    int n,m;

    cin>>n>>m;

    int ans=n,temp;

    while(temp!=1)
    {
        temp=(n/m);

        ans+=temp;

        m+=m;
    }

    cout << ans << endl;

    return 0;
}


//#include<stdio.h>
//#include<stdlib.h>
//
//#define LIST_INIT_SIZE 2
//#define NULL_VALUE -99999
//#define SUCCESS_VALUE 99999
//
//int listMaxSize;
//int * list;
//int length;
//int flag  = 0;
//
//void initializeList()
//{
//    listMaxSize = LIST_INIT_SIZE;
//    list = (int*)malloc(sizeof(int)*listMaxSize) ;
//    length = 0 ;
//}
//
//
//
//////////////////// HW_1 //////////////////
//
//int getLength(){
//    return length;
//}
//
//int insertItemAt(int pos, int item)
//{
//    if(flag == 1){
//        initializeList();
//        flag = 0;
//    }
//    if(pos >= length){
//        return NULL_VALUE;
//    }
//
//    int * tempList ;
//    if (length == listMaxSize)
//    {
//        //allocate new memory space for tempList
//        listMaxSize = 2 * listMaxSize ;
//        tempList = (int*) malloc (listMaxSize*sizeof(int)) ;
//        int i;
//        for( i = 0; i < length ; i++ )
//        {
//            tempList[i] = list[i] ; //copy all items from list to tempList
//        }
//        free(list) ; //free the memory allocated before
//        list = tempList ; //make list to point to new memory
//    };
//
//    list[length++] = list[pos];
//    list[pos] = item;
//    return SUCCESS_VALUE;
//
//}
//
//int shrink()
//{
//
//    if(length == listMaxSize / 2 && listMaxSize != LIST_INIT_SIZE)
//    {
//        int *tempList;
//        //allocate new memory space for tempList
//        listMaxSize = listMaxSize / 2;
//        tempList = (int*) malloc (listMaxSize*sizeof(int)) ;
//        int i;
//        for( i = 0; i < length ; i++ )
//        {
//            tempList[i] = list[i] ; //copy all items from list to tempList
//        }
//        free(list) ; //free the memory allocated before
//        list = tempList ; //make list to point to new memory
//        return SUCCESS_VALUE;
//    }
//
//    return NULL_VALUE;
//}
//
//
//int searchItem(int item)
//{
//    int i = 0;
//    for (i = 0; i < length; i++)
//    {
//        if( list[i] == item ) return i;
//    }
//    return NULL_VALUE;
//}
//
//int insertItem(int newitem)
//{
//    if(flag == 1){
//        initializeList();
//        flag = 0;
//    }
//    int * tempList ;
//    if (length == listMaxSize)
//    {
//        //allocate new memory space for tempList
//        listMaxSize = 2 * listMaxSize ;
//        tempList = (int*) malloc (listMaxSize*sizeof(int)) ;
//        int i;
//        for( i = 0; i < length ; i++ )
//        {
//            tempList[i] = list[i] ; //copy all items from list to tempList
//        }
//        free(list) ; //free the memory allocated before
//        list = tempList ; //make list to point to new memory
//    };
//
//    list[length] = newitem ; //store new item
//    length++ ;
//    return SUCCESS_VALUE ;
//}
//
//
//int deleteItemAt(int position) //version 2, do not preserve order of items
//{
//    if ( position >= length ) return NULL_VALUE;
//    list[position] = list[length-1] ;
//    length-- ;
//    shrink();
//    return SUCCESS_VALUE ;
//}
//
//
//int deleteItem(int item)
//{
//    int position;
//    position = searchItem(item) ;
//    if ( position == NULL_VALUE ) return NULL_VALUE;
//    deleteItemAt(position) ;
//    shrink();
//    return SUCCESS_VALUE ;
//}
//
//void printList()
//{
//    int i;
//    for(i=0;i<length;i++)
//        printf("%d ", list[i]);
//    printf("\nCurrent size: %d, current length: %d\n", listMaxSize, length);
//}
//
//
//
//int deleteLast()
//{
//    if(length == 0)
//        return NULL_VALUE;
//    deleteItemAt(length-1);
//    shrink();
//    return SUCCESS_VALUE;
//}
//
//int deleteAll()
//{
//    int n = length;
//    while(n)
//    {
//        deleteLast();
//        n--;
//    }
//}
//
//int _clear()
//{
//    if(flag == 1){
//        return NULL_VALUE;
//    }
//    deleteAll();
//    free(list);
//    listMaxSize = 0;
//    flag = 1;
//    return SUCCESS_VALUE;
//}
//
//
//
//////////////////// MAIN_1 /////////////////
//
//
//int main(void)
//{
//    initializeList();
//    while(1)
//    {
//        printf("1. Insert new item. 2. Delete item at. 3. Delete item.\n");
//        printf("4. (Add from homework). 5. Print. 6. exit. 7. insertItemAt. 8. deleteLast. 9. clear.\n");
//        printf("10. deletAll. \n");
//
//        int ch;
//        scanf("%d",&ch);
//        if(ch==1)
//        {
//            int item;
//            scanf("%d", &item);
//            insertItem(item);
//        }
//        else if(ch==2)
//        {
//            int pos;
//            scanf("%d", &pos);
//            deleteItemAt(pos);
//        }
//        else if(ch==3)
//
//        {
//            int item;
//            scanf("%d", &item);
//            deleteItem(item);
//        }
//        else if(ch==5)
//        {
//            printList();
//        }
//        else if(ch==6)
//        {
//            break;
//        }
//        else if(ch == 7){
//            int pos, item;
//            scanf("%d %d", &pos, &item);
//            insertItemAt(pos, item);
//        }
//        else if(ch == 8){
//            deleteLast();
//        }
//        else if(ch == 9){
//            _clear();
//        }
//        else if(ch == 10){
//            deleteAll();
//        }
//    }
//
////    double x;
////    int n;
////    scanf("%lf %d", &x, &n);
////    double sum = 1, m = 1, l = 0;
////    for(int i = 0; i< n-1;i++)
////    {
////        m *= (x*x)/((l+2)*(l+1));
////        if(i % 2)sum += m;
////        else{
////            sum -= m;
////        }
////        l+=2;
////    }
////
////    printf("%lf", sum);
//
//}
//
//
//
//
////////////////// MAIN_2 /////////////////////
////
////
////int main()
////{
////    int i ,j ,k ,l, t1, t2, t;
////    char s[10000];
////    initializeList();
////    scanf("%s", s);
////
////    for(i=0;s[i];i++){
//////        printf("\n");
//////        printf("i = %d : ", i);
//////        printList();
//////        printf("\n");
////        if(s[i] == '+'){
////            t1 = list[length - 1];
////            t2 = list[length - 2];
////            t = t1 + t2;
////            for(j=0;j<2;j++)
////                deleteLast();
////
////            insertItem(t);
////        }else if(s[i] == '-'){
////            t1 = list[length - 1];
////            t2 = list[length - 2];
////            t = t2 - t1;
////            for(j=0;j<2;j++)
////                deleteLast();
////            insertItem(t);
////        }else if(s[i] == '*'){
////            t1 = list[length - 1];
////            t2 = list[length - 2];
////            t = t1 * t2;
////            for(j=0;j<2;j++)
////                deleteLast();
////            insertItem(t);
////        }else if(s[i] == '/'){
////            t1 = list[length - 1];
////            t2 = list[length - 2];
////            t = t2 / t1;
////            for(j=0;j<2;j++)
////                deleteLast();
////            insertItem(t);
////        }else{
////            insertItem(s[i] - 48);
////        }
////    }
////
////    int ans = list[length - 1];
////    printf("%d", ans);
////    _clear();
////}
////
////
////
////
////
////
/////////// MAIN MAIN /////////////
//
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define EPS 1e-10

int chack[2000005];
int main() {
    ios::sync_with_stdio(false);
    int n, i, j, k, l, m, sum = 0;
    vector<int> v;
    cin >> n >> m;
    int a[n+2], b[m+2];
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    for(i=0;i<m;i++){
        cin >> b[i];
        sum += b[i];
    }

    for(i=1;i<=m;i++){
        for(j=1;j<=b[i];j++){
            v.push_back(i);
        }
    }

//    for(i=0;i<v.size();i++){
//        cout << v[i] << " ";
//    }
    int cnt = 0;
    l = v.size();
    for(i=0;i<n-l+1;i++){
        cnt = 0;
        for(j=i;j<=i+l;j++){
            if(a[j] != v[cnt++]){
                break;
            }
            if(j == i + l){
                cout << "YES";
                return 0;
            }
        }
    }

    cout << "NO";

}


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

string s[51];
double dp[1050000];
int b[1050000];
long long bm[1050000];
int N, M;

void prep(){
    for(int i=0;i<(1<<M);++i)
        bm[i] = 0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            int cur = 0;
            for(int k=0;k<M;++k){
                if(s[i][k] == s[j][k]){
                    cur |= 1<<k;
                }
            }
            bm[cur] |= 1LL<<i;
            bm[cur] |= 1LL<<j;
        }
    }
    for(int i=(1<<M)-1;i>=0;--i){
        for(int j=0;j<M;++j){
            bm[i & (~(1<<j))] |= bm[i];
        }
    }
    /*
    for(int i=0;i<(1<<M);++i){
        int tmp = bm[i];
        int cur = i;
        for(int j=0;j<M;++j){
            printf("%d", cur%2);
            cur/=2;
        }
        printf(" ");
        for(int j=0;j<N;++j){
            printf("%d", tmp%2);
            tmp/=2;
        }
        printf("\n");
    }
    */
}

double dp2[1050000];

int main(){
    cin >> N;
    for(int i=0;i<N;++i){
        cin >> s[i];
    }
    M = s[0].size();
    int lim = 1<<M;
    double prob = 1L / ((double) N);
    prep();
    b[0] = 0;
    for(int i=0;i<lim;++i){
        b[i] = b[i/2] + i%2;
    }
    double cnt, tmp, pr, p, tot;
    long long cur;
    dp[lim-1] = 0;
    for(int i=lim-2;i>=0;--i){
        tot = 0;
        p = 1 / ((double)M - b[i]);
        dp[i] = 0;
        for(int j=0;j<N;++j)if(bm[i] & (1LL<<j))++tot;
        if(bm[i] == 0){
            dp[i] = 0;
            continue;
        }
        for(int j=0;j<M;++j){
            if(!(i & (1<<j))){
                cnt = 0;
                cur = bm[i ^ (1<<j)] | ~bm[i];
                for(int k=0;k<N;++k) if(!(cur & (1LL<<k))) ++cnt;
                pr = cnt/tot;
                dp[i] += ((dp[i ^ (1<<j)] + 1) * (1-pr) + (pr)) * p;
            }
        }
    }
    printf("%.12lf\n", dp[0]);
    return 0;
}


By pin3da, contest: Codeforces Round #275 (Div. 1), problem: (C) Game with Strings, Accepted, #

using namespace std;
#include <bits/stdc++.h>
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define D(x) cout << #x " = " << (x) << endl
#define endl '\n'

const int MN = 55, MM = 20;
long long dp[(1 << MM) + 2];
double ans[(1 << MM) + 2];
string data[MN];

int s, n;

int main() { ___

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

  s = data[0].size();

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int same = 0;
      for (int k = 0; k < s; ++k)
        if (data[i][k] == data[j][k])
          same |= 1 << k;
      dp[same] = (1LL << j) | (dp[same] | 1LL << i);
    }
  }

  for (int mask = (1 << s) - 1; mask >= 0; --mask)
    for (int i = 0; i < s; ++i)
      if ((mask >> i) & 1)
        dp[mask ^ (1 << i)] |= dp[mask];

  for (int mask = (1 << s) - 1; mask >= 0; --mask) {
    if (dp[mask] == 0)
      ans[mask] = 0;
    else {
      ans[mask] = 0;
      double events = s - __builtin_popcount(mask);
      for (int i = 0; i < s; ++i) {
        if (!((mask >> i) & 1)) {
          ans[mask] += ans[mask | 1 << i] * (double) __builtin_popcountll(dp[mask | 1 << i]) / (double)__builtin_popcountll(dp[mask]);
        }
      }
      ans[mask] = 1.0 + ans[mask] / events;
    }
  }

  cout << setprecision(15) << ans[0] << endl;

  return 0;
}