Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

typedef pair<ll, pair<string, int>> S;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<string> s(n); vector<ll> c(n);
	vector<string> revs(n);
	rep(i, n) cin >> s[i] >> c[i];
	map<pair<string, ll>, ll> mp;
	priority_queue<S, vector<S>, greater<S>> que;
	que.push({ 0,{"",0} });
	que.push({ 0,{"",1} });
	int f = 0;
	while (!que.empty()) {
		S p = que.top(); que.pop();
		ll cost = p.first; string now = p.second.first; int mode = p.second.second;
		int len = now.size();
		if (cost != 0) {
			bool ok = true;
			rep(i, len) if (now[i] != now[len - 1 - i]) ok = false;
			if (ok) {
				cout << cost << '\n';
				return 0;
			}
		}
		if (cost > mp[{now, mode}]) continue;
		rep(i, n) {
			int sz = s[i].size();
			string tmp = s[i];
			if (mode == 0) reverse(all(tmp));
			if (now.size() >= sz && now.substr(0, sz) == tmp) {
				string rem = now.substr(sz);
				if (!mp.count[{ rem, mode }] == 0 || mp[{rem, mode}] > mp[{now, mode}] + c[i]) {
					mp[{rem, mode}] = cost + c[i];
					que.push({ cost + c[i],{rem,mode} });
				}
			}
			if (tmp.substr(0, len) == now) {
				string rem = tmp.substr(len);
				if (!mp.count[{ rem, mode ^ 1 }] == 0 || mp[{rem, mode ^ 1}] > mp[{now, mode}] + c[i]) {
					mp[{rem, mode ^ 1}] = cost + c[i];
					que.push({ cost + c[i],{rem,mode ^ 1} });
				}
			}
		}
	}
	cout << "-1\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:78:46: error: invalid types '<unresolved overloaded function type>[<brace-enclosed initializer list>]' for array subscript
   78 |                                 if (!mp.count[{ rem, mode }] == 0 || mp[{rem, mode}] > mp[{now, mode}] + c[i]) {
      |                                              ^
a.cc:85:46: error: invalid types '<unresolved overloaded function type>[<brace-enclosed initializer list>]' for array subscript
   85 |                                 if (!mp.count[{ rem, mode ^ 1 }] == 0 || mp[{rem, mode ^ 1}] > mp[{now, mode}] + c[i]) {
      |                                              ^