QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#496207#6557. LCSLCSLCSpandapythonerTL 123ms10972kbC++236.6kb2024-07-28 04:14:022024-07-28 04:14:02

Judging History

你现在查看的是最新测评结果

  • [2024-07-28 04:14:02]
  • 评测
  • 测评结果:TL
  • 用时:123ms
  • 内存:10972kb
  • [2024-07-28 04:14:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using ll = long long;

#define int ll
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) (int(a.size()))
#define assert(a) if(!(a)) {while(true){}}


const ll inf = 1e18;
mt19937 rnd(234);



ll solve(ll n, ll m, string a, string b, bool stupid = false) {
    string na, nb;
    for (auto x : a) {
        if (find(all(b), x) != b.end()) {
            na.push_back(x);
        }
    }
    for (auto x : b) {
        if (find(all(a), x) != a.end()) {
            nb.push_back(x);
        }
    }
    a = na;
    b = nb;
    if (a.empty() or b.empty()) {
        return 0;
    }
    if (stupid) {
        na = "";
        rep(i, n) na += a;
        n = 1;
        a = na;
    }

    int s = len(a);
    int t = len(b);
    vector<ll> p(t);
    rep(i, t) p[i] = i;
    for (int i = 0; i < s; i += 1) {
        int first_same = -1;
        rep(j, t) if (a[i] == b[j]) { first_same = j; break; }
        assert(first_same != -1);
        vector<ll> np(t);
        for (int l = first_same; ; ) {
            int r = (l + 1) % t;
            while (a[i] != b[r]) {
                r = (r + 1) % t;
            }
            ll cur = p[l];
            if (l == t - 1) {
                cur -= t;
            }
            for (int j = (l + 1) % t; j != r; j = (j + 1) % t) {
                ll val = p[j];
                assert(val != cur);
                if (val < cur) {
                    np[j] = cur;
                    cur = val;
                } else {
                    np[j] = val;
                }
                if (j == t - 1) {
                    cur -= t;
                }
            }
            np[r] = cur;
            if (r == first_same) {
                break;
            }
            l = r;
        }
        p = np;
    }
    auto check_perm = [&](vector<ll> x) {
        for (auto& v : x) {
            v = ((v % t) + t) % t;
        }
        sort(all(x));
        rep(i, t) if (x[i] != i) return false;
        return true;
        };
    assert(check_perm(p));
    auto merge = [&](const vector<ll>& p, const vector<ll>& q) {
        vector<ll> invq(t, t);
        rep(i, t) {
            ll val = q[i];
            ll r = ((val % t) + t) % t;
            ll d = (val - r) / t;
            assert(d <= 0);
            invq[r] = (-d) * t + i;
        }
        // assert(check_perm(invq));
        vector<ll> biba, boba;
        vector<ll> base;
        rep(i, t) {
            biba.push_back(p[i]);
            biba.push_back(p[i] + t);
            base.push_back(p[i] + t);
            biba.push_back(p[i] + 2 * t);

            boba.push_back(invq[i]);
            boba.push_back(invq[i] + t);
            boba.push_back(invq[i] + 2 * t);
        }
        sort(all(biba));
        sort(all(boba));
        sort(all(base));
        biba.resize(unique(all(biba)) - biba.begin());
        boba.resize(unique(all(boba)) - boba.begin());
        base.resize(unique(all(base)) - base.begin());
        assert(len(biba) == 3 * t);
        assert(len(boba) == 3 * t);
        assert(len(base) == t);
        vector<ll> a(3 * t), b(3 * t);
        rep(i, t) {
            a[i] = lower_bound(all(biba), p[i]) - biba.begin();
            a[i + t] = lower_bound(all(biba), p[i] + t) - biba.begin();
            a[i + 2 * t] = lower_bound(all(biba), p[i] + 2 * t) - biba.begin();

            b[lower_bound(all(boba), invq[i]) - boba.begin()] = i;
            b[lower_bound(all(boba), invq[i] + t) - boba.begin()] = i + t;
            b[lower_bound(all(boba), invq[i] + 2 * t) - boba.begin()] = i + 2 * t;
        }
        vector<pair<int, int>> swaps;
        while (true) {
            bool flag = false;
            for (int i = 0; i + 1 < 3 * t; i += 1) {
                if (b[i] > b[i + 1]) {
                    swaps.push_back(make_pair(i, i + 1));
                    swap(b[i], b[i + 1]);
                    flag = true;
                }
            }
            if (!flag) {
                break;
            }
        }
        reverse(all(swaps));
        for (auto [i, j] : swaps) {
            if (a[i] < a[j]) {
                swap(a[i], a[j]);
            }
        }
        vector<ll> result(t, t);
        rep(i, 3 * t) {
            int j = a[i];
            ll x = biba[j];
            if (binary_search(all(base), x)) {
                ll y = boba[i];
                ll ry = (y % t + t) % t;
                result[ry] = (x - (y - ry));
            }
        }
        assert(check_perm(result));
        return result;
        };
    function<vector<ll>(const vector<ll>&, int)> bin_pow;
    bin_pow = [&](const vector<ll>& p, int n) {
        if (n == 0) {
            vector<ll> res(t); rep(i, t) res[i] = i; return res;
        }
        auto a = bin_pow(p, n / 2);
        a = merge(a, a);
        if (n & 1) {
            a = merge(a, p);
        }
        return a;
        };
    auto q = bin_pow(p, n);
    ll result = 0;
    rep(i, t) {
        if (q[i] >= 0) {
            continue;
        }
        ll f = (-q[i] + t - 1) / t;
        result += min(f, m);
    }
    return result;
}


ll stupid_solve(ll n, ll m, string a, string b) {
    string na, nb;
    rep(i, n) na += a;
    rep(i, m) nb += b;
    a = na;
    b = nb;
    ll s = len(a); ll t = len(b);
    vector<vector<ll>> dp(s + 1, vector<ll>(t + 1, 0));
    rep(i, s) rep(j, t) dp[i + 1][j + 1] = max({ dp[i][j + 1], dp[i + 1][j], dp[i][j] + ll(a[i] == b[j]) });
    return dp[s][t];
}


void stress() {
    int c = 0;
    while (true) {
        cout << ++c << "\n";
        ll n = rnd() % 100 + 1;
        ll m = rnd() % 100 + 1;
        ll s = rnd() % 10 + 1;
        ll t = rnd() % 10 + 1;
        string a, b;
        a.resize(s); b.resize(t);
        rep(i, s) a[i] = 'a' + rnd() % 10;
        rep(i, t) b[i] = 'a' + rnd() % 10;
        ll right_rs = stupid_solve(n, m, a, b);
        ll my_rs = solve(n, m, a, b);
        if (right_rs != my_rs) {
            cout << "\n\n";
            cout << n << " " << m << "\n";
            cout << a << "\n";
            cout << b << "\n";
            cout << "\n\n";
            cout << my_rs << " " << right_rs << "\n";
            break;
        }
    }
}

int32_t main() {
    // stress();
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    ll n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;
    ll result = solve(n, m, a, b);
    cout << result << "\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

10 10
AB
BA

output:

19

result:

ok 1 number(s): "19"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

100000000 100000000
A
AB

output:

100000000

result:

ok 1 number(s): "100000000"

Test #3:

score: 0
Accepted
time: 5ms
memory: 3916kb

input:

1000000000000000 1000000000000000
BDCABACCCABBBDBDDCDADACBACBACDDCDCBADDDCDDCBBABDBA
DACBBDDBBCADCCACACAACBCBCCCBBABDACAACADAADCDBCCCBB

output:

30999999999999997

result:

ok 1 number(s): "30999999999999997"

Test #4:

score: 0
Accepted
time: 5ms
memory: 3788kb

input:

1000000000000000 1000000000000000
BDDCACBCBCBBAACBBBBACCBADDDCDACCBACCDDDBBDBDBBBCBA
CCCCBAADCDCDABADDBCCDACAABADAABCBDCCAADDABADDBCBBC

output:

30000000000000000

result:

ok 1 number(s): "30000000000000000"

Test #5:

score: 0
Accepted
time: 5ms
memory: 3924kb

input:

1000000000000000 1000000000000000
BADDABDACDAAABBCDBBDDDCDAACCAACBBCBBACCACDCBCDDAAD
CCADACCCDBBCAABCCDBDBAABDAACDBBABBDDCBCBACBBAABCBB

output:

32999999999999993

result:

ok 1 number(s): "32999999999999993"

Test #6:

score: 0
Accepted
time: 5ms
memory: 3712kb

input:

1000000000000000 1000000000000000
ABAABDCBBABACBDDDADBBBCBBDBACBACDCCBADCDBDBBAAABBA
BCCCBAACBBDCBCADADBACCBBCBCCACDBCDCBBCCACCADBCDBCB

output:

31999999999999998

result:

ok 1 number(s): "31999999999999998"

Test #7:

score: 0
Accepted
time: 5ms
memory: 3716kb

input:

1000000000000000 1000000000000000
BCDAABCABDCDDBDADABBDABBBDACCCAADABCCCDBDAADBCACDA
DBACCCDCCBDACADAADACCBCDADDCABCCBDBCBDBADACCDABBDB

output:

35999999999999991

result:

ok 1 number(s): "35999999999999991"

Test #8:

score: 0
Accepted
time: 5ms
memory: 3984kb

input:

1000000000000000 1000000000000000
AACACCDDDDBACAADADCBABCCBDBACDDABABABDBCAABABADADA
ACDBAACBCBBDBBACBABABBDBBBDAADBCACCABBADDDDDDADCDC

output:

33999999999999996

result:

ok 1 number(s): "33999999999999996"

Test #9:

score: 0
Accepted
time: 5ms
memory: 3700kb

input:

1000000000000000 1000000000000000
CADADCCCDDADBDCDCDBAACDBDACACBDDDCCDAADABDBACCBCDB
BABABACCBDAAADCDBDDDABDBADDADBBDBBACAABCCACCBDCAAD

output:

32999999999999996

result:

ok 1 number(s): "32999999999999996"

Test #10:

score: 0
Accepted
time: 5ms
memory: 3784kb

input:

1000000000000000 1000000000000000
ADDCBCBBAADDBCADCCDBDBBAADACDBCAAACCBBABCADBBAABCC
AAACCDDDCBBDBCCCCCBBAAACBCDCDAAABBBAAACCCDBADADBCB

output:

32999999999999999

result:

ok 1 number(s): "32999999999999999"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3716kb

input:

1000000000000000 1000000000000000
BACBCACDDBCDADDDBBAABBCBCCBCBCABDBDBBBCADABDDDCDAA
CCBCACADDBDDCCBABAABBABCDDAACADBCDBDBDABABCCBBCAAB

output:

32999999999999999

result:

ok 1 number(s): "32999999999999999"

Test #12:

score: 0
Accepted
time: 2ms
memory: 3984kb

input:

1000000000000000 777777777777777
CCBBCBAABCCCBABCBCAAAACABBACCCCACAABCBBACACAACABCB
CCBAABCABBBCCAABBCBBCACABCAAACACABACBCCBAACBCBCAAC

output:

31666666666666648

result:

ok 1 number(s): "31666666666666648"

Test #13:

score: 0
Accepted
time: 5ms
memory: 3784kb

input:

1000000000000000 777777777777777
ACBAAAACCACCCBAACAAABACACCABCBCBABBBACBABCAACCBCCA
CBCBACACACBCACCABACCBCCBAAAAABBACBACACBCCBABCAACBB

output:

31777777777777755

result:

ok 1 number(s): "31777777777777755"

Test #14:

score: 0
Accepted
time: 5ms
memory: 3720kb

input:

1000000000000000 777777777777777
CCCACCBCBACBACBCABAABABCCAAAACCCCCBBAABBCCBCCCABBA
CACAACBCCCBAAACACABCCABCCCCCABCAAAABBBCBBBAABCCACC

output:

29888888888888870

result:

ok 1 number(s): "29888888888888870"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3916kb

input:

1000000000000000 777777777777777
CABACBCBBCBABACABBBBBBABBCABCBCBCAABCBCCCBABACCCCA
BBABBBACBBACBCCCAAACACCABABCCCBCACCBCBCAACACBCCBAC

output:

31222222222222201

result:

ok 1 number(s): "31222222222222201"

Test #16:

score: 0
Accepted
time: 5ms
memory: 3696kb

input:

1000000000000000 777777777777777
BCCBCCACCBCBCABBBCCABAACACCBCCCBCCACCBBCBCCCBBCCBA
CBCBCBBCBABCBACBBABABCBCACBAAABBABACABBCBCCBACCBBC

output:

31777777777777754

result:

ok 1 number(s): "31777777777777754"

Test #17:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

1000000000000000 777777777777777
BABACACCABCAACBAABCCACCACBCCAABBCBAABABAACAAAAAACC
CBCBBABBBBBCBCACBABABACBBABCBABBCACBCACCBCAAABACAA

output:

29555555555555538

result:

ok 1 number(s): "29555555555555538"

Test #18:

score: 0
Accepted
time: 2ms
memory: 3984kb

input:

1000000000000000 777777777777777
ACCACABABBACBBAACCBBACBBCCACCACCABCCBABABBBACBACBA
ABCBBCAACAABABBABBAACABCAABCCABACBBBBCABCCCACBACBA

output:

32666666666666648

result:

ok 1 number(s): "32666666666666648"

Test #19:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

1000000000000000 777777777777777
ABBBBAABCAACCBACBBAACACABCABACBAABCAABBCCCCCCACBCC
CCAABCBABAABCBBAAACCCCCABAAAABCAABBCCCCACCBACABABB

output:

32222222222222200

result:

ok 1 number(s): "32222222222222200"

Test #20:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

1000000000000000 777777777777777
ABBAACCCACBBABBABCCCABABCACABABACCCBACACABCBCCCBAB
CCCCABCBAABBAAABACCCCABBABABAACABBCACBACACBBCBAABA

output:

32888888888888869

result:

ok 1 number(s): "32888888888888869"

Test #21:

score: 0
Accepted
time: 5ms
memory: 3752kb

input:

973726016575412 359840763615420
CCBBCBAABCCCBABCBCAAAACABBACCCCACAABCBBACACAACABCB
CCBAABCABBBCCAABBCBBCACABCAAACACABACBCCBAACBCBCAAC

output:

17886241906500152

result:

ok 1 number(s): "17886241906500152"

Test #22:

score: 0
Accepted
time: 5ms
memory: 3960kb

input:

158612425862653 819897228289078
CBABBBACBABCAACCBCCACBCBACACACBCACCABACCBCCBAAAAAB
BACBACACBCCBABCAACBBCCCACCBCBACBACBCABAABABCCAAAAC

output:

7930621293132650

result:

ok 1 number(s): "7930621293132650"

Test #23:

score: 0
Accepted
time: 5ms
memory: 3984kb

input:

342887581257444 503649293440596
BAAACACABCCABCCCCCABCAAAABBBCBBBAABCCACCCABACBCBBC
BABACABBBBBBABBCABCBCBCAABCBCCCBABACCCCABBABBBACBB

output:

13930205890208364

result:

ok 1 number(s): "13930205890208364"

Test #24:

score: 0
Accepted
time: 5ms
memory: 3784kb

input:

611173004830129 302236715540260
ACACBCCBACBCCBCCACCBCBCABBBCCABAACACCBCCCBCCACCBBC
BCCCBBCCBACBCBCBBCBABCBACBBABABCBCACBAAABBABACABBC

output:

14534160640930915

result:

ok 1 number(s): "14534160640930915"

Test #25:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

748236303528072 636528103155221
ABBBBCCAABCBBCACCBBCAAAABABABBABBBACAAABAABACCBCAA
CCAABCBBACCACBABBCCCACCBCABCACABBAACCCACBBABBABCCC

output:

22870745711378875

result:

ok 1 number(s): "22870745711378875"

Test #26:

score: 0
Accepted
time: 2ms
memory: 3716kb

input:

313370955837837 945058801322270
CCCCABCBAABBAAABACCCCABBABABAACABBCACBACACBBCBAABA
ABBBBAABCAACCBACBBAACACABCABACBAABCAABBCCCCCCACBCC

output:

15668547791891850

result:

ok 1 number(s): "15668547791891850"

Test #27:

score: 0
Accepted
time: 5ms
memory: 3696kb

input:

639219823402319 847398008805143
CAABBCCCCACCBACABABBACCACABABBACBBAACCBBACBBCCACCA
CCABCCBABABBBACBACBAABCBBCAACAABABBABBAACABCAABCCA

output:

26580313328719184

result:

ok 1 number(s): "26580313328719184"

Test #28:

score: 0
Accepted
time: 5ms
memory: 3996kb

input:

644195574734088 149903035076783
ABBACCCBBBCCACBACCCBCCAABCAABCBBBCCBACCBABCAACACAA
BABABACABBCBBACCACBBBCBABCCACCABCACABAACBBACBACCAA

output:

7495151753839150

result:

ok 1 number(s): "7495151753839150"

Test #29:

score: 0
Accepted
time: 5ms
memory: 3716kb

input:

546793478816387 321638328601260
ACCBCBAABAAACABBAABABBBBBCABAAAAAABACBBAABBAABBCAC
ABBCBBCAABBCBAAAAACBABCAACAAACAACBCCCBCBABABBCBCAC

output:

13701859359967636

result:

ok 1 number(s): "13701859359967636"

Test #30:

score: 0
Accepted
time: 5ms
memory: 3700kb

input:

973726016575412 359840763615420
PHQGHUMEAYLNLFDXFIRCVSCXGGBWKFNQDUXWFNFOZVSRTKJPRE
PGGXRPNRVYSTMWCYSYYCQPEVIKEFFMZNIMKKASVWSRENZKYCXF

output:

8932674756917526

result:

ok 1 number(s): "8932674756917526"

Test #31:

score: 0
Accepted
time: 2ms
memory: 3892kb

input:

158612425862653 819897228289078
YGPOEYLFPBNPLJVRVIPYAMYEHWQNQRQPMXUJJLOOVAOWUXWHMS
NCBXCOKSFZKVATXDKNLYJYHFIXJSWNKKUFNUXXZRZBMNMGQOOK

output:

4494818122105909

result:

ok 1 number(s): "4494818122105909"

Test #32:

score: 0
Accepted
time: 3ms
memory: 3912kb

input:

342887581257444 503649293440596
VSCMPSAJLFVGUBFAAOVLZYLNTRKDCPWSRTESJWHDIZCOBZCNFW
LQIJTVDWVXHRCBLDVGYLWGBUSBMBORXTLHCSMPXOHGMGNKEUFD

output:

6793659154475459

result:

ok 1 number(s): "6793659154475459"

Test #33:

score: 0
Accepted
time: 5ms
memory: 3984kb

input:

611173004830129 302236715540260
GEKJDQZJENPEVQGXIEPJSRDZJAZUJLLCHHBFQMKIMWZOBIWYBX
DUUNFSKSRSRTEKMQDCYZJEEUHMSRQCOZIJIPFIONEEDDPSZRNA

output:

7280479467964673

result:

ok 1 number(s): "7280479467964673"

Test #34:

score: 0
Accepted
time: 3ms
memory: 3744kb

input:

748236303528072 636528103155221
MHECTHLEGRPUNKDMBPPWEQTGJOPARMOWZDQYOXYTJBBHAWDYDC
PRJBXPHOOHPKWQYUHRQZHNBNFUVQNQQLRZJPXIOGVLIEXDZUZO

output:

9994754348819718

result:

ok 1 number(s): "9994754348819718"

Test #35:

score: 0
Accepted
time: 3ms
memory: 3688kb

input:

644195574734088 149903035076783
MDCASZSGOVSODKJGHCWMBMXRMHUYFYQGAJQKCKLZNAYXQKQOYZ
WMYUBZAZCPKHKTKYDZIVCUYPURFMBISGEKYRGZVXDHPOAMVAFY

output:

4586257921157402

result:

ok 1 number(s): "4586257921157402"

Test #36:

score: 0
Accepted
time: 2ms
memory: 3752kb

input:

546793478816387 321638328601260
PNARAEWKEGJCCVHHRJVBJTSQDJOOTGPKNFPFYCGFIEOWQRWWWP
ZSQMETOGEPSPXNVJIUPALYYNMKMNUVKLHSECDWRACGFMZKGIPD

output:

5725195529879408

result:

ok 1 number(s): "5725195529879408"

Test #37:

score: 0
Accepted
time: 4ms
memory: 3700kb

input:

636154209737260 637882913598407
BBAABAAAAABBBBBBBABABAABAABAABBABABABBBABBA
BBABBBABAABBBBBBAABAAAAAAAAABABAAABBABBAAAAAABAAB

output:

22917109885291680

result:

ok 1 number(s): "22917109885291680"

Test #38:

score: 0
Accepted
time: 4ms
memory: 3948kb

input:

681989722828907 925533374380880
BABBBABAAABAAABBBBBBBBBBBABAAAAABAABABABABA
BBBAABAAAABABAABABBAAAABBABABBBABBABABBABBAABAAAB

output:

28107502331466223

result:

ok 1 number(s): "28107502331466223"

Test #39:

score: 0
Accepted
time: 4ms
memory: 3760kb

input:

862146291503649 616335532825361
ABBAABAAABAAAABBBAAABAABBBBAABBAAABBBABBBBA
BABAABBAABABBABAABBABBABAABBBBABBBBABBBBAABAABAAB

output:

26862100868859748

result:

ok 1 number(s): "26862100868859748"

Test #40:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

567384926577457 831484920706070
ABBAAABBABAAAABBABABBAAAAAABBABBABBABAABAAB
BABBBBABABBBABBBBAAAAAABABAAABBBAABBAAABABBAAAABA

output:

23370142230523426

result:

ok 1 number(s): "23370142230523426"

Test #41:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

858324115951064 324442792373157
BABAAABABBBBAAAAAABBBBBAAAABABABABAABBBAABB
ABABABBBAAABABABABAAABBAAABABBBBBAABABABBBBBBBAAB

output:

15897696826284693

result:

ok 1 number(s): "15897696826284693"

Test #42:

score: 0
Accepted
time: 4ms
memory: 3780kb

input:

190429314820559 745680774313630
BBAABBBABAABABAABABBBBAABBAAABABABBAAABAABB
BAABABBABBABAAABBABABBBBAABBABBBBBABABBBBBAABABAA

output:

8188460537284037

result:

ok 1 number(s): "8188460537284037"

Test #43:

score: 0
Accepted
time: 4ms
memory: 3648kb

input:

562535661446268 454253268266394
BAABAABABBBAAABABBBABABAAABBAAABABBBBBABBBA
BBABBBBBBAAAABAAAAABBAAABABBABABBAABBBAABAABBBBBA

output:

18756454003094308

result:

ok 1 number(s): "18756454003094308"

Test #44:

score: 0
Accepted
time: 2ms
memory: 3940kb

input:

908387269381033 92824504405115
ABBBABBBBAAAAABBAAAABABABAAABBBAAAAAABBABAB
BABBAABAAABBBABABBBBBAABBABAABABAABBBBBBBAABABBBB

output:

4548400715850635

result:

ok 1 number(s): "4548400715850635"

Test #45:

score: 0
Accepted
time: 4ms
memory: 3696kb

input:

780208928205527 986623826275782
AAAABBABBBBBABABAABBAAABBABABBAAAAABBAAABAB
ABBABABBABBAAAABBBAAAABAAABAAABAABABABAAABABBABAA

output:

31918503150582829

result:

ok 1 number(s): "31918503150582829"

Test #46:

score: 0
Accepted
time: 4ms
memory: 3992kb

input:

104075905120989 790814079538232
BBBBBBAAAAABAABABABAAAAAABABBBABBAAAABBABAB
BBBAABAAAAABAABABBAAAABAAAABABAABBBBBBAAABBABBAAA

output:

4475263920202527

result:

ok 1 number(s): "4475263920202527"

Test #47:

score: 0
Accepted
time: 4ms
memory: 3696kb

input:

263159702617625 132816467796419
BBBBABAAAAABABBBAAAABABBABAAABBBAABBAAABABA
AABABAAAABAABAABABBABBBAAAABABABBBBAABBABBAABBAAB

output:

6485747825247612

result:

ok 1 number(s): "6485747825247612"

Test #48:

score: 0
Accepted
time: 2ms
memory: 3764kb

input:

529126170152290 536315340317903
BAABBBBBAAAABBBABBABBBAABAABAAABBBBBBABBAAA
BBAAABAAABBABBBABBAABABBBBAABAABAABABBABABAAAABBB

output:

20193064507774373

result:

ok 1 number(s): "20193064507774373"

Test #49:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

13939365540506 266330081381698
BBABAAAABAABAABABABABBAAAAABAABBABAABBBBAAB
BBAABABABABABBBBABAAABAABAABBBBBABBBBBABBBAABBBAB

output:

599392718241758

result:

ok 1 number(s): "599392718241758"

Test #50:

score: 0
Accepted
time: 4ms
memory: 3768kb

input:

958962576385930 476630908015103
BBBABAAABABABAAABAAAAAABAAABBABAABBABABABAB
BAABABABAAAAABAAABBBBBABBBBBBABBBBABBAAAABBAABABB

output:

23354914492740047

result:

ok 1 number(s): "23354914492740047"

Test #51:

score: 0
Accepted
time: 4ms
memory: 3764kb

input:

413850921335290 810687651295615
BBAABAABBBAAABBBABBBBBBBABBBAABBBBBAAAABBAB
BBABBABABBABBBAAAABAABAABBABABAAAABBBBBBABBABBBAB

output:

17795589617417470

result:

ok 1 number(s): "17795589617417470"

Test #52:

score: 0
Accepted
time: 4ms
memory: 3720kb

input:

23168772879592 668058895732220
AABBBBABABABBAABABAABABAAAABBABAABAAABBBBBA
BAABBBAABABABAABAAABABBABABBBBAABABBBAABAAAABABAB

output:

996257233822456

result:

ok 1 number(s): "996257233822456"

Test #53:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

233730148789897 710283556149383
BBBAABBAAAABBABAABBABBABBBAABABBAABBBBABABA
BBBBABBBABBBAABBBBBBBABAAABABAABAAAABBABBABAAAAAB

output:

10050396397965571

result:

ok 1 number(s): "10050396397965571"

Test #54:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

1000000000000000 1000000000000000
A
B

output:

0

result:

ok 1 number(s): "0"

Test #55:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

1 1
Z
Z

output:

1

result:

ok 1 number(s): "1"

Test #56:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

1 1
Z
X

output:

0

result:

ok 1 number(s): "0"

Test #57:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ
QWERTYUIOPQWERTYUIOPQWERTYUIOPQWERTYUIOPQWERTYUIOP

output:

10

result:

ok 1 number(s): "10"

Test #58:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

1 1
WUENWFRVUKUMWDWDTLNRJVVTDNQOQHBYYRLMTJGXCCFFOYLSYU
IIYVWJQBXKFYLNASJZKWNDPRHFXQLYNXBLISAHVVUTGPPDDBES

output:

13

result:

ok 1 number(s): "13"

Test #59:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

1 1
ETENXUYB
OADWEXSILYMACRDWTFJW

output:

3

result:

ok 1 number(s): "3"

Test #60:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

1 1000000000000000
ZBIPVAVAHJNPFOUWQBAENFAIFIKBNLHACXNGXJACJIUCREXTNF
PLCOKTLSGXYCWEYUESHJPWOXQHYKGTJCLDPRXVPKBGGWXCRNFG

output:

39

result:

ok 1 number(s): "39"

Test #61:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

1 1000000000000000
DPKSKTQCQAZW
UKEMYAACWM

output:

5

result:

ok 1 number(s): "5"

Test #62:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

1000000000000000 1000000000000000
YGHXKMKWKQJDDRDCYJQEBIWLUKRZYANNFLCKXREDLESEGCLLGM
IVFCHPGIJVJ

output:

5999999999999998

result:

ok 1 number(s): "5999999999999998"

Test #63:

score: 0
Accepted
time: 3ms
memory: 3704kb

input:

1000000000000000 1000000000000000
PVRLQSSFHCGHZFFBAYSAZSOLCTUXQXNOAVRMQXBKLOIWXHMNXS
SBFAMJRALFKFDIOBYQDUATNSFECSOREZPUCKBIZXXLAFWKWXEQ

output:

16999999999999999

result:

ok 1 number(s): "16999999999999999"

Test #64:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

709861939765211 1000000000000000
BRJOSOC
JITUQQPUCJBXFNOEMZRMMW

output:

3129585819295632

result:

ok 1 number(s): "3129585819295632"

Test #65:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

710452281077929 1000000000000000
XXZKPXGCOBRQFIQBFQQDBTFIFYIUIOTHQXVBBYJUYQAFIIYCWE
OMWHJWLNTNFVVNRHTOEVDYQYLVMWJJSTFSJUUHGFVLTQKNYPRA

output:

9973165967545502

result:

ok 1 number(s): "9973165967545502"

Test #66:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

1000000000000000 683432196932049
YJIODJWMKNJWCGFFPRCOQOIBHYLXLHRT
LTCKSUBLTJVQNPHLDRPXJFYCP

output:

7417160984660242

result:

ok 1 number(s): "7417160984660242"

Test #67:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

1000000000000000 613892017596863
FHICJRFEZUMZGNGEUDGMNZFZQCCQDNNSPGCGZLGANMEDECZMLS
ZBIFBVNTCXJKZXKYIIGWRECTSWIYORTSHARHQRSATPQWYEPPCR

output:

9525028158371766

result:

ok 1 number(s): "9525028158371766"

Test #68:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

284965599323079 890548365990318
IQLBRWKRCZPUUOAXEDBSCXEXHJLQYZ
ARIZ

output:

1460479564636476

result:

ok 1 number(s): "1460479564636476"

Test #69:

score: 0
Accepted
time: 2ms
memory: 3964kb

input:

517331754115797 889576652477014
RTGJFGHOGKGSZGHRVXYGGPZEWKYOJEOSGKZBFHBFHBCVBWZHOJ
RDTSOBLHLZGJDNYCIYFKOMZYEDSBWRKKBVLADSPTLCKUIOMHTY

output:

9621200803543040

result:

ok 1 number(s): "9621200803543040"

Test #70:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

1000000000000000 1000000000000000
FA
VHSTVJHLYSCEHKZLEFSKUUTZXBWKBDEZOOONFBZFFMPU

output:

1000000000000000

result:

ok 1 number(s): "1000000000000000"

Test #71:

score: 0
Accepted
time: 2ms
memory: 3664kb

input:

1000000000000000 1000000000000000
AAQFZLADEGQJAVHYPJTHLGJMIEKHQGVODPNDNOWODNRZKAYQCF
VUUBBBLRQKSRPNMVWENXLYUSBGIBAFXLAOOSJJGKPNKAJIYJBN

output:

14999999999999998

result:

ok 1 number(s): "14999999999999998"

Test #72:

score: 0
Accepted
time: 4ms
memory: 8696kb

input:

1 1
SRFMKMIIWQASZHMXDZSCBSLOJOFIDYQHUDHZGLOBZEUFSHBLSDFFSXRUJKZCUDJZLWCJVQJGQZDRWABTFUIFSTEKGQZFVVTDWUPLNWIWJPNFLMDGLIIVHEUZWXIURGNLFZTVKWRHCRWNQMNNYEIDVDGPJGAAYSXKOMBCNSXTTUHLXHVNUDXXZMDNMHQKKSFYWPPRHFWXWCAZNXLLZVTNKTNKAXMXEMJPEIEPQCVTIQZPLMNHXTSJEILHDVGPXYPPGROZUYYUEJRUMVJSMILKLLMXCZBFNSXWFVWVBFPM...

output:

154

result:

ok 1 number(s): "154"

Test #73:

score: 0
Accepted
time: 0ms
memory: 3992kb

input:

1 1
XGFEIWMOZABDVGHURAVSMEENWXZUALZWHGLGTHMRYUMPBPKPAKKGUNBUWTBESXGKRTNULOMQNTZVRINHOANCPNZLQVKEFXHIHCTFBRCYOGETVZFRBXSRRERSSWJMNPZUFXMDLLPTRZSTAKUQEUVZNNWRWFQIMXQTDNHWCGSNIVALFICCSJGNWOLGGYIFDYZZIAUWPDRNTRELNNYNBEHUFZLEIKAQKEUEIHTHJTQTHKVSFFEHVLXKTUVRCUUACBFCIDSPCYGFRHHIQOOGONVNFNVJTPOPNVXAEYRWZ
QY...

output:

66

result:

ok 1 number(s): "66"

Test #74:

score: 0
Accepted
time: 8ms
memory: 8592kb

input:

1 1000000000000000
WTEIORVIPRJDVAINQMXMGHNIDCCMIBTOWZLZATVHOBZLFGQWQKJJOLBPBTMXXOYWNRVHJVDGWJGSNVXPLFBJQQSETXKDCCQQIVDCXGFNOVBMQFCEQCWZJUOJKCRGJYPPYFRMROVWFFSQJPXVAZBVJSRQVJSCNOVNVVBCFLIHCOFOOHYYYXWGKBIZXDTQQSCWGIGZLGSCXLGJYBJNHQQEIPONFEPROPOIUFGMZLVRZPQDJGVSXTQAFIVVHKXTJROHAEHCLEQIBKMRSVBRNIYOEVBNA...

output:

500

result:

ok 1 number(s): "500"

Test #75:

score: 0
Accepted
time: 5ms
memory: 5352kb

input:

1 1000000000000000
CLQFBZVZWTYSHTMEUOVNFTBSCZDADHDUALRKJERXLVBAXWPUWATBMYOMADTBVSZJFYJRQXOREPUQXSIOLXCXFWLLYCHSRYVZTPOWFZQFUYERYTTUDMNEFLAFKQNPITXLOPPSOZNXICCACGMIQHGYZQPRMBOJVGPUWGRJKBQQZVBWKCZKBYMZGKNMNZFDNPSHMDQAOMXXEVCPXITEZAIWKJOYTLDJCZWZPQTEASIIECDDHFEAVLJAVJOXMLTSWPXGBIIDZXZDAIBHRPAKHWJCFHJOZ...

output:

410

result:

ok 1 number(s): "410"

Test #76:

score: 0
Accepted
time: 123ms
memory: 10972kb

input:

1000000000000000 1000000000000000
YQSWVRNQIXGPAOARKSUYPMEEJNBXFNULBTTRXYVAYPJPBZDWGCJHRCWYDIXRCMXEPJGSLMNWPXSMTWYBEBOESQQEIBRXBXFKQASDJOTPFCQEOEOOKUWLLKWMWECVYLLAXNZPJOGRZTPCCJDCQUCOXKDIWMZGCRXROVAMCKQZUSOUETBBDZEQAEZMNADMBMIWRFPAEPGCAIQANGWATSGNWJLKIMJTNUAQPAHFNPOJRMQWHWYHYSRJATCNPROSIEZCNMVHKUAZEF...

output:

106999999999999992

result:

ok 1 number(s): "106999999999999992"

Test #77:

score: -100
Time Limit Exceeded

input:

1000000000000000 1000000000000000
GOAZLWUAILEUHESJJHLZUKKUNWCYNORLAFENCZXNCXDMTCAKUOZJYORXGYTHBVEMVKTDTGZERYCWXDVKHIRWIUEOIRPWMBYVSUNNWTGUUMEWBJPRFORTOCYQQCNNWNDSOXGBALFTAUMNYHKXAESQJDOGVDGTXZGICHJAWARMUYFVGGJWTOWXLCAPQXEQRSAETGYOQJRCLMPOUQXXXQRACHMDPHNDDNVSFAIBXYJRNMVFWQKKXHKJHPDENUMILVJHLUIYZHDOMG...

output:


result: