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
}

C++: #include <iostream>
using namespace std;

int main(){
	int b,c1,c2,q1,q2,aizu,ord;
	while(cin>>q1,q1){
		bool flag=false;
		cin>>b>>c1>>c2>>q2;
		if(b/c1>q2){
			aizu=q2;
			ord=(b-c1*q2)/c2;
		}else{
			aizu=b/c1;
			ord=(b%c1)/c2;
		}
		//cout<<aizu<<" "<<ord<<endl;
		if(c1>b){cout<<"NA"<<endl;}
		
		else if((aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				if((b-c1*i)/c2>=q1-i){
					flag=true;
					cout<<i<<" "<<(b-c1*i)/c2<<endl;
					break;
				}
			}
			if(!flag){
				cout<<"NA"<<endl;
			}
		}else{
			cout<<aizu<<" "<<ord<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;

int main(void)
{
	int q1, b, c1, c2, q2;
	
	while(1){
		scanf("%d", &q1);
		if (q1 == 0) break;
		scanf("%d %d %d %d", &b, &c1, &c2, &q2);
		
		if (c1 <= c2){
			int x = min(b/c1, q2);
			int y = (b - (x * c1)) / c2;
			if ((x + y) < q1){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
		else {
			int x = min(min((b - (c2 * q1)) / (c1 - c2), q2), (b / c1));
			int y = (b - (x * c1)) / c2;
			if(x <= 0){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
typedef long long ll;
int main(){
????ll q1,b,c1,c2,q2;
????cin >> q1;
????while(q1!=0){
????????cin >> b >> c1 >> c2 >> q2;
????????ll x1=0,x2=0,m=min(c1,c2);
????????bool f=false;
????????//cout << b-min(c1,c2)*q1 << endl;
??????????
????????if(c1<=c2){
????????????if(b<c1*q2+c2*(q1-q2)) f=true;
????????????while(b>=c1*(x1+1)&&x1<q2) x1++;
????????????while(b>=c1*x1+c2*(x2+1)) x2++;
????????????if(x1==0) f=true;
????????????if(f) cout << "NA" << endl;
????????????else cout << x1 << " " << x2 << endl;
????????????cin >> q1;
????????}else{
????????????if(b<m*q1) f=true;
????????????ll s=c1-c2,sum=0;
????????????sum=q1*m;
????????????while(b-sum>=s*(x1+1)&&x1<q1&&x1<q2) {
????????????????x1++; 
????????????????//cout << b-sum<<":"<<s*x1<<endl;
????????????????//cout << x1<<":"<<c1*x1<<endl;
????????????}
????????????if(x1==q1)
????????????????while(b>=c1*(x1+1)&&x1 + 1<=q2) x1++;
????????????//while(b>=c1*x1+c2*(x2+1)) x2++;
??????????????
????????????if(x1==0) f=true;
????????????x2=0;
????????????while(b>=c1*x1+c2*(x2+1)) x2++;
????????????if(f) cout << "NA" << endl;
????????????else cout << x1 << " " << x2 << endl;
????????????//cout << c1*x1+c2*x2 << endl;
????????????cin >> q1;
????????}
????}
????return 0;
}

C++: #include<iostream>
using namespace std;
main(){
  int max,min,mid;
  int q1,q2,b,c1,c2;
  int aizumoney,sosomoney,sosonum;
  while(1){
    cin>>q1;
    if(q1==0)break;
    cin>>b>>c1>>c2>>q2;
    //会津地鶏二分探索
    min=0;
    max=q2;
    while(min<=max){
      mid=(max+min)/2;
      aizumoney=mid*c1;
      sosomoney=b-aizumoney;
      sosonum=sosomoney/c2;
      // cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<" "<<sosonum<<endl;
      if(mid+sosonum>=q1&&mid>0&&sosonum>=0&&sosomoney>=0){
	//cout<<"OK"<<endl;
	min=mid+1;
      }
      else{
	//cout<<"NG"<<endl;
	max=mid-1;
      }
    }
    mid=(max+min)/2;
    aizumoney=mid*c1;
    sosomoney=b-aizumoney;
    sosonum=sosomoney/c2; 
    // cout<<min<<" "<<max<<" "<<mid<<" "<<aizumoney<<" "<<sosomoney<<" "<<sosonum<<endl;
    if(mid+sosonum>=q1&&mid>0&&sosonum>=0&&sosomoney>=0){
      cout<<mid<<" "<<sosonum<<endl;
    }
    else{
      cout<<"NA"<<endl;
    }
  }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

#define INF (1 << 21)

using namespace std;

int N;

int check[100000];

queue<string> que, que_next;

int index(string str){
	
	int ref = 0;
	
	for(int i = 0; i < N; i++){
		ref *= 3;
		ref += str[i] - '0';
	}
	
	return ref;
}

int main(){
	
	while(true){
		
		int b, c1, c2, q1, q2;
		
		cin >> q1;
		
		if(q1 == 0){
			break;
		}
		
		cin >> b >> c1 >> c2 >> q2;
		
		int ans1, ans2;
		
		if(c1 <= c2){
			ans1 = min(b / c1, q2);
			ans2 = (b - c1 * ans1) / c2;
		}else{
			ans1 = min((b - q1 * c2) / (c1 - c2), q2);
			ans2 = (b - c1 * ans1) / c2;
		}
		
		if(ans1 < 1 || ans2 < 0){
			cout << "NA" << endl;
		}else{
			cout << ans1 << " " << ans2 << endl;
		}
		
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int q1, money, cost1, cost2, q2;
    while(cin >> q1, q1){
        cin >> money >> cost1 >> cost2 >> q2;
        bool is = false;
        for(int i=q2; 0 <= i; i--){
            int g1 = i;
            if(money < cost1*g1) continue;
            int g2 = (money-cost1*g1)/cost2;
            if(g2 < 0 || g1+g2 < q1 || g1 == 0) continue;
            else {
                is = true;
                cout << g1 << " " << g2 << endl;
                break;
            }
        }
        if(!is) cout << "NA" << endl;
    }
}

C++: #include<iostream>
using namespace std;
int a, b, c, d, e;
int main() {
	while (true) {
		cin >> a; if (a == 0)break;
		cin >> b >> c >> d >> e;
		int H = 0, I = 0;
		for (int i = 0; i <= e; i++) {
			int Y = c*i; if (Y > b)break;
			int P = (b - Y) / d;
			if (i + P < a)break;
			H = i, I = P;
		}
		if (H == 0)cout << "NA" << endl;
		else { cout << H << ' ' << I << endl; }
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	int q1;
	while(~scanf("%d",&q1)){
		if(q1==0) break;
		int b,c1,c2,q2;
		//1:aize chiken 2:normal chiken
		scanf("%d %d %d %d",&b,&c1,&c2,&q2);
		for(int i=q2;i>=1;i--){
			int cost = i*c1;

			int ub = 1000000;
			int lb = 0;

			for(int j=0;j<50;j++){
				int md = (ub+lb)/2;
				if(cost + md*c2 <=b) lb = md;
				else ub = md;
			}

			if(lb+i >= q1 && cost + lb*c2 <=b){
				printf("%d %d\n",i,lb);
				goto next;
			}
		}
		printf("NA\n");
next:;
	}
}