Language: C

#include<stdio.h>
#include<stdlib.h>
#include<math.h>


typedef struct val{
	int raw;
	int a; 
};

int main(void){
	int n;
	int i,j;
	val v[2000];
	int i_m;
	int l;
	int r;
	long long int ret;


	val buff;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&v[i].a);
		v[i].raw = i;
	}

	for(i=0;i<n;i++){
		printf("%d : %d\n",v[i].raw,v[i].a);

	}

	for(i=0;i<n-1;i++){
		i_m = i;
		for(j=i+1;j<n;j++){
			if(v[j].a > v[i_m].a){
				i_m = j;
			}
		}
		buff = v[i];
		v[i] = v[i_m];
		v[i_m] = buff;
	}

	for(i=0;i<n;i++){
		printf("%d : %d\n",v[i].raw,v[i].a);

	}

	l = 0;
	r = n-1;
	ret = 0;

	for(i=0;i<n;i++){
		if(l == r){
			ret += abs(l - v[i].raw) * v[i].a;
			l++;
		}
		else
		{
			if(abs(l - v[i].raw) > abs(r - v[i].raw)){
				ret += abs(l - v[i].raw) * v[i].a;
				l++;
			}else if((abs(l - v[i].raw) < abs(r - v[i].raw))){
				ret += abs(r - v[i].raw) * v[i].a;
				r--;
			}else{
				if(abs(l - v[i+1].raw) > abs(r - v[i+1].raw)){
					ret += abs(l - v[i+1].raw) * v[i+1].a;
					l++;
					ret += abs(r - v[i].raw) * v[i].a;
					r--;
				}
				else{
					ret += abs(l - v[i].raw) * v[i].a;
					l++;
					ret += abs(r - v[i+1].raw) * v[i+1].a;
					r--;
				}
				i++;
			}
		}

	}

	printf("%lld\n",ret);



	return 0;

}



Compiler output:
main.c:9:1: warning: useless storage class specifier in empty declaration
    9 | };
      | ^
main.c: In function 'main':
main.c:14:9: error: unknown type name 'val'; use 'struct' keyword to refer to the type
   14 |         val v[2000];
      |         ^~~
      |         struct 
main.c:21:9: error: unknown type name 'val'; use 'struct' keyword to refer to the type
   21 |         val buff;
      |         ^~~
      |         struct 
main.c:24:33: error: request for member 'a' in something not a structure or union
   24 |                 scanf("%d",&v[i].a);
      |                                 ^
main.c:25:21: error: request for member 'raw' in something not a structure or union
   25 |                 v[i].raw = i;
      |                     ^
main.c:29:40: error: request for member 'raw' in something not a structure or union
   29 |                 printf("%d : %d\n",v[i].raw,v[i].a);
      |                                        ^
main.c:29:49: error: request for member 'a' in something not a structure or union
   29 |                 printf("%d : %d\n",v[i].raw,v[i].a);
      |                                                 ^
main.c:36:32: error: request for member 'a' in something not a structure or union
   36 |                         if(v[j].a > v[i_m].a){
      |                                ^
main.c:36:43: error: request for member 'a' in something not a structure or union
   36 |                         if(v[j].a > v[i_m].a){
      |                                           ^
main.c:46:40: error: request for member 'raw' in something not a structure or union
   46 |                 printf("%d : %d\n",v[i].raw,v[i].a);
      |                                        ^
main.c:46:49: error: request for member 'a' in something not a structure or union
   46 |                 printf("%d : %d\n",v[i].raw,v[i].a);
      |                                                 ^
main.c:56:44: error: request for member 'raw' in something not a structure or union
   56 |                         ret += abs(l - v[i].raw) * v[i].a;
      |                                            ^
main.c:56:56: error: request for member 'a' in something not a structure or union
   56 |                         ret += abs(l - v[i].raw) * v[i].a;
      |                                                        ^
main.c:61:40: error: request for member 'raw' in something not a structure or union
   61 |                         if(abs(l - v[i].raw) > abs(r - v[i].raw)){
      |                                        ^
main.c:61:60: error: request for member 'raw' in something not a structure or union
   61 |                         if(abs(l - v[i].raw) > abs(r - v[i].raw)){
      |                                                            ^
main.c:62:52: error: request for member 'raw' in something not a structure or union
   62 |                                 ret += abs(l - v[i].raw) * v[i].a;
      |                                                    ^
main.c:62:64: error: request for member 'a' in something not a structure or union
   62 |                                 ret += abs(l - v[i].raw) * v[i].a;
      |                                                                ^
main.c:64:47: error: request for member 'raw' in something not a structure or union
   64 |                         }else if((abs(l - v[i].raw) < abs(r - v[i].raw))){
      |                                               ^
main.c:64:67: error: request for member 'raw' in something not a structure or union
   64 |                         }else if((abs(l - v[i].raw) < abs(r - v[i].raw))){
      |                                                                   ^
main.c:65:52: error: request for member 'raw' in something not a structure or union
   65 |                                 ret += abs(r - v[i].raw) * v[i].a;
      |                                                    ^
main.c:65:64: error: request for member 'a' in something not a structure or union
   65 |                                 ret += abs(r - v[i].raw) * v[i].a;
      |                                                                ^
main.c:68:50: error: request for member 'raw' in something not a structure or union
   68 |                                 if(abs(l - v[i+1].raw) > abs(r - v[i+1].raw)){
      |                                                  ^
main.c:68:72: error: request for member 'raw' in something not a structure or union
   68 |                                 if(abs(l - v[i+1].raw) > abs(r - v[i+1].raw)){
      |                                                                        ^
main.c:69:62: error: request for member 'raw' in something not a structure or union
   69 |                                         ret += abs(l - v[i+1].raw) * v[i+1].a;
      |                                                              ^
main.c:69:76: error: request for member 'a' in something not a structure or union
   69 |                                         ret += abs(l - v[i+1].raw) * v[i+1].a;
      |                                                                            ^
main.c:71:60: error: request for member 'raw' in something not a structure or union
   71 |                                         ret += abs(r - v[i].raw) * v[i].a;
      |                                                            ^
main.c:71:72: error: request for member 'a' in something not a structure or union
   71 |                                         ret += abs(r - v[i].raw) * v[i].a;
      |                                                                        ^
main.c:75:60: error: request for member 'raw' in something not a structure or union
   75 |                                         ret += abs(l - v[i].raw) * v[i].a;
      |                                                            ^
main.c:75:72: error: request for member 'a' in something not a structure or union
   75 |                                         ret += abs(l - v[i].raw) * v[i].a;
      |                                                                        ^
main.c:77:62: error: request for member 'raw' in something not a structure or union
   77 |                                         ret += abs(r - v[i+1].raw) * v[i+1].a;
      |                                                              ^
main.c:77:76: error: request for member 'a' in something not a structure or union
   77 |                                         ret += abs(r - v[i+1].raw) * v[i+1].a;
      |                                                                            ^