Language: C++

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
     
     
     
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
     
     
void merge(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}
     
     
void m_sort(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  m_sort(left,mid);
  m_sort(mid,right);
  merge(left,mid,right);
}
     
     
void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}
     
     
     
     
     
     
       
      
       
     
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  m_sort(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  return 0;
}


Compiler output:
a.cc:4:1: error: extended character   is not valid in an identifier
    4 |      
      | ^
a.cc:4:1: error: extended character   is not valid in an identifier
a.cc:4:1: error: extended character   is not valid in an identifier
a.cc:4:1: error: extended character   is not valid in an identifier
a.cc:4:1: error: extended character   is not valid in an identifier
a.cc:5:1: error: extended character   is not valid in an identifier
    5 |      
      | ^
a.cc:5:1: error: extended character   is not valid in an identifier
a.cc:5:1: error: extended character   is not valid in an identifier
a.cc:5:1: error: extended character   is not valid in an identifier
a.cc:5:1: error: extended character   is not valid in an identifier
a.cc:6:1: error: extended character   is not valid in an identifier
    6 |      
      | ^
a.cc:6:1: error: extended character   is not valid in an identifier
a.cc:6:1: error: extended character   is not valid in an identifier
a.cc:6:1: error: extended character   is not valid in an identifier
a.cc:6:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
   10 |      
      | ^
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
   11 |      
      | ^
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:13:1: error: extended character   is not valid in an identifier
   13 |   int i,j,n1=mid-left,n2=right-mid;
      | ^
a.cc:13:1: error: extended character   is not valid in an identifier
a.cc:14:1: error: extended character   is not valid in an identifier
   14 |   for(i=0;i<n1;i++) L[i]=A[left+i];
      | ^
a.cc:14:1: error: extended character   is not valid in an identifier
a.cc:15:1: error: extended character   is not valid in an identifier
   15 |   L[n1]=INT_MAX;
      | ^
a.cc:15:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
   16 |   for(i=0;i<n2;i++) R[i]=A[mid+i];
      | ^
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:17:1: error: extended character   is not valid in an identifier
   17 |   R[n2]=INT_MAX;
      | ^
a.cc:17:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
   18 |   int l=0,r=0;
      | ^
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:19:1: error: extended character   is not valid in an identifier
   19 |   for(i=left;i<right;i++){
      | ^
a.cc:19:1: error: extended character   is not valid in an identifier
a.cc:20:1: error: extended character   is not valid in an identifier
   20 |     if(L[l]<=R[r]){
      | ^
a.cc:20:1: error: extended character   is not valid in an identifier
a.cc:20:1: error: extended character   is not valid in an identifier
a.cc:20:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
   21 |       A[i]=L[l];
      | ^
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
   22 |       l++;
      | ^
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
   23 |     }
      | ^
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
   24 |     else{
      | ^
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
   25 |       A[i]=R[r];
      | ^
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
   26 |       r++;
      | ^
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:27:1: error: extended character   is not valid in an identifier
   27 |     }
      | ^
a.cc:27:1: error: extended character   is not valid in an identifier
a.cc:27:1: error: extended character   is not valid in an identifier
a.cc:27:1: error: extended character   is not valid in an identifier
a.cc:28:1: error: extended character   is not valid in an identifier
   28 |   }
      | ^
a.cc:28:1: error: extended character   is not valid in an identifier
a.cc:30:1: error: extended character   is not valid in an identifier
   30 |      
      | ^
a.cc:30:1: error: extended character   is not valid in an identifier
a.cc:30:1: error: extended character   is not valid in an identifier
a.cc:30:1: error: extended character   is not valid in an identifier
a.cc:30:1: error: extended character   is not valid in an identifier
a.cc:31:1: error: extended character   is not valid in an identifier
   31 |      
      | ^
a.cc:31:1: error: extended character   is not valid in an identifier
a.cc:31:1: error: extended character   is not valid in an identifier
a.cc:31:1: error: extended character   is not valid in an identifier
a.cc:31:1: error: extended character   is not valid in an identifier
a.cc:33:1: error: extended character   is not valid in an identifier
   33 |   int mid;
      | ^
a.cc:33:1: error: extended character   is not valid in an identifier
a.cc:34:1: error: extended character   is not valid in an identifier
   34 |   if( left+1 >= right) return;
      | ^
a.cc:34:1: error: extended character   is not valid in an identifier
a.cc:35:1: error: extended character   is not valid in an identifier
   35 |   mid=(left+right)/2;
      | ^
a.cc:35:1: error: extended character   is not valid in an identifier
a.cc:36:1: error: extended character   is not valid in an identifier
   36 |   m_sort(left,mid);
      | ^
a.cc:36:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
   37 |   m_sort(mid,right);
      | ^
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
   38 |   merge(left,mid,right);
      | ^
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
   40 |      
      | ^
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
   41 |      
      | ^
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:43:1: error: extended character   is not valid in an identifier
   43 |   int swap;
      | ^
a.cc:43:1: error: extended character   is not valid in an identifier
a.cc:44:1: error: extended character   is not valid in an identifier
   44 |   swap=C[a];
      | ^
a.cc:44:1: error: extended character   is not valid in an identifier
a.cc:45:1: error: extended character   is not valid in an identifier
   45 |   C[a]=C[b];
      | ^
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:46:1: error: extended character   is not valid in an identifier
   46 |   C[b]=swap;
      | ^
a.cc:46:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
   48 |      
      | ^
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:49:1: error: extended character   is not valid in an identifier
   49 |      
      | ^
a.cc:49:1: error: extended character