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;
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<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>
using namespace std;
int main(){
  int count=0,count2=0,b,c1,d=0,i,j,q1,c2,q2,y=0;
  while(1){
    j=0;
    y=0;
    count=0;
    count2=0;
    cin >> q1;
    if(q1==0){
      break;
    }
    cin >> b >> c1 >> c2 >> q2;
    if(b<c1){
      cout << "NA" <<endl;
      continue;
    }
    while(b>c1){
      b=b-c1;
      count++;
      if(count >= q2){
	break;
      }
    }
    if(b<c2 && count<q1){
      cout << "NA" <<endl;
      continue;
    }
    if(b>=c2){
      while(b>c2){
	b=b-c2;
	count2++;
      }
    }
    if(count+count2<q1){
      while(1){
	d=0;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	count--;
	b=b+c1;
	while(c1>=c2*d){
	  count2++;
	  b=b-c2;
	  d++;
	  if(count+count2>=q1){
	    y=1;
	    break;
	  }
	}
	if(y==1){
	  break;
	}
      }
    }
    if(j!=1){
      cout << count << " " << count2 <<endl;
    }
  }
}

C++: #include<stdio.h>
int main(){
	int a,b,c,d,e;
	while(scanf("%d",&a),a){
		scanf("%d%d%d%d",&b,&c,&d,&e);
		bool ok=false;
		int bestA=0;
		int bestB=0;
		for(int i=1;i<=e;i++){
			int f=b-c*i;
			int g=f/d;
			if(f>=0&&i+g>=a){
				bestA=i;
				bestB=g;
				ok=true;
			}
		}
		if(!ok)printf("NA\n");
		else printf("%d %d\n",bestA,bestB);
	}
}

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

int main()
{
    int q1,b,c1,c2,q2,g1=0,g2=0;
    while(cin>> q1>>b>>c1>>c2>>q2)
    {
        int na = 1;
        for(g1=q2;g1> 0 ;--g1)
        {
            if( (g1+(b-g1*c1)/c2)>=q1 &&(g1*c1+g2*c2)<=b)
            {
                na=0;break;
            }
        }
        if(na){cout<<"NA"<<endl;continue;}
        cout << g1 << " "<< (b-g1*c1)/c2<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int q1,b,c1,c2,q2;
	while(q1=in()){
		cin>>b>>c1>>c2>>q2;
		if(b<c1+c2*(q1-1)){
			cout<<"NA"<<endl;
			continue;
		}
		b-=c1;q1--;q2--;
		int t;
		if(c1>c2){
			t=(b-c2*q1)/(c1-c2);
			if(t>q1)t=b/c1;
			chmin(t,q2);
		}else{
			t=q2;
		}
		cout<<t+1<<" "<<(b-c1*t)/c2<<endl;
	}
	return 0;
}

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

int main()
{
  long long int q1, b, c1, c2, q2;
  while (cin >> q1 >> b >> c1 >> c2 >> q2) {
    if (q1 == 0)
      break;

    long long int aizu = min(b/c1, q2);
    b -= aizu * c1;
    long long int chicken = b / c2;
    b -= chicken * c2;

    if (aizu+chicken < q1 && c1 > c2) {
      while (aizu > 0 && aizu+chicken < q1) {
	--aizu;
	b += c1;
	long long int new_chicken = b / c2;
	b -= new_chicken * c2;
	chicken += new_chicken;
      }
    }

    if (aizu <= 0LL || aizu+chicken < q1)
      cout << "NA" << endl;
    else
      cout << aizu << " " << chicken << 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)
		{
			cout << ans1 << " " << ans2 << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	
	}

	return 0;
}