#include<bits/stdc++.h>

using namespace std;

using ll = long long;

/*-----for personal-----*/
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n)  rep(i,0,n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

/*-----for lib-----*/
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)

const long double EPS = 1e-12;
const int MOD = 1e9+7;
const int INF = INT_MAX / 2;
const ll LLINF = LLONG_MAX / 2;
//for(auto &h : H){ cout << h << " ";} cout << endl;
//for(auto &h : H){for(auto &k:h){cout << k << " ";}cout << endl;}
//for(auto [k,v] : mp){cout << k << " " << v << endl;}
//for(auto [k,v] : mp){cout << k << " "; for(auto &u:v){cout << u << " ";}cout << endl;}

/*
f(n) = (f(n+1)+1) * 1/M + (f(n+2)+1) * 1/M + .... + (f(n+M)+1) * 1/M
     = 1/M (f(n+1)+1+f(n+2)+1+f(n+3)+1+f(n+M)+1)
     = 1/M (f(n+1)+f(n+2)+...+f(n+M)+M)
     = 1/M (f(n+1)+f(n+2)+...+f(n+M)) + 1
f(n) = f(0) [循環する]

g(n) = 1/M (g(n+1)+g(n+2)+....+g(n+M)) + 1 振り出しじゃない
g(n) = X 振り出し

g(0) = 1/M (g(1)+g(2)+....+g(M)) + 1

f(0) - f(0)A = B
(1-A)f(0) = B

Mf(0) = MB/(M-MA)
A = 1/M*(1~Nでgが振り出しの数)
B = 1/M+(1~Mでgが振り出しでない数)+1
MA = (1~Nでgが振り出しの数)
MB = (1~Mでgが振り出しでない数)+M
*/

const int N = 100000;
const int M = 100000;
vector<bool> A(N+1,false);
vector<long double> dp(N+M, 0);
vector<long double> S(N+M, 0);
int n, m, k;

long double f(long double v){
  for(int i = n-1; i>=0; i--){
    if(A[i]){
      dp[i] = v;
    }else{
      dp[i] = 1+(S[i+1]-S[i+1+m])/m;
    }
    S[i] = dp[i] + S[i+1];
  }
  return dp[0];
}

int main(){
  cin >> n >> m >> k;
  repn(i,k){
    int a; cin >> a;
    A[a] = true;
  }

  int count = 0;
  for(int i = 0; i <= n; i++){
    if(!A[i]){count=0; continue;}
    count++;
    if(count>=m){ cout << -1 << endl; return 0;}
  }

  long double l=0, r=1e12, mid;
  //mid -> v
  count = 0;
	while(count<=100) {
		mid=(l+r)/2;
		if(abs(f(mid)-mid)<EPS) break;
    else if(f(mid)>mid) l=mid;
		else r=mid;
    count++;
	}

  cout << setprecision(12) << mid << endl;

}

//............Created by:- Arth Raj...........................//
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <climits>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<sstream>
#define ll long long int
#define pll pair<long long int,long long int>
#define pb push_back
#define mp make_pair
#define vi vector<long long int>
#define vii vector<pair<long long int,long long int>>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lp(i,a,b) for(long long int i=a;i<b;i++)
#define rlp(i,a,b) for(long long int i=b;i>=a;i--)
#define ld long double
#define tl tuple<ll,ll,ll>
#define all(x) (x).begin(),(x).end()
#define bs(x,b) binary_search(all(x),b)
#define vip vector<pair<long long int,pair<long long int,long long int>>>
#define pip pair<long long int,pair<long long int,long long int>>
#define INF 1e18
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;}
ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;}
int main()
{
	ll a, b, k;
	cin >> a >> b >> k;
	ll dp[70][70];
	lp(i, 0, 70)
	{
		dp[i][0] = 1;
	}
	lp(i, 1, 70)
	{
		lp(j, 1, i + 1)
		{
			dp[i][j] = i * dp[i - 1][j - 1];
			dp[i][j] /= j;
		}
	}
	char ans[a + b];
	ll pointer = 0;
	ll lefta = a, leftb = b;
	ll totalper = dp[a + b][a];
	while (pointer < (a + b))
	{
		ll x = dp[lefta + leftb - 1][leftb];
		// cout << x << endl;
		if (k > x)
		{
			// cout << "awd" << endl;
			ans[pointer++] = 'b';
			k -= x;
			leftb--;
		}
		else
		{
			ans[pointer++] = 'a';
			lefta--;
		}
		// cout << k << endl;
		if (k <= 1)
			break;
	}
	lp(i, pointer, a + b)
	{
		if (lefta)
		{
			ans[i] = 'a';
			lefta--;
		}
		else
		{
			ans[i] = 'b';
			leftb--;
		}
	}
	lp(i, 0, a + b)
	{
		cout << ans[i];
	}
	cout << endl;
}


#include <bits/stdc++.h>
#define fo(i, k, n) for (ll i = k; i < n; i++)
#define rfo(i, k, n) for (ll i = k; i >= n  ; i--)
#define ll long long
#define ld long double
#define que queue
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define gcd(m,n) __gcd( m,  n)
#define sq(x)   (x*x)
#define rev(v)  reverse(v.begin(),v.end())
#define srt(v)  sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v)     *min_element(v.begin(),v.end())
#define mxv(v)    *max_element(v.begin(),v.end())
#define all(v)    v.begin(),v.end()
#define toInteger(s) stoll(s)
#define toString(num) to_string(num)
#define show(arr) { for (auto x: arr) cout << x << " "; cout << '\n'; }

using namespace std;
ll MOD = 1e9 + 7;
//--------------------------------------------functions-------------------------------------------------//

ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=mul(a,res,M);
        }
        a=mul(a,a,M);b/=2ll;
    }
    return res;
}
int log22(long long x)
{
    return 64 - __builtin_clzll(x) - 1;
}

//--------------------------------------------SieveOfEratosthenes-------------------------------------------------//
//mem will have true if its prime.
void SieveOfEratosthenes( vector<bool>&mem)
{ ll n = 1e6 +1;

    bool prime[n + 1];
    memset(prime, true, sizeof(prime));

    for (int p = 2; p * p <= n; p++)
    {

        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

     fo(i,2,n)
     if(prime[i])mem[i]=true;

}

//--------------------------------------------solve-------------------------------------------------//

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

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

cout<<fixed;
float a,b;
cin>>a>>b;

float answer = a*b/100.0;

cout<<setprecision(8)<<answer;

  return 0;
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod  998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int dp[N][20];
int fact[N],inv[N];
void pre()
{
    fact[0]=1;
    inv[0]=1;
    for(int i=1;i<N;i++)
    fact[i]=(i*fact[i-1])%mod;
    for(int i=1;i<N;i++)
    inv[i]=power(fact[i], mod-2, mod);
}
int nCr(int n, int r, int p)
{
    if(r>n)
    return 0;
    if(n==r)
    return 1;
    if (r==0)
    return 1;
    return (((fact[n]*inv[r]) % p )*inv[n-r])%p;
}
int32_t main()
{
    IOS;
    pre();
    int n, m;
    cin>>n>>m;
    int ans=0;
    for(int i=m;i>0;i--)
    {
        dp[i][0]=1;
        for(int j=i*2;j<=m;j+=i)
        {
            for(int k=1;k<20;k++)
            dp[i][k]+=dp[j][k-1];
        }
        rep(j,0,20)
        {
            dp[i][j]%=mod;
            ans+=(nCr(n-1, j, mod)*dp[i][j])%mod;
            ans%=mod;
        }
    }
    cout<<ans;
}


//wtrl,everybody hangbeat me
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,int> mpci;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))
#define INF 1e9
#define PI acos(-1)

/*=====================================================================*/

string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
string turn(int n,int k)
{
	string s="";
	while(n)
	{
		s+=(char)(n%k+'0');
		n/=k;
	}
	reverse(s.begin(),s.end());
	return s;
}
const string turn16(int n)
{
	string s="";
	while(n!=0)
	{
		if(n%16>9)
		  s+=(char)('A'+n%16-10);
		else
		  s+=(char)('0'+n%16);
		n/=16;
	}
	reverse(s.begin(),s.end());
	return s;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])
  {
  	cout<<"Won"<<endl;
  }
  else
  {
  	cout<<"Lost"<<endl;
  }
  return 0;
}

#include <iostream>

using namespace std;
int main() {
	string s;
	cin >> s;

	if (s[0] == s[1]) {
		if (s[1] == s[2]) {
			cout << "Won";
			return 0;
		}
	}
	cout << "Lost";
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    double a,b;
    cin>>a>>b;
    decimal;
    out(a*b/100);
}

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

//#define int long long

template <int mod = 1000000007>
struct modint{
    int x;
    modint(int y = 0) : x((y % mod + mod) % mod) { }
    friend modint operator^(modint a, long long b) {
        modint r = 1;
        for(; b; b >>= 1, a *= a) if(b & 1) r *= a;
        return r;
    }
    friend modint operator-(modint a) {return modint(0) - a;}
    friend modint operator!(modint a) {return a ^ (mod - 2);}
    modint& operator/=(modint const& b) {return *this *= !b;}
    friend bool operator==(modint a, modint b) {return a.x == b.x;}
    friend bool operator!=(modint a, modint b) {return a.x != b.x;}
    friend modint operator+(modint a, modint const& b) {return a += b;}
    friend modint operator-(modint a, modint const& b) {return a -= b;}
    friend modint operator*(modint a, modint const& b) {return a *= b;}
    friend modint operator/(modint a, modint const& b) {return a /= b;}
    modint& operator*=(modint const& b) {x = 1LL * x * b.x % mod; return *this;}
    friend ostream& operator<<(ostream& os, modint const& a) {return os << a.x;}
    modint& operator+=(modint const& b) {x += b.x; x = (x >= mod) ? x - mod : x;return *this;}
    modint& operator-=(modint const& b) {x = x >= b.x ? x - b.x : x - b.x + mod;return *this;}
};

using mint = modint <>;

mint nCr(int n, int m) {
    if(m > n) return mint(0);
    mint res = 1;
    for(int i = n - m + 1; i <= n; i++) res *= i;
    for(int i = 1; i <= m; i++) res /= i;
    return res;
}

int32_t main() {

    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, sum = 0; cin >> n >> m;
    vector <int> v(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        sum += v[i];
    }

    if(sum > m) {
        cout << 0 << endl;
        return 0;
    }

    mint a = nCr(m + n, (sum + n));
    cout << a << endl;
}


#include <bits/stdc++.h>
using namespace std;
// vtqi6hy80o@email.edu.pl
#define rep(i, a, b) for(lli i = a; i < b; i++)
#define lli long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define hell 1000000000000000
#define pb push_back
#define pf push_front
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define F first
#define S second
#define pi 2*acos(0.0)
#define sz(s) s.size()
#define atmod (1000000000+7)
#define mod 998244353
// auto _C=clock();
// lli n = 10000000;
// int dx[]={1,-1,0,0};
// int dy[]={0,0,1,-1};
/*vector<bool> p(n + 1, true);
void sieve()
{
    for (long long int i = 2; i * i <= n; i++)
    {
        if (p[i])
        {
            for (long long int j = i + i; j <= n; j = j + i)
            {
                p[j] = false;
            }
        }
    }
}
*/
/*
WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!
Falling down is an accident, Staying down is a choice.
*/
/*lli binpow(lli a, lli n,lli m)
{
    lli r = 1;
    a %=m ;
    while (n > 0)
    {
        if (n & 1)
        {
            r = (r * a)%m ;
        }
        a = (a * a)%m ;
        n = n / 2;
    }
    return r;
}*/
/*bool cmp(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.F<b.F) return 1;
    else if(a.F==b.F) return(a.S>b.S);
    else return 0;
}*/
/*lli ncr(lli n,lli r)
{
    lli res = 1;
    rep(i,1,r+1)
    {
        res = (res%atmod*(n-r+i)%atmod)%atmod;
        res = (res%atmod * binpow(i,atmod-2,atmod)%atmod)%atmod;
    }
    return res;
}*/
void solve()
{
    lli n;
    cin>>n;
    lli a[n];
    rep(i,0,n)cin>>a[i];
    if(n==1)
    {
        cout<<a[0];
        return;
    }
    lli dp[n][2];
    lli f[n][2];
    f[1][1]=f[1][0]=1;
    rep(i,2,n)
    {
        f[i][1] = f[i-1][0];
        f[i][0] = (f[i-1][1]%atmod+f[i-1][0]%atmod)%atmod;
    }
    dp[1][0] = (a[1]+a[0])%atmod;
    dp[1][1] = (a[0]-a[1])%atmod;
    rep(i,2,n)
    {
        dp[i][0] = (dp[i-1][1]%atmod+dp[i-1][0]%atmod + ((f[i-1][1]+f[i-1][0])%atmod)*a[i])%atmod;
        dp[i][1] = (dp[i-1][0]%atmod - (f[i-1][0])%atmod*a[i]%atmod+(lli)atmod*atmod)%atmod;
    }
    cout<<(dp[n-1][1]%atmod+dp[n-1][0]%atmod)%atmod;
    // cout<<endl;
    // rep(i,1,n)
    // {
    //     rep(j,0,2)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    // sieve();
    lli t = 1;
    // cin >> t;
    rep(i,1,t+1)
    {
        solve();
    }
    // cerr<<"\n\n\nTime elapsed: ";
    // cout<<"\n"<<(double)(clock()-_C)*1000.0/CLOCKS_PER_SEC<<"ms\n";
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
const long long mod=1000000007;
int n;
long long res,dp[maxn];
inline long long go(int x) {
    if (x<=0) return 1;
    return dp[x];
}
int main()
{
    dp[0]=1;
    dp[1]=2;
    for (int i=2;i<maxn;++i)
        dp[i]=(dp[i-1]+dp[i-2])%mod;
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        int x;scanf("%d",&x);
        if (i==1) res+=go(n-1)*x%mod;
        else res+=(go(i-2)*go(n-i)%mod-go(i-3)*go(n-i-1)%mod)*x%mod;
        res=(res+mod)%mod;
    }
    cout<<res<<endl;
    return 0;
}


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

const long long int mod = 1000000007;
const long long int big = 2999999999999999999;
const long long int small = -2999999999999999999;
#define ll long long int
#define pb(a) push_back(a)
#define vll vector<long long int>
#define loop(i, n) for(long long int i=1;i<=n;i++)
#define loop0(i, n) for(long long int i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>

ll n, m, k;
vll a, b, c, d;

void in2(ll& a, ll& b)
{
  in(a);
  in(b);
}
void in3(ll& a, ll& b, ll& c)
{
  in(a);
  in(b);
  in(c);
}

ll howMany(vll counter)
{
  ll ret = 0;
  loop0(i, m)
  {
    if(counter[a[i]] && counter[b[i]])
      ret += 1;
  }
  return ret;
}

ll solve(ll i, vll occ)
{
  if(i == k-1)
  {
    return howMany(occ);
  }
  occ[c[i+1]] += 1;
  ll a = solve(i+1, occ);
  occ[c[i+1]] -= 1;
  occ[d[i+1]] += 1;
  ll b = solve(i+1, occ);
  occ[d[i+1]] -= 1;
  return max(a, b);
}

int main()
{
  in2(n, m);
  a.resize(m);
  b.resize(m);
  loop0(i, m)
  {
    in2(a[i], b[i]);
  }
  in(k);
  c.resize(k);
  d.resize(k);
  loop0(i, k)
  {
    in2(c[i], d[i]);
  }
  vll occ(n+1, 0);
  ll ans = solve(-1, occ);
  cout<<ans<<"\n";
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

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

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

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

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int ri(){
    int n;
    scanf("%d",&n);
    return n;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> cond(M);
    for (auto &[A, B] : cond)
        cin >> A >> B;
    int K;
    cin >> K;
    vector<pair<int, int>> choice(K);
    for (auto &[C, D] : choice)
        cin >> C >> D;

    int ans = 0;
    for (int bit = 0; bit < 1 << K; bit++)
    {
        vector<bool> ball(N);
        for (int i = 0; i < K; i++)
        {
            const auto [C, D] = choice[i];
            ball[bit & 1 << i ? C : D] = 1;
        }
        int cnt = 0;
        for (auto [A, B] : cond)
            if (ball[A] && ball[B])
                cnt++;
        if (ans < cnt)
            ans = cnt;
    }
    cout << ans << endl;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(n+2);
  a[0]=0;
  a[n+1]=0;
  int maxa=0;
  rep(i,n){
    cin>>a[i+1];
    maxa=max(maxa,a[i+1]);
  }
  set<int>is[maxa+2];
  rep(i,n+2){
    is[a[i]].insert(i);
  }

  rep(i,maxa+2){
    if(is[i].size() ==0){
      cout<<i<<endl;
      return 0;
    }
    int temp=0;
    for(auto e=is[i].begin();e != is[i].end();e++){
      if(*e-temp>m){
        cout<<i<<endl;
        return 0;
      }
      else{
        temp=*e;
      }
    }
    if(n-temp>=m){
      cout<<i<<endl;
      return 0;
    }

  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf LLONG_MAX
#define int long long
#define mod 998244353

int a[1500005];
int x[1500005];

signed main(void)
{
	int n, m; cin >> n >> m;
	rep (i, n) cin >> a[i];
	set<int> s;
	rep (i, n+1) s.insert(i);
	rep (i, m)
	{
		x[a[i]]++;
		if (x[a[i]] == 1) s.erase(a[i]);
	}
	int ans;
	ans = min(n, *(s.begin()));
	reps (i, m, n)
	{
		x[a[i-m]]--;
		x[a[i]]++;
		if (a[i-m] != a[i])
		{
			if (x[a[i-m]] == 0) s.insert(a[i-m]);
			if (x[a[i]] == 1) s.erase(a[i]);
		}
		ans = min(ans, *(s.begin()));
	}
	cout << ans << endl;
}


#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

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

const ll INF = 1e18;

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll ans = n;
    vector<int>cnt;
    rep(i, n) {
        if (s[i] == 'f')cnt.push_back(1);
        else if (s[i] == 'o')cnt.push_back(2);
        else if (s[i] == 'x')cnt.push_back(3);
        else cnt.push_back(0);
        int size = cnt.size();
        //cout << i << ' ' << size << endl;
        if (size >= 3 && cnt[size - 3] == 1 && cnt[size - 2] == 2 && cnt[size-1] == 3) {
            ans -= 3;
            rep(j, 3)cnt.pop_back();
        }

    }

    cout << ans << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  REP(i,n)cin>>v[i];
  REP(i,n)v[i]--;
  set<int> rem;
  REP(i,n-1)if(v[i]>i&&v[i+1]<i+1)rem.insert(i);
  vector<int> ans;
  while(rem.size()){
    int p=*rem.begin();
    ans.push_back(p);
    rem.erase(p);
    swap(v[p],v[p+1]);
    for(int i=p-1;i<=p+1;i++)if(~i&&v[i]>i&&v[i+1]<i+1)rem.insert(i);
  }
  if(ans.size()!=n-1)fin(-1);
  REP(i,n)if(i!=v[i])fin(-1);
  for(int p:ans)cout<<p+1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int akaPow(int e, int p)
{
    int ans = 1;
    while (p > 0)
    {
        if (p & 1) ans = ans * e;
        e = e * e;
        p >>= 1;
    }
    return ans;
}
int32_t main() {
    IOS;
#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b, c;
    cin >> a >> b >> c;
    if (akaPow(a, 2) + akaPow(b, 2) < akaPow(c, 2)) cout << "Yes";
    else cout << "No";
}

#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
#define sz size();
using namespace std;

int main(){

	ios::sync_with_stdio(0);
	int V, T, S, D;

	cin>>V>>T>>S>>D;

	if(D>=T*V && D<=V*S){
		cout<<"No"<<endl;
	} else {
		cout<<"Yes"<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD =1000000007;
using Graph = vector<vector<int>>;

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

    int n,m;
    cin>>n>>m;

    map<pair<int,int>,int> p;
    Graph g(n);
    rep(i,m){
        int u,v,c;
        cin>>u>>v>>c;
        u--;
        v--;
        c--;
        if(u>v)swap(u,v);
        p[make_pair(u,v)]=c;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    queue<int> q;
    q.push(0);
    vector<int> ans(n,-1);
    ans[0]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();

        for(auto nv:g[v]){
            if(ans[nv]!=-1)continue;
            int l=v,r=nv;
            if(l>r) swap(l,r);

            ans[nv]=p[make_pair(l,r)];
            if(ans[v]==ans[nv]){
                ans[nv]=(ans[nv]+1)%n;
            }
            q.push(nv);

        }
    }
    rep(i,n){
        cout<<ans[i]+1<<endl;
    }

}

//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
//a+b=(axorb)+2*(a&b)
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn))
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
//#define endl "\n"
#define fi first
#define sec second
#define sp setprecision
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=998244353;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp
{
    bool operator() (const pll &a, const pll &b)  const
    {
        ll lena = a.sec - a.fi + 1;
        ll lenb = b.sec - b.fi + 1;
        if (lena == lenb) return a.fi < b.fi;
        return lena > lenb;
    }
};
********************************/

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

ll binpow(ll a, ll b,ll m)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll n)
{
    return binpow(n, mod - 2,mod);
}

/**************coding*********************/
lld dp[102][102][102]={};
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;//cin>>T;
    For(i,1,T)
    {
        ll a,b,c;cin>>a>>b>>c;
        Forr(j,99,0)
        {
            Forr(k,99,0)
            {
                Forr(l,99,0)
                {
                    lld sum=j+k+l;
                    if(sum!=0)
                    {
                        lld p1=(double(j)/sum),p2=(double(k)/sum),p3=double(l)/sum;
                        dp[j][k][l]=(1+((dp[j+1][k][l])*p1)+
                        ((dp[j][k+1][l])*p2)+((dp[j][k][l+1])*p3));
                    }
                }
            }
        }
        cout<<sp(20)<<dp[a][b][c];
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define sc second
#define fr first
#define pb push_back
#define pii pair<int, int>
#define Nmax 100005
using namespace std;
vector <pii> v[Nmax];
int t[Nmax], s[Nmax], viz[Nmax], n, m;

int tata(int x)
{
    if(x!=t[x]) t[x]=tata(t[x]);
    return t[x];
}
void uneste(int x, int y)
{
    if(s[x]>s[y])
    {
        t[y]=x;
        s[x]+=s[y];
    }
    else
    {
        t[x]=y;
        s[y]+=s[x];
    }
}
void dfs(int x)
{
    for(auto it:v[x])
        if(viz[it.fr]==0)
        {
            if(viz[x]==it.sc)
                viz[it.fr]=(viz[x]+1)%n+1;
            else viz[it.fr]=it.sc;
            dfs(it.fr);
        }
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;

    for(int i=1;i<=n;i++)
    {
        s[i]=1; t[i]=i;
    }

    for(int i=1;i<=m;i++)
    {
        int x, y, k;
        cin >> x >> y >> k;
        if(tata(x)!=tata(y))
        {
            uneste(t[x], t[y]);
            v[x].push_back(mp(y, k));
            v[y].push_back(mp(x, k));
        }
    }

    viz[1]=1;
    dfs(1);

    for(int i=1;i<=n;i++)
        cout << viz[i] << '\n';
    return 0;
}

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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)
constexpr int INF = 1e9;
//constexpr ll INF = 1LL << 61;
constexpr int mod = 1e9+7;

struct Edge{
  int x, y, d;
  Edge(){}
  Edge(int x, int y, int d): x(x), y(y), d(d){}
  bool operator< (const Edge l)const{
    return d < l.d;
  }
};

struct UnionFind{
  vector<int> node;
  UnionFind(int n){
    node = vector<int>(n, -1);
  }
  int find(int v){
    if(node[v] < 0){
      return v;
    }
    return node[v] = find(node[v]);
  }
  bool merge(int v, int u){
    int rootv = find(v);
    int rootu = find(u);
    if(rootv == rootu) return false;
    if(node[rootv] < node[rootu]){
      swap(rootv, rootu);
    }
    node[rootv] += node[rootu];
    node[rootu] = rootv;
    return true;
  }
  int size(int v){
    return -node[v];
  }
};
vector<int> ans;
void dfs(int v, vector<vector<pair<int, int>>> &g, int root){
  for(auto edge : g[v]){
    int nv = edge.first;
    int cost = edge.second;
    if(nv == root) continue;
    assert(nv != v);
    if(ans[v] == cost){
      if(cost ==0){
        ans[nv]= 1;
      }
      else{
        ans[nv] = 0;
      }
    }
    else{
      ans[nv] = cost;
    }
    dfs(nv, g, v);
  }
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<Edge> edges(M);
  REP(i, M){
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--, c--;
    edges[i] = Edge(u, v, c);
  }
  sort(edges.begin(), edges.end());
  vector<vector<pair<int, int>>> g(N);
  UnionFind uf(N);
  REP(i, M){
    int u, v;
    u = edges[i].x, v = edges[i].y;
    if(uf.merge(u, v)){
      g[v].push_back({u, edges[i].d});
      g[u].push_back({v, edges[i].d});
    }
  }
  ans.resize(N);
  ans[0] = 0;
  dfs(0, g, -1);
  REP(i, N){
    cout << ans[i]+1 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl                "\n"
#define fi                  first
#define se                  second
#define For(i,a,b)          for(ll i=a;i<b;i++)
#define RFor(i,b,a)         for(ll i = b;i>=a;i--)
#define sz                  size()
#define PQ                  priority_queue
#define len                 length()
#define mll                 map<ll,ll>
#define mpll                map<pll,ll>
#define vll                 vector<ll>
#define sll                 set<ll>
#define vpll                vector<pair<ll,ll> >
#define mp(x,y)             make_pair(x,y)
#define pll                 pair<ll,ll>
#define pb                  push_back
#define pf                  push_front
#define ALL(v)              v.begin(),v.end()
#define print(ans)          cout<<(ans?"YES":"NO")<<endl
#define LAPAK               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const int MAX = 1e5+3;

int main(){
LAPAK
    cout<<fixed<<setprecision(15);
    ll tc;
    tc = 1;
    //cin>>tc;
    while(tc--){
        ll n;
        cin>>n;
        ld a[n];
        ll m = 0, c = 0;
        ld e = 0;
        For(i,0,n){
            cin>>a[i];
            m += abs(a[i]);
            c = max(c, abs((ll)a[i]));
            e += (a[i]*a[i]);
        }
        e = sqrt(e);
        cout<<m<<endl<<e<<endl<<c<<endl;
    }
return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
//const lint MOD =1000000007;
const lint MOD=998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

    int main(){
        string s;
        cin>>s;
        lint now=0;
        lint n=s.size();
        lint a[n];
        rep(i,n){
            lint g=s[i]-'0';
            a[i]=g;
            a[i]%=3;
            now+=g;
        }
        now%=3;
        lint ans=INF;
        if(now==0)ans=0;
        else if(now==1){
            rep(i,n)if(a[i]==1)chmin(ans,1LL);
            lint count=0;
            rep(i,n)if(a[i]==2)count++;
            chmin(count,2LL);
            if(count>=2&&(n-count)>0)chmin(ans,2LL);
        }else if(now==2){
            rep(i,n)if(a[i]==2)chmin(ans,1LL);
            lint count=0;
            rep(i,n)if(a[i]==1)count++;
            chmin(count,2LL);
            if(count>=2&&(n-count)>0)chmin(ans,2LL);

        }
        if(n==1){
            lint g=s[0]-'0';
            if(g%3!=0)ans=INF;
            else ans=0;
        }
        if(ans==INF)cout<<-1<<endl;
        else cout<<ans<<endl;

    }


// Problem: D - Logical Expression
// Contest: AtCoder - AtCoder Beginner Contest 189
// URL: https://atcoder.jp/contests/abc189/tasks/abc189_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll>
#define all(x) (x).begin() , (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_ll_distribution<ll>(x, y)(rng)

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

const ll max_n = 1e5 + 9;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	ll n;
	cin >> n;
	vector<string> vec(n);
	for(ll i = 0 ; i < n ; i++){
		cin >> vec[i];
	}

	ll dp[n+1][2];
	dp[0][0] = dp[0][1] = 1;
	for(ll i = 1 ; i <= n ; i++){
		if(vec[i-1] == "AND"){
			dp[i][0] = 2 * dp[i-1][0] + dp[i-1][1];
			dp[i][1] = dp[i-1][1];
		}
		else{
			dp[i][0] = dp[i-1][0];
			dp[i][1] = 2 * dp[i-1][1] + dp[i-1][0];
		}
	}

	cout << dp[n][1] << "\n";
}
signed main(){
	ll t = 1;
	// cin >> t;
	for(ll i = 1 ; i <= t ; i++){
		solve();
	}
}

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
ll n;
string s[1000];
int main()
{
   ll n,i,j,t,a,b,c,p,k,kk;
    scanf("%lld",&n);
    for(i=1;i<=n;i++) cin>>s[i];
    ll sum=0;
    for(i=n;i>=1;i--)
    {
    	 if(s[i]=="OR") sum+=(1ll<<i);
	}
	printf("%lld\n",++sum);
}


#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  int n;
  cin >> n;
  cout << setprecision(10);
  vector<double>dp(n+1);
  dp[1] = 0;
  for (int i = 1; i < n; i++) {
      dp[i+1] = dp[i] + (double)n/(n-i);
  }
  cout << dp[n] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 998244353;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main(){
  ll N;
  cin >> N;
  if(N%2==0){
    cout << "White" << endl;
  }else{
    cout << "Black" << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
/*
#include <chrono>
using namespace std::chrono;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<lli, null_type,less_equal<lli>, rb_tree_tag,tree_order_statistics_node_update>
//remove _equal from less_equal to make it ordered set , currently it is ordered_multiset
*/
#define pb push_back
const lli mod=1e9+7;
const lli mod1=998244353;
#define fir first
#define sec second
#define plli pair<lli,lli>
#define pplli pair<lli,plli>
/*
lli power(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
lli powermod(lli a, lli b)
{
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = ((res%mod)*(a%mod))%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
*/
int main()
{
    lli T,i,j;
    T=1;
    while(T--)
    {

        lli n;
        cin>>n;
        lli a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        lli x=a[n/2]/2;
        lli f=(a[n/2]%2);
        lli loss=0;
        for(i=0;i<n;i++)
        {
            lli z=((a[i]+x)-min(a[n/2]*1ll,a[i]*1ll));
            loss=loss+z;
        }
        if(f)
        {
            loss+=(n/2);
        }
        ld ans=(ld) loss/n;
        if((n%2==1)and(f))
            ans=ans+ ((ld)0.5/n);
        cout<<fixed<<setprecision(10)<<ans<<"\n";
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> T(N);
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> T[i];
        sum += T[i];
    }
    int ave = (sum+1)/2;
    vector<vector<int>> dp(101, vector<int>(1000001, 0));
    for(int i = 0; i < N; i++){
        for(int t = 0; t <= ave; t++){
            if(t >= T[i] && abs(ave-dp[i][t-T[i]] - T[i]) < abs(ave-dp[i][t])){
                dp[i+1][t] = dp[i][t-T[i]] + T[i];
            }else{
                dp[i+1][t] = dp[i][t];
            }
            dp[i+1][t];
        }
    }
    cout << max(dp[N][ave], sum-dp[N][ave]) << endl;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string S;
  cin >> S;
  string T;
  bool rev = false;
  string revT;
  for (int i = 0; i < S.length(); i++){
    if (S[i] == 'R') {
      rev = !rev;
    }
    else {
      if (rev) revT += S[i];
      else T += S[i];
    }
  }
  reverse(revT.begin(), revT.end());
  T.insert(0, revT);
  if (rev) reverse(T.begin(), T.end());
  int i = 0;
  while (i < (int) T.length()-1) {
    if (T[i] == T[i+1]) {
      T.erase(i, 2);
      if (i>0) i--;
    }
    else i++;
  }
  cout << T << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(){
    string S; cin >> S;
    ll N = S.length();
    deque<char> dq;
    ll rr[N] = {};
    rep(i, N){
        if(i == 0){
            if(S[i] == 'R'){
                rr[i] = 1;
            }
            else {
                rr[i] = 0;
                dq.push_back(S[i]);
            }
        }
        else {
            if(S[i] == 'R'){
                rr[i] = rr[i-1] + 1;
            }
            else {
                rr[i] = rr[i-1];
                if(rr[i-1] %2 == 0 ){
                    if(dq.size() &&  S[i] == dq.back() ){
                        dq.pop_back();
                    }
                    else {
                        dq.push_back(S[i]);
                    }
                }
                else {
                    if(dq.size() &&  S[i] == dq.front() ){
                        dq.pop_front();
                    }
                    else {
                        dq.push_front(S[i]);
                    }
                }
            }
        }
    }
    if(rr[N-1] %2 != 0) reverse(dq.begin(), dq.end());
    rep(i,dq.size()) cout << dq[i];
    cout << endl;
}


#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	REP(i, 0, n) scanf("%d", &a[i]);

	int last = -1;
	REP(i, 0, n){
		if(i>a[i]-1){
			if(a[i]-1<last){
				puts("-1");
				return 0;
			}
			last = i;
		}
	}
	last = n;
	for(int i=n-1; i>=0; i--){
		if(i<a[i]-1){
			if(a[i]-1>last){
				puts("-1");
				return 0;
			}
			last = i;
		}
	}

	std::set<int> used;
	std::vector<int> ans;
	int pos[n];
	REP(i, 0, n) pos[a[i]-1] = i;
	REP(i, 0, n){
		if(i<pos[i]){
			for(int j=pos[i]; j>i; j--){
				if(used.count(j)){
					puts("-1");
					return 0;
				}
				used.insert(j);
				ans.push_back(j);
				pos[a[j-1]-1]++;
				std::swap(a[j-1], a[j]);
			}
			pos[i] = i;
		}else{
			for(int j=pos[i]; j<i; j++){
				if(used.count(j+1)){
					puts("-1");
					return 0;
				}
				used.insert(j+1);
				ans.push_back(j+1);
				pos[a[j+1]]--;
				std::swap(a[j], a[j+1]);
			}
		}
	}
	if(used.size()!=n-1) puts("-1");
	else for(int x: ans) printf("%d\n", x);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
}
// ****************************************************************************
int fun2(vector<int>&a,multiset<int>&st){
    if(st.size()==0)
    return 1e16;
    int val;
    int ans = LLONG_MAX;
    fo(i,0,a.size()){
        auto it = st.lower_bound(a[i]);
        if(it!=st.begin())
        it--;
        fo(k,0,3){
            if(it==st.end())
            break;
            if(ans>(abs(*it-a[i]))){
                ans=abs(*it-a[i]);
                val=*it;
            }
            it++;
        }
    }
    st.erase(st.find(val));
    return ans;
}
int fun(vector<int>&a,vector<int>&b,vector<int>&c){
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int ans = LLONG_MAX;
    fo(i,0,a.size()){
        auto it = lower_bound(b.begin(),b.end(),a[i]);
        if(it!=b.begin())
        it--;
        fo(k,0,3){
            if(it==b.end())
            break;
            ans=min(ans,abs(*it-a[i]));
            it++;
        }
    }
    multiset<int>st;
    for(auto it : c)
    st.insert(it);
    if(st.size()==0)
    return ans;
   int tempans = fun2(a,st);
   tempans+=fun2(b,st);
    return min(ans,tempans);
}
void solve(){
    int n;
    cin>>n;
    n*=2;
    vector<int>r,g,b;
    fo(i,0,n){
        int x;
        cin>>x;
        char cc;
        cin>>cc;
        if(cc=='R'){
            r.pb(x);
        }
        else if(cc=='G')
        g.pb(x);
        else b.pb(x);
    }
    if(r.size()%2==0 && g.size()%2==0 && b.size()%2==0){
        cout<<"0";
        return;
    }
    if(r.size()%2 && g.size()%2)
    cout<<fun(r,g,b);
    else if(r.size()%2 && b.size()%2)
    cout<<fun(r,b,g);
    else cout<<fun(g,b,r);
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

int A[100001], B[100001];
ll kotae = 0;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N = getint();
	rep(i, N) A[getint()]++;
	rep1(i, N) B[i] = A[getint()];
	rep(i, N) kotae += B[getint()];

	co(kotae);

	Would you please return 0;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <iterator>
#include <queue>
#define ll long long int
using namespace std;

int main()
{
  ll n,q;
  cin>>n>>q;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++){
    cin>>a[i];
  }
  ll ans;
  for(ll i = 0; i < q; i++){
    ll num;
    cin>>num;
    ll ans;
    if(num >= a[n-1]){
      ans = num + n;
    }else{
      auto iter = lower_bound(a.begin(),a.end(),num);
      num += distance(a.begin(),iter);
      for(auto iter2 = iter; iter2 != a.end(); iter2++){
        if(num < *iter2){
          ans = num;
          break;
        }else{
          num++;
          ans = num;
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
};


#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, 1}, dy[4] = {0, 0, 1, 1};
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) cin >> S[i];
    int ans = 0;
    for(int i = 0; i < H - 1; i++){
        for(int j = 0; j < W - 1; j++){
            int cnt = 0;
            for(int k = 0; k < 4; k++){
                int nx = i + dx[k], ny = j + dy[k];
                if(S[nx][ny] == '#') cnt++;
            }
            if(cnt % 2 == 1) ans++;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

long long Seigenjikan=50000;//1800000;//実行時間1000000で1秒
long long Seigenjikan2=1900000;//1800000;//実行時間1000000で1秒
long long time_s;
clock_t endt,start;
int t[100][100];//入力受け取りタイルセット
int p[100][100];//タイルの得点
vector<int>used(2525,0);//タイルセットの使用を確認
int vx[4]={-1,1,0,0};
int vy[4]={0,0,-1,1};
char moji[4]={'U','D','L','R'};
int tmp_score,best_score;
string tmp_ans,best_ans;

void dfs(int x,int y){
  //時間を計測
  endt = clock();
  time_s = endt - start;
  if(time_s>Seigenjikan)return;
  used[t[x][y]]=1;
  tmp_score+=p[x][y];
  if(tmp_score>best_score){
    best_ans=tmp_ans;
    best_score=tmp_score;
  }
  rep(i,4){
    if(x+vx[i]<0||x+vx[i]>49||y+vy[i]<0||y+vy[i]>49)continue;
    if(used[t[x+vx[i]][y+vy[i]]]==1)continue;
    tmp_ans.push_back(moji[i]);
    dfs(x+vx[i],y+vy[i]);
  }
  used[t[x][y]]=0;
  tmp_ans.pop_back();
  return;
}
int main(){
  start = clock();
  int si,sj,tmp_score,best_score=0;
  string ans="",A="";
  cin>>si>>sj;
  int x=si;
  int y=sj;
  rep(i,50)rep(j,50)cin>>t[i][j];
  rep(i,50)rep(j,50)cin>>p[i][j];

  dfs(x,y);
  cout<<best_ans<<endl;
  return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <string>
#include <list>
using namespace std;

long long min(long long int a,long long int b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void f(vector<vector<int>>& a,vector<vector<int>>& b,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[k][i]+a[k][j]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                b[i][j]=1;
                b[j][i]=1;
            }
        }
    }
}

void g(vector<vector<int>>& a,vector<vector<int>>& c,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[i][k]+a[j][k]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                c[i][j]=1;
                c[j][i]=1;
            }
        }
    }
}

int h(vector<vector<int>>& b,vector<int>& x,int N){
    int M=1;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        a[i]=0;
    }
    stack<int> d;
    for(int i=0;i<N;i++){
        int j=0;
        if(a[i]==0){
            d.push(i);
            a[i]=1;
        }
        while(!d.empty()){
            int k=d.top();
            d.pop();
            j+=1;
            for(int l=0;l<N;l++){
                if(b[k][l]==1 && a[l]==0){
                    d.push(l);
                    a[l]=1;
                }
            }
        }
        if(j>1){
            x.push_back(j);
            M=max(M,j);
        }
    }
    return M;
}

int main(){
    long long int N;
    cin>>N;
    vector<long long int> A(N),B(N+1),C(N+1),D(N+1);
    for(long long int i=0;i<N;i++){
        cin>>A[i];
        B[i]=0LL;
        C[i]=0LL;
    }
    for(long long int i=1;i<N+1;i++){
        B[i]=B[i-1]+A[i-1];
        C[i]=max(C[i-1],B[i]);
    }
    D[0]=0LL;
    long long int ans=0;
    for(long long int i=1;i<N+1;i++){
        D[i]=D[i-1]+B[i];
        ans=max(ans,D[i]);
    }
    for(long long int i=0;i<N;i++){
        ans=max(ans,D[i]+C[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<int64_t> B(N);
    int64_t sum = 0;
    for (int i = 0; i < N; i++) {
        sum = sum + A[i];
        B[i] = sum;
    }

    vector<int64_t> C(N);
    int64_t maxC = 0;
    sum = 0;
    for (int i = 0; i < N; i++) {
        sum = sum + A[i];
        if (sum > maxC) {
            maxC = sum;
        }
        C[i] = maxC;
    }

    int64_t max = 0;
    int64_t count = 0;
    for (int i = 0; i < N; i++) {
        if (count + C[i] > max) {
            max = count + C[i];
        }
        count = count + B[i];
    }
    cout << max << endl;
}


/**
*    author:  tomo0608
*    created: 27.02.2021 21:15:09
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

void solve(){
    ll K;cin >> K;
    string s,t;cin >> s >> t;
    V<int> cards(10, 0), cardt(10, 0);
    rep(i,4){
        cards[s[i] - '0']++;
        cardt[t[i] - '0']++;
    }
    ld ans = 0;
    int sum = 0;
    rep2(i, 1, 10)rep2(j, 1, 10){
        cards[i]++;
        cardt[j]++;
        ll now_s = 0, now_t = 0;
        bool check = true;
        rep(k,10){
            now_s += k * mypow(10, cards[k]);
            now_t += k * mypow(10, cardt[k]);
            if(K - cards[k] - cardt[k] < 0)check = false;
        }
        if(check)sum++;
        cards[i]--;
        cardt[j]--;
        if(check && now_s > now_t){
            //cout << i << ' ' << j << endl;
            ans += ((ld)(K - cards[i] - cardt[i]) * (K - cards[j] - cardt[j] - (i == j)))/ ((9*K - 8) * (9*K - 9));
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (C * D - B == 0)cout << -1;
	if (C * D - B < 0)cout << -1;
	if (C * D - B > 0){
		int N = A / (C * D - B);
		if (A % (C * D - B) != 0)cout << N + 1;
		if (A % (C * D - B) == 0)cout << N;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#include <iomanip>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(vec) (vec).begin(),(vec).end()

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))
#define sz(v) ((ll)(v).size())
#define bit(n) (1LL<<n)

double pi=3.14159265358979323846;

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,double> pld;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	rep(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	for(T p:z)os << p << ", " ;
	//each(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	//each(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	for(auto p:z)os << (p.first) << ": " << (p.second) << ", " ;
	return ( os << "}" << endl);
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

ll mod = 1000000007;

vector<string> S;
vector<vi> reach;

void rec(int oldv, int v){
	if(reach[oldv][v])return;
	reach[oldv][v] = 1;
	rep(v2,S.size()){
		if(S[v][v2]=='1'){
			rec(oldv,v2);
		}
	}
}

void _main(istream &inp){
	ll N;
	inp >> N;
	rep(i,N){
		string s;
		inp >> s;
		S.push_back(s);
	}
	reach = vector<vi>(N, vi(N));
	rep(v,N) rec(v,v);
	double ret = 0;
	rep(i,N){
		ll u = 0;
		rep(j,N) if(i!=j && reach[j][i])u++;
		ret += 1.0/(1.0+u);
	}
	cout << fixed << setprecision(15);
	cout << ret << endl;

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &vec)
    {
        for (auto &value : vec)
            is >> value;
        return is;
    }

}

#include <experimental/optional>

namespace asl
{

    template <typename T>
    std::vector<std::vector<T>> board(int n = 0, int m = 0)
    {
        return std::vector<std::vector<T>>(n, std::vector<T>(m));
    }

}

#include <utility>

#include <tuple>

#include <random>

#define endl '\n'

using namespace std;
using namespace asl;

void solve()
{
    int n;
    cin >> n;
    vec<string> b(n);
    cin >> b;
    auto a = board<int>(n, n);

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            a[i][j] = b[i][j] == '1' | (i == j);

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                a[i][j] |= a[i][k] & a[k][j];

    long double res = 0;

    for (int i = 0; i < n; ++i)
    {
        int t = 0;
        for (int j = 0; j < n; ++j)
            t += a[j][i];
        res += 1. / t;
    }
    cout << res << endl;
}

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

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}


#include <iostream>
using namespace std;

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

  if (A+B >= 15 && B >= 8) {
	  cout << 1 << endl;
  } else if (A+B >= 10 && B >= 3) {
	  cout << 2 << endl;
  }else if (A+B >= 3) {
	  cout << 3 << endl;
  }else {
	  cout << 4 << endl;
  }
}

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

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

	int a, b, sum = 0;
	while(cin >> a >> b){
		sum += a + b;
		if(sum >= 15 and b >= 8)
			cout << "1\n";
		else if(sum >= 10 and b >= 3)
			cout << "2\n";
		else if(sum >= 3)
			cout << "3\n";
		else
			cout << "4\n";
	}
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
ll a[66];
ll n;
int main(void)
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		if(s=="OR") a[i]=1;
		else a[i]=0;
	}
	ll ans=0;
	a[0]=1;
	for(ll i=n;i>=0;i--)
	{
		if(a[i]==1) ans+=(1ll<<i);
	}
	printf("%lld\n",ans);
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const ll LLMAX = (1llu<<(sizeof(ll)*8-1)) - 1;
const int IMAX = (1llu<<(sizeof(int)*8-1)) - 1;

int N;
string s[100];

ull dp[100][2];

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> s[i];
  }
  // 0 = false, 1 = true;
  dp[0][0] = 1;
  dp[0][1] = 1;
  for(int i = 1; i <= N; i++){
    if(s[i-1][0] == 'A'){
      dp[i][0] = dp[i-1][0] * 2 + dp[i-1][1];
      dp[i][1] = dp[i-1][0] * 0 + dp[i-1][1];
    } else{
      dp[i][0] = dp[i-1][0];
      dp[i][1] = dp[i-1][0] + dp[i-1][1] * 2;
    }
    // for(int r = 0; r <= i; r++){
    //   for(int c = 0; c <= 1; c++){
    //     cerr << dp[r][c] << "\t";
    //   }
    //   cerr << endl;
    // }
  }
  cout << dp[N][1] << endl;
  return 0;
}


//Time to take charge!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MAX 200110LL
#define MOD 1000000007LL
#define INF 1000000000000000000LL

ll modularExp(ll x, ll n) {
    x %= MOD;
    if (n == 0) {
        return 1;
    }else if (n & 1) {
        return (x * (modularExp((x * x) % MOD, n / 2)) % MOD) % MOD;
    }else{
        return modularExp((x * x) % MOD, n / 2) % MOD;
    }
}

ll modularInverse(ll x) {
    return modularExp(x, MOD - 2) % MOD;
}

ll ftA[MAX], ftB[MAX];
ll ftASum[MAX], ftBSum[MAX];

void update(ll i, ll val, ll ft[]){
      while(i < MAX){
            ft[i] += val;
            i += (i & (-i));
      }
}

ll query(ll i, ll ft[]){
      ll ret = 0;
      while(i > 0){
            ret += ft[i];
            i -= (i & (-i));
      }
      return ret;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif

    ll t = 1;
    //cin>>t;
    while (t--) {
        ll n, m, q;
        cin>>n>>m>>q;
        ll t[q], x[q], y[q];
        set <ll> cc;
        cc.insert(0);
        for (ll i = 0; i < q; i++) {
            cin>>t[i]>>x[i]>>y[i];
            cc.insert(y[i]);
        }
        map <ll, ll> ind;
        ll index = 1;
        for (ll it: cc) {
            ind[it] = (index++);
        }
        memset(ftA, 0, sizeof(ftA));
        memset(ftB, 0, sizeof(ftB));
        memset(ftASum, 0, sizeof(ftASum));
        memset(ftBSum, 0, sizeof(ftBSum));
        ll a[n + 10] = {}, b[m + 10] = {};
        for (ll i = 1; i <= n; i++) {
            update(ind[0], 1, ftA);
        }
        for (ll i = 1; i <= m; i++) {
            update(ind[0], 1, ftB);
        }
        ll ans = 0;
        ll prev;
        for (ll i = 0; i < q; i++) {
            if (t[i] == 1) {
                prev = a[x[i]];
                ans -= (prev * query(ind[prev] - 1, ftB));
                ans -= (query(MAX - 1, ftBSum) - query(ind[prev] - 1, ftBSum));
                update(ind[prev], -1, ftA);
                update(ind[prev], (-1 * prev), ftASum);

                a[x[i]] = y[i];
                ans += (y[i] * query(ind[y[i]] - 1, ftB));
                ans += (query(MAX - 1, ftBSum) - query(ind[y[i]] - 1, ftBSum));
                update(ind[y[i]], 1, ftA);
                update(ind[y[i]], y[i], ftASum);
            } else {
                prev = b[x[i]];
                ans -= (prev * query(ind[prev], ftA));
                ans -= (query(MAX - 1, ftASum) - query(ind[prev], ftASum));
                update(ind[prev], -1, ftB);
                update(ind[prev], (-1 * prev), ftBSum);

                b[x[i]] = y[i];
                ans += (y[i] * query(ind[y[i]], ftA));
                ans += (query(MAX - 1, ftASum) - query(ind[y[i]], ftASum));
                update(ind[y[i]], 1, ftB);
                update(ind[y[i]], y[i], ftBSum);
            }
            cout<<ans<<"\n";
        }
    }
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 200010, mod = 1000000007;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
struct Seg{
	int tot,s[maxn*100],v[maxn*100],rt,ls[maxn*100],rs[maxn*100];
	void psp(int k) {s[k]=s[ls[k]]+s[rs[k]],v[k]=v[ls[k]]+v[rs[k]];}
	void ins(int&k,int l,int r,int p,int VL,int VL2)
	{
		if(!k) k=++tot;
		if(l==r) return s[k]+=VL,v[k]+=VL2,void();int mid=l+r>>1;
		p>mid?ins(rs[k],mid+1,r,p,VL,VL2):ins(ls[k],l,mid,p,VL,VL2),psp(k);
	}
	int asks(int k,int l,int r,int L,int R)
	{
		if(l>R||L>r||!k) return 0;
		if(L<=l&&r<=R) return s[k];int mid=l+r>>1;
		return asks(ls[k],l,mid,L,R)+asks(rs[k],mid+1,r,L,R);
	}
	int askv(int k,int l,int r,int L,int R)
	{
		if(l>R||L>r||!k) return 0;
		if(L<=l&&r<=R) return v[k];int mid=l+r>>1;
		return askv(ls[k],l,mid,L,R)+askv(rs[k],mid+1,r,L,R);
	}
}s1,s2;
int ans,n,m,Q,a[maxn],b[maxn];
signed main()
{
	n=read(),m=read(),Q=read();
	s1.ins(s1.rt,0,1e8,0,0,n);
	s2.ins(s2.rt,0,1e8,0,0,m);
	for(int i=1,x,y;i<=Q;cout<<ans<<'\n',i++)
		if(read()==1)
		{
			x=read();
			ans-=s2.asks(s2.rt,0,1e8,a[x]+1,1e8)+a[x]*s2.askv(s2.rt,0,1e8,0,a[x]);
			s1.ins(s1.rt,0,1e8,a[x],-a[x],-1);
			a[x]=read();
			s1.ins(s1.rt,0,1e8,a[x],a[x],1);
			ans+=s2.asks(s2.rt,0,1e8,a[x]+1,1e8)+a[x]*s2.askv(s2.rt,0,1e8,0,a[x]);
		}
		else
		{
			x=read();
			ans-=s1.asks(s1.rt,0,1e8,b[x]+1,1e8)+b[x]*s1.askv(s1.rt,0,1e8,0,b[x]);
			s2.ins(s2.rt,0,1e8,b[x],-b[x],-1);
			b[x]=read();
			s2.ins(s2.rt,0,1e8,b[x],b[x],1);
			ans+=s1.asks(s1.rt,0,1e8,b[x]+1,1e8)+b[x]*s1.askv(s1.rt,0,1e8,0,b[x]);
		}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a[9];
template<typename T>
inline void read(T &x)
{
	x=0;T w=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')w=-1;	c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-'0';	c=getchar();}
	x*=w;
}
int main()
{
	for(LL i=1;i<=4;++i)
		read(a[i]);
	sort(a+1,a+5);
	printf(a[1]+a[4]==a[2]+a[3]||a[1]+a[2]+a[3]==a[4]?"Yes":"No");
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> A(2 * N);
    for(int i = 0; i < 2 * N; i++){
        cin >> A[i];
    }

    vector<pair<int, int>> aIndex(2 * N);
    for(int i = 0; i < 2 * N; i++){
        aIndex[i] = make_pair(A[i], i);
    }

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

    vector<bool> isLower(2 * N, false);
    for(int i = 0; i < N; i++){
        isLower[aIndex[i].second] = true;
    }

    string ans = "";
    int cnt = 0;
    bool lowerOpen = false;
    for(int i = 0; i < 2 * N; i++){
        if(cnt == 0){
            ans += "(";
            cnt++;
            if(isLower[i]){
                lowerOpen = true;
            }
            else{
                lowerOpen = false;
            }
        }
        else{
            if(isLower[i]){
                if(lowerOpen){
                    ans += "(";
                    cnt++;
                }
                else{
                    ans += ")";
                    cnt--;
                }
            }
            else{
                if(lowerOpen){
                    ans += ")";
                    cnt--;
                }
                else{
                    ans += "(";
                    cnt++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=998244353 ;

ll calc(int s, int n){
    if(2* n < s || s<= 1) return 0;
    if(s <= n + 1) return s-1;
    else return 2*n-s+1;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    ll ans = 0;
    rep(i,1000000)ans += calc(i, n)*calc(i+k, n);
    cout<<ans<<endl;
    return 0;
}

/**
 * CODE
 * BY
 * VIKAS VERMA
 *
 * $$Always Check for Constraints
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, n) for (int i = 1; i <= n; i++)
#define fr(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP(l, r) for (int i = l; i < r; i++)
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"
#define jaldi ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef long long ll;
//=======================
const int MOD = 1'000'000'007;
const int N = 2e6 + 13;
//=======================
vi g[N];
int a[N];
//=======================
void solve()
{
  int x, y;
  cin >> x >> y;
  cout << (abs(x - y) < 3 ? "Yes" : "No") << endl;
}

int main()
{
  jaldi
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;

  // cin >> t;

  while (t--)
  {
    solve();
  }

  return 0;
}


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

class xor_shift_128 {
public:
    typedef uint32_t result_type;
    xor_shift_128(uint32_t seed = 42) {
        set_seed(seed);
    }
    void set_seed(uint32_t seed) {
        a = seed = 1812433253u * (seed ^ (seed >> 30));
        b = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
        c = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
        d = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
    }
    uint32_t operator() () {
        uint32_t t = (a ^ (a << 11));
        a = b; b = c; c = d;
        return d = (d ^ (d >> 19)) ^ (t ^ (t >> 8));
    }
    static constexpr uint32_t max() { return numeric_limits<result_type>::max(); }
    static constexpr uint32_t min() { return numeric_limits<result_type>::min(); }
private:
    uint32_t a, b, c, d;
};

constexpr int H = 30;
constexpr int W = 30;

string get_command_from_path(const vector<pair<int, int>>& path) {
    string command;
    assert (not path.empty());
    REP (i, path.size() - 1) {
        auto [ay, ax] = path[i];
        auto [by, bx] = path[i + 1];
        if (by == ay - 1 and bx == ax) {
            command.push_back('U');
        } else if (by == ay + 1 and bx == ax) {
            command.push_back('D');
        } else if (by == ay and bx == ax + 1) {
            command.push_back('R');
        } else if (by == ay and bx == ax - 1) {
            command.push_back('L');
        } else {
            assert (false);
        }
    }
    return command;
}

template <class RandomEngine>
void solve(function<tuple<int, int, int, int> ()> read, function<int64_t (const string&)> write, int K, RandomEngine& gen, chrono::high_resolution_clock::time_point clock_end) {
    chrono::high_resolution_clock::time_point clock_begin = chrono::high_resolution_clock::now();

    REP (query, K) {
        auto [sy, sx, ty, tx] = read();
#ifdef VERBOSE
        cerr << "(" << sy << ", " << sx << ") -> (" << ty << ", " << tx << ")" << endl;
#endif  // VERBOSE

        vector<pair<int, int>> path;
        int y = sy;
        int x = sx;
        path.emplace_back(y, x);
        while (y < ty) {
            y += 1;
            path.emplace_back(y, x);
        }
        while (y > ty) {
            y -= 1;
            path.emplace_back(y, x);
        }
        while (x < tx) {
            x += 1;
            path.emplace_back(y, x);
        }
        while (x > tx) {
            x -= 1;
            path.emplace_back(y, x);
        }

        int64_t score = write(get_command_from_path(path));
    }
}

int main() {
    constexpr auto TIME_LIMIT = chrono::milliseconds(2000);
    chrono::high_resolution_clock::time_point clock_begin = chrono::high_resolution_clock::now();
    xor_shift_128 gen(20210425);
    auto read = [&]() {
        int sy, sx, ty, tx;
        cin >> sy >> sx >> ty >> tx;
        return make_tuple(sy, sx, ty, tx);
    };
    auto write = [&](const string& command) {
        cout << command << '\n';
        cout.flush();
        int64_t dist;
        cin >> dist;
        return dist;
    };
    constexpr int K = 1000;
    solve(read, write, K, gen, clock_begin + chrono::duration_cast<chrono::milliseconds>(TIME_LIMIT * 0.95));
    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

string path(int si, int sj, int ti, int tj){
	int di = ti - si, dj = tj - sj;
	string s;
	if(di >= 0) rep(k,di) s.push_back('D');
	else rep(k,-di) s.push_back('U');
	if(dj >= 0) rep(k,dj) s.push_back('R');
	else rep(k,-dj) s.push_back('L');
	return s;
}

int main(){
	//FILE *outputfile;
	//outputfile = freopen("test.txt", "w", stdout);

	rep(i,1000){
		int si, sj, ti, tj;
		cin >> si >> sj >> ti >> tj;
		string ans = path(si, sj, ti, tj);
		cout << ans << endl;
		LL dist;
		cin >> dist;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

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

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
}

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[2000005],R[2000005];
void make(){
	F[0] = 1;
	for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<2000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
ll a, b;
int pr[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
ll dp[2][(1<<20)];
void solve(){
	cin >> a >> b;
		int cur = 0, nxt = 1;
		dp[cur][0] = 1;
	for(ll i=a;i<=b;i++){
		memset(dp[nxt], 0, sizeof(dp[nxt]));
		int cur_m = 0;
		rep(x, 20){
			if(i % pr[x] == 0) cur_m |= (1<<x);
		}
		rep(j, (1<<20)){
			if(dp[cur][j] == 0) continue;
			add(dp[nxt][j], dp[cur][j]);
			if( (j & cur_m) == 0) add(dp[nxt][j+cur_m], dp[cur][j]);
		}
		swap(cur,nxt);
	}
	ll ans = 0;
	rep(i,(1<<20)) ans += dp[cur][i];o(ans);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

#include <iostream>
#include <vector>

using namespace std;
#define ll long long

vector<int> primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

int main() {
	std::ios::sync_with_stdio(false);
	ll a, b, sol = 0;
	cin >> a >> b;
	vector<ll> dp(1 << 20);

	dp[0] = 1;//the empty set
	int act;
	for (ll x = a; x <= b; ++x) {
		act = 0;
		//activate divisor bits
		for (int i = 0; i < 20; ++i) {
			if (x % primes[i] == 0) act |= (1 << i);
		}

		//if no conflict, count resulting sets
		for (int y = (1 << 20) - 1; y >= 0; --y) {
			if ((act & y) == 0) dp[act | y] += dp[y];
		}
	}

	for (int i = 0; i < (1 << 20); ++i) sol += dp[i];
	cout << sol << '\n';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull maxn=800005;
ull w[maxn];
const ull mod=1e9+7;
ull head[maxn], to[maxn], nex[maxn], val[maxn], cnt, dep[maxn];
void add(ull i, ull j, ull w){
    cnt++;
    to[cnt]=j; val[cnt]=w;
    nex[cnt]=head[i]; head[i]=cnt;
}
void dfs(ull x){
    for(ull i=head[x]; i; i=nex[i]){
        ull y=to[i];
        if(dep[y])
            continue;
        dep[y]=dep[x]+1;
        w[y]=w[x]^val[i];
        dfs(y);
    }
}
signed main(){
    ull n;
    scanf("%llu", &n);
    for(ull i=2; i<=n; i++){
        ull u, v, w;
        scanf("%llu%llu%llu", &u, &v, &w);
        add(v, u, w); add(u, v, w);
    }
    dfs(dep[1]=1);
    ull ans=0;
    for(ull i=0; i<=60; i++){
        ull cnt=0;
        for(ull j=1; j<=n; j++)
            if(w[j]>>i&1) cnt++;
        ans=(ans+(1LL<<i)%mod*cnt%mod*(n-cnt)%mod)%mod;
    }
    ans=(ans%mod+mod)%mod;
    printf("%llu", ans);
    return 0;
}

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

ll mod = 1000000007;

int main() {
    //GraphInput
    ll N; cin >> N;
    Graph G(N+1);
    rep(i,N-1){
        ll a,b,c; cin >> a >> b >> c;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    ll ans = 0;
    rep(i,60){
        //Graph G(N+1);
        ll base = (1LL<<i);
        /*for(auto p:path){
            ll a = get<0>(p), b = get<1>(p), c = get<2>(p);
            if(c&base){
                G[a].push_back(make_pair(b,1));
                G[b].push_back(make_pair(a,1));
            }
            else{
                G[a].push_back(make_pair(b,0));
                G[b].push_back(make_pair(a,0));
            }
        }*/
        ll odd = 0,ev = 1;
        //BFS (普通の幅優先探索)
        queue<int> go; ll dist[N+1]; // ll par[N+1];
        rep(i,N+1){
            dist[i] = 2000000000;
        }
        dist[1] = 0; go.push(1);
        while(!go.empty()){
            int s = go.front(); go.pop();
            for(auto q:G[s]){
                ll x = q.first; ll b = q.second;
                ll a = 0;
                if(b&base) a = 1;
                if(dist[x]<=dist[s]+a) continue;
                dist[x] = dist[s] + a;
                if(dist[x]%2==0) ev++;
                else odd++;
                //par[x] = s;
                go.push(x);
            }
        }
        ans += base%mod*(odd*ev%mod)%mod;
        ans %= mod;
    }
    cout << ans << endl;
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

// union find {{{
class union_find {

    using data_type = int_fast32_t;
    std::vector< data_type > data_;

    public:
    union_find(std::size_t size) : data_(size, -1) {}

    std::size_t size() const {
        return data_.size();
    }

    data_type get_root(data_type x) {
        return (data_[x] < 0 ? x : data_[x] = get_root(data_[x]));
    }

    bool is_root(data_type x) {
        return x == get_root(x);
    }

    bool is_same(data_type x, data_type y) {
        return get_root(x) == get_root(y);
    }

    void unite(data_type x, data_type y) {
        x = get_root(x); y = get_root(y);
        if (x == y) return;

        if (data_[x] > data_[y]) std::swap(x, y);
        data_[x] += data_[y];
        data_[y] = x;
    }

    data_type element_count(data_type x) {
        return -data_[get_root(x)];
    }
};
// }}}

void solver() {
  int n, q;
  cin >> n >> q;

  union_find uf(n);
  vector< map<int, int> > cnt(n);
  range(i, 0, n) {
    int c;
    cin >> c;

    cnt[i][c]++;
  }

  range(query, 0, q) {
    int type;
    cin >> type;

    switch (type) {
      case 1: {
        int a, b;
        cin >> a >> b;

        a = uf.get_root(a - 1);
        b = uf.get_root(b - 1);

        if (uf.is_same(a, b)) continue;

        if (uf.element_count(a) < uf.element_count(b)) {
          swap(a, b);
        }

        uf.unite(a, b);
        for (auto [c, val] : cnt[b]) {
          cnt[a][c] += val;
        }
      } break;

    case 2: {
        int x, y;
        cin >> x >> y;

        x = uf.get_root(x - 1);
        cout << cnt[x][y] << endl;
      } break;
    }
  }
}

signed main(int argc, char *argv[]) {
  solver();
}

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N_MAX = 501;
int M_MAX = 250000;
typedef long long ll;
typedef pair<ll,int> P;
template<class T> void chmin(T &a, T b){if(a>b){a=b;}}
int p[501],id[501],res[250000];
void sw(int m){
  swap(p[res[m]],p[res[m]+1]);
  id[p[res[m]]]=res[m];
  id[p[res[m]+1]]=res[m]+1;
  return;
}
int main()
{
  int n,i,j,t,tt,m;
  cin >> t;
  for(tt=0;tt<t;tt++){
    m=0;
    cin >> n;
    for(i=0;i<n;i++){
      cin >> p[i];
      id[p[i]]=i;
    }
    if(n==2){
      if(p[0]==1){
        cout << "0" << endl;
      }else{
        cout << "1" << endl;
        cout << "1" << endl;
      }
      continue;
    }
    for(i=1;i<=n-4;i++){
      if(p[i-1]==i)
        continue;
      if((id[i]+m)%2==0){
        if(id[i]<=i)
          res[m]=id[i]+2;
        else
          res[m]=id[i]-2;
        sw(m);
        m++;
      }
      while(p[i-1]!=i){
        res[m]=id[i]-1;
        sw(m);
        m++;
      }
    }
    if(i==n-3){
      for(j=0;j<7;j++){
        if(p[i-1]==i)
          break;
        if((m+n-4)%2==0){
          if(p[n-1]==i)
            res[m]=n-2;
          else
            res[m]=n-4;
        }else{
          res[m]=n-3;
        }
        sw(m);
        m++;
      }
    }
    for(j=0;j<5;j++){
      if(p[n-3]==n-2 && p[n-2]==n-1 && p[n-1]==n)
        break;
      if((m+n-3)%2==0)
        res[m]=n-3;
      else
        res[m]=n-2;
      sw(m);
      m++;
    }
    cout << m << endl;
    for(i=0;i<m;i++)
      cout << res[i]+1 << " ";
    cout << endl;
  }
  return 0;
}


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

int h, w, a, b;

ll hanjo(vector<vector<bool>>& heya, int i, int j, int a, int b){
    if(a < 0 || b < 0) return 0;
    if(j >= w){ j = 0; ++i; }
    if(i >= h) return 1;
    if(heya[i][j]) return hanjo(heya, i, j+1, a, b);

    ll ans = 0;
    heya[i][j] = true;
    ans += hanjo(heya, i, j+1, a, b-1);
    heya[i][j] = false;

    if(j + 1 < w && !heya[i][j+1]){
        heya[i][j] = true;
        heya[i][j+1] = true;
        ans += hanjo(heya, i, j+1, a-1, b);
        heya[i][j] = false;
        heya[i][j+1] = false;
    }
    if(i + 1 < h && !heya[i+1][j]){
        heya[i][j] = true;
        heya[i+1][j] = true;
        ans += hanjo(heya, i, j+1, a-1, b);
        heya[i][j] = false;
        heya[i+1][j] = false;
    }
    return ans;
}

int main(){
    cin >> h >> w >> a >> b;
    vector<vector<bool>> heya(h, vector<bool>(w, false));
    cout << hanjo(heya, 0, 0, a, b) << endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <unordered_set>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0;i<(int)n;i++)

struct Edge {
  int to; // 隣接頂点番号
  long long w; // 重み
  Edge(int to, long long w) : to(to), w(w) {}
};
// using Graph = vector<vector<Edge> >
// using Graph = vector<vector<int> >

struct UnionFind {
  vector<int> par, siz;

  UnionFind(int n) : par(n, -1), siz(n, 1) {}

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

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

  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;

    if(siz[x] < siz[y]) swap(x, y);

    par[y] = x;
    siz[x] += siz[y];
    return true;
  }

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

long long factorial(long long n) {
  if(n <= 0) return 1;

  long long fact = 0;
  for(long long i=1;i<=n;i++) fact *= i;
  return n;
}

long long aCb(long long a, long long b) {
  if(a < b) return 0;
  return factorial(a) / (factorial(a-b) * factorial(b));
}

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

  ll pA = abs(A), pB = abs(B);

  if(C % 2 == 0) {
    if(pA == pB) cout << "=";
    if(pA > pB) cout << ">";
    if(pA < pB) cout << "<";
  } else {
    if(A == B) cout << "=";
    if(A > B) cout << ">";
    if(A < B) cout << "<";
  }
}