Problem: There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.

Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.

The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties. 

Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).

Input

A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.

Output

In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

7


Output

0


Input

8


Output

1440

Solution (in JAVA):

Solution:

import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Class<?> here = new Object(){}.getClass().getEnclosingClass();
		try {
			String packageName = here.getPackage().getName();
			packageName = "src/" + packageName.replaceAll("\\.", "/") + "/";
			System.setIn(new FileInputStream(packageName + "input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream(packageName + "output.txt")));
		} catch (FileNotFoundException e) {
		} catch (NullPointerException e) {
		}

		Object o = Class.forName(here.getName()).newInstance();
		o.getClass().getMethod("run").invoke(o);
	}

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}


	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	long[][] dp;
	void solve() {
		long m = sc.nextLong();
		 dp = new long[12][12];

		dp[0][0] = 1;
		dp[1][0] = 7;
		dp[1][1] = 2;
		for (int i = 1; i < 11; i++) {
			for (int d = 0; d < 10; d++) {
				dp[i+1][d+1] += 2 * dp[i][d];
				dp[i+1][d] += 8 * dp[i][d];
			}
		}
		for (int i = 0; i < 11; i++) {
			for (int d = 0; d < 10; d++)
				dp[i + 1][d] += dp[i][d];
		}

		long[] ways = getWays(m);
		ways[0]--;

		int[] count = new int[11];

		ans = 0;
		dfs(6, 0, count, ways);
		System.out.println(ans);
	}

	final long MOD = 1000000007;
	long ans = 0;

	void dfs(int d, int sum, int[] count, long[] ways) {
		if (sum > 10) return;
		if (d == 0) {
			long cur = 0;
			for (int i = sum + 1; i < 11; i++) cur += ways[i];

			for (int i = 0; i < count.length; i++) {
				for (int j = 0; j < count[i]; j++) {
					cur *= ways[i] - j;
					cur %= MOD;
				}
			}


			ans += cur;
			ans %= MOD;
			return;
		}

		for (int i = 0; i < 11; i++) {
			count[i]++;
			dfs(d - 1, sum + i, count, ways);
			count[i]--;
		}
	}

	long[] getWays(long  m) {

		if (m < 10) return naive(m);

		long[] ways = new long[12];

		long ten = 1;
		for (int i = 1; i <= 10; i++, ten *= 10)  if (ten <= m && ten * 10 > m) {

			int k = (int)((m / ten) % 10);
			for (int j = 0; j < k; j++) {
				for (int d = 0; d < 10; d++) {
					if (j == 4 || j == 7)
						ways[d+1] += dp[i-1][d];
					else
						ways[d] += dp[i-1][d];
				}
			}

			long[] doc = getWays(m % ten);
			for (int d = 0; d < 10; d++)
				if (k == 4 || k == 7)
					ways[d+1] += doc[d];
				else
					ways[d] += doc[d];
		}
		return ways;
	}

	long[] naive(long m) {
		long ways[] = new long[12];
		for (int i = 0; i <= m; i++) {
			int k = i;
			int l = 0;
			while (k > 0) {
				if (k % 10 == 7 || k % 10 == 4) l++;
				k /= 10;
			}
			ways[l]++;
		}
		return ways;
	}

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}

		public String next() {
			eat();
			return tokenizer.nextToken();
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}