#include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; if (!(cin >> N)) return 0; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } // A を辞書順にソート sort(A.begin(), A.end()); int Q; cin >> Q; string S = ""; while (Q--) { int type; cin >> type; if (type == 1) { char x; cin >> x; S.push_back(x); } else if (type == 2) { S.pop_back(); } else if (type == 3) { if (S.empty()) { cout << N << "\n"; } else { // S 以上の最小の要素の位置 auto left = lower_bound(A.begin(), A.end(), S); // S を接頭辞として持つ範囲の右端('z' の次の ASCII 文字 '{' を末尾につけた文字列未満の位置) string S_upper = S + '{'; auto right = lower_bound(A.begin(), A.end(), S_upper); cout << (right - left) << "\n"; } } } return 0; }