OI XXXII - ana

// https://szkopul.edu.pl/problemset/problem/147B4xwesQFef6eQCa0daM_t/site/?key=statement

#include <bits/stdc++.h>

// #define GARY_DBG
#define GARY_LIB

constexpr int sizik = 200 * 1001;

#define ar std::array

typedef std::vector<std::vector<int>> _kra;

#define int int64_t

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int n;
std::string s;

bool hasAtMostOneBitSet(int64_t x) {
    return x == 0 || (x & (x - 1)) == 0;
}

std::pair<bool, int> maseczka(int i, int x, int curr_mask, const std::multiset<int>& st) {
    if ((i + 1) >= x && hasAtMostOneBitSet(curr_mask)) {
        return {true, curr_mask};
    }

    if (st.find(curr_mask) != st.end()) {
        return {true, curr_mask};
    }

    for (int j = 1; j <= ('z' - 'a' + 1); j++) {
        int local_mask = curr_mask ^ ((int)1 << j);
        if (st.find(curr_mask ^ ((int)1 << j)) != st.end()) {
            return {true, local_mask};
        }
    }

    return {false, 0};
}

bool isGood(int x, bool daj_wyn = false) {
    std::queue<std::pair<int, int>> q;
    std::multiset<int> st;
    std::unordered_map<int, int, custom_hash> um;
    std::vector<std::pair<int, int>> ve;

    int curr_mask = 0;
    for (int i = 0; i < n; i++) {
        curr_mask ^= ((int)1 << (s[i] - 'a' + 1));

        while (!q.empty() && q.front().second + x <= i) {
            st.insert(q.front().first);
            if (um[q.front().first] == 0) {
                um[q.front().first] = q.front().second;
            }
            q.pop();
        }

        auto [isOk, local_mask] = maseczka(i, x, curr_mask, st);

        if (isOk) {
            if (i == (n - 1)) {
                if (daj_wyn) {
                    std::vector<int> ans;
                    ans.push_back(i);

                    while (!ve.empty() && !(ve.back().second + x <= i)) {
                        ve.pop_back();
                    }

                    int maska = curr_mask, pos = i;
                    while (!hasAtMostOneBitSet(maska)) {
                        while (ve.back().second > pos - x) {
                            st.erase(st.lower_bound(ve.back().first));
                            ve.pop_back();
                        }
                        auto [_, nowa_maska] = maseczka(pos, x, maska, st);
                        pos = um[nowa_maska];
                        ans.push_back(pos);
                        maska = nowa_maska;
                    }

                    std::cout << ans.size() << '\n';
                    std::reverse(ans.begin(), ans.end());
                    for (int j = 0; j < (int)ans.size(); j++) {
                        if (j == 0) {
                            std::cout << 1 << " " << (ans[j] + 1) << '\n';
                        } else if ((j + 1) == (int)ans.size()) {
                            std::cout << (ans[j - 1] + 2) << " " << n << '\n';
                        } else {
                            std::cout << (ans[j - 1] + 2) << " " << (ans[j] + 1) << '\n';
                        }
                    }
                }

                return true;
            }

            q.push({curr_mask, i});
            if (daj_wyn) {
                ve.push_back({curr_mask, i});
            }
        }
    }

    return false;
}

void solve() {
    std::cin >> n;
    std::cin >> s;

    assert(n == (int)s.size());

    int l = 1, r = n;
    while (l < r) {
        int sr = (l + r + 1) / 2;
        if (isGood(sr)) {
            l = sr;
        } else {
            r = sr - 1;
        }
    }

    std::cout << l << '\n';
    if (l == 1) {
        std::cout << n << "\n";
        for (int i = 1; i <= n; i++) {
            std::cout << i << " " << i << '\n';
        }
    } else {
        isGood(l, true);
    }
}

int32_t main() {
#ifndef GARY_DBG
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
#endif

    int t = 1;
    // std::cin >> t;

    for (; t > 0; t--) {
        solve();
    }

    return 0;
}