Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- ll a[10000], n;
- int view(){
- cout << "No" << endl;
- exit(0);
- }
- int swp(ll i){
- ll temp;
- temp = a[i + 2];
- a[i + 2] = a[i + 1];
- a[i + 1] = a[i];
- a[i] = temp;
- }
- int swp1(ll i){
- if (i >= n - 2)
- view();
- ll temp;
- temp = a[i];
- a[i] = a[i + 1];
- a[i + 1] = a[i + 2];
- a[i + 2] = temp;
- }
- int doo(int i){
- for (int j = i; j >= 0; j -= 2){
- if (j >= 2 && a[j] < a[j - 2]){
- swp(j - 2);
- }
- else
- if (j >= 1 && a[j] < a[j - 1]){
- swp1(j - 1);
- break;
- }
- else
- if (j && a[j - 1] > a[j])
- view();
- }
- }
- int main()
- {
- ll ind;
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int i = 2; i < n; i++){
- if (a[i - 1] > a[i])
- doo(i);
- }
- for (int i = 2; i < n; i++){
- if (a[i - 1] > a[i])
- doo(i);
- }
- cout << "Yes" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement