#include #include using namespace std; int getPriority(char c) { // [1;52] if ('a' <= c && c <= 'z') return c - 'a' + 1; if ('A' <= c && c <= 'Z') return c - 'A' + 27; throw "unexpected input"; } int main() { long total = 0; for (string line; getline(cin, line); ) { bool inFirstHalf[52] = {0}; if (line.length() % 2 != 0) throw "unexpected input"; int found = -1; for (int i = 0; i < line.length(); i++) { int p = getPriority(line[i]); if (i < line.length() / 2) { inFirstHalf[p-1] = true; } else { if (inFirstHalf[p-1]) { found = p; break; } } } if (found == -1) throw "bad input"; total += found; } cout << total << endl; }