jiahuimbzuai/CoQuIR huggingface dataset:
//  [javascript]
var MAX_VALUE = 1000;

var inputRaw = require('fs').readFileSync('/dev/stdin', 'utf8');
var rows = inputRaw.trim().split('\n');
var row1 = rows[0].split(' ').map(Number);
var N = row1[0];
var W = row1[1];
var list = rows.slice(1).map(r => r.split(' ').map(Number));
var dp = Array.from({ length: N + 1 }, _ => Array( N * MAX_VALUE + 1).fill(Infinity));
dp[0][0] = 0;

function solve() {

  for (var i = 0; i < N; i++) {
    for (var j = 0; j <= N * MAX_VALUE; j++) {
      if (list[i][1] <= j) {
        var a = dp[i][j - list[i][1]] + list[i][0];
        var b = dp[i][j];
        dp[i + 1][j] = Math.min(a, b);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  var result = 0;
  for (var i = 0; i <= N * MAX_VALUE; i++) if (dp[N][i] <= W) result = i;
  return result;
}

console.log(solve());
//  [javascript]
function main(input){
  const lines = input.split('\n');
  const NW = lines.shift().split(' ').map(x => parseInt(x));
  const N = NW[0]
  const W = NW[1]
  const items = lines.map(line => line.split(' ').map(x => parseInt(x)));

  const first = items.shift();
  const first_weight = first[0];
  const first_value = first[1];
  var value_sum = first_value;
  dp = [0]

  for(var i=1;i<=value_sum;i++){
    dp[i]=first_weight;
  }

  for(var i=0;i<items.length;i++){
    var current_weight = items[i][0];
    var current_value = items[i][1];
    value_sum += current_value;

  //console.log(dp);

    for(var value=value_sum;value>0;value--){

      if(value >= current_value){
        var prev_weight = dp[value - current_value];
        if(dp[value]==undefined){
          dp[value] = current_weight + prev_weight;
        }else{
          dp[value] = Math.min(prev_weight+current_weight, dp[value]);
        }
      }else{
        if(dp[value]==undefined){
          dp[value]=current_weight;
        }else{
          dp[value]=Math.min(current_weight, dp[value]);
        }
     }
    }
  }


  var result = 0;

//  for(var i=value_sum;i>=0;i--){
//    if(dp[i]<=W){
//      result = i;
//      break;
//    }
//  }

  for(var i=dp.length-1;i>=0;i--){
    if(dp[i]<=W){
      result = i;
      break;
    }
  }

  //console.log(dp);

//  console.log(result==90);
  console.log(result);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(row, col,  filler = 0) {
    return Array(row)
        .fill(filler)
        .map(() => Array(col).fill(filler));
}
// ---------------------------------------



function main() {
    let [n, w] = getArray(readline());
    const arr = [];
    const dp = create2DArray(n+1, w+1, 0)

    let c = n;


    while(c--) {
        arr.push(getArray(readline()));
    }

    function solve(n1, w1) {
        //console.log(n1, w1);
        if (n1 < 0 || w1 <= 0) {
            return 0;
        }
        if (dp[n1][w1]) {
            return dp[n1][w1];
        }
        if (w1 >= arr[n1][0]) {
            dp[n1][w1] = Math.max(arr[n1][1] + solve(n1 - 1, w1 - arr[n1][0]), solve(n1 - 1, w1));
        } else {
            dp[n1][w1] = solve(n1 - 1, w1);
        }
        return dp[n1][w1];
    }

    console.log(solve(n-1, w));
}
//  [javascript]
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');

// Your code here!
const max = (a)=>{
    let i = a.length;
    let max=-Infinity;
    while (i--) {
        if (a[i] > max)max = a[i];
    }
    return max;
}
const min = (a)=>{
    let i = a.length;
    let max=Infinity;
    while (i--) {
        if (a[i] < max)max = a[i];
    }
    return max;
}
const Main = (p)=>{
	p = p.split("\n");//2 or more
	//let N = parseInt(p[0]);//N
	const N = parseInt(p[0].split(" ")[0]);//N M
	const W = parseInt(p[0].split(" ")[1]);//N M
	//let h = (p[1].split(" ").map(Number));//a1 a2 a3...
	
	let w = new Array(N);
	let v = new Array(N);
	//let c=new Array(N);
    //let z=new Array(N);
    for(let i=0;i<N;i++){
        let h = (p[i+1].split(" ").map(Number));
        w[i]=h[0];
        v[i]=h[1];
    }
    
    const maxv=30000;
	let m = new Array(N+1);
    //console.log(N,W,w,v);return;
    m[0]=new Array(maxv+1).fill(Infinity);
    m[0][0]=0;
    for(let i=0;i<=N;i++){
        m[i+1]=m[i].concat();
        for(let j=0;j<=maxv;j++){
            if(j-v[i]>=0){
                //console.log(m[i][j-w[i]]+v[i],m[i][j])
                m[i+1][j]=Math.min(m[i][j-v[i]]+w[i],m[i][j]);
            }
            
        }
        //console.log(i,m[i])
    }
	//console.log(m[N][maxv-1]);
	let i=maxv;
	while(m[N][i--]>W);//console.log(m[N][i--]);
	console.log(i+1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [javascript]
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');

// Your code here!
const max = (a)=>{
    let i = a.length;
    let max=-Infinity;
    while (i--) {
        if (a[i] > max)max = a[i];
    }
    return max;
}
const min = (a)=>{
    let i = a.length;
    let max=Infinity;
    while (i--) {
        if (a[i] < max)max = a[i];
    }
    return max;
}
const Main = (p)=>{
	p = p.split("\n");//2 or more
	//let N = parseInt(p[0]);//N
	const N = parseInt(p[0].split(" ")[0]);//N M
	const W = parseInt(p[0].split(" ")[1]);//N M
	//let h = (p[1].split(" ").map(Number));//a1 a2 a3...
	
	let w = new Array(N);
	let v = new Array(N);
	//let c=new Array(N);
    //let z=new Array(N);
    for(let i=0;i<N;i++){
        let h = (p[i+1].split(" ").map(Number));
        w[i]=h[0];
        v[i]=h[1];
    }
    
    const maxv=100;
	let m = new Array(N+1);
    //console.log(N,W,w,v);return;
    m[0]=new Array(maxv+1).fill(Infinity);
    m[0][0]=0;
    for(let i=0;i<=N;i++){
        m[i+1]=m[i].concat();
        for(let j=0;j<=maxv;j++){
            if(j-v[i]>=0){
                //console.log(m[i][j-w[i]]+v[i],m[i][j])
                m[i+1][j]=Math.min(m[i][j-v[i]]+w[i],m[i][j]);
            }
            
        }
        //console.log(i,m[i])
    }
	//console.log(m[N][maxv-1]);
	let i=maxv;
	while(m[N][i--]>W);//console.log(m[N][i--]);
	console.log(i+1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [go]
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,u := input.NextInts()
  dp := make([]int,100002)
  for i:=1;i<100002;i++ { dp[i] = 2*u }
  for i:=0;i<n;i++ {
    w,v := input.NextInts()
    for j:=100001;j>v-1;j-- {
      t := dp[j-v]+w
      if dp[j] > t { dp[j] = t }
    }
  }
  for i:=100001;i>-1;i-- {
    if dp[i] <= u { fmt.Println(i);return }
  }
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int) {
  s := strings.Split(i.NextLine()," ")
  a,_ := strconv.Atoi(s[0])
  b,_ := strconv.Atoi(s[1])
  return a,b
}
//  [go]
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF = math.MaxInt32
var INF64 = math.MaxInt64

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

func main() {
	bf := bufio.NewReader(os.Stdin)
	nw := readLineNums(bf)
	N, W := nw[0], nw[1]
	Ws := make([]int, 0)
	Vs := make([]int, 0)
	for i:=0; i<N; i++ {
		wv := readLineNums(bf)
		Ws = append(Ws, wv[0])
		Vs = append(Vs, wv[1])
	}

	V := 0
	for _, v := range Vs {
		V += v
	}

	dp := make([]int, V+1) // dp[i]: 表示产生价值为i, 需要的最少背包容量
	for i:=1; i<=V; i++ {
		dp[i] = INF
	}

	for i:=0; i<N; i++ {
		wi := Ws[i]
		vi := Vs[i]
		for v:=V; v>=vi; v-- {
			dp[v] = min(dp[v], dp[v-vi]+wi)
		}
	}

	ans := 0
	for i:=0; i<=V; i++ {
		if dp[i] <= W {
			ans = max(ans, i)
		}
	}
	fmt.Println(ans)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	const valueMax = int(1e5)
	const inf = int(1e18)
	N, W := readI(), readI()
	w, v := make([]int, N+1), make([]int, N+1)
	for i := 1; i <= N; i++ {
		w[i], v[i] = readI(), readI()
	}

	//dp[i][j] = iまでの商品を価値j以上で選んだ際の最小の重量
	dp := make([][]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int, valueMax+1)
		for j := 0; j <= valueMax; j++ {
			dp[i][j] = inf
		}
	}
	dp[0][0] = 0
	for i := 0; i <= N; i++ {
		if i == 0 {
			continue
		}
		for j := 1; j <= valueMax; j++ {
			if j-v[i] >= 0 {
				dp[i][j] = min(dp[i-1][j-v[i]]+w[i], dp[i-1][j])
			} else {
				dp[i][j] = dp[i-1][j]
			}
		}
	}
	ans := valueMax
	for dp[N][ans] > W && ans > 0 {
		ans--
	}
	fmt.Println(ans)
}

func min(a ...int) int {
	m := a[0]
	for i := 1; i < len(a); i++ {
		if m > a[i] {
			m = a[i]
		}
	}
	return m
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}
//  [go]
package main

import (
	"fmt"
	"math"
)

var dp [][]int64

func main() {
	var n, w int64
	fmt.Scanf("%d%d", &n, &w)
	weight := make([]int64, n)
	values := make([]int64, n)
	for i := 0; i < int(n); i++ {
		fmt.Scanf("%d%d", &weight[i], &values[i])
	}
	ans := maximumPossibleSumKnapsack2(n, w, values, weight)
	fmt.Println(ans)
}

func createDPTable(n int64, v int64) [][]int64 {
	dp = make([][]int64, n+1)
	for i := range dp {
		dp[i] = make([]int64, v+1)
		for j := range dp[i] {
			dp[i][j] = 1 << 32
		}
	}
	dp[0][0] = 0
	return dp
}

func maximumPossibleSumKnapsack2(n int64, w int64, values []int64, weight []int64) int64 {
	var totalValues int64
	for i := range values {
		totalValues += values[i]
	}
	dp = createDPTable(n, totalValues)
	var ans int64
	for i := totalValues; i >= 0; i-- {
		if solve(n, i, values, weight) <= w {
			ans = int64(i)
			break
		}
	}
	return ans
}

func solve(n int64, v int64, values []int64, weight []int64) int64 {
	if n == 0 {
		if v == 0 {
			return 0
		}
		return 1 << 32
	}
	if dp[n][v] != 1<<32 {
		return dp[n][v]
	}
	ans := solve(n-1, v, values, weight)
	if values[n-1] <= v {
		ans = int64(math.Min(float64(ans), float64(weight[n-1]+solve(n-1, v-values[n-1], values, weight))))
	}
	dp[n][v] = ans
	return ans
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, w int64
	fmt.Scanf("%d%d", &n, &w)
	weight := make([]int64, n)
	values := make([]int64, n)
	for i := 0; i < int(n); i++ {
		fmt.Scanf("%d%d", &weight[i], &values[i])
	}
	ans := maximumPossibleSum(n, w, values, weight)
	fmt.Println(ans)
}

// https://atcoder.jp/contests/dp/tasks/dp_d
func maximumPossibleSum(n int64, w int64, values []int64, weight []int64) int64 {
	dp := make([][]int64, n+1)
	for i := 0; i <= int(n); i++ {
		dp[i] = make([]int64, w+1)
	}
	for i := 1; i <= int(n); i++ {
		for j := 1; j <= int(w); j++ {
			if weight[i-1] > int64(j) {
				dp[i][j] = dp[i-1][j]
			} else {
				dp[i][j] = int64(math.Max(float64(dp[i-1][j]), float64(values[i-1]+dp[i-1][int64(j)-weight[i-1]])))
			}
		}
	}
	return dp[n][w]
}
//  [ruby]
#参考 #4023546 by kamina_zzz
N,W = gets.split.map &:to_i
D = [[0, 0]]
m = 0
N.times {
  w,v = gets.split.map &:to_i
  next if w+m > W
  D[0,D.size].each {|d|
    D << [d[0]+w, d[1]-v] if d[0]+w+m <= W
  }
  m = 0
  D.sort!.uniq! {|d| m>d[1] ? m=d[1] : m}
  m = D[0][0]
}
p -D[-1][1]
//  [ruby]
N, W = gets.split.map(&:to_i)
d = [[0, 0]]

(0..(N-1)).each do
  w, v = gets.split.map(&:to_i)
  next if w > W
  
  (0..(d.size - 1)).each do |i|
    d << [d[i][0] + w, d[i][1] + v] if d[i][0] + w <= W
  end
  d.sort!
  
  idx = 1
  while idx < d.size do
    if d[idx-1][1] >= d[idx][1]
      d.delete_at(idx)
    else
      idx += 1
    end
  end
end

puts d[-1][1]
//  [ruby]
def r;gets.split.map &:to_i;end

N,W = r
DP = [[0,0]] # weight, value

N.times do
  w,v = r
  DP.size.times do |i|
    next if DP[i][0] + w > W
    DP << [DP[i][0] + w, DP[i][1] + v]
  end

  DP.sort!

  i = 0
  while i < DP.size - 1
    unless DP[i][1] < DP[i+1][1]
      DP.delete_at(i+1)
    else
      i += 1
    end
  end
end

p DP[-1][1]
//  [ruby]
N, W = gets.split.map(&:to_i)
wv = N.times.map { gets.split.map(&:to_i) }

dp =[]
dp[0] = [10 ** 9 + 1] * (10 ** 5)
dp[0][0] = 0

1.upto(N) do |i|
  dp[i] = [10 ** 9 + 1] * (10 ** 5)
  0.upto(10 ** 5 - 1) do |j|
    if j - wv[i - 1][1] >= 0
      dp[i][j] = [dp[i - 1][j], dp[i - 1][j - wv[i - 1][1]] + wv[i - 1][0]].min
    else
      dp[i][j] = dp[i - 1][j]
    end
  end
end

(10 ** 5 - 1).downto(0) do |i|
  if dp[N][i] <= W
    puts i
    break
  end
end
//  [ruby]
N, W = gets.split.map(&:to_i)
wv = N.times.map { gets.split.map(&:to_i) }

dp =[]
dp[0] = [10 ** 9 + 1] * (10 ** 5)
dp[0][0] = 0

1.upto(N + 1) do |i|
  dp[i] = [10 ** 9 + 1] * (10 ** 5)
  0.upto(10 ** 5 - 1) do |j|
    if j - wv[i - 1][1] >= 0
      dp[i][j] = [dp[i - 1][j], dp[i - 1][j - wv[i - 1][1]] + wv[i - 1][0]].min
    else
      dp[i][j] = dp[i - 1][j]
    end
  end
end

10000.downto(0) do |i|
  if dp[N + 1][i] <= W
    puts i
    break
  end
end
//  [ruby]
N, W = gets.split.map(&:to_i)
wv = N.times.map { gets.split.map(&:to_i) }

dp =[]
dp[0] = [10 ** 9 + 1] * (10 ** 5)
dp[0][0] = 0

1.upto(N) do |i|
  dp[i] = [10 ** 9 + 1] * (10 ** 5)
  0.upto(10 ** 5 - 1) do |j|
    if j - wv[i - 1][1] >= 0
      dp[i][j] = [dp[i - 1][j], dp[i - 1][j - wv[i - 1][1]] + wv[i - 1][0]].min
    else
      dp[i][j] = dp[i - 1][j]
    end
  end
end

10000.downto(0) do |i|
  if dp[N][i] <= W
    puts i
    break
  end
end
//  [rust]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::min;
fn main() {
    input! { n, cap, wv: [(usize, usize); n] };
    const V: usize = 1_000_00;
    let mut dp = vec![std::usize::MAX; V + 1];
    dp[0] = 0;
    for &(w, v) in &wv {
        for vi in (0..(V + 1)).rev() {
            if dp[vi] == std::usize::MAX {
                continue;
            }
            if vi + v <= V {
                dp[vi + v] = min(dp[vi + v], dp[vi] + w);
            }
        }
    }
    println!(
        "{}",
        dp.iter()
            .enumerate()
            .filter_map(|(v, &w)| if w <= cap { Some(v) } else { None })
            .max()
            .unwrap()
    );
}
//  [rust]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, w) = i.read2::<usize, usize>();
    let mut wv = Vec::new();
    for _ in 0..n {
        wv.push(i.read2::<usize, usize>())
    }
    writeln!(o, "{}", solve(w, &wv)).unwrap();
}
fn solve(w: usize, wv: &[(usize, usize)]) -> usize {
    let mut ws = vec![usize::max_value(); wv.len() * 1000 + 1]; // 現時点でのws[v] は価値vの品物の最小の重さ
    let mut v_max = 0;
    ws[0] = 0;

    for &(wi, vi) in wv {
        for j in (0..v_max + 1).rev() {
            let w_next = min(ws[j + vi], ws[j] + wi);
            if w_next <= w {
                ws[vi + j] = w_next;
                v_max = max(v_max, vi + j);
            }
        }
        for j in 0..vi {
            if ws[vi] < ws[j] {
                ws[j] = ws[vi];
            }
        }
    }
    v_max
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, [ $struct:ident; $( $field:ident ),* ]) => {
        $struct {
            $(
                $field : read_value!($iter),
            )*
        }
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };

    ($iter:expr) => {
        $iter.next().unwrap().parse().expect("Parse error")
    };
}

#[derive(Debug)]
struct Load {
    weight: i64,
    value: i64,
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: i64,
        w: i64,
        loads: [[Load; weight, value]; n as usize]
    }
    let mut cache = BTreeMap::new();
    let v = max_value(&loads, &mut cache, n - 1, w);
    println!("{}", v)
}

fn max_value(loads: &Vec<Load>, cache: &mut BTreeMap<(i64, i64), i64>, k: i64, y: i64) -> i64 {
    if k < 0 || y < 0 {
        0
    } else {
        if let Some(v) = cache.get(&(k, y)) {
            return *v;
        }
        let using = if y - loads[k as usize].weight < 0 {
            0
        } else {
            max_value(loads, cache, k - 1, y - loads[k as usize].weight) + loads[k as usize].value
        };
        let not_using = max_value(loads, cache, k - 1, y);
        let value = i64::max(using, not_using);
        cache.insert((k, y), value);
        value
    }
}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, [ $struct:ident; $( $field:ident ),* ]) => {
        $struct {
            $(
                $field : read_value!($iter),
            )*
        }
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };

    ($iter:expr) => {
        $iter.next().unwrap().parse().expect("Parse error")
    };
}

#[derive(Debug)]
struct Load {
    weight: i64,
    value: i64,
}

use std::collections::HashMap;

fn main() {
    input! {
        n: i64,
        w: i64,
        loads: [[Load; weight, value]; n as usize]
    }
    let mut cache = HashMap::new();
    let v = max_value(&loads, &mut cache, n - 1, w);
    println!("{}", v)
}

fn max_value(loads: &Vec<Load>, cache: &mut HashMap<(i64, i64), i64>, k: i64, y: i64) -> i64 {
    if k < 0 || y < 0 {
        0
    } else {
        if let Some(v) = cache.get(&(k, y)) {
            return *v;
        }
        let using = if y - loads[k as usize].weight < 0 {
            0
        } else {
            max_value(loads, cache, k - 1, y - loads[k as usize].weight) + loads[k as usize].value
        };
        let not_using = max_value(loads, cache, k - 1, y);
        let value = i64::max(using, not_using);
        cache.insert((k, y), value);
        value
    }
}
//  [rust]
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        w: usize,
        items: [(usize, usize); n],
    }

    let inf = 10usize.pow(10);
    let max_v = 1001;
    let mut dp = vec![vec![inf; max_v]; n + 1];
    dp[0][0] = 0;

    for i in 1..=n {
        for j in 0..max_v {
            dp[i][j] = dp[i - 1][j];
            if j >= items[i - 1].1 {
                dp[i][j] = cmp::min(dp[i][j], dp[i - 1][j - items[i - 1].1] + items[i - 1].0);
            }
        }
    }

    let mut ans = 0;
    for i in 0..max_v {
        if dp[n][i] <= w {
            ans = i;
        }
    }
    println!("{}", ans);
}
//  [swift]
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nw = readWords { Int($0)! }
    let n = nw[0]
    let w = nw[1]

    var items = [(w: Int, v: Int)]()
    var totalWeight = 0
    var totalValue = 0
    for _ in 1...n { 
        let wv = readWords { Int($0)! }
        items.append((w: wv[0], v: wv[1]))
        totalWeight += wv[0]
        totalValue += wv[1]
    }

    // ある価値での最小の重さ
    var dp = [Int](repeating: totalWeight, count: totalValue+1)
    dp[0] = 0
    
    for i in 0..<n {
        let item = items[i]
        for value in (0...totalValue).reversed() {
            if value + item.v <= totalValue { 
                dp[value+item.v] = min(dp[value+item.v], dp[value]+item.w)
            }
        }
    }

    let ans = dp.enumerated().filter { $0.1 <= w }
    print(ans.last!.0)
}


main()
//  [swift]
let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let W = input[1]

var weights: [Int] = .init(repeating: 0, count: N)
var values: [Int] = .init(repeating: 0, count: N)

for i in 0..<N {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  weights[i] = inp[0]
  values[i] = inp[1]
}

let V = values.reduce(0, +)

var dp: [[Int]] = .init(repeating: .init(repeating: .max, count: V + 1), count: N + 1)
dp[0][0] = 0
for i in 1...N {
  for j in 0...V {
   	let prev = j - values[i - 1]
    if prev < 0 || dp[i-1][prev] == .max {
      dp[i][j] = dp[i-1][j]
      continue
    }
    dp[i][j] = min(dp[i-1][prev] + weights[i - 1], dp[i-1][j])
  }
}
for j in (0..<dp[N].count).reversed() {
  if dp[N][j] <= W {
    print(j)
    break
  }
}
//  [swift]
/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
  	// func lastIndex(where predicate: (Element) throws -> Bool) rethrows -> Int?
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
      	for i in stride(from: count - 1, through: 0, by: -1) {
          	if predicate(self[i]) {
              	return i
            }
        }
      	return nil
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}

/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let W = input[1]

var dp = Array(repeating: 1_000_000_000 + 1, count: 1_000 * N + 1)
dp[0] = 0

for _ in 0 ..< N {
    let knapsack = readLine()!.split(separator: " ").map { Int($0)! }
    let weight = knapsack[0]
    let value = knapsack[1]

    for i in stride(from: 1_000 * N, through: value, by: -1) {
        dp[i] = min(dp[i], dp[i - value] + weight)
    }
}

print(dp.lastIndex { $0 <= W }!)
//  [swift]
let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let W = input[1]

var weights: [Int] = .init(repeating: 0, count: N)
var values: [Int] = .init(repeating: 0, count: N)

for i in 0..<N {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  weights[i] = inp[0]
  values[i] = inp[1]
}

var dp: [[Int]] = .init(repeating: .init(repeating: 0, count: W + 1), count: N + 1)

for i in 1...N {
  for j in 1...W {
   	let prev = j - weights[i - 1]
    if prev < 0 {
      dp[i][j] = dp[i-1][j]
      continue
    }
    dp[i][j] = max(dp[i-1][prev] + values[i - 1], dp[i-1][j])
  }
}
print(dp[N][W])
//  [swift]
/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
        for i in (0 ..< self.count).reverse() {
            if predicate(self[i]) {
                return i
            }
        }
        return nil
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}

/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let W = input[1]

var dp = Array(repeating: 1_000_000_000 + 1, count: 1_000 * N + 1)
dp[0] = 0

for _ in 0 ..< N {
    let knapsack = readLine()!.split(separator: " ").map { Int($0)! }
    let weight = knapsack[0]
    let value = knapsack[1]

    for i in (value ... 1_000 * N).reversed() {
        dp[i] = min(dp[i], dp[i - value] + weight)
    }
}

print(dp.lastIndex { $0 <= W }!)
//  [typescript]
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf8');

// Your code here!
const max = (a)=>{
    let i = a.length;
    let max=-Infinity;
    while (i--) {
        if (a[i] > max)max = a[i];
    }
    return max;
}
const min = (a)=>{
    let i = a.length;
    let max=Infinity;
    while (i--) {
        if (a[i] < max)max = a[i];
    }
    return max;
}
const Main = (p)=>{
	p = p.split("\n");//2 or more
	//let N = parseInt(p[0]);//N
	const N = parseInt(p[0].split(" ")[0]);//N M
	const W = parseInt(p[0].split(" ")[1]);//N M
	//let h = (p[1].split(" ").map(Number));//a1 a2 a3...
	
	let w = new Array(N);
	let v = new Array(N);
	//let c=new Array(N);
    //let z=new Array(N);
    for(let i=0;i<N;i++){
        let h = (p[i+1].split(" ").map(Number));
        w[i]=h[0];
        v[i]=h[1];
    }
    
    const maxv=100000;
	let m = new Array(N+1);
    //console.log(N,W,w,v);return;
    m[0]=new Array(maxv+1).fill(Infinity);
    m[0][0]=0;
    for(let i=0;i<=N;i++){
        m[i+1]=m[i].concat();
        for(let j=0;j<=maxv;j++){
            if(j-v[i]>=0){
                //console.log(m[i][j-w[i]]+v[i],m[i][j])
                m[i+1][j]=Math.min(m[i][j-v[i]]+w[i],m[i][j]);
            }
            
        }
        //console.log(i,m[i])
    }
	//console.log(m[N][maxv-1]);
	let i=maxv;
	while(m[N][i--]>W);//console.log(m[N][i--]);
	console.log(i+1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
//  [typescript]
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const itemNum = rule[0];
  const weightMax = rule[1];

  const data: any = lines.map((line) => {
    return line.split(" ").map((int) => parseInt(int));
  });

  const dp = [];
  dp.push(new Array(weightMax + 1).fill(0));
  for (let i = 0; i < itemNum; i++) {
    dp.push(new Array(weightMax + 1).fill(-1));
  }

  for (let i = 0; i < itemNum; i++) {
    for (let w = 0; w <= weightMax; w++) {
      if (w - data[i][0] >= 0) {
        dp[i + 1][w] = Math.max(
          dp[i + 1][w],
          dp[i][w - data[i][0]] + data[i][1]
        );
      }
      dp[i + 1][w] = Math.max(dp[i + 1][w], dp[i][w]);
    }
  }

  console.log(Math.max.apply(null, dp[itemNum]));
});
//  [python]
S = input()

if S <= "2019/04/30":
    print("Heisei")
else:
    print("TBD")
//  [python]
s = input()
if int(s[5:7]) > 4:
  print("TBD")
else:
  print("Heisei")
//  [python]
y,m,d = map(int,input().split("/"))
if y <= 2018:
    print("Heisei")
elif y >= 2020:
    print("TBD")
elif y == 2019 and m <= 4:
    print("Heisei")
else:
    print("TBD")
//  [python]
s = input()

year = s[:4]
mo = s[5:7]
da = s[8:]

if year < 2019:
  ans = "Heisei"
elif year == 2019 and mo<= 4:
  ans ='Heisei'
else:
  ans = 'TBD'
print(ans)
//  [python]
s = map(str,input().split())
if int(s[5]) == 1:
  print("TBD")
elif int(s[6]) <= 4:
  print("Heisei")
else:
  print("TBD")
//  [python]
s = [int(x) for x in input().split("/")]

if s[1] < 4:
  print("Heisei")
elif s[1] == 4 and s[2] < 30:
  print("Heisei")
else:
  print("TBD")
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] str = br.readLine().split("/");
		int y = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);
		if(y>2019 || (y<=2019 && m>4)){
			System.out.println("TBD");
		}else{
			System.out.println("Heisei");
		}
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String[] s = sc.next().split("/");
    int year = Integer.parseInt(s[0]);
    int month = Integer.parseInt(s[1]);
    int day = Integer.parseInt(s[2]);
    String result = "TBD";
    if (year < 2019) result = "Heisei";
    else if (year == 2019 && month < 4) result = "Heisei";
    else if (year == 2019 && month == 4 && day <= 30) result = "Heisei";
    System.out.println(result);
  }
}
//  [java]
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String S = in.next();

            int yyyy = Integer.parseInt(S.substring(0, 4));
            int mm = Integer.parseInt(S.substring(5, 7));
            int dd = Integer.parseInt(S.substring(8, 10));

            System.out.println(isHeisei(yyyy, mm, dd) ? "Heisei" : "TBD");
        }
    }

    private static boolean isHeisei(int yyyy, int mm, int dd) {
        if (yyyy < 2019) {
            return true;
        }
        if (yyyy > 2019) {
            return false;
        }
        if (dd < 5) {
            return true;
        }
        return false;
    }
}
//  [java]
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
		s.replaceAll("/", "");
      	if(s.compareTo("20190430") <= 0) System.out.println("Heisei");
        else System.out.println("TBD");
    }
}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		String t="";
		t+=s.charAt(5);
		t+=s.charAt(6);
		int a=Integer.parseInt(t);
		System.out.println(a);
		if(a<=04) System.out.println("Heisei");
		else System.out.println("TBD");
	}

}
//  [cpp]
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ch[15];
int main()
{
  scanf("%s",ch+1);
  int a=0;
  for(int i=1;i<=4;i++)
    a=a*10+ch[i]-'0';
  if(a<2019){puts("Heisei");return 0;}
  if(a>2019){puts("TBD");return 0;}
  a=(ch[6]-'0')*10+ch[7]-'0';
  if(a<4){puts("Heisei");return 0;}
  if(a>4){puts("TBD");return 0;}
  a=(ch[9]-'0')*10+ch[10]-'0';
  if(a<=30){puts("Heisei");return 0;}
  else {puts("TBD");return 0;}
}
//  [cpp]
#include <stdio.h>

int main(){
	int yyyy, mm, dd;
	scanf("%d/%d/%d", &yyyy, &mm, &dd);

	if (yyyy >= 2019 && mm >= 5) {
		printf("TBD"); 
	}
	else {
		printf("Heisei");
	}

	return 0;
}
//  [cpp]
#include <cstdio>
using namespace std;

int num_of(char ch){return ch-'0';}
int main(){
  char buf[100];
  scanf("%s", buf);
  int y = num_of(buf[0])*1000 + num_of(buf[1])*100 + num_of(buf[2])*10 + num_of(buf[3]);
  int m = num_of(buf[5])*10 + num_of(buf[6]);
  int d = num_of(buf[8])*10 + num_of(buf[9]);
  bool flag;
  if(y>2019){
    flag = true;
  }else if(y<2019){
    flag = false;
  }else if(m>4){
    flag = true;
  }else if(m<4){
    flag = false;
  }else if(d>30){
    flag = true;
  }else if(d<=30){
    flag = false;
  }
  printf("%s", flag ? "TBD" : "Heisei");
  return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	string s;
	cin >> s;
	if((s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0') >= 2019){
		if((s[5]-'0')*10+(s[6]-'0') >= 4){
			if((s[8]-'0')*10+(s[9]-'0') >= 30){
				cout << "Heisei" << endl;
				return 0;
			}
		}
	}
	cout << "TBD" << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	string s;
	cin >> s;
	if((s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0') >= 2019){
		if((s[5]-'0')*10+(s[6]-'0') >= 4){
			if((s[8]-'0')*10+(s[9]-'0') >= 30){
				cout << "Heisei" << endl;
			}else{
				cout << "TBD" << endl;
			}
		}else{
			cout << "TBD" << endl;
		}
	}else{
		cout << "TBD" << endl;
	}
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	string s;
	cin >> s;
	if((s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0') >= 2019){
		if((s[5]-'0')*10+(s[6]-'0') >= 4){
			if((s[8]-'0')*10+(s[9]-'0') >= 30){
				cout << "Heisei" << endl;
			}else{
				cout << "TBD" << endl;
			}
		}
	}
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int y, m, d;
    int ans;

    scanf("%d/%d/%d", &y, &m, &d);

    if (y >= 2019 && m >= 5) {
        printf("TBD\n");
    } else {
        printf("Heisei\n");
    }

    return 0;
}
//  [c]
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long*)a>*(long long *)b )return 1;
    return -1;
}
int main()
{   int i,j,a,b,x,y,n,m,k;
char s[11];
    scanf("%s",s);
    char h[11]="2019/04/30";
    if(strcmp(s,h)<=0)
    printf("Heisei");
    else printf("TBD");

    return 0;
}
//  [c]
#include <stdio.h>
int main(void){
    unsigned int y=0,m=0,d=0;
    scanf("%4d/%2d/%2d",&y,&m,&d);
    if(y<2019 ){
        printf("Heisei");
    }else  if(m<5){
        printf("Heisei");
    }else{
        printf("TBD");
    }
    return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  char s[100];
  scanf("%s",s);
  if(s[6]<='4'){
    printf("Heisei\n");
  }else if(s[6]>='5'){
    printf("TBD\n");
  }
  return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  char s[100];
  scanf("%s",s);
  if(s[6]<='4'){
    printf("Heisei\n");
  }else{
    printf("TBD\n");
  }
  return 0;
}
//  [c]
#include<stdio.h>

int main(void){
  char s[100];
  scanf("%s",s);
  if(s[6]<=4){
    printf("Heisei\n");
  }else{
    printf("TBD\n");
  }
  return 0;
}
//  [javascript]
function Main(input) {
  input = input.trim()
  input = input.split("/").map(Number);
  if(input[1]<=4) console.log("Heisei");
  else console.log("TBD")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
  	input = input.trim();
  
    if(input > "2019/04/30"){
    console.log("TBD");
    }else{
    console.log("Heisei");
    }
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var S = input[0].split("/");
  var ans = "Heisei";
  if(parseInt(S[0])>=2020||(parseInt(S[0])>=2019&&parseInt(S[1])>=5)){
    ans ="TBD";
  }


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function main(input) {
  const args = input.split('/').map(n => parseInt(n, 10));
  const M = args[1];
  
  if (M >= 4) {
    console.log('TBD');
  } else {
    console.log('Heisei');
  }
  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");
stdin = stdin.trim().split("\n").reverse();
function input(){return stdin.pop()}
var stdout = [];


s = input().split("/")
if (parseInt(s[1], 10) < 5){
    stdout.push("Heisei")
}else{
    stdout.push("TBD")
}


console.log(stdout);
//  [javascript]
function Main(input) {
  input = input.trim()
  input = input.split("/").map(Number);
  if(input[1]<=5) console.log("Heisei");
  else console.log("TBD")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	ymd := strings.Split(s, "/")
	y, _ := strconv.Atoi(ymd[0])
	m, _ := strconv.Atoi(ymd[1])
	d, _ := strconv.Atoi(ymd[2])
	if y <= 2019 && m <= 4 && d <= 30 {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}
//  [go]
package main

import (
	"fmt"
	"time"
)

func main() {
	var s string
	fmt.Scan(&s)

	layout := "2006/01/02"
	date, _ := time.Parse(layout, s)
	if date.After(time.Date(2019, 4, 30, 0, 0, 0, 0, time.UTC)) {
		fmt.Println("TBD")
	} else {
		fmt.Println("Heisei")
	}
}
//  [go]
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scan(&s)
  ans := "TBD"
  if s[6] <= '4' {ans = "Heisei"}
  fmt.Println(ans)
}
//  [go]
package main

import "fmt"

func main(){
var s string
  fmt.Scanf("%s",&s)
  if s<="2019/04/30"{
    fmt.Println("Heisei")
  }else {
    fmt.println("TBD")
  }
}
//  [go]
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	// 勉強用。先人の丸パクリです
	var s string
	fmt.Scan(&s)
	//スラッシュでsplitさせてAtoi
	ss := strings.Split(s, "/")
	fmt.Println(ss)
	a ,_ := strconv.Atoi(ss[0])
	b ,_ := strconv.Atoi(ss[1])
	c ,_ := strconv.Atoi(ss[2])
	if a <= 2019 && b <= 4 && c <= 30 {
		fmt.Println("Heisei")
		return
	}
	fmt.Println("TBD")
  //ひどいなこれは
}
//  [ruby]
s = gets.chomp
puts s <= '2019/04/30' ? 'Heisei' : 'TBD'
//  [ruby]
s = gets.chomp
puts s > "2019/04/30" ? "TBD" : "Heisei"
//  [ruby]
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2/24/2019, 8:54:51 PM
# Powered by Visual Studio Code
#

s = gets.chomp
if s <= "2019/04/30"
  puts "Heisei"
else
  puts "TBD"
end
//  [ruby]
puts gets.split.map(&:to_i)[1]<=4?'Heisei':'TBD'
//  [ruby]
require 'date'
puts Date.new(gets.split('/').map(&:to_i).join(','))<=Date.new(2019,4,30) ?'Heisei':'TBD'
//  [ruby]
require 'date'
puts Date.new(gets.split('/').map(&:to_i).join(','))<=Date.new(2019,4,30)?'Heisei':'TBD'
//  [rust]
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let v:Vec<&str> = buf.trim().split('/').collect();
	let mut x:Vec<i32> = Vec::new();
	for i in 0..3 {
		x.push(v[i].parse().ok().unwrap());
	}
	if x[0] > 2019 ||  x[1] > 4 || x[2] > 30{
		println!("TBD");
	}else{
		println!("Heisei");
	}
}
//  [rust]
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    let s: Vec<&str> = s.split("/").collect();
    let year: i32 = s[0].parse().unwrap();
    let month: i32 = s[1].parse().unwrap();
    let day: i32 = s[2].parse().unwrap();
    let mut heisei = true;
    if year > 2019 {
        heisei = false;
    } else if year == 2019 {
        if month > 4 {
            heisei = false;
        } else if month == 4 {
            if day > 30 {
                heisei = false;
            }
        }
    }
    if heisei {
        println!("Heisei");
    } else {
        println!("TBD");
    }

}
//  [rust]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }

    let y: i32 = (&s[0..4]).parse().unwrap();
    let m: i32 = (&s[5..7]).parse().unwrap();
    let d: i32 = (&s[8..10]).parse().unwrap();

    if y <= 2018 {
        println!("Heisei");
    } else if m <= 3 || m == 4 && d <= 30 {
        println!("Heisei");
    } else {
        println!("TBD");
    }

}