Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: mantaggez

Problemset: ดีกค์เวิร์ด

Language: cpp

Time: 0.021 second

Submitted On: 2026-03-23 20:07:45

#include <bits/stdc++.h>

using namespace std;

int n, ans;
string c1, c2;

void recur(string str, int f, int s)
{
    if(f > n || s > n) return ;
    if(f == n && s == n) {
        int sum = 0;
        for(int i=1;i<=2*n;i++) ans += (i * (str[i - 1] - 'A' + 1));
        return ;
    }

    if(f == s) {
        recur(str + c1, f + 1, s);
    }
    else if(f > s) {
        recur(str + c1, f + 1, s);
        recur(str + c2, f, s + 1);
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n >> c1 >> c2;
    recur("", 0, 0);
    cout << ans << '\n';
    return 0;
}