program Project2; var t : array [1..200000, 1..2] of integer; i, j, n, k, zam : integer; f, g : text; procedure zamina(); var u, m : integer; begin u := t[1, 1]; m := t[1, 2]; t[1, 1] :=t[zam, 1]; t[1, 2] := t[zam, 2]; t[zam, 1] := u; t[zam, 2] := m; end; function perev():boolean; var ii, jj : integer; bool : boolean; begin bool := false; ii := 1; for jj := 2 to n do begin if ((t[ii, 1] < t[jj, 1]) and (t[ii, 2] <= t[jj, 2])) then bool := true; if ((t[ii, 2] < t[jj, 2]) and (t[ii, 1] <= t[jj, 1])) then bool := true; if ((t[ii, 2] < t[jj, 1]) and (t[ii, 1] <= t[jj, 2])) then bool := true; if ((t[ii, 1] < t[jj, 2]) and (t[ii, 2] <= t[jj, 1])) then bool := true; end; perev := bool; end; begin assign(f, 'task.in'); reset(f); read(f, n); i := 1; while i < n +1 do begin read (f, t[i, 1], t[i, 2]); inc(i); end; i := 2; zam := 2; k := 0; if perev = true then inc(k); while i <= n do begin zamina(); if perev = true then inc(k); inc(zam); inc(i); end; assign(g, 'task.out'); rewrite(g); writeln(g, k); close(g); { TODO -oUser -cConsole Main Insert code here } end.