#!/usr/bin/env python3 import sys import re num_values = dict( one="1", two="2", three="3", four="4", five="5", six="6", seven="7", eight="8", nine="9", ) patterns = "one two three four five six seven eight nine 1 2 3 4 5 6 7 8 9".split() sum = 0 for line in sys.stdin: first = len(line) last = 0 nums = [] for pat in patterns: for m in re.finditer(pat, line): nums.append((m.start(), pat)) nums.sort() first_word = nums[0][1] last_word = nums[-1][1] first_word = num_values.get(first_word, first_word) last_word = num_values.get(last_word, last_word) value = int(first_word + last_word) sum += value print(sum)