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: import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    ipt = readline()
    if ipt == "0\n":
        return False
    q1, b, c1, c2, q2 = map(int, ipt.split())
    for p1 in range(q2, 0, -1):
        b1 = b - p1*c1
        if b1 < 0:
            continue
        p2 = b1 // c2
        if p1 + p2 >= q1:
            write("%d %d\n" % (p1, p2))
            break
    else:
        write("NA\n")
    return True
while solve():
    ...

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, 0)
    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: # 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: 
class Solve:
    def __init__(self):
        tmp = [int(i) for i in input().split()]
        if len(tmp) == 1:
            self.cal = False
        else:
            self.cal = True
            q1, b, c1, c2, q2 = tmp

            self.B = b
            self.C = (c1, c2)
            self.Q = (q1, q2)

            self.a = 0  # >= 0; True;
            self.b = min(self.Q[1]+1, self.B//self.C[0]+1)  # <= 10**6+1; False

    def check(self, A):
        b = self.B
        b -= self.C[0] * A  # self.b(??????)?????????????´\?¶????100A[g]????????\??¶?????????????????????
        b -= self.C[1] * max(0, self.Q[0]-A)
        if b >= 0:
            return True
        else:
            return False

    def solve(self):
        while self.b - self.a > 1:
            m = (self.a + self.b) // 2
            if self.check(m):
                self.a = m
            else:
                self.b = m
        return self.buy(self.a)

    def buy(self, A):
        if A == 0:
            return ['NA']
        else:
            return [str(A), str((self.B-self.C[0]*A)//self.C[1])]

while True:
    s = Solve()
    if not s.cal:
        break

    print(" ".join(s.solve()))

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

  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: while True:
    N = input()
    if N == "0":
        break

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

    x = min((b-c2*q1) // (c1-c2), q2, b // c1)
    y = (b-c1*x) // c2

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

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:
        print("NA")
    else:
        print(x,y)

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


while True:
    input_str = input()
    if len(input_str) == 1 and input_str[0] == "0":
        break

    need,budget,aizu,normal,limit = map(int,input_str.split())

    left = 1;right = limit
    mid = (left+right)//2
    num_aizu = 0;num_normal = 0

    while left <= right:
        rest = budget-mid*aizu
        tmp_normal = rest//normal
        if rest >= 0 and mid+tmp_normal >= need:
            num_aizu = mid
            num_normal = tmp_normal
            left = mid+1
        else:
            right = mid-1
        mid = (left+right)//2

    if num_aizu == 0:
        print("NA")
    else:
        print("%d %d"%(num_aizu,num_normal))

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):
    if c2 * q1 > b:
        return False, 0, 0

    ub = q2
    lb = 1
    max_aizu = 0

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

    if Cond(q1, b, ub, c1, c2):
        max_aizu = ub

    b -= (max_aizu * c1)
    normal_chicken = b // c2
    if normal_chicken < 0 or max_aizu == 0:
        return False, 0, 0
    else:
        return True, max_aizu, 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:])