#include <bits/stdc++.h>
using namespace std;
const int nx=51;
int n, k, a[nx], mx, h[nx], sm;
vector<pair<int, int>> res;
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>a[i], mx=max(mx, a[i]), sm+=a[i];
    if (sm%2) return cout<<-1, 0;
    for (int i=1; i<=n; i++) while (a[i]<mx) res.push_back({1, i}), a[i]+=2;
    for (int i=1; i<=n; i++) h[i]=a[i]>mx;
    for (int i=1; i<n; i++) if (!h[i]&&!h[i+1]) h[i]++, h[i+1]++, res.push_back({2, i});
    for (int i=2; i<=n; i+=2)
    {
        if (!h[i])
        {
            if (h[1]<=1) res.push_back({1, 1}), h[1]+=2;
            for (int j=2; j<i; j+=2) res.push_back({2, j});
            for (int j=i+1; j<=n; j+=2) res.push_back({2, j});
            res.push_back({1, i});
            h[1]--;
            h[i]=1;
        }
    }
    if (h[1]>1)
    {
        if (h[n]<=1) res.push_back({1, n}), h[n]+=2;
        for (int j=2; j<n; j+=2) res.push_back({2, j});
        h[1]=1, h[n--];
    }
    for (int i=1; i<=n; i+=2)
    {
        if (!h[i])
        {
            if (h[n]<=1) res.push_back({1, n}), h[n]+=2;
            for (int j=1; j<i; j+=2) res.push_back({2, j});
            for (int j=i+1; j<n; j+=2) res.push_back({2, j});
            res.push_back({1, i});
            h[n]--;
            h[i]=1;
        }
    }
    cout<<res.size()<<'\n';
    for (auto [x, y]:res) cout<<x<<' '<<y<<'\n';
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |