#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(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; }
typedef long long ll;
using namespace std;
ll mod=1000000000000000000;
long long modpow(long long a, long long n){
  long long r = 1;
  while (n) {
    r = r * ( (n%2)?a:1 ) %mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}
int main(void){
    sp(10);
    ll k;cin>>k;
    string s,t;cin>>s>>t;
    long double res=0;
    map<ll,ll> mp1,mp2,mp3;
    for(ll i=1;i<=9;i++){
        mp1[i]=mp2[i]=0;
    }
    rep(i,s.size()){
        mp1[s[i]-'0']++;
        mp2[t[i]-'0']++;
        mp3[s[i]-'0']++;
        mp3[t[i]-'0']++;
    }
    
    //手札は多くても5枚まで
    for(ll a=1;a<=9;a++){
        for(ll b=1;b<=9;b++){
            if(mp3[a]==k||mp3[b]==k||(a==b&&mp3[a]==k-1))continue;
            ll buf1=0,buf2=0;
            for(auto& p:mp1){
                ll buf=p.first;
                ll c=p.second,d=mp2[buf];
                if(buf==a)c++;
                if(buf==b)d++;
                buf1+=buf*modpow(10,c);
                buf2+=buf*modpow(10,d);
            }
            //cout<<a<<" "<<b<<" ";
            //cout<<buf1<<" "<<buf2<<endl;
            //cout<<k-mp3[a]<<" "<<k-mp3[b]<<endl;
            long double buf=9*k-8;
            buf=(a==b)? ((k-mp3[a])/buf)*((k-mp3[b]-1)/(buf-1)) : ((k-mp3[a])/buf)*((k-mp3[b])/(buf-1));
            //cout<<buf<<endl;
            if(buf1>buf2){
                res+=buf;
            }
        }
    }
    cout<<res<<endl;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 3e5 + 5;

int n, k;
int a[N];

void readTest(){
    cin >> n >> k;
    ForE(i, 1, n){
        cin >> a[i];
    }
}

ll ans, cur;
ll cnt[N];

void resetTest(){
    cur = k;
    ForE(i, 1, n){
        cnt[a[i]]++;
    }
}

void solveTest(){
    For(i, 0, n){
        cur = min(cur, cnt[i]);
        ans += cur;
    }
    cout << ans << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("B.inp", "r", stdin);
    // freopen("B.out", "w", stdout);
// int q; cin >> q; while (q--){
    readTest();
    resetTest();
    solveTest();
// }
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/