Language: C++

#include <bits/stdc++.h>

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 10000000;
const ll inf = 5e18-1;

int main() {
	fastio;
	ll n,x,cont=0;
	cin>>n;
	ll p[n],k[n];
	f(i,0,n){
		cin>>x;
		p[i]=x;
		k[i]=x;
	}
	sort(p,p+n);
	f(i,0,n){
		if(p[i]!=k[i]) cont++;
	}
	if(cont<3) yes;
	else no; 
	return 0;
#include <bits/stdc++.h>

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"

using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 10000000;
const ll inf = 5e18-1;

int main() {
	fastio;
	ll n,x,cont=0;
	cin>>n;
	ll p[n],k[n];
	f(i,0,n){
		cin>>x;
		p[i]=x;
	}
	f(i,0,n){
		k[i]=i+1;
	}
	f(i,0,n){
		if(p[i]!=k[i]) cont++;
	}
	if(cont==2 || cont==0) yes;
	else no; 
	return 0;
	}

Compiler output:
a.cc:65:9: warning: "yes" redefined
   65 | #define yes cout<<"YES\n"
      |         ^~~
a.cc:18:9: note: this is the location of the previous definition
   18 | #define yes cout<<"Yes\n"
      |         ^~~
a.cc:66:9: warning: "no" redefined
   66 | #define no cout<<"NO\n"
      |         ^~
a.cc:19:9: note: this is the location of the previous definition
   19 | #define no cout<<"No\n"
      |         ^~
a.cc: In function 'int main()':
a.cc:78:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   78 | int main() {
      |         ^~
a.cc:78:9: note: remove parentheses to default-initialize a variable
   78 | int main() {
      |         ^~
      |         --
a.cc:78:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:78:12: error: a function-definition is not allowed here before '{' token
   78 | int main() {
      |            ^
a.cc:96:10: error: expected '}' at end of input
   96 |         }
      |          ^
a.cc:31:12: note: to match this '{'
   31 | int main() {
      |            ^