Untitled

mail@pastecode.io avatar
unknown
c_cpp
19 days ago
948 B
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n; scanf("%d", &n);
    int op = 0;

    if(n % 2 == 0){
        op = n / 2;
        cout << op << "\n";
        for(int i = 0; i < 3 * n; i += 6){
            // swapping (1, 6, ...) => B of 1st BAN(1), N of 2nd BAN(6) ... ... 
            cout << i + 1 << " " << i + 5 + 1 << "\n"; // 0 based indexing + 1
        }
    }
    else if(n % 2){
        int cnt = 0;
        op = (n / 2) + 1;
        cout << op << "\n";
        for(int i = 0; i < 3 * n; i += 6){
            if(cnt == op - 1){
                // very last 'BAN' related part
                cout << i + 1 << " " << i + 2 + 1 << "\n"; // swapping (25, 27) the lat BAN in the string
            }
            else cout << i + 1 << " " << i + 6 << "\n"; // same as even part
            cnt++; // cnt to detect the very last BAN 
        }
    }
}

int main(){
    int tc; scanf("%d", &tc);
    while(tc--) solve();
}
Leave a Comment