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 <cstdio>

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 (b < (c2 * q1 - 1) + c1){
			printf("NA\n");
			continue;
		}
		
		int aizu = 0, nomal = 0;
		
		for (int i = 1; i <= q2; i++){
			aizu++;
			b -= c1;
			if (b < 0){
				aizu--;
				b += c1;
				break;
			}
		}
		for (int i = 0; 0 <= b; i++){
			nomal++;
			b -= c2;
		}
		nomal--;
		b += c2;
		
		while ((aizu + nomal) < q1){
			aizu--;
			b += c1;
			while (c2 <= b){
				nomal++;
				b -= c2;
			}
		}
		
		while (c1 <= b && aizu <= q2){
			aizu++;
			b -= c1;
		}
		while (c2 <= b){
			nomal++;
			b -= c2;
		}
		
		printf("%d %d\n", aizu, nomal);
	}
	
	return (0);
}

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

using namespace std;

int main(){
    int q1;
    
    while(cin >> q1 && q1){
        int badget, pi, pn, lim;
        int reti, retn;
        cin >> badget >> pi >> pn >> lim;
        
        if(pi*q1 <= badget){
            reti = q1;
            retn = 0;
        }else{
            retn = ceil((double)(pi*q1 - badget) / (pi - pn));
            reti = q1 - retn;
        }

        badget -= pi * reti + pn * retn;

        if(reti > lim){
            badget += pi * (reti - lim);
            reti = lim;
        }else{
            if(badget > 0){
                reti += min(lim - reti, badget / pi);
                badget -= min(lim - reti, badget / pi) * pi;
            }
        }

        if(badget > 0){
            retn += badget / pn;
            badget = badget - (badget / pn) * pn;
        }
        if(badget < 0 || retn+reti < q1 || retn < 0 || reti <= 0){
            cout << "NA" << endl;
        }else{
            cout << reti << " " << retn << endl;
        }
    }
}

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

int main(void){
  while(true){
    int q1, b, c1, c2, q2, aChicken, oChicken;
    cin >> q1 >> b >> c1 >> c2 >> q2;
    if(q1 == 0) break;
    aChicken = min(q2, b / c1);
    b = b - aChicken * c1;
    oChicken = max(0, b / c2);
    b = b - oChicken * c2;

    while(aChicken + oChicken < q1 && aChicken != 0){
    b += c1;
    b += oChicken * c2;
    oChicken = b / c2;
    b = b - oChicken * c2;
    aChicken--;
    }

    if(aChicken == 0){
      cout << "NA" << endl;
    }else{
      cout << aChicken << " " << oChicken << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

int main()
{
	int q1,b,c1,c2,q2;
	while(cin>>q1,q1)
	{
		cin>>b>>c1>>c2>>q2;
		for(int aizu=q2;aizu>0;aizu--)
		{
			if(double(aizu)*c1>b)continue;
			int hutuu=(b-aizu*c1)/c2;
			if(aizu+hutuu<q1)continue;
			
			cout<<aizu<<" "<<hutuu<<endl;
			goto END;
		}
		cout<<"NA"<<endl;
		
		END:;
	}
	return 0;
}

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

int main()
{
	int q1,money,c1,c2,q2;
	while(cin >> q1){
		if(!q1)
			break;
			cin >> money >> c1 >> c2 >> q2;
			int zidori = min(money/c1,q2);
			int hutuu = 0;
			int kakaku = zidori*c1 + hutuu*c2;
			while(zidori+hutuu < q1){
				while(kakaku < money){
					if(kakaku+c2 < money){
						kakaku += c2;
						hutuu++;
					}
					else
						break;
				}
				if(zidori+hutuu >= q1)
					break;
				zidori--;
				kakaku -= c1;
				if(zidori <= 0)
					break;
			}
			if(zidori <= 0 || zidori + hutuu < q1)
				cout << "NA" << endl;
			else
				cout << zidori << " " << hutuu << endl;
	}
	return 0;
}

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

int main(){
	int b,c1,c2,q1,q2,aizu,ord;

	while(cin>>q1,q1){
		cin>>b>>c1>>c2>>q2;
		if(b/c1>q2){
			aizu=q2;
			ord=(b-c1*q2)/c2;
		}else{
			aizu=b/c1;
			ord=(b%c1)/c2;
		}
		if((aizu+ord)<q1){
			for(int i=aizu-1;i>0;i--){
				if((c1*i+c2*(q1-i))<b){
					cout<<i<<" "<<q1-i<<endl;
					break;
				}
			}
			cout<<"NA"<<endl;
		}else{
			cout<<aizu<<" "<<ord<<endl;
			continue;
		}
	}
	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(){
	long long q1,b,c1,c2,q2;
	while(cin >> q1 , q1){
		cin >> b >> c1 >> c2 >> q2;
		long long now = q2 * c1;
		while(now>b){
			now -= c1;
			q2--;
		}
		while(q2+(b-now)/c2 < q1 && q2 > 0){
			now -= c1;
			q2--;
		}
		if(q2>0){
			cout << q2 << " " << (b-now)/c2 << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

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