#include <algorithm>
#include <stack>
#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;
    int idx = -1;
    
    for (int i = 1; i <= n; i++) {
        a[i] = v[i - 1];

        if (a[i] == 1) idx = i;
    }

    if (idx == -1) return {0, {}};
    vector <pair <int, int>> ans;

    for (int i = 1; i < n; i++) {
        int curr = idx - i;
        if (curr < 1) curr += n;

        ans.push_back({curr - 1, a[curr] - 1});
        a[curr] = 1;
    }

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