#pragma once
/**
* Author: Teetat T.
* Date: 2024-06-14
* Description: Z Algorithm. z[i] := the length of the longest common prefix between s and s[i:].
*/template<classSTR>vector<int>z_algorithm(constSTR&s){intn=(int)s.size();vector<int>z(n);z[0]=n;for(inti=1,l=0,r=1;i<n;i++){if(i<r)z[i]=min(r-i,z[i-l]);while(i+z[i]<n&&s[z[i]]==s[i+z[i]])z[i]++;if(i+z[i]>r)l=i,r=i+z[i];}returnz;}
#line 2 "src/string/z-algorithm.hpp"
/**
* Author: Teetat T.
* Date: 2024-06-14
* Description: Z Algorithm. z[i] := the length of the longest common prefix between s and s[i:].
*/template<classSTR>vector<int>z_algorithm(constSTR&s){intn=(int)s.size();vector<int>z(n);z[0]=n;for(inti=1,l=0,r=1;i<n;i++){if(i<r)z[i]=min(r-i,z[i-l]);while(i+z[i]<n&&s[z[i]]==s[i+z[i]])z[i]++;if(i+z[i]>r)l=i,r=i+z[i];}returnz;}