reserve x,y,z for set;
reserve f,f1,f2,f3 for FinSequence,
  p,p1,p2,p3 for set,
  i,k for Nat;
reserve D for non empty set,
  p,p1,p2,p3 for Element of D,
  f,f1,f2 for FinSequence of D;
reserve D for non empty set;
reserve p, q for FinSequence,
  X, Y, x, y for set,
  D for non empty set,
  i, j, k, l, m, n, r for Nat;
reserve a, a1, a2 for TwoValued Alternating FinSequence;

theorem
  X <> Y & n > 1 implies ex a1 st rng a1 = {X, Y} & len a1 = n & a1.1 = X
proof
  deffunc F(Nat,Nat) = 3-'$2;
  assume that
A1: X <> Y and
A2: n > 1;
  set p = <*X, Y*>;
A3: p.1 = X;
A4: 3-'2 =1+2-2 by XREAL_0:def 2
    .=1;
A5: p.2 = Y;
  consider f1 being sequence of NAT such that
A6: f1.0=2 & for n being Nat holds f1.(n+1)=F(n,f1.n)
  from NAT_1:sch 12;
  defpred P[Nat] means (f1.$1=1 or f1.$1=2) & f1.$1<>f1.($1+1);
A7: 3-'1=2+1-1 by XREAL_0:def 2
    .=2;
A8: for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A9: f1.i = 1 or f1.i = 2 and
    f1.i <> f1.(i+1);
    thus f1.(i+1)=1 or f1.(i+1) = 2 by A6,A4,A7,A9;
    hence thesis by A6,A4,A7;
  end;
A10: P[0] by A6,A4;
A11: for i being Nat holds P[i] from NAT_1:sch 2(A10, A8);
  deffunc F(Nat) = p.(f1.$1);
  consider p1 being FinSequence such that
A12: len p1 = n & for k be Nat st k in dom p1 holds p1.k= F(k) from
  FINSEQ_1:sch 2;
A13: f1.(0+1) = 1 by A6,A4;
  then
A14: f1.(1+1) = 2 by A6,A7;
A15: now
    let y be object;
    hereby
      assume y in {X, Y};
      then
A16:  y = X or y = Y by TARSKI:def 2;
      1 in dom p1 by A2,A12,FINSEQ_3:25;
      then
A17:  p1.1=X by A3,A13,A12;
A18:  1 in dom p1 by A2,A12,FINSEQ_3:25;
      1+1<=n by A2,NAT_1:13;
      then
A19:  2 in dom p1 by A12,FINSEQ_3:25;
      then p1.2=Y by A5,A14,A12;
      hence ex x being object st x in dom p1 & y = p1.x by A16,A19,A17,A18;
    end;
    given x being object such that
A20: x in dom p1 and
A21: y = p1.x;
    x in Seg len p1 by A20,FINSEQ_1:def 3;
    then consider x9 being Nat such that
A22: x9=x and
A23: 1<=x9 and
A24: x9<=len p1;
    x9 in dom p1 by A23,A24,FINSEQ_3:25;
    then
A25: p1.x9 = p.(f1.x9) by A12;
    f1.x9 = 1 or f1.x9 = 2 by A11;
    hence y in {X, Y} by A21,A22,A25,TARSKI:def 2;
  end;
  then rng p1 = {X, Y} by FUNCT_1:def 3;
  then reconsider p1 as TwoValued FinSequence by A1,A2,A12,Th19;
  now
    let i be Nat;
    assume that
A26: 1<=i and
A27: (i+1)<=len p1;
    1<=(i+1) by A26,NAT_1:13;
    then (i+1) in dom p1 by A27,FINSEQ_3:25;
    then
A28: p1.(i+1)=p.(f1.(i+1)) by A12;
A29: f1.(i+1)=1 or f1.(i+1)=2 by A11;
    i<=n by A12,A27,NAT_1:13;
    then i in dom p1 by A12,A26,FINSEQ_3:25;
    then p1.i=p.(f1.i) by A12;
    hence p1.i <> p1.(i+1) by A1,A3,A5,A11,A28,A29;
  end;
  then reconsider p1 as TwoValued Alternating FinSequence by Def4;
  take p1;
  thus rng p1 = {X, Y} by A15,FUNCT_1:def 3;
  thus len p1 = n by A12;
  1 in dom p1 by A2,A12,FINSEQ_3:25;
  hence thesis by A3,A13,A12;
end;
