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 <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
	ll q1, b, c1, c2, q2;
	while(scanf("%lld", &q1), q1){
		scanf("%lld%lld%lld%lld", &b, &c1, &c2, &q2);
		b -= c1;
		q1--; q2--;
		if(b < 0){
			puts("NA");
			continue;
		}
		
		int ans[2] = {0};
		rep(i, q1+1){
			ll cost = i*c1 + (q1-i)*c2;
			if(cost <= b){
				ans[0] = i + (b-cost)/c1;
				ans[1] = q1-i + ((b-cost)%c1)/c2;
			}
		}
		
		if(ans[0] > q2){
			ans[0] = q2;
			ans[1] = (b-q2*c1)/c2;
		}
		
		if(ans[0]+ans[1] >= q1)
			printf("%d %d\n", ans[0]+1, ans[1]);
		else
			puts("NA");
	}
	return 0;
}

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;
			if (b < 0){
				nomal--;
				b += c2;
				break;
			}
		}
		
		while ((aizu + nomal) < q1){
			aizu--;
			b += c1;
			while (c2 <= b){
				nomal++;
				b -= c2;
			}
		}
		
		printf("%d %d\n", aizu, nomal);
	}
	
	return (0);
}

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;

        if((b - c1) / min(c1, c2) < q1 - 1)
            cout << "NA" << endl;
        else{
            int x = 1;
            int y = q2;
            int tmp = 0;
            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(++tmp > 1000)
                    x = y;
            }
            cout << x << ' ' << ((b - x*c1) / c2) << 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<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long q1,b,c1,c2,q2,d,n,t;
	while(cin>>q1,q1){
		cin>>b>>c1>>c2>>q2;
		if(c1<=c2){
			d=min(q2,b/c1),n=(b-c1*d)/c2;
			if(d+n<q1)cout<<"NA"<<endl;
			else cout<<d<<" " <<n<<endl;
		}else{
			if(c2*(q1-1)+c1>b)cout<<"NA"<<endl;
			else{
				d=min(q2,min((b-q1*c2)/(c1-c2),b/c1)),n=(b-c1*d)/c2;
				cout<<d<<" "<<n<<endl;
			}
		}
	}
	return 0;
}

C++: #include <cstdio>

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

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

    int cnt1 = b / c1;
    if(cnt1 > q2){
      cnt1 = q2;
    }

    b -= cnt1 * c1;

    if(0 <= b && q1 <= cnt1){
      printf("%d %d\n" ,cnt1 ,0);
      continue;
    }

    int cnt2 = b / c2;
    b -= cnt2 * c2;

    while(true){
      if(cnt1 + cnt2 >= q1 && b >= 0){    
	break;	
      } 

      cnt1--;
      b += c1;

      b += cnt2 * c2;
      cnt2 = b / c2;
      b -= cnt2 * c2;
    }

    if(cnt1 > 0){
      printf("%d %d\n" ,cnt1 ,cnt2);
    }else{
      puts("NA");
    }
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

void failed() {
  cout << "NA" << endl;
}

int main() {
  
  int Q1, B, C1, C2, Q2;
  
  while(cin >> Q1) {
    
    if(Q1 == 0) break;
    
    cin >> B >> C1 >> C2 >> Q2;
    
    assert(Q2 >= 0);
    
    /*
    if(B/C1 == 0) {
      failed(); continue;
    }
    */
    
    int AizuCh = min(B/C1, Q2);
    if(AizuCh <= 0) { failed(); continue; }
    int NCh = 0;
    for(;;) {
      
      NCh = (B - AizuCh*C1)/C2;
      
      /*
      if(B - (NCh+1)*C2 - AizuCh*C1 >= 0) {
        NCh = (B - AizuCh*C1)/C2;
      }
      */
      if(AizuCh + NCh >= Q1) {
        cout << AizuCh << ' ' << NCh << endl; break;
      }
      /*
      else if(B - (NCh+1)*C2 - (AizuCh-1)*C1 >= 0) {
        NCh ++, AizuCh --;
      }
      */
      else AizuCh --;
      
      if(AizuCh <= 0) { failed(); break; }
    }
    
  }
  
  return 0;
}

C++: #include<iostream>
#include<cstdio>
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--;
	b=b+c1;
	if(count<=0){
	  cout << "NA" << endl;
	  j=1;
	  break;
	}
	if(count+count2>=q1){
	  break;
	}
	while(b-c2*d>0){
	  count2++;
	  b=b-c2;
	  d++;
	  if(count+count2>=q1){
	    y=1;
	    break;
	  }
	}
	if(y==1){
	  break;
	}
      }
    }
    if(j==0){
      cout << count << " " << count2 <<endl;
    }
  }
}