Hello, I can not understand how to solve this problem, please, who can, give the code with explanations ... Thanks in advance.

Task:

The number n is entered from the keyboard - the order of substitution, and then a table of two lines. Determine whether this table is an nth order permutation.

`Пример: 5 1 2 3 4 2 4 2 1 3 5 NO 5 1 5 3 4 2 4 7 1 3 5 NO 4 3 2 1 4 4 2 1 3 YES 5 1 2 3 4 4 2 1 3 NO 5 1 5 3 4 2 4 3 5 3 5 NO 5 1 5 3 4 2 4 2 1 3 5 YES`

Here is my solution (to display an error - help):

` ``type DinArr = array of longint; function Sort(arr: DinArr): DinArr; var i, j: longint; b: word; begin for i:= 1 to length(arr)-1 do begin for j:= 1 to length(arr)-i do begin if (arr[j] > arr[j+1]) then begin b:= arr[j]; arr[j]:= arr[j+1]; arr[j+1]:= b; end; end; end; Sort:= arr; end; var a, b: DinArr; a2, b2: DinArr; i, j, n: longint; begin readln(n); setlength(a, 1); setlength(b, 1); for i:= 1 to length(a) do begin setlength(a, length(a)+1); readln(a[i]); end; for i:= 1 to length(b) do begin setlength(b, length(b)+1); readln(b[i]); end; setlength(a2, 100); setlength(b2, 100); a2:= Sort(a); b2:= Sort(b); for i:= 1 to length(a) do begin if (a2[i] <> b2[i]) then begin writeln('NO'); exit; end; end; writeln('YES'); readln; end.`