Олимпиадный тренинг

Задача 38316. Calculator


The new OpenCalculator program has a new feature – you can customize which buttons are shown and which – No. If the button is not displayed on the screen, then you cannot enter the corresponding number from the keyboard or by copying from another program. Petya set up the calculator in such a way that it only displays buttons with numbers x, y, z. Write a program that determines whether Petya can enter the number N, and if not, what is the minimum number of buttons that must be additionally displayed on the screen to enter it.

Input
First, three different numbers from 0 to 9 are entered: x, y, and z (the numbers are separated by spaces). Next, enter a non-negative integer N, which Petya wants to enter into the calculator. The number N does not exceed 10000.

Imprint
Print the minimum number of buttons that must be added so that the number N can be entered (if the number can be entered using existing buttons, print 0)
 
Examples
# Input Output Explanation
1 1 2 3
1123
0 The number can be entered using the available buttons.
2 1 2 3
1001
1 Need to add button 0.
3 5 7 3
123
2 We need to add buttons 1 and 2.