#include <cassert>
#include <cstddef>
#include <iostream>
#include <optional>
#include <vector>
class BoundedStack {
  std::vector<int> a;
  std::size_t limit;

public:
  explicit BoundedStack(std::size_t n) : limit(n) {}
  bool push(int x) {
    if (a.size() == limit)
      return false;
    a.push_back(x);
    return true;
  }
  std::optional<int> pop() {
    if (a.empty())
      return {};
    int x = a.back();
    a.pop_back();
    return x;
  }
  std::size_t size() const { return a.size(); }
};
long long triangle(int n) {
  long long count = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < i; ++j)
      ++count;
  return count;
}
int main() {
  for (int n = 0; n <= 100; ++n)
    assert(triangle(n) == 1LL * n * (n - 1) / 2);
  BoundedStack s(2);
  assert(!s.pop());
  assert(s.push(1) && s.push(2));
  assert(!s.push(3) && s.size() == 2);
  assert(s.pop() == 2 && s.pop() == 1 && !s.pop());
  BoundedStack zero(0);
  assert(!zero.push(1));
  std::cout << "chapter02: passed\n";
}
