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

int main(){
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    int Q, R, S;
    Q = x * 2;
    //同じ階の場合
    if(a == b) cout << x << endl;
    //下りの場合
    else if(a > b){
        R = a - b - 1;
        cout << min(R * y + x, R * Q + x) << endl;
    }
    //上りの場合
    else{
        S = b - a;
        cout << min(S * y + x, S * Q + x) << endl;
    }

    
}
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

long long power(long long base, long long val)
{
    int ans = 1;
    for (long long i = 0; i < val; ++i) {
        ans *= base;
    }
    return ans;
}

long long count_point(long long n1, long long n2, long long n3, long long n4, long long n5)
{
    vector<long long> counts(9, 0);
    counts[n1 - 1]++;
    counts[n2 - 1]++;
    counts[n3 - 1]++;
    counts[n4 - 1]++;
    counts[n5 - 1]++;

    long long cnt = 0;
    for (long long i = 0; i < 10; ++i) {
        cnt += (i + 1) * power(10, counts[i]);
    }
    return cnt;
}

int main()
{
    long long K;
    string S, T;
    cin >> K;
    cin >> S;
    cin >> T;
    unordered_map<int, long long> num_cards;
    vector<long long> Snumbers;
    vector<long long> Tnumbers;
    for (long long i = 1; i <= 9; ++i)
        num_cards[i] = K;

    for (long long i = 0; i < 4; ++i) {
        long long Snumber = S[i] - '0';
        long long Tnumber = T[i] - '0';
        num_cards[Snumber]--;
        num_cards[Tnumber]--;
        Snumbers.push_back(Snumber);
        Tnumbers.push_back(Tnumber);
    }

    long double win_rate = 0;

    for (long long i = 1; i <= 9; ++i) {
        if (num_cards[i] <= 0)
            continue;
        for (long long j = 1; j <= 9; ++j) {
            if (num_cards[j] <= 0)
                continue;
            if (num_cards[j] == 1 && i == j)
                continue;
            long long Spoint = count_point(Snumbers[0], Snumbers[1], Snumbers[2], Snumbers[3], i);
            long long Tpoint = count_point(Tnumbers[0], Tnumbers[1], Tnumbers[2], Tnumbers[3], j);
            // cout << Spoint << endl;
            // cout << Tpoint << endl;
            if (Spoint > Tpoint) {
                if (i == j)
                    win_rate += num_cards[i] * (num_cards[i] - 1);
                else
                    win_rate += num_cards[i] * num_cards[j];
            }
        }
    }

    cout << setprecision(16) << win_rate / ((9 * K - 8) * (9 * K - 9)) << endl;

    return 0;
}