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 <string>
#include <vector>
using namespace std;

int q1,b,c1,c2,q2;

int main() {
    while (cin >> q1, q1) {
        cin >> b >> c1 >> c2 >> q2;
        bool ok = false;
        int x, y;
        for (x=min(b/c1,q2); x>=1; --x) {
            y = (b - c1 * x) / c2;
            if (q1 <= x + y) {
                ok = true;
                break;
            }
        }
        if (ok) {
            cout << x << " " << y << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: 
#include<iostream>


using namespace std;


typedef struct struct_input
{
	//欲しい肉の量
	int niku;
	//予算
	int yosan;
	//地鶏の値段
	int didori_nedan;
	//普通の
	int normal_tori;
	//地鶏を最大で買える数
	int didori_max;
}S_input;


S_input s_input;




int main(void)
{
	while (true)
	{
		int ans1 = 0 , ans2 = 0;

		cin >> s_input.niku;

		if (s_input.niku == 0)	{	return 0;	}

		cin >> s_input.yosan >> s_input.didori_nedan >> s_input.normal_tori >> s_input.didori_max;
	
		//地鶏の最大
		for (int i = 0; i < s_input.didori_max; i++)
		{
			//金の少ない多い
			if (s_input.yosan < s_input.didori_nedan)
			{
				break;
			}
			s_input.yosan -= s_input.didori_nedan;
			ans1++;
		}

		//残りの金で鶏肉を買う
		while (s_input.yosan > s_input.normal_tori)
		{
			ans2++;
			s_input.yosan -= s_input.normal_tori;
		}

		if (ans1 <= 0)
		{
			cout << "NA" << endl;
			continue;
		}
		if (ans1 + ans2 >= s_input.niku)
		{
			cout << ans1 << " " << ans2 << endl;
			continue;
		}

		//2つの肉の差
		int sa = s_input.didori_nedan - s_input.normal_tori;
		while (ans1 > 0)
		{
			ans1--;
			ans2++;
			s_input.yosan += sa;

			while (s_input.yosan >= s_input.normal_tori)
			{
				ans2++;
				s_input.yosan -= s_input.normal_tori;
			}

			if (ans1 + ans2 >= s_input.niku)
			{
				break;
			}
		}
		

		if (ans1 + ans2 >= s_input.niku && ans1 > 0)
		{
			cout << ans1 << " " << ans2 << endl;
			continue;
		}
		cout << "NA" << 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=max(n-i,0);;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<bits/stdc++.h>
using namespace std;

int main(){

  int q1,b,c1,c2,q2;
  int sum1,sum2;

  while(cin >> q1 && q1){

    cin >> b >> c1 >> c2 >> q2;
    sum1 = sum2=0;

    while(b>=c1 && q2>0){
      sum1 ++;
      b -= c1;
      q2--;
    }
    while(b>=c2){
      sum2++;
      b -= c2;
    }

    while(sum1>1 && sum1+sum2<q1){
      sum1--;
      b+=c1;
      while(b>=c2){
	b-=c2;
	sum2++;
      }
    }
   

    if(sum1+sum2 >= q1 && sum1>0){
      cout << sum1 << ' ' << sum2 << endl;
    }
    else{
      cout << "NA" << endl;
    }

  }
      

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef unsigned long long ull; 
 
class AOJ0186{
private:
  int q1,b,c1,c2,q2;
public:
 
  AOJ0186(int a,int b,int c,int d,int f):q1(a),b(b),c1(c),c2(d),q2(f){}
  ~AOJ0186(){}
 
 
  void run(){
    int aizu_meet,meet;
 
    bool ok = false;
    int preb = b;
     
    for(int i=q2;i>=1;i--){
      aizu_meet = meet = 0,b = preb;
      if(i*c1 > b)continue;
      aizu_meet = i;
      b -= (c1*i);
      meet = b/c2;
      //cout << "i =" << i << endl;
      //cout << aizu_meet << ' ' << meet << ", b = " << b << endl;
      if(aizu_meet+meet < q1)continue;
      if(aizu_meet == 0)continue;
      ok = true;
      cout << aizu_meet << ' ' << meet << endl;
      //cout << "i = " << i << endl;
 
      break;
    }
 if(!ok)cout << "NA" << endl;

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((c1*i+c2*(q1-i))<b){
					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>
using namespace std;

int main() {
	int q1, b, c1, c2, q2;
	while(cin >> q1, q1) {
		cin >> b >> c1 >> c2 >> q2;
		int jidori, normal;
		jidori = normal = -1;
		for(int i = 1; i <= q2; i++) {
			if(b >= c1 * i && i + (b - c1 * i) / c2 >= q1) {
				jidori = i;
				normal = (b - c1 * i) / c2;
			}
		}
		if(jidori >= 0 && normal >= 0)
			cout << jidori << " " << normal << endl;
		else
			cout << "NA" << endl;
	}
}

C++: #include<iostream>

using namespace std;

int main()
{
	int q_lower,bud,c_aizu,c_normal,q_aizuupper;
	while(cin>>q_lower>>bud>>c_aizu>>c_normal>>q_aizuupper){
		int q_aizu=0,q_normal=0;
		q_aizu+=q_aizuupper;
		bud-=q_aizu*c_aizu;
		if(bud<0){
			q_aizu-=(-bud+(c_aizu-1))/c_aizu;
			bud+=((-bud+(c_aizu-1))/c_aizu)*c_aizu;
			if(q_aizu<=0){
				cout<<"NA"<<endl;
				continue;
			}
		}
		q_normal+=bud/c_normal;
		bud-=q_normal*c_normal;

		while(q_aizu+q_normal<q_lower && q_aizu>0){
			q_aizu--;
			bud+=c_aizu;
			q_normal+=bud/c_normal;
			bud-=(bud/c_normal)*c_normal;
		}
		if(q_aizu<=0){
			cout<<"NA"<<endl;
			continue;
		}
		if(q_aizu+q_normal>=q_lower)	cout<<q_aizu<<' '<<q_normal<<endl;
		else	cout<<"NA"<<endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long q1,b,c1,c2,q2,i,j,p1,p2,qq;
while(cin>>q1){
if(q1==0)break;
cin>>b>>c1>>c2>>q2;
p1=p2=0;

for(i=0;i<q1;i++){
if(b<c2){cout<<"NA"<<endl;goto E;}
b-=c2;p2++;
}
if(q1>q2){
for(i=0;i<q2;i++){
if(b<c1-c2)break;
b-=(c1-c2);p1++;p2--;
}
for(;;){
if(b<c2){break;}
b-=c2;p2++;
}
}else{
for(i=0;i<q1;i++){
if(b<c1-c2)break;
b-=(c1-c2);p1++;p2--;
}
for(;p1<=q2;){
if(b<c1){break;}
b-=c1;p1++;
}
}
if(p1==0)cout<<"NA"<<endl;
else cout<<p1<<" "<<p2<<endl;
E:;
}
return 0;
}