#include<bits/stdc++.h> #define int unsigned long long int #define INF 0x3f3f3f3f #define N 500005 #define mod 1000000007 usingnamespace std; int power[N],hash_func[N],charc[30],n,m,C = 137; char target[N],a[N]; vector<int> vec;
voidinit(){ power[0] = 1; srand(time(NULL)); for(int i=1;i<=m;i++){ power[i] = ((power[i-1]*C)+mod)%mod; } for(int i=0;i<30;i++){ //再用rand來使字串更亂(不用也沒差) int temp = rand(); charc[i] = temp; } } signedmain(){ scanf("%s\n%s",target+1,a+1); m = strlen(target+1); n = strlen(a+1); init(); hash_func[0] = 0; for(int i=1;i<=n;i++){ hash_func[i] = ((C*hash_func[i-1]+(charc[a[i]-'a']))+mod)%mod; } int sum = 0; for(int i=1;i<=m;i++){ sum = ((sum*C+(charc[target[i]-'a']))+mod)%mod; } for(int i=0;i<=n-m;i++){ if(sum == ((hash_func[i+m]-((hash_func[i]*power[m])+mod)%mod)+mod)%mod) vec.push_back(i); } int len = vec.size(); if(len>0)printf("%llu",vec[0]); for(int i=1;i<len;i++){ printf(" %llu",vec[i]); } cout<<endl; //這一行是毒瘤 }