using System;
public class Test
{
public static List<int> getMax(List<string> operations)
{
Stack<int> arr = new Stack<int>();
List<int> ans = new List<int>();
SortedDictionary<int, int> occurences = new SortedDictionary<int, int>();
foreach (var query in operations)
{
if (query.Length > 1)
{
string x = query.Substring(2);
int value = int.Parse(x);
arr.Push(value);
if (occurences.ContainsKey(value))
{
occurences[value]++;
}
else
{
occurences.Add(value, 1);
}
}
else if (query == "2")
{
occurences[arr.Peek()]--;
if (occurences[arr.Peek()] == 0)
{
occurences.Remove(arr.Peek());
}
arr.Pop();
}
else
{
ans.Add(occurences.Last().Key);
}
}
return ans;
}
public static void Main()
{
// your code goes here
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyBMaXN0PGludD4gZ2V0TWF4KExpc3Q8c3RyaW5nPiBvcGVyYXRpb25zKQoJewoJICAgIFN0YWNrPGludD4gYXJyID0gbmV3IFN0YWNrPGludD4oKTsKCSAgICBMaXN0PGludD4gYW5zID0gbmV3IExpc3Q8aW50PigpOwoJCgkgICAgU29ydGVkRGljdGlvbmFyeTxpbnQsIGludD4gb2NjdXJlbmNlcyA9IG5ldyBTb3J0ZWREaWN0aW9uYXJ5PGludCwgaW50PigpOwoJCgkgICAgZm9yZWFjaCAodmFyIHF1ZXJ5IGluIG9wZXJhdGlvbnMpCgkgICAgewoJICAgICAgICBpZiAocXVlcnkuTGVuZ3RoID4gMSkKCSAgICAgICAgewoJICAgICAgICAgICAgc3RyaW5nIHggPSBxdWVyeS5TdWJzdHJpbmcoMik7CgkgICAgICAgICAgICBpbnQgdmFsdWUgPSBpbnQuUGFyc2UoeCk7CgkKCSAgICAgICAgICAgIGFyci5QdXNoKHZhbHVlKTsKCQoJICAgICAgICAgICAgaWYgKG9jY3VyZW5jZXMuQ29udGFpbnNLZXkodmFsdWUpKQoJICAgICAgICAgICAgewoJICAgICAgICAgICAgICAgIG9jY3VyZW5jZXNbdmFsdWVdKys7CgkgICAgICAgICAgICB9CgkgICAgICAgICAgICBlbHNlCgkgICAgICAgICAgICB7CgkgICAgICAgICAgICAgICAgb2NjdXJlbmNlcy5BZGQodmFsdWUsIDEpOwoJICAgICAgICAgICAgfQoJICAgICAgICB9CgkgICAgICAgIGVsc2UgaWYgKHF1ZXJ5ID09ICIyIikKCSAgICAgICAgewoJICAgICAgICAgICAgb2NjdXJlbmNlc1thcnIuUGVlaygpXS0tOwoJCgkgICAgICAgICAgICBpZiAob2NjdXJlbmNlc1thcnIuUGVlaygpXSA9PSAwKQoJICAgICAgICAgICAgewoJICAgICAgICAgICAgICAgIG9jY3VyZW5jZXMuUmVtb3ZlKGFyci5QZWVrKCkpOwoJICAgICAgICAgICAgfQoJCgkgICAgICAgICAgICBhcnIuUG9wKCk7CgkgICAgICAgIH0KCSAgICAgICAgZWxzZQoJICAgICAgICB7CgkgICAgICAgICAgICBhbnMuQWRkKG9jY3VyZW5jZXMuTGFzdCgpLktleSk7CgkgICAgICAgIH0KCSAgICB9CgkKCSAgICByZXR1cm4gYW5zOwoJfQoJCglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJfQp9Cg==