Cod sursa(job #3371744)

Utilizator mihiboiBacis Mihai-Cristian mihiboi Data 31 octombrie 2026 13:54:10
Problema Litere Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("litere.in");
ofstream fout("litere.out");
    
int n, w[26], ind;
long long rez;
char s[10005];

int main() {
    fin >> n;
    fin >> s;

    for(int i = n - 1; i >= 0;i--) {
        ind = s[i] - 'a';
        for(int j = 0; j < ind; j++) {
            rez += w[j];
        }
        w[ind]++;
    }
    
    fout << rez;
    return 0;
}