import std.stdio;
import std.string;

void amidaSort(uint[] origList){
    auto sortedList = origList.dup.sort;
    auto tmpList = origList.dup;
    auto amidaRowProto = cast(char[])repeat("| ", origList.length)[0..($ - 1)];
    string[] amida;
    while(tmpList != sortedList){
        for(uint start; start <= 1; start++){
            uint[] swap;
            for(uint i = start; i < tmpList.length - 1; i += 2){
                if(tmpList[i] > tmpList[i + 1]){
                    swap ~= i;
                    auto tmp = tmpList[i + 1];
                    tmpList[i + 1] = tmpList[i];
                    tmpList[i] = tmp;
                }
            }
            if(swap.length){
                auto amidaRow = amidaRowProto.dup;
                foreach(i; swap){
                    amidaRow[(i * 2) + 1] = '-';
                }
                amida ~= cast(string)amidaRow;
            }
        }
    }
    string[] s;
    foreach(n; sortedList){
        s ~= toString(n);
    }
    string[] o;
    foreach(n; origList){
        o ~= toString(n);
    }
    if(!amida.length){
        amida ~= cast(string)amidaRowProto.dup;
    }
    writefln((s.join(" ") ~ amida.reverse ~ o.join(" ")).join("\n"));
}

void main(){
    amidaSort([3, 5, 2, 4, 0, 1]);
}
