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 <bits/stdc++.h>
using namespace std;

int q1,b,c1,c2,q2;

// ????´\?¶???????????????????x??¨??????
bool C(int x){
    if(x*c1 > b || x > q2)
        return false;

    return x + (b-x*c1)/c2 >= q1;
}

int main(){
    while(1){
        cin>>q1;
        if(!q1)break;
        cin>>b>>c1>>c2>>q2;

        int lb = 0, ub = 1e+9;
        for(int i=0;i<100;i++){
            int mid = (lb + ub) / 2;
            if(C(mid)) lb = mid;
            else ub = mid;
        }

        if(lb == 0)
            cout<<"NA"<<endl;
        else
            cout<<lb<<" "<<(b-lb*c1)/c2<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	long long int q1, b, c1, c2, q2;
	while(cin >> q1, q1)
	{
		cin >> b >> c1 >>  c2 >>  q2;
		if(b / c1 > q1 && b / c1 <= q2)
		{
			cout << b / c1 << " " << 0 << endl;
		}
		else
		{
			if(c1 != c2)
			{
				long long int chicken = (q1 * c1 - b) / (c1 - c2) + 1;
				long long int aizu_chicken = q1 - chicken;
				bool flag = true;
				if(aizu_chicken <= 0)
				{
					cout << "NA" << endl;
					flag = false;
				}
				if(flag)
				{
					if(aizu_chicken > q2)
					{
						aizu_chicken = q2;
						chicken = (b - c1 * q2) / c2;
					}
					cout << aizu_chicken << " " << chicken << endl;
				}
			}
			else
			{
				long long int aizu_chicken = b / c1;
				long long int chicken;
				if(aizu_chicken > q2)
				{
					aizu_chicken = q2;
					chicken = (b - c1 * q2) / c2;
				}
				else
				{
					chicken = (b - c1 * aizu_chicken) / c2;
				}
				if(aizu_chicken + chicken < q1)
				{
					cout << "NA" << endl;
				}
				else
				{
					cout << aizu_chicken << " " << chicken << endl;
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a,b,c,d,e;
	cin >> a;
	if(a == 0)break;
	cin >> b >> c >> d >> e;
	int m1 = min(e,b / c); 
	int m = b/d;
	REP(i,m1+1){
	    int tm,tm1;
	    tm = m;
	    tm1 = m1-i;
	    while((tm) * d + (tm1) * c > b){
		tm--;
		if(tm==0) {
		    break;
		}
	    }
	    if(tm+tm1 >= a) {
		m = tm;
		m1 = tm1;
		break;
	    }else if(i == m1){
		m = 0;
		m1 = 0;
	    }
	}
	if(m == 0 && m1 == 0) cout << "NA" << endl;
	else cout << m1 << " " << m << endl;
    }
    return 0;
}

C++: #include <stdio.h>

int max(int a, int b)
{
   if(a>b) return a;
   else return b;
}

int main(void)
{
   int q1, b, c1, c2, q2;
   int qa;
   int hi, lo, ce;

   while(scanf("%d", &q1)){
      if(q1==0) break;
      scanf("%d %d %d %d", &b, &c1, &c2, &q2);

      qa=0;
      hi=q2;
      lo=0;
      while(hi>=lo){
         ce=(hi+lo)/2;
	 if(c1*ce+c2*max(q1-ce, 0)<=b){
	    lo=ce+1;
	    qa=ce;
	 }
	 else {
	    if(c1>=c2) hi=ce-1;
	    else lo=ce+1;
	 }
      }
      if(qa==0) printf("NA\n");
      else printf("%d %d\n", qa, (b-c1*qa)/c2);
   }
   return 0;
}

C++: #include <boost/regex.hpp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int b, c1, c2, q1, q2;
ll com;

bool pred(int x)
{
	com = (b - c1 * x) / c2;
	
	if(com < 0 || q2 < x || b - c1 * x < 0) return false;
	
	return q1 <= x + com;
}

int main()
{
	while(cin >> q1 && q1)
	{
		cin >> b >> c1 >> c2 >> q2;
	
		ll lb = 0, ub = 10000000;
		
		rep(i, 100)
		{
			ll mid = (lb + ub) / 2;
			(pred(mid) ? lb : ub) = mid;
		}
		
		if(ub <= 1) cout << "NA" << endl;
		else cout << ub - 1 << " " << (com < 0 ? 0 : com) << endl;
	}
}

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

int main(){
	int n;
	while(cin >> n , n){
		int need , ans = 0;
		vector<int> d(n);
		rep(i,n) cin >> d[i];
		
		cin >> need;
		int l = 0 , r = n-1;
		while( l !=  r ){
			ans++;
			int m = (l+r)/2;
			if(d[m] > need) r = m-1;
			else if(d[m] < need) l = m+1;
			else {ans--;break;}
		}
		cout << ans+1 << endl;
	}
}

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 = 0; 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;
			}
		}
		
		printf("%d %d\n", aizu, nomal);
	}
	
	return (0);
}

C++: #include <cstdio>

int main(void)
{
	long q1, b, c1, c2, q2;
	
	while (1){
		scanf("%ld", &q1);
		if (q1 == 0) break;
		scanf("%ld %ld %ld %ld", &b, &c1, &c2, &q2);
		
		if ((b < (c2 * (q1 - 1)) + c1) && (c2 < c1)){
			printf("NA\n");
			continue;
		}
		
		long aizu = 0, normal = 0;
		
		aizu = b / c1;
		b = b % c1;
		if (q2 < aizu){
			long over = aizu - q2;
			aizu -= over;
			b += (over * c1);
		}
//		printf("%ld %ld\n", aizu, b);
		
		normal = b / c2;
		b = b % c2;
//		printf("%ld %ld\n", normal, b);
		
		while ((aizu + normal) < q1){
			aizu--;
			b += c1;
			while (c2 <= b){
				normal++;
				b -= c2;
			}
		}
		
		printf("%ld %ld\n", aizu, normal);
	}
	
	return (0);
}