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

#include<iostream>
const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:5: error: 'map' was not declared in this scope
   11 |     map<int, int> mp;
      |     ^~~
a.cc:2:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    1 | #include<iostream>
  +++ |+#include <map>
    2 | const int MAXN = 1010;
a.cc:11:9: error: expected primary-expression before 'int'
   11 |     map<int, int> mp;
      |         ^~~
a.cc:14:9: error: 'mp' was not declared in this scope
   14 |         mp[w[i]] = 0;
      |         ^~
a.cc:19:24: error: 'mp' was not declared in this scope; did you mean 'p'?
   19 |         for (auto& p : mp) p.second = k++;
      |                        ^~
      |                        p
a.cc:31:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   31 |             now = mp[w[now]];
      |                   ^~
      |                   mi
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve(){
int ans = 0;

bool V[MAX];
for(int i = 0; i < n; i++){
B[i] = A[i];
V[i] = false;
}
sort(B, B+n);
for(int i = 0; i < n; i++) T[B[i]] = i;
for(int i = 0; i < n; i++){ 
if(V[i]) continue;
int cur = i;
int S = 0;
int m = VMAX;
int an = 0;
while(1){
V[cur} = true;
an++;
int v = A[cur];
m = min(m, v);
S += v;
if(V[cur]) break;
}
ans += min(S + (an - 2) * m, m + S + (an + 1) * S);
}
return ans;
}

int main(){
cin >> n;
S = VMAX;
}
int ans = solve();
count << ans << Ende;

return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:27:6: error: expected ']' before '}' token
   27 | V[cur} = true;
      |      ^
      |      ]
a.cc:27:6: error: expected ';' before '}' token
   27 | V[cur} = true;
      |      ^
      |      ;
a.cc:27:8: error: expected primary-expression before '=' token
   27 | V[cur} = true;
      |        ^
a.cc:34:12: error: 'S' was not declared in this scope
   34 | ans += min(S + (an - 2) * m, m + S + (an + 1) * S);
      |            ^
a.cc:34:17: error: 'an' was not declared in this scope; did you mean 'ans'?
   34 | ans += min(S + (an - 2) * m, m + S + (an + 1) * S);
      |                 ^~
      |                 ans
a.cc:34:27: error: 'm' was not declared in this scope
   34 | ans += min(S + (an - 2) * m, m + S + (an + 1) * S);
      |                           ^
a.cc: At global scope:
a.cc:36:1: error: expected unqualified-id before 'return'
   36 | return ans;
      | ^~~~~~
a.cc:37:1: error: expected declaration before '}' token
   37 | }
      | ^
a.cc: In function 'int main()':
a.cc:41:1: error: 'S' was not declared in this scope
   41 | S = VMAX;
      | ^
a.cc: At global scope:
a.cc:44:1: error: 'count' does not name a type
   44 | count << ans << Ende;
      | ^~~~~
a.cc:46:1: error: expected unqualified-id before 'return'
   46 | return 0;
      | ^~~~~~
a.cc:47:1: error: expected declaration before '}' token
   47 | }
      | ^
a.cc: In function 'int solve()':
a.cc:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;
 
int n, A[MAX], s;
int B[MAX], T[VMAX+1];
 
int solve(){
int ans = 0;
 
bool V[MAX];
for(int i = 0; i < n; i++){
B[i] = A[i];
V[i] = false;
}
sort(B, B+n);
for(int i = 0; i < n; i++) T[B[i]] = i;
for(int i = 0; i < n; i++){ 
if(V[i]) continue;
int cur = i;
int S = 0;
int m = VMAX;
int an = 0;
while(1){
V[cur] = true;
an++;
int v = A[cur];
m = min(m, v);
S += v;
if(V[cur]) break;
}
ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
}
return ans;
}
 
int main(){
cin >> n;
s = VMAX;
}
int ans = solve();
count << ans << endl;
 
return 0;
}


Compiler output:
a.cc:6:1: error: extended character   is not valid in an identifier
    6 |  
      | ^
a.cc:9:1: error: extended character   is not valid in an identifier
    9 |  
      | ^
a.cc:12:1: error: extended character   is not valid in an identifier
   12 |  
      | ^
a.cc:38:1: error: extended character   is not valid in an identifier
   38 |  
      | ^
a.cc:45:1: error: extended character   is not valid in an identifier
   45 |  
      | ^
a.cc:6:1: error: '\U000000a0' does not name a type
    6 |  
      | ^
a.cc:9:1: error: '\U000000a0' does not name a type
    9 |  
      | ^
a.cc:38:1: error: '\U000000a0' does not name a type
   38 |  
      | ^
a.cc:43:11: error: 'solve' was not declared in this scope
   43 | int ans = solve();
      |           ^~~~~
a.cc:44:1: error: 'count' does not name a type
   44 | count << ans << endl;
      | ^~~~~
a.cc:45:1: error: '\U000000a0' does not name a type
   45 |  
      | ^
a.cc:47:1: error: expected declaration before '}' token
   47 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;
int n, A[MAX], s;
int B[MAX], T[VMAX+1];
int solve(){
int ans = 0;
bool V[MAX];
for(int i = 0; i < n; i++){
B[i] = A[i];
V[i] = false;
}
sort(B, B+n);
for(int i = 0; i < n; i++) T[B[i]] = i;
for(int i = 0; i < n; i++){ 
if(V[i]) continue;
int cur = i;
int S = 0;
int m = VMAX;
int an = 0;
while(1){
V[cur] = true;
an++;
int v = A[cur];
m = min(m, v);
S += v;
if(V[cur]) break;
}
ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
}
return ans;
}
int main(){
cin >> n;
s = VMAX;
}
int ans = solve();
count << ans << endl;
return 0;
}


Compiler output:
a.cc:40:1: error: 'count' does not name a type
   40 | count << ans << endl;
      | ^~~~~
a.cc:41:1: error: expected unqualified-id before 'return'
   41 | return 0;
      | ^~~~~~
a.cc:42:1: error: expected declaration before '}' token
   42 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;
int n, A[MAX], s;
int B[MAX], T[VMAX+1];
int solve(){
int ans = 0;
bool V[MAX];
for(int i = 0; i < n; i++){
B[i] = A[i];
V[i] = false;
}
sort(B, B+n);
for(int i = 0; i < n; i++) T[B[i]] = i;
for(int i = 0; i < n; i++){ 
if(V[i]) continue;
int cur = i;
int S = 0;
int m = VMAX;
int an = 0;
while(1){
V[cur] = true;
an++;
int v = A[cur];
m = min(m, v);
S += v;
if(V[cur]) break;
}
ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
}
return ans;
}
int main(){
cin >> n;
s = VMAX;
}
int ans = solve();
cout << ans << endl;
return 0;
}


Compiler output:
a.cc:40:1: error: 'cout' does not name a type
   40 | cout << ans << endl;
      | ^~~~
a.cc:41:1: error: expected unqualified-id before 'return'
   41 | return 0;
      | ^~~~~~
a.cc:42:1: error: expected declaration before '}' token
   42 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;
int n, A[MAX], s;
int B[MAX], T[VMAX+1];
int solve(){
int ans = 0;
bool V[MAX];
for(int i = 0; i < n; i++){
B[i] = A[i];
V[i] = false;
}
sort(B, B+n);
for(int i = 0; i < n; i++) T[B[i]] = i;
for(int i = 0; i < n; i++){ 
if(V[i]) continue;
int cur = i;
int S = 0;
int m = VMAX;
int an = 0;
while(1){
V[cur] = true;
an++;
int v = A[cur];
m = min(m, v);
S += v;
cur = T[v]
if(V[cur]) break;
}
ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
}
return ans;
}
int main(){
cin >> n;
s = VMAX;
for(int i = 0; i < n; i++){
cin >> A[i]
s = min(s, A[i]
}
int ans = solve();
cout << ans << endl;
return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:29:11: error: expected ';' before 'if'
   29 | cur = T[v]
      |           ^
      |           ;
   30 | if(V[cur]) break;
      | ~~         
a.cc: In function 'int main()':
a.cc:40:12: error: expected ';' before 's'
   40 | cin >> A[i]
      |            ^
      |            ;
   41 | s = min(s, A[i]
      | ~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX_N 10000
#define MAX_V 100000000
#define INF 1000000000

int n, A[MAX_N], s, B[MAX_N], T[MAX_V];

int minimum_cost_sort() {
	int ans = 0;
	bool V[MAX_N];
	memset(V, false, sizeof(V));
	for (int i = 0; i < n; i++) { B[i] = A[i]; }
	sort(B, B + n);
	for (int i = 0; i < n; i++) { T[B[i]] = i; }
	for (int i = 0; i < n; i++) {
		if (V[i]) { goto owata; }
		int cur = i;
		int S = 0;
		int m = INF;
		int x = 0;
		while (1) {
			V[cur] = true;
			x++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur]) { break; }
		}
		ans += min(S + (x - 2)*m, m + S + (x + 1)*s);
	owata:;
	}
	return ans;
}

int main() {
	cin >> n;
	s = INF;
	for (int i = 0; i < n; i++){
		cin >> A[i];
		s = min(s, A[i]);
	}
	cout << minimum_cost_sort() << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int minimum_cost_sort()':
a.cc:34:9: error: jump to label 'owata'
   34 |         owata:;
      |         ^~~~~
a.cc:19:34: note:   from here
   19 |                 if (V[i]) { goto owata; }
      |                                  ^~~~~
a.cc:23:21: note:   crosses initialization of 'int x'
   23 |                 int x = 0;
      |                     ^
a.cc:22:21: note:   crosses initialization of 'int m'
   22 |                 int m = INF;
      |                     ^
a.cc:21:21: note:   crosses initialization of 'int S'
   21 |                 int S = 0;
      |                     ^
a.cc:20:21: note:   crosses initialization of 'int cur'
   20 |                 int cur = i;
      |                     ^~~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX_N 10000
#define MAX_V 100000000
#define INF 1000000000

int n, A[MAX_N], s, B[MAX_N], T[MAX_V];

int minimum_cost_sort() {
	int ans = 0;
	bool V[MAX_N];
	for (int i = 0; i < MAX_V; i++) { V[i] = false; }
	for (int i = 0; i < n; i++) { B[i] = A[i]; }
	sort(B, B + n);
	for (int i = 0; i < n; i++) { T[B[i]] = i; }
	for (int i = 0; i < n; i++) {
		if (V[i]) { goto owata; }
		int cur = i;
		int S = 0;
		int m = INF;
		int x = 0;
		while (1) {
			V[cur] = true;
			x++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur]) { break; }
		}
		ans += min(S + (x - 2)*m, m + S + (x + 1)*s);
	owata:;
	}
	return ans;
}

int main() {
	cin >> n;
	s = INF;
	for (int i = 0; i < n; i++){
		cin >> A[i];
		s = min(s, A[i]);
	}
	cout << minimum_cost_sort() << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int minimum_cost_sort()':
a.cc:34:9: error: jump to label 'owata'
   34 |         owata:;
      |         ^~~~~
a.cc:19:34: note:   from here
   19 |                 if (V[i]) { goto owata; }
      |                                  ^~~~~
a.cc:23:21: note:   crosses initialization of 'int x'
   23 |                 int x = 0;
      |                     ^
a.cc:22:21: note:   crosses initialization of 'int m'
   22 |                 int m = INF;
      |                     ^
a.cc:21:21: note:   crosses initialization of 'int S'
   21 |                 int S = 0;
      |                     ^
a.cc:20:21: note:   crosses initialization of 'int cur'
   20 |                 int cur = i;
      |                     ^~~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX_N 10000
#define MAX_V 100000000
#define INF 1000000000

int n, A[MAX_N], s, B[MAX_N], T[MAX_V];

int minimum_cost_sort() {
	int ans = 0;
	bool V[MAX_N];
	for (int i = 0; i < MAX_V; i++) { V[i] = false; }
	for (int i = 0; i < n; i++) { B[i] = A[i]; }
	sort(B, B + n);
	for (int i = 0; i < n; i++) { T[B[i]] = i; }
	for (int i = 0; i < n; i++) {
		if (V[i]==true) { goto owata; }
		int cur = i;
		int S = 0;
		int m = INF;
		int x = 0;
		while (1) {
			V[cur] = true;
			x++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur]) { break; }
		}
		ans += min(S + (x - 2)*m, m + S + (x + 1)*s);
	owata:;
	}
	return ans;
}

int main() {
	cin >> n;
	s = INF;
	for (int i = 0; i < n; i++){
		cin >> A[i];
		s = min(s, A[i]);
	}
	cout << minimum_cost_sort() << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int minimum_cost_sort()':
a.cc:34:9: error: jump to label 'owata'
   34 |         owata:;
      |         ^~~~~
a.cc:19:40: note:   from here
   19 |                 if (V[i]==true) { goto owata; }
      |                                        ^~~~~
a.cc:23:21: note:   crosses initialization of 'int x'
   23 |                 int x = 0;
      |                     ^
a.cc:22:21: note:   crosses initialization of 'int m'
   22 |                 int m = INF;
      |                     ^
a.cc:21:21: note:   crosses initialization of 'int S'
   21 |                 int S = 0;
      |                     ^
a.cc:20:21: note:   crosses initialization of 'int cur'
   20 |                 int cur = i;
      |                     ^~~
Language: C++

#include <map>
#include <queue>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int sorting(vector<short> v)
{
	map<vector<short>, int> d;
	
	vector<short> sorted(v.begin(), v.end());
	
	sort(v.begin(), v.end());
	
	queue<pair<vector<short>, int> > que;
	
	que.push(make_pair(v, 1)); d[v] = 1; // pair(vector, cost + 1)
	
	while(!que.empty())
	{
		vector<short> v1 = que.front().first;
		
		int cost = que.front().second; que.pop();
		
		for(int i = 0; i < v.size(); i++)
		{
		    for(int j = i + 1; j < v.size(); j++)
		    {
		        vector<short> v2(v1.begin(), v1.end());
		        
		        int cost2 = cost + v1[i] + v1[j];
		        
		        swap(v2[i], v2[j]);
		        
		        if(d[v2] == 0 || d[v2] > cost2)
		        {
		            d[v2] = cost2;
		            
		            que.push(make_pair(v2, cost2));
		        }
		    }
		}
	}
	
	return d[sorted] - 1;
}

int main()
{
	vector<short> v; int n;
	
	scanf("%d", &n); v = vector<short>(n);
	
	for(int i = 0; i < n; i++) { cin >> v[i]; }
	
	printf("%d\n", sorting(v));
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:57:38: error: 'cin' was not declared in this scope
   57 |         for(int i = 0; i < n; i++) { cin >> v[i]; }
      |                                      ^~~
a.cc:7:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    6 | #include <algorithm>
  +++ |+#include <iostream>
    7 |
Language: C++

const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'cin' was not declared in this scope
    6 |     cin.tie(0);
      |     ^~~
a.cc:7:5: error: 'ios' has not been declared
    7 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:10:5: error: 'map' was not declared in this scope
   10 |     map<int, int> mp;
      |     ^~~
a.cc:10:9: error: expected primary-expression before 'int'
   10 |     map<int, int> mp;
      |         ^~~
a.cc:13:9: error: 'mp' was not declared in this scope
   13 |         mp[w[i]] = 0;
      |         ^~
a.cc:14:16: error: 'min' was not declared in this scope; did you mean 'mini'?
   14 |         mini = min(mini, w[i]);
      |                ^~~
      |                mini
a.cc:18:24: error: 'mp' was not declared in this scope; did you mean 'p'?
   18 |         for (auto& p : mp) p.second = k++;
      |                        ^~
      |                        p
a.cc:28:18: error: 'min' was not declared in this scope; did you mean 'mi'?
   28 |             mi = min(mi, w[now]);
      |                  ^~~
      |                  mi
a.cc:30:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   30 |             now = mp[w[now]];
      |                   ^~
      |                   mi
a.cc:33:15: error: 'min' was not declared in this scope; did you mean 'mi'?
   33 |         tmp = min(tmp, sum+mi+mini*(cnt+1));
      |               ^~~
      |               mi
a.cc:36:5: error: 'cout' was not declared in this scope
   36 |     cout << ans << endl;
      |     ^~~~
a.cc:36:20: error: 'endl' was not declared in this scope
   36 |     cout << ans << endl;
      |                    ^~~~
Language: C++

const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int void main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:5:1: error: two or more data types in declaration of 'main'
    5 | int void main() {
      | ^~~
Language: C++

#include<iostream>
using namespace std;
const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:5: error: 'map' was not declared in this scope
   12 |     map<int, int> mp;
      |     ^~~
a.cc:2:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    1 | #include<iostream>
  +++ |+#include <map>
    2 | using namespace std;
a.cc:12:9: error: expected primary-expression before 'int'
   12 |     map<int, int> mp;
      |         ^~~
a.cc:15:9: error: 'mp' was not declared in this scope
   15 |         mp[w[i]] = 0;
      |         ^~
a.cc:20:24: error: 'mp' was not declared in this scope; did you mean 'p'?
   20 |         for (auto& p : mp) p.second = k++;
      |                        ^~
      |                        p
a.cc:32:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   32 |             now = mp[w[now]];
      |                   ^~
      |                   mi
Language: C++

#include<iostream>
#incldue<map>
using namespace std;
const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #incldue; did you mean #include?
    2 | #incldue<map>
      |  ^~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:13:5: error: 'map' was not declared in this scope
   13 |     map<int, int> mp;
      |     ^~~
a.cc:2:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    1 | #include<iostream>
  +++ |+#include <map>
    2 | #incldue<map>
a.cc:13:9: error: expected primary-expression before 'int'
   13 |     map<int, int> mp;
      |         ^~~
a.cc:16:9: error: 'mp' was not declared in this scope
   16 |         mp[w[i]] = 0;
      |         ^~
a.cc:21:24: error: 'mp' was not declared in this scope; did you mean 'p'?
   21 |         for (auto& p : mp) p.second = k++;
      |                        ^~
      |                        p
a.cc:33:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   33 |             now = mp[w[now]];
      |                   ^~
      |                   mi
Language: C++

#include<iostream>
#incldue<map>
using namespace std;
const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #incldue; did you mean #include?
    2 | #incldue<map>
      |  ^~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:13:5: error: 'map' was not declared in this scope
   13 |     map<int, int> mp;
      |     ^~~
a.cc:2:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    1 | #include<iostream>
  +++ |+#include <map>
    2 | #incldue<map>
a.cc:13:9: error: expected primary-expression before 'int'
   13 |     map<int, int> mp;
      |         ^~~
a.cc:16:9: error: 'mp' was not declared in this scope
   16 |         mp[w[i]] = 0;
      |         ^~
a.cc:29:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   29 |             now = mp[w[now]];
      |                   ^~
      |                   mi
Language: C++

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private int[] a;
	private int[] b;
	
	private Scanner sc;

	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		int lim = Integer.parseInt(sc.nextLine());
		
		a = new int[lim];		
		b = new int[lim];
		for (int i = 0; i < lim; i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = a[i];
		}
		Arrays.sort(b);
		
		int ans = 0;
		for (int i = 0; i < lim; i++) {
			if (a[i] != b[i]) {
				for (int j = (i + 1); j < lim; j++) {
					if ((a[j] == b[i]) && (a[i] == b[j])) {
						a[i] = b[i];
						a[j] = b[j];
						
						ans = ans + a[i] + a[j];
					}
				}
			}
		}
		
		System.out.print(ans);
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.Arrays;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.Scanner;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main {
      | ^~~~~~
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

const int INF = 1000000;

struct node
{
	int num;
	int place;  
};

int partition(node *A,int p,int r)
{
	int j,temp;
	node x;

	x = A[r];
	j = p-1;

	for(int i = p; i < r; i++)
	{
		if (A[i].num <= x.num)
		{
			j++;
			temp = A[i].num;
			A[i].num = A[j].num;
			A[j].num = temp;
		}
	}

	temp = A[j+1].num;
	A[j+1].num = A[r].num;
	A[r].num = temp;

	return j+1;
}

void quicksort(node *A,int p,int r)
{
	int q;

	if (p < r)
	{
		q = partition(A,p,r);
		quicksort(A,p,q-1);
		quicksort(A,q+1,r);
	}
}


int main()
{
	int n,sum,minall,mini,sol,cnt,j;
	node a[1000] = {0},b[1000] = {0};

	sol = 0;
	minall = INF;

	scanf("%d", &n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i].num);
		a[i].place = i;
		b[i] = a[i];
		b[i].place = i;
	}

	quicksort(b,0,n-1);

	for(int i = 0; i < n; i++)
	{
		sum = 0;

		if (a[i].num >= 0)
		{
			sum += a[i].num;
			mini = a[i].num;
			cnt = 1;
			j = i;

			while(b[a[j].place].num != a[i].num)
			{
				for(int k = 0; k < n; k++)
				{
					if (a[k].num == b[a[j].place].num)
					{
						j = k;
						sum += a[k].num;
						cnt++;

						if (mini > a[k].num)
						{
							mini = a[k].num;
						}

						a[k].num = -1;
						break;
					}
				}
			}

			a[i].num = -1;

			sol += min(sum + mini * (cnt -2), sum + mini + (cnt + 1) * b[0]);
		}
	}

	printf("%d\n", sol);


	return 0;
}
	

Compiler output:
a.cc: In function 'int main()':
a.cc:109:82: error: no match for 'operator*' (operand types are 'int' and 'node')
  109 |                         sol += min(sum + mini * (cnt -2), sum + mini + (cnt + 1) * b[0]);
      |                                                                        ~~~~~~~~~ ^ ~~~~
      |                                                                             |         |
      |                                                                             int       node
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int silly_sort(vector<int> v, int n){
	vector<pair<int, int> > temp(n);
	for (int i = 0; i < n; i++){
		temp[i].first = v[i];
		temp[i].second = i;
	}
	sort(temp.begin(), temp.end());

	int cost = 0, s = temp[0].first;
	for (int i = 0; i < n; i++){
		int j = temp[i].second;
		if (j != i && j >= 0){
			int n = 1, amin, sum;
			amin = sum = temp[i].first;
			while (j != i){
				int next = temp[j].second;
				sum += temp[j].first;
				n++;
				temp[j].second = -1;
				j = next;
			}
			cost += min(sum + (n - 2) * amin, sum + amin + (n + 1) * s);
		}
	}
	return cost;
}

void main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	cout << silly_sort(v, n) << endl;
}

Compiler output:
a.cc:34:1: error: '::main' must return 'int'
   34 | void main(){
      | ^~~~
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
	int ans = 0;
	
	bool V[VMAX];
	for(int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for(int i = 0; i < n; i++) T[B[i]] = i;
	for(int i = 0; i < n; i++) {
		if( V[i] ) continue;
		int cur = i;
		int S = 0;
		int as = 1;
		int m = VMAX;
		while(1) {
			V[cur] = false;
			an++;
			int v = A[cur];
			m = min(m, v);
			s += v;
			cur = T[v];
			if( V[cur] ) break;			
		}
		ans += min(S + (an - 2) * m, S + m +(an + 1) * s);
	}
	
	return ans;
} 

int main() {
	cin >> n;
	s = VMAX;
	for(int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	int ans = solve();
	cout << ans << endl;
	
	return 0;
}
 

Compiler output:
a.cc: In function 'int solve()':
a.cc:28:25: error: 'an' was not declared in this scope; did you mean 'as'?
   28 |                         an++;
      |                         ^~
      |                         as
a.cc:35:33: error: 'an' was not declared in this scope; did you mean 'as'?
   35 |                 ans += min(S + (an - 2) * m, S + m +(an + 1) * s);
      |                                 ^~
      |                                 as
Language: C++

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

bool cmp(const int n1, const int n2) {
	return n1 < n2;
}

struct Data {
	int num;
	int i;
};

int main() {
	int n;
	int minValue = INT_MAX;
	int sortAry[1000];
	Data ary[1000];
	vector<vector<int>> groups;
	int cost = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sortAry[i] = ary[i].num = temp;
		minValue = min(minValue, temp);
	}

	sort(sortAry, sortAry + n, cmp);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ary[i].num == sortAry[j]) {
				ary[i].i = j;
				break;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		vector<int> group;
		int j = i;
		int s = i;
		while (j != ary[j].i) {
			group.push_back(ary[j].num);

			int temp = ary[j].i;
			ary[j].i = j;
			j = temp;
		}
		if (!group.empty()) {
			groups.push_back(group);
		}
	}

	for (int i = 0; i < groups.size(); i++) {
		int sum = 0;
		int m = INT_MAX;
		int num = groups[i].size();

		for (int j = 0; j < num; j++) {
			sum += groups[i][j];
			m = min(groups[i][j], m);
		}

		int c1, c2;
		c1 = sum + (num - 2) * m;
		c2 = sum + (num + 1) * minValue + m;
		cost += min(c1, c2);
	}

	cout << cost << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:24: error: 'INT_MAX' was not declared in this scope
   17 |         int minValue = INT_MAX;
      |                        ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include<vector>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include <iostream>

using namespace std;

static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve() {
    int ans = 0;

    bool V[MAX];
    for (int i = 0; i < n; ++i) {
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B + n);
    for (int i = 0; i < n; ++i) {
        T[B[i]] = i;
    }
    for (int i = 0; i < n; ++i) {
        if (V[i]) {
            continue;
        }
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while (true) {
            V[cur] = true;
            ++an;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) {
                break;
            }
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    
    return ans;
}

int main() {
    scanf("%d", &n);
    s = VMAX;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        s = min(s, A[i]);
    }
    int ans = solve();
    printf("%d\n", ans);    

    return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:19:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   19 |     sort(B, B + n);
      |     ^~~~
      |     short
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve(){
	int ans = 0;

	bool V[MAX];
	for (int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for (int i = 0; i < n; i++)T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		if (V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S+= v;
			cur = T[[v];
			if (V[cur])break;
		}
		ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
	}

	return ans;
}

int main() {
	cin >> n;
	s = VMAX;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	int ans = solve();
	cout << ans << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:32:32: error: two consecutive '[' shall only introduce an attribute before '[' token
   32 |                         cur = T[[v];
      |                                ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve(){
	int ans = 0;

	bool V[MAX];
	for (int i = 0; i < n; i++) {
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	for (int i = 0; i < n; i++)T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		if (V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while (1) {
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			{
			cur = T[[v];
			if (V[cur])break;
		}
		ans += min(S + (an - 2)*m, m + S + (an + 1)*s);
	}

	return ans;
}

int main() {
	cin >> n;
	s = VMAX;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		s = min(s, A[i]);
	}
	int ans = solve();
	cout << ans << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:33:32: error: two consecutive '[' shall only introduce an attribute before '[' token
   33 |                         cur = T[[v];
      |                                ^
a.cc:42:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   42 | int main() {
      |         ^~
a.cc:42:9: note: remove parentheses to default-initialize a variable
   42 | int main() {
      |         ^~
      |         --
a.cc:42:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:42:12: error: a function-definition is not allowed here before '{' token
   42 | int main() {
      |            ^
a.cc:53:2: error: expected '}' at end of input
   53 | }
      |  ^
a.cc:10:12: note: to match this '{'
   10 | int solve(){
      |            ^
a.cc:53:2: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      |  ^
Language: C++

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define MAX_NUM 1000

int W[MAX_NUM];
int N;

int Compare(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

void Swap(int idx1, int idx2) {
	int tmp = W[idx1];
	W[idx1] = W[idx2];
	W[idx2] = tmp;
}

int SearchIdx(int wi)
{	
	for (int i = 0; i < N; i++) {
		if (W[i] == wi) {
			return i;
		}
	}
	return -1;
}

int main(void)
{
	//input
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}

	//minimum cost?
	int cost = 0;
	int w2[MAX_NUM];
	memcpy(w2, W, sizeof(int) * N);
	qsort(w2, N, sizeof(int), Compare);
	for (int i = 0; i < N; i++) {
		int idx1 = SearchIdx(w2[i]);
		if (idx1 == -1) return -1;
		while (idx1 != i) {
			int idx2 = SearchIdx(w2[idx1]);
			Swap(idx1, idx2);
			cost = cost + W[idx1] + W[idx2];
			idx1 = idx2;
		}
	}

	//output
	cout << cost << "\n";
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:9: error: 'memcpy' was not declared in this scope
   43 |         memcpy(w2, W, sizeof(int) * N);
      |         ^~~~~~
a.cc:4:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <stdlib.h>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define MAX_NUM 1000

int W[MAX_NUM];
int N;

int Compare(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

void Swap(int idx1, int idx2) {
	int tmp = W[idx1];
	W[idx1] = W[idx2];
	W[idx2] = tmp;
}

int SearchIdx(int wi)
{	
	for (int i = 0; i < N; i++) {
		if (W[i] == wi) {
			return i;
		}
	}
	return -1;
}

int main(void)
{
	//input
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}

	//minimum cost?
	int cost = 0;
	int w2[MAX_NUM];
	memcpy(w2, W, sizeof(int) * N);
	qsort(w2, N, sizeof(int), Compare);
	for (int i = 0; i < N; i++) {
		int idx1 = SearchIdx(w2[i]);
		while (idx1 != i) {
			int idx2 = SearchIdx(w2[idx1]);
			Swap(idx1, idx2);
			cost = cost + W[idx1] + W[idx2];
			idx1 = idx2;
		}
	}

	//output
	cout << cost << "\n";
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:9: error: 'memcpy' was not declared in this scope
   43 |         memcpy(w2, W, sizeof(int) * N);
      |         ^~~~~~
a.cc:4:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <stdlib.h>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, mini = 100000;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        mp[w[i]] = 0;
        mini = min(mini, w[i]);
    }
    {
        int k = 0;
        for (auto& p : mp) p.second = k++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int cnt = 0, now = i, mi = 100000, sum = 0;
        while (1) {
            if (done[now]) break;
            cnt++;
            done[now] = true;
            mi = min(mi, w[now]);
            sum += w[now];
            now = mp[w[now]];
        }
        int tmp = sum+(cnt-2)*mi;
        tmp = min(tmp, sum+mi+mini*(cnt+1));
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'cin' was not declared in this scope
    6 |     cin.tie(0);
      |     ^~~
a.cc:7:5: error: 'ios' has not been declared
    7 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:10:5: error: 'map' was not declared in this scope
   10 |     map<int, int> mp;
      |     ^~~
a.cc:10:9: error: expected primary-expression before 'int'
   10 |     map<int, int> mp;
      |         ^~~
a.cc:13:9: error: 'mp' was not declared in this scope
   13 |         mp[w[i]] = 0;
      |         ^~
a.cc:14:16: error: 'min' was not declared in this scope; did you mean 'mini'?
   14 |         mini = min(mini, w[i]);
      |                ^~~
      |                mini
a.cc:18:24: error: 'mp' was not declared in this scope; did you mean 'p'?
   18 |         for (auto& p : mp) p.second = k++;
      |                        ^~
      |                        p
a.cc:28:18: error: 'min' was not declared in this scope; did you mean 'mi'?
   28 |             mi = min(mi, w[now]);
      |                  ^~~
      |                  mi
a.cc:30:19: error: 'mp' was not declared in this scope; did you mean 'mi'?
   30 |             now = mp[w[now]];
      |                   ^~
      |                   mi
a.cc:33:15: error: 'min' was not declared in this scope; did you mean 'mi'?
   33 |         tmp = min(tmp, sum+mi+mini*(cnt+1));
      |               ^~~
      |               mi
a.cc:36:5: error: 'cout' was not declared in this scope
   36 |     cout << ans << endl;
      |     ^~~~
a.cc:36:20: error: 'endl' was not declared in this scope
   36 |     cout << ans << endl;
      |                    ^~~~
Language: C++

let quick_sort a n cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let i = ref p in
    for j = p to r - 1 do
      if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i)
    done;
    swap !i r;
    !i in
  let rec doit p r =
    if p >= r then () else
    let q = partition p r in
    doit p (q - 1);
    doit (q + 1) r in
  doit 0 (n - 1)

let calc_cost a n =
  let b = Array.copy a in
  quick_sort b n compare;
  let t = Array.make (b.(n-1) + 1) 0 in
  Array.iteri (fun i e -> t.(e) <- i) b;
  let p = Array.make n false in
  let rec cycle i acc =
    p.(i) <- true;
    let j = t.(a.(i)) in
    if p.(j) then a.(i) :: acc
    else cycle j (a.(i) :: acc) in
  let cycle i = cycle i [] in
  let rec doit i acc =
    if i = n then acc
    else if p.(i) then doit (i + 1) acc
    else
      let ws = cycle i in
      let m = List.length ws in
      let s = List.fold_left (+) 0 ws in
      let z = List.fold_left min max_int ws in
      doit (i + 1) (acc + (min (s + (m - 2)*z) (s + z + (m + 1)*b.(0)))) in
  doit 0 0

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  calc_cost a n |> Printf.printf "%d\n"


Compiler output:
a.cc:1:1: error: 'let' does not name a type
    1 | let quick_sort a n cmp =
      | ^~~
a.cc:2:53: error: 'a' does not name a type
    2 |   let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
      |                                                     ^
a.cc:6:48: error: 'incr' does not name a type
    6 |       if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i)
      |                                                ^~~~
a.cc:8:5: error: 'swap' does not name a type
    8 |     swap !i r;
      |     ^~~~
a.cc:9:5: error: expected unqualified-id before '!' token
    9 |     !i in
      |     ^
a.cc:14:10: error: expected constructor, destructor, or type conversion before '(' token
   14 |     doit (q + 1) r in
      |          ^
a.cc:20:3: error: 'let' does not name a type
   20 |   let t = Array.make (b.(n-1) + 1) 0 in
      |   ^~~
a.cc:22:3: error: 'let' does not name a type
   22 |   let p = Array.make n false in
      |   ^~~
a.cc:25:5: error: 'let' does not name a type
   25 |     let j = t.(a.(i)) in
      |     ^~~
Language: C++

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
#define N 40

bool comp1(const pair<int, int> &a, const pair<int, int> &b)
{
    return a.first < b.first;
}
bool comp2(const pair<int, int> &a, const pair<int, int> &b)
{
    return a.second < b.second;
}
int main()
{
    int n;
    cin >> n;
    int w[n], x[n];
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        x[i] = w[i];
    }

    sort(x, x + n);
    for (int i = 0; i < n; i++)
    {
        if (i != 0)
            cout << " ";
        cout << x[i];
    }
    cout << endl;
    int *p, *q;
    int sum = 0, tmp;
 }
    for (int i = 0; i < n; i++)
    {
        p = find(w, w + n, x[i]);
        while (i != p - w)
        {
            q = find(w, w + n, x[p - w]);
            tmp = *p;
            *p = *q;
            *q = tmp;
            sum += *p + *q;
            p = q;
        }
    }

    cout << sum << "\n";
    return 0;
}


Compiler output:
a.cc:39:5: error: expected unqualified-id before 'for'
   39 |     for (int i = 0; i < n; i++)
      |     ^~~
a.cc:39:21: error: 'i' does not name a type
   39 |     for (int i = 0; i < n; i++)
      |                     ^
a.cc:39:28: error: 'i' does not name a type
   39 |     for (int i = 0; i < n; i++)
      |                            ^
a.cc:53:5: error: 'cout' does not name a type
   53 |     cout << sum << "\n";
      |     ^~~~
a.cc:54:5: error: expected unqualified-id before 'return'
   54 |     return 0;
      |     ^~~~~~
a.cc:55:1: error: expected declaration before '}' token
   55 | }
      | ^
Language: C++

#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MAX 1000
#define VMAX 10000
typedef long long ll;
using namespace std;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve(){
  int ans=0;

  bool V[MAX];
  for (size_t i = 0; i < n; i++) {
    B[i]=A[i];
    V[i]=false;
  }
  sort(B.begin(), B.end());

  for (size_t i = 0; i < n; i++) T[B[i]]=i;
  for (size_t i = 0; i < n; i++) {
    if (V[i]) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int A_n = 0;
    while (1) {
      V[cur] = true;
      A_n++;
      int v = A[cur];
      m = min(m, v);
      S += v;
      cur = T[v];
      if (V[cur]) break;
    }
    ans += min(S + (A_n-2) * m, S + m + (A_n + 1)*s );
  }

  
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  std::cin >> n;
  s = VMAX;

  for (size_t i = 0; i < n; i++) {
    std::cin >> A[i];
    s = min(s, A[i]);
  }
  int cost = solve();

  std::cout << cost << '\n';

  return 0;
}



Compiler output:
a.cc: In function 'int solve()':
a.cc:28:10: error: request for member 'begin' in 'B', which is of non-class type 'int [1000]'
   28 |   sort(B.begin(), B.end());
      |          ^~~~~
a.cc:28:21: error: request for member 'end' in 'B', which is of non-class type 'int [1000]'
   28 |   sort(B.begin(), B.end());
      |                     ^~~
a.cc:50:1: warning: no return statement in function returning non-void [-Wreturn-type]
   50 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 10000;
static const int VMAX = 100000;

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

int solve(){
    int i,ans = 0;
    
    bool V[MAX];
    for(i=0;i<n;i++){
        B[i] = A[i];
        V[i] = false;
    }
    sort(B,B+n);
    for(i=0;i<n;i++) T[B[i]] = i;
    for(i=0;i<n;i++){
        if(V[i]) continue;
        int cur=i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while(1){
            V[cur] = true;
            an++
            int v=A[cur];
            m = min(m,v);
            S+=v;
            cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}

int main(){
    int i;
    cin>>n;
    s=VMAX;
    for(i=0;i<n;i++){
        cin>>A[i];
        s=min(s,A[i]);
    }
    int ans = solve();
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:28:17: error: expected ';' before 'int'
   28 |             an++
      |                 ^
      |                 ;
   29 |             int v=A[cur];
      |             ~~~  
a.cc:30:23: error: 'v' was not declared in this scope
   30 |             m = min(m,v);
      |                       ^
Language: Java

mport java.util.Scanner;
public class Main{
 static int[][] tree;
 static int[]par;
	public static void main(String[] args) {
	int x,i,j,n,pn,swi=0,root = 0;
	// TODO Auto-generated method stub
     Scanner sca = new Scanner(System.in);
     n=sca.nextInt();
     tree = new int[n][n+1];
     par=new int[n];
    for(j=0;j<n;j++){
    	x=sca.nextInt();
	if(j==0)root=x;
    	tree[x][n]=pn=sca.nextInt();
    	for(i=0;i<pn;i++) {
    		tree[x][i]=sca.nextInt();
    	}
    	if(swi==0&&pn!=0){
    		swi=-1;
    		root=x;
    	}
    }
    chain(root,n,-1);
     for(i=0;i<n;i++){
    	 System.out.print("node "+i+": parent ="+ par[i]+", depth = "+serdepth(i,0)+", ");
    	if(par[i]==-1){
    	System.out.print("root, [");
    	}else if(tree[i][n]==0){
    	 System.out.print("leaf, [");
    	}else{
    		System.out.print("internal node, [");
    	}
    	for(j=0;j<tree[i][n]-1;j++){
    		System.out.print(tree[i][j]+", ");
    	}
   if(tree[i][n]!=0){
	   System.out.println(tree[i][j]+"]");
   }else{
	   System.out.println("]");	   
   }
  }
	}
    public static void chain(int chi,int n,int p){
	int i;
	 par[chi]=p;
	if(tree[chi][n]==0)return;
	for(i=0;i<tree[chi][n];i++){
	    chain(tree[chi][i],n,chi);
	}
	}
	public static int serdepth(int x,int cnt){
		if(par[x]==-1)return cnt;
		cnt++;
		return serdepth(par[x],cnt);
	}
}


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
mport java.util.Scanner;
^
1 error