#include #include #include #include struct SockInfo { int left = 0, right = 0, any = 0; }; int main() { int n; std::cin >> n; std::string name, type; int count; std::unordered_map infos; while (std::cin >> name >> type >> count) { auto& sockInfo = infos[name]; if (type[0] == 'l') sockInfo.left += count; if (type[0] == 'a') sockInfo.any += count; if (type[0] == 'r') sockInfo.right += count; } int ans = 1; bool possible = false; for (const auto& [_, sockInfo] : infos) { ans += std::max(1, std::max(sockInfo.left, sockInfo.right)); if ((std::min(1, sockInfo.left) + std::min(1, sockInfo.right) + sockInfo.any) >= 2) possible = true; } if (possible) std::cout << ans << std::endl; else std::cout << "impossible" << std::endl; }