#include using namespace std; #define int long long templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n >> k; tmp['J'] = 0; tmp['O'] = 1; tmp['I'] = 2; bool flag[300]; for(int i = 0;i < n;i++){ cin >> s[i] >> c[i]; for(int j = 0;j < s[i].size();j++){ rui[i][j+1][tmp[s[i][j]]]++; rui[i][j+1][0] += rui[i][j][0]; rui[i][j+1][1] += rui[i][j][1]; rui[i][j+1][2] += rui[i][j][2]; flag[s[i][j]] = true; } } if(!(flag['J'] && flag['O'] && flag['I'])){ cout << -1 << endl; return 0; } memset(memo, -1, sizeof(memo)); cout << dp(0, 0) << endl; return 0; }