#include<bits/stdc++.h> #define ll long long #define ld long double #define N 500005 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define pii pair<int,int> #define x first #define y second usingnamespace std; int n,m;
voidZ_algo(char *S,int *Z){ int l = 0,r = 0; Z[0] = 0; for(int i=1;S[i];i++){ Z[i] = max(0,min(Z[i-l],r-i)); while(S[Z[i]]&&S[Z[i]] == S[i+Z[i]]){ l = i;r = i+Z[i]; Z[i]++; } } }