#include #define rep(i,n)for(int i=0;iP; const int MOD=1000000007; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; string s[100]; int c[100]; ll dp[320000]; int nx[100][3200000]; int main(){ int n,K;cin>>n>>K; rep(i,n){ cin>>s[i]>>c[i]; } rep(i,n){ rep(j,3*K){ if(j){ int l=j/K,r=(j+100)/K; if(l==r){ nx[i][j]=nx[i][j-1]+1; continue; } } int cur=j; rep(k,s[i].size()){ char want=(cur