#include using namespace std; typedef long long ll; typedef long double ld; typedef pair ii; typedef vector vi; typedef vector vvi; typedef vector vii; #define x first #define y second #define pb push_back #define eb emplace_back #define rep(i,a,b) for(auto i=(a); i<(b); ++i) #define REP(i,n) rep(i,0,n) #define all(v) begin(v), end(v) #define sz(v) ((int) (v).size()) #define rs resize #define DBG(x) cerr << __LINE__ << ": " \ << #x<< " = " << (x) << endl template ostream& operator<<(ostream &os, const vector &v) { os << "\n["; for(const T &x : v) os << x << ','; return os << "]\n"; } namespace std { template struct hash> { public: size_t operator()(const pair &p) const { size_t x = hash()(p.x), y = hash()(p.y); return x ^ (y + 0x9e3779b9 + (x<<6) + (x>>2)); } }; } void run() { ll n; cin >> n; unordered_map A; ll res = 0; bool rb = false; for (ll i = 0; i < n; i++) { string t, f; ll k; cin >> t >> f >> k; if (A[t] > 0 || (f == "any" && k > 1)) { rb = true; } if (f == "any") { k = 1; } res += max(k, A[t]) - A[t]; A[t] = max(k, A[t]); } if (rb) { cout << res+1 << endl; } else { cout << "impossible" << endl; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); run(); return 0; }