fork download
  1. #include <bits/stdc++.h>
  2. #include <string>
  3. using namespace std;
  4. #define ll long long
  5. #define dd double
  6. #define ld long double
  7. #define pi 3.14159265359
  8. #define ull unsigned long long
  9. #define yes cout<<"YES\n"
  10. #define no cout<<"NO\n"
  11. #define el "\n"
  12. #define Arwa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  13. #define fix(x) cout<<fixed<<setprecision(x)
  14. ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
  15. ll lcm(int a,int b) {return a/gcd(a,b)*b;}
  16. bool prime(ll n)
  17. {
  18. if(n==2) return true;
  19. if(n%2==0||n==1) return false;
  20. else { for(ll i=3; i*i<=n; i+=2) {if(n%i==0) return false;}}return true;
  21. }
  22. //here we go again
  23. int main()
  24. {
  25. Arwa
  26. int t=1;
  27. //cin>>t;
  28. stack<int>st;
  29. vector<int>v;
  30. while(t--)
  31. {
  32. int n;
  33. cin>>n;
  34. int arr[n];
  35. bool f=0;
  36. for(int i=0;i<n;i++)
  37. cin>>arr[i];
  38. for(int i=0;i<n;i++)
  39. {
  40. if(st.empty()||st.top()!=arr[i])
  41. st.push(arr[i]);
  42. else if(st.top()==arr[i])
  43. st.pop();
  44. }
  45. while(!st.empty())
  46. {
  47. v.push_back(st.top());
  48. st.pop();
  49. }
  50. if(v.size()<=1)
  51. yes;
  52. else if(v.size()==2)
  53. {
  54. if((v[0]%2)!=(v[1]%2))
  55. no; else yes;
  56. }
  57. else
  58. {
  59. for(int i=1;i<v.size()-1;i++)
  60. {
  61. if(v[i]%2!=v[i-1]%2&&v[i-1]%2==v[i+1]%2)
  62. f=1;
  63. }
  64. if(!f)
  65. yes; else no;
  66. }
  67. }
  68. return 0;
  69. }
  70. /*
  71. 5
  72. 2 1 1 2 5
  73. 3
  74. 4 5 3
  75. 2 10 10
  76. 3 1 2 3
  77. */
  78.  
  79.  
  80.  
  81.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
NO