type TSequence = set of Byte; TFriends = array [1..255*256] of TSequence; procedure Print(const s: TSequence); var i: Byte; begin for i := 0 to 255 do if i in s then write(i:4); end; procedure Fill(const fName: String; var s: TFriends; var n: Integer); var f: Text; a, b: Byte; begin assign(f, fName); reset(f); n := 0; readln(f); while not(eof(f)) do begin inc(n); s[n] := []; read(f, a, b); readln(f); include(s[n], a); include(s[n], b); end; close(f); end; function FindMaxSequence(const s: TFriends; const n: Integer): TSequence; var i, j, count, mxCount: Integer; temp, max: TSequence; begin max := []; mxCount := 0; for i := 1 to n - 1 do begin temp := s[i]; count := 0; for j := i + 1 to n do if temp <> s[j] then if temp * s[j] <> [] then begin inc(Count); temp := temp + s[j]; end; if (count > mxCount) or (mxCount = 0) then begin mxCount := count; max := temp; end; end; FindMaxSequence := max; end; var s: TFriends; n: Integer; begin Fill('C:\forum.txt', s, n); Print(FindMaxSequence(s, n)); end.