#include<iostream>
using namespace std;
#define N 7
void MatrixChain(int p[N],int n,int m[N][N],int s[N][N])
{for(int i=1;i<=n;i++)m[i][i]=0;for(int r=2;r<=n;r++)//有多少个相乘(规模){for(int i=1;i<=n-r+1;i++){int j=i+r-1;m[i][j]=m[i][i]+m[i+1][j]+p[i]*p[i+1]*p[j];s[i][j]=i;for(int k=i+1;k<j;k++){int t=m[i][k]+m[k+1][j]+p[i]*p[k]*p[j];if(t<m[i][j]){m[i][j]=t;s[i][j]=k;}}}}
}
void Traceback(int i,int j,int s[N][N])
{if(i==j)//仅有一个元素cout<<"A"<<i;else{cout<<"(";//将数组以是s[i][j]为界分为两部分Traceback(i,s[i][j],s);Traceback(s[i][j]+1,j,s);cout<<")";}
}
int main()
{int p[N]={30,35,15,5,10,20,25};int m[N][N]={0},s[N][N]={0};MatrixChain(p,N-1,m,s);int cnt;cin>>cnt;Traceback(1,cnt,s);return 0;
}