Comments

For problem B this worked for me. but no exact idea why. initially i was thinking of rotating by 1, then by n-1 but that didn't work so i thought may be rotate them by increasing value might work. but no idea how this actually works for all cases. how to prove that this will work always?

void solve() {
    ll n;
    cin >> n;
    vll a(4*n);
    vll v(n);
    for(int i = 1; i <= n; ++i) v[i-1] = i;
    ll k = 0, cnt = 1;
    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < n; ++j) a[k++] = v[j];
        rotate(v.begin(), v.begin() + (cnt % n), v.end());
        cnt++;
    }
    print(a);
}