Problem:
Problem D
Hidden Anagrams
An
anagram
is a word or a phrase that is formed by rearranging the letters of another. For instance, by rearranging the letters of "William Shakespeare," we can have its anagrams "I am a weakish speller," "I'll make a wise phrase," and so on. Note that when $A$ is an anagram of $B$, $B$ is an anagram of $A$.
In the above examples, differences in letter cases are ignored, and word spaces and punctuation symbols are freely inserted and/or removed. These rules are common but not applied here; only exact matching of the letters is considered.
For two strings $s_1$ and $s_2$ of letters, if a substring $s'_1$ of $s_1$ is an anagram of a substring $s'_2$ of $s_2$, we call $s'_1$ a
hidden anagram
of the two strings, $s_1$ and $s_2$. Of course, $s'_2$ is also a
hidden anagram
of them.
Your task is to write a program that, for given two strings, computes the length of the longest hidden anagrams of them.
Suppose, for instance, that "anagram" and "grandmother" are given. Their substrings "nagr" and "gran" are hidden anagrams since by moving letters you can have one from the other. They are the longest since any substrings of "grandmother" of lengths five or more must contain "d" or "o" that "anagram" does not. In this case, therefore, the length of the longest hidden anagrams is four. Note that a substring must be a sequence of letters occurring
consecutively
in the original string and so "nagrm" and "granm" are not hidden anagrams.
Input
The input consists of a single test case in two lines.
$s_1$
$s_2$
$s_1$ and $s_2$ are strings consisting of lowercase letters (a through z) and their lengths are between 1 and 4000, inclusive.
Output
Output the length of the longest hidden anagrams of $s_1$ and $s_2$. If there are no hidden anagrams, print a zero.
Sample Input 1
anagram
grandmother
Sample Output 1
4
Sample Input 2
williamshakespeare
iamaweakishspeller
Sample Output 2
18
Sample Input 3
aaaaaaaabbbbbbbb
xxxxxabababxxxxxabab
Sample Output 3
6
Sample Input 4
abababacdcdcd
efefefghghghghgh
Sample Output 4
0

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <chrono>
#include <random>
#include <cassert>

using namespace std;

// --- Global RNG and Prime Moduli ---
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const uint64_t MODS[] = {1000000007, 1000000019, 1000000009, 1000000033, 1000000087};
const int K = 5;
// FIX: Adjusted bitset size to fit within 256 MB memory limit
// 5 * (4e8 / 8) = 250 MB
const size_t BITSET_SIZE = 400000000;

class Bloom_Filter {

    vector<bool> bt[K];
    vector<uint64_t> bases;
    vector<uint64_t> preCompPower[K];

public:
    Bloom_Filter(int max_len = 4000) {
        for (int i = 0; i < K; i++) {
            bt[i].resize(BITSET_SIZE);
            bases.push_back(rng() % 193LL + 101LL);
            preCompPower[i].resize(26);
            preCompPower[i][0] = 1;
            for (int j = 1; j < 26; j++) {
                preCompPower[i][j] = (bases[i] * preCompPower[i][j - 1]) % MODS[i];
            }
        }
    }

    void addHashes(const vector<uint64_t>& hashes) {
        for (int i = 0; i < K; ++i) {
            bt[i][hashes[i] % BITSET_SIZE] = true;
        }
    }

    bool areHashesPresent(const vector<uint64_t>& hashes) {
        for (int i = 0; i < K; ++i) {
            if (!bt[i][hashes[i] % BITSET_SIZE]) {
                return false;
            }
        }
        return true;
    }

    vector<uint64_t> getCharWeights(char c) {
        vector<uint64_t> weights(K);
        int char_idx = c - 'a';
        for (int i = 0; i < K; ++i) {
            weights[i] = preCompPower[i][char_idx];
        }
        return weights;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;

    Bloom_Filter bf;

    for (int i = 0; i < s1.length(); i++) {
        vector<uint64_t> current_hashes(K, 1);
        for (int j = i; j < s1.length(); j++) {
            vector<uint64_t> char_weights = bf.getCharWeights(s1[j]);
            for (int k = 0; k < K; ++k) {
                current_hashes[k] = (current_hashes[k] + char_weights[k]) % MODS[k];
            }
            bf.addHashes(current_hashes);
        }
    }

    int ans = 0;
    for (int i = 0; i < s2.length(); i++) {
        vector<uint64_t> current_hashes(K, 1);
        for (int j = i; j < s2.length(); j++) {
            vector<uint64_t> char_weights = bf.getCharWeights(s2[j]);
            for (int k = 0; k < K; ++k) {
                current_hashes[k] = (current_hashes[k] + char_weights[k]) % MODS[k];
            }
            if (bf.areHashesPresent(current_hashes)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 1490
memory_kb: 247388
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <chrono>
#include <random>
#include <cassert>

using namespace std;

// --- Global RNG and Prime Moduli ---
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const uint64_t MODS[] = {1000000007, 1000000019, 1000000009};
const int K = 3;
const size_t BITSET_SIZE = 500000000;

class Bloom_Filter {

    vector<bool> bt[K];
    vector<uint64_t> bases;
    vector<uint64_t> preCompPower[K];

public:
    Bloom_Filter(int max_len = 4000) {
        for (int i = 0; i < K; i++) {
            bt[i].resize(BITSET_SIZE);
            bases.push_back(rng() % 193LL + 101LL);
            // We only need 26 unique weights, one for each character
            preCompPower[i].resize(26);
            preCompPower[i][0] = 1;
            for (int j = 1; j < 26; j++) {
                preCompPower[i][j] = (bases[i] * preCompPower[i][j - 1]) % MODS[i];
            }
        }
    }

    // O(1) functions to add/check hashes directly
    void addHashes(const vector<uint64_t>& hashes) {
        for (int i = 0; i < K; ++i) {
            bt[i][hashes[i] % BITSET_SIZE] = true;
        }
    }

    bool areHashesPresent(const vector<uint64_t>& hashes) {
        for (int i = 0; i < K; ++i) {
            if (!bt[i][hashes[i] % BITSET_SIZE]) {
                return false;
            }
        }
        return true;
    }

    // O(1) function to get the unique weight for a character
    vector<uint64_t> getCharWeights(char c) {
        vector<uint64_t> weights(K);
        int char_idx = c - 'a';
        for (int i = 0; i < K; ++i) {
            weights[i] = preCompPower[i][char_idx];
        }
        return weights;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;

    Bloom_Filter bf;

    // --- OPTIMIZED: Process s1 with Sliding Window ---
    // O(L1^2) reduced to O(L1 * L1) -> still O(L1^2) but the inner loop is faster
    for (int i = 0; i < s1.length(); i++) {
        vector<uint64_t> current_hashes(K, 1); // Start with initial hash
        for (int j = i; j < s1.length(); j++) {
            // O(1) hash update
            vector<uint64_t> char_weights = bf.getCharWeights(s1[j]);
            for (int k = 0; k < K; ++k) {
                current_hashes[k] = (current_hashes[k] + char_weights[k]) % MODS[k];
            }
            bf.addHashes(current_hashes);
        }
    }

    int ans = 0;
    // --- OPTIMIZED: Process s2 with Sliding Window ---
    for (int i = 0; i < s2.length(); i++) {
        vector<uint64_t> current_hashes(K, 1);
        for (int j = i; j < s2.length(); j++) {
            // O(1) hash update
            vector<uint64_t> char_weights = bf.getCharWeights(s2[j]);
            for (int k = 0; k < K; ++k) {
                current_hashes[k] = (current_hashes[k] + char_weights[k]) % MODS[k];
            }
            if (bf.areHashesPresent(current_hashes)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;

    return 0;
}
accuracy: 0.20967741935483872
time_ms: 890
memory_kb: 186264
final_rank: 17

code_snippet: #include <bitset>
#include <chrono>
#include <iostream>
#include <random>
#include<cassert>

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const uint64_t MOD1 = 1000000007;
const uint64_t MOD2 = 1000000019;
const uint64_t MOD3 = 1000000009;

class Bloom_Filter {

    vector<bool> bt[3];
    vector<uint64_t> bases;
    vector<uint64_t> preCompPower[3];
    uint64_t offset1, offset2, offset3;

  public:
    Bloom_Filter(int len = 4000) {
        for(int i = 0; i < 3; i++) bt[i].resize(500000000);
        for (int i = 0; i < 3; i++) {
            bases.push_back(rng() % 193LL + 101LL);
        }
        preCompPower[0].resize(len + 1);
        preCompPower[1].resize(len + 1);
        preCompPower[2].resize(len + 1);
        preCompPower[0][0] = preCompPower[1][0] =  preCompPower[2][0]= 1;
        for (int i = 1; i <= len; i++) {
            preCompPower[0][i] = (bases[0] * preCompPower[0][i - 1]) % MOD1;
            preCompPower[1][i] = (bases[1] * preCompPower[1][i - 1]) % MOD2;
            preCompPower[2][i] = (bases[2] * preCompPower[2][i - 1]) % MOD3;
        }
        offset1 = rng() % 999 + 101;
        offset2 = rng() % 923 + 103;
        offset3 = rng() % 919 + 119;
        offset1 |= 1;
        offset2 |= 1;
        offset3 |= 1;
    }

    void addString(vector<uint64_t> &num) {
        uint64_t hsh1 = 0, hsh2 = 0, hsh3 = 0;
        int pw = 25;
        for (uint64_t t : num) {
            assert(pw>=0);
            hsh1 = (preCompPower[0][pw] * (t + offset1) + hsh1) % MOD1;
            hsh2 = (preCompPower[1][pw] * (t + offset2) + hsh2) % MOD2;
            hsh3 = (preCompPower[2][pw] * (t + offset3) + hsh3) % MOD3;
            pw--;
        }
        hsh1 %= 500000000;
        hsh2 %= 500000000;
        hsh3 %= 500000000;
        bt[0][hsh1] = true;
        bt[1][hsh2] = true;
        bt[2][hsh3] = true;
    }
    bool isPresent(vector<uint64_t> &num) {
        uint64_t hsh1 = 0, hsh2 = 0, hsh3 = 0;
        int pw = 25;
        for (uint64_t t : num) {
            assert(pw>=0);
            hsh1 = (preCompPower[0][pw] * (t + offset1) + hsh1) % MOD1;
            hsh2 = (preCompPower[1][pw] * (t + offset2) + hsh2) % MOD2;
            hsh3 = (preCompPower[2][pw] * (t + offset3) + hsh3) % MOD3;
            pw--;
        }
        hsh1 %= 500000000;
        hsh2 %= 500000000;
        hsh3 %= 500000000;
        if (bt[0][hsh1] && bt[1][hsh2] && bt[2][hsh3])
            return true;
        else
            return false;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    int len1 = s1.length();
    int len2 = s2.length();
    Bloom_Filter bf(4000);
    for (int i = 0; i < len1; i++) {
        vector<uint64_t>num(26, 0);
        for (int j = i; j < len1; j++) {
            num[s1[j] - 'a']++;
            bf.addString(num);
        }
    }
    int ans = 0;
    for (int i = 0; i < len2; i++) {
        vector<uint64_t>num(26, 0);
        for (int j = i; j < len2; j++) {
            num[s2[j] - 'a']++;
            if (bf.isPresent(num)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.20967741935483872
time_ms: 1870
memory_kb: 186264
final_rank: 19

code_snippet: #include <bitset>
#include <chrono>
#include <iostream>
#include <random>
#include<cassert>

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const uint64_t MOD1 = 1000000007;
const uint64_t MOD2 = 1000000019;

class Bloom_Filter {

    bitset<200000000> bt[2];
    vector<uint64_t> bases;
    vector<uint64_t> preCompPower[2];
    uint64_t offset1, offset2;

  public:
    Bloom_Filter(int len = 4000) {
        for (int i = 0; i < 2; i++) {
            bases.push_back(rng() % 193LL + 101LL);
        }
        preCompPower[0].resize(len + 1);
        preCompPower[1].resize(len + 1);
        preCompPower[0][0] = preCompPower[1][0] = 1;
        for (int i = 1; i <= len; i++) {
            preCompPower[0][i] = (bases[0] * preCompPower[0][i - 1]) % MOD1;
            preCompPower[1][i] = (bases[1] * preCompPower[1][i - 1]) % MOD2;
        }
        offset1 = rng() % 999 + 10;
        offset2 = rng() % 923 + 11;
        offset1 |= 1;
        offset2 |= 1;
    }

    void addString(vector<uint64_t> &num) {
        uint64_t hsh1 = 0, hsh2 = 0;
        int pw = 25;
        for (uint64_t t : num) {
            assert(pw>=0);
            hsh1 = (preCompPower[0][pw] * (t + offset1) + hsh1) % MOD1;
            hsh2 = (preCompPower[1][pw] * (t + offset2) + hsh2) % MOD2;
            pw--;
        }
        hsh1 %= 200000000;
        hsh2 %= 200000000;
        bt[0].set(hsh1);
        bt[1].set(hsh2);
    }
    bool isPresent(vector<uint64_t> &num) {
        uint64_t hsh1 = 0, hsh2 = 0;
        int pw = 25;
        for (uint64_t t : num) {
            assert(pw>=0);
            hsh1 = (preCompPower[0][pw] * (t + offset1) + hsh1) % MOD1;
            hsh2 = (preCompPower[1][pw] * (t + offset2) + hsh2) % MOD2;
            pw--;
        }
        hsh1 %= 200000000;
        hsh2 %= 200000000;
        if (bt[0][hsh1] && bt[1][hsh2])
            return true;
        else
            return false;
    }
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    int len1 = s1.length();
    int len2 = s2.length();
    Bloom_Filter bf(4000);
    for (int i = 0; i < len1; i++) {
        vector<uint64_t>num(26, 0);
        for (int j = i; j < len1; j++) {
            num[s1[j] - 'a']++;
            bf.addString(num);
        }
    }
    int ans = 0;
    for (int i = 0; i < len2; i++) {
        vector<uint64_t>num(26, 0);
        for (int j = i; j < len2; j++) {
            num[s2[j] - 'a']++;
            if (bf.isPresent(num)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.20967741935483872
time_ms: 1580
memory_kb: 52332
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string s,t;cin >> s >> t;
    int n = s.size();
    int m = t.size();

    ll INF = 1e15;
    vector<ll> al(26);
    mt19937_64 ran(37);
    for (int i = 0; i < 26; i++)al[i] = ran() % INF;

    int k = min(n,m);
    unordered_set<ll> st;
    for (int i = k; i > 0; i--){
        st.clear();
        ll num = 0;
        for (int j = 0; j < i; j++)num = (num + al[s[j]-'a']) % INF;
        st.insert(num);
        for (int j = i; j < n; j++){
            num = (num + al[s[j]-'a'] - al[s[j-i]-'a'] + INF) % INF;
            st.insert(num);
        }

        num = 0;
        for (int j = 0; j < i; j++)num = (num + al[t[j]-'a']) % INF;
        if (st.count(num)){
            cout << i << endl;
            return 0;
        }
        for (int j = i; j < m; j++){
            num = (num + al[t[j]-'a'] - al[t[j-i]-'a'] + INF) % INF;
            if (st.count(num)){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 1
time_ms: 510
memory_kb: 3632
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string s,t;cin >> s >> t;
    int n = s.size();
    int m = t.size();

    ll INF = 1e15;
    vector<ll> al(26);
    mt19937_64 ran(37);
    for (int i = 0; i < 26; i++)al[i] = ran() % INF;

    int k = min(n,m);
    set<ll> st;
    for (int i = k; i > 0; i--){
        st.clear();
        ll num = 0;
        for (int j = 0; j < i; j++)num = (num + al[s[j]-'a']) % INF;
        st.insert(num);
        for (int j = i; j < n; j++){
            num = (num + al[s[j]-'a'] - al[s[j-i]-'a'] + INF) % INF;
            st.insert(num);
        }

        num = 0;
        for (int j = 0; j < i; j++)num = (num + al[t[j]-'a']) % INF;
        if (st.count(num)){
            cout << i << endl;
            return 0;
        }
        for (int j = i; j < m; j++){
            num = (num + al[t[j]-'a'] - al[t[j-i]-'a'] + INF) % INF;
            if (st.count(num)){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 1
time_ms: 1230
memory_kb: 3632
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string s,t;cin >> s >> t;
    int n = s.size();
    int m = t.size();

    int w = 6e7;
    vector<int> h(w,-1);
    vector<ll> al(26);
    mt19937_64 ran(37);
    for (int i = 0; i < 26; i++)al[i] = ran() % w;

    int k = min(n,m);
    for (int i = k; i > 0; i--){
        ll num = 0;
        for (int j = 0; j < i; j++)num = (num + al[s[j]-'a']) % w;
        h[num] = i;
        for (int j = i; j < n; j++){
            num = (num + al[s[j]-'a'] - al[s[j-i]-'a'] + w) % w;
            h[num] = i;
        }

        num = 0;
        for (int j = 0; j < i; j++)num = (num + al[t[j]-'a']) % w;
        if (h[num] == i){
            cout << i << endl;
            return 0;
        }
        for (int j = i; j < m; j++){
            num = (num + al[t[j]-'a'] - al[t[j-i]-'a'] + w) % w;
            if (h[num] == i){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 0.20967741935483872
time_ms: 40
memory_kb: 237452
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string s,t;cin >> s >> t;
    int n = s.size();
    int m = t.size();

    int w = 5e7;
    vector<int> h(w,-1);
    vector<ll> al(26);
    mt19937_64 ran(37);
    for (int i = 0; i < 26; i++)al[i] = ran() % w;

    int k = min(n,m);
    for (int i = k; i > 0; i--){
        ll num = 0;
        for (int j = 0; j < i; j++)num = (num + al[s[j]-'a']) % w;
        h[num] = i;
        for (int j = i; j < n; j++){
            num = (num + al[s[j]-'a'] - al[s[j-i]-'a'] + w) % w;
            h[num] = i;
        }

        num = 0;
        for (int j = 0; j < i; j++)num = (num + al[t[j]-'a']) % w;
        if (h[num] == i){
            cout << i << endl;
            return 0;
        }
        for (int j = i; j < m; j++){
            num = (num + al[t[j]-'a'] - al[t[j-i]-'a'] + w) % w;
            if (h[num] == i){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 0.20967741935483872
time_ms: 20
memory_kb: 198388
final_rank: 15

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

#define len(a) ((int)a.size())
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using str = string;

seed_seq sseq{
    (i64)chrono::steady_clock::now().time_since_epoch().count(),
    (i64)__builtin_ia32_rdtsc(),
    (i64)make_unique<char>().get()
};
mt19937 mt(sseq);
template<class T = int> T rng(T l, T r) {
    return uniform_int_distribution<T>{l, r}(mt);
}

const u64 mod = (u64(1) << 61) - 1;
u64 add(u64 a, u64 b) { return i64(a -= mod - b) < 0 ? a + mod : a; }
u64 mul(u64 a, u64 b) {
    auto t = __uint128_t(a) * b;
    t = (t & mod) + (t >> 61);
    return t < mod ? t : t - mod;
}
u64 inv(u64 a) {
    u64 r = a, b = mul(a, a);
    for (int i = 2; i < 61; i++) b = mul(b, b), r = mul(r, b);
    return r;
}
u64 divi(u64 a, u64 b) { return mul(a, inv(b)); }
u64 weyl(u64 a) {
    static const u64 gamma = rng<u64>(0, mod - 1), s = rng<u64>(0, mod - 1);
    return add(mul(a, gamma), s);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    str s, t;
    cin >> s >> t;
    int n = len(s), m = len(t);
    for (int w = min(n, m); w >= 1; w--) {
        unordered_set<u64> vals;
        u64 hash = 1;
        for (int i = 0; i < n; i++) {
            int j = i - w;
            hash = mul(hash, weyl(s[i]));
            if (j >= 0) hash = divi(hash, weyl(s[j]));
            if (j + 1 >= 0) vals.insert(hash);
        }
        hash = 1;
        for (int i = 0; i < m; i++) {
            int j = i - w;
            hash = mul(hash, weyl(t[i]));
            if (j >= 0) hash = divi(hash, weyl(t[j]));
            if (j + 1 >= 0 && vals.count(hash)) {
                cout << w << "\n";
                return 0;
            }
        }
    }
    cout << "0\n";
}
accuracy: 1
time_ms: 4530
memory_kb: 3600
final_rank: 8

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

#define len(a) ((int)a.size())
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using str = string;

seed_seq sseq{
    (i64)chrono::steady_clock::now().time_since_epoch().count(),
    (i64)__builtin_ia32_rdtsc(),
    (i64)make_unique<char>().get()
};
mt19937 mt(sseq);
template<class T = int> T rng(T l, T r) {
    return uniform_int_distribution<T>{l, r}(mt);
}

const u64 mod = (u64(1) << 61) - 1;
u64 add(u64 a, u64 b) { return i64(a -= mod - b) < 0 ? a + mod : a; }
u64 red(u64 a) { return add(a & mod, a >> 61); }
u64 mul(u64 a, u64 b) {
    u64 la = u32(a), ha = a >> 32, lb = u32(b), hb = b >> 32;
    u64 l = la * lb, m = la * hb + ha * lb, h = ha * hb;
    return red((l & mod) + (l >> 61) + (m >> 29) + (m << 32 & mod) + (h << 3));
}
u64 inv(u64 a) {
    u64 r = a, b = mul(a, a);
    for (int i = 2; i < 61; i++) b = mul(b, b), r = mul(r, b);
    return r;
}
u64 divi(u64 a, u64 b) { return mul(a, inv(b)); }
u64 weyl(u64 a) {
    static const u64 gamma = rng<u64>(0, mod - 1), s = rng<u64>(0, mod - 1);
    return add(mul(a, gamma), s);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    str s, t;
    cin >> s >> t;
    int n = len(s), m = len(t);
    for (int w = min(n, m); w >= 1; w--) {
        set<u64> vals;
        u64 hash = 1;
        for (int i = 0; i < n; i++) {
            int j = i - w;
            hash = mul(hash, weyl(s[i]));
            if (j >= 0) hash = divi(hash, weyl(s[j]));
            if (j + 1 >= 0) vals.insert(hash);
        }
        hash = 1;
        for (int i = 0; i < m; i++) {
            int j = i - w;
            hash = mul(hash, weyl(t[i]));
            if (j >= 0) hash = divi(hash, weyl(t[j]));
            if (j + 1 >= 0 && vals.count(hash)) {
                cout << w << "\n";
                return 0;
            }
        }
    }
    cout << "0\n";
}
accuracy: 1
time_ms: 6010
memory_kb: 3656
final_rank: 9

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

#define len(a) ((int)a.size())
using i64 = int64_t;
using str = string;

seed_seq sseq{
    (i64)chrono::steady_clock::now().time_since_epoch().count(),
    (i64)__builtin_ia32_rdtsc(),
    (i64)make_unique<char>().get()
};
mt19937 mt(sseq);
template<class T = int> T rng(T l, T r) {
    return uniform_int_distribution<T>{l, r}(mt);
}

const int mod = (int)1e9 + 7;
int add(int a, int b) { return (a -= mod - b) < 0 ? a + mod : a; }
int mul(i64 a, int b) { return int(a * b % mod); }
int inv(int a) {
    int b = mod, x = 1, y = 0;
    while (b) {
        x = exchange(y, x - a / b * y);
        a = exchange(b, a % b);
    }
    return x < 0 ? x + mod : x;
}
int divi(int a, int b) { return mul(a, inv(b)); }
int weyl(int a) {
    static const int gamma = rng(0, mod - 1), s = rng(0, mod - 1);
    return add(mul(a, gamma), s);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    str s, t;
    cin >> s >> t;
    int n = len(s), m = len(t);
    for (int w = min(n, m); w >= 1; w--) {
        set<int> vals;
        int hash = 1;
        for (int i = 0; i < n; i++) {
            int j = i - w;
            hash = mul(hash, weyl(s[i]));
            if (j >= 0) hash = divi(hash, weyl(s[j]));
            if (j + 1 >= 0) vals.insert(hash);
        }
        hash = 1;
        for (int i = 0; i < m; i++) {
            int j = i - w;
            hash = mul(hash, weyl(t[i]));
            if (j >= 0) hash = divi(hash, weyl(t[j]));
            if (j + 1 >= 0 && vals.count(hash)) {
                cout << w << "\n";
                return 0;
            }
        }
    }
    cout << "0\n";
}
accuracy: 0.20967741935483872
time_ms: 120
memory_kb: 3468
final_rank: 12

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
#include <array>
using item = std::array<int, 26>;
std::vector<item> enumerate(const std::string& s, const int L) {
    std::vector<item> res;
    item cur;
    cur.fill(0);
    for (int i = 0 ; i < L ; i++) cur[s[i] - 'a']++;
    for (int i = L ; i <= std::ssize(s) ; i++) {
        res.push_back(cur);
        if (i < std::ssize(s)) {
            cur[s[i] - 'a']++;
            cur[s[i - L] - 'a']--;
        }
    }
    return res;
}
int solve(const std::string& S, const std::string& T) {
    int ans = 0;
    for (int L = 1 ; L <= std::min(std::ssize(S), std::ssize(T)) ; L++) {
        auto A = enumerate(S, L);
        ranges::sort(A.begin(), A.end());
        for (const auto& b : enumerate(T, L)) {
            auto it = ranges::lower_bound(A, b);
            if (it != A.end() and *it == b) {
                ans = L;
                break;
            }
        }
    }
    return ans;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::string S, T;
    std::cin >> S >> T;
    std::cout << solve(S, T) << '\n';
}
accuracy: 1
time_ms: 2330
memory_kb: 4604
final_rank: 7

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
ll f(vector<ll> ar, ll mod)
{
    ll base = 1;
    ll ret = 0;
    rep(i, 0, ar.size())
    {
        ll t = base * ar[i];
        ret += t;
        ret %= mod;
        base *= 301;
        base %= mod;
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<vector<ll>> ar(s.length() + 1, vector<ll>(26));
    rep(i, 0, s.length())
    {
        ar[i + 1][s[i] - 'a']++;
    }
    rep(i, 0, s.length())
    {
        rep(j, 0, 26)
        {
            ar[i + 1][j] += ar[i][j];
        }
    }
    vector<ll> p = {4294967189, 4294966661, 4294966657};
    vector<vector<ll>> st(3);
    vector<ll> in(26);
    rep(i, 0, s.length())
    {
        rep(j, i, s.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar[j + 1][k] - ar[i][k];
            }
            rep(k, 0, 3)
            {
                st[k].push_back(f(in, p[k]));
            }
        }
    }
    vector<vector<ll>> ar2(t.length() + 1, vector<ll>(26));
    rep(i, 0, t.length())
    {
        ar2[i + 1][t[i] - 'a']++;
    }
    rep(i, 0, t.length())
    {
        rep(j, 0, 26)
        {
            ar2[i + 1][j] += ar2[i][j];
        }
    }
    rep(i, 0, 3)
    {
        srt(st[i]);
    }
    ll ans = 0;
    rep(i, 0, t.length())
    {
        rep(j, i, t.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar2[j + 1][k] - ar2[i][k];
            }
            bool F = true;
            rep(k, 0, 3)
            {
                ll x = f(in, p[k]);
                auto itr = lower_bound(all(st[k]), x);
                if (itr == st[k].end())
                {
                    F = false;
                    break;
                }
                else
                {
                    if (*itr != x)
                    {
                        F = false;
                        break;
                    }
                }
            }
            if (F)
            {
                chmax(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 8610
memory_kb: 195896
final_rank: 11

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
ll f(vector<ll> ar, ll mod)
{
    ll base = 1;
    ll ret = 0;
    rep(i, 0, ar.size())
    {
        ll t = base * ar[i];
        ret += t;
        ret %= mod;
        base *= 301;
        base %= mod;
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<vector<ll>> ar(s.length() + 1, vector<ll>(26));
    rep(i, 0, s.length())
    {
        ar[i + 1][s[i] - 'a']++;
    }
    rep(i, 0, s.length())
    {
        rep(j, 0, 26)
        {
            ar[i + 1][j] += ar[i][j];
        }
    }
    vector<ll> p = {998244353, 1000000007, 4294966657};
    vector<vector<ll>> st(3);
    vector<ll> in(26);
    rep(i, 0, s.length())
    {
        rep(j, i, s.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar[j + 1][k] - ar[i][k];
            }
            rep(k, 0, 3)
            {
                st[k].push_back(f(in, p[k]));
            }
        }
    }
    vector<vector<ll>> ar2(t.length() + 1, vector<ll>(26));
    rep(i, 0, t.length())
    {
        ar2[i + 1][t[i] - 'a']++;
    }
    rep(i, 0, t.length())
    {
        rep(j, 0, 26)
        {
            ar2[i + 1][j] += ar2[i][j];
        }
    }
    rep(i, 0, 3)
    {
        srt(st[i]);
    }
    ll ans = 0;
    rep(i, 0, t.length())
    {
        rep(j, i, t.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar2[j + 1][k] - ar2[i][k];
            }
            bool F = true;
            rep(k, 0, 3)
            {
                ll x = f(in, p[k]);
                auto itr = lower_bound(all(st[k]), x);
                if (itr == st[k].end())
                {
                    F = false;
                    break;
                }
                else
                {
                    if (*itr != x)
                    {
                        F = false;
                        break;
                    }
                }
            }
            if (F)
            {
                chmax(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.20967741935483872
time_ms: 8640
memory_kb: 195896
final_rank: 20

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
ll f(vector<ll> ar)
{
    ll mod = 998244353;
    ll base = 1;
    ll ret = 0;
    rep(i, 0, ar.size())
    {
        ll t = base * ar[i];
        ret += t;
        ret %= mod;
        base *= 301;
        base %= mod;
    }
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<vector<ll>> ar(s.length() + 1, vector<ll>(26));
    rep(i, 0, s.length())
    {
        ar[i + 1][s[i] - 'a']++;
    }
    rep(i, 0, s.length())
    {
        rep(j, 0, 26)
        {
            ar[i + 1][j] += ar[i][j];
        }
    }
    vector<ll> st;
    vector<ll> in(26);
    rep(i, 0, s.length())
    {
        rep(j, i, s.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar[j + 1][k] - ar[i][k];
            }
            st.push_back(f(in));
        }
    }
    vector<vector<ll>> ar2(t.length() + 1, vector<ll>(26));
    rep(i, 0, t.length())
    {
        ar2[i + 1][t[i] - 'a']++;
    }
    rep(i, 0, t.length())
    {
        rep(j, 0, 26)
        {
            ar2[i + 1][j] += ar2[i][j];
        }
    }
    srt(st);
    ll ans = 0;
    rep(i, 0, t.length())
    {
        rep(j, i, t.length())
        {
            rep(k, 0, 26)
            {
                in[k] = ar2[j + 1][k] - ar2[i][k];
            }
            auto itr = lower_bound(all(st), f(in));
            if (itr == st.end())
            {
                continue;
            }
            if (*itr == f(in))
            {
                chmax(ans, j - i + 1);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.20967741935483872
time_ms: 4600
memory_kb: 71124
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

const ll mod1=998244353;
const ll mod2=1e9+7;

void Add(int &a,int &b,int &c,int &d){
	a+=b;
	a%=mod1;
	c+=d;
	c%=mod2;
}
void Sub(int &a,int &b,int &c,int &d){
	a+=mod1-b;
	a%=mod1;
	c+=mod2-d;
	c%=mod2;
}

int main(){
	random_device sd;
	mt19937 mt(sd());

	vector<int> rd1(26),rd2(26);{
		set<int> st1,st2;
		for(int i=0; i<26; i++){
			while(true){
				int r=mt()%mod1;
				if(r==0||st1.count(r)) continue;
				st1.insert(r);
				rd1[i]=r;
				break;
			}
			while(true){
				int r=mt()%mod2;
				if(r==0||st2.count(r)) continue;
				st2.insert(r);
				rd2[i]=r;
				break;
			}
		}
	}

	string S,T; cin>>S>>T;
	int N=S.size(),M=T.size();

	for(int l=min(N,M); l>0; l--){
		set<pair<int,int>>ha;
		{
			int a=0,c=0;
			for(int i=0; i<l-1; i++) Add(a,rd1[S[i]-'a'],c,rd2[S[i]-'a']);
			for(int i=l-1; i<N; i++){
				Add(a,rd1[S[i]-'a'],c,rd2[S[i]-'a']);
				ha.insert({a,c});
				Sub(a,rd1[S[i-l+1]-'a'],c,rd2[S[i-l+1]-'a']);
			}
		}
		{
			int a=0,c=0;
			for(int i=0; i<l-1; i++) Add(a,rd1[T[i]-'a'],c,rd2[T[i]-'a']);
			for(int i=l-1; i<M; i++){
				Add(a,rd1[T[i]-'a'],c,rd2[T[i]-'a']);
				if(ha.count({a,c})){
					cout<<l<<endl;
					return 0;
				}
				Sub(a,rd1[T[i-l+1]-'a'],c,rd2[T[i-l+1]-'a']);
			}
		}
	}

	cout<<0<<endl;
}
accuracy: 1
time_ms: 1280
memory_kb: 3604
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;

const ll mod=998244353;

void Add(int &a,int &b){
	a+=b;
	a%=mod;
}
void Sub(int &a,int &b){
	a+=mod-b;
	a%=mod;
}

int main(){
	random_device sd;
	mt19937 mt(sd());

	vector<int> rd(26);{
		set<int> st;
		for(int i=0; i<26; i++){
			while(true){
				int r=mt()%mod;
				if(r==0||st.count(r)) continue;
				st.insert(r);
				rd[i]=r;
				break;
			}
		}
	}

	string S,T; cin>>S>>T;
	int N=S.size(),M=T.size();

	for(int l=min(N,M); l>0; l--){
		set<int> ha;
		{
			int a=0;
			for(int i=0; i<l-1; i++) Add(a,rd[S[i]-'a']);
			for(int i=l-1; i<N; i++){
				Add(a,rd[S[i]-'a']);
				ha.insert(a);
				Sub(a,rd[S[i-l+1]-'a']);
			}
		}
		{
			int a=0;
			for(int i=0; i<l-1; i++) Add(a,rd[T[i]-'a']);
			for(int i=l-1; i<M; i++){
				Add(a,rd[T[i]-'a']);
				if(ha.count(a)){
					cout<<l<<endl;
					return 0;
				}
				Sub(a,rd[T[i-l+1]-'a']);
			}
		}
	}

	cout<<0<<endl;
}
accuracy: 0.20967741935483872
time_ms: 260
memory_kb: 3464
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

template<typename T>struct BIT{
    int n; T all=0; vector<T> val;
    BIT(int _n=0):n(_n),val(_n+10){}
    void clear(){val.assign(n+10,0); all=T();}
    void add(int i,T x){
        for(i++;i<=n;i+=(i&-i))val[i]=val[i]+x;
        all+=x;
    }
    T sum(int i){
        T res=0;
        for(;i;i-=(i&-i))res+=val[i];
        return res;
    }
    T sum(int L,int R){return sum(R)-sum(L);} // [L,R)

    int lower_bound(T x){
        int ret=0,len=1;
        while(2*len<=n)len<<=1;
        for(;len>=1;len>>=1){
            if(ret+len<=n and val[ret+len]<x){
                ret+=len;
                x-=val[ret];
            }
        }
        return ret;
    }
};

/**
 * @brief Binary Indexed Tree
 */

int main() {
    string S, T;
    cin >> S >> T;
    if (S.size() > T.size()) swap(S,T);
    int N = S.size(), M = T.size();
    rrep(i,1,N+1) {
        set<vector<int>> st;
        vector<int> C(26,0);
        rep(j,0,i) C[S[j]-'a']++;
        st.insert(C);
        rep(j,i,N) C[S[j]-'a']++, C[S[j-i]-'a']--, st.insert(C);
        rep(j,0,26) C[j] = 0;
        rep(j,0,i) C[T[j]-'a']++;
        if (st.count(C)) {
            cout << i << endl;
            return 0;
        }
        rep(j,i,M) {
            C[T[j]-'a']++, C[T[j-i]-'a']--;
            if (st.count(C)) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 1
time_ms: 1600
memory_kb: 4112
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<set>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> cnt(26, 0);
    for(int len = min((int)s.size(), (int)t.size()); len >= 1; --len) {
        set<vector<int> > all;
        fill(cnt.begin(), cnt.end(), 0);
        for(int i = 0; i < len; ++i) ++cnt[s[i] - 'a'];
        for(int i = len; i < (int)s.size(); ++i) {
            all.insert(cnt);
            --cnt[s[i - len] - 'a'];
            ++cnt[s[i] - 'a'];
        }
        all.insert(cnt);

        fill(cnt.begin(), cnt.end(), 0);
        for(int i = 0; i < len; ++i) ++cnt[t[i] - 'a'];
        for(int i = len; i < (int)t.size(); ++i) {
            if(all.find(cnt) != all.end()) {cout << len << '\n'; return 0;}
            --cnt[t[i - len] - 'a'];
            ++cnt[t[i] - 'a'];
        }
        if(all.find(cnt) != all.end()) {cout << len << '\n'; return 0;}
    }
    cout << 0 << '\n';
    return 0;
}
accuracy: 1
time_ms: 1880
memory_kb: 3844
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
#include<set>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> cnt(26, 0);
    for(int len = min((int)s.size(), (int)t.size()); len >= 1; --len) {
        set<vector<int>> all;
        fill(cnt.begin(), cnt.end(), 0);
        for(int i = 0; i < len; ++i) ++cnt[s[i] - 'a'];
        for(int i = len; i < (int)s.size(); ++i) {
            all.insert(cnt);
            --cnt[s[i - len] - 'a'];
            ++cnt[s[i] - 'a'];
        }
        all.insert(cnt);

        fill(cnt.begin(), cnt.end(), 0);
        for(int i = 0; i < len; ++i) ++cnt[t[i] - 'a'];
        for(int i = len; i < (int)t.size(); ++i) {
            if(all.find(cnt) != all.end()) {cout << len << '\n'; return 0;}
            --cnt[t[i - len] - 'a'];
            ++cnt[t[i] - 'a'];
        }
        if(all.find(cnt) != all.end()) {cout << len << '\n'; return 0;}
    }
    cout << 0 << '\n';
    return 0;
}
accuracy: 1
time_ms: 1600
memory_kb: 4116
final_rank: 5