Diana and Liana

传送门

题目:

At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly kk flowers.

The work material for the wreaths for all nn citizens of Shortriver is cut from the longest flowered liana that grew in the town that year. Liana is a sequence a1a1, a2a2, ..., amam, where aiai is an integer that denotes the type of flower at the position ii. This year the liana is very long (m≥n⋅km≥n⋅k), and that means every citizen will get a wreath.

Very soon the liana will be inserted into a special cutting machine in order to make work material for wreaths. The machine works in a simple manner: it cuts kk flowers from the beginning of the liana, then another kk flowers and so on. Each such piece of kk flowers is called a workpiece. The machine works until there are less than kk flowers on the liana.

Diana has found a weaving schematic for the most beautiful wreath imaginable. In order to weave it, kk flowers must contain flowers of types b1b1, b2b2, ..., bsbs, while other can be of any type. If a type appears in this sequence several times, there should be at least that many flowers of that type as the number of occurrences of this flower in the sequence. The order of the flowers in a workpiece does not matter.

Diana has a chance to remove some flowers from the liana before it is inserted into the cutting machine. She can remove flowers from any part of the liana without breaking liana into pieces. If Diana removes too many flowers, it may happen so that some of the citizens do not get a wreath. Could some flowers be removed from the liana so that at least one workpiece would conform to the schematic and machine would still be able to create at least nn workpieces?

Input

The first line contains four integers mm, kk, nn and ss (1≤n,k,m≤5⋅1051≤n,k,m≤5⋅105, k⋅n≤mk⋅n≤m, 1≤s≤k1≤s≤k): the number of flowers on the liana, the number of flowers in one wreath, the amount of citizens and the length of Diana's flower sequence respectively.

The second line contains mm integers a1a1, a2a2, ..., amam (1≤ai≤5⋅1051≤ai≤5⋅105)  — types of flowers on the liana.

The third line contains ss integers b1b1, b2b2, ..., bsbs (1≤bi≤5⋅1051≤bi≤5⋅105)  — the sequence in Diana's schematic.

Output

If it's impossible to remove some of the flowers so that there would be at least nn workpieces and at least one of them fullfills Diana's schematic requirements, output −1−1.

Otherwise in the first line output one integer dd  — the number of flowers to be removed by Diana.

In the next line output dd different integers  — the positions of the flowers to be removed.

If there are multiple answers, print any.

Examples

input

Copy

7 3 2 2
1 2 3 3 2 1 2
2 2

output

Copy

1
4 

input

Copy

13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

output

Copy

-1

input

Copy

13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

output

Copy

9
1 2 3 4 5 9 11 12 13

Note

In the first example, if you don't remove any flowers, the machine would put out two workpieces with flower types [1,2,3][1,2,3] and [3,2,1][3,2,1]. Those workpieces don't fit Diana's schematic. But if you remove flower on 44-th place, the machine would output workpieces [1,2,3][1,2,3] and [2,1,2][2,1,2]. The second workpiece fits Diana's schematic.

In the second example there is no way to remove flowers so that every citizen gets a wreath and Diana gets a workpiece that fits here schematic.

In the third example Diana is the only citizen of the town and that means she can, for example, just remove all flowers except the ones she needs.

题意:给你两个字符串,要求将第一个字符串删除任意多的字符后,每k个构成一个花环,要求至少有一个花环包含第二个字符串的数量,不要求顺序,只要求数量

思路:求出第二个字符串中没一个字符串的数量和字符的种类数,然后定义两个指针,从l到r统计每个数出现的次数,如果相应字符数个数比第二个字符串打,子符种类数--,如果种类数为0就判断能不能构成n个花环,能就调出输出,不能就移动左限,删除左限的影响再继续进行操作;

AC代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
using namespace std;
const int maxn=5e5+5;
int x[maxn];
int num[maxn],judge[maxn];
int main( )
{
    int m,k,n,s,num1=0;
    bool judge1=true;
    memset(num,0,sizeof(num));
    scanf("%d %d %d %d",&m,&k,&n,&s);
    for(int a=1;a<=m;a++)
        scanf("%d",&x[a]);
    for(int b=1;b<=s;b++){
        int i;
        scanf("%d",&i);
        if(num[i]==0)
            num1++;
        num[i]++;
        judge[i]=num[i];
    }
    int r=1,l;
    for(l=1;l<=m;l++){
        if(num1==0&&(r-l+1)>=s){
            num[x[l-1]]++;
            if(num[x[l-1]]>0)
                num1++;
        }
        while(r<=m&&num1>0){
            if(num[x[r]]==1)
                num1--;
            num[x[r]]--;//printf("%d %d %d\n",r,num1,num[x[r]]);
            r++;

        }
        if(num1!=0)
            break;
        if((l-1)/k+1+(m-r+1)/k>=n){
            judge1=false;
            break;
        }
    }
    if(judge1){
        printf("-1\n");
        return 0;
    }
    //printf("%d %d\n",l,r);
    r--;
    int ans=max(r-l+1-k,0);
    printf("%d\n",ans);
    for(int a=l;a<=r;a++){
        if(ans==0)
            break;
        if(judge[x[a]]>0)
            judge[x[a]]--;
        else{
            if(ans!=1)
                printf("%d ",a);
            else
                printf("%d\n",a);
                ans--;
        }
    }
}

 

你可能感兴趣的:(ACM)