CF 845D
int main(){
int n,t,nsd,csd,overtake_cnt=0;
vector<int>pre_sp;
pre_sp.push_back(INF);
cin>>n;
int ans=0;
while(n--){
cin>>t;
if(t==1||t==3){//change speed or speed limit
cin>>nsd;
}
if(t==1){
csd=nsd;
while(pre_sp.size()&&pre_sp.back()<csd){
pre_sp.pop_back();
++ans;
}
}
if(t==3){//speed limit
if(csd>nsd){
++ans;
}else{
pre_sp.push_back(nsd);
}
}
if(t==2){//overtake other car
ans+=overtake_cnt;
overtake_cnt=0;
}
if(t==4){//allow overtakes
overtake_cnt=0;
}
if(t==5){//no speed limit
pre_sp.push_back(INF);
}
if(t==6){//no overtake
overtake_cnt++;
}
}
cout<<ans<<'\n';
}
CF 835D
int main(){
string s;
cin>>s;
int n=s.size();
s=')'+s;
vector dp(n+1,vector<int>(n+1));
vector<int>ans(n+1);
for(int i=1;i<=n;++i){
dp[i][i]=1;
ans[1]++;
}
for(int len=2;len<=n;++len){
for(int l=1;l+len-1<=n;++l){
int r=l+len-1;
if(s[l]!=s[r]||l+1<=r-1&&dp[l+1][r-1]==0){
dp[l][r]=0;
}else if(s[l]==s[r]){
dp[l][r]=dp[l][l+len/2-1]+1;
}
if(dp[l][r]>0){
ans[dp[l][r]]++;
}
}
}
for(int i=n-1;i>=1;--i){
ans[i]+=ans[i+1];
}
for(int i=1;i<=n;++i){
cout<<ans[i]<<" \n"[i==n];
}
return 0;
}