#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 5228;

struct St : vector<int> {
    int pop() {
        int x = back();
        pop_back();
        return x;
    }
};

St g(const string& s) {
    string t(s.rbegin(), s.rend());
    int p = 0;
    t += 'c';
    St v;
    for (int i = 1; i < t.length(); ++i) {
        if (t[i] != t[i - 1]) {
            v.push_back(i - p);
            p = i;
        }
    }

    return v;
}

using Ans = vector<pair<int, int>>;

Ans best(const Ans& l, const Ans& r) {
    return l.size() < r.size() ? l : r;
}

bool bn, bm;

Ans eval(St l, St r) {
    Ans ans;
    int iters = max(r.size(), l.size());
    int suml = iters * 4;

    int n = l.size(), m = r.size();
    while (l.size() > 1 || r.size() > 1) {
        assert(iters--);

        if (l.empty()) {
            l.push_back(0);
        }

        if (r.empty()) {
            r.push_back(0);
        }

        St adl;
        adl.push_back(l.pop());
        St adr;
        adr.push_back(r.pop());

        while (l.size() + adr.size() + 1 < r.size() + adl.size()) {
            adr.push_back(r.pop());
            adr.push_back(r.pop());
        }

        while (r.size() + adl.size() + 1 < l.size() + adr.size()) {
            adl.push_back(l.pop());
            adl.push_back(l.pop());
        }

        ans.emplace_back(accumulate(adl.begin(), adl.end(), 0), accumulate(adr.begin(), adr.end(), 0));

        suml -= adl.size();
        suml -= adr.size();

        if (suml < 0) {
            exit(0);
        }

        if (!l.empty()) {
            l.back() += adr.pop();
        }

        l.insert(l.end() ,adr.rbegin(), adr.rend());

        if (!r.empty()) {
            r.back() += adl.pop();
        }

        r.insert(r.end(), adl.rbegin(), adl.rend());
    }

    return ans;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    string s, t;
    cin >> s >> t;
    St a = g(s), b = g(t);

    Ans ans;

    if (s[0] == t[0]) {

        {
            St adl;
            St adr;
            auto& l = a;
            auto& r = b;
            int sl = 0, sr = 0;

            if (l.size() < r.size()) {
                adr.push_back(r.pop());

                while (l.size() + adr.size() + 1 < r.size()) {
                    adr.push_back(r.pop());
                    adr.push_back(r.pop());
                }

                sr = accumulate(adr.begin(), adr.end(), 0);
                l.back() += adr.pop();
            } else {
                adl.push_back(l.pop());

                while (r.size() + adl.size() + 1 < l.size()) {
                    adl.push_back(l.pop());
                    adl.push_back(l.pop());
                }

                sl = accumulate(adl.begin(), adl.end(), 0);

                r.back() += adl.pop();
            }

            l.insert(l.end(), adr.rbegin(), adr.rend());

            r.insert(r.end(), adl.rbegin(), adl.rend());

            ans = eval(l, r);
            ans.insert(ans.begin(), { sl, sr });
        }

    } else {
        ans = eval(a, b);
    }

    cout << ans.size() << "\n";
    for (auto p: ans) {
        cout << p.first << " " << p.second << "\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200228;
int nx[MAXN];
int p_[MAXN];

int p(int x) {
    return p_[x] == x ? x : (p_[x] = p(p_[x]));
}

int a[MAXN];
int b[MAXN];
bool dead[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n, s;
    cin >> n >> s;
    s = min(s, n);
    if (s == 1) {
        s = 0;
    }

    map<int, vector<int>> m;

    set<int> avail;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
        avail.insert(i);
        m[a[i]].push_back(i);
    }

    sort(b, b + n);
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            ++s;
            avail.erase(i);

            dead[i] = true;
        }
    }

    for (int i = 0; i < n; ++i) {
        p_[i] = i;
    }

    for (int i = 0; i < n; ++i) {
        if (dead[i]) continue;

        auto  it = avail.lower_bound(lower_bound(b, b + n, a[i]) - b);
        nx[i] = *it;
        int pi = p(i), pnx = p(nx[i]);
        if (pi != pnx) {
            p_[pi] = pnx;
        }

        avail.erase(it);
    }

    if (s < n) {
        cout << "-1\n";
        return 0;
    }

    for (auto&[_, v] : m) {
        vector<int> v2;
        for (int x : v) {
            if (!dead[x]) {
                v2.push_back(x);
            }
        }

        for (int i = 1; i < v2.size(); ++i) {
            int x = v2[i - 1], y = v2[i];
            int px = p(x), py = p(y);
            if (px != py) {
                swap(nx[x], nx[y]);
                p_[px] = py;
            }
        }
    }

    vector<vector<int>> ans;

    for (int i = 0; i < n; ++i) {
        if (!dead[i]) {
            ans.emplace_back();
            int j = i;
            while (!dead[j]) {
                dead[j] = true;
                ans.back().push_back(j);
                j = nx[j];
            }
        }
    }

    cout << ans.size() << "\n";
    for (auto& v : ans) {
        cout << v.size() << "\n";
        for (int x : v) {
            cout << x + 1 << " ";
        }

        cout << "\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200228;
int nx[MAXN];
int p_[MAXN];

int p(int x) {
    return p_[x] == x ? x : (p_[x] = p(p_[x]));
}

int a[MAXN];
int b[MAXN];
bool dead[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n, s;
    cin >> n >> s;

    map<int, vector<int>> m;

    set<int> avail;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
        avail.insert(i);
        m[a[i]].push_back(i);
    }

    sort(b, b + n);
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            ++s;
            avail.erase(i);

            dead[i] = true;
        }
    }

    for (int i = 0; i < n; ++i) {
        p_[i] = i;
    }

    for (int i = 0; i < n; ++i) {
        if (dead[i]) continue;

        auto  it = avail.lower_bound(lower_bound(b, b + n, a[i]) - b);
        nx[i] = *it;
        int pi = p(i), pnx = p(nx[i]);
        if (pi != pnx) {
            p_[pi] = pnx;
        }

        avail.erase(it);
    }

    if (s < n) {
        cout << "-1\n";
        return 0;
    }

    for (auto&[_, v] : m) {
        vector<int> v2;
        for (int x : v) {
            if (!dead[x]) {
                v2.push_back(x);
            }
        }

        for (int i = 1; i < v2.size(); ++i) {
            int x = v2[i - 1], y = v2[i];
            int px = p(x), py = p(y);
            if (px != py) {
                swap(nx[x], nx[y]);
                p_[px] = py;
            }
        }
    }

    vector<vector<int>> ans;

    auto gen = [&]() {
        ans.clear();
        fill(dead, dead + n, false);

        for (int i = 0; i < n; ++i) {
            if (!dead[i] && nx[i] != i) {
                ans.emplace_back();
                int j = i;
                while (!dead[j]) {
                    dead[j] = true;
                    ans.back().push_back(j);
                    j = nx[j];
                }
            }
        }
    };

    gen();

    int cyc = min<int>(ans.size(), s - n);
    if (cyc > 2) {
        vector<int> ad;

        for (int j = 0; j < cyc; ++j) {
            ad.push_back(ans[cyc - 1 - j][0]);
            if (j) {
                swap(nx[ans[j][0]], nx[ans[j - 1][0]]);
            }
        }

        gen();

        ans.insert(ans.begin(), ad);
    }

    cout << ans.size() << "\n";
    for (auto& v : ans) {
        cout << v.size() << "\n";
        for (int x : v) {
            cout << x + 1 << " ";
        }

        cout << "\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200228;
int nx[MAXN];
int p_[MAXN];

int p(int x) {
    return p_[x] == x ? x : (p_[x] = p(p_[x]));
}

int a[MAXN];
int b[MAXN];
bool dead[MAXN];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n, s;
    cin >> n >> s;

    if (s == 1) {
        s = 0;
    }

    map<int, vector<int>> m;

    set<int> avail;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = a[i];
        avail.insert(i);
        m[a[i]].push_back(i);
    }

    sort(b, b + n);
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            ++s;
            avail.erase(i);

            dead[i] = true;
        }
    }

    for (int i = 0; i < n; ++i) {
        p_[i] = i;
    }

    for (int i = 0; i < n; ++i) {
        if (dead[i]) continue;

        auto  it = avail.lower_bound(lower_bound(b, b + n, a[i]) - b);
        nx[i] = *it;
        int pi = p(i), pnx = p(nx[i]);
        if (pi != pnx) {
            p_[pi] = pnx;
        }

        avail.erase(it);
    }

    if (s < n) {
        cout << "-1\n";
        return 0;
    }

    for (auto&[_, v] : m) {
        vector<int> v2;
        for (int x : v) {
            if (!dead[x]) {
                v2.push_back(x);
            }
        }

        for (int i = 1; i < v2.size(); ++i) {
            int x = v2[i - 1], y = v2[i];
            int px = p(x), py = p(y);
            if (px != py) {
                swap(nx[x], nx[y]);
                p_[px] = py;
            }
        }
    }

    vector<vector<int>> ans;

    auto gen = [&]() {
        ans.clear();
        fill(dead, dead + n, false);

        for (int i = 0; i < n; ++i) {
            if (!dead[i] && nx[i] != i) {
                ans.emplace_back();
                int j = i;
                while (!dead[j]) {
                    dead[j] = true;
                    ans.back().push_back(j);
                    j = nx[j];
                }
            }
        }
    };

    gen();

    int cyc = min<int>(ans.size(), s - n);
    if (cyc >= 2) {
        vector<int> ad;

        for (int j = 0; j < cyc; ++j) {
            ad.push_back(ans[cyc - 1 - j][0]);
            if (j) {
                swap(nx[ans[j][0]], nx[ans[j - 1][0]]);
            }
        }

        gen();

        ans.insert(ans.begin(), ad);
    }

    cout << ans.size() << "\n";
    for (auto& v : ans) {
        cout << v.size() << "\n";
        for (int x : v) {
            cout << x + 1 << " ";
        }

        cout << "\n";
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ECycleSort solver = new ECycleSort();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECycleSort {
        int n;
        int[] a;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            n = in.readInt();
            int s = in.readInt();
            a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            int[] b = a.clone();
            Randomized.shuffle(b);
            Arrays.sort(b);
            int[] same = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) {
                    same[i] = 1;
                }
            }
            for (int x : same) {
                sum += x;
            }
            if (n - sum > s) {
                out.println(-1);
                return;
            }
            IntegerList permList = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 0) {
                    permList.add(i);
                }
            }
            int[] perm = permList.toArray();
            CompareUtils.quickSort(perm, (x, y) -> Integer.compare(a[x], a[y]), 0, perm.length);
            DSU dsu = new DSU(n);
            for (int i = 0; i < perm.length; i++) {
                int from = perm[i];
                int to = permList.get(i);
                dsu.merge(from, to);
            }
            for (int i = 1; i < perm.length; i++) {
                if (a[perm[i]] != a[perm[i - 1]]) {
                    continue;
                }
                if (dsu.find(perm[i]) == dsu.find(perm[i - 1])) {
                    continue;
                }
                dsu.merge(perm[i], perm[i - 1]);
                SequenceUtils.swap(perm, i, i - 1);
            }
            IntegerList first = new IntegerList();
            if (perm.length > 0) {
                int remain = s - (n - sum) - 1;
                first.add(perm[0]);
                for (int i = 1; remain > 0 && i < perm.length; i++) {
                    if (dsu.find(perm[i - 1]) != dsu.find(perm[i])) {
                        remain--;
                        first.add(perm[i]);
                        dsu.merge(perm[i - 1], perm[i]);
                    }
                }

                int last = first.get(0);
                for (int i = 1; i < first.size(); i++) {
                    int y = first.get(i);
                    a[y] = a[last];
                    last = y;
                }
                a[first.get(0)] = a[last];
            }

            List<IntegerList> circles = new ArrayList<>();
            if (first.size() > 1) {
                circles.add(first);
            }
            circles.addAll(solve());
            out.println(circles.size());
            for (IntegerList list : circles) {
                out.println(list.size());
                for (int i = 0; i < list.size(); i++) {
                    out.append(list.get(i) + 1).append(' ');
                }
                out.println();
            }
        }

        public List<IntegerList> solve() {
            int[] b = a.clone();
            Randomized.shuffle(b);
            Arrays.sort(b);
            int[] same = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) {
                    same[i] = 1;
                }
            }
            for (int x : same) {
                sum += x;
            }
            IntegerList permList = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 0) {
                    permList.add(i);
                }
            }
            int[] perm = permList.toArray();
            CompareUtils.quickSort(perm, (x, y) -> Integer.compare(a[x], a[y]), 0, perm.length);
            DSU dsu = new DSU(n);
            for (int i = 0; i < perm.length; i++) {
                int from = perm[i];
                int to = permList.get(i);
                dsu.merge(from, to);
            }
            for (int i = 1; i < perm.length; i++) {
                if (a[perm[i]] != a[perm[i - 1]]) {
                    continue;
                }
                if (dsu.find(perm[i]) == dsu.find(perm[i - 1])) {
                    continue;
                }
                dsu.merge(perm[i], perm[i - 1]);
                SequenceUtils.swap(perm, i, i - 1);
            }

            int[] index = new int[n];
            for (int i = 0; i < n; i++) {
                if (same[i] == 1) {
                    index[i] = i;
                }
            }
            for (int i = 0; i < perm.length; i++) {
                index[perm[i]] = permList.get(i);
            }
            PermutationUtils.PowerPermutation pp = new PermutationUtils.PowerPermutation(index);
            List<IntegerList> circles = pp.extractCircles(2);

            return circles;
        }

    }

    static class DSU {
        int[] p;
        int[] rank;

        public DSU(int n) {
            p = new int[n];
            rank = new int[n];
            reset();
        }

        public void reset() {
            for (int i = 0; i < p.length; i++) {
                p[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int a) {
            return p[a] == p[p[a]] ? p[a] : (p[a] = find(p[a]));
        }

        public void merge(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
            if (rank[a] > rank[b]) {
                p[b] = a;
            } else {
                p[a] = b;
            }
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(int[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(int[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                int tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class IntegerList implements Cloneable {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntegerList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntegerList(IntegerList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntegerList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public int get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(int x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(IntegerList list) {
            addAll(list.data, 0, list.size);
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntegerList)) {
                return false;
            }
            IntegerList other = (IntegerList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Integer.hashCode(data[i]);
            }
            return h;
        }

        public IntegerList clone() {
            IntegerList ans = new IntegerList(size);
            ans.addAll(this);
            return ans;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int mod(int x, int mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return x;
        }

    }

    static interface IntComparator {
        public int compare(int a, int b);

    }

    static class PermutationUtils {
        private static final long[] PERMUTATION_CNT = new long[21];

        static {
            PERMUTATION_CNT[0] = 1;
            for (int i = 1; i <= 20; i++) {
                PERMUTATION_CNT[i] = PERMUTATION_CNT[i - 1] * i;
            }
        }

        public static class PowerPermutation {
            int[] g;
            int[] idx;
            int[] l;
            int[] r;
            int n;

            public List<IntegerList> extractCircles(int threshold) {
                List<IntegerList> ans = new ArrayList<>(n);
                for (int i = 0; i < n; i = r[i] + 1) {
                    int size = r[i] - l[i] + 1;
                    if (size < threshold) {
                        continue;
                    }
                    IntegerList list = new IntegerList(r[i] - l[i] + 1);
                    for (int j = l[i]; j <= r[i]; j++) {
                        list.add(g[j]);
                    }
                    ans.add(list);
                }
                return ans;
            }

            public PowerPermutation(int[] p) {
                this(p, p.length);
            }

            public PowerPermutation(int[] p, int len) {
                n = len;
                boolean[] visit = new boolean[n];
                g = new int[n];
                l = new int[n];
                r = new int[n];
                idx = new int[n];
                int wpos = 0;
                for (int i = 0; i < n; i++) {
                    int val = p[i];
                    if (visit[val]) {
                        continue;
                    }
                    visit[val] = true;
                    g[wpos] = val;
                    l[wpos] = wpos;
                    idx[val] = wpos;
                    wpos++;
                    while (true) {
                        int x = p[g[wpos - 1]];
                        if (visit[x]) {
                            break;
                        }
                        visit[x] = true;
                        g[wpos] = x;
                        l[wpos] = l[wpos - 1];
                        idx[x] = wpos;
                        wpos++;
                    }
                    for (int j = l[wpos - 1]; j < wpos; j++) {
                        r[j] = wpos - 1;
                    }
                }
            }

            public int apply(int x, int p) {
                int i = idx[x];
                int dist = DigitUtils.mod((i - l[i]) + p, r[i] - l[i] + 1);
                return g[dist + l[i]];
            }

            public String toString() {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < n; i++) {
                    builder.append(apply(i, 1)).append(' ');
                }
                return builder.toString();
            }

        }

    }

    static class CompareUtils {
        private static final int THRESHOLD = 4;

        private CompareUtils() {
        }

        public static <T> void insertSort(int[] data, IntComparator cmp, int l, int r) {
            for (int i = l + 1; i <= r; i++) {
                int j = i;
                int val = data[i];
                while (j > l && cmp.compare(data[j - 1], val) > 0) {
                    data[j] = data[j - 1];
                    j--;
                }
                data[j] = val;
            }
        }

        public static void quickSort(int[] data, IntComparator cmp, int f, int t) {
            if (t - f <= THRESHOLD) {
                insertSort(data, cmp, f, t - 1);
                return;
            }
            SequenceUtils.swap(data, f, Randomized.nextInt(f, t - 1));
            int l = f;
            int r = t;
            int m = l + 1;
            while (m < r) {
                int c = cmp.compare(data[m], data[l]);
                if (c == 0) {
                    m++;
                } else if (c < 0) {
                    SequenceUtils.swap(data, l, m);
                    l++;
                    m++;
                } else {
                    SequenceUtils.swap(data, m, --r);
                }
            }
            quickSort(data, cmp, f, l);
            quickSort(data, cmp, m, t);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ECycleSort solver = new ECycleSort();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECycleSort {
        boolean[] visited;
        int[] index;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int s = in.readInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            int[] b = a.clone();
            Randomized.shuffle(b);
            Arrays.sort(b);
            byte[] same = new byte[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) {
                    same[i] = 1;
                }
            }
            for (byte x : same) {
                sum += x;
            }
            if (n - sum > s) {
                out.println(-1);
                return;
            }
            IntegerList permList = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 0) {
                    permList.add(i);
                }
            }
            int[] perm = permList.toArray();
            CompareUtils.quickSort(perm, (x, y) -> Integer.compare(a[x], a[y]), 0, perm.length);
            DSU dsu = new DSU(n);
            for (int i = 0; i < perm.length; i++) {
                int from = perm[i];
                int to = permList.get(i);
                dsu.merge(from, to);
            }
            for (int i = 1; i < perm.length; i++) {
                if (a[perm[i]] != a[perm[i - 1]]) {
                    continue;
                }
                if (dsu.find(perm[i]) == dsu.find(perm[i - 1])) {
                    continue;
                }
                dsu.merge(perm[i], perm[i - 1]);
                SequenceUtils.swap(perm, i, i - 1);
            }
            index = new int[n];
            for (int i = 0; i < n; i++) {
                if (same[i] == 1) {
                    index[i] = i;
                }
            }
            for (int i = 0; i < perm.length; i++) {
                index[perm[i]] = i;
            }

            visited = new boolean[n];
            List<IntegerList> circles = new ArrayList<>(n / 2);
            IntegerList reuse = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 1 || visited[i]) {
                    continue;
                }
                reuse.clear();
                circles.add(detect(i, reuse));
            }
            out.println(circles.size());
            for (IntegerList list : circles) {
                out.println(list.size());
                for (int i = 0; i < list.size(); i++) {
                    out.append(list.get(i) + 1).append(' ');
                }
            }
        }

        public IntegerList detect(int i, IntegerList list) {
            if (visited[i]) {
                return list.clone();
            }
            visited[i] = true;
            list.add(i);
            return detect(index[i], list);
        }

    }

    static class DSU {
        int[] p;
        int[] rank;

        public DSU(int n) {
            p = new int[n];
            rank = new int[n];
            reset();
        }

        public void reset() {
            for (int i = 0; i < p.length; i++) {
                p[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int a) {
            return p[a] == p[p[a]] ? p[a] : (p[a] = find(p[a]));
        }

        public void merge(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
            if (rank[a] > rank[b]) {
                p[b] = a;
            } else {
                p[a] = b;
            }
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(int[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(int[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                int tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class IntegerList implements Cloneable {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntegerList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntegerList(IntegerList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntegerList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public int get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(int x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(IntegerList list) {
            addAll(list.data, 0, list.size);
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public void clear() {
            size = 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntegerList)) {
                return false;
            }
            IntegerList other = (IntegerList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Integer.hashCode(data[i]);
            }
            return h;
        }

        public IntegerList clone() {
            IntegerList ans = new IntegerList(size);
            ans.addAll(this);
            return ans;
        }

    }

    static interface IntComparator {
        public int compare(int a, int b);

    }

    static class CompareUtils {
        private static final int THRESHOLD = 4;

        private CompareUtils() {
        }

        public static <T> void insertSort(int[] data, IntComparator cmp, int l, int r) {
            for (int i = l + 1; i <= r; i++) {
                int j = i;
                int val = data[i];
                while (j > l && cmp.compare(data[j - 1], val) > 0) {
                    data[j] = data[j - 1];
                    j--;
                }
                data[j] = val;
            }
        }

        public static void quickSort(int[] data, IntComparator cmp, int f, int t) {
            if (t - f <= THRESHOLD) {
                insertSort(data, cmp, f, t - 1);
                return;
            }
            SequenceUtils.swap(data, f, Randomized.nextInt(f, t - 1));
            int l = f;
            int r = t;
            int m = l + 1;
            while (m < r) {
                int c = cmp.compare(data[m], data[l]);
                if (c == 0) {
                    m++;
                } else if (c < 0) {
                    SequenceUtils.swap(data, l, m);
                    l++;
                    m++;
                } else {
                    SequenceUtils.swap(data, m, --r);
                }
            }
            quickSort(data, cmp, f, l);
            quickSort(data, cmp, m, t);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Random;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Collection;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.UncheckedIOException;
import java.util.List;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ECycleSort solver = new ECycleSort();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECycleSort {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int s = in.readInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            int[] b = a.clone();
            Randomized.shuffle(b);
            Arrays.sort(b);
            int[] same = new int[n];
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) {
                    same[i] = 1;
                }
            }
            IntegerPreSum ps = new IntegerPreSum(same);
            if (n - ps.prefix(n) > s) {
                out.println(-1);
                return;
            }
            IntegerList permList = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 0) {
                    permList.add(i);
                }
            }
            int[] perm = permList.toArray();
            CompareUtils.quickSort(perm, (x, y) -> Integer.compare(a[x], a[y]), 0, perm.length);
            DSU dsu = new DSU(n);
            for (int i = 0; i < perm.length; i++) {
                int from = perm[i];
                int to = permList.get(i);
                dsu.merge(from, to);
            }
            for (int i = 1; i < perm.length; i++) {
                if (a[perm[i]] != a[perm[i - 1]]) {
                    continue;
                }
                if (dsu.find(perm[i]) == dsu.find(perm[i - 1])) {
                    continue;
                }
                dsu.merge(perm[i], perm[i - 1]);
                SequenceUtils.swap(perm, i, i - 1);
            }
            int[] index = new int[n];
            for (int i = 0; i < n; i++) {
                if (same[i] == 1) {
                    index[i] = i;
                }
            }
            for (int i = 0; i < perm.length; i++) {
                index[perm[i]] = i;
            }

            PermutationUtils.PowerPermutation pp = new PermutationUtils.PowerPermutation(index);
            List<IntegerList> circles = pp.extractCircles();
            circles = circles.stream().filter(c -> c.size() > 1).collect(Collectors.toList());
            out.println(circles.size());
            for (IntegerList list : circles) {
                out.println(list.size());
                for (int i = 0; i < list.size(); i++) {
                    out.append(list.get(i) + 1).append(' ');
                }
            }
        }

    }

    static class DSU {
        int[] p;
        int[] rank;

        public DSU(int n) {
            p = new int[n];
            rank = new int[n];
            reset();
        }

        public void reset() {
            for (int i = 0; i < p.length; i++) {
                p[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int a) {
            return p[a] == p[p[a]] ? p[a] : (p[a] = find(p[a]));
        }

        public void merge(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
            if (rank[a] > rank[b]) {
                p[b] = a;
            } else {
                p[a] = b;
            }
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(int[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(int[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                int tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class IntegerPreSum {
        private int[] pre;
        private int n;

        public IntegerPreSum(int n) {
            pre = new int[n];
        }

        public void populate(int[] a) {
            n = a.length;
            pre[0] = a[0];
            for (int i = 1; i < n; i++) {
                pre[i] = pre[i - 1] + a[i];
            }
        }

        public IntegerPreSum(int[] a) {
            this(a.length);
            populate(a);
        }

        public int prefix(int i) {
            if (i < 0) {
                return 0;
            }
            return pre[Math.min(i, n - 1)];
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class IntegerList implements Cloneable {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntegerList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntegerList(IntegerList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntegerList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public int get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(int x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(IntegerList list) {
            addAll(list.data, 0, list.size);
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntegerList)) {
                return false;
            }
            IntegerList other = (IntegerList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Integer.hashCode(data[i]);
            }
            return h;
        }

        public IntegerList clone() {
            IntegerList ans = new IntegerList();
            ans.addAll(this);
            return ans;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int mod(int x, int mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return x;
        }

    }

    static interface IntComparator {
        public int compare(int a, int b);

    }

    static class PermutationUtils {
        private static final long[] PERMUTATION_CNT = new long[21];

        static {
            PERMUTATION_CNT[0] = 1;
            for (int i = 1; i <= 20; i++) {
                PERMUTATION_CNT[i] = PERMUTATION_CNT[i - 1] * i;
            }
        }

        public static class PowerPermutation {
            int[] g;
            int[] idx;
            int[] l;
            int[] r;
            int n;

            public List<IntegerList> extractCircles() {
                List<IntegerList> ans = new ArrayList<>(n);
                for (int i = 0; i < n; i++) {
                    IntegerList list = new IntegerList(r[i] - l[i] + 1);
                    for (int j = l[i]; j <= r[i]; j++) {
                        list.add(g[j]);
                    }
                    ans.add(list);
                    i = r[i];
                }
                return ans;
            }

            public PowerPermutation(int[] p) {
                this(p, p.length);
            }

            public PowerPermutation(int[] p, int len) {
                n = len;
                boolean[] visit = new boolean[n];
                g = new int[n];
                l = new int[n];
                r = new int[n];
                idx = new int[n];
                int wpos = 0;
                for (int i = 0; i < n; i++) {
                    int val = p[i];
                    if (visit[val]) {
                        continue;
                    }
                    visit[val] = true;
                    g[wpos] = val;
                    l[wpos] = wpos;
                    idx[val] = wpos;
                    wpos++;
                    while (true) {
                        int x = p[g[wpos - 1]];
                        if (visit[x]) {
                            break;
                        }
                        visit[x] = true;
                        g[wpos] = x;
                        l[wpos] = l[wpos - 1];
                        idx[x] = wpos;
                        wpos++;
                    }
                    for (int j = l[wpos - 1]; j < wpos; j++) {
                        r[j] = wpos - 1;
                    }
                }
            }

            public int apply(int x, int p) {
                int i = idx[x];
                int dist = DigitUtils.mod((i - l[i]) + p, r[i] - l[i] + 1);
                return g[dist + l[i]];
            }

            public String toString() {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < n; i++) {
                    builder.append(apply(i, 1)).append(' ');
                }
                return builder.toString();
            }

        }

    }

    static class CompareUtils {
        private static final int THRESHOLD = 4;

        private CompareUtils() {
        }

        public static <T> void insertSort(int[] data, IntComparator cmp, int l, int r) {
            for (int i = l + 1; i <= r; i++) {
                int j = i;
                int val = data[i];
                while (j > l && cmp.compare(data[j - 1], val) > 0) {
                    data[j] = data[j - 1];
                    j--;
                }
                data[j] = val;
            }
        }

        public static void quickSort(int[] data, IntComparator cmp, int f, int t) {
            if (t - f <= THRESHOLD) {
                insertSort(data, cmp, f, t - 1);
                return;
            }
            SequenceUtils.swap(data, f, Randomized.nextInt(f, t - 1));
            int l = f;
            int r = t;
            int m = l + 1;
            while (m < r) {
                int c = cmp.compare(data[m], data[l]);
                if (c == 0) {
                    m++;
                } else if (c < 0) {
                    SequenceUtils.swap(data, l, m);
                    l++;
                    m++;
                } else {
                    SequenceUtils.swap(data, m, --r);
                }
            }
            quickSort(data, cmp, f, l);
            quickSort(data, cmp, m, t);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ECycleSort solver = new ECycleSort();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ECycleSort {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int s = in.readInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.readInt();
            }
            int[] b = a.clone();
            Randomized.shuffle(b);
            Arrays.sort(b);
            int[] same = new int[n];
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) {
                    same[i] = 1;
                }
            }
            IntegerPreSum ps = new IntegerPreSum(same);
            if (n - ps.prefix(n) > s) {
                out.println(-1);
                return;
            }
            IntegerList permList = new IntegerList(n);
            for (int i = 0; i < n; i++) {
                if (same[i] == 0) {
                    permList.add(i);
                }
            }
            int[] perm = permList.toArray();
            CompareUtils.quickSort(perm, (x, y) -> Integer.compare(a[x], a[y]), 0, perm.length);
            DSU dsu = new DSU(n);
            for (int i = 0; i < perm.length; i++) {
                int from = perm[i];
                int to = permList.get(i);
                dsu.merge(from, to);
            }
            for (int i = 1; i < perm.length; i++) {
                if (a[perm[i]] != a[perm[i - 1]]) {
                    continue;
                }
                if (dsu.find(perm[i]) == dsu.find(perm[i - 1])) {
                    continue;
                }
                dsu.merge(perm[i], perm[i - 1]);
                SequenceUtils.swap(perm, i, i - 1);
            }
            int[] index = new int[n];
            for (int i = 0; i < n; i++) {
                if (same[i] == 1) {
                    index[i] = i;
                }
            }
            for (int i = 0; i < perm.length; i++) {
                index[perm[i]] = i;
            }

            PermutationUtils.PowerPermutation pp = new PermutationUtils.PowerPermutation(index);
            List<IntegerList> circles = pp.extractCircles(2);
            out.println(circles.size());
            for (IntegerList list : circles) {
                out.println(list.size());
                for (int i = 0; i < list.size(); i++) {
                    out.append(list.get(i) + 1).append(' ');
                }
            }
        }

    }

    static class DSU {
        int[] p;
        int[] rank;

        public DSU(int n) {
            p = new int[n];
            rank = new int[n];
            reset();
        }

        public void reset() {
            for (int i = 0; i < p.length; i++) {
                p[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int a) {
            return p[a] == p[p[a]] ? p[a] : (p[a] = find(p[a]));
        }

        public void merge(int a, int b) {
            a = find(a);
            b = find(b);
            if (a == b) {
                return;
            }
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
            if (rank[a] > rank[b]) {
                p[b] = a;
            } else {
                p[a] = b;
            }
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int mod(int x, int mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return x;
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(int[] data) {
            shuffle(data, 0, data.length - 1);
        }

        public static void shuffle(int[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                int tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class SequenceUtils {
        public static void swap(int[] data, int i, int j) {
            int tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

        public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class IntegerPreSum {
        private int[] pre;
        private int n;

        public IntegerPreSum(int n) {
            pre = new int[n];
        }

        public void populate(int[] a) {
            n = a.length;
            pre[0] = a[0];
            for (int i = 1; i < n; i++) {
                pre[i] = pre[i - 1] + a[i];
            }
        }

        public IntegerPreSum(int[] a) {
            this(a.length);
            populate(a);
        }

        public int prefix(int i) {
            if (i < 0) {
                return 0;
            }
            return pre[Math.min(i, n - 1)];
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            cache.append(c);
            println();
            return this;
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class IntegerList implements Cloneable {
        private int size;
        private int cap;
        private int[] data;
        private static final int[] EMPTY = new int[0];

        public IntegerList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new int[cap];
            }
        }

        public IntegerList(IntegerList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public IntegerList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public int get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(int x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(int[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(IntegerList list) {
            addAll(list.data, 0, list.size);
        }

        public int size() {
            return size;
        }

        public int[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof IntegerList)) {
                return false;
            }
            IntegerList other = (IntegerList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Integer.hashCode(data[i]);
            }
            return h;
        }

        public IntegerList clone() {
            IntegerList ans = new IntegerList();
            ans.addAll(this);
            return ans;
        }

    }

    static interface IntComparator {
        public int compare(int a, int b);

    }

    static class PermutationUtils {
        private static final long[] PERMUTATION_CNT = new long[21];

        static {
            PERMUTATION_CNT[0] = 1;
            for (int i = 1; i <= 20; i++) {
                PERMUTATION_CNT[i] = PERMUTATION_CNT[i - 1] * i;
            }
        }

        public static class PowerPermutation {
            int[] g;
            int[] idx;
            int[] l;
            int[] r;
            int n;

            public List<IntegerList> extractCircles(int threshold) {
                List<IntegerList> ans = new ArrayList<>(n);
                for (int i = 0; i < n; i = r[i] + 1) {
                    int size = r[i] - l[i] + 1;
                    if (size < threshold) {
                        continue;
                    }
                    IntegerList list = new IntegerList(r[i] - l[i] + 1);
                    for (int j = l[i]; j <= r[i]; j++) {
                        list.add(g[j]);
                    }
                    ans.add(list);
                }
                return ans;
            }

            public PowerPermutation(int[] p) {
                this(p, p.length);
            }

            public PowerPermutation(int[] p, int len) {
                n = len;
                boolean[] visit = new boolean[n];
                g = new int[n];
                l = new int[n];
                r = new int[n];
                idx = new int[n];
                int wpos = 0;
                for (int i = 0; i < n; i++) {
                    int val = p[i];
                    if (visit[val]) {
                        continue;
                    }
                    visit[val] = true;
                    g[wpos] = val;
                    l[wpos] = wpos;
                    idx[val] = wpos;
                    wpos++;
                    while (true) {
                        int x = p[g[wpos - 1]];
                        if (visit[x]) {
                            break;
                        }
                        visit[x] = true;
                        g[wpos] = x;
                        l[wpos] = l[wpos - 1];
                        idx[x] = wpos;
                        wpos++;
                    }
                    for (int j = l[wpos - 1]; j < wpos; j++) {
                        r[j] = wpos - 1;
                    }
                }
            }

            public int apply(int x, int p) {
                int i = idx[x];
                int dist = DigitUtils.mod((i - l[i]) + p, r[i] - l[i] + 1);
                return g[dist + l[i]];
            }

            public String toString() {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < n; i++) {
                    builder.append(apply(i, 1)).append(' ');
                }
                return builder.toString();
            }

        }

    }

    static class CompareUtils {
        private static final int THRESHOLD = 4;

        private CompareUtils() {
        }

        public static <T> void insertSort(int[] data, IntComparator cmp, int l, int r) {
            for (int i = l + 1; i <= r; i++) {
                int j = i;
                int val = data[i];
                while (j > l && cmp.compare(data[j - 1], val) > 0) {
                    data[j] = data[j - 1];
                    j--;
                }
                data[j] = val;
            }
        }

        public static void quickSort(int[] data, IntComparator cmp, int f, int t) {
            if (t - f <= THRESHOLD) {
                insertSort(data, cmp, f, t - 1);
                return;
            }
            SequenceUtils.swap(data, f, Randomized.nextInt(f, t - 1));
            int l = f;
            int r = t;
            int m = l + 1;
            while (m < r) {
                int c = cmp.compare(data[m], data[l]);
                if (c == 0) {
                    m++;
                } else if (c < 0) {
                    SequenceUtils.swap(data, l, m);
                    l++;
                    m++;
                } else {
                    SequenceUtils.swap(data, m, --r);
                }
            }
            quickSort(data, cmp, f, l);
            quickSort(data, cmp, m, t);
        }

    }
}


#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;

const int P = 57, P2 = 1300031;

map< long long , bool > dict[P2];

int main() {
    int ret = 0;
    char str[2010],beg[2010],end[2010];
    scanf(" %s %s %s",str,beg,end);
    int beg_hash = 0, end_hash = 0;
    int beg_size = strlen(beg), end_size = strlen(end), str_size = strlen(str);
    if(beg_size > str_size || end_size > str_size) { printf("0\n"); return 0; }
    int beg_power=1, end_power=1;
    for(int a=0;a<beg_size;++a) {
        beg_hash = P*beg_hash + beg[a];
    }
    for(int a=0;a<beg_size-1;++a) beg_power *= P;
    for(int a=0;a<end_size;++a) {
        end_hash = P*end_hash + end[a];
    }
    for(int a=0;a<end_size-1;++a) end_power *= P;
    int bh, eh;
    int wh;
    int maxsize = max(beg_size, end_size);
    for(int i=0;i<str_size;++i) {
        if(ret == str_size*str_size) break;
        bh = eh = 0;
        wh = 0;
        for(short j=0;i+j<str_size;++j) {
            wh = P*wh + str[i+j];
            if(j < beg_size) bh = P*bh + str[i+j];
            if(j >= end_size) eh -= end_power*str[i+j-end_size];
            eh = P*eh + str[i+j];
            wh = P*wh + str[i+j];
            if(j+1 >= maxsize) {
                if(bh != beg_hash) break;
                if(eh == end_hash) {
                    int whh = ((wh%P2)+P2)%P2;
                    bool &flag = dict[whh][wh];
                    if(!flag) {
                        ++ret;
                        flag = true;
                    }
                }
            }
        }
    }
    printf("%d\n",ret);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

typedef long long lint;

const lint P = 7;

map< pair<lint,int>, bool> dict;

char str[2010],sb[2010],se[2010];

lint exp(int e) {
    if(e==0) return 1;
    if(e==1) return P;
    lint aux = exp(e/2);
    if(e%2==0) return aux*aux;
    return aux*aux*P;
}

int main() {
    scanf(" %s",str);
    scanf(" %s",sb);
    scanf(" %s",se);
    lint hb = 0, he = 0;
    int ret = 0;
    int s1 = strlen(sb), s2 = strlen(se);
    for(int a=0;a<s1;++a) {
        hb = P*hb + sb[a];
    }
    for(int a=0;a<s2;++a) {
        he = P*he + se[a];
    }
    int size = strlen(str);
    if(s1 > size || s2 > size) { printf("0\n"); return 0; }
    lint h1=0, h2=0, word=0;
    int wordsize = 0;
    for(int i=0;i<s1;++i) {
        h1 = P*h1 + str[i];
    }
    //printf("hb = %lld, h1 = %lld, he = %lld\n",hb,h1,he);
    for(int i=s1;;++i) {
        if(h1 == hb) {
            //printf("Found match beggining at %d(%c)\n",i-s1,str[i-s1]);
            wordsize = s1;
            word = h1;
            h2 = 0;
            int d = min(s1,s2);
            if(i-d+s2 > size) break;
            for(int j=i-d;j<i-d+s2;++j) {
                h2 = P*h2 + str[j];
            }
            for(int j=i-d+s2;;++j) {
                //printf("\th2 = %lld\n",h2);
                if(h2 == he) {
                    //printf("\tFound ending match at %d(%c)\n",j-1,str[j-1]);
                    if(!dict[make_pair(word,wordsize)]) {
                        //printf("\tNew match! Size = %d\n",wordsize);
                        ++ret;
                        dict[make_pair(word,wordsize)] = true;
                    }
                }
                if(j==size) break;
                h2 -= exp(s2-1)*str[j-s2];
                h2 = P*h2 + str[j];
                wordsize++;
                word = P*word + str[j];
            }
        }
        if(i == size) break;
        h1 -= exp(s1-1)*str[i-s1];
        h1 = P*h1 + str[i];
    }
    printf("%d\n",ret);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <map>
#include <iostream>
using namespace std;

typedef long long lint;

const int P = 31;

map< int, bool > dict;

int main() {
    int ret = 0;
    char str[2010],beg[2010],end[2010];
    scanf(" %s %s %s",str,beg,end);
    int beg_hash = 0, end_hash = 0;
    int beg_size = strlen(beg), end_size = strlen(end), str_size = strlen(str);
    if(beg_size > str_size || end_size > str_size) { printf("0\n"); return 0; }
    int beg_power=1, end_power=1;
    for(int a=0;a<beg_size;++a) {
        beg_hash = P*beg_hash + beg[a];
    }
    for(int a=0;a<beg_size-1;++a) beg_power *= P;
    for(int a=0;a<end_size;++a) {
        end_hash = P*end_hash + end[a];
    }
    for(int a=0;a<end_size-1;++a) end_power *= P;
    int bh, eh, wh;
    int maxsize = max(beg_size, end_size);
    for(int i=0;i<str_size;++i) {
        bh = eh = wh = 0;
        for(int j=0;i+j<str_size;++j) {
            wh = P*wh + str[i+j];
            if(j < beg_size) bh = P*bh + str[i+j];
            if(j >= end_size) eh -= end_power*str[i+j-end_size];
            eh = P*eh + str[i+j];
            wh = P*wh + str[i+j];
            if(j+1 >= maxsize) {
                if(bh != beg_hash) break;
                if(eh == end_hash) {
                    if(!dict[wh]) {
                        ++ret;
                        dict[wh] = true;
                    }
                }
            }
        }
    }
    printf("%d\n",ret);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

typedef long long lint;

const lint P = 97, M = 28794583627;

map< pair<lint,int>, bool> dict;

char str[2010],sb[2010],se[2010];

lint exp(int e) {
    if(e==0) return 1;
    if(e==1) return P;
    lint aux = exp(e/2);
    if(e%2==0) return aux*aux;
    return aux*aux*P;
}

int main() {
    scanf(" %s",str);
    scanf(" %s",sb);
    scanf(" %s",se);
    lint hb = 0, he = 0;
    int ret = 0;
    int s1 = strlen(sb), s2 = strlen(se);
    for(int a=0;a<s1;++a) {
        hb = P*hb + sb[a];
    }
    for(int a=0;a<s2;++a) {
        he = P*he + se[a];
    }
    int size = strlen(str);
    if(s1 > size || s2 > size) { printf("0\n"); return 0; }
    lint h1=0, h2=0, word=0,word2 = 0;
    int wordsize = 0;
    for(int i=0;i<s1;++i) {
        h1 = P*h1 + str[i];
    }
    //printf("hb = %lld, h1 = %lld, he = %lld\n",hb,h1,he);
    for(int i=s1;;++i) {
        if(h1 == hb) {
            //printf("Found match beggining at %d(%c)\n",i-s1,str[i-s1]);
            wordsize = s1;
            word = h1;
            word2 = h1%M;
            h2 = 0;
            int d = min(s1,s2);
            if(i-d+s2 > size) break;
            for(int j=i-d;j<i-d+s2;++j) {
                h2 = P*h2 + str[j];
            }
            for(int j=i-d+s2;;++j) {
                //printf("\th2 = %lld\n",h2);
                if(h2 == he) {
                    //printf("\tFound ending match at %d(%c)\n",j-1,str[j-1]);
                    if(!dict[make_pair(word,wordsize)]) {
                        //printf("\tNew match! Size = %d\n",wordsize);
                        ++ret;
                        dict[make_pair(word,wordsize)] = true;
                    }
                }
                if(j==size) break;
                h2 -= exp(s2-1)*str[j-s2];
                h2 = P*h2 + str[j];
                wordsize++;
                word = P*word + str[j];
                word2 = (P*word + str[j])%M;
            }
        }
        if(i == size) break;
        h1 -= exp(s1-1)*str[i-s1];
        h1 = P*h1 + str[i];
    }
    printf("%d\n",ret);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

typedef long long lint;

const lint P = 1009;

map< pair<lint,int>, bool> dict;

char str[2010],sb[2010],se[2010];

lint exp(int e) {
    if(e==0) return 1;
    if(e==1) return P;
    lint aux = exp(e/2);
    if(e%2==0) return aux*aux;
    return aux*aux*P;
}

int main() {
    scanf(" %s",str);
    scanf(" %s",sb);
    scanf(" %s",se);
    lint hb = 0, he = 0;
    int ret = 0;
    int s1 = strlen(sb), s2 = strlen(se);
    for(int a=0;a<s1;++a) {
        hb = P*hb + sb[a];
    }
    for(int a=0;a<s2;++a) {
        he = P*he + se[a];
    }
    int size = strlen(str);
    if(s1 > size || s2 > size) { printf("0\n"); return 0; }
    lint h1=0, h2=0, word=0;
    int wordsize = 0;
    for(int i=0;i<s1;++i) {
        h1 = P*h1 + str[i];
    }
    //printf("hb = %lld, h1 = %lld, he = %lld\n",hb,h1,he);
    for(int i=s1;;++i) {
        if(h1 == hb) {
            //printf("Found match beggining at %d(%c)\n",i-s1,str[i-s1]);
            wordsize = s1;
            word = h1;
            h2 = 0;
            int d = min(s1,s2);
            if(i-d+s2 > size) break;
            for(int j=i-d;j<i-d+s2;++j) {
                h2 = P*h2 + str[j];
            }
            for(int j=i-d+s2;;++j) {
                //printf("\th2 = %lld\n",h2);
                if(h2 == he) {
                    //printf("\tFound ending match at %d(%c)\n",j-1,str[j-1]);
                    if(!dict[make_pair(word,wordsize)]) {
                        //printf("\tNew match! Size = %d\n",wordsize);
                        ++ret;
                        dict[make_pair(word,wordsize)] = true;
                    }
                }
                if(j==size) break;
                h2 -= exp(s2-1)*str[j-s2];
                h2 = P*h2 + str[j];
                wordsize++;
                word = P*word + str[j];
            }
        }
        if(i == size) break;
        h1 -= exp(s1-1)*str[i-s1];
        h1 = P*h1 + str[i];
    }
    printf("%d\n",ret);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

const long long p=57;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    set<long long> res;
    string s, sb,se;
    cin>>s>>sb>>se;
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length();j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res.insert((pref_hash[i+j-1]-i!=0?pref_hash[i-1]:0)*p_step[s.length()-i-1]);
        }
    }
    cout<<res.size()<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

const long long p=51;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    vector< set<long long> > res;
    string s, sb,se;
    cin>>s>>sb>>se;
    if(s.length()<sb.length() || s.length()<se.length())
    {
        cout<<0<<endl;
        return 0;
    }
    res.resize(s.length());
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length();j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            buf = pref_hash[i+j-1];
            buf1 = i!=0?pref_hash[i-1]:0;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res[j-1].insert((buf-buf1)*p_step[s.length()-i-1]);
        }
    }
    long long res_count=0;
    for(int i=0;i<s.length();i++)
        res_count+=res[i].size();
    cout<<res_count<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

const long long p=31;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    string s, sb,se;
    cin>>s>>sb>>se;
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    long long res=0;
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length() && j<=(sb.length()+se.length());j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res++;
        }
    }
    cout<<res<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

const long long p=31;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    set<long long> res;
    string s, sb,se;
    cin>>s>>sb>>se;
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length();j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res.insert((pref_hash[i+j-1]-i!=0?pref_hash[i-1]:0)*p_step[s.length()-i-1]);
        }
    }
    cout<<res.size()<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

const long long p=51;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    vector< set<long long> > res;
    string s, sb,se;
    cin>>s>>sb>>se;
    res.resize(s.length());
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length();j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            buf = pref_hash[i+j-1];
            buf1 = i!=0?pref_hash[i-1]:0;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res[j-1].insert((buf-buf1)*p_step[s.length()-i-1]);
        }
    }
    long long res_count=0;
    for(int i=0;i<s.length();i++)
        res_count+=res[i].size();
    cout<<res_count<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

const long long p=31;

vector<long long> pref_hash;
vector<long long> p_step;

int main()
{
    //freopen("input.txt", "r",stdin);
    set<long long> res;
    string s, sb,se;
    cin>>s>>sb>>se;
    pref_hash.resize(s.length());
    p_step.resize(s.length());
    long long step=1;
    pref_hash[0]=(s[0]-'a'+1);
    p_step[0]=1;
    for(int i=1;i<s.length();i++)
    {
        step*=p;
        p_step[i]=step;
        pref_hash[i] = step*(s[i]-'a'+1)+pref_hash[i-1];
    }
    long long hb=0;
    for(int i=0;i<sb.length();i++)
    {
        hb+=(sb[i]-'a'+1)*p_step[i];
    }
    long long he=0;
    for(int j=0;j<se.length();j++)
    {
        he+=(se[j]-'a'+1)*p_step[j];
    }
    for(int i=0;i<s.length();i++)
    {
        for(int j=(max(sb.length(),se.length()));i+j-1<s.length();j++)
        {
            long long buf=pref_hash[i+sb.length()-1], buf1 = i!=0?pref_hash[i-1]:0;
            long long curr_hb = buf-buf1;
            buf = pref_hash[i+j-1]; buf1 = (i+j-se.length())?pref_hash[i+j-se.length()-1]:0;
            long long curr_he = buf-buf1;
            if(curr_hb == hb*p_step[i] && curr_he==he*p_step[i+j-se.length()])
                res.insert(pref_hash[i+j-1]-i!=0?pref_hash[i-1]:0);
        }
    }
    cout<<res.size()<<endl;
    return 0;
}


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>

#include <iostream>
#include <utility>
#include <algorithm>

#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define forn(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

char a[2100], b[2100], c[2100];
int indc[2100], indb[2100], la, lb, lc;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    #endif

    scanf("%s\n%s\n%s\n", a+1, b+1, c+1);
    la = strlen(a+1);
    lb = strlen(b+1);
    lc = strlen(c+1);
    indb[1]=0;
    int k=0, q;
    for (q=2; q<=lb; q++)
    {
        while (k>0 && b[k+1]!=b[q]) k=indb[k];
        if (b[k+1]==b[q]) k++;
        indb[q]=k;
    }
    q=k=0;
    indc[1]=0;
    for (q=2; q<=lc; q++)
    {
        while (k>0 && c[k+1]!=c[q]) k=indc[k];
        if (c[k+1]==c[q]) k++;
        indc[q]=k;
    }
    vector<int> matchb, matchc;
    q=0;
    forn(i, 1, la)
    {
        while (q>0 && b[q+1]!=a[i]) q=indb[q];
        if (b[q+1]==a[i]) q++;
        if (q==lb)
        {
            matchb.pb(i-lb+1);
            q=indb[q];
        }
    }
    q=0;
    forn(i, 1, la)
    {
        while (q>0 && c[q+1]!=a[i]) q=indc[q];
        if (c[q+1]==a[i]) q++;
        if (q==lc)
        {
            matchc.pb(i);
            q=indc[q];
        }
    }
    /*rep(i, sz(matchb)) cout << matchb[i] << ' ';
    cout << '\n';
    rep(i, sz(matchc)) cout << matchc[i] << ' ';
    cout << '\n';*/

    set<string> st;
    int ans=0; string tmp;
    rep(i, sz(matchb))
    {
        rep(j, sz(matchc))
            if (matchc[j] >= matchb[i])
            {
                tmp = "";
                for (int k=matchb[i]; k<=matchc[j]; k++) tmp += a[k];
                st.insert(tmp);
            }
    }
    cout << sz(st) << '\n';
    return 0;
}


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>

#include <iostream>
#include <utility>
#include <algorithm>

#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>

#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define forn(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

char a[2100], b[2100], c[2100];
int indc[2100], indb[2100], la, lb, lc;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    #endif

    scanf("%s\n%s\n%s\n", a+1, b+1, c+1);
    la = strlen(a+1);
    lb = strlen(b+1);
    lc = strlen(c+1);
    indb[1]=0;
    int k=0, q;
    for (q=2; q<=lb; q++)
    {
        while (k>0 && b[k+1]!=b[q]) k=indb[k];
        if (b[k+1]==b[q]) k++;
        indb[q]=k;
    }
    q=k=0;
    indc[1]=0;
    for (q=2; q<=lb; q++)
    {
        while (k>0 && c[k+1]!=c[q]) k=indc[k];
        if (c[k+1]==c[q]) k++;
        indb[q]=k;
    }
    vector<int> matchb, matchc;
    q=0;
    forn(i, 1, la)
    {
        while (q>0 && b[q+1]!=a[i]) q=indb[q];
        if (b[q+1]==a[i]) q++;
        if (q==lb)
        {
            matchb.pb(i-lb+1);
            q=indb[q];
        }
    }
    q=0;
    forn(i, 1, la)
    {
        while (q>0 && c[q+1]!=a[i]) q=indc[q];
        if (c[q+1]==a[i]) q++;
        if (q==lc)
        {
            matchc.pb(i);
            q=indc[q];
        }
    }
    /*rep(i, sz(matchb)) cout << matchb[i] << ' ';
    cout << '\n';
    rep(i, sz(matchc)) cout << matchc[i] << ' ';
    cout << '\n';*/

    set<string> st;
    int ans=0; string tmp;
    rep(i, sz(matchb))
    {
        rep(j, sz(matchc))
            if (matchc[j] >= matchb[i])
            {
                tmp = "";
                for (int k=matchb[i]; k<=matchc[j]; k++) tmp += a[k];
                st.insert(tmp);
            }
    }
    cout << sz(st) << '\n';
    return 0;
}