Problem:
Score : 100 points

Problem Statement

You are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd format. (For example, April 30, 2019 is represented as 2019/04/30.)

Write a program that prints Heisei if the date represented by S is not later than April 30, 2019, and prints TBD otherwise.

Constraints

S is a string that represents a valid date in the year 2019 in the yyyy/mm/dd format.

Input

Input is given from Standard Input in the following format:

S

Output

Print Heisei if the date represented by S is not later than April 30, 2019, and print TBD otherwise.

Sample Input 1

2019/04/30

Sample Output 1

Heisei

Sample Input 2

2019/11/01

Sample Output 2

TBD

Solution in Haskell (GHC 7.10.3) (judge verdict: Runtime Error)

{-# LANGUAGE BangPatterns          #-}

import Control.Monad
import qualified Data.Vector.Unboxed as V


main = do
    [a,b,q] <- map read . words <$> getLine
    vss <- (\x->V.fromList $ (-2*10^10):x ++ [2*10^10]) <$> replicateM a readLn 
    vts <- (\x->V.fromList $ (-2*10^10):x ++ [2*10^10]) <$> replicateM b readLn 
    vxs <- (\x->V.fromList $ x) <$> replicateM q readLn 
    let as = V.toList $ V.map (solve vss vts) vxs
    sequence_ [print $ a | a <- as]

solve :: V.Vector Int -> V.Vector Int -> Int -> Int
solve vss vts x = minimum [d n|n <-ns]
    where 
        !ns = toPair (bIdxSrch vss x (0,V.length vss -1)) (bIdxSrch vts x (0,V.length vts -1))
        !d = \(i,j) -> min (abs(x - (V.unsafeIndex vss i)) + abs ((V.unsafeIndex vss i) - (V.unsafeIndex vts j))) (abs (x - (V.unsafeIndex vts j) ) + abs((V.unsafeIndex vss i) - (V.unsafeIndex vts j)))

toPair :: (Int,Int) -> (Int,Int) -> [(Int,Int)]
toPair (a,b) (c,d) = [(a,c),(a,d),(b,c),(b,d)]

bIdxSrch :: V.Vector Int -> Int -> (Int,Int) -> (Int,Int) 
bIdxSrch vs x (!l,!r)
    | midIdx == l = (l,l+1)
    |  x <= midVal = bIdxSrch vs x (l, midIdx)
    | otherwise = bIdxSrch vs x (midIdx, r)
        where
            !midIdx = (r-l) `div` 2 + l
            !midVal = V.unsafeIndex vs midIdx