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: # -*- 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, 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:])

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1 >> B >> C1 >> C2 >> Q2) {
    if(Q1 == 0) break;
    
    if(B/C1 == 0) {
      failed(); continue;
    }
    
    int AizuCh = min(B/C1, Q2);
    int NCh = 0;
    for(;;) {
      
      if(AizuCh <= 0) { failed(); break; }
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
    }
    
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
double  q1,b,q2,ans;
int A,B;
double c1,c2;
int L,R,M;

void calcB(){
  int money = b-A*c1;
  if(money>=0)B=money/c2;
  else B=-99999;
}

  
bool check(int x){
  A=x;
  calcB();
  if(B>=0&&A+B>=q1)return true;
  else return false;
}

int main(){
  while(cin>>q1){
    ans=-1;
    if(q1==0)break;
    cin>>b>>c1>>c2>>q2;

    L=1;
    R=q2;
    M=(L+R)/2;

    while(L<R){
      if(check(M)&&!check(M+1)){
	break;
      }else if(check(M)){
	L=M+1;
	M=(L+R)/2;
      }else{
	R=M;
	M=(L+R)/2;
      }
	
    }


    if(check(M)){
      A=M;
      calcB();
      cout<<M<<' '<<B<<endl;
    } else cout<<"NA"<<endl;
    
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int a,b,c,d,e;
	while(scanf("%d",&a),a){
		scanf("%d%d%d%d",&b,&c,&d,&e);
		bool ok=false;
		int bestA=0;
		int bestB=0;
		for(int i=0;i<=e;i++){
			int f=b-c*i;
			int g=f/d;
			if(f>=0&&i+g>=a){
				bestA=i;
				bestB=g;
				ok=true;
			}
		}
		if(!ok)printf("NA\n");
		else printf("%d %d\n",bestA,bestB);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
	int q1, b, c1, c2, q2;
	while(cin >> q1, q1) {
	   cin >> b >> c1 >> c2 >> q2;
	   int aizu = min(b / c1, q2);
	   int money = b - aizu * c1;
	   int ordinal = money / c2;
	   while (aizu + ordinal < q1) {
		   aizu--;
		   money = b - aizu * c1;
		   ordinal = money / c2;
		   money = b - aizu * c1 - ordinal * c2;
	   }
	   if (aizu < 1) cout << "NA" << endl;
	   else cout << aizu << ' ' << ordinal << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int have,price[2],up;
        cin>>have>>price[0]>>price[1]>>up;
        bool kawa=0;
        for(int i=up;i>0;i--){
            if(have<price[0]*i)continue;
            for(int j=n-i;;j++){
                if(have-price[0]*i-price[1]*j<0){
                    if(i+j-1>=n){
                        kawa=1;
                        have=j-1;
                    }
                    break;
                }
            }
            if(kawa){
                cout<<i<<" "<<have<<endl;
            }
        }
        if(!kawa)cout<<"NA\n";
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int q1,b,c1,c2,q2;
	while(cin >> q1 , q1){
		cin >> b >> c1 >> c2 >> q2;
		int one = min(q2,b/c1) , two = 0;
		int cur = b - c1 * one;
		while(one+two<q1 && one > 0){
			if(cur<c2) one-- , cur += c1;
			while(cur - c2 >= 0){
				two++;
				cur -= c2;
			}	
		}
		if(one == 0 || cur < 0 || one+two < q1){
			cout << "NA" << endl;
		}else{
			cout << one << " " << two << endl;
		}
		
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <sstream>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1) {
    
    if(Q1 == 0) break;
    
    cin >> B >> C1 >> C2 >> Q2;
    
    assert(Q2 >= 1);
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh <= 0) { failed(); continue; }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

C++: #include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int b, c1, c2, q1, q2;

int c(int x)
{
    int y = (b - c1 * x) / c2;
	if(b-c1*x<0) return -1; 
	if(q1>(x+y)) return -1;
	if(q2<x) return -1;
	if(y<0) return -1;
	return y;
}

int main()
{
    while(cin >> q1 && q1) {
        cin >> b >> c1 >> c2 >> q2;
        int y;
        bool flag = false;
        for(int x = q2; !flag && x > 0; x--) {
            if((y = c(x)) != -1) {
                cout << x << " " << y << endl;
                flag = true;
            }
        }
        if(!flag) cout << "NA" << endl;
        
    }
    return 0;
}