Program Task_12_7;
Type TSet=Set Of 0..9;
Var i, j, cnt : Integer;
sm, se : TSet;
Procedure Change(t : Integer; Var s : TSet);
Begin
s := [ ] ;
While t<>0 Do
Begin
s := s+[t Mod 10];
t := t Div 10;
End;
End;
Function Qw(s : TSet) : Integer;
Var i, cnt : Integer;
Begin
cnt := 0;
For i := 0 To 9 Do
If i In s Then
Inc(cnt);
Qw := cnt;
End;
Begin
cnt := 0;
For i := 1000 To 4999 Do
Begin
Change(i, sm) ;
If Qw(sm)=4 Then
Begin
j:=2*i;
Change (j, se);
If (sm*se=[]) And (Qw(se)=4) Then
Inc(cnt);
End;
End;
WriteLn (cnt);
End.