Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		if buf[0] == "0" {
			break
		}
		q1, _ := strconv.Atoi(buf[0]) // 買うべき鶏肉の量の下限(g)
		b, _ := strconv.Atoi(buf[1])  // 予算
		c1, _ := strconv.Atoi(buf[2]) // 会津地鶏の値段(/100g)
		c2, _ := strconv.Atoi(buf[3]) // 普通の鶏肉の値段(/100g)
		q2, _ := strconv.Atoi(buf[4]) // 会津地鶏の買える量の上限(g)
		maxAizuChiken := min(b/c1, q2)
		if maxAizuChiken <= 0 {
			fmt.Println("NA")
			continue
		}
		if c2 >= c1 {
			maxNormalChiken := (b - maxAizuChiken*c1) / c2
			if maxAizuChiken+maxNormalChiken < q1 { // 買い切ったけども必要な鶏肉の下限に達しなかった
				fmt.Println("NA")
			} else {
				fmt.Println(maxAizuChiken, maxNormalChiken)
			}
			continue
		}
		if (b-c1)/c2+1 < q1 { // 会津地鶏を1単位+普通の鶏肉を予算目一杯買ったが買うべき下限を超えなかった
			fmt.Println("NA")
			continue
		}
		// 二分探索
		low, high := 0, maxAizuChiken+1
		for high-low > 1 {
			mid := (low + high) / 2
			if check(mid, b, c1, c2, q1) {
				low = mid
			} else {
				high = mid
			}
		}
		fmt.Println(low, (b-low*c1)/c2)
	}
}

func check(mid, b, c1, c2, q1 int) bool {
	if mid+(b-mid*c1)/c2 < q1 {
		return false
	}
	return true
}

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

Python: while True:
    N = input()
    if N == "0":
        break

    q1,b,c1,c2,q2 = [int(i) for i in N.split()]

    if c1 <= c2:
        x = min(q2, b // c1)
    else:
        x = min((b-c2*q1) // (c1-c2), q2, b // c1)
    y = (b-c1*x) // c2

    if x <= 0 or x + y < q1:
        print("NA")
    else:
        print(x,y)

Python: while True:
    n = input()
    if n == '0': break
    q1, b, c1, c2, q2 = map(int, n.split())
    for i in range(q2, 0, -1):
        c = i * c1
        x = (b-c)//c2
        if i+x < q1:
            continue
        elif x >= 0:
            print(i, x)
            break
    else:
        print('NA')

Python: def binary_search(quantity, budget, aizu_chicken_price, chicken_price, aizu_chicken_limit):
    if budget < (quantity - 1) * chicken_price + aizu_chicken_price:
        return None

    if aizu_chicken_price * quantity <= budget:
        aizu_chicken_count = budget // aizu_chicken_price

        if aizu_chicken_limit < aizu_chicken_count:
            aizu_chicken_count = aizu_chicken_limit

        rest = budget - aizu_chicken_price * aizu_chicken_count
        chicken_count = rest // chicken_price
        return aizu_chicken_count, chicken_count

    if aizu_chicken_price * aizu_chicken_limit + chicken_price * (quantity - aizu_chicken_limit) < budget:
        rest = budget - aizu_chicken_price * aizu_chicken_limit
        chicken_count = rest // chicken_price
        return aizu_chicken_limit, chicken_count

    # 二分探索
    aizu_chicken_count = aizu_chicken_limit // 2
    chicken_count = quantity - aizu_chicken_count
    update_count = aizu_chicken_count // 2 + 1

    max_pair = (0, quantity)

    while 0 < update_count:

        if aizu_chicken_count * aizu_chicken_price + chicken_count * chicken_price <= budget:
            max_pair = (aizu_chicken_count, chicken_count)
            aizu_chicken_count += update_count + 1
            chicken_count -= (update_count + 1)

        else:
            aizu_chicken_count -= (update_count + 1)
            chicken_count += update_count + 1

        update_count //= 2

    return max_pair


while True:

    input_data = input()

    if input_data == "0":
        break

    quantity, budget, aizu_chicken_price, chicken_price, aizu_chicken_limit = [int(item) for item in
                                                                               input_data.split(" ")]

    result = binary_search(quantity, budget, aizu_chicken_price, chicken_price, aizu_chicken_limit)

    if result is not None:
        print(result[0], result[1])
    else:
        print("NA")

Python: def check(mid, b, c1, c2, q1):
  if mid + (b - mid * c1) // c2 < q1:
    return False
  return True

while True:
  s = input()
  if s == "0":
    break
  q1, b, c1, c2, q2 = map(int, s.split())
  max_aizu = min(b // c1, q2)
  if max_aizu <= 0:
    print("NA")
    continue
  if c2 >= c1:
    if max_aizu >= q1:
      print(max_aizu, (b - max_aizu * c1) // c2)
    else:
      print("NA")
    continue
  
  left = 0
  right = max_aizu + 1
  while right - left > 1:
    mid = (left + right) // 2
    if check(mid, b, c1, c2, q1):
      left = mid
    else:
      right = mid
  
  if (b - left * c1) // c2 + left < q1:
    print("NA")
  else:
    print(left, (b - left * c1) // c2)

Python: def check(mid, b, c1, c2, q1):
  if mid + (b - mid * c1) // c2 < q1:
    return False
  return True

while True:
  s = input()
  if s == "0":
    break
  
  q1, b, c1, c2, q2 = map(int, s.split())
  max_aizu = min(b // c1, q2)
  
  if max_aizu <= 0:
    print("NA")
    continue
  
  if c2 >= c1:
    max_normal = (b - max_aizu * c1) // c2
    if max_aizu + max_normal < q1:
      print("NA")
    else:
      print(max_aizu, max_normal)
    continue
  
  if (b - c1) // c2 + 1 < q1:
    print("NA")
    continue

  left = 0
  right = max_aizu + 1
  while right - left > 1:
    mid = (left + right) // 2
    if check(mid, b, c1, c2, q1):
      left = mid
    else:
      right = mid
  
  print(left, (b - left * c1) // c2)

Python: # Aizu Problem 0186: Aizu Chicken
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def aizu_chicken(q1, b, c1, c2, q2):
    for i in range(q2, 0, -1):
        cj = i * c1
        normal = int((b - cj) / c2)
        if i + normal < q1:
            continue
        elif normal >= 0:
            print(i, normal)
            break
    else:
        print("NA")


while True:
    inp = [int(_) for _ in input().split()]
    if len(inp) == 1:
        break
    q1, b, c1, c2, q2 = inp[:]
    aizu_chicken(q1, b, c1, c2, q2)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0186

"""
import sys
from sys import stdin
input = stdin.readline


def Cond(q1, b, mid, c1, c2):
    b -= (c1 * mid)
    if b < 0:
        return False
    b -= (c2 * (q1 - mid))
    if b < 0:
        return False
    return True


def solve(q1, b, c1, c2, q2):
    ub = q2
    lb = 1
    aizu_chicken = 0

    while (ub - lb) > 1:
        mid = (ub + lb) // 2
        if Cond(q1, b, mid, c1, c2):
            lb = mid
            aizu_chicken = max(aizu_chicken, mid)
        else:
            ub = mid

    if Cond(q1, b, lb, c1, c2):
        aizu_chicken = max(aizu_chicken, lb)
    if Cond(q1, b, ub, c1, c2):
        aizu_chicken = max(aizu_chicken, ub)

    b -= (aizu_chicken * c1)
    normal_chicken = b // c2
    if normal_chicken < 0 or aizu_chicken == 0:
        return False, 0, 0
    else:
        return True, aizu_chicken, normal_chicken


def main(args):
    while True:
        txt = input().strip()
        if txt[0] == '0':
            break

        q1, b, c1, c2, q2 = map(int, txt.split())
        result, aizu, normal = solve(q1, b, c1, c2, q2)
        if result is False:
            print('NA')
        else:
            print(aizu, normal)


if __name__ == '__main__':
    main(sys.argv[1:])