{"raw_statement":[{"iden":"problem statement","content":"In a string fair, they determine the _beauty_ of a non-empty string $S$ consisting of lowercase English letters.\nThe beauty of string $S$ equals the sum of $N$ scores determined by $N$ criteria. For $i = 1, 2, \\ldots, N$, the score determined by the $i$\\-th criterion is \"the number of occurrences of a string $T_i$ (of length **at most $3$** given in the Input) in $S$ as a consecutive subsequence\" multiplied by $P_i$.\nPrint the maximum possible beauty of a **non-empty** string $S$ consisting of lowercase English letters. If it is possible to obtain infinitely large beauty, print `Infinity` instead.\nHere, the number of occurrences of a string $V$ in a string $U = U_1U_2\\ldots U_{|U|}$ as a consecutive subsequence is defined to be the number of integers $i$ such that $1 \\leq i \\leq |U|-|V|+1$ and $U_iU_{i+1}\\ldots U_{i+|V|-1} = V$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 18278$\n*   $N$ is an integer.\n*   $T_i$ is a string of length between $1$ and $3$ consisting of lowercase English letters.\n*   $i \\neq j \\Rightarrow T_i \\neq T_j$\n*   $-10^9 \\leq P_i \\leq 10^9$\n*   $P_i$ is an integer."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$T_1$ $P_1$\n$T_2$ $P_2$\n$\\vdots$\n$T_N$ $P_N$"},{"iden":"sample input 1","content":"3\na -5\nab 10\nba -20"},{"iden":"sample output 1","content":"Infinity\n\nFor example, if $S =$ `abzabz`:\n\n*   The score determined by the $1$\\-st criterion is $2 \\times (-5) = -10$ points, because `a` occurs twice in $S$ as a consecutive subsequence.\n*   The score determined by the $2$\\-nd criterion is $2 \\times 10 = 20$ points, because `ab` occurs twice in $S$ as a consecutive subsequence.\n*   The score determined by the $3$\\-rd criterion is $0 \\times (-20) = 0$ points, because `ba` occurs $0$ times in $S$ as a consecutive subsequence.\n\nThus, the beauty of $S$ is $(-10) + 20 + 0 = 10$.\nAs another example, if $S =$ `abzabzabz`:\n\n*   The score determined by the $1$\\-st criterion is $3 \\times (-5) = -15$ points, because `a` occurs $3$ times in $S$ as a consecutive subsequence.\n*   The score determined by the $2$\\-nd criterion is $3 \\times 10 = 30$ points, because `ab` occurs $3$ times in $S$ as a consecutive subsequence.\n*   The score determined by the $3$\\-rd criterion is $0 \\times (-20) = 0$ points, because `ba` occurs $0$ times in $S$ as a consecutive subsequence.\n\nThus, the beauty of $S$ is $(-15) + 30 + 0 = 15$.\nIn general, for a positive integer $X$, if $S$ is a concatenation of $X$ copies of `abz`, then the beauty of $S$ is $5X$. Since you can obtain as large beauty as you want, `Infinity` should be printed."},{"iden":"sample input 2","content":"28\na -5\nab 10\nba -20\nbb -20\nbc -20\nbd -20\nbe -20\nbf -20\nbg -20\nbh -20\nbi -20\nbj -20\nbk -20\nbl -20\nbm -20\nbn -20\nbo -20\nbp -20\nbq -20\nbr -20\nbs -20\nbt -20\nbu -20\nbv -20\nbw -20\nbx -20\nby -20\nbz -20"},{"iden":"sample output 2","content":"5\n\n$S = $ `ab` achieves the maximum beauty possible."},{"iden":"sample input 3","content":"26\na -1\nb -1\nc -1\nd -1\ne -1\nf -1\ng -1\nh -1\ni -1\nj -1\nk -1\nl -1\nm -1\nn -1\no -1\np -1\nq -1\nr -1\ns -1\nt -1\nu -1\nv -1\nw -1\nx -1\ny -1\nz -1"},{"iden":"sample output 3","content":"\\-1\n\nNote that $S$ should be a non-empty string."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}