#54519: Python解答


kita197 (KK)


#f866
from fractions import Fraction
from collections import Counter
import sys
lines = sys.stdin.read().splitlines()
i = 0
n = len(lines)
def next_non_empty():
    global i
    while i < n and not lines[i].strip():
        i += 1
    if i >= n:
        return None
    line = lines[i]
    i += 1
    return line
while True:
    line = next_non_empty()
    if line is None:
        break
    parts = line.split()
    if len(parts) != 2:
        continue
    M, S = parts
    M = int(M)
    cnt = Counter()
    total = 0
    read = 0
    while read < M:
        line = next_non_empty()
        if line is None:
            break
        c, num = line.split()
        num = int(num)
        cnt[c] += num
        total += num
        read += 1
    prob = Fraction(1, 1)
    remain = total
    ok = True
    for ch in S:
        if cnt[ch] <= 0:
            ok = False
            break
        prob *= Fraction(cnt[ch], remain)
        cnt[ch] -= 1
        remain -= 1
    if not ok:
        print(1)
        continue
    if prob.denominator == 1:
        print(1-prob.numerator, end="")
    else:
        print(1-prob, end="")

    if prob >= Fraction(1, 2):
        print(" DD真幸運!!我要下注!")
    else:
        print()