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 PHP7 (7.0.15) (judge verdict: Wrong Answer)

<?php
list($A, $B, $Q) = explode(" ", trim(fgets(STDIN)));
for($i = 0; $i < $A; $i++){
    $aArray[] = trim(fgets(STDIN));
}
array_unshift($aArray, -10**12);
$aArray[] = 10**12;
for($i = 0; $i < $B; $i++){
    $bArray[] = trim(fgets(STDIN));
}
array_unshift($bArray, -10**12);
$bArray[] = 10**12;

for($i = 0; $i < min(2000, $Q); $i++){
    $qArray[] = trim(fgets(STDIN));
}

foreach($qArray as $q){
    $min = 10**18;
    $a = bsl($aArray, $q);
    foreach([$aArray[$a], $aArray[$a+1]] as $a1){
        $b = bsl($bArray, $q);
        $p3 = $bArray[$b]??10**12;
        $p4 = $bArray[$b+1]??10**12;
        $min = min($min, abs($q - $a1) + abs($a1 - $p3));
        $min = min($min, abs($q - $a1) + abs($a1 - $p4));
    }
    $b = bsl($bArray, $q);
    foreach([$bArray[$b], $bArray[$b+1]] as $b1){
        $a = bsl($aArray, $q);
        $p3 = $aArray[$a]??10*10;
        $p4 = $aArray[$a+1]??10*10;
        $min = min($min, abs($q - $b1) + abs($b1 - $p3));
        $min = min($min, abs($q - $b1) + abs($b1 - $p4));
    }
    printf("%d\n", $min);
}

//二分探索　target以下で最大の値の場所を返す
function bsl($nums, $target) {
    $size = count($nums);
    $min = 0; 
    $max = $size - 1;
    while(true){
        $center = floor(($min + $max) / 2);
        $centerValue = $nums[$center];
        if($target == $centerValue){
            return $center;
        }elseif($target > $centerValue){
            $min = $center + 1;
        }else{
            $max = $center;
        }
        if($min == $max){
            $center = floor(($min + $max) / 2);
            $centerValue = $nums[$center];
            if($centerValue == $target){
                return $center;
            }elseif($centerValue < $target){
                return $center;
            }else{
                return $center-1;
            }
        }
    }
}