#pragma once
/**
* Author: Teetat T.
* Date: 2024-06-14
* Description: Prefix function. pi[i] := the length of the longest proper prefix of s[0:i] which is also a suffix of s[0:i].
*/template<classSTR>vector<int>prefix_function(constSTR&s){intn=(int)s.size();vector<int>pi(n);for(inti=1,j=0;i<n;i++){while(j>0&&s[i]!=s[j])j=pi[j-1];if(s[i]==s[j])j++;pi[i]=j;}returnpi;}
#line 2 "string/prefix-function.hpp"
/**
* Author: Teetat T.
* Date: 2024-06-14
* Description: Prefix function. pi[i] := the length of the longest proper prefix of s[0:i] which is also a suffix of s[0:i].
*/template<classSTR>vector<int>prefix_function(constSTR&s){intn=(int)s.size();vector<int>pi(n);for(inti=1,j=0;i<n;i++){while(j>0&&s[i]!=s[j])j=pi[j-1];if(s[i]==s[j])j++;pi[i]=j;}returnpi;}