program checkh;

uses
    testlib, sysutils;

const
    maxn = 100;

var
    i, j, n, t: longint;
    a: array [1..maxn] of longint;

begin
    n := inf.readlongint;
    for i := 1 to n do
    begin
        a[i] := inf.readlongint;
        if a[i] = i then
            quit(_fail, 'input array has stable elements');
    end;

    while not ouf.seekeof do
    begin
        i := ouf.readlongint;
        j := ouf.readlongint;

        if (i < 1) or (i > n) then
            quit(_wa, 'accessing element outside array');
        if (j < 1) or (j > n) then
            quit(_wa, 'accessing element outside array');
        if i = j then
            quit(_wa, 'trying to exchange element with itself');
        if abs(i - j) <> 1 then
            quit(_wa, 'trying to exchange elements that are not neighbours');

        if (a[i] = i) or (a[j] = j) then
            quit(_wa, 'trying to move stable element');

        t := a[i]; a[i] := a[j]; a[j] := t;
    end;

    for i := 1 to n do
        if a[i] <> i then
            quit(_wa, 'array is not sorted after all exchanges');

    quit(_ok, '');
end.