#include using namespace std; using ll = long long; using vll = vector; using vvl = vector; using pll = pair; #define rep(i,N) for(ll i=0;i=0; --i) #define all(v) (v).begin(), (v).end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N,K;cin >> N >> K; vll P(N); rep(i,N){ cin >> P[i]; --P[i]; } ll j; //入れ替えるのがmodK rep(i,N){// if(P[i]%K!=i%K){ cout << "-1\n"; return 0; } } vector bubble;//どことどこを{x,y} bool swapped; rep(r,K){ swapped=true; while(swapped){ swapped=false; for(ll i=r;iP[i+K]){ swap(P[i],P[i+K]); bubble.push_back({i+1,i+K+1});//1_indexed swapped = true; } } } } cout << bubble.size() << endl; for(auto ans : bubble){ cout << ans.first << " " << ans.second << endl; } return 0; }