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>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int a[10];

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){
			a[-1] = 0;
			ans1 = min(b / c1, q2);
			ans2 = (b - c1 * ans1) / c2;
		}else if(q1 * c1 > b){
			ans1 = min((b - q1 * c2) / (c1 - c2), q2);
			ans2 = (b - c1 * ans1) / c2;
		}else{
			ans1 = min(b / c1, q2);
			ans2 = (b - c1 * ans1) / c2;
		}
		
		
		if(ans1 < 1 || ans2 < 0){
			cout << "NA" << endl;
		}else{
			cout << ans1 << " " << ans2 << endl;
		}
		
		//cout << ans1 << " " << ans2 << endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	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
		{
			int chicken = (q1 * c1 - b) / (c1 - c2) + 1;
			int aizu_chicken = q1 - chicken;
			if(aizu_chicken <= 0)
			{
				cout << "NA" << endl;
				continue;
			}
			if(aizu_chicken > q2)
			{
				aizu_chicken = q2;
				chicken = (b - c1 * q2) / c2;
			}
			cout << aizu_chicken << " " << chicken << endl;
		}
	}
}

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

C++: #include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	for (int q1, b, c1, c2, q2; cin >> q1 >> b >> c1 >> c2 >> q2&&q1;) {
		int money = b;
		int aizu_m = min(q2, money / c1);
		money -= aizu_m*c1;
		int normal_m = money / c2;
		money -= normal_m*c2;
		bool NA = false;
		while (aizu_m + normal_m < q1) {
			if (aizu_m <= 0) {
				NA = true;
				break;
			}
			aizu_m -= 1;
			money += c1;
			int normal_m_add = money / c2;
			normal_m += normal_m_add;
			money -= normal_m_add*c2;
		}
		if (aizu_m == 0)NA = true;
		if (NA) {
			cout << "NA" << endl;
			continue;
		}
		cout << aizu_m << " " << normal_m << endl;
	}
	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 now = money - zidori*c1;
			int hutuu = q1-zidori;
			if(hutuu < 0)
				hutuu = 0;
			int kakaku = zidori*c1 + hutuu*c2;
			while(kakaku > money){
				zidori--;
				hutuu++;
				kakaku -= c1-c2;
			}
			while(kakaku < money){
				if(kakaku+c2 < money){
					kakaku += c2;
					hutuu++;
				}
				else
					break;
			}
			if(zidori <= 0)
				cout << "NA" << endl;
			else
				cout << zidori << " " << hutuu << " " << kakaku << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
  long int q1, b, c1, c2, q2, s, t, cost, a;
  float f;

  while(1){
    cin >> q1;
    if(q1 == 0){
      break;
    }
    cin >> b >> c1 >> c2 >> q2;

    s = b / c1;
    if(s > q2){
      s = q2;
    }
    t = q1 - s;
    if(t < 0){
      t = 0;
    }
    cost = c1*s + c2*t;
    if(cost > b){
      while(s > 0 && cost > b){
	cost -= c1;
	s--;
      }
    }
    if(s <= 0){
      cout << "NA" << endl;
      continue;
    }
    while(cost+c2 <= b){
      t++; 
      cost += c2;
    }
    if(s+t < q1){
      q1 -= (s+t);
      f = (float)c1/c2;
      a = 1;
      while((int)f < q1){
	f += f;
	a++;
      }
      s -= a;
      if(s <= 0){
	cout << "NA" << endl;
	continue;
      }
      cost -= c1*a;
      cost += ((int)f*c2);
      t += (int)f;
      while(cost+c2 <= b){
	t++; 
	cost += c2;
      }
      if(s+t < q1){
	cout << "NA" << endl;
	continue;
      }
    }
    cout << s << " " << t << endl;
  }

  return 0;
}

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

int q1,q2,b,c1,c2,ans1,ans2;

bool solve(){
	if(!q2)
		return false;
	ans1 = q2;
	ans2 = 0;
	while(ans1*c1 + ans2*c2 <= b)
		ans2++;
	if(ans2)
		ans2--;
	if(ans1 + ans2 >= q1 && ans1*c1 + ans2*c2 <= b)
		return true;
	while(true){
		ans1--;
//		if(!ans1)
//			return false;
		while(true){
			ans2++;
			if(ans1*c1 + ans2*c2 > b){
				ans2--;
				break;
			}
		}
		if((ans1*c1 + ans2*c2 <= b && ans1 + ans2 >= q1) || ans1 == 0)
			break;
	}
	if(!ans1)
		return false;
	else
		return true;
}

int main(){
	while(true){
		cin >> q1;
		if(!q1)
			return 0;
		cin >> b >> c1 >> c2 >> q2;
		if(solve())
			cout << ans1 << ' ' << ans2 << endl;
		else
			cout << "NA" << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int q1, b, c1, c2, q2;
        cin >> q1 >> b >> c1 >> c2 >> q2;
        if(q1 == 0)
            return 0;

        int x = 0;
        int y = q2;
        while(x != y){
            int z = (x + y + 1) / 2;
            if(b - z*c1 >= 0 && (b - z*c1) / c2 >= q1 - z)
                x = z;
            else
                y = z-1;
        }

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