#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    stack<pair<int,int>> st;
    st.push({v[0],0});
    vector<int> right(n,-1);
    vector<int> left(n,-1);
    for(int i=1;i<n;i++){
        while(!st.empty() && st.top().first>v[i]){
            right[st.top().second]=i;
            st.pop();
        }
        st.push({v[i],i});
    }
    while(!st.empty()){
        st.pop();
    }
    st.push({v[n-1],n-1});
    for(int i=n-2;i>=0;i--){
        while(!st.empty() && st.top().first>v[i]){
            left[st.top().second]=i;
            st.pop();
        }
        st.push({v[i],i});
    }
    int ans=0;
    for(int i=0;i<n;i++){
         if(left[i]==-1 && right[i]==-1){
            ans=max(ans,v[i]*n);
         }
         else if(left[i]==-1 && right[i]!=-1){
            ans=max(ans,v[i]*right[i]);
         }
         else if(right[i]==-1 && left[i]!=-1){
            ans=max(ans,v[i]*(n-left[i]-1));
         }
         else{
            ans=max(ans,v[i]*(right[i]-left[i]-1));
         }
    }
    cout<<ans<<endl;
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int cnt[10];

int calc_points(string s)
{
	//cout << "b";
	int res = 0;
	vector<int> c(10,0);
	rep(i,5)
	{
		c[s[i]-'0']++;
	}
	for (int i = 1; i <= 9; ++i)
	{
		int t = i;
		rep(j,c[i])
		{
			t *= 10;
		}
		res += t;
	}
	//cout << "c";
	return res;
}

int main()
{
	int K;
	cin >> K;
	rep(i,9)
	{
		cnt[i+1] = K;
	}
	string S,T;
	cin >> S >> T;
	rep(i,4)
	{
		cnt[S[i]-'0']--;
		cnt[T[i]-'0']--;

	}
	double ans = 0.0;
	for (int i = 1; i <= 9; ++i)
	{
		if (cnt[i] < 1) continue;
		char new_c = '0'+i;
		S[4] = new_c;
		int S_point = calc_points(S);
		for (int j = 1; j <= 9; ++j)
		{
			if ((i == j && cnt[j] < 2) || (i != j && cnt[j] < 1)) continue;
			char new_c2 = '0'+j;
			T[4] = new_c2;
			int T_point = calc_points(T);
			if (S_point > T_point)
			{
			 	if (i != j) ans += double(cnt[i])/double(9*K-8) * double(cnt[j])/double(9*K-9);
				else ans += double(cnt[i])/double(9*K-8) * double(cnt[j]-1)/double(9*K-9);
			}
		}
		//cout << "a";
	}
	cout << setprecision(10) << ans << endl;
	return 0;
}