The Little Elephant loves numbers. 

He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations. 

Help the Little Elephant to find the described number.

Input

A single line contains a single integer x (1 ≤ x ≤ 109).

Output

In a single line print an integer — the answer to the problem.

Examples

Input

1


Output

1


Input

10


Output

2
import java.util.*;
import java.io.*;
public class B {
	List<Integer> prime;
	Map<Integer, Integer> map;
	public boolean check(int x, int y){
		String sb = Integer.toString(x);
		String key = Integer.toString(y);
		int[] num = new int[10];
		for(int i = 0; i < sb.length(); i++){
			int a = (int)(sb.charAt(i)-'0');
			num[a]++;
		}
		for(int i = 0; i < key.length(); i++){
			int a = (int)(key.charAt(i)-'0');
			if( num[a] > 0 ){
				return true;
			}
		}
		return false;
	}
	public void solve() throws IOException {
		prime = new ArrayList<Integer>();
		prime.add(2);
		for(int i = 3; i < Math.sqrt(1000000000); i += 2){
			for(int j = 0; j < prime.size(); j++){
				if( prime.get(j) > Math.sqrt(i) ){
					prime.add(i);
					break;
				}
				if( i % prime.get(j) == 0 ){
					break;
				}
			}
		}
		int n = nextInt();
		int x = n;
		map = new HashMap<Integer, Integer>();
		int num = 1;
		for(Integer a : prime){
			if( x%a != 0 ){
				continue;
			}
			int count = 0;
			while( x%a == 0 ){
				x /= a;
				count++;
			}
			map.put(a, count);
			num *= (count+1);
		}
		if( x != 1 ){
			map.put(x, 1);
			num *= 2;
		}
		int ans = 0;
		while( num-- > 0 ){
			int key = 1;
			int temp = num;
			for(Integer a : map.keySet()){
				int index = temp%(map.get(a)+1);
	//			writer.println("a = " + a + ", index = " + index);
				temp /= map.get(a)+1;
				key *= (int)Math.pow(a, index);
			}
	//		writer.println(key);
			if( check(n, key) ){
	//			writer.println(key);
				ans++;
			}
		}
		writer.println(ans);
	}

	public static void main(String[] args) throws IOException {
		new B().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() throws IOException {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

}
