B. Pasha and Phone
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.

Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of length k. The first block will be formed by digits from the phone number that are on positions 1, 2,..., k, the second block will be formed by digits from the phone number that are on positions k + 1, k + 2, ..., 2·k and so on. Pasha considers a phone number good, if the i-th block doesn't start from the digit bi and is divisible by ai if represented as an integer.

To represent the block of length k as an integer, let's write it out as a sequence c1, c2,...,ck. Then the integer is calculated as the result of the expression c1·10k - 1 + c2·10k - 2 + ... + ck.

Pasha asks you to calculate the number of good phone numbers of length n, for the given k, ai and bi. As this number can be too big, print it modulo 109 + 7.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(n, 9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that n is divisible by k.

The second line of the input contains n / k space-separated positive integers — sequence a1, a2, ..., an / k (1 ≤ ai < 10k).

The third line of the input contains n / k space-separated positive integers — sequence b1, b2, ..., bn / k (0 ≤ bi ≤ 9).

Output

Print a single integer — the number of good phone numbers of length n modulo 109 + 7.

Examples
Input
6 2
38 56 49
7 3 4
Output
8
Input
8 2
1 22 3 44
5 4 3 2
Output
32400
Note

In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.

当d==0的时候就是从999999--099999

其他的时候假设d=k; 那么结果就是 999999-(k+1)00000+(k-1)99999--0;

所以随便模拟一下就行了。

B. Pasha and Phone的更多相关文章

  1. Codeforces Round #326 (Div. 2) B. Pasha and Phone C. Duff and Weight Lifting

    B. Pasha and PhonePasha has recently bought a new phone jPager and started adding his friends' phone ...

  2. CF 435B Pasha Maximizes(贪心)

    题目链接: [传送门][1] Pasha Maximizes time limit per test:1 second     memory limit per test:256 megabytes ...

  3. Codeforces Round #337 (Div. 2) A. Pasha and Stick 水题

    A. Pasha and Stick   Pasha has a wooden stick of some positive integer length n. He wants to perform ...

  4. Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学

    A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...

  5. Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题

    B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...

  6. B. Pasha and String

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  8. Pasha and String(思维,技巧)

    Pasha and String Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u S ...

  9. Pasha and Phone(思维)

    Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. Codeforces 435B. Pasha Maximizes

    简单贪心.... B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input s ...

随机推荐

  1. JUCE_FIFO实现分析

    JUCE_FIFO代码简单剖析,此处的剖析就是给自己留一个方便查询的内容:不做太多内容的要求,只做简单的记录:本文以初学者的角度来些,大牛请飘过O(∩_∩)O FIFO的功能在博客的其他帖子里面已经有 ...

  2. 微信小程序之----组件

    1.view 把文档分割为独立的.不同的部分. view组件类似于html中的div标签,默认为块级元素,独占一行,可以通过设置display:inline-block改为行级元素. view.wxm ...

  3. Windows显示不了磁盘

    ps:当我的磁盘插电脑上却显示不了磁盘信息.终于最后将我的200G资料,搞没了,也不能恢复了..刚刚磁盘显示了,为了让更多人能不走弯路,我结合了网络能让磁盘显示的几个经验,也便大家方便参考...   ...

  4. Struts2标签遍历List<Map<String,String>>

    <s:if test="resultList != null && resultList.size() > 0"> <s:iterator  ...

  5. UVa 10226 - Hardwood Species

    题目大意:给出n棵树(有重复),统计每种树出现的频率.使用STL的map. #include <cstdio> #include <iostream> #include < ...

  6. UVa 10706 - Number Sequence

    题目大意:Sk表示从1到k的字符序列,如S4为1234,现如今有如下的序列S1S2...Sk,形如1 12 123 1234这样的序列,给一个数n,让你去这个序列第n个位置上的数字. 可以构建出一个S ...

  7. spark 1.6 idea本地运行错误

    将spark maven更新至1.6,运行原有程序,发现以下错误: java.lang.IllegalArgumentException: System memory must be at least ...

  8. PHP header( ) 禁止页面后退

    header("Cache-control:no-cache,no-store,must-revalidate"); header("Pragma:no-cache&qu ...

  9. max-width

    #main { max-width: 600px; margin: 0 auto; } <div id="main"> Using max-width instead ...

  10. html标签默认样式整理

    引:http://www.jb51.net/web/94964.html 文为大家整理了html标签默认样式属性及浏览器默认样式等等,喜欢css布局的朋友们可以学下,希望对大家有所帮助 html, a ...