fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main() {
  7. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  8. int n, seila;
  9. stack<int> a, est, b;
  10. while (cin >> n && n) {
  11. while (cin >> seila) {
  12. if (!seila) {
  13. cout << "\n";
  14. break;
  15. }
  16. while (!a.empty()) a.pop();
  17. while (!est.empty()) est.pop();
  18. while (!b.empty()) b.pop();
  19. a.push(seila);
  20. b.push(1);
  21. for (int i=2; i<=n; ++i) {
  22. cin >> seila;
  23. a.push(seila);
  24. b.push(i);
  25. }
  26. while (!a.empty() || !est.empty() || !b.empty()) {
  27. if (!a.empty() && !b.empty() && a.top() == b.top()) {
  28. a.pop();
  29. b.pop();
  30. } else if (!est.empty() && !b.empty() && est.top() == b.top()) {
  31. est.pop();
  32. b.pop();
  33. } else if (!a.empty()) {
  34. est.push(a.top());
  35. a.pop();
  36. } else {
  37. break;
  38. }
  39. }
  40. if (a.empty() && est.empty() && b.empty())
  41. cout << "Yes\n";
  42. else
  43. cout << "No\n";
  44. }
  45. }
  46. }
Success #stdin #stdout 0s 572KB
stdin
Standard input is empty
stdout
Standard output is empty