#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;
    long long sum = 0;

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

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

    vector <pair <int, int>> ans;

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

        if (a[i] > a[j]) {
            int cnt = (a[i] - 1) / a[j];
            a[i] -= cnt * a[j];
            sum -= cnt * a[j];

            ans.push_back({i - 1, cnt});
        }

        i = j;
    }

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