criyle/codenet-compile-errors huggingface dataset:
Language: C

#include <stdio.h#include <stdio.h>

int main(void)
{
	int N;
	scanf("%d",&N);
	int p[N];
	int i,w = 0;
	for(i = 0; i < N;i++)
	{
		scanf("%d",&p[i]);
	}
	for(i = 0; i < N; i++)
	{
		if(p[i]== i+1)
		{
			w++;
		}
	}
	if(w < 3)
	{
		printf("YES");
	}
	else{
		printf("NO");
	}
	
	return 0;
}




Compiler output:
main.c:1:10: fatal error: stdio.h#include <stdio.h: No such file or directory
    1 | #include <stdio.h#include <stdio.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
using namespace std;
 
int main(void)
{
  int n;
  int cnt = 0;
  vector<int> v;
  cin >> n;
  
  int buf;
  for(int i = 0;i < n;i++)
  {
    cin >> buf;
  	v.push_back(buf);
    
  }
  
  for(i = 0;i < n;i++)
  {
  	if(v[i] != i + 1)
      cnt ++;
    if (cnt >3)
    {
      cout << "NO";
      break;
    }
  }
  
  if(cnt < 3)
    cout << "YES";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:7: error: 'i' was not declared in this scope
   20 |   for(i = 0;i < n;i++)
      |       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
  	cin >> N;
  
  	vector<int> vec(N);
  	vector<int> vec_sort(N);
  
  	for (int i=0;i<N;i++){
    	cin >> vec.at(i);
    }
  
  	for (int i=0;i<N;i++){
  		vec_sort.at(i) = sort(vec.begin(),vec.end());
  		if (vec.at(i) == vec_sort(i)){
        	cout << "YES" << endl;
        }
    }
  
  	

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:38: error: void value not ignored as it ought to be
   16 |                 vec_sort.at(i) = sort(vec.begin(),vec.end());
      |                                  ~~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:17:42: error: no match for call to '(std::vector<int>) (int&)'
   17 |                 if (vec.at(i) == vec_sort(i)){
      |                                  ~~~~~~~~^~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;

int main(void)
{
  int n;
  int cnt = 0;
  vector<int> v;
  cin >> n;
  
  for(int i = 0;i < n;i++)
  {
  	v.push_back();
    cin >> v[i];
  }
  
  for(i = 0;i < n;i++)
  {
  	if(v[i] != i + 1)
      cnt ++;
    if (cnt >3)
    {
      cout << "NO";
      break;
    }
  }
  
  if(cnt < 3)
    cout << "YES";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:20: error: no matching function for call to 'std::vector<int>::push_back()'
   14 |         v.push_back();
      |         ~~~~~~~~~~~^~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; value_type = int]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 0 provided
a.cc:18:7: error: 'i' was not declared in this scope
   18 |   for(i = 0;i < n;i++)
      |       ^
Language: C++

#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int　p[N];
    for(int i = 0;i < N;i++) cin >> p[i];
    int dif = 0;
    
    for(int j = 0;j < N;j++){
        if(p[j] != j + 1) dif++;
    }
    
    if(dif <= 2){
        cout << "YES" << endl;
        return 0;
    }else{
        cout << "NO" << endl;
        return 0;
    }
}


Compiler output:
a.cc:7:5: error: extended character 　 is not valid in an identifier
    7 |     int　p[N];
      |     ^
a.cc: In function 'int main()':
a.cc:7:5: error: 'int\U00003000p' was not declared in this scope
    7 |     int　p[N];
      |     ^~~~~~
a.cc:8:37: error: 'p' was not declared in this scope
    8 |     for(int i = 0;i < N;i++) cin >> p[i];
      |                                     ^
a.cc:12:12: error: 'p' was not declared in this scope
   12 |         if(p[j] != j + 1) dif++;
      |            ^
Language: C


#include<stdio.h>
#include <stdlib.h>
int asc(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int main(void) {
	int n;
	int p[50];
	int p1[50];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &p[i]);
		int tmp = p[i];
		p1[i] = tmp;
	}
	qsort(p1, n, sizeof(int), asc);
	int c = 0;
	int x[50];
	for (int i = 0; i< n; i++) {
		if (p1[i] != p[i]) {
			x[c] = i;
			c++;
		}
	}
	if (c == 0) {
		printf("Yes");
	}else {
		if (c == 2) {
			int tmp = p[x[0]];
			p[x[0]] = p[x[1]];
			p[x[1]] = tmp;
		}
		c = 0;
		for (int i = 0; i < n; i++) {
			if (p1[i] != p[i]) {
				printf("No");
				break;
			}
			c++;
		}
		if (c == n) {
			printf("Yes");
		}
	}
	return 0;


Compiler output:
main.c: In function 'main':
main.c:46:9: error: expected declaration or statement at end of input
   46 |         return 0;
      |         ^~~~~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> v(n, 0);
  for(int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  int diff = 0;
  vector<int> c(v.begin(),v.end());
  sort(c.begin(), c.end());
  for(int i = 0; i < n; ++i) {
    if(v[i] != c[i]) {
      diff += 1;
    }
  }
  if(diff <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |   sort(c.begin(), c.end());
      |   ^~~~
      |   short
Language: C++

#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int k = 0;
  for (int i = 0; i < N; i ++) {
    int a;
    cin >> a;
    if (a != i + 1) k ++;
  }
  if (k > 2) cout << "NO" << endl;
  else cut << "YES" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:8: error: 'cut' was not declared in this scope
   13 |   else cut << "YES" << endl;
      |        ^~~
Language: C

#include <stdio.h>

int main(void)
{
  int i, a, n, ans=0;
  scanf("%d", &n);
  
  for(i=1; i<=n; i++){
    scanf("%d", &a);
    if(a != i) {
      ans++;
      if(ans > 2){
        printf("NO");
        return 0;
    }
  }
  printf("YES");
  return 0;
}

Compiler output:
main.c: In function 'main':
main.c:19:1: error: expected declaration or statement at end of input
   19 | }
      | ^
Language: C++

#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const long long mod = 1e9+7;

int main(){
    int n, t, s, p;
    bool flag = false;
    cin >> n;
    t = 0;
    i = 0;
    for(int i = 1; i <= n; i++){
        cin >> p;
        if(p != i){
            if(flag){
                if(i != t || p != s){
                    cout << "No" << endl;
                    return 0;
                }
            }else{
                t = p;
                s = i;
                flag = true;
            }
        }
    }

    cout << "Yes" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:5: error: 'i' was not declared in this scope
   19 |     i = 0;
      |     ^
Language: C++

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
int main () {
  
  ll N ;
  cin >> N ;
  int a[N]
  for(int i =0 ; i < N ;i++)
    cin >> a[i] ;
  
  //sort(a,a+N) ;
  vector<int> pos ;
  for(int i = 0 ; i < N ;i++)
    if(a[i] != (i + 1)) pos.push_back(i) ;
  
  if(pos.size() <= 1) cout<<"YES\n" ;
  else cout<<"NO\n" ;
  
  return 0 ;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:3: error: expected initializer before 'for'
    9 |   for(int i =0 ; i < N ;i++)
      |   ^~~
a.cc:9:18: error: 'i' was not declared in this scope
    9 |   for(int i =0 ; i < N ;i++)
      |                  ^
a.cc:15:8: error: 'a' was not declared in this scope
   15 |     if(a[i] != (i + 1)) pos.push_back(i) ;
      |        ^
Language: C++

#include<iostream>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  int p[N-1];
  int not = 0;
  
  for(int i=0;i<N;i++){
    cin >> p[i];
    if(p[i]==i+1)
      continue;
    else
      not=not+1;
  }
  
  if(not<3)
    cout << "Yes";
  else
    cout << "No";
  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:7: error: expected unqualified-id before 'not' token
   10 |   int not = 0;
      |       ^~~
a.cc:17:10: error: expected primary-expression before '=' token
   17 |       not=not+1;
      |          ^
a.cc:20:9: error: expected primary-expression before '<' token
   20 |   if(not<3)
      |         ^
Language: C++

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
int main () {
  
  ll N 
  cin >> N ;
  int a[N]
  for(int i =0 ; i < N ;i++)
    cin >> a[i] ;
  
  //sort(a,a+N) ;
  vector<int> pos ;
  for(int i = 0 ; i < N ;i++)
    if(a[i] != (i + 1)) pos.push_back(i) ;
  
  if(pos.size() <= 1) cout<<"YES\n" ;
  else cout<<"NO\n" ;
  
  return 0 ;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected initializer before 'cin'
    7 |   cin >> N ;
      |   ^~~
a.cc:8:9: error: 'N' was not declared in this scope
    8 |   int a[N]
      |         ^
a.cc:9:3: error: expected initializer before 'for'
    9 |   for(int i =0 ; i < N ;i++)
      |   ^~~
a.cc:9:18: error: 'i' was not declared in this scope
    9 |   for(int i =0 ; i < N ;i++)
      |                  ^
a.cc:15:8: error: 'a' was not declared in this scope
   15 |     if(a[i] != (i + 1)) pos.push_back(i) ;
      |        ^
Language: C++

#include<iostream>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  int p[N-1];
  int not=0;
  
  for(int i=0;i<N;i++){
    cin >> p[i];
    if(p[i]==i+1)
      continue;
    else
      not++;
  }
  
  if(not<3)
    cout << "Yes";
  else
    cout << "No";
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:7: error: expected unqualified-id before 'not' token
   10 |   int not=0;
      |       ^~~
a.cc:17:12: error: expected primary-expression before ';' token
   17 |       not++;
      |            ^
a.cc:20:9: error: expected primary-expression before '<' token
   20 |   if(not<3)
      |         ^
Language: C++

#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n;
int a[50+5],b[50+5];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int now[2],nowl=0;
    for(int i=0;i<n;i++)
        if(a[i]!=b[i]){
            if(nowl==2){
                cout<<"NO\n";
                return ;
            }
            now[nowl++]=i;
    }
    if(a[now[0]]==b[now[1]]&&a[now[1]]==b[now[0]])
        printf("YES\n");
    else
        printf("NO\n");
        
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   18 |                 return ;
      |                 ^~~~~~
Language: C++


    explicit C(vector<ll> v) : v_(move(v)){}
    bool resolve() {
        auto v = v_;
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i < v.size(); ++i) {
            if (v[i] != v_[i]) {
                count++;
            }
        }
        return count == 2 || count == 0;
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<ll> v{};
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        v.emplace_back(x);
    }
    C c{move(v)};
    cout << c.resolve() << endl;
    return 0;
}


Compiler output:
a.cc:2:14: error: ISO C++ forbids declaration of 'C' with no type [-fpermissive]
    2 |     explicit C(vector<ll> v) : v_(move(v)){}
      |              ^
a.cc:2:5: error: 'explicit' outside class declaration
    2 |     explicit C(vector<ll> v) : v_(move(v)){}
      |     ^~~~~~~~
a.cc:2:16: error: 'vector' was not declared in this scope
    2 |     explicit C(vector<ll> v) : v_(move(v)){}
      |                ^~~~~~
a.cc:2:23: error: 'll' was not declared in this scope
    2 |     explicit C(vector<ll> v) : v_(move(v)){}
      |                       ^~
a.cc:2:27: error: 'v' was not declared in this scope
    2 |     explicit C(vector<ll> v) : v_(move(v)){}
      |                           ^
a.cc: In function 'bool resolve()':
a.cc:4:18: error: 'v_' was not declared in this scope; did you mean 'v'?
    4 |         auto v = v_;
      |                  ^~
      |                  v
a.cc:5:9: error: 'sort' was not declared in this scope; did you mean 'short'?
    5 |         sort(v.begin(), v.end());
      |         ^~~~
      |         short
a.cc: At global scope:
a.cc:14:1: error: expected declaration before '}' token
   14 | };
      | ^
a.cc: In function 'int main()':
a.cc:17:5: error: 'll' was not declared in this scope
   17 |     ll N;
      |     ^~
a.cc:18:5: error: 'cin' was not declared in this scope
   18 |     cin >> N ;
      |     ^~~
a.cc:18:12: error: 'N' was not declared in this scope
   18 |     cin >> N ;
      |            ^
a.cc:19:5: error: 'vector' was not declared in this scope
   19 |     vector<ll> v{};
      |     ^~~~~~
a.cc:19:16: error: 'v' was not declared in this scope
   19 |     vector<ll> v{};
      |                ^
a.cc:21:11: error: expected ';' before 'x'
   21 |         ll x;
      |           ^~
      |           ;
a.cc:22:16: error: 'x' was not declared in this scope
   22 |         cin >> x;
      |                ^
a.cc:25:6: error: expected ';' before 'c'
   25 |     C c{move(v)};
      |      ^~
      |      ;
a.cc:26:5: error: 'cout' was not declared in this scope
   26 |     cout << c.resolve() << endl;
      |     ^~~~
a.cc:26:13: error: 'c' was not declared in this scope
   26 |     cout << c.resolve() << endl;
      |             ^
a.cc:26:28: error: 'endl' was not declared in this scope
   26 |     cout << c.resolve() << endl;
      |                            ^~~~
Language: Java

mport java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j,k;
		Scanner sc = new Scanner(System.in);
		int n = parseInt(sc.next());
		int[] p = new int[n];
		int[] q = new int[n];
		for(i=0;i<n;i++) {
			p[i] = parseInt(sc.next());
			q[i] = p[i];
		}
		sc.close();
		Arrays.sort(q);
		boolean f = true;
		int cnt = 0;
		for(i=0;i<n;i++) {
			if(p[i]!=q[i]) {
				cnt++;
				if(cnt >= 3) {
					f = false;
					break;
				}
			}
		}
		if(f)out.println("YES");
		else out.println("NO");
	}
}


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
mport java.util.*;
^
Main.java:2: error: class, interface, enum, or record expected
import static java.lang.Integer.*;
^
Main.java:4: error: class, interface, enum, or record expected
import static java.lang.Math.*;
^
Main.java:5: error: class, interface, enum, or record expected
import static java.lang.System.*;
^
4 errors
Language: C++

#include <iostream>

using namespace std;

int main(){
  int N, sum = 0;
  int s[60];
  
  cin >> N;
  
  for(int a = 0; a < N; ++a) cin >> s[];
  
  for (int a = 0; a < N-1; ++a){
    int b = s[a] - s[a + 1];
    sum = sum + b;
  }
  
  if(sum == N - 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:39: error: expected primary-expression before ']' token
   11 |   for(int a = 0; a < N; ++a) cin >> s[];
      |                                       ^
Language: C++

#include <iostream>

using namespace srd;

int main(){
  int N, sum = 0;
  int s[60];
  
  cin >> N;
  
  for(int a = 0; a < N; ++a) cin >> s;
  
  for (int a = 0; a < N-1; ++a){
    int b = s[a] - s[a + 1];
    sum = sum + b;
  }
  
  if(sum == N - 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Compiler output:
a.cc:3:17: error: 'srd' is not a namespace-name
    3 | using namespace srd;
      |                 ^~~
a.cc: In function 'int main()':
a.cc:9:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    9 |   cin >> N;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:18:20: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   18 |   if(sum == N - 1) cout << "YES" << endl;
      |                    ^~~~
      |                    std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:18:37: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   18 |   if(sum == N - 1) cout << "YES" << endl;
      |                                     ^~~~
      |                                     std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:19:8: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   19 |   else cout << "NO" << endl;
      |        ^~~~
      |        std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:19:24: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   19 |   else cout << "NO" << endl;
      |                        ^~~~
      |                        std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a;
  cin >> a;
  vector<int> array(a);
  vector<int> array2(a);

  for (int i = 0; i < array.length; i++)
  {
    cin >> array[i];
    array2[i] = array[i];
  }

  sort(array2.begin(), array2.end());

  int cnt = 0;
  for (int i = 0; i < array.length; i++)
  {
    if (array[i] != array2[i])
    {
      cnt++;
    }
  }
  if (cnt < 3) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:29: error: 'class std::vector<int>' has no member named 'length'
   11 |   for (int i = 0; i < array.length; i++)
      |                             ^~~~~~
a.cc:20:29: error: 'class std::vector<int>' has no member named 'length'
   20 |   for (int i = 0; i < array.length; i++)
      |                             ^~~~~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int n,k;
  vector<int> p, d;
	cin >> n;
  rep(i,n) {
    cin >> k;
    p.push_back(k);
    d.push_back(k);
  }
  sort(d.begin(), d.end());
  int cnt = 0;
  rep(i,n) {
    if (p.at(i) != d.at(i)) cnt++;
  }
  if (cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   16 |   sort(d.begin(), d.end());
      |   ^~~~
      |   short
Language: C++

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int N, tmp, ans=0;
    cin >> N;
    vector<int> p, q;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        p.push_back(tmp);
        q.push_back(tmp);
    }
    sort(q.begin(), q.end());
    for (int i = 0; i < N; i++) {
        if (p[i] != q[i]) {
            ans++;
        }
    }
    if (ans <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   16 |     sort(q.begin(), q.end());
      |     ^~~~
      |     short
Language: Java

import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int f = 0;
Integer a[] = new Integer[N];
Integer b[] = new Integer[N];
for(int i=0;i<N;i++){
a[i] = sc.nextInt();
b[i] = a[i];
}
Arrays.sort(a,Comparator,reverseOrder());
for(int i=0;i<N;i++){
if(a[i]==b[i]){
f++;
}
}
if(f=2){
System.out.println(YES);
}else{
System.out.println("NO");
}}}

Compiler output:
Main.java:13: error: cannot find symbol
Arrays.sort(a,Comparator,reverseOrder());
              ^
  symbol:   variable Comparator
  location: class Main
Main.java:13: error: cannot find symbol
Arrays.sort(a,Comparator,reverseOrder());
                         ^
  symbol:   method reverseOrder()
  location: class Main
Main.java:19: error: incompatible types: int cannot be converted to boolean
if(f=2){
    ^
Main.java:20: error: cannot find symbol
System.out.println(YES);
                   ^
  symbol:   variable YES
  location: class Main
4 errors
Language: C++

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;

int main() {

	int a[4], sum, n, flag = 0, m;

	cin >> n >> m;

	sum = (n + m) / 2;

	if (sum % 2 == 0)cout << sum << endl;
	else cout << "IMPOSSIBLE" << endl;
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

	using namespace std;

	int main() {

		int a[51], sum, n, flag = 0, m, count = 0;

		cin >> n;


		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i] != i + 1)count++;
		}

		if (count == 2||count == 0)cout << "YES" << endl;
		else cout << "NO" << endl;

		return 0;
	}

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:17: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   49 |         int main() {
      |                 ^~
a.cc:49:17: note: remove parentheses to default-initialize a variable
   49 |         int main() {
      |                 ^~
      |                 --
a.cc:49:17: note: or replace parentheses with braces to value-initialize a variable
a.cc:49:20: error: a function-definition is not allowed here before '{' token
   49 |         int main() {
      |                    ^
Language: C++

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	int t = n;
	vector<int> data;
	while(t--) {
	    int a;
	    cin >> a;
	    data.push_back(a);
	}
	int count = 0;
	for(int i = 0; i < n; i++) {
	    if(ans[i]!=(i+1)) {
	        count += 1;
	    }
	}
	if(count == 0 || count == 2) {
	    cout << "YES" << endl;
	}
	else {
	    cout << "NO" <<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
   17 |             if(ans[i]!=(i+1)) {
      |                ^~~
      |                abs
Language: C++

#include<bits/stdc++.h>
#define speed ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
  speed;
  int n;
  cin>>n;
  int l[n];
  for (int i=0;i<n;i++)
    cin>>l[i];
  int ctr=0;
  for (i=0;i<n;i++)
  {
    if (l[i]!=i+1)
    {
      if (l[l[i]-1]!=(i+1))
      {
        ctr=3;
        break;
      }
      else
        ctr++;
    }
  }
  if (ctr==0 || ctr==2)
    cout<<"YES\n";
  else
    cout<<"NO\n";
}

Compiler output:
a.cc:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:17:8: error: 'i' was not declared in this scope
   17 |   for (i=0;i<n;i++)
      |        ^
Language: Java

import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int f = 0;
Integer A[] = new Integer[N];
Integer B[] = new Integer[N];
for(int i=0;i<N;i++){
a[i] = sc.nextint();
b[i] = a[i];
}
Arrays.sort(a,Comparator,reverseOrder());
for(int i=0;i<N;i++){
if(a[i]==b[i]){
f++;
}
}
if(f=2){
System.out.println(YES);
}else{
System.out.println("NO");
}}}

Compiler output:
Main.java:10: error: cannot find symbol
a[i] = sc.nextint();
^
  symbol:   variable a
  location: class Main
Main.java:10: error: cannot find symbol
a[i] = sc.nextint();
         ^
  symbol:   method nextint()
  location: variable sc of type Scanner
Main.java:11: error: cannot find symbol
b[i] = a[i];
^
  symbol:   variable b
  location: class Main
Main.java:11: error: cannot find symbol
b[i] = a[i];
       ^
  symbol:   variable a
  location: class Main
Main.java:13: error: cannot find symbol
Arrays.sort(a,Comparator,reverseOrder());
            ^
  symbol:   variable a
  location: class Main
Main.java:13: error: cannot find symbol
Arrays.sort(a,Comparator,reverseOrder());
              ^
  symbol:   variable Comparator
  location: class Main
Main.java:13: error: cannot find symbol
Arrays.sort(a,Comparator,reverseOrder());
                         ^
  symbol:   method reverseOrder()
  location: class Main
Main.java:15: error: cannot find symbol
if(a[i]==b[i]){
   ^
  symbol:   variable a
  location: class Main
Main.java:15: error: cannot find symbol
if(a[i]==b[i]){
         ^
  symbol:   variable b
  location: class Main
Main.java:19: error: incompatible types: int cannot be converted to boolean
if(f=2){
    ^
Main.java:20: error: cannot find symbol
System.out.println(YES);
                   ^
  symbol:   variable YES
  location: class Main
11 errors
Language: C++

//  Created by liszt on 2019/07/27.
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n; cin>>n;
    vector<int> p(n);
    vector<vector<int>> pij(2,vector<int>(2));
    
    for(int i=0;i<n;i++)cin>>p[i];
    
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(p[i]!=i){
            cnt++;
            if(!pij[0]){pij[0][0]=p[i];pij[0][1]=i;}
            else {pij[1][0]=p[i]; pij[1][1]=i;}
        }
    }
    
    if(cnt>2){
        cout<<"NO"<<endl;
        return 0;
    }
    if(pij[0][1]==pij[1][0]&&pij[0][0]==pij[1][1]){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:16: error: no match for 'operator!' (operand type is '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
   16 |             if(!pij[0]){pij[0][0]=p[i];pij[0][1]=i;}
a.cc:16:16: note: candidate: 'operator!(bool)' (built-in)
a.cc:16:16: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'bool'
Language: C++

#include  <bits/stdc++.h>
using namespace  std;
int main()
{
	int n;
	cin>>n;
	vector<int>A(n), B;
	rep(i,0,n)cin>>A[i];
	B=A;
	int counter=0;
	rep(i,0,n)
	{
		if(A[i]!=B[i])counter++;
	}
	if(counter<=2)cout<<"YES";
	else cout<<"NO";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:13: error: 'i' was not declared in this scope
    8 |         rep(i,0,n)cin>>A[i];
      |             ^
a.cc:8:9: error: 'rep' was not declared in this scope
    8 |         rep(i,0,n)cin>>A[i];
      |         ^~~
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pq 	priority_queue<int, vector<int>, greater<int> >
#define lp(n,i) for(ll i=0;i<n;i++)
ll e=  1000000007;
using namespace std;

int main(){
	

ll n;
cin>>n;
ll a[n];
lp
(n,i)v
{
	cin>>a[i];
}
ll v=0;
lp(n,i)
{
	if(a[i]!=(i+1))v++;
}
	if(v==0||v==2)cout<<"YES";
	else cout<<"NO";
	
	
 return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:6: error: 'v' was not declared in this scope
   19 | (n,i)v
      |      ^
Language: C++

#include<bits/stdc++.h>

using namespace std;

int main()
{
  int n;
  cin>>n;
  
  int a[n+5];
  
  for(int i=1;i<=n;i++)cin>>a[i];
  
  int cnt=0;
  
  for(int i=1;i<=n;i++)
  {
    if(a[i]!=i)cnt++;
  }
  if(cnt<=2)
    cout<<"YES"<<'\n';
  else
    cout<<"NO"<<'\n'
  
 return 0; 	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:21: error: expected ';' before 'return'
   23 |     cout<<"NO"<<'\n'
      |                     ^
      |                     ;
   24 | 
   25 |  return 0;
      |  ~~~~~~
Language: C++

#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ind1=0,ind2=0,ind2=0;
  int ar[n];
  for(int i=0;i<n;++i)
  {cin>>ar[i];if(ar[i]!=i+1){ind1++;}}
  if(ind1<=2){cout<<"YES";return 0;}
  cout<<"NO";
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:7:21: error: redeclaration of 'int ind2'
    7 |   int ind1=0,ind2=0,ind2=0;
      |                     ^~~~
a.cc:7:14: note: 'int ind2' previously declared here
    7 |   int ind1=0,ind2=0,ind2=0;
      |              ^~~~
Language: C++

#include <stdio.h>


int main()
{
	int N;
	int i;
	int prev = 0;
	int current;
	int cnt = 0;

	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf_s("%d", &current);
		if (prev > current) {
			cnt++;
		}
		prev = current;

	}

	if (cnt > 1) {
		printf("NO\n");
	}
	else {
		printf("YES\n");
	}
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   14 |                 scanf_s("%d", &current);
      |                 ^~~~~~~
      |                 scanf
Language: C++

//#include "SaveFuncs.cpp"

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
string strMulti(string t, int n) { string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }

/*****/

int Main()
{
	int N;
	cin >> N;
	vector<int> P(N);
	rep(i, N)	cin >> P.at(i);

	int diff = 0;
	rep(i, N)
	{
		if (P.at(i) != i + 1)
		{
			diff++;
		}
	}

	debug_cout(diff);

	if (diff == 0 || diff == 2)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

/*****/

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	Main();

	return 0;
}


Compiler output:
a.cc: In function 'int Main()':
a.cc:47:9: error: 'debug_cout' was not declared in this scope
   47 |         debug_cout(diff);
      |         ^~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pq 	priority_queue<int, vector<int>, greater<int> >
ll e=  1000000007;
using namespace std;

int main(){
	

ll n;
cin>>n;
ll a[n];
lp
(n,i)v
{
	cin>>a[i];
}
ll v=0;
lp(n,i)
{
	if(a[i]!=(i+1))v++;
}
	if(v==0||v==2)cout<<"YES";
	else cout<<"NO";
	
	
 return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:4: error: 'i' was not declared in this scope
   18 | (n,i)v
      |    ^
a.cc:17:1: error: 'lp' was not declared in this scope; did you mean 'll'?
   17 | lp
      | ^~
      | ll
Language: C++

#include "SaveFuncs.cpp"

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
string strMulti(string t, int n) { string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }

/*****/

int Main()
{
	int N;
	cin >> N;
	vector<int> P(N);
	rep(i, N)	cin >> P.at(i);

	int diff = 0;
	rep(i, N)
	{
		if (P.at(i) != i + 1)
		{
			diff++;
		}
	}

	debug_cout(diff);

	if (diff == 0 || diff == 2)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

/*****/

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	Main();

	return 0;
}


Compiler output:
a.cc:1:10: fatal error: SaveFuncs.cpp: No such file or directory
    1 | #include "SaveFuncs.cpp"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pq 	priority_queue<int, vector<int>, greater<int> >
ll e=  1000000007;
using namespace std;

int main(){
	

ll n;
cin>>n;
ll a[n];
lp
(n,i)v
{
	cin>>a[i];
}
ll =0;
lp(n,i)
{
	if(a[i]!=(i+1))v++;
}
	if(v==0||v==2)cout<<"YES";
	else cout<<"NO";
	
	
 return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:4: error: 'i' was not declared in this scope
   18 | (n,i)v
      |    ^
a.cc:17:1: error: 'lp' was not declared in this scope; did you mean 'll'?
   17 | lp
      | ^~
      | ll
a.cc:22:4: error: expected unqualified-id before '=' token
   22 | ll =0;
      |    ^
a.cc:27:12: error: 'v' was not declared in this scope
   27 |         if(v==0||v==2)cout<<"YES";
      |            ^
Language: C++

#include<bits/stdc++.h>
#define ll long long
#define pub push_back 
#define pob pop_back 
#define puf push_front
#define pof pop_front
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
using namespace std ;
int main()
{
	ll n ; 
	cin >> n ;
	ll arr[n] , sor[n];
	fo(i , n)
	{
		cin >> arr[i] ;
		sor[i] = arr[i] ;
	}
	sort(sor , sor+n);
	ll a = 0 ;
	fo(i , n)
		if(sor[i] != arr[i])
			a++ ;
	if(a == 0 || a == 2)
		cout << "YES" << endl ;
	else
		cout << "NO" <<< endl ;
		

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:32: error: expected primary-expression before '<' token
   27 |                 cout << "NO" <<< endl ;
      |                                ^
Language: C++

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;



int main(int argc, const char * argv[]) {
    ll N;
  	cin >> N;
  	ll i;
  	ll difs = 0;
  	ll num;
  for(i=0;i<N;i++){
    cin >> num;
    if(i+1!=num)difs++:
  }
  if(difs==0 || difs == 2){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
  
  
    
    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:25:23: error: expected ';' before ':' token
   25 |     if(i+1!=num)difs++:
      |                       ^
      |                       ;
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,count = 0,p;
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> p;
    if(1(i == p)){
      count++;
    }
  }
  if(count >= 3){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: expression cannot be used as a function
    9 |     if(1(i == p)){
      |        ~^~~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int arr[110];
int cntl
int main(){
	int n;
	cin>>n;
	int x;
	for(x=1;x<=n;x++)
	{
		cin>>arr[x];
		if(arr[x]!=x)
		{
			cnt++;
		}
	}
	if(cnt<=2)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	cout<<"NO"<<endl;
}

Compiler output:
a.cc:5:1: error: expected initializer before 'int'
    5 | int main(){
      | ^~~
Language: C++

#include <bits/stdc++.h>

using namespace std;
int n;
int a[55];
int main()
{
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]!=i) ans++;
    }
    if(a[i]==0||a[i]==2)
        printf("YES");
    else
        printf("NO");
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:10: error: 'i' was not declared in this scope
   15 |     if(a[i]==0||a[i]==2)
      |          ^
Language: C++

#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
int main(){
  int N,a=0;
  cin>>N;
  vector<int>p(N);
  REP(i,N){
    cin>>p[i]
    if((p[i]-i-1)!=0){
      a++;
    }
  }
  if(a!=0 && a!=2){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:14: error: expected ';' before 'if'
   24 |     cin>>p[i]
      |              ^
      |              ;
   25 |     if((p[i]-i-1)!=0){
      |     ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
	long long int a;
	cin>>a;
	int top=0;
	for(int i = 0 ;i<a;i++){
		cin>>dizi[i];
		if(dizi[i]!=i+1){
			top++;
		}
	}
	if(top == 0 || top == 2){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:9:22: error: 'dizi' was not declared in this scope
    9 |                 cin>>dizi[i];
      |                      ^~~~
Language: C++


#include <bits/stdc++.h>
 
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define ll long long 
#define inf 1000000000
#define iPair pair< ll , ll >
using namespace std;
#define lp(n,i) for(ll i=0;i<n;i++)
#define rlp(n) for(ll i=n-1;i>=0;i--)
#define pq 	priority_queue<int, vector<int> , greater<int> >
 
/*ll pw(ll x, ll  y) ;
ll mi(ll  a) 
{ return pw(a, e-2); } 
 
ll pw(ll x, ll  y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = pw(x, y/2) % e; 
    p = (p * p) % e; 
  
    return (y%2 == 0)? p : (x * p) % e; 
} 
  
  
 bool sortbysec(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int mod(string num, int a) 
{ 
    // Initialize result 
    int res = 0; 
  
    // One by one process all digits of 'num' 
    for (int i = 0; i < num.length(); i++) 
         res = (res*10 + (int)num[i] - '0') %a; 
  
    return res; 
} */












int main()
{
ll n;
cin>>n;
ll a[n];
lp
(n,i)
{
	cin>>a[i];
}
ll a=0;
lp(n,i)
{
	if(a[i]!=(i+1))a++;
}
	if(a==0||a==2)cout<<"YES";
	else cout<<"NO";
	
	
 
	cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
	return 0;
}
 
 
 
 

Compiler output:
a.cc: In function 'int main()':
a.cc:68:4: error: conflicting declaration 'long long int a'
   68 | ll a=0;
      |    ^
a.cc:62:4: note: previous declaration as 'long long int a [n]'
   62 | ll a[n];
      |    ^
a.cc:71:24: error: lvalue required as increment operand
   71 |         if(a[i]!=(i+1))a++;
      |                        ^
a.cc:73:19: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   73 |         if(a==0||a==2)cout<<"YES";
      |                  ~^~~
Language: C++

#include<bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;

const int maxn = 3010;
double mina[maxn], maxa[maxn];

double deg2rad(double deg) { return deg * pi * 180; }

int main() {
  #ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
  #endif

  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ok = 1;
  for (int i = 0; i < n - 1; ++i) if (a[i] > a[i + 1]) { ok = 0; break; }
  if (ok) { cout << "YES"; return 0; }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      swap(a[i], a[j]);
      ok = 1;
      for (int k = 0; k < n - 1; ++k) if (a[k] > a[k + 1]) { ok = 0; break; }
      if (ok) { cout << "YES"; return 0; }
    }
  }
  cout << "NO\n";
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:38: error: 'a' was not declared in this scope
   19 |   for (int i = 0; i < n; ++i) cin >> a[i];
      |                                      ^
a.cc:21:39: error: 'a' was not declared in this scope
   21 |   for (int i = 0; i < n - 1; ++i) if (a[i] > a[i + 1]) { ok = 0; break; }
      |                                       ^
a.cc:25:12: error: 'a' was not declared in this scope
   25 |       swap(a[i], a[j]);
      |            ^
Language: C++

#include <bits/stdc++.h>

using namespace std;
int n;
int a[55];
int main()
{
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]!=i) ans++;
    }
    if(a[i]==0||a[i]==2)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:10: error: 'i' was not declared in this scope
   15 |     if(a[i]==0||a[i]==2)
      |          ^
Language: C++

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

void fastscan(ll &number)
{
	bool negative = false;
	register int c;
	number = 0;
	c = getchar();
	if (c=='-') 
	{
		negative = true;
		c = getchar();
	}
	for (; (c>47 && c<58); c=getchar())
		number = number *10 + c - 48;
	if (negative)
		number *= -1;
}

bool isprime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

bool checkisTree(ll degree[],ll n) 
{
    ll deg_sum = 0; 
    for (ll i = 0; i < n; i++) 
        deg_sum += degree[i]; 
    return (2*(n-1) == deg_sum);
}

ll gcd(ll a, ll b) 
{
    
    if (b == 0)  return a;
    return gcd(b, a % b);

}

int main()
{
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll arr[n], arr1[n];
		for(ll i=0; i<n; i++)
		{
			cin>>arr[i];
			arr1[i]=arr[i];
		}
		sort(arr1,arr1+n);
		for(ll i=0; i<n; i++)
		{
			if(arr1[i]-arr[i]!=0)
				cnt++;
		}
		if(cnt==2)
			cout<<"YES";
		else
			cout<<"NO";
	}	
}

Compiler output:
a.cc: In function 'void fastscan(ll&)':
a.cc:20:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |         register int c;
      |                      ^
a.cc: In function 'int main()':
a.cc:84:33: error: 'cnt' was not declared in this scope; did you mean 'int'?
   84 |                                 cnt++;
      |                                 ^~~
      |                                 int
a.cc:86:20: error: 'cnt' was not declared in this scope; did you mean 'int'?
   86 |                 if(cnt==2)
      |                    ^~~
      |                    int
Language: C++

#include<bits/stdc++.h>

using namespace std;
int a[100];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]!=i) now++;
	}
	int now=0;
	if(now!=2){
		puts("NO");return 0;
	}
	puts("YES");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:29: error: 'now' was not declared in this scope; did you mean 'pow'?
   10 |                 if(a[i]!=i) now++;
      |                             ^~~
      |                             pow
Language: Java

package abc135;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class B {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] tmpArray = br.readLine().split(" ");
		
		int input[] = new int[n];
		
		int diff = 0;
		for(int i = 1; i <= n; i++){
			input[i - 1] = Integer.parseInt(tmpArray[i - 1]);
			if(input[i - 1] != i){
				diff++;
			}
		}
		
		if(diff <= 2){
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

}


Compiler output:
Main.java:7: error: class B is public, should be declared in a file named B.java
public class B {
       ^
1 error
Language: C++

#include<bits/stdc++.h>

using namespace std;
int a[100];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]!=i) now++;
	}
	if(now!=2){
		puts("NO");return 0;
	}
	puts("YES");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:29: error: 'now' was not declared in this scope; did you mean 'pow'?
   10 |                 if(a[i]!=i) now++;
      |                             ^~~
      |                             pow
a.cc:12:12: error: 'now' was not declared in this scope; did you mean 'pow'?
   12 |         if(now!=2){
      |            ^~~
      |            pow
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main() 
{
    FIO;
    int t,n,k,i,j;
    cin >> n;
    
    int a[n],b[n];
    
    for(i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    
    sort(b,b+n);
    
    k=0;
    for(i=0;i<n;i++)
        if(a[i]!=b[i])
            k++;
    f(k<=2)
        cout << "YES";
    else    
        cout << "NO";
    
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:5: error: 'f' was not declared in this scope
   27 |     f(k<=2)
      |     ^
a.cc:29:5: error: 'else' without a previous 'if'
   29 |     else
      |     ^~~~