#include <algorithm>
#include <queue>
#include "legos.h"
using namespace std;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

const int MAXN = 2e5 + 10;
long long a[MAXN], n;

pair <bool, vector <pair <int, int>>> solve(vector <int> v) {
    n = v.size();

    int total = 0;

    for (int i = 1; i <= n; i++) {
        a[i] = v[i - 1];
        total = gcd(total, a[i]);
    }

    if (total != 1) return {0, {}};

    queue <int> q;

    for (int i = 1; i <= n; i++) {
        q.push(i);
    }

    vector <pair <int, int>> ans;

    while (q.size()) {
        int i = q.front();
        q.pop();

        int j = i + 1;
        if (j > n) j = 1;

        int cnt = (a[i] - 1) / a[j];
        if (!cnt) continue;

        ans.push_back({i - 1, cnt});
        a[i] -= cnt * a[j];

        j = i - 1;
        if (j < 1) j = n;

        q.push(j);
    }

    reverse(ans.begin(), ans.end());
    return {1, ans};
}