This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
    idea:
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef pair<int,int> pii;
typedef pair<int,char> pic;
const int maxn=2010;
vector<pic>rez;
int n,cp,a[maxn],pos[maxn];
void rotation3(int x){
   /// printf("%d ROTATE\n",x);
    int id[3]={x%n,(x+1)%n,(x+2)%n};
    int pom=a[id[0]];
    int p0=a[id[0]];
    int p1=a[id[1]];
    int p2=a[id[2]];
    a[id[0]]=p2;
    pos[p2]=id[0];
    a[id[2]]=p1;
    pos[p1]=id[2];
    a[id[1]]=p0;
    pos[p0]=id[1];
}
int dist(int x,int y){
    if(x<y)return y-x;
    else return n-x+y;
}
void rot3(int x,int val){
    if(cp!=x){
        rez.pb({dist(cp,x),'a'});
        cp=x;
    }
    rez.pb({val,'b'});
    for(int i=1;i<=val;i++)rotation3(x);
}
int inversions(){
    int ret=0;
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
            if(a[i]>a[j])ret++;
    return ret;
}
bool isNO(){
    if(n%2==0)return false;
    if(inversions()%2==1)return true;
    return false;
}
int find_num(int x){
    return pos[x];
}
void ispis(){
    for(int i=0;i<n;i++)printf("%d %d |",a[i],pos[a[i]]);
    printf("   >>\n\n");
}
void go(){
    for(int i=2;i<=n;i++){
        ///printf("%d III\n",i);
        ///ispis();
        if(find_num(i)==(find_num(i-1)+1)%n)continue;
        ///printf("%d III\n",i);
        ///ispis();
        if(i<=n-2){
            while((pos[i-1]+1)%n!=pos[i] && (pos[i-1]+2)%n!=pos[i])
                rot3((pos[i]-2+n)%n,1);
            if((pos[i-1]+1)%n==pos[i])continue;
            else rot3((pos[i]-1+n)%n,2);
        }
        else{
            if(n%2==0){
                while((pos[i-1]+1)%n!=pos[i]){
                    ///printf("%d %d AAA\n",(pos[i-1]+1)%n,pos[i]);
                    ///ispis();
                    rot3((pos[i]-2+n)%n,1);
                }
            }
            else return;
        }
        ///printf("%d III\n",i);
        ///ispis();
    }
}
int main(){
    ///freopen("test.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        pos[a[i]]=i;
    }
    if(n==1){
        printf("%d\n",0);
        return 0;
    }
    if(n==2){
        if(a[0]==1)printf("%d\n",0);
        else printf("1\n1a\n");
        return 0;
    }
    if(isNO()){
        printf("NIE DA SIE\n");
        return 0;
    }
    go();
    if(cp!=pos[1])rez.pb({dist(cp,pos[1]),'a'});
    vector<pic>rez2;
    if(rez.size()>0)rez2.pb(rez[0]);
    for(int i=1;i<rez.size();i++)
        if(rez[i].ss==rez2.back().ss)rez2[rez2.size()-1].ff+=rez[i].ff;
        else rez2.pb(rez[i]);
    printf("%d\n",rez.size());
    for(int i=0;i<rez.size();i++){
        printf("%d%c ",rez[i].ff,rez[i].ss);
    }
    return 0;
}
Compilation message (stderr)
prz.cpp: In function 'void rotation3(int)':
prz.cpp:23:9: warning: unused variable 'pom' [-Wunused-variable]
   23 |     int pom=a[id[0]];
      |         ^~~
prz.cpp: In function 'int main()':
prz.cpp:144:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |     for(int i=1;i<rez.size();i++)
      |                 ~^~~~~~~~~~~
prz.cpp:148:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wformat=]
  148 |     printf("%d\n",rez.size());
      |             ~^    ~~~~~~~~~~
      |              |            |
      |              int          std::vector<std::pair<int, char> >::size_type {aka long unsigned int}
      |             %ld
prz.cpp:149:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |     for(int i=0;i<rez.size();i++){
      |                 ~^~~~~~~~~~~
prz.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  117 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
prz.cpp:119:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  119 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~| # | 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... | 
| # | 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... |