Language: C++

#include<cstdlib>
#include<cstring>
using namespace std;
int dp[205][205];
int s[205][205];
int a[205];
int n;
void print(int i,int j,int t){
    if(i==j){
        cout<<"A"<<i-1;
    }
    else{
        if(t!=0)
        cout<<"(";
        print(i,s[i][j],t+1);
        print(s[i][j]+1,j,t+1);
        if(t!=0)
        cout<<")";
    }
}
int main(){
    int n;
    while(~scanf("%d",&n)&&n!=0){
        int i,j,k;
        int length;
        //memset(s,0,zizeof(s));
        n++;
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
            dp[i][i]=0;
        }
        int t;
        for(length=2;length<=n;length++){
            for(i=1;i<=n-length+1;i++){
                j=i+length-1;
                dp[i][j]=0x7fffffff;
                for(k=i;k<=j-1;k++){
                    t=dp[i][k]+dp[k+1][j]+a[i-1]*a[k]*a[j];
                    if(t<dp[i][j]){
                        dp[i][j]=t;
                        //printf("%d\n",dp[i][j]);
                        s[i][j]=k;
                    }
                }
            }
        }
        //printf("%d\n",dp[1][n-1]);
        print(1,n-1,0);
        cout<<endl;
    }
    return 0;
}


/*
1 
10 20

A0


2 
10 20 30

A0A1


3 
10 20 30 40

(A0A1)A2


6 
30 35 15 5 10 20 250

(A0(A1A2))((A3A4)A5)
*/




/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
//#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

LL gcd(LL a,LL b,LL c)
{
    return __gcd(__gcd(a,b),c);
}

int main()
{
    LL k,ans=0;
    cin>>k;
    rer(a,1,k)rer(b,1,k)rer(c,1,k)ans+=gcd(a,b,c);
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'void print(int, int, int)':
a.cc:10:9: error: 'cout' was not declared in this scope
   10 |         cout<<"A"<<i-1;
      |         ^~~~
a.cc:3:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<cstring>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:14:9: error: 'cout' was not declared in this scope
   14 |         cout<<"(";
      |         ^~~~
a.cc:14:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:18:9: error: 'cout' was not declared in this scope
   18 |         cout<<")";
      |         ^~~~
a.cc:18:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc: In function 'int main()':
a.cc:23:12: error: 'scanf' was not declared in this scope
   23 |     while(~scanf("%d",&n)&&n!=0){
      |            ^~~~~
a.cc:49:9: error: 'cout' was not declared in this scope
   49 |         cout<<endl;
      |         ^~~~
a.cc:49:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:49:15: error: 'endl' was not declared in this scope
   49 |         cout<<endl;
      |               ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<cstring>
  +++ |+#include <ostream>
    3 | using namespace std;
a.cc: At global scope:
a.cc:111:5: error: redefinition of 'int main()'
  111 | int main()
      |     ^~~~
a.cc:21:5: note: 'int main()' previously defined here
   21 | int main(){
      |     ^~~~