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 C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			D();
		}

		public static void D()
		{
			Scanner cin = new Scanner();
			int a = cin.NextInt();
			int b = cin.NextInt();
			int q = cin.NextInt();
			long[] s = new long[a];
			for (int n = 0; n < a; ++n) {
				s[n] = cin.NextInt();
			}

			long[] t = new long[b];
			for (int n = 0; n < b; ++n) {
				t[n] = cin.NextInt();
			}

			long[] x = new long[q];
			for (int n = 0; n < q; ++n) {
				x[n] = cin.NextInt();
			}

			for (int n = 0; n < q; ++n) {
				long start = x[n];
				
				if (s[0] > start) {
					if (t[0] > start) {
						Console.WriteLine(Math.Max(t[0] - start, s[0] - start));
					} else if (t[b - 1] < start) {
						Console.WriteLine(Math.Min(
							s[0] - start * 2 + start - t[b - 1],
							start - t[b - 1] * 2 + s[0] - start));
					} else {
						int indexT = Array.IndexOf(t, t.First(h => h >= start));
						long t1 = t[indexT];
						long t0 = t[indexT - 1];

						long[] answers = new long[2];

						{
							answers[0] = Math.Abs(start - t0)
								+ Math.Abs(s[0] - t0);
						}

						{
							answers[1] = Math.Abs(start - t1)
								+ Math.Abs(s[0] - t1);
						}

						Console.WriteLine(answers.Min());
					}
				} else if (t[0] > start) {
					if (s[a - 1] < start) {
						Console.WriteLine(Math.Min(
							t[0] - start * 2 + start - s[b - 1],
							start - s[b - 1] * 2 + t[0] - start));
					} else {
						int indexS = Array.IndexOf(s, s.First(h => h >= start));
						long s1 = s[indexS];
						long s0 = s[indexS - 1];
						long[] answers = new long[2];

						{
							answers[0] = Math.Abs(start - s0)
								+ Math.Abs(t[0] - s0);
						}

						{
							answers[1] = Math.Abs(start - s1)
								+ Math.Abs(t[0] - s1);
						}

						Console.WriteLine(answers.Min());
					}
				} else if (s[a - 1] < start) {
					if (t[b - 1] < start) {
						Console.WriteLine(Math.Max(start - t.Last(), start - s.Last()));
					} else {
						int indexT = Array.IndexOf(t, t.First(h => h >= start));
						long t1 = t[indexT];
						long t0 = t[indexT - 1];

						long[] answers = new long[2];

						{
							answers[0] = Math.Abs(start - t0)
								+ Math.Abs(s.Last() - t0);
						}

						{
							answers[1] = Math.Abs(start - t1)
								+ Math.Abs(s.Last() - t1);
						}

						Console.WriteLine(answers.Min());
					}
				} else if (t[b - 1] < start) {
					int indexS = Array.IndexOf(s, s.First(h => h >= start));
					long s1 = s[indexS];
					long s0 = s[indexS - 1];
					long[] answers = new long[2];

					{
						answers[0] = Math.Abs(start - s0)
							+ Math.Abs(t[b - 1] - s0);
					}

					{
						answers[1] = Math.Abs(start - s1)
							+ Math.Abs(t[b - 1] - s1);
					}

					Console.WriteLine(answers.Min());
				} else {
					long[] answers = new long[4];
					int indexT = Array.IndexOf(t, t.First(h => h >= start));
					int indexS = Array.IndexOf(s, s.First(h => h >= start));
					long t1 = t[indexT];
					long t0 = t[indexT - 1];
					long s1 = s[indexS];
					long s0 = s[indexS - 1];
					{
						int it2 = Array.IndexOf(t, t.First(h => h >= s1));
						answers[0] = Math.Min(
							s1 - start + t[it2] - s1,
							s1 - start + s1 - t[it2 - 1]);
					}

					{
						int it2 = Array.IndexOf(t, t.First(h => h >= s0));
						answers[1] = Math.Min(
							start - s0 + t[it2] - s1,
							start - s0 + s1 - t[it2 - 1]);
					}

					{
						int is2 = Array.IndexOf(s, s.First(h => h >= t1));
						answers[2] = Math.Min(
							t1 - start + s[is2] - t1,
							t1 - start + t1 - s[is2 - 1]);
					}

					{
						int is2 = Array.IndexOf(s, s.First(h => h >= t0));
						answers[3] = Math.Min(
							start - t0 + s[is2] - t1,
							start - t0 + t1 - s[is2 - 1]);
					}

					Console.WriteLine(answers.Min());
				}
			}
		}

		
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}