jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

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

const inf = 1 << 60

func solve() {
	d, g := getInt(), getInt()
	ps, cs := make([]int, d), make([]int, d)
	for i := 0; i < d; i++ {
		ps[i] = getInt()
		cs[i] = getInt()
	}

	ans := inf
	for bit := 0; bit < (1 << uint(d)); bit++ {
		score := 0
		cnt := 0
		restMax := -1
		for i := 0; i < d; i++ {
			if mask := (1 << uint(i)); (bit & mask) > 0 {
				score += (100*(i+1))*ps[i] + cs[i]
				cnt += ps[i]
			} else {
				restMax = i
			}
		}

		if diff := g - score; diff > 0 {
			if restMax == -1 {
				continue
			}

			s := 100 * (restMax + 1)
			add := (diff + s - 1) / s
			if add > ps[restMax] {
				continue
			}
			cnt += add
		}

		ans = min(ans, cnt)
	}

	fmt.Fprintln(wr, ans)
}

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

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}
//  [go]
package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		D, G int
	)
	fmt.Scan(&D, &G)
	p := make([]int, D)
	c := make([]int, D)
	for i := 0; i < D; i++ {
		fmt.Scan(&p[i], &c[i])
	}
	ans := 9223372036854775807
	for mask := 0; mask < (1 << uint64(D)); mask++ {
		var score, num int
		restMax := -1
		for i := 0; i < D; i++ {
			if mask >> uint64(i) & 1 != 0 {
				score += 100 * (i+1) * p[i] + c[i]
				num += p[i]
			} else {
				restMax = i
			}
		}
		if score < G {
			nextScore := 100 * (restMax + 1)
			remainNum := (G - score + nextScore - 1) / nextScore
			if remainNum >= p[restMax] {
				continue
			}
			num += remainNum
		}
		ans = int(math.Min(float64(ans), float64(num)))
	}
	fmt.Println(ans)
}
//  [go]
package main

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

type Problem struct {
	Num   int
	Bonus int
	Base  int
}

var MinProblem = 100*10 + 1

func main() {
	s := IOInitialize()
	D := Int(s)
	G := Int(s)
	problems := scanNums(s, D)
	solveNums := []int{}
	calc(problems, G, &solveNums, 0, 0)
	fmt.Println(minSlice(solveNums))
}

func calc(problems []Problem, G int, solveNums *[]int, sum int, problemNum int) {
	if len(problems) == 0 {
		panic("unreachable")
	}
	for i := 0; i < len(problems); i++ {
		score := problems[i].Num*problems[i].Base + problems[i].Bonus
		if sum+score >= G {
			target := G - sum
			n := target / problems[i].Base
			if target%problems[i].Base != 0 {
				n++
			}
			*solveNums = append(*solveNums, problemNum+min(problems[i].Num, n))
		} else {
			_sum := sum + score
			num := problems[i].Num
			_problems := remove(problems, i)
			calc(_problems, G, solveNums, _sum, problemNum+num)
		}
	}
}

func remove(slice []Problem, index int) []Problem {
	_slice := []Problem{}
	for i, v := range slice {
		if i != index {
			_slice = append(_slice, v)
		}
	}
	return _slice
}

func min(nums ...int) int {
	res := nums[0]
	for _, num := range nums {
		if res > num {
			res = num
		}
	}
	return res
}

func minSlice(nums []int) int {
	res := nums[0]
	for _, num := range nums {
		if res > num {
			res = num
		}
	}
	return res
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

func scanNums(s *bufio.Scanner, len int) (nums []Problem) {
	for i := 0; i < len; i++ {
		num := Int(s)
		bonus := Int(s)
		nums = append(nums, Problem{Num: num, Bonus: bonus, Base: (i + 1) * 100})
	}
	return
}
//  [go]
package main

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

func main() {
	D, G := ReadInt(), ReadInt()
	p := make([]int, D)
	c := make([]int, D)
	for i := 0; i < D; i++ {
		p[i], c[i] = ReadInt(), ReadInt()
	}
	min := 1 << 62
	for i := 0; i < D; i++ {
		for j := 0; j <= p[i]; j++ {
			for S := 0; S < 1<<D; S++ {
				score := j * (i + 1) * 100
				if j == p[i] {
					score += c[i]
				}
				cnt := j
				for k := 0; k < D; k++ {
					if S>>k&1 == 1 && k != i {
						score += p[k]*(k+1)*100 + c[k]
						cnt += p[k]
					}
				}
				if score >= G {
					if cnt < min {
						min = cnt
					}
				}
			}
		}
	}
	fmt.Println(min)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var (
	d int
	g int
)

func main() {
	sc.Split(bufio.ScanWords)

	d = nextInt()
	g = nextInt()

	p := make([]int, d)
	c := make([]int, g)
	for i := 0; i < d; i++ {
		p[i] = nextInt()
		c[i] = nextInt()
	}

	res := 100000100000
	for bit := 0; bit < (1 << uint(d)); bit++ {
		sum := 0
		num := 0

		// p[i]をすべて解いた時の得点
		for i := 0; i < d; i++ {
			if bit&(1<<uint(i)) == 1<<uint(i) {
				sum += c[i] + p[i]*100*(int(i)+1)
				num += p[i]
			}
			// fmt.Println(res)

		}

		if sum >= g {
			res = min(res, num)
		} else {
			for i := d - 1; i >= 0; i-- {
				if bit&(1<<uint(i)) == 1<<uint(i) {
					continue
				}
				for j := 0; j < p[i]; j++ {
					if sum >= g {
						break
					}
					sum += 100 * (int(i) + 1)
					num++
				}
			}
			res = min(res, num)
		}

	}

	fmt.Println(res)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
//  [ruby]
io = STDIN
d,G=io.gets.split.map(&:to_i)
ar=d.times.map do |i|
  q,c = io.gets.split.map(&:to_i)
  [100*(i+1),q,100*(i+1)*q+c] #点数、問題数、合計
end
$ans=1000
def dfs(questions,highest,amt,num)
  if amt>=G
    $ans=[$ans,num].min
  else
    if questions==[]
      x,q,tot=highest
      if G-amt<=x*(q-1)
        $ans=[$ans,num+((G-amt).to_f/x).ceil].min
      end
      return
    end
    x,q,tot=questions[0]
    dfs(questions[1..-1],highest,amt+tot,num+q)
    dfs(questions[1..-1],questions[0],amt,num)
  end
end
dfs(ar,[],0,0)
p $ans
//  [ruby]
d,g = gets.chomp.split.map(&:to_i)
ps = d.times.map{gets.chomp.split.map(&:to_i)}
ans = 10**18
(2**d).times do |i|
  cnt = 0
  sum = 0
  idx = 0
  d.times do |j|
    if i[j] == 1
      cnt += ps[j][0]
      sum += ps[j][0] * (j+1) * 100 + ps[j][1]
    else
      idx = j
    end
  end
  if sum >= g
    ans = cnt if ans > cnt
  else
    rem = (g - sum)/100
    if rem <= ps[idx][0] * (idx+1)
      cnt += (rem / (idx+1).to_f).ceil
      ans = cnt if ans > cnt
    end
  end
end

puts ans
//  [ruby]
d,g = gets.chomp.split.map(&:to_i)
ps,cs = d.times.map{gets.chomp.split.map(&:to_i)}.transpose
ans = ps.inject(:+)
(2 ** d).times do |i|
  sum = 0
  cnt = 0
  num = 0
  d.times do |j|
    if i[j] == 1
      cnt += ps[j]
      sum += (ps[j] * 100 * (j+1) + cs[j])
    else
      num = j
    end
  end

  if sum < g
    temp = ((g - sum).to_f / (100 * (num+1)) ).ceil
    if temp < ps[num]
      cnt += temp
      ans = cnt if ans > cnt
    end
  else
    ans = cnt if ans > cnt
  end
end

puts ans
//  [ruby]
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

D,G=get_i
$ans=INF
def dfs(pc,select,now,res,n)
    if now!=-1
        if ((G-res).to_f/((now+1)*100).to_f).ceil<=pc[now][0]
            $ans=min(n+((G-res).to_f/((now+1)*100).to_f).ceil,$ans)
        return
      elsif res+(now+1)*100*pc[now][0]+pc[now][1]>=G
        $ans=min(n+pc[now][0],$ans)
        return
      end
      n+=pc[now][0]
      res+=(now+1)*100*pc[now][0]+pc[now][1]
    end
    return if n>=$ans
    select.each_with_index do|f,i|
        next if f
        select[i]=true
        dfs(pc,select,i,res,n)
        select[i]=false
    end
end
pc=array(D)
D.times do|i|
  pc[i]=get_i
end
res=0
n=0
pc.each_with_index do|(p,c),i|
  res+=p*(i+1)*100+c
  n+=p
end
if res==G
    puts n
    exit
end
dfs(pc,Array.new(D){false},-1,0,0)
puts $ans
//  [ruby]
d, g = gets.split.map(&:to_i)
pc = []
d.times do |i|
  pc << [(i+1) * 100,*gets.split.map(&:to_i)]
end
# p pc
cnts = []
[true,false].repeated_permutation(d).each do |bools|
  sum = 0
  cnt = 0
  pc.size.times do |i|
    if bools[i]
      sum += pc[i][0] * pc[i][1] + pc[i][2]
      cnt += pc[i][1]
    end
  end
  if sum >= g
    cnts << cnt
    next
  end
  until sum >= g
    (pc.size-1).downto(0) do |i|
      next if bools[i]
      tmpflag = false
      pc[i][1].times do |ii|
        sum += pc[i][0]
        cnt += 1
        if sum >= g
          tmpflag = true
          break
        end
      end
      break if tmpflag
    end
  end

  cnts << cnt
end
p cnts.sort[0]

# 3 7 2 66
//  [ruby]
D, G = gets.split.map(&:to_i)
ps, cs = [], []
(1..D).each do |i|
    ps[i], cs[i] = gets.split.map(&:to_i)
end

SUM = ps[1, D].inject(:+)
dp = Array.new(D+1){Array.new(SUM+1, 0)}
(1..D).each do |i|
    (0..SUM).each do |j|
        (0..ps[i]).each do |k|
            next if j < k
            result = dp[i-1][j-k] + 100*i*k
            result += cs[i] if k == ps[i]
            dp[i][j] = result if dp[i][j] < result
        end
    end
end

(1..SUM).each do |i|
    if dp[D][i] >= G
        puts i
        exit
    end
end
//  [rust]
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      d: usize,
      g: usize,
      pc: [(usize, usize); d],
   }
   let mut ans = 1001;
   for k in 0..1 << d {
      let us: Vec<_> = (0..d).map(|i| (k >> i) & 1 == 1).collect();
      let mut score = 0;
      let mut count = 0;
      for i in 0..d {
         if us[i] {
            score += 100 * (i + 1) * pc[i].0;
            score += pc[i].1;
            count += pc[i].0;
         }
      }
      for i in (0..d).rev() {
         if score >= g {
            break;
         } else if !us[i] {
            if score + 100 * (i + 1) * (pc[i].0 - 1) < g {
               score += 100 * (i + 1) * (pc[i].0 - 1);
               count += pc[i].0 - 1;
            } else {
               let k = (g - score - 1) / (100 * (i + 1)) + 1;
               score += 100 * (i + 1) * k;
               count += k;
            }
         }
      }
      if score >= g {
         ans = std::cmp::min(count, ans);
      }
   }
   println!("{}", ans);
}
//  [rust]
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let g: usize = itr.next().unwrap().parse().unwrap();
    let pc: Vec<(usize, usize)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    // g以上
    let mut ans = 1usize << 60;
    for bit in 0..1 << n {
        let mut tc = 0;
        let mut tp = 0;
        for i in 0..n {
            if bit >> i & 1 == 1 {
                tc += pc[i].0;
                tp += pc[i].1 + pc[i].0 * 100 * (i + 1);
            }
        }
        // 足りない分解く
        if tp >= g {
            ans = std::cmp::min(ans, tc);
        } else {
            // 大きいほうコアラ
            let mut ok = false;
            for i in (0..n).rev() {
                if bit >> i & 1 == 0 {
                    for _ in 0..pc[i].0 {
                        tc += 1;
                        tp += 100 * (i + 1);
                        if tp >= g {
                            ok = true;
                            break;
                        }
                    }
                }
                if ok {
                    break;
                }
            }
            if ok {
                ans = std::cmp::min(ans, tc);
            }
        }
    }
    println!("{}", ans);
}
//  [rust]
#![allow(unused_imports)]

use std::collections::*;
use std::cmp::Ordering;

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let d: usize = iter.next().unwrap().parse().unwrap();
    let g: i64 = iter.next().unwrap().parse().unwrap();
    let mut p: Vec<i64> = Vec::with_capacity(d);
    let mut c: Vec<i64> = Vec::with_capacity(d);
    
    for _ in 0..d {
        p.push(iter.next().unwrap().parse().unwrap());
        c.push(iter.next().unwrap().parse().unwrap());
    }

    let mut best_eff: Vec<i64> = Vec::with_capacity(d);
    let mut complete: Vec<i64> = Vec::with_capacity(d);
    
    for i in 0..d {
        best_eff.push((i as i64 +1)*100*(p[i] - 1));
        complete.push((i as i64 +1)*100*p[i] + c[i]);
    }

    let mut hset = (0..d).collect::<HashSet<_>>();

    println!("{}", calc(d, g, &mut hset, &best_eff, &complete, &p));
}

fn calc(d: usize, rest_score: i64, problems: &mut HashSet<usize>, best_eff: &[i64], complete: &[i64], p: &[i64]) -> i64 {
    if rest_score <= 0 {
        return 0;
    }

    let mut min = 1i64 << 60;

    let mut max_best_eff = 0;
    let mut max_bset_eff_p = 0i64;
    for &prob in problems.iter() {
        if max_best_eff < best_eff[prob] {
            max_best_eff = best_eff[prob];
            max_bset_eff_p = prob as i64;
        }
    }
    if max_best_eff >= rest_score {
        min = std::cmp::min(min, 
            if rest_score % (100 * (max_bset_eff_p + 1)) == 0 {
                rest_score / (100 * (max_bset_eff_p + 1))
            } else {
                rest_score / (100 * (max_bset_eff_p + 1)) + 1
            }
        );
    }
    let problems_clone: Vec<_> = problems.iter().cloned().collect();
    for prob in problems_clone {
        problems.remove(&prob);
        min = std::cmp::min(
            min,
            p[prob] + calc(d,rest_score - complete[prob],problems,best_eff,complete,p)
        );
        problems.insert(prob);
    }
    min
}
//  [rust]
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let (d,g) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize)
    };
    let (ps, cs) = {
        let mut ps = vec![];
        let mut cs = vec![];
        for _ in 0..d {
            let mut xs = read_vec_i64();
            ps.push(xs[0] as usize);
            cs.push(xs[1] as usize / 100);
        }
        (ps,cs)
    };
    let inf = 1usize << 40;
    let mut xs = vec![inf; 212345];
    let mut ys = vec![inf; 212345];
    let m = 200001;
    xs[0] = 0;
    for i in 0..d {
        for k in 0..m {
            ys[k] = xs[k];
        }
        for k in 0..m {
            for j in 1..ps[i] {
                ys[k+(i+1)*(j)] = min(ys[k+(i+1)*(j)], xs[k] + j);
            }
            ys[k+(i+1)*ps[i]+cs[i]] = min(ys[k+(i+1)*ps[i]+cs[i]], xs[k] + ps[i]);
        }
        for k in 0..m {
            xs[k] = ys[k];
        }
    }
    let mut res = inf;
    for i in g/100..212345 {
        res = min(res, xs[i]);
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}

#[allow(dead_code)]
fn tf<T>(cond: bool, t: T, f: T) -> T {
    if cond { t } else { f }
}
//  [swift]
/*
 蟻本 例題 2-1-1　部分和問題 の類題
 ABC 104 C - All Green
 
 問題を解く組み合わせを全部調べるには時間が足りない(ノ)•̥ૅㅁ•̥(ヾ)
 そこで,
 ある難易度の問題を全問解く(or 解かない) + 解き切っていない問題で一番得点の高い問題をいくつか解く
 場合に限って調べる٩(๑❛ᴗ❛๑)۶
 */
// bit全(?)探索
let DG: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let pc: [[Int]] = (1...DG[0]).map { _ in readLine()!.split(separator: " ").map { Int($0)! }}
var res: Int = 1100 // 問題数は最大で 10 * 100 問

let w: Int = Array(repeating: 2, count: DG[0]).reduce(1, *)  // 各難易度の問題を解き切るかどうかの場合の数

for i in 0..<w {
    var num2 = String(i, radix: 2)  // 2進数へ変換
    num2 = String(repeating: "0", count: DG[0]-num2.count) + num2   // 001 みたいになるように0埋め

    var score: Int = 0
    var count: Int = 0
    var idx0: Int = 0   // 解き切ってない難易度で最大の難易度

    for (j, k) in num2.enumerated() {
        if k=="1" { // 難易度 j+1 の問題を解き切る
            score += 100*(j+1)*pc[j][0] + pc[j][1]
            count += pc[j][0]
        } else {
            idx0 = j    // 難易度 j+1 を解ききらない
        }
    }
    if score >= DG[1] { // 目標達成しているか(・・？)
        res = min(res, count)
    }
    
    // 解き切っていない難易度のうち最高難易度の問題を1問ずつ解く
    for j in 1...pc[idx0][0] {
        score += 100*(idx0+1)
        count += 1
        if j==pc[idx0][0] { score += pc[idx0][1] }  // 解き切ったとき
        if score >= DG[1] { // 目標達成しているか(・・？)
            res = min(res, count)
            break
        }
    }
}
print(res)   // (๑•ૅㅁ•๑)
//  [swift]
/*
 蟻本 例題 2-1-1　部分和問題 の類題
 ABC 104 C - All Green
 
 問題を解く組み合わせを全部調べるには時間が足りない(ノ)•̥ૅㅁ•̥(ヾ)
 そこで,
 ある難易度の問題を全問解く(or 解かない) + 解き切っていない問題で一番得点の高い問題をいくつか解く
 場合に限って調べる٩(๑❛ᴗ❛๑)۶
 */
// bit全(?)探索
let DG: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let pc: [[Int]] = (1...DG[0]).map { _ in readLine()!.split(separator: " ").map { Int($0)! }}
var res: Int = 1100 // 問題数は最大で 10 * 100 問

let w: Int = Array(repeating: 2, count: DG[0]).reduce(1, *)  // 各難易度の問題を解き切るかどうかの場合の数

for i in 0..<w {
    var num2 = String(i, radix: 2)  // 2進数へ変換
    num2 = String(repeating: "0", count: DG[0]-num2.count) + num2   // 001 みたいになるように0埋め

    var score: Int = 0
    var count: Int = 0
    var idx0: Int = 0   // 解き切ってない難易度で最大の難易度

    for (j, k) in num2.enumerated() {
        if k=="1" { // 難易度 j+1 の問題を解き切る
            score += 100*(j+1)*pc[j][0] + pc[j][1]
            count += pc[j][0]
        } else {
            idx0 = j    // 難易度 j+1 を解ききらない
        }
    }
    if score >= DG[1] { // 目標達成しているか(・・？)
        res = min(res, count)
        continue
    }
    
    // 解き切っていない難易度のうち最高難易度の問題を1問ずつ解く
    for j in 1...pc[idx0][0] {
        score += 100*(idx0+1)
        count += 1
        if j==pc[idx0][0] { score += pc[idx0][1] }  // 解き切ったとき
        if score >= DG[1] { // 目標達成しているか(・・？)
            res = min(res, count)
            break
        }
    }
}
print(res)   // (๑•ૅㅁ•๑)
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let D=tn(),G=tn(),qNum=[],qPoint=[],kaisuu=0,goukei=0,ans=Infinity
  for(let i=0;i<D;i++){
    qNum.push(tn())
    qPoint.push(tn())
  }
  for(let i=0;i<(1<<D);i++){
    goukei=0
    kaisuu=0
    for(let j=0;j<D;j++){
      if(i&(1<<j)){
        goukei+=(j+1)*100*qNum[j]+qPoint[j]
        kaisuu+=qNum[j]
      }
    }
    for(let j=D-1;j>=0;j--){
      if(!(i&(1<<j))){
        if(goukei>=G){
          ans=min(ans,kaisuu)
          break
        }else if(goukei+(j+1)*100*qNum[j]>=G){
          kaisuu+=ceil((G-goukei)/((j+1)*100))
          ans=min(ans,kaisuu)
          break
        }else{
          goukei+=(j+1)*100*qNum[j]
          kaisuu+=qNum[j]
        }
      }
    }
    if(goukei>=G){
      ans=min(ans,kaisuu)
    }
  }
  to(ans)
}
main()
//  [typescript]
declare var require: (x: string) => any;

let p: number[] = [], c: number[] = [];
let ans = 123456789;

function dfs(dep: number, goal: number, current: number, cand: number) {
  if (dep == -1) {
    let idx = p.length - 1;
    let tmp_p = p.slice();
    while(current < goal) {
      if(tmp_p[idx] > 0){
        tmp_p[idx]--;
        cand++;
        current += (idx+1);
        if (tmp_p[idx]==0){
          current += c[idx];
        }
      }
      if(tmp_p[idx] == 0) {
        idx--;
      }
    }
    ans = Math.min(ans, cand);
    return;
  }

  dfs(dep-1, goal, current, cand);
  const old_p = p[dep];
  p[dep] = 0;
  dfs(dep-1, goal, current + (old_p)*(dep+1) + c[dep], cand + old_p);
  p[dep] = old_p;
}

function Main(input: string[]) {
  const [d, g] = input[0].split(' ').map(x => parseInt(x, 10));

  for (let i = 0; i < d; i++) {
    [p[i], c[i]] = input[i+1].split(' ').map(x => parseInt(x, 10));
    c[i] /= 100;
  }

  dfs(d-1, g/100, 0, 0);

  console.log(ans);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'));
//  [python]
N = int(input())
s = []
for i in range(N):
    s.append(str(input()))
M = int(input())
t = []
for i in range(M):
    t.append(str(input()))
    
from collections import Counter
import numpy as np
counter = Counter(s)
sw = []
sc = []
for word, cnt in counter.most_common():
    sw.append(word)
    sc.append(cnt)
counter2 = Counter(t)
tw = []
tc = []
for word, cnt in counter2.most_common():
    tw.append(word)
    tc.append(cnt)
    
sw = np.array(sw)
sc = np.array(sc)
tw = np.array(tw)
tc = np.array(tc)

anslist = []
for i in range(len(sw)):
    anslist.append(sc[i] - sum((sw[i] == tw)*tc))
ans = max(anslist)
if(ans < 0):
    print("0")
else:
    print(ans)
//  [python]
import collections
n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]
bc = collections.Counter(b)
rc = collections.Counter(r)
ans = 0
for x in bc.keys():
  ans = max(ans, bc[x]-rc[x])
print(ans)
//  [python]

import collections
n = int(raw_input())
cca = collections.Counter([raw_input() for _ in range(n)])
m = int(raw_input())
ccb = collections.Counter([raw_input() for _ in range(m)])

r = 0
for w in cca.keys() + ccb.keys():
	r = max(r,cca[w] - ccb[w])
print r
//  [java]
import java.util.*;
import java.util.stream.Collectors;

import static java.lang.System.out;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String,Integer> map = new HashMap<>();
        long n = sc.nextLong();
        for (int i = 0; i < n ; i++) {
            String s = sc.next();
            Integer score = map.getOrDefault(s, 0);
            score += 1;
            map.put(s,score);
        }
        long m = sc.nextLong();
        for (int i = 0; i < m ; i++) {
            String s = sc.next();
            Integer score = map.getOrDefault(s, 0);
            score -= 1;
            map.put(s,score);
        }

        int max = map.values().stream().max(Comparator.naturalOrder()).get();
        if(max < 0){
            out.print(0);
        }else{
            out.print(max);
        }
    }
}
//  [java]

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String> s = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            s.add(sc.next());
        }

        int m = sc.nextInt();
        List<String> t = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            t.add(sc.next());
        }

        long max = 0;
        Set<String> set = new HashSet<>(s);
        for (String str: set) {
            long blue = s.stream().filter(a -> a.equals(str)).count();
            long red = t.stream().filter(a -> a.equals(str)).count();
            if ((blue-red) > max) max = blue-red;
        }
        System.out.println(max);
        sc.close();
    }

}
//  [java]
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=Integer.parseInt(sc.nextLine());
		Map<String,Integer> keywords=new HashMap<>();
		for(int i=0;i<N;i++) {
			String key=sc.nextLine();
			if(keywords.containsKey(key)) {
				keywords.put(key,keywords.get(key)+1);
			}else {
				keywords.put(key, 1);
			}
		}
		N=Integer.parseInt(sc.nextLine());
		for(int i=0;i<N;i++) {
			String key=sc.nextLine();
			if(keywords.containsKey(key)) {
				keywords.put(key,keywords.get(key)-1);
			}
		}
		Integer max=keywords.values().stream().max(Integer::compare).get();
		System.out.println(max<0?0:max);
	}
}
//  [cpp]
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;



int main(){
	int n,m,max=0,b=0;
	vector<pair<string,int>>a(10000000);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].first;
		a[i].second=1;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>a[n+i].first;
		a[n+i].second=-1;
	}
	sort(a.begin(),a.end(),greater<>());

	for(int i=0;i<m+n;i++){
		if(i!=0){
			if(a[i-1].first==a[i].first){
				
			}
			else{
				if(max<b){
					max=b;
				}
				b=0;
			}
		}
		b+=a[i].second;
	}
	if(max<b){
					max=b;
				}
	
	cout<<max<<endl;
	
	
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,m;cin>>n;
    string s;
    map<string,int> dic;
    for(int i=0;i<n;i++){
        cin>>s;
        dic[s]++;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>s;
        dic[s]--;
    }
    int ans=0;
    for(auto p:dic){
        auto v=p.second;
        if(v>ans)ans=v;
    }
    cout<<ans<<endl;
}
//  [cpp]
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
    int n,m,cnt1,cnt2,cnt,ans=-10,i,j;
    string a[100],b[100];
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    cin>>m;
    for(i=0;i<m;i++) cin>>b[i];
    for(i=0;i<n;i++)
    {
        cnt1=0;
        for(j=0;j<n;j++) if(a[i]==a[j]) cnt1++;
        cnt2=0;
        for(j=0;j<m;j++) if(a[i]==b[j]) cnt2++;
        cnt=cnt1-cnt2;
        if(cnt>ans) ans=cnt;
    }
    if(ans<0) puts("0");
    else cout<<ans;
    WAIT;
    rt0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//strcmp
typedef struct
{
    char zifu[101];
    int shu;
}yi;
int main()
{
    int x,y,ai,bi,i,j,cnt,max;
    char sz[101];
    yi a[101],b[101];
    scanf("%d",&x);
    ai=0;bi=0;
    for(i=0;i<x;i++)
    {
        scanf("%s",sz);
        cnt=1;
        for(j=0;j<=ai;j++)
        {
            if(strcmp(sz,a[j].zifu)==0)
            {
                cnt=0;
                a[j].shu++;
                break;
            }
        }
        if(cnt)
        {
            ai++;
            strcpy(a[ai].zifu,sz);
            a[ai].shu=1;
        }
    }
    fflush(stdin);

    scanf("%d",&y);
        for(i=0;i<y;i++)
    {
        scanf("%s",sz);
        cnt=1;
        for(j=0;j<=bi;j++)
        {
            if(strcmp(sz,b[j].zifu)==0)
            {
                cnt=0;
                b[j].shu++;
                break;
            }
        }
        if(cnt)
        {
            bi++;
            strcpy(b[bi].zifu,sz);
            b[bi].shu=1;
        }
    }
    for(i=1;i<=ai;i++)
    {
        for(j=1;j<=bi;j++)
        {
            if(strcmp(a[i].zifu,b[j].zifu)==0)
            {
                a[i].shu=a[i].shu-b[j].shu;
            }
            if(a[i].shu<0 )
                a[i].shu=0;
        }
    }
  //  for(i=0;i<ai;i++)
  //  {
      max=a[1].shu;
        for(j=2;j<=ai;j++)
        {
            if( max<a[j].shu )
            {
                max=a[j].shu;
                //temp=a[i].shu; a[i].shu=a[j].shu;a[j].shu=temp;
            }

        }
        printf("%d",max);
  //  }
    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int n,m;
char s[100][11], t[100][11];
int num=0;
int max1=-150, max2=-150, maxnum1, maxnum2;

int main(void){
	scanf("%d", &n);
  	for(int i=0;i<n;i++)	scanf("%s", s[i]);
	scanf("%d", &m);
  	for(int i=0;i<m;i++)	scanf("%s", t[i]);

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(strcmp(s[i], s[j])==0)	num++;			
		}
		for(int j=0;j<m;j++){
			if(strcmp(s[i], t[j])==0)	num--;
		}
		if(num>max1){
			max1 = num;
			maxnum1 = i;
		}
		num=0;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(strcmp(t[i], s[j])==0)	num++;			
		}
		for(int j=0;j<m;j++){
			if(strcmp(t[i], t[j])==0)	num--;
		}
		if(num>max2){
			max2 = num;
			maxnum2 = i;
		}
		num=0;
	}

	if(max1<0 && max2<0)	printf("0");
	else if(max1 > max2)	printf("%d", max1);
	else	printf("%d", max2);

	return 0;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int p;
    int q;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}
//構造体の.pを降順
int comp( const void *c1, const void *c2 )
{ data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.p;   /* b を基準とする */
  int tmp2 = test2.p;
    return tmp2 - tmp1;}




int main(){
    int bl,rd;
    scanf("%d",&rd);
    char rc[rd][12];
    rep(i,rd){
        scanf("%s",rc[i]);
    }
    scanf("%d",&bl);
    char bc[bl][12];
    rep(i,bl){
        scanf("%s",bc[i]);
    }
    int max=0;
    for(int i=0;i<rd;i++){
        int cnt=0;
        for(int j=i;j<rd;j++){
            if(strcmp(rc[i],rc[j])==0){
                cnt++;
            }else{
                ;
            }
        }
        for(int k=0;k<bl;k++){
            if(strcmp(rc[i],bc[k])==0){
                cnt--;
            }else{
                ;
            }
        }
        if(max<cnt){
            max=cnt;
        }
    }
    if(max<=0){
        printf("0");
        return 0;
    }else{
        printf("%d",max);
        return 0;
    }
}
//  [javascript]
function getMax(blue, red) {
  var BLUE = {};
  var RED = {};
  max = 0;
  blue.forEach(keyword => {
    if (typeof BLUE[keyword] === "undefined") {
      BLUE[keyword] = 1;
    } else {
      BLUE[keyword] += 1;
    }
  });
  red.forEach(keyword => {
    if (typeof RED[keyword] === "undefined") {
      RED[keyword] = 1;
    } else {
      RED[keyword] += 1;
    }
  });
  Object.keys(BLUE).forEach(key => {
    if (typeof RED[key] === "undefined") {
      if (BLUE[key] > max) max = BLUE[key];
    }
    var tmp = (BLUE[key] - RED[key]) < 0 ? 0 : BLUE[key] - RED[key];
    if (tmp > max) max = tmp;
  })
  return max;
}

function Main(input) {
  input = input.split('\n');
  BLUE = input.slice(1, parseInt(input[0], 10) + 1);
  RED = input.slice(parseInt(input[0], 10) + 2, -1);
  console.log(getMax(BLUE, RED));
}

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

var print = function print(x) {
  return console.log(x);
};

var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
var A, B, C;

function solve(A, B, C) {
  if (A + B >= C) return true;
  return false;
}

var lines = [];
rl.on('line', function (line) {
  lines.push(line);
});
rl.on('close', function (line) {
  var i = 0;
  var N = parseInt(lines[i++]);
  var S = {};

  for (var j = 0; j < N; ++j) {
    var v = lines[i++];
    S[v] = (S[v] || 0) + 1;
  }

  var M = parseInt(lines[i++]);
  var T = {};

  for (var _j = 0; _j < M; ++_j) {
    var _v = lines[i++];
    T[_v] = (T[_v] || 0) + 1;
  }

  var keys = {};
  Object.keys(S).forEach(function (v) {
    return keys[v] = true;
  });
  Object.keys(T).forEach(function (v) {
    return keys[v] = true;
  });
  var ret = Math.max(...[...Object.keys(keys).map(function (k) {
    return (S[k] || 0) - (T[k] || 0);
  }), 0]);
  console.log(ret);
});
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
  input = input.split('\n');
  var answer;

  var good = []; 
  var bad = []; 
  var switched = false;
  var counts = {};
  var max = 0;
  // nums = nums.map((e) => parseInt(e));

  for (var i = 1; i < input.length; i++) {
    if (/\d/.test(input[i])) {
      switched = true;
      continue;
    }

    if (switched) {
      bad.push(input[i]);
    } else {
      good.push(input[i]);
    }
  }

  good.forEach(e => {
    if (counts[e]) {
      counts[e] += 1;
    } else {
      counts[e] = 1;
    }
  });

  bad.forEach(e => {
    if (counts[e]) {
      counts[e] -= 1;
    }
  });

  for (var key in counts) {
    if (counts[key] > max) {
      max = counts[key];
    }
  }



  // 出力
  console.log(max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [go]
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	blueMap := map[string]int{}
	redMap := map[string]int{}

	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(r, &s)
		v, _ := blueMap[s]
		v++
		blueMap[s] = v
	}

	var m int
	fmt.Fscan(r, &m)
	for i := 0; i < m; i++ {
		var t string
		fmt.Fscan(r, &t)
		v, _ := redMap[t]
		v++
		redMap[t] = v
	}

	var bestScore int
	for key, value := range blueMap {
		tmpScore := value
		redValue, ok := redMap[key]
		if ok {
			tmpScore -= redValue
		}

		if tmpScore > bestScore {
			bestScore = tmpScore
		}
	}

	fmt.Fprintln(w, bestScore)
}
//  [ruby]
require 'pp'

H = {}
N,d=gets.chomp.split(' ').map{|n| n.to_i}
if(N == 0)
	puts 0
	exit(0)
end
0.upto(N-1){|i|
	s = gets.chomp
	H[s].nil? ? H[s]=1 : H[s]+=1
}
M,d=gets.chomp.split(' ').map{|n| n.to_i}
B = Array.new(M)
0.upto(M-1){|i|
	s = gets.chomp
	H[s].nil? ? H[s]=-1 : H[s]-=1
}

max = H.sort{|(k1,v1),(k2,v2)|v2<=>v1}[0][1]
if(max <= 0)
	puts 0
else
	puts max
end
//  [ruby]
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

hash = Hash.new { |h,k| h[k] = 0 }

N = get_int
N.times do |i|
  key = gets.chomp
  hash[key] += 1
end
M = get_int
M.times do |i|
  key = gets.chomp
  hash[key] -= 1
end

puts [0, *hash.values].max
//  [ruby]
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
n = gets_i
slist = []
tlist = []

n.times do
  slist.push gets.chomp
end

m = gets_i
m.times do
  tlist.push gets.chomp
end

sh = slist.tally
th = tlist.tally

max = 0
sh.each do |k, v|
  max = [max, v - th[k].to_i].max
end

puts max
//  [rust]
use std::collections::HashMap;

use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let mut map: HashMap<String, isize> = HashMap::new();

    let n: usize = parse_line().unwrap();
    for _ in 0..n {
        let s: String = parse_line().unwrap();
        let entry = map.entry(s).or_insert(0);
        *entry += 1;
    }

    let m: usize = parse_line().unwrap();
    for _ in 0..m {
        let t: String = parse_line().unwrap();
        let entry = map.entry(t).or_insert(0);
        *entry -= 1;
    }

    let ret = map.values().into_iter().fold(0, |a, b| a.max(*b));
    println!("{}", ret);
}
//  [rust]
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

#[allow(unused_macros)]
macro_rules ! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
#[allow(unused_macros)]
macro_rules ! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }

fn main() {
    input! {
        n: usize,
        s: [String; n],
        m: usize,
        t: [String; m],
    }

    let mut ret = 0;
    for i in 0..n {
        let mut tmp = s.iter().filter(|&e| *e == s[i]).count() as isize;
        tmp -= t.iter().filter(|&e| *e == s[i]).count() as isize;
        chmax!(ret, tmp);
    }

    println!("{}", ret);
}
//  [swift]
import Foundation

var si: [String: Int] = [:]
var ti: [String: Int] = [:]
let n = Int(readLine()!)!
for _ in 0..<n {
  let s = readLine()!
  if si[s] != nil {
    si[s]! += 1
  } else {
    si[s] = 1
  }
}
let m = Int(readLine()!)!
for _ in 0..<m {
  let t = readLine()!
  if ti[t] != nil {
    ti[t]! += 1
  } else {
    ti[t] = 1
  }
}
var ans: [Int] = [0]
for k in si.keys {
  if ti[k] != nil {
    ans.append(si[k]! - ti[k]!)
  } else {
    ans.append(si[k]!)
  }
}
print(ans.max()!)
//  [swift]
var b=[String:Int]()
for _ in 0..<Int(readLine()!)!{
    let s=readLine()!
    if b[s]==nil{
        b[s]=1
    }else{
        b[s]=b[s]!+1
    }
}
var r=[String:Int]()
for _ in 0..<Int(readLine()!)!{
    let s=readLine()!
    if r[s]==nil{
        r[s]=1
    }else{
        r[s]=r[s]!+1
    }
}
var ans=0
for (s,_) in b{
    ans=max(b[s]!-(r[s] ?? 0),ans)
}
print(ans)
//  [swift]
import Foundation

func readInt() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func counter(_ seq: [String]) -> [String: Int] {
    var count = [String:Int]()
    for e in seq {
        if count.contains(where: {$0.key == e}) {
            count[e]! += 1
        } else {
            count[e] = 1
        }
    }
    return count
}

func main() {
    let N = Int(readLine()!)!
    let s = counter((1...N).map { _ in readLine()! })

    let M = Int(readLine()!)!
    let t = counter((1...M).map { _ in readLine()! })

    var ans = 0
    for (label, blueCount) in s {
        if let redCount = t[label] {
            if blueCount > redCount {
                ans = max(ans, blueCount - redCount)
            }
        } else {
            ans = max(ans, blueCount)
        }
    }

    print(ans)
}


main()
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const M = Number(input[N + 1][0]);

  const counts: { [key: string]: number } = {};

  for (let i = 1; i < N + 1; i++) {
    const s = input[i][0];

    counts[s] = (counts[s] || 0) + 1;
  }

  for (let i = N + 2; i < M + N + 2; i++) {
    const t = input[i][0];

    counts[t] = (counts[t] || 0) - 1;
  }

  return Math.max(0, ...Object.values(counts));
};

console.log(main(read()));
//  [typescript]
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  var blueCardsNum: number = Number(lines[0]);

  var earnMap: { [key: string]: number } = {};

  for (var i = 1; i < blueCardsNum + 1; i++) {
    if (earnMap[lines[i]]) {
      earnMap[lines[i]] = earnMap[lines[i]] + 1;
    } else {
      earnMap[lines[i]] = 1;
    }
  }

  for (var i = blueCardsNum + 2; i < lines.length; i++) {
    if (earnMap[lines[i]]) {
      earnMap[lines[i]] = earnMap[lines[i]] - 1;
    } else {
      earnMap[lines[i]] = -1;
    }
  }

  var maxKey: string = Object.keys(earnMap).reduce(
    (prev: string, current: string): string => {
      return earnMap[current] > earnMap[prev] ? current : prev;
    }
  );
  console.log(earnMap[maxKey] < 0 ? 0 : earnMap[maxKey]);
});
//  [typescript]
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc091 {
    export class TaskB implements AtCoder.Paramable, AtCoder.Task {
        constructor(readonly args: string[][]) {
        }

        main(this: TaskB): void {
            const n: number = parseInt(this.args[0][0], 10);
            const m: number = parseInt(this.args[n + 1][0], 10);
            const map = new Map;

            for (let i = 0; i < n; i++) {
                const key: string = this.args[i + 1][0];
                if (!map.has(key)) {
                    map.set(key, 0);
                }
                map.set(key, 1 + map.get(key))
            }

            for (let i = 0; i < m; i++) {
                const key: string = this.args[n + i + 2][0];
                if (!map.has(key)) {
                    map.set(key, 0);
                }
                map.set(key, -1 + map.get(key));
            }

            // const array: number[] = [];
            // map.forEach((value) => {
            //     array.push(value);
            // });
            const ans: number = Math.max(...Array.from(map.values()));
            console.log(ans > 0 ? ans : 0);
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(x => x.split(' '));
    const task: AtCoder.Task = new TaskB(args);
    task.main();
}
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


a,b = map(int, input().split())

c = a + b
d = a - b
e = a * b
answer = c
if c < d:
    answer = d
if answer < e:
    answer = e

print(answer)
//  [python]
import numpy as np

def calc(a , b):
    arr = np.array([0,0,0])
    arr[0] = a + b
    arr[1] = a - b
    arr[2] = a * b
    return np.max(arr)

l = list(map(int, input().split()))
print(calc(l[0], l[1]))
//  [python]
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

A,B = ria()
print(max((A+B, A-B, A*B)))
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans;
		ans = A+B;
		if(ans<A-B) {
			ans = A-B;
		}
		if(ans<A*B) {
			ans = A*B;
		}
		System.out.println(ans);
	}

}
//  [java]
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Math.max(a+b, Math.max(a-b, a*b)));

	}
}