import scala.
io .
Source .
{ fromFile, stdin
}
def main
( args
: Array
[ String
] ) { val input
= if ( args.
length >= 1 ) fromFile
( args
( 0 ) ) else stdin
input.getLines .filterNot ( _ .isEmpty ) .map ( beauty) .foreach ( println)
}
def beauty
( s
: String
) = s
// "abcC!" .filter ( _ .isLetter ) // "abcC"
.toLowerCase // "abcc"
.groupBy ( identity) // [a -> a, b -> b, c -> cc]
.mapValues ( _ .size ) // [a -> 1, b -> 1, c -> 2]
.values .toList // [1, 1, 2]
.sortWith ( _ > _ ) // [2, 1, 1]
.zip ( 26 to 1 by -1 ) // [(2, 26), (1, 25), (1, 24)]
.map ( x => x._ 1 * x._ 2) // [52, 25, 24]
.sum // 101
}
aW1wb3J0IHNjYWxhLmlvLlNvdXJjZS57ZnJvbUZpbGUsIHN0ZGlufQoKb2JqZWN0IE1haW4gewogIGRlZiBtYWluKGFyZ3M6IEFycmF5W1N0cmluZ10pIHsKICAgIHZhbCBpbnB1dCA9IGlmIChhcmdzLmxlbmd0aCA+PSAxKSBmcm9tRmlsZShhcmdzKDApKSBlbHNlIHN0ZGluCiAgICBpbnB1dC5nZXRMaW5lcy5maWx0ZXJOb3QoXy5pc0VtcHR5KS5tYXAoYmVhdXR5KS5mb3JlYWNoKHByaW50bG4pCiAgfQoKICBkZWYgYmVhdXR5KHM6IFN0cmluZykgPSBzIC8vICJhYmNDISIKICAgIC5maWx0ZXIoXy5pc0xldHRlcikgICAgIC8vICJhYmNDIgogICAgLnRvTG93ZXJDYXNlICAgICAgICAgICAgLy8gImFiY2MiCiAgICAuZ3JvdXBCeShpZGVudGl0eSkgICAgICAvLyBbYSAtPiBhLCBiIC0+IGIsIGMgLT4gY2NdCiAgICAubWFwVmFsdWVzKF8uc2l6ZSkgICAgICAvLyBbYSAtPiAxLCBiIC0+IDEsIGMgLT4gMl0KICAgIC52YWx1ZXMudG9MaXN0ICAgICAgICAgIC8vIFsxLCAxLCAyXQogICAgLnNvcnRXaXRoKF8gPiBfKSAgICAgICAgLy8gWzIsIDEsIDFdCiAgICAuemlwKDI2IHRvIDEgYnkgLTEpICAgICAvLyBbKDIsIDI2KSwgKDEsIDI1KSwgKDEsIDI0KV0KICAgIC5tYXAoeCA9PiB4Ll8xICogeC5fMikgIC8vIFs1MiwgMjUsIDI0XQogICAgLnN1bSAgICAgICAgICAgICAgICAgICAgLy8gMTAxCn0K
stdin
QUJiQ2NjCkdvb2QgbHVjayBpbiB0aGUgRmFjZWJvb2sgSGFja2VyIEN1cCB0aGlzIHllYXIhCklnbm9yZSBwdW5jdHVhdGlvbiwgcGxlYXNlIDopClNvbWV0aW1lcyB0ZXN0IGNhc2VzIGFyZSBoYXJkIHRvIG1ha2UgdXAuClNvIEkganVzdCBnbyBjb25zdWx0IFByb2Zlc3NvciBEYWx2ZXM=
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves