Algorithm


F. Pacifist frogs
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.

One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n and the number of a hill is equal to the distance in meters between it and the island. The distance between the n-th hill and the shore is also 1 meter.

Thumbelina is too small to make such jumps. Fortunately, a family of frogs living in the swamp suggests to help her. Each frog agrees to give Thumbelina a ride but Thumbelina should choose only one frog. Each frog has a certain jump length. If Thumbelina agrees to accept help from a frog whose jump length is d, the frog will jump from the island on the hill d, then — on the hill 2d, then 3d and so on until they get to the shore (i.e. find itself beyond the hill n).

However, there is one more problem: mosquitoes also live in the swamp. At the moment they have a siesta, and they are having a nap on some hills. If the frog jumps on a hill with a mosquito the frog will smash it. The frogs Thumbelina has met are pacifists, so they will find the death of each mosquito very much sad. Help Thumbelina choose a frog that will bring her to the shore and smash as small number of mosquitoes as possible.

Input

The first line contains three integers nm and k (1 ≤ n ≤ 1091 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleeping. No more than one mosquito can sleep on each hill. The numbers in the lines are separated by single spaces.

Output

In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.

Examples
input
Copy
5 3 5
2 3 4
1 2 3 4 5
output
Copy
2
2 3
input
Copy
1000000000 2 3
2 5
999999995 999999998 999999996
output
Copy
1
2

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <vector>
#include <map>

int main(){

    long n, m, k; scanf("%ld %ld %ld", &n, &m, &k);
    std::vector<long> fv(m); for(long p = 0; p < m; p++){scanf("%ld", &fv[p]);}
    std::vector<long> mv(k); for(long p = 0; p < k; p++){scanf("%ld", &mv[p]);}

    long minSmashed(k + 1); std::vector<long> frogs;

    for(long p = 0; p < m; p++){
        long cnt(0);
        for(long q = 0; q < k; q++){cnt += (mv[q] % fv[p] == 0);}
        if(cnt < minSmashed){minSmashed = cnt; frogs.clear(); frogs.push_back(p + 1);}
        else if(cnt == minSmashed){frogs.push_back(p + 1);}
    }

    printf("%ld\n", frogs.size());
    for(long p = 0; p < frogs.size(); p++){printf("%ld ", frogs[p]);}

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 3 5
2 3 4
1 2 3 4 5

Output

x
+
cmd
2
2 3
Advertisements

Demonstration


Codeforces Solution-F. Pacifist frogs-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+