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 isAlpha
( c
: Char
) = ( c
>= 'a' && c
<= 'z' ) ||
( c
>= 'A' && c
<= 'Z' )
def desc
[ T
: Ordering
] = implicitly
[ Ordering
[ T
] ] .
reverse
def beauty
( s
: String
) = s
// "abcC!" .filter ( isAlpha) // "abcC"
.toLowerCase // "abcc"
.groupBy ( identity) // [a -> a, b -> b, c -> cc]
.mapValues ( _ .size ) // [a -> 1, b -> 1, c -> 2]
.values .toList // [1, 1, 2]
.sortBy ( identity) ( desc) // [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+PSAxKSBmcm9tRmlsZShhcmdzKDApKSBlbHNlIHN0ZGluCiAgICBpbnB1dC5nZXRMaW5lcy5maWx0ZXJOb3QoXy5pc0VtcHR5KS5tYXAoYmVhdXR5KS5mb3JlYWNoKHByaW50bG4pCiAgfQoKICBkZWYgaXNBbHBoYShjOiBDaGFyKSA9IChjID49ICdhJyAmJiBjIDw9ICd6JykgfHwgKGMgPj0gJ0EnICYmIGMgPD0gJ1onKQoKICBkZWYgZGVzY1tUOiBPcmRlcmluZ10gPSBpbXBsaWNpdGx5W09yZGVyaW5nW1RdXS5yZXZlcnNlCgogIGRlZiBiZWF1dHkoczogU3RyaW5nKSA9IHMgLy8gImFiY0MhIgogICAgLmZpbHRlcihpc0FscGhhKSAgICAgICAgLy8gImFiY0MiCiAgICAudG9Mb3dlckNhc2UgICAgICAgICAgICAvLyAiYWJjYyIKICAgIC5ncm91cEJ5KGlkZW50aXR5KSAgICAgIC8vIFthIC0+IGEsIGIgLT4gYiwgYyAtPiBjY10KICAgIC5tYXBWYWx1ZXMoXy5zaXplKSAgICAgIC8vIFthIC0+IDEsIGIgLT4gMSwgYyAtPiAyXQogICAgLnZhbHVlcy50b0xpc3QgICAgICAgICAgLy8gWzEsIDEsIDJdCiAgICAuc29ydEJ5KGlkZW50aXR5KShkZXNjKSAvLyBbMiwgMSwgMV0KICAgIC56aXAoMjYgdG8gMSBieSAtMSkgICAgIC8vIFsoMiwgMjYpLCAoMSwgMjUpLCAoMSwgMjQpXQogICAgLm1hcCh4ID0+IHguXzEgKiB4Ll8yKSAgLy8gWzUyLCAyNSwgMjRdCiAgICAuc3VtICAgICAgICAgICAgICAgICAgICAvLyAxMDEKfQo=
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