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

#include<iostream>

using namespace std;

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1].value = R[n2].value = SENTINEL;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
   
void mergeSort(struct Card A[], int left, int right){
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  struct Card x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j].value <= x.value) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

void quickSort(struct Card 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() {
  struct Card A[MAX], B[MAX];

  int N;
  cin >> N;

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i].suit >> A[i].value;
    B[i] = A[i];
  }

  mergeSort(A, 0, N);
  quickSort(A, 0, N - 1);

  bool stable = true;

  for (int i = 0; i < N; i++) {
    if (A[i].suit != B[i].suit) {
      stable = false;
    }
  }

  if (stable) {
    cout << "Stable" << endl;
  } else {
    cout << "Not Stable" << endl;
  }
  for (int i = 0; i < N; i++) {
    cout << B[i].suit << " " << B[i].value << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'void merge(Card*, int, int, int)':
a.cc:28:5: error: 'cnt' was not declared in this scope; did you mean 'int'?
   28 |     cnt++;
      |     ^~~
      |     int
a.cc: In function 'void quickSort(Card*, int, int)':
a.cc:64:27: error: expected ';' before '}' token
   64 |     quickSort(A, q + 1, r)
      |                           ^
      |                           ;
   65 |   }
      |   ~                        
a.cc: In function 'int main()':
a.cc:74:7: error: conflicting declaration 'int A [N]'
   74 |   int A[N];
      |       ^
a.cc:69:15: note: previous declaration as 'Card A [100000]'
   69 |   struct Card A[MAX], B[MAX];
      |               ^
Language: C++

#include<iostream>

using namespace std;

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1].value = R[n2].value = SENTINEL;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    if (L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
   
void mergeSort(struct Card A[], int left, int right){
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  struct Card x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j].value <= x.value) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

void quickSort(struct Card 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() {
  struct Card A[MAX], B[MAX];

  int N;
  cin >> N;

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i].suit >> A[i].value;
    B[i] = A[i];
  }

  mergeSort(A, 0, N);
  quickSort(A, 0, N - 1);

  bool stable = true;

  for (int i = 0; i < N; i++) {
    if (A[i].suit != B[i].suit) {
      stable = false;
    }
  }

  if (stable) {
    cout << "Stable" << endl;
  } else {
    cout << "Not Stable" << endl;
  }
  for (int i = 0; i < N; i++) {
    cout << B[i].suit << " " << B[i].value << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'void quickSort(Card*, int, int)':
a.cc:63:27: error: expected ';' before '}' token
   63 |     quickSort(A, q + 1, r)
      |                           ^
      |                           ;
   64 |   }
      |   ~                        
a.cc: In function 'int main()':
a.cc:73:7: error: conflicting declaration 'int A [N]'
   73 |   int A[N];
      |       ^
a.cc:68:15: note: previous declaration as 'Card A [100000]'
   68 |   struct Card A[MAX], B[MAX];
      |               ^
Language: C++


#include<iostream>

using namespace std;

#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1].value = R[n2].value = SENTINEL;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    if (L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
   
void mergeSort(struct Card A[], int left, int right){
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  struct Card x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j].value <= x.value) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

void quickSort(struct Card 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() {
  struct Card A[MAX], B[MAX];

  int N;
  cin >> N;

  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i].suit >> A[i].value;
    B[i] = A[i];
  }

  mergeSort(A, 0, N);
  quickSort(A, 0, N - 1);

  bool stable = true;

  for (int i = 0; i < N; i++) {
    if (A[i].suit != B[i].suit) {
      stable = false;
    }
  }

  if (stable) {
    cout << "Stable" << endl;
  } else {
    cout << "Not Stable" << endl;
  }
  for (int i = 0; i < N; i++) {
    cout << B[i].suit << " " << B[i].value << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:7: error: conflicting declaration 'int A [N]'
   74 |   int A[N];
      |       ^
a.cc:69:15: note: previous declaration as 'Card A [100000]'
   69 |   struct Card A[MAX], B[MAX];
      |               ^
Language: C++

#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  struct Card t;
  struct Card x = A[r].value;
  int i = p - 1;
  for ( int j = p; j < r; j++ ) {
    if ( A[j].value < x ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i++;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, n, p, r);
    partition(A, n, p, q - 1);
    partition(A, n, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n - 1);

  for ( i = 0; i < n; i++ ) {
    if ( A[i].suit != B[i].suit ) stable = 0;
  } 

  if ( stable == 1) print("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}


Compiler output:
a.cc: In function 'int partition(Card*, int, int, int)':
a.cc:41:24: error: conversion from 'int' to non-scalar type 'Card' requested
   41 |   struct Card x = A[r].value;
      |                   ~~~~~^~~~~
a.cc:44:21: error: no match for 'operator<' (operand types are 'int' and 'Card')
   44 |     if ( A[j].value < x ) {
      |          ~~~~~~~~~~ ^ ~
      |               |       |
      |               int     Card
a.cc: In function 'int main()':
a.cc:83:21: error: 'print' was not declared in this scope; did you mean 'printf'?
   83 |   if ( stable == 1) print("Stable\n");
      |                     ^~~~~
      |                     printf
Language: C++

#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  struct Card t;
  struct Card x = A[r];
  int i = p - 1;
  for ( int j = p; j < r; j++ ) {
    if ( A[j].value < x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i++;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, n, p, r);
    partition(A, n, p, q - 1);
    partition(A, n, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n - 1);

  for ( i = 0; i < n; i++ ) {
    if ( A[i].suit != B[i].suit ) stable = 0;
  } 

  if ( stable == 1) print("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:83:21: error: 'print' was not declared in this scope; did you mean 'printf'?
   83 |   if ( stable == 1) print("Stable\n");
      |                     ^~~~~
      |                     printf
Language: C++

#include <stdio.h>
#define MAX 100000
#define INF 1<<30

struct Card {
    char suit;
    int value;
};

void merge(struct Card A[], int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    
    struct Card L[n1+1], R[n2+1];
    for(int i=0; i<n1; i++) L[i].value = A[left + i].value;
    for(int i=0; i<n2; i++) R[i].value = A[mid + i].value;
    L[n1].value = R[n2].value = INF;
    
    int i=0, j=0;
    for (int k=left; k<right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(struct Card *A, int left, int right) {
    if(left+1 < right) {
        int mid = (left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(struct Card *A, int p, int r) {
    struct Card x;
    x = A[r];
    int i = p-1;
    for (int j=p; j<r; j++) {
        if(A[j].value <= x.value) {
            i++;
            struct Card tmp=A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
    }
    struct Card tmp;
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    
    return i+1;
}

void quickSort(struct Card 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, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for (int i=0; i<n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }
    
    mergeSort(A, 0, n);
    mergeSort(B, 0, n-1);
    
    for (int i=0; i<n; i++) {
        if(A[i].suit != B[i].suit) stable=0;
    }
    
    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");
    for (int i=0; i<n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    printf("\n");
    return 0;
}


Compiler output:
a.cc: In function 'void merge(Card*, int, int, int)':
a.cc:20:9: error: redeclaration of 'int i'
   20 |     int i=0, j=0;
      |         ^
a.cc:11:9: note: 'int i' previously declared here
   11 |     int i, j, k;
      |         ^
a.cc:20:14: error: redeclaration of 'int j'
   20 |     int i=0, j=0;
      |              ^
a.cc:11:12: note: 'int j' previously declared here
   11 |     int i, j, k;
      |            ^
Language: Java

import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

public static void main(Stirng[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] w=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) w[i]=Integer.parseInt(st.nextToken());
int[] wd=w.clone();
Arrays.sort(wd);
int ans=0;
for(int i=0;i<=n/2;i++){
if(w[i]!=wd[i]) ans+=w[i]+wd[i];
}
out.println(ans);
}
out.flush();
}
}

Compiler output:
Main.java:9: error: cannot find symbol
public static void main(Stirng[] args) throws IOException{
                        ^
  symbol:   class Stirng
  location: class Main
1 error
Language: Java

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main2 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		// ??°?????????????????¨?????????????????????????????????????????????????´????????????????????????????????????????
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int n = scanner.nextInt();
		int count = 0;
		int[] list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scanner.nextInt();
		}
		int[] sortedList = (int[]) list.clone();
		// ???????????????????´???°???????????????????????????????????????????????????????????????????????????
		mergeSort(sortedList, 0, n);
		// ??????????????????????????¨?????????????´????????´??????????????????????
		for (int i = 0; i < n; i++) {
			map.put(sortedList[i], i);
		}
		boolean flag = true;
		int time = 1;
		// ????????¨
		do{
			int temp3 = -1;
			int index2 = 0;
		for (int i = 0; i < n; i++) {
			if (i != map.get(list[i]) && temp3 < list[i]) {
					//??????????????§?????£??°???????´???????????????????????´????????????????
					temp3 = map.get(list[i]);
					index2 = i;
				}
			}
		int temp = list[index2];
		int ind = map.get(list[index2]);
		int temp2 = list[ind];
		list[index2] = temp2;
		list[ind] = temp;
		count = count + temp + temp2;
		//System.out.println(temp + "??¨" + temp2 +"?????????" + time+ "??????");
		//time++;
		flag = true;
		for(int i = 0; i < n; i++){
			if(i != map.get(list[i])){
				flag = false;
			}
		}
		}while(flag != true);
		System.out.println(count);
	}
	
	static void merge(int[] numList, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];

		for (int i = 0; i < n1; i++) {
			L[i] = numList[left + i];
		}

		for (int i = 0; i < n2; i++) {
			R[i] = numList[mid + i];
		}

		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		// L??¨R??????????????????????°????????????????numList???????´??????????
		// ?°?????????????????????????????????????????¬??????????????????????????????????????´????????????????????????°?????????+1?????????
		for (int k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				numList[k] = L[i];
				i = i + 1;
			} else {
				numList[k] = R[j];
				j = j + 1;
			}
		}
	}

	// ????¨????merge???????????????????±??????????????°?????´???????(left)??¨?????§????´???????(right)?????????-1??????????????§??°????????????
	static void mergeSort(int[] numList, int left, int right) {
		if ((left + 1) < right) {
			int mid = (left + right) / 2;

			mergeSort(numList, left, mid);
			// System.out.println("???");
			mergeSort(numList, mid, right);
			// System.out.println("???");
			merge(numList, left, mid, right);
		}
	}
}

Compiler output:
Main.java:5: error: class Main2 is public, should be declared in a file named Main2.java
public class Main2 {
       ^
1 error
Language: Java

import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new Bufferedreader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] W = new int[n];
		String[] in = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			W[i] = Integer.parseInt(in[i]);
		}
		System.out.printf("%d\n", minCostSort(W));
	}

	public static int indexOf(int[] A, int x){
		for(int i = 0; i < A.length; i++){
			if(A[i] == x){
				return i;
			}
		}
		return -1;
	}

	public static int minCostSort(int[] W){
		int[] sorted = W.clone();
		Arrays.sort(sorted);
		int cost = 0;
		for(int i = 0; i < W.length; i++){
			int a = indexOf(W, sorted[i]);
			int j = 0;
			while(a > i){
				j++;
				int b = indexOf(W, sorted[a]);
				cost += W[b];
				int work = W[a];
				W[a] = W[b];
				W[b] = work;
				a = b;
			}
			cost += Math.min(sorted[i] * j, sorted[i] * 2 + sorted[0] * (j+2));
		}
		return cost;
	}
}

Compiler output:
Main.java:7: error: cannot find symbol
		BufferedReader br = new Bufferedreader(new InputStreamReader(System.in));
		                        ^
  symbol:   class Bufferedreader
  location: class Main
Main.java:28: error: cannot find symbol
		Arrays.sort(sorted);
		^
  symbol:   variable Arrays
  location: class Main
2 errors
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[MAX+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() {
  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:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
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 (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() {
  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:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
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 (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() {
  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:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>
#define MAX  1000
#define VMAX 10000

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

int min(int a,int b){
  if(a>b) return b;
  else return a;
}

int partition(int A[],int p,int r){
  int i,j;
  int t,x;
  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}
void quickSort(int 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 solve(){
  int ans=0,i,cur,S,m,an,V;

  int V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(b,0,n-1);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = VMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      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;

  scanf("%d", &n);
  
  s = VMAX;
  for(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:
main.c: In function 'solve':
main.c:47:7: error: conflicting types for 'V'; have 'int[1000]'
   47 |   int V[MAX];
      |       ^
main.c:45:26: note: previous declaration of 'V' with type 'int'
   45 |   int ans=0,i,cur,S,m,an,V;
      |                          ^
main.c:52:13: error: 'b' undeclared (first use in this function)
   52 |   quickSort(b,0,n-1);
      |             ^
main.c:52:13: note: each undeclared identifier is reported only once for each function it appears in
main.c:63:7: error: 'v' undeclared (first use in this function)
   63 |       v = A[cur];
      |       ^
Language: C

#include<stdio.h>
#define MAX  1000
#define VMAX 10000

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

int min(int a,int b){
  if(a>b) return b;
  else return a;
}

int partition(int A[],int p,int r){
  int i,j;
  int t,x;
  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}
void quickSort(int 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 solve(){
  int ans=0,i,cur,S,m,an,v;

  int V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(b,0,n-1);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = VMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      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;

  scanf("%d", &n);
  
  s = VMAX;
  for(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:
main.c: In function 'solve':
main.c:52:13: error: 'b' undeclared (first use in this function)
   52 |   quickSort(b,0,n-1);
      |             ^
main.c:52:13: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include <vector>
#include <algorithm>
#include <cstdio>
int main(){
	int N,r=0;
	scanf("%d",&N);
	std::vector<int>v(N);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	for(int i=N-1;i>=0;i--){
		int ma=v[i],idx=i;
		for(int j=i-1;j>=0;j--)if(ma<v[j])ma=v[j],idx=j;
		if(ma>v[i]){
			r+=v[i]+v[idx];
			std::swap(v[i],v[idx]);
		}
	}
	printf("%d\n",r);
}

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

#include<stdio.h>

#define W_MAX 1000001
#define MAX 1001

int array[MAX];
int sorted[MAX];

void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int calc_cost(int n, int min_pos, int flag = 0){
  int loop_pos = min_pos;
  int i, sum = 0;
  int min = array[min_pos];

  do{
    //printf("%d %d %d\n", loop_pos, sum, min);

    for(i = 0; i < n; i++){
      if(array[i] == sorted[loop_pos]){
	sum += array[i] + array[loop_pos];
	if(flag){ swap(&array[i], &array[loop_pos]); }
	loop_pos = i;
	
	break;
      }
    }
  }while(min != sorted[loop_pos]);

  return sum;
}

int greedy(int n){
  int i, j;
  int absolute_min = array[0], absolute_min_pos = -1;
  int min = W_MAX, min_pos = -1;
  int loop_pos = -1;
  int direct_sum = 0;
  int indirect_sum = 0;

  for(i = 0; i < n; i++){
    if(array[i] == absolute_min){
      absolute_min_pos = i;
      break;
    }
  }

  for(i = 0; i < n; i++){
    if(min > array[i] && sorted[i] != array[i]){
      min = array[i];
      min_pos = i;
    }
  }

  if(min_pos == -1){
    return 0;
  }

  direct_sum += calc_cost(n, min_pos);
  
  swap(&array[min_pos], &array[absolute_min_pos]);
  indirect_sum += array[min_pos] + array[absolute_min_pos];
  indirect_sum += calc_cost(n, min_pos);
  indirect_sum += array[min_pos] + array[absolute_min_pos];
  swap(&array[min_pos], &array[absolute_min_pos]);

  //printf("direct_sum = %d, indirect_sum = %d\n", direct_sum, indirect_sum);

  if(direct_sum <= indirect_sum){
    calc_cost(n, min_pos, 1);
    
    return direct_sum + greedy(n);
  }else{
    swap(&array[min_pos], &array[absolute_min_pos]);
    calc_cost(n, min_pos, 1);
    swap(&array[min_pos], &array[absolute_min_pos]);

    return indirect_sum + greedy(n);
  }

  return 0;
}

int main(int argc, char* argv[]){
  int i, j, n;
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &array[i]);
    sorted[i] = array[i];
  }
  
  for(i = 0; i < n; i++){
    int min = sorted[i];
    int min_pos = i;
    
    for(j = i + 1; j < n; j++){
      if(min > sorted[j]){
	min = sorted[j];
	min_pos = j;
      }
    }

    if(min_pos != i){
      swap(&sorted[i], &sorted[min_pos]);
    }
  }


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

  return 0;
}

Compiler output:
main.c:15:44: error: expected ';', ',' or ')' before '=' token
   15 | int calc_cost(int n, int min_pos, int flag = 0){
      |                                            ^
main.c: In function 'greedy':
main.c:63:17: error: implicit declaration of function 'calc_cost' [-Wimplicit-function-declaration]
   63 |   direct_sum += calc_cost(n, min_pos);
      |                 ^~~~~~~~~
Language: C

#include <stdio.h>
#define MAX 1000
#define VMAX 10000

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

int solve(){
  int i,cur,S,m,an,v,ans = 0;
  int V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i] = 0;
  }
  sort(B,B+n);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = VMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      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,ans;
  scanf("%d",&n);
  s = VMAX;
  for(i=0;i<n;i++){
    scanf("%d",A[i]);
    s = min(s,A[i]);
  }
  ans = solve();
  printf("%d\n",ans);
  return 0;
}

Compiler output:
main.c: In function 'solve':
main.c:15:3: error: implicit declaration of function 'sort' [-Wimplicit-function-declaration]
   15 |   sort(B,B+n);
      |   ^~~~
main.c:27:11: error: implicit declaration of function 'min' [-Wimplicit-function-declaration]
   27 |       m = min(m,v);
      |           ^~~
Language: C

#include<stdio.h>
#include<stdbool.h>
#include<math.h>
static const int MAX = 1000;
static const int VMAX = 10000;

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

void swap(int *a,int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

void qsort(int X[], int left, int right){
  int i,j;
  int pivot;
  i=left;j=right;
  pivot = X[(left+right)/2];

  while(1) {
    while(X[i]<pivot)i++;
    while(pivot<X[j])j--;
    if(i>=j) break;

    swap(&X[i],&X[j]);
    i++;  j--;
  }
  if(left < i-1) qsort(X,left,i-1);
  if(j+1<right) qsort(X,j+1,right);
}



int solve() {
  int i;
  int ans = 0;

  bool V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i]=false;
  }
  qsort(B,0,n-1);
  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 = fmin(m,v);
      S+=v;
      cur=T[v];
      if(V[cur])break;
    }
    ans+=fmin(S+(an - 2) * m , m+S+(an+1)*s);

  }
  return ans;
}

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

  return 0;
}

Compiler output:
main.c:7:7: error: variably modified 'A' at file scope
    7 | int n,A[MAX],s;
      |       ^
main.c:8:5: error: variably modified 'B' at file scope
    8 | int B[MAX], T[VMAX+1];
      |     ^
main.c:8:13: error: variably modified 'T' at file scope
    8 | int B[MAX], T[VMAX+1];
      |             ^
Language: C

#include<stdio.h>
#include<stdbool.h>
#include<math.h>
#define MAX 1000;
#define VMAX 10000;

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

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

void swap(int *a,int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

void qsort(int X[], int left, int right){
  int i,j;
  int pivot;
  i=left;j=right;
  pivot = X[(left+right)/2];

  while(1) {
    while(X[i]<pivot)i++;
    while(pivot<X[j])j--;
    if(i>=j) break;

    swap(&X[i],&X[j]);
    i++;  j--;
  }
  if(left < i-1) qsort(X,left,i-1);
  if(j+1<right) qsort(X,j+1,right);
}



int solve() {
  int i;
  int ans = 0;

  bool V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i]=false;
  }
  qsort(B,0,n-1);
  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 = fmin(m,v);
      S+=v;
      cur=T[v];
      if(V[cur])break;
    }
    ans+=fmin(S+(an - 2) * m , m+S+(an+1)*s);

  }
  return ans;
}

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

  return 0;
}

Compiler output:
main.c:4:17: error: expected ']' before ';' token
    4 | #define MAX 1000;
      |                 ^
main.c:10:9: note: in expansion of macro 'MAX'
   10 | int n,A[MAX],s;
      |         ^~~
main.c:4:17: error: expected ']' before ';' token
    4 | #define MAX 1000;
      |                 ^
main.c:11:7: note: in expansion of macro 'MAX'
   11 | int B[MAX], T[VMAX+1];
      |       ^~~
main.c:11:19: error: expected identifier or '(' before '+' token
   11 | int B[MAX], T[VMAX+1];
      |                   ^
main.c: In function 'solve':
main.c:4:17: error: expected ']' before ';' token
    4 | #define MAX 1000;
      |                 ^
main.c:44:10: note: in expansion of macro 'MAX'
   44 |   bool V[MAX];
      |          ^~~
main.c:46:5: error: 'B' undeclared (first use in this function)
   46 |     B[i] = A[i];
      |     ^
main.c:46:5: note: each undeclared identifier is reported only once for each function it appears in
main.c:46:12: error: 'A' undeclared (first use in this function)
   46 |     B[i] = A[i];
      |            ^
main.c:47:5: error: 'V' undeclared (first use in this function)
   47 |     V[i]=false;
      |     ^
main.c:50:20: error: 'T' undeclared (first use in this function)
   50 |   for(i=0;i<n;i++) T[B[i]] = i;
      |                    ^
main.c:66:43: error: 's' undeclared (first use in this function)
   66 |     ans+=fmin(S+(an - 2) * m , m+S+(an+1)*s);
      |                                           ^
main.c: In function 'main':
main.c:75:3: error: 's' undeclared (first use in this function)
   75 |   s=VMAX;
      |   ^
main.c:77:17: error: 'A' undeclared (first use in this function)
   77 |     scanf("%d",&A[i]);
      |                 ^
Language: C

#include<stdio.h>
  
int n;
int a[1000];
int b[1000];
int vd[1000];
int cnt,sum,mini;

void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int min(int x,int y){
  if(x<y)return x;
  else return y;
}
  
int search(int x){
  int i;
  for(i=0;i<n;i++)if(a[i]==x)return i;
}
  
int main(){
  int i,j,ans,x;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=a[i];
  }
  
  for(i=n-1;i>0;i--)
    for(j=0;j<i;j++)
      if(B[j]>B[j+1])swap(&b[j],&b[j+1]);
    
  ans=0;
  for(i=0;i<n;i++)vd[i]=0;
  
  for(i=0;i<n;i++){   
    x=i;
    cnt=sum=0;
    mini=(1<<24);
    while(vd[x]==0){
      vd[x]=1;
      cnt++;
      sum+=a[x];
      mini=min(mini,a[x]);
      x=search(b[x]);
    }
    if(cnt<2)continue;
    ans+=min(sum+b[0]*(cnt+1)+mini,sum+mini*(cnt-2));
  
  }
  
  printf("%d\n",ans);
  return 0;
}

Compiler output:
main.c: In function 'main':
main.c:36:10: error: 'B' undeclared (first use in this function)
   36 |       if(B[j]>B[j+1])swap(&b[j],&b[j+1]);
      |          ^
main.c:36:10: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include<stdio.h>
  
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
  
int n;
int a[1000];
int b[1000];
int vd[1000];
int cnt,sum,mini;
  
int min(int x,int y){
  if(x<y)return x;
  else return y;
}
  
int search(int x){
  int i;
  for(i=0;i<n;i++)if(a[i]==x) return i;
}
  
int main(){
  int i,j,ans,x;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[i]=a[i];
  }
  
  for(i=n-1;i>0;i--)
    for(j=0;j<i;j++)
      if(B[j]>B[j+1])swap(&b[j],&b[j+1]);
    
  ans=0;
  for(i=0;i<n;i++)vd[i]=0;
  
  for(i=0;i<n;i++){   
    x=i;
    cnt=sum=0;
    mini=(1<<24);
    while(vd[x]==0){
      vd[x]=1;
      cnt++;
      sum+=a[x];
      mini=min(mini,a[x]);
      x=search(b[x]);
    }
    if(cnt<2)continue;
    ans+=min(sum+b[0]*(cnt+1)+mini,sum+mini*(cnt-2));
  
  }
  
  printf("%d\n",ans);
  return 0;
}

Compiler output:
main.c: In function 'main':
main.c:36:10: error: 'B' undeclared (first use in this function)
   36 |       if(B[j]>B[j+1])swap(&b[j],&b[j+1]);
      |          ^
main.c:36:10: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main(){
  int n,ans=0,t[1000],u[1000];
  bool visited[1000];
  map<int,int> change;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
    change[t[i]]=i;
    u[i]=t[i];
    visited[i]=false;
  }
  sort(u,u+n);
  for(int i=0;i<n;i++){   
    int w=i,x=0,y=0,z=10000;
    while(!visited[w]){
      z=min(z,t[w]);
      y+=t[w];
      x++;
      visited[w]=true;
      w=change[u[w]];
    }
    if(x>=2)ans+=min(y+z+u[0]*(x+1),y+z*(x-2));
  }
  cout<<ans<<endl;
  return 0;
}


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

#include<stdio.h>
#include<algorithm>
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;
    scanf("%d",&n);
    s=VMAX;
    for(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:
main.c:2:9: fatal error: algorithm: No such file or directory
    2 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
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:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>

#define Max  1000
#define vMax 10000

int n, a[Max], s;
int b[Max], T[vMax + 1];


int partition(int a[], int p, int r){
  int i, j;
  int t, x;
  x = a[r];
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}

void quickSort(int 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 solve(){
  int i,ans = 0, cur, S, m, an, v;

  int V[Max];
  for(i = 0 ; i < n ; i++){
    b[i] = a[i];
    V[Max] = 0;
  }

  quickSort(b, 0, n - 1);

  for(i = 0 ; i < n ; i++) t[b[i]] = i;
  for(i = 0 ; i < n ; i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = vMax;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      v = a[cur];

      if(v < m) m = v;

      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    if(S + (an -2) * m < m + S + (an + 1) * s) ans += S + (an -2) * m;
    if(S + (an -2) * m > m + S + (an + 1) * s) ans +=  m + S + (an + 1) * s;
  }
  return ans;
}


int main(){
  int i;

  scanf("%d", &n);
  s = vMax;
  for(i = 0 ; i < n ; i++){
    scanf("%d", &a[i]);
    if(a[i] < s) s = a[i];
}

  int ans = solve();
  printf("%d\n", ans);

  return 0;
}


Compiler output:
main.c: In function 'solve':
main.c:54:28: error: 't' undeclared (first use in this function)
   54 |   for(i = 0 ; i < n ; i++) t[b[i]] = i;
      |                            ^
main.c:54:28: note: each undeclared identifier is reported only once for each function it appears in
Language: C

include<stdio.h>
//とりあえず
int sort(int *A,int n){
  int i,j;
  int min=1000,max=0;
  int cost=0;
  
  for(i=1;i<n;i++){
    if(A[i]>max) max=A[i];
    else if(A[i]<min) min=A[i];
  }
  cost+=max+min;
  return cost;
}
int main(){

  int i,n,cost;
  int A[1000];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);
  cost=sort(&A[0],n);
  
  printf("%d\n",cost);
}

Compiler output:
main.c:1:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    1 | include<stdio.h>
      |        ^
main.c: In function 'main':
main.c:20:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   20 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | include<stdio.h>
main.c:20:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   20 |   scanf("%d",&n);
      |   ^~~~~
main.c:20:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:23:8: error: implicit declaration of function 'sort' [-Wimplicit-function-declaration]
   23 |   cost=sort(&A[0],n);
      |        ^~~~
main.c:25:3: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   25 |   printf("%d\n",cost);
      |   ^~~~~~
main.c:25:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:25:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:25:3: note: include '<stdio.h>' or provide a declaration of 'printf'
Language: C

include<stdio.h>
//toriaezu
int sort(int *A,int n){
  int i,j;
  int min=1000,max=0;
  int cost=0;
  
  for(i=1;i<n;i++){
    if(A[i]>max) max=A[i];
    else if(A[i]<min) min=A[i];
  }
  cost+=max+min;
  return cost;
}
int main(){

  int i,n,cost;
  int A[1000];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);
  cost=sort(&A[0],n);
  
  printf("%d\n",cost);
return 0;
}

Compiler output:
main.c:1:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
    1 | include<stdio.h>
      |        ^
main.c: In function 'main':
main.c:20:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   20 |   scanf("%d",&n);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | include<stdio.h>
main.c:20:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   20 |   scanf("%d",&n);
      |   ^~~~~
main.c:20:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:23:8: error: implicit declaration of function 'sort' [-Wimplicit-function-declaration]
   23 |   cost=sort(&A[0],n);
      |        ^~~~
main.c:25:3: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   25 |   printf("%d\n",cost);
      |   ^~~~~~
main.c:25:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:25:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:25:3: note: include '<stdio.h>' or provide a declaration of 'printf'
Language: C

#include <bits/stdc++.h>

using namespace std;

#define MAX 1000
#define MAX_D 10001

int main(){
  int N, arr[MAX], _arr[MAX], dest[MAX_D];
  bool used[MAX];

  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> arr[i];
    used[i] = false;
    _arr[i] = arr[i];
  }
  sort(_arr, _arr+N);

  for(int i = 0 ; i < N ; i++){
    dest[_arr[i]] = i;
  }

  int ans = 0;
  for(int i = 0 ; i < N ; i++){
    if(dest[arr[i]] == i || used[i]){
      used[i] = true;
      continue;
    }

    int cnt = -1, sum = 0, min = arr[i], next = i;
    for( ; !used[next] ; ){
      sum += arr[next]; cnt++;
      min = std::min(min, arr[next]);
      used[next] = true;
      next = dest[arr[next]];
    }
    sum -= min;
    ans += sum + min*cnt;
  }

  cout << ans << endl;

  return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
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;
      |                    ^~~~