Language: Java

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const ll oo=1e18+5;
const int N=2e5+5;
const int mod=1e9+7;

vector<vector<string>> s;
vector<int> cost;
ll dp[55][35][2];
int n;

bool isGud(const string& s,int l,int r){
	for(int i=l,j=r-1;i<j;++i,--j){
		if(s[i]!=s[j]) return 0;
	}
	return 1;
}

ll solve(int id,int suff,int dir){
	int len=(int)s[id][dir].size();
	if(isGud(s[id][dir],len-suff,len)) return 0;
	ll res=dp[id][suff][dir];
	if(res>=0) return res;
	res=INF;
	int rev=dir^1;
	for(int i=0;i<n;++i){
		int sizee=(int)s[i][rev].size();
		if(sizee<=suff){
			if(s[i][rev]==s[id][dir].substr(len-suff,sizee)){
				res=min(res,cost[i]+solve(id,suff-sizee,dir));
			}
		}
		else{
			if(s[id][dir].substr(len-suff)==s[i][rev].substr(0,suff)){
				res=min(res,cost[i]+solve(i,sizee-suff,rev));
			}
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	s.resize(n,vector<string>(2));
	cost.resize(n);
	for(int i=0;i<n;++i){
		cin>>s[i][0]>>cost[i];
		s[i][1]=s[i][0];
		reverse(all(s[i][1]));
	}
	ll ans=oo;	
	memset(dp,255,sizeof(dp));
	for(int i=0;i<n;++i){
		ll cur=cost[i]+solve(i,(int)s[i][0].size(),0);
		ans=min(ans,cur);
	}
	if(ans>=INF) ans=-1;
	cout<<ans;
	return 0;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:3: error: class, interface, enum, or record expected
typedef long long ll;
^
Main.java:4: error: illegal character: '#'
#define endl '\n'
^
Main.java:4: error: class, interface, enum, or record expected
#define endl '\n'
        ^
Main.java:5: error: illegal character: '#'
#define all(x) (x).begin(),(x).end()
^
Main.java:7: error: class, interface, enum, or record expected
const ll oo=1e18+5;
^
Main.java:8: error: class, interface, enum, or record expected
const int N=2e5+5;
^
Main.java:9: error: class, interface, enum, or record expected
const int mod=1e9+7;
^
Main.java:11: error: unnamed classes are a preview feature and are disabled by default.
vector<vector<string>> s;
^
  (use --enable-preview to enable unnamed classes)
Main.java:13: error: class, interface, enum, or record expected
ll dp[55][35][2];
^
Main.java:16: error: illegal start of type
bool isGud(const string& s,int l,int r){
           ^
Main.java:16: error: class, interface, enum, or record expected
bool isGud(const string& s,int l,int r){
                           ^
Main.java:17: error: class, interface, enum, or record expected
	for(int i=l,j=r-1;i<j;++i,--j){
	                  ^
Main.java:17: error: class, interface, enum, or record expected
	for(int i=l,j=r-1;i<j;++i,--j){
	                      ^
Main.java:19: error: class, interface, enum, or record expected
	}
	^
Main.java:21: error: class, interface, enum, or record expected
}
^
Main.java:25: error: class, interface, enum, or record expected
	if(isGud(s[id][dir],len-suff,len)) return 0;
	^
Main.java:27: error: class, interface, enum, or record expected
	if(res>=0) return res;
	^
Main.java:28: error: class, interface, enum, or record expected
	res=INF;
	^
Main.java:30: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	^
Main.java:30: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	            ^
Main.java:30: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	                ^
Main.java:32: error: class, interface, enum, or record expected
		if(sizee<=suff){
		^
Main.java:35: error: class, interface, enum, or record expected
			}
			^
Main.java:40: error: class, interface, enum, or record expected
			}
			^
Main.java:44: error: class, interface, enum, or record expected
}
^
Main.java:48: error: class, interface, enum, or record expected
	cin.tie(0);
	^
Main.java:49: error: class, interface, enum, or record expected
	cin>>n;
	^
Main.java:50: error: class, interface, enum, or record expected
	s.resize(n,vector<string>(2));
	^
Main.java:51: error: class, interface, enum, or record expected
	cost.resize(n);
	^
Main.java:52: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	^
Main.java:52: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	            ^
Main.java:52: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	                ^
Main.java:54: error: class, interface, enum, or record expected
		s[i][1]=s[i][0];
		^
Main.java:55: error: class, interface, enum, or record expected
		reverse(all(s[i][1]));
		^
Main.java:56: error: class, interface, enum, or record expected
	}
	^
Main.java:58: error: class, interface, enum, or record expected
	memset(dp,255,sizeof(dp));
	^
Main.java:59: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	^
Main.java:59: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	            ^
Main.java:59: error: class, interface, enum, or record expected
	for(int i=0;i<n;++i){
	                ^
Main.java:61: error: class, interface, enum, or record expected
		ans=min(ans,cur);
		^
Main.java:62: error: class, interface, enum, or record expected
	}
	^
Main.java:64: error: class, interface, enum, or record expected
	cout<<ans;
	^
Main.java:65: error: class, interface, enum, or record expected
	return 0;
	^
Main.java:66: error: class, interface, enum, or record expected
}
^
46 errors