//////////////////////////////////////// ///////////////////////////////
// Inversion
// Reverse Order and its original order
# Include <iostream>
# Include <string>
Using namespace STD;
Char nor [100];
Long shuru [10000];
Long chu [10000];
Long I, J, K, jishu;
Void perm (int n)
{
Jishu = 0;
For (I = 0; I <n; I ++)
Cin> shuru [I];
For (I = 0; I <n; I ++) // output of each number
{
For (j = 0; j <n; j ++) // there are several large numbers before a number.
{
If (shuru [J]> I + 1)
Jishu ++;
Else if (shuru [J] = I + 1)
Break;
}
Cout <jishu;
If (I! = N-1)
Cout <"";
Jishu = 0;
}
}
Void inv (int n)
{
Int temp;
For (I = 0; I <n; I ++)
Cin> shuru [I];
For (j = 0; j <n; j ++)
Chu [J] = N-J;
For (I = 0; I <n; I ++) // This loop allows n numbers to be exchanged once.
{
Jishu = 0;
For (k = n-1; k> = 0; k --)
{
If (chu [k] = I + 1)
Break;
}
J = 0;
Do {// This round robin swaps the I-th number and its proper position
If (jishu = shuru [I] & chu [J]> chu [k] & J <K)
{
Temp = chu [J];
Chu [J] = chu [k];
Chu [k] = temp;
Break;
}
If (chu [J]> chu [k] & jishu <= shuru [I])
{
Jishu ++;
}
J ++;
If (chu [J]> chu [k] & jishu = shuru [I]-1 & K <j)
{
Temp = chu [J];
Chu [J] = chu [k];
Chu [k] = temp;
Break;
}
} While (j <n );
}
For (I = 0; I <n; I ++)
{
Cout <chu [I];
If (I! = N-1)
Cout <"";
}
}
Int main ()
{
Int N;
While (CIN> N)
{
If (n = 0)
Return 0;
Cin> nor;
If (strcmp (nor, "P") = 0)
Perm (N );
Else
Inv (N );
Cout <Endl;
}
Return 0;
}