QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#612019#9425. Generated Stringucup-team4435TL 1259ms59424kbC++2023.8kb2024-10-05 02:15:192024-10-05 02:15:19

Judging History

你现在查看的是测评时间为 2024-10-05 02:15:19 的历史记录

  • [2024-10-14 17:49:05]
  • hack成功,自动添加数据
  • (/hack/995)
  • [2024-10-13 20:42:17]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:TL
  • 用时:1252ms
  • 内存:59304kb
  • [2024-10-05 02:15:19]
  • 评测
  • 测评结果:97
  • 用时:1259ms
  • 内存:59424kb
  • [2024-10-05 02:15:19]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}


// faster implementation
// source: https://judge.yosupo.jp/submission/42086
void SA_IS(const int *s, int *SA, int n, int K) {
    // s 为字符串数组[0..n-1] 必须保证 s[n-1]=0 且为最小值
    // SA 为存储后缀数组[0..n-1]
    // n 为字符串长度
    // K 为值域

    bool *t = new bool[n]; // 类型数组
    int *bkt = new int[K]; // 桶
    int *bkt_l = new int[K];
    int *bkt_r = new int[K];
    int n1 = 0; // LMS-后缀的数量
    int *p1;    //按出现顺序存储所有 LMS-后缀的索引

#define is_S_type(x) (t[x])
#define is_L_type(x) (!t[x])
#define is_LMS_type(x) (is_S_type(x) && x != 0 && is_L_type(x - 1))

    // 预处理每一个后缀的类型
    t[n - 1] = true; // 0 为 S-型后缀且为 LMS-型后缀
    for (int i = n - 2; i >= 0; --i) {
        t[i] = (s[i] < s[i + 1] || (is_S_type(i + 1) && s[i] == s[i + 1]));
        n1 += is_LMS_type(i + 1); // s[0] 必然不是 LMS-型后缀,不会影响
    }

    // 预处理桶的边界
    for (int i = 0; i != K; ++i) bkt[i] = 0;
    for (int i = 0; i != n; ++i) ++bkt[s[i]];
    for (int i = 0, sum = 0; i != K; ++i) sum += bkt[i], bkt_r[i] = sum, bkt_l[i] = sum - bkt[i];

#define indecud_sort()                                                                             \
  do {                                                                                             \
    for (int i = 0; i != K; ++i) bkt[i] = bkt_l[i];                                                \
    for (int i = 0, j; i != n; ++i)                                                                \
      if ((j = SA[i] - 1) >= 0 && is_L_type(j)) SA[bkt[s[j]]++] = j;                               \
    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];                                                \
    for (int i = n - 1, j; i >= 0; --i)                                                            \
      if ((j = SA[i] - 1) >= 0 && is_S_type(j)) SA[--bkt[s[j]]] = j;                               \
  } while (0)

    // 将所有 LMS-后缀放入 SA 对应桶的末尾并诱导排序
    p1 = new int[n1];
    for (int i = 0, j = 0; i != n; ++i) {
        SA[i] = -1;
        if (is_LMS_type(i)) p1[j++] = i;
    }
    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];
    for (int i = n1 - 1; i >= 0; --i) SA[--bkt[s[p1[i]]]] = p1[i];
    indecud_sort();

    int *s1 = new int[n1];  // 新的字符串
    int *SA1 = new int[n1]; // 存储新的字符串排的后缀数组
    for (int i = 0, j = 0; i != n; ++i)
        if (is_LMS_type(SA[i])) SA1[j++] = SA[i]; // 存储 LMS-子串的相对顺序
    int name = 0;
    // 对所有 LMS-子串命名
    for (int i = 0, prev = -1; i != n1; ++i) {
        int pos = SA1[i];
        for (int j = 0;; ++j) // 无需设置范围,因为 s[n-1]=0 为最小值且不会出现在其余位置
            if (prev == -1 || s[pos + j] != s[prev + j] || is_S_type(pos + j) != is_S_type(prev + j)) {
                prev = pos, ++name;
                break;
            } else if (j != 0 && (is_LMS_type(pos + j) || is_LMS_type(prev + j))) // 到末尾了停止比较
                break;
        SA[pos] = name - 1; // 利用 SA 暂时存储新字符串的 name
    }
    for (int i = 0; i != n1; ++i) s1[i] = SA[p1[i]];

    if (name != n1)
        SA_IS(s1, SA1, n1, name);
    else
        for (int i = 0; i != n1; ++i) SA1[s1[i]] = i;

    for (int i = 0; i != K; ++i) bkt[i] = bkt_r[i];
    for (int i = 0; i != n; ++i) SA[i] = -1;
    for (int i = n1 - 1; i >= 0; --i) SA[--bkt[s[p1[SA1[i]]]]] = p1[SA1[i]];
    indecud_sort();

    delete[] SA1;
    delete[] s1;
    delete[] p1;
    delete[] bkt_r;
    delete[] bkt_l;
    delete[] bkt;
    delete[] t;

#undef is_S_type
#undef is_L_type
#undef is_LMS_type
#undef indecud_sort
}


const ll INF = 2e18;
const int INFi = 1e9;
const int N = 2e5 + 50;
const int LG = 20;

template<typename T, typename merge_t>
struct sparse_table {
    std::vector<std::vector<T>> sparse;
    const merge_t merge;

    sparse_table(const merge_t &merge) : merge(merge) {}

    sparse_table(const std::vector<T> &a, const merge_t &merge) : merge(merge) {
        if (a.empty())
            return;

        const int n = int(a.size()), lg = std::__lg(n);
        sparse.reserve(lg + 1);
        sparse.push_back(a);

        for (int level = 1; level <= lg; level++) {
            sparse.push_back(std::vector<T>(n - (1 << level) + 1));
            for (int i = 0; i < int(sparse[level].size()); i++)
                sparse[level][i] = merge(sparse[level - 1][i], sparse[level - 1][i + (1 << (level - 1))]);
        }
    }

    sparse_table &operator=(const sparse_table<T, merge_t> &another) {
        sparse = another.sparse;
        return *this;
    }

    T query(int l, int r) const {
        assert(l < r);
        const int level = std::__lg(r - l);
        return merge(sparse[level][l], sparse[level][r - (1 << level)]);
    }
};


std::vector<int> get_sa(const std::string &s) {
    int len = s.size();
    std::vector<int> SA(len + 1), s_cpy(len + 1);
    for (int i = 0; i != len; ++i) s_cpy[i] = s[i];
    s_cpy.back() = 0;
    SA_IS(s_cpy.data(), SA.data(), len + 1, 128);
    return std::vector<int>(SA.begin() + 1, SA.end());
}

auto min_merge = [](int x, int y) {
    return min(x, y);
};

struct suffix_array {
    std::vector<int> order, suffix_position, lcp;
    string s;

    sparse_table<int, decltype(min_merge)> sp;

    suffix_array() : sp(min_merge) {
    }

    void build(std::string str) {
        order.clear();
        suffix_position.clear();
        lcp.clear();
        s.clear();

        s = str;
        int n = str.size() + 1;
        order = get_sa(str);
        order.insert(order.begin(), n - 1);

        suffix_position.resize(n);
        for (int i = 0; i < n; i++) {
            suffix_position[order[i]] = i;
        }

        lcp.resize(n);
        int current_lcp = 0;
        for (int suffix = 0; suffix < n - 1; suffix++, current_lcp = current_lcp == 0 ? 0 : current_lcp - 1) {
            int previous_suffix = order[suffix_position[suffix] - 1];
            while (str[suffix + current_lcp] == str[previous_suffix + current_lcp])
                current_lcp++;

            lcp[suffix_position[suffix]] = current_lcp;
        }

        sp = sparse_table<int, decltype(min_merge)>(lcp, min_merge);
    }

    int LCP(int l, int r) {
        if (l == r) return (int) suffix_position.size() - 1 - l;
        l = suffix_position[l];
        r = suffix_position[r];
        if (l > r) swap(l, r);
        return sp.query(l + 1, r + 1);
    }

    char Get(int pos) {
        return s[pos];
    }
} S;

namespace rect_solve {
    template<typename Val = long long>
    struct binary_indexed_tree {
        int M, H;
        std::vector<Val> sum;

        binary_indexed_tree() {}

        binary_indexed_tree(int N) : M(N), H(31 - __builtin_clz(M)), sum(M + 1, 0) { assert(N > 0); }

        binary_indexed_tree(const std::vector<Val> &v) : M(v.size()), H(31 - __builtin_clz(M)), sum(1) {
            assert(v.size() > 0);
            sum.insert(sum.begin() + 1, v.begin(), v.end());
            for (int i = 1; i <= v.size(); i++) {
                int nxt = i + (i & (-i));
                if (nxt <= M) sum[nxt] += sum[i];
            }
        }

        void update(int k, Val x) {
            for (int i = k + 1; i <= M; i += (i & (-i))) sum[i] += x;
        }

        Val query(int r) {
            Val ret = 0;
            for (int k = r; k > 0; k -= (k & (-k))) ret += sum[k];
            return ret;
        }

        Val query(int l, int r) {
            return query(r) - query(l);
        }
        // sum[0, k]がx以上になるような最小のkとsum[0, k], 無い場合は{M, 総和}
        // sumが単調非減少であることが必要
        using p = std::pair<int, Val>;

        p lower_bound(Val x) {
            int v = 1 << H, h = H;
            Val s = 0, t = 0;
            while (h--) {
                if (M < v) v -= 1 << h;
                else if (x <= s + sum[v]) t = s + sum[v], v -= 1 << h;
                else s += sum[v], v += 1 << h;
            }
            if (v == M + 1) return {M, s};
            return (x <= s + sum[v] ? p{v - 1, s + sum[v]} : p{v, t});
        }
    };
//#line 3 ".lib/minior/map_sum_cache.hpp"
//#include <limits>
//#line 5 ".lib/minior/map_sum_cache.hpp"

    template<typename Key, typename Val>
    struct map_sum_cache {
        static constexpr Key inf = std::numeric_limits<Key>::max();
        static constexpr Val inf_val = std::numeric_limits<Val>::max();
        static constexpr int limit_size_per_node = 16;
    private:
        struct node {
            int h, sz, sz_sum;
            std::array<Key, limit_size_per_node> keys;
            std::array<Val, limit_size_per_node> vals;
            Val sum, sumsub;
            node *l, *r;

            node() : h(1), l(nullptr), r(nullptr), sum(0) {}

            node(Key _key, Val _val) : h(1), sz(1), sz_sum(1), l(nullptr), r(nullptr) {
                keys[0] = _key;
                vals[0] = sum = sumsub = _val;
            }

            node(const std::vector<std::pair<Key, Val>> &v, int l, int r) : h(1), sz(r - l), sz_sum(sz), sum(0),
                                                                            l(nullptr), r(nullptr) {
                assert(sz < limit_size_per_node);
                for (int i = 0; i < sz; i++) {
                    keys[i] = v[l + i].first;
                    vals[i] = v[l + i].second;
                    sum += vals[i];
                }
                sumsub = sum;
            }

            int balanace_factor() {
                return (l ? l->h : 0) - (r ? r->h : 0);
            }

            node *split_half() {
                assert(sz == limit_size_per_node);
                node *u = new node();
                sz = limit_size_per_node / 2;
                u->sz_sum = u->sz = limit_size_per_node - sz;
                for (int i = 0; i < u->sz; i++) {
                    u->keys[i] = keys[sz + i];
                    u->vals[i] = vals[sz + i];
                    u->sum += u->vals[i];
                }
                u->sumsub = u->sum;
                sum -= u->sum;
                return u;
            }
        };

        node *root;

        int size(node *v) { return v ? v->sz_sum : 0; }

        void update(node *v) {
            v->h = std::max(v->l ? v->l->h : 0, v->r ? v->r->h : 0) + 1;
            v->sz_sum = (v->l ? v->l->sz_sum : 0) + (v->r ? v->r->sz_sum : 0) + v->sz;
            v->sumsub = (v->l ? v->l->sumsub : 0) + (v->r ? v->r->sumsub : 0) + v->sum;
        }

        node *rotate_right(node *v) {
            node *l = v->l;
            v->l = l->r;
            l->r = v;
            update(v);
            update(l);
            return l;
        }

        node *rotate_left(node *v) {
            node *r = v->r;
            v->r = r->l;
            r->l = v;
            update(v);
            update(r);
            return r;
        }

        node *balance(node *v) {
            int bf = v->balanace_factor();
            assert(-2 <= bf && bf <= 2);
            if (bf == 2) {
                if (v->l->balanace_factor() == -1) {
                    v->l = rotate_left(v->l);
                    update(v);
                }
                return rotate_right(v);
            } else if (bf == -2) {
                if (v->r->balanace_factor() == 1) {
                    v->r = rotate_right(v->r);
                    update(v);
                }
                return rotate_left(v);
            }
            return v;
        }

        node *build(const std::vector<node *> &nodes, int l, int r) {
            int m = (l + r) >> 1;
            node *v = nodes[m];
            if (m > l) v->l = build(nodes, l, m);
            if (r > m + 1) v->r = build(nodes, m + 1, r);
            update(v);
            return v;
        }

        node *insert_leftmost(node *v, node *u) {
            if (!v) return u;
            v->l = insert_leftmost(v->l, u);
            update(v);
            return balance(v);
        }

        node *emplace_inner(node *v, Key k, Val val, bool replace = false) {
            if (!v) return new node(k, val);
            if (v->l && k < v->keys[0]) {
                v->l = emplace_inner(v->l, k, val, replace);
            } else if (v->r && v->keys[v->sz - 1] < k) {
                v->r = emplace_inner(v->r, k, val, replace);
            } else {
                int idx = std::lower_bound(v->keys.begin(), v->keys.begin() + v->sz, k) - v->keys.begin();
                if (idx < v->sz && v->keys[idx] == k) {
                    v->vals[idx] += val;
                    v->sum += val;
                    v->sumsub += val;
                    return v;
                }
                for (int i = v->sz; i > idx; i--) {
                    v->keys[i] = v->keys[i - 1];
                    v->vals[i] = v->vals[i - 1];
                }
                v->keys[idx] = k;
                v->vals[idx] = val;
                v->sum += val;
                v->sz++;
                if (v->sz == limit_size_per_node) {
                    v->r = insert_leftmost(v->r, v->split_half());
                }
            }
            update(v);
            return balance(v);
        }

        Val query_inner(node *v, Key k) {
            Val ret = 0;
            while (v) {
                if (k < v->keys[0]) {
                    v = v->l;
                } else if (k > v->keys[v->sz - 1]) {
                    ret += (v->l ? v->l->sumsub : 0) + v->sum;
                    v = v->r;
                } else {
                    ret += (v->l ? v->l->sumsub : 0);
                    for (int i = 0; i < v->sz; i++) {
                        if (v->keys[i] >= k) return ret;
                        ret += v->vals[i];
                    }
                }
            }
            return ret;
        }

    public:
        map_sum_cache() : root(nullptr) {}

        map_sum_cache(std::vector<std::pair<Key, Val>> v) {
            std::sort(v.begin(), v.end());
            init_sorted(v);
        }

        // すでにソート済みかつキーがユニーク
        void init_sorted(const std::vector<std::pair<Key, Val>> &v) {
            if (v.empty()) {
                root = nullptr;
                return;
            }
            int n = v.size();
            int size_per_node = limit_size_per_node / 2;
            int m = (n + size_per_node - 1) / size_per_node;
            std::vector<node *> nodes(m);
            for (int i = 0; i < m; i++) {
                nodes[i] = new node(v, i * size_per_node, std::min((i + 1) * size_per_node, n));
            }
            root = build(nodes, 0, m);
        }

        int size() {
            return size(root);
        }

        void update(Key key, Val val) {
            root = emplace_inner(root, key, val);
        }

        Val query(Key l, Key r) {
            return query_inner(root, r) - query_inner(root, l);
        }
    };
//#line 8 ".lib/data_structure/range_query/point_add_rectangle_sum.hpp"

    template<typename Idx, typename Val>
    struct offline_point_add_rectangle_sum {
    private:
        struct query_type {
            int id;
            Idx lx, rx, ly, ry;
            Val z;

            query_type(int a, Idx b, Idx c, Idx d, Idx e, Val f) : id(a), lx(b), rx(c), ly(d), ry(e), z(f) {}
        };

        struct event_type {
            Idx x;
            int q, id;
            int lyc, ryc;
            Val z;

            event_type(Idx a, int b, int c, int d, int e, Val f) : x(a), q(b), id(c), lyc(d), ryc(e), z(f) {}
        };

        std::vector<query_type> q;
        std::vector<int> qcount{0};
        int qs = 0;

        void solve(int l, int r, std::vector<Val> &ans) {
            if (r - l < 2) return;
            int mid = (l + r) >> 1;
            solve(l, mid, ans);
            solve(mid, r, ans);
            int left_update = (mid - l) - (qcount[mid] - qcount[l]);
            int right_query = qcount[r] - qcount[mid];
            if (left_update == 0 || right_query == 0) return;

            // compress y
            std::vector<Idx> y;
            for (int i = l; i < mid; i++) if (q[i].id == -1) y.push_back(q[i].ly);
            std::sort(y.begin(), y.end());
            y.erase(std::unique(y.begin(), y.end()), y.end());

            binary_indexed_tree<Val> bit(y.size());
            std::vector<event_type> e;
            for (int i = l; i < mid; i++) {
                if (q[i].id == -1) {
                    int y_idx = std::lower_bound(y.begin(), y.end(), q[i].ly) - y.begin();
                    e.push_back(event_type(q[i].lx, 2, -1, y_idx, 0, q[i].z));
                }
            }
            for (int i = mid; i < r; i++) {
                if (q[i].id != -1) {
                    int ly_idx = std::lower_bound(y.begin(), y.end(), q[i].ly) - y.begin();
                    int ry_idx = std::lower_bound(y.begin(), y.end(), q[i].ry) - y.begin();
                    e.push_back(event_type(q[i].lx, 0, q[i].id, ly_idx, ry_idx, 0));
                    e.push_back(event_type(q[i].rx, 1, q[i].id, ly_idx, ry_idx, 0));
                }
            }
            std::sort(e.begin(), e.end(), [](event_type &a, event_type &b) {
                if (a.x != b.x) return a.x < b.x;
                return a.q < b.q;
            });
            for (event_type &ei: e) {
                if (ei.q == 0) {
                    ans[ei.id] -= bit.query(ei.lyc, ei.ryc);
                } else if (ei.q == 1) {
                    ans[ei.id] += bit.query(ei.lyc, ei.ryc);
                } else {
                    bit.update(ei.lyc, ei.z);
                }
            }
        }

    public:
        offline_point_add_rectangle_sum() {}

        void update(Idx x, Idx y, Val z) {
            q.push_back(query_type(-1, x, 0, y, 0, z));
            qcount.push_back(0);
        }

        void query(Idx lx, Idx rx, Idx ly, Idx ry) {
            q.push_back(query_type(qs++, lx, rx, ly, ry, 0));
            qcount.push_back(1);
        }

        std::vector<Val> solve() {
            std::vector<Val> ret(qs, 0);
            for (int i = 1; i < qcount.size(); i++) qcount[i] += qcount[i - 1];
            solve(0, q.size(), ret);
            return ret;
        }
    };
}

struct Element {
    vpi a;
    int idx;
    int priority;

    void read() {
        int k;
        cin >> k;
        a.resize(k);
        for (auto &[l, r]: a) {
            cin >> l >> r;
            l--;
        }
    }
};

bool operator<(const Element &a, const Element &b) {
    int i = 0;
    int used_i = 0;
    int j = 0;
    int used_j = 0;
    while (true) {
        if (j == b.a.size() && i == a.a.size()) return a.priority < b.priority;
        if (j == b.a.size()) return b.priority > 0 ? true : false;
        if (i == a.a.size()) return a.priority > 0 ? false : true;

        int mx_i = a.a[i].second - a.a[i].first - used_i;
        int mx_j = b.a[j].second - b.a[j].first - used_j;
        int mx = min(mx_i, mx_j);
        int len = S.LCP(a.a[i].first + used_i, b.a[j].first + used_j);
        ckmin(len, mx);
        used_i += len;
        used_j += len;
        if (len < mx) return S.Get(a.a[i].first + used_i) < S.Get(b.a[j].first + used_j);
        if (mx_i == len) {
            i++;
            used_i = 0;
        }
        if (mx_j == len) {
            j++;
            used_j = 0;
        }
    }
    return false;
}

void solve() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<Element> elems;
    auto Add = [&](Element e) {
        e.idx = elems.size();
        elems.push_back(e);
        return e.idx;
    };
    vector<ar<int, 5>> qs(q, {-1, -1, -1, -1, -1});
    for (auto &[tp, l1, r1, l2, r2]: qs) {
        char t;
        cin >> t;
        if (t == '+') {
            Element e;
            e.read();
            e.priority = -1;
            tp = 1;
            l1 = Add(e);
        } else if (t == '-') {
            tp = -1;
            int pos;
            cin >> pos;
            pos--;
            l1 = qs[pos][1];
        } else {
            tp = 0;

            Element e1, e2;
            e1.read();
            e2.read();
            e1.priority = -2;
            l1 = Add(e1);
            e1.priority = 2;
            r1 = Add(e1);
            e2.priority = -2;
            l2 = Add(e2);
            e2.priority = 2;
            r2 = Add(e2);
        }
    }
    vector<ar<int, 2>> pos(elems.size());

    rep(rot, 2) {
        S.build(s);

        sort(all(elems));

        rep(i, elems.size()) pos[elems[i].idx][rot] = i;


        reverse(all(s));
        for (auto &e: elems) {
            for (auto &[l, r]: e.a) {
                r--;
                swap(l, r);
                l = n - 1 - l;
                r = n - 1 - r;
                r++;
            }
            reverse(all(e.a));
        }
    }

    rect_solve::offline_point_add_rectangle_sum<int, ll> rect1, rect2;

    int idx = 0;
    for (auto &[tp, l1, r1, l2, r2]: qs) {
        if (tp == 1) {
            int i = l1;
            l1 = r1 = pos[i][0];
            l2 = r2 = pos[i][1];
//            cerr << "+ " << l1 << ' ' << l2 << endl;
            rect1.update(l1, l2, 1);
        } else if (tp == -1) {
            int i = l1;
            l1 = r1 = pos[i][0];
            l2 = r2 = pos[i][1];
//            cerr << "- " << l1 << ' ' << l2 << endl;
            rect2.update(l1, l2, 1);
        } else {
            l1 = pos[l1][0];
            r1 = pos[r1][0];
            l2 = pos[l2][1];
            r2 = pos[r2][1];
//            cerr << "? " << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << endl;
            rect1.query(l1, r1, l2, r2);
            rect2.query(l1, r1, l2, r2);
        }
    }

    auto ans1 = rect1.solve();
    auto ans2 = rect2.solve();
    rep(i, ans1.size()) {
        cout << ans1[i] - ans2[i] << '\n';
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

8 7
abcaabbc
+ 3 1 3 2 4 3 8
+ 2 1 4 1 8
+ 1 2 4
? 1 5 6 1 7 8
- 3
+ 1 2 5
? 1 2 3 1 5 5

output:

2
1

result:

ok 2 lines

Test #2:

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

input:

5 2000
bbaab
+ 1 3 5
+ 2 5 5 3 5
- 2
? 1 1 3 3 3 3 4 5 2 5
- 1
? 3 1 1 2 4 1 5 1 3 4
? 1 1 2 2 2 4 4 4
? 1 1 5 1 5 5
+ 3 1 2 1 5 1 4
? 2 1 5 1 3 2 1 2 5 5
? 1 3 4 1 4 5
- 9
? 1 1 4 1 2 3
+ 2 1 5 1 2
+ 1 1 4
- 15
- 14
? 2 2 5 2 5 1 3 4
+ 1 2 3
- 19
+ 3 1 4 1 5 4 5
- 21
+ 1 2 5
? 3 1 5 5 5 1 5 1 3 5
?...

output:

0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
0
0
2
0
3
1
0
0
0
0
1
0
0
0
0
0
0
0
0
2
0
0
0
0
0
1
0
0
0
0
0
0
0
3
1
0
1
0
2
0
0
0
3
0
1
0
0
2
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
2
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
0
1
3
2
3
0
0
0
0
0
2
0
0
2
0
0
0
2
3
...

result:

ok 702 lines

Test #3:

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

input:

5 2000
ababa
+ 1 4 4
+ 1 2 2
? 1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0
0
1
7
1
0
1
2
9
0
1
2
2
0
0
2
7
0
4
2
8
2
8
0
1
0
2
0
9
10
1
1
2
1
1
0
0
10
0
0
0
6
0
0
2
4
0
5
4
5
5
5
0
4
0
3
2
2
5
5
5
5
0
0
0
4
0
3
5
5
6
9
6
6
4
6
0
4
6
0
4
4
2
2
12
0
5
6
6
6
13
0
13
2
1
0
1
10
10
5
8
1
8
8
1
1...

result:

ok 672 lines

Test #5:

score: 0
Accepted
time: 430ms
memory: 33212kb

input:

5 100000
bbabb
+ 1 2 5
? 5 4 5 3 5 4 5 2 4 4 5 3 1 5 3 4 3 4
? 2 4 4 1 5 1 1 3
? 1 3 5 5 1 1 1 3 1 1 4 4 3 5
? 1 2 5 2 2 5 2 5
+ 2 1 5 3 3
- 1
+ 4 1 5 1 5 1 5 2 3
? 4 3 5 1 5 1 5 2 5 1 2 4
? 1 1 5 3 4 4 3 4 1 5
- 6
- 8
+ 2 1 5 1 4
- 13
? 1 1 5 3 1 2 3 4 1 3
+ 5 2 4 1 2 1 4 2 2 1 5
- 16
+ 1 1 5
- 18
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
4
0
3
0
0
0
1
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
2
0
8
0
0
0
0
0
0
0
2
0
0
...

result:

ok 33212 lines

Test #6:

score: 0
Accepted
time: 1035ms
memory: 41696kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
1
0
1
0
1
0
5
0
4
1
1
1
1
2
0
3
0
0
0
0
1
1
0
0
2
2
0
0
1
5
1
0
0
3
3
5
2
5
0
8
2
2
2
13
2
2
0
2
4
11
9
5
3
14
4
9
19
12
4
12
11
6
7
8
2
22
7
3
20
7
9
6
0
5
5
17
2
9
9
0
2
7
10
11
0
9
3
4
5
12
6
10
0
2
21
2
9
1
3
1
2
2
10
22
8
21
4
3
16
3
8
2
12
9
0
2
12
4
5
19
16
7
5
4
4
3
8
5
11
4
6
5
13
0
6
5
1...

result:

ok 33583 lines

Test #7:

score: 0
Accepted
time: 402ms
memory: 40332kb

input:

100000 100000
baabbabaabaaaabbaaababaaabbbbbaabbababbabbbaabbaaabbbbababaababbbbbababaabaaabaaababaabbbbaaababbbbabaabbaaaaaabbbabbbabababababaabbabbbbbaaabababbbaabababbbaaababaabbaaaabbabbaabbababaabbaaaababaabbbbbababbaaabbbaababbaaaaaabbbbabbbbbbabbaabababbbaaaaaabbabbabaaaaaabbbaaaaaabaabaaabab...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33381 lines

Test #8:

score: 0
Accepted
time: 1102ms
memory: 40688kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

2
2
0
2
1
1
2
2
2
2
0
0
0
0
0
1
0
0
1
0
0
0
2
2
2
0
1
0
0
0
0
1
0
2
3
0
1
0
1
0
0
1
1
2
2
2
1
1
1
0
0
0
2
0
3
0
0
0
0
0
1
2
0
0
1
1
0
0
0
1
1
2
0
2
1
2
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
1
2
2
1
2
4
3
2
0
2
0
0
1
4
0
0
1
1
5
1
0
1
0
0
2
1
0
3
3
1
0
1
1
2
2
3
0
1
3
7
6
0
7
1
1
1
5
2
5
0
2
6
2
2
2
5
...

result:

ok 33565 lines

Test #9:

score: 0
Accepted
time: 384ms
memory: 39812kb

input:

100000 100000
aaabbbabbaababbbbbbaaababbbaaaaaabbaaaabababbabababbabbabbbaababbbbabaabaaabbaaabbabababbaaabbabbaaaaabbabababbaaaaababbbbabbabaaabbbaabaabbbaaababbbbbabaaabaaaaabbaabaabbabababbabaaabbbbbbbbaababaabbbabaabbabaaabbbbbababaaabbbbbaaaaaaabbbabbbaabbaabbaaaaaaabbbaabbbaabbaaaababbabaababb...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33118 lines

Test #10:

score: 0
Accepted
time: 1194ms
memory: 41096kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
1
0
0
0
2
0
0
0
0
0
0
0
1
0
0
1
0
0
3
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
4
0
1
0
0
0
0
2
0
3
4
4
5
8
7
9
5
0
9
3
8
2
9
0
5
7
1
7
9
0
1
4
1
5
8
5
1
0
0
5
0
4
12
0
9
5
11
10
3
1
8
1
9
2
1
0
5
5
5
0
2
5
1
1
0
0
12
8
11
11
1
4
11
10
3
7
9
9
4
12
11
5
9
6
1
2
8
10
11
4
17
11
6
3
2
4
1
1
3
1
3
2
3
6
5
4
8
12...

result:

ok 33215 lines

Test #11:

score: 0
Accepted
time: 381ms
memory: 40580kb

input:

100000 100000
mwtmtwnsgaynckkprtjhfnmyzylblnkmrismcyyksqxcikyhrsannbmflvloshydnfvydmuoyphxpjgxsfmyqozidivsigleuvmnyniccdqjekyzjtytudpjbwjmsulfipurvjuxququmkfbrigctewalryoiilmqapofcwpllcwjnzmbtirmfmyhbuqkwqhzidrqbxnulklkjmrn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ines

Test #13:

score: 0
Accepted
time: 640ms
memory: 41912kb

input:

100000 100000
bbbbbaabbbbbaaabaabaaabbbbaabaaabaabbababbaaaaaaaabbababbbbabbababaabbabaabbaaaabbbbabaabbababbbbbbbaaabaabbabbbbbbaaaaababaaabbbabbaabaabaaabbbabbaaabaaaababbaaabaabbabaaaaaaababababbbbaabbaaaabaabbbbaaaababbabbbbabaabbbaaabbbaabaaabbbaaabaabbbbbabbaaabbaabbabbaababbbabbababbabbaabbbb...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 33438 lines

Test #14:

score: 0
Accepted
time: 303ms
memory: 42460kb

input:

100000 100000
aaabbbbabbaababbabaabbabababaaaaabbababababaabbaaabbbaaaaaabaaabbabbabbbabaabbaabbabbbbbbbaabaaababaaaaabaaaabbbaaaabbaabbaabbbbaaababbabababbaaaaabbbababababaabaabababbabbbbbabbabbbbaaababbbbaabbaaabababaabbbaaabaaaabbabbaabbbaabbbbabbbababbbabaabbaababaaaabbaabaaabbaaabaaaaabbbbbbbab...

output:

0
0
0
0
0
0
0
2
1
4
0
0
1
1
0
0
0
2
0
0
0
8
2
0
2
0
0
0
0
0
0
7
0
0
0
0
10
5
4
4
0
1
4
0
0
2
4
4
0
0
0
6
0
4
0
0
0
7
4
7
3
5
0
0
0
7
0
7
7
0
8
7
3
0
0
11
0
0
4
11
0
2
2
0
11
9
2
11
3
2
12
3
0
13
0
0
3
0
4
5
0
0
0
4
6
0
0
6
0
4
4
0
0
0
5
5
0
0
6
0
7
0
7
8
7
0
6
6
7
7
7
6
17
6
8
7
7
3
15
0
14
6
0
0
14...

result:

ok 33321 lines

Test #15:

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

input:

5 1000
glbdh
+ 2 2 2 1 2
? 2 1 2 3 4 1 1 5
? 1 3 4 3 2 3 4 4 1 5
- 1
? 1 1 2 2 1 2 1 4
+ 1 1 3
+ 2 1 4 1 2
? 2 4 5 1 2 3 2 3 3 4 1 2
? 2 4 4 1 1 2 3 4 1 3
? 1 1 2 1 1 3
- 7
+ 1 1 5
? 1 3 3 1 1 2
? 3 3 4 4 4 2 3 1 1 2
+ 3 1 5 2 5 1 2
? 1 1 1 3 1 2 3 3 1 2
? 2 4 5 3 3 2 3 3 1 2
? 1 2 3 2 3 4 1 2
? 1 1...

output:

0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
11
0
0
0
0
0
0
0
0
0
1
0
0
0
9
0
0
0
0
3
0
1
0
1
0
1
11
0
0
11
0
0
0
0
0
0
12
0
12
0
0
1
0
0
1
0
0
0
0
0
0
0
11
0
0
0
0
0
0
0
3
0
0
13
0
0
0
0
13
0
0
0
0
0
1
0
0
0
0
0
0
5
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 525 lines

Test #16:

score: 0
Accepted
time: 1192ms
memory: 44052kb

input:

100000 100000
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...

output:

0
0
0
1
0
0
0
2
0
0
0
0
2
0
0
0
0
1
0
0
2
0
0
1
1
1
1
0
1
2
2
0
2
1
1
1
0
2
1
1
1
1
1
1
0
2
3
3
1
1
1
1
4
1
3
4
0
2
2
2
2
3
2
3
2
0
2
1
3
4
4
3
1
4
2
0
0
3
2
3
3
3
2
3
0
3
3
3
3
3
5
4
0
4
3
4
3
4
4
1
3
3
4
5
4
5
1
6
5
6
8
6
3
6
8
6
3
5
2
1
6
4
3
6
3
1
1
3
4
3
5
8
4
3
5
6
3
6
1
7
3
7
8
6
4
7
4
3
1
5
...

result:

ok 49940 lines

Test #17:

score: 0
Accepted
time: 773ms
memory: 34400kb

input:

100000 100000
dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

0
6
5
7
5
8
6
6
17
13
14
20
26
23
16
21
20
17
39
26
31
32
46
39
36
52
36
28
28
28
26
29
46
53
48
55
18
43
44
40
49
25
59
42
57
60
42
36
65
50
52
59
25
56
42
42
16
77
43
42
65
57
57
52
44
48
42
19
43
72
65
56
101
69
37
69
73
106
72
55
66
22
70
60
40
73
81
78
60
79
94
63
74
62
74
78
110
76
107
113
108...

result:

ok 9964 lines

Test #18:

score: 0
Accepted
time: 1259ms
memory: 59424kb

input:

100000 100000
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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 49932 lines

Test #20:

score: 0
Accepted
time: 734ms
memory: 32692kb

input:

100000 100000
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

1
1
1
0
1
2
2
1
4
4
4
6
6
7
7
9
12
12
11
15
8
21
3
4
8
8
26
11
15
11
20
21
22
29
14
26
25
31
34
26
19
11
29
33
17
20
20
27
33
29
29
43
31
33
33
16
35
30
17
24
40
36
41
19
33
38
51
32
64
28
21
50
42
41
46
29
48
51
62
56
30
45
62
37
54
38
22
43
38
45
43
40
59
53
73
73
72
45
68
27
68
64
62
72
51
65
39
...

result:

ok 10030 lines

Test #21:

score: 0
Accepted
time: 1090ms
memory: 58640kb

input:

100000 100000
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp...

output:

0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
1
1
2
0
0
0
1
1
1
1
1
0
1
3
1
1
1
2
0
1
2
3
3
0
1
1
1
1
1
1
2
2
2
0
2
3
1
1
1
1
0
1
1
0
2
0
2
0
1
0
2
3
2
1
1
1
1
1
5
3
0
2
2
2
0
2
2
2
1
2
4
5
2
2
5
2
1
2
5
0
2
5
3
5
5
0
2
2
3
0
4
2
4
0
2
1
2
1
2
2
1
0
2
1
3
1
0
2
0
2
2
0
3
3
3
5
2
2
5
3
6
5
3
3
...

result:

ok 90160 lines

Test #22:

score: 0
Accepted
time: 424ms
memory: 45040kb

input:

100000 100000
faxyuxswncplvrzynzvlbjqvkdhqfmdddimahxygchjxwqaouebuiijkydypsvhlqeoelcnizmzcnuzvxzqilitcmbrhwjtbastbqyktczoarrihswnbsjtzvkrdjkwzijqkcziwqndcfgyvpepsokrgtlvrwxwjbtctdluemgbpzneomxcqdxxaoxdrgdzrherrygznacprcimyudgbjpelkpxotckckzihjuxnlmkczsutackpunsfnkwvhkadjfnhmvplqfgzmkssoacpuxaipepwro...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
2
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
...

result:

ok 49806 lines

Test #23:

score: 0
Accepted
time: 312ms
memory: 33056kb

input:

100000 100000
twdczjujsjrmpsipsunndczjujsjrmpsipsuwynwdczjujsjrmpsipsuwjwdczjujsjrmpsipsuyhtwdczjujsjrmpsipsuwwddczjujsjrmpsipsudczjujsjrmpsipsuybtwdczjujsjrmpsipsuwexdczjujsjrmpsipsuwevtwdczjujsjrmpsipsuwexatwdczjujsjrmpsipsuapwdczjujsjrmpsipsuwepwdczjujsjrmpsipsuwowdczjujsjrmpsipsudczjujsjrmpsipsu...

output:

0
1
0
0
0
1
0
0
1
1
7
0
0
0
0
3
3
0
3
3
1
1
0
0
0
0
0
3
9
13
0
14
5
0
2
10
6
5
2
9
3
9
3
5
6
2
1
0
4
2
1
0
0
10
3
5
2
0
7
0
30
27
0
3
13
0
0
0
1
0
22
0
0
1
0
0
27
0
35
1
0
1
17
0
0
0
1
10
0
0
0
2
2
15
0
52
0
4
14
0
0
36
6
0
25
0
12
0
6
1
0
1
0
0
0
3
9
2
0
60
38
16
15
11
0
0
0
2
13
0
0
6
0
7
0
0
0
25...

result:

ok 9909 lines

Test #24:

score: 0
Accepted
time: 366ms
memory: 58840kb

input:

100000 100000
gqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxicygqxi...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
6
6
6
6
7
7
7
7
7
7
7
8
8
8
8
8
8
8
8
8
8
8
9
9
9
10
10
11
11
11
11
11
11
11
11
12
12
12
12
12
12
13
13
13
13
13
13
13
14
14
14
15
15
15
15
15
1...

result:

ok 90066 lines

Test #25:

score: 0
Accepted
time: 422ms
memory: 44288kb

input:

100000 100000
nbaiostoyrvtrkngnuatnddlyjzqnfgufkqtmahrkmxxstxnqszjxibrnymsyujvzvazdmernpfoapfefjnbberzsmfmfqjwyyrqmbgdzppkratnddlyjzqnfgufkqtmahrkmxxstxnqszjxibrnymsyujvzvazdmernpfoapfefjnbberzsmfmfqjwyyrqvazynjzqnfgufkqtmahrkmxxstxnqszjxibrnymsyujvzvazdmernpfoapfefjnbberzsjzqnfgufkqtmahrkmxxstxnqsz...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 50106 lines

Test #26:

score: 0
Accepted
time: 270ms
memory: 32568kb

input:

100000 100000
avrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpogavrzpo...

output:

2
2
13
28
31
64
83
95
108
119
121
127
134
141
157
158
162
164
175
181
181
195
201
201
209
210
215
218
253
259
263
263
273
274
280
303
310
317
318
325
328
342
360
368
376
392
393
420
427
431
434
440
456
457
485
501
502
533
556
593
601
601
605
606
614
617
644
654
687
700
721
723
728
728
731
731
738
74...

result:

ok 9852 lines

Test #27:

score: 0
Accepted
time: 455ms
memory: 55868kb

input:

100000 100000
nzqcglfwczqmzqcglfwczazqcglfwczzmzqcglfwczzqcglfwczpmzqcglfwczzqcglfwcxmzqcglfwcznzqcglfwczqcglfwcmzqcglfwczmzqcglfwcjmzqcglfwczzqcglfwczrzqcglfwczqcglfwczqcglfwczmzqcglfwczwzqcglfwczqcglfwcjzqcglfwcmzqcglfwcmzqcglfwczzqcglfwcizqcglfwcomzqcglfwcmzqcglfwczzqcglfwcjmzqcglfwczmzqcglfwczmz...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
2
0
1
0
0
3
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
3
0
0
0
0
0
0
0
1
2
0
0
0
0
1
0
1
0
1
0
0
...

result:

ok 90005 lines

Test #28:

score: 0
Accepted
time: 939ms
memory: 52812kb

input:

100000 100000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

5379
21600
8676
17796
6561
7062
8794
24490
12428
13642
26349
12930
17230
4054
29012
19503
23951
2084
14612
6542
11110
18521
5532
30725
21338
30107
893
12051
20828
7845
32580
8063
4190
21112
8005
33480
15470
3466
1311
10240
13981
29868
3358
35905
19687
9180
46665
11173
4030
5610
14002
22315
28887
629...

result:

ok 49879 lines

Extra Test:

score: -3
Extra Test Failed : Time Limit Exceeded on 2

input:

100000 100000
acbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:


result: