<reponame>japaric-archived/eulermark.rs
OFFSET = ord('A') - 1


def name_value(name):
    return sum(map(lambda c: ord(c) - OFFSET, name))


def f():
    with open("022.txt") as f:
        names = list(map(lambda s: s[1:-1], f.read().split(',')))

    names.sort()

    ans = 0
    for (n, name) in enumerate(names, start=1):
        ans += n * name_value(name)

    return ans

import ctypes
import sys

CLOCK_MONOTONIC = 1


class timespec(ctypes.Structure):
    _fields_ = [
        ('tv_sec', ctypes.c_long),
        ('tv_nsec', ctypes.c_long)
    ]

librt = ctypes.CDLL('librt.so.1')
clock_gettime = librt.clock_gettime
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]


def to_ns(ts):
    return ts.tv_sec * int(1e9) + ts.tv_nsec


if len(sys.argv) == 1:
    print(f())
elif len(sys.argv) == 2:
    start, end = timespec(), timespec()
    iters = int(sys.argv[1])

    clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(start))
    for _ in range(0, iters):
        f()
    clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(end))

    print(to_ns(end) - to_ns(start))
