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;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int q1, b, c1, c2, q2;
	while (cin >> q1, q1) {
		cin >> b >> c1 >> c2 >> q2;
		
		int ans1 = 0, ans2 = 0;
		for (int i = 1; i <= q2; i++) {
			int nc = b - i * c1;
			int cnt = nc / c2;
			
			if (nc < 0 || i + cnt < q1) continue;
			
			ans1 = i;
			ans2 = cnt;
		}
		
		if (ans1 == 0) puts("NA");
		else printf("%d %d\n", ans1, ans2);
		 
	}
	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;
	count--;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	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<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;
	count--;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	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<iostream>
using namespace std;

#define min(a,b) (a<b?a:b)

int main() {
	int q1, b, c1, c2, q2;
	int amax, A, B;
	while(1) {
		cin >> q1;
		if(!q1) break;
		cin >> b >> c1 >> c2 >> q2;
		amax = min(b/c1, q2);
		for(A=amax; A>0; --A) {
			B = (b-A*c1)/c2;
			if(A+B>=q1) break;
		}
		if(!A) cout << "NA" << endl;
		else cout << A << " " << B << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

	while (cin >> q1 >> b >> c1 >> c2 >> q2 && q1 ){

		int add = 0;		// ª
		bool no_ans = false;
		int resx = 0, resy = 0;
		while (1){
			int l = 0;
			int r = q2;
			int x = 0, y = 0;	// ïÃn{ÌÊAÊÌ{÷ÌÊ
			while (l <= r ){
				x = (l+r)/2;
				y = q1 + add - x;
				if (y < 0 ){
					r = x - 1;
					continue;
				} // end if
				if (c1*x + c2*y <= b ){
					l = x + 1;
				}else{
					r = x - 1;
				} // end if
			} // end while
			x = min (l, r );
			y = q1 + add - x;
			
			if (add == 0 ){
				if (x <= 0 ){
					no_ans = true;
					break;
				}else{
					resx = x, resy = y;
				} // end if	
			}else{
				if (x >= resx && y >= resy ){
					resx = x, resy = y;
				}else if (x == resx && y > resx ){
					resx = x, resy = y;
				}else if (x > resx && y >= 0 ){
					resx = x, resy = y;
				}else{
					break;
				} // end if
			} // end if
			add++;
		} // end while		
		if (no_ans ){
			cout << "NA" << endl;
		}else{
			cout << resx << ' ' << resy << endl;
		} // end if
	} // end while
		
	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) / c2 < q1 - 1)
		{
			cout << "NA" << endl;
			continue;
		}
		int aizuChicken = min(b / c1, q2);
		while(aizuChicken + (b - (aizuChicken * c1)) / c2 < q1)
		{
			--aizuChicken;
		}
		cout << aizuChicken << " " << (b - (aizuChicken * c1)) / c2 << endl;
	}
}

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

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(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{
    ll 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=0;
    while(b>=c1*x1+c2*(x2+1)) x2++;
    if(f) cout << "NA" << endl;
    else cout << x1 << " " << x2 << endl;
    cin >> q1;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	while(true){
		int aizu_ckn = 0, ckn = 0;
		int q1,q2,b,c1,c2;
		cin>>q1;
		if(q1==0)
			break;
		cin>>b>>c1>>c2>>q2;

		if(!(b>=c1)){
			cout<<"NA\n";
			continue;
		}

		aizu_ckn=b/c1;
		if(aizu_ckn>q2)aizu_ckn=q2;
		b-=aizu_ckn*c1;
		if(aizu_ckn+ckn<q1){
			ckn=q1-aizu_ckn;
			b-=ckn*c2;
			if( b<0 ){
				int change=-b/(c1-c2)+1;
				aizu_ckn-=change;
				ckn+=change;
				b+=change*(c1-c2);
			}else{
				ckn+=b/c2;
			}
		}

		if( b<0||aizu_ckn<1 )
			cout<<"NA\n";
		else
			cout<<aizu_ckn<<' '<<ckn<<endl;
	}
	return 0;
}