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

const int N = 3005;
int a[N];
int pre[N][N] = {{0}};

int sum[N][N] = {0};
int cur[N];

const int M = 1e9 + 7;

void add (int &a, int b) {
    a += b;
    if (a >= M) a -= M;
}

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        for (int mod = 1; mod <= n; ++mod) {
            pre[i][mod] = (pre[i - 1][mod] + a[i]) % mod;
        }
    }

    add(sum[0][0], 1);
    for (int i = 1; i <= n; ++i) {
        memset(cur, 0, sizeof cur);
        for (int block = 1; block <= i; ++block) {
            add(cur[block], sum[block - 1][pre[i][block]]);
        }
        for (int block = 1; block <= i; ++block) {
            add(sum[block][pre[i][block + 1]], cur[block]);
        }
    }
    int ans = 0;
    for (int block = 1; block <= n; ++block)
        add(ans, cur[block]);
    cout << ans;
}

// #pragma GCC optimize("O2")
#include <bits/stdc++.h>
// #include "D:/program_learning/vs_code/workplace/ACMtemplate/data_structure/CompleteBinaryHeap.hpp"
// #include "D:/program_learning/vs_code/workplace/ACMtemplate/math/Prime.hpp"
using namespace std;

#define mp make_pair
#define phb push_back
#define ppb pop_back
#define eb emplace_back
#define pp pop
#define ph push
#define ff first
#define ss second
#define htl(v, n) (v)+1,(v)+1+(n), greater<decltype((v)[1])>()
#define lth(v, n) (v)+1,(v)+1+(n), less<decltype((v)[1])>()
#define Max(a, b) (((a) > (b)) ? (a) : (b))
#define Min(a, b) (((a) < (b)) ? (a) : (b))
#define isZero(x) ((x)>0?(x):-(x)<eps)
#define isEqual(x, y) (abs((x)-(y))<eps)
#define FOR(i, a, b) for(ll i = (a); i <= (b); i++)
#define gFOR(i, a) for(ll i = h[(a)] ; ~i ; i = ne[i])
#define iFOR(it, begin, end) for(auto it = (begin); it!=(end);it++)
#define rFOR(i, a, b) for(ll i = (a); i >= (b); i--)
#define vFOR(it, a) for(auto it = a.begin();it != a.end();it++)
#define aFOR(a, s) for(auto & (a) : (s))
#define pFOR(i, j, l, r, sit) for(int i = l,j = r; sit ;i++, j--)
#define DEBUG(x) cout << #x << " = " << (x) << endl
#define checktime() cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" ; system("pause")
#define endl "\n"
#define faster_cpp_io() std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define setp(n) fixed << setprecision(n)
#define setINF(b) memset((b), 0x3f, sizeof(b))
#define set0(b) memset((b), 0, sizeof(b))
#define set1(b) memset((b), -1, sizeof(b))
#define cases(t,i) int t;cin >> t;for(int i = 1;i<=t;i++)

using pll = pair<long long,long long>;
using pii = pair<int,int>;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using vs = vector<string>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mll = map<long long, long long>;
using umll = unordered_map<long long, long long>;

template<typename T>
T qpow(T x, T n, const T& mod){
    return ( (n == 0) ? 1 : ( (n & 1) ? (x % mod * qpow(x % mod * x % mod, n >> 1, mod) ) : ( qpow(x % mod * x % mod, n >> 1, mod) ) ) ) % mod;
}

constexpr int INF32 = 0x3f3f3f3f;
constexpr ll INF64 = 0x3f3f3f3f3f3f3f3f;
constexpr ll mod = 1e4 + 7;
constexpr ld eps = 1e-9;
constexpr ld pi = acos(-1);
constexpr ll cap = 1e5+5;

ll score(string s){
    vector<ll> cnt(10);
    iota(cnt.begin(),cnt.end(),0);
    for(char c:s){
        cnt[c-'0'] *= 10;
    }
    return accumulate(cnt.begin(),cnt.end(),0);
}

void solve(){
    ll k;
    string s,t;
    cin >> k >> s >> t;
    vector<ll> cnt(10,k);
    for(char c: s+t){
        cnt[c-'0']--;
    }
    ll win = 0;
    for(ll i=1;i<=9;i++){
        for(ll j=1;j<=9;j++){
            s.back() = '0' + i;
            t.back() = '0' + j;
            if (score(s) <= score(t))
                continue;
            win += cnt[i] * (cnt[j] - (i == j));
        }
    }
    ll rem = 9*k - 8;
    cout << double(win) / rem / (rem-1) << endl;
}
    

int main()
{
	faster_cpp_io();

    // cases(t,i)
    solve();

    // checktime();
    return 0;
}