#define fi first #define se second #define lowbit(x) ((x)&(-x)) #define endl '\n'
typedeflonglong LL; typedef pair<int,int> PII; constint N=2e5+10,M=2e5+10,mod=998244353,INF=0x3f3f3f3f; int n, m, k; char s[N];
voidsolve(){ cin >> n >> s + 1; vector<int> cnt(10); for (int i = 1; i <= n; i++) { if (s[i] == '0' && n > 2) { if (n == 3 && i == 2) { int a = s[i-1] - '0'; int b = s[i+1] - '0'; cout << min(a * b, a + b) << endl; } else cout << "0\n"; return; } cnt[s[i] - '0'] ++; } int res = INF; for (int i = 1; i <= n - 1; i ++) { int ans = 10 * (s[i] - '0') + s[i + 1] - '0'; cnt[s[i] - '0'] -- , cnt[s[i + 1] - '0'] --; for (int i = 2; i <= 9; i ++) { ans += cnt[i] * i; } cnt[s[i] - '0'] ++ , cnt[s[i + 1] - '0'] ++; res = min(res, ans); } cout << res << endl; }