/* * TemplateCS * Copyright (C) 2014-2016 Markus Himmel * This file is distributed under the terms of the MIT license */ //#define CodeJam #define CodeForces using System; using System.Linq; using System.IO; using System.Text; using System.Collections.Generic; namespace ProgrammingCompetitions { class Program { #region GCJ #if CodeJam private static bool DEBUG = false; static void debug() { } static string solveCase(int num) { checked { return null; } } #endif #endregion #region CodeForces #if CodeForces #if DEBUG static Queue testInput = new Queue(string.Format(@" 1 3 1 3 1 4 1 3 2 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 abc ").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); #endif static object Solve() { checked { var a = readMany(); var b = read().ToCharArray(); return b.Length * b.Select(c => a[c - 'a']).Max(); } } #endif #endregion // Everything after this comment is template code private static T read() { return (T)Convert.ChangeType(read(), typeof(T)); } private static T[] readMany() { return readMany(' '); } private static _[] readMany<_>(params char[] ___) { return read().Split(___).Select(__ => (_)Convert.ChangeType(__, typeof(_))).ToArray(); } private static string[] readMany() { return readMany(); } private static T[][] readMany(int n) { T[][] res = new T[n][]; for (int i = 0; i < n; i++) { res[i] = readMany(); } return res; } private static T[][] readField(int height, Func map) { T[][] res = new T[height][]; for (int _ = 0; _ < height; _++) { res[_] = read().Select(c => map(c)).ToArray(); } return res; } private static char[][] readField(int height) { return readField(height, c => c); } private static T[][] readField(int height, Dictionary dic) { return readField(height, c => dic[c]); } private static void read(out T1 t1) { var vals = readMany(); t1 = (T1)Convert.ChangeType(vals[0], typeof(T1)); } private static void read(out T1 t1, out T2 t2) { var vals = readMany(); t1 = (T1)Convert.ChangeType(vals[0], typeof(T1)); t2 = (T2)Convert.ChangeType(vals[1], typeof(T2)); } private static void read(out T1 t1, out T2 t2, out T3 t3) { var vals = readMany(); t1 = (T1)Convert.ChangeType(vals[0], typeof(T1)); t2 = (T2)Convert.ChangeType(vals[1], typeof(T2)); t3 = (T3)Convert.ChangeType(vals[2], typeof(T3)); } private static void read(out T1 t1, out T2 t2, out T3 t3, out T4 t4) { var vals = readMany(); t1 = (T1)Convert.ChangeType(vals[0], typeof(T1)); t2 = (T2)Convert.ChangeType(vals[1], typeof(T2)); t3 = (T3)Convert.ChangeType(vals[2], typeof(T3)); t4 = (T4)Convert.ChangeType(vals[3], typeof(T4)); } private static void read(out T1 t1, out T2 t2, out T3 t3, out T4 t4, out T5 t5) { var vals = readMany(); t1 = (T1)Convert.ChangeType(vals[0], typeof(T1)); t2 = (T2)Convert.ChangeType(vals[1], typeof(T2)); t3 = (T3)Convert.ChangeType(vals[2], typeof(T3)); t4 = (T4)Convert.ChangeType(vals[3], typeof(T4)); t5 = (T5)Convert.ChangeType(vals[4], typeof(T5)); } static Func DP(Func, TResult> f) { var cache = new Dictionary, TResult>(); Func res = null; res = (t1) => { var key = Tuple.Create(t1); if (!cache.ContainsKey(key)) cache.Add(key, f(t1, res)); return cache[key]; }; return res; } static Func DP(Func, TResult> f) { var cache = new Dictionary, TResult>(); Func res = null; res = (t1, t2) => { var key = Tuple.Create(t1, t2); if (!cache.ContainsKey(key)) cache.Add(key, f(t1, t2, res)); return cache[key]; }; return res; } static Func DP(Func, TResult> f) { var cache = new Dictionary, TResult>(); Func res = null; res = (t1, t2, t3) => { var key = Tuple.Create(t1, t2, t3); if (!cache.ContainsKey(key)) cache.Add(key, f(t1, t2, t3, res)); return cache[key]; }; return res; } static Func DP(Func, TResult> f) { var cache = new Dictionary, TResult>(); Func res = null; res = (t1, t2, t3, t4) => { var key = Tuple.Create(t1, t2, t3, t4); if (!cache.ContainsKey(key)) cache.Add(key, f(t1, t2, t3, t4, res)); return cache[key]; }; return res; } static IEnumerable single(T it) { yield return it; } static IEnumerable range(long first, long last, long step = 1) { for (long i = first; i <= last; i += step) { yield return i; } } static IEnumerable range(int first, int last, int step = 1) { for (int i = first; i <= last; i += step) { yield return i; } } static T id(T a) { return a; } public static T[][] mkarr(int x, int y) { T[][] res = new T[x][]; for (int i = 0; i < x; i++) { res[i] = new T[y]; } return res; } public static T[][][] mkarr(int x, int y, int z) { T[][][] res = new T[x][][]; for (int i = 0; i < x; i++) { res[i] = new T[y][]; for (int j = 0; j < y; j++) { res[i][j] = new T[z]; } } return res; } static bool[] tf = new[] { true, false }; #if CodeJam static void Main(string[] args) { if (DEBUG) { debug(); } else { Initialize(); SolveAll(solveCase); } Console.ReadKey(); } private static StreamReader inf; private static StreamWriter outf; private delegate void o(string format, params object[] args); private static o Output; public static void Initialize() { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("File name: "); string name = Console.ReadLine(); inf = new StreamReader($"D:\\Users\\marku\\Downloads\\{name}.in"); outf = new StreamWriter($"D:\\Users\\marku\\Downloads\\{name}.out"); Console.ForegroundColor = ConsoleColor.White; Output = highlightedPrint; Output += outf.WriteLine; } private static void highlightedPrint(string format, params object[] args) { ConsoleColor prev = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(format, args); Console.ForegroundColor = prev; } public static void SolveAll(Func calc) { int cases = int.Parse(inf.ReadLine()); for (int _ = 1; _ <= cases; _++) { Output($"Case #{_}: {calc(_)}"); } inf.Close(); outf.Close(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Eureka!"); } private static string read() { return inf.ReadLine(); } #endif #if CodeForces static string asString(object s) { if (s is double) { return ((double)s).ToString("0.000000000", System.Globalization.CultureInfo.InvariantCulture); } return s.ToString(); } static void Main(string[] args) { #if DEBUG var sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif object o = Solve(); if (o != null) { string s = null; if (o is System.Collections.IEnumerable) { s = string.Join(" ", ((System.Collections.IEnumerable)o).OfType().Select(x => asString(x))); } else { s = asString(o); } if (!string.IsNullOrEmpty(s)) { Console.WriteLine(s); } } #if DEBUG sw.Stop(); Console.WriteLine(sw.Elapsed); Console.ReadKey(); #endif } private static string read() { #if !DEBUG return Console.ReadLine(); #else return testInput.Dequeue(); #endif } #endif } public static class ExtensionMethods { public static IEnumerable Of(this int n, Func gen) { for (int i = 0; i < n; i++) { yield return gen(); } } public static IEnumerable Of(this int n, Func gen) { for (int i = 0; i < n; i++) { yield return gen(i); } } public static IEnumerable Of(this int n, T gen) { for (int i = 0; i < n; i++) { yield return gen; } } public static IEnumerable Cartesian(this IEnumerable first, IEnumerable second, Func collector) { return first.SelectMany(f => second.Select(s => collector(f, s))); } public static IEnumerable> Cartesian(this IEnumerable first, IEnumerable second) { return first.Cartesian(second, Tuple.Create); } public static IEnumerable> CartesianE(this IEnumerable first, IEnumerable second) { // Calling CartesianE prevents selection of the wrong overload of Cartesian when you want a tuple of tuples to be returned return first.Cartesian(second); } public static IEnumerable> Cartesian(this IEnumerable> first, IEnumerable second) { return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, y)); } public static IEnumerable> Cartesian(this IEnumerable> first, IEnumerable second) { return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, y)); } public static IEnumerable> Cartesian(this IEnumerable> first, IEnumerable second) { return first.Cartesian(second, (x, y) => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4, y)); } public static IEnumerable> Cartesian(this IEnumerable> source) { IEnumerable> res = source.First().Select(x => single(x)); foreach (IEnumerable next in source.Skip(1)) { res = res.Cartesian(next, (sofar, n) => sofar.Concat(single(n))); } return res; } public static IEnumerable> Pow(this IEnumerable it, int num) { return Enumerable.Repeat(it, num).Cartesian(); } public static IEnumerable Demask(this IEnumerable> inp) { foreach (var pair in inp) { if (pair.Item2) { yield return pair.Item1; } } } public static IEnumerable>> Partition(this IEnumerable source, int groups) { foreach (var part in Enumerable.Range(0, groups).Pow(source.Count()).Select(x => x.ToArray())) { yield return Enumerable.Range(0, groups).Select(x => source.Where((item, idx) => part[idx] == x)); } } public static IEnumerable> Combinations(this IEnumerable it) { foreach (var conf in new[] { true, false }.Pow(it.Count())) { yield return it.Zip(conf, Tuple.Create).Demask(); } } private static IEnumerable single(T it) { yield return it; } private static IEnumerable ExceptSingle(this IEnumerable first, T it, IEqualityComparer comp = null) { comp = comp ?? EqualityComparer.Default; bool seen = false; foreach (T a in first) { if (!seen && comp.Equals(a, it)) { seen = true; } else { yield return a; } } } public static IEnumerable> Permutations(this IEnumerable it) { if (it.Count() < 2) { yield return it; yield break; } foreach (T first in it) { foreach (IEnumerable part in Permutations(it.ExceptSingle(first))) { yield return single(first).Concat(part); } } } public static T[][] Rho(this IEnumerable source, int x, int y) { T[][] res = Program.mkarr(x, y); int i = 0, j = 0; while (true) { foreach (T item in source) { res[i][j] = item; j++; if (j == y) { j = 0; i++; if (i == x) break; } } if (i == x) break; } return res; } public static T[][][] Rho(this IEnumerable source, int x, int y, int z) { T[][][] res = Program.mkarr(x, y, z); int i = 0, j = 0, k = 0; while (true) { foreach (T item in source) { res[i][j][k] = item; k++; if (k == z) { k = 0; j++; if (j == y) { j = 0; i++; if (i == x) { break; } } } } if (i == x) break; } return res; } } }