#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define N 214514
#define all(x) (x).begin(), (x).end()
const ll mod = 1000000007;
const ll inf = 1000000000000000000;

int main() {
    vector<ll> cnt(10);
    ll k;
    cin >> k;
    for (int i = 1; i <= 9; i++) cnt[i] = k;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < 4; i++) {
        cnt[s[i] - '0']--;
        cnt[t[i] - '0']--;
    }
    long double sum = (9 * k - 8) * (9 * k - 9), num = 0.0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if ((i == j && cnt[i] < 2) ||
                (i != j && (cnt[i] < 1 || cnt[j] < 1)))
                continue;
            ll score_a = 0, score_t = 0;
            vector<ll> ca(10), ct(10);
            for (int i = 0; i < 4; i++) {
                ca[t[i] - '0']++;
                ct[s[i] - '0']++;
            }
            ca[i]++;
            ct[j]++;
            for (int i = 1; i <= 9; i++) {
                score_a += pow(10, ca[i]) * i;
                score_t += pow(10, ct[i]) * i;
            }
            if (score_t > score_a) {
                if (i == j)
                    num += (long double)cnt[i] * (cnt[i] - 1.0);
                else
                    num += (long double)cnt[i] * cnt[j];
            }
        }
    }
    cout << fixed << setprecision(15) << num / sum << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    long long val(){
        return x;
    }
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(long long n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(long long n, long long k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

void Main(){
    int N,M; cin >> N >> M;
    int S = 0;
    VL A(N); REP(i,N) cin >> A[i], S+=A[i];
    if(M<S){
        cout << 0 << en;
        return;
    }

    mint ans(1);
    REP(i,N+S){
        ans *= M+N-i;
    }
    REP(i,N+S){
        ans /= i+1;
    }
    cout << ans.val() << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}