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 <csdio>
using namespace std;

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 (c1 <= c2){
			int x = min(b/c1, q2);
			int y = ((b - x) * c1) / c2;
			if ((x + y) < q1){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
		else {
			int x = min(min(((b - c2) * q1) / (c1 - c2), q2), (b / c1));
			int y = ((b - x) * c1) / c2;
			if(x <= 0){
				printf("NA\n");
			}
			else {
				printf("%d %d\n", x, y);
			}
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  while(1){
    int q1,b,c1,c2,q2,p,n;
    cin >> q1;
    if(!q1)break;
    cin >> b >> c1 >> c2 >> q2;
    p = min(b/c1,q2);
    b -= p*c1;
    n = b/c2;
    b -= n*c2;
    int f=0;
    while(p){
      if(p+n >= q1){
	f=1;
	break;
      }
      p--;
      b+=c1;
      int t = b/c2;
      n+=t;
      b-=t*c2;
    }
    if(f){
      cout << p << ' ' << n << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

C++: // 2011/08/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int q1;
		cin >> q1;
		if(q1==0)
			break;

		int b, c1, c2, q2;
		cin >> b >> c1 >> c2 >> q2;

		int A = b/c1;
		if(A<=0){
			cout << "NA" << endl;
			continue;
		}
		if(A>q2)
			A = q2;

		int B = (b-c1*A)/c2;
		if(A+B>=q1){
			cout << A << ' ' << B << endl;
			continue;
		}

		if((b-c1)/c2<q1-1){
			cout << "NA" << endl;
			continue;
		}

		A = 1;
		B = (b-c1*A)/c2;
		while(B>=0&&A+B>=q1){
			A++;
			B = (b-c1*A)/c2;
		}
		A--;
		B = (b-c1*A)/c2;

		cout << A << ' ' << B << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

#define INF (1 << 21)

using namespace std;

int N;

int check[100000];

queue<string> que, que_next;

int index(string str){
	
	int ref = 0;
	
	for(int i = 0; i < N; i++){
		ref *= 3;
		ref += str[i] - '0';
	}
	
	return ref;
}

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){
			int hoge = 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>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <sstream>

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 <stdio.h>

int max(int a, int b)
{
   if(a>b) return a;
   else return b;
}
int min(int a, int b)
{
   if(a<b) return a;
   else return b;
}

int main(void)
{
   int q1, b, c1, c2, q2;
   int qa;
   int hi, lo, ce;

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

      qa=0;
      hi=q2;
      lo=1;
      //while(hi>=lo){
         ce=(hi+lo)/2;
	 if(c1*ce+c2*max(q1-ce, 0)<=b){
	    //lo=ce+1;
	    //qa=ce;
            for(qa=q2; qa>=ce; qa--){
               if(c1*qa+c2*max(q1-qa, 0)<=b) break;
            }
	 }
	 else {
	    //if(c1>=c2) hi=ce-1;
	    //else lo=ce+1;
	    if(c1>=c2){
            for(qa=ce-1; qa>0; qa--){
               if(c1*qa+c2*max(q1-qa, 0)<=b) break;
            }}
	    else {
	       qa=min(b/c1, q2);
	    }
	 }
      //}
      if(qa==0) printf("NA\n");
      else printf("%d %d\n", qa, (b-c1*qa)/c2);
   }
   return 0;
}

C++: #include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int lm,bud,an,cn,um;
pair<int,int> dp[1000005];

int main(){
	while(1){
		bool used=false;
		cin>>lm;
		if(lm==0) break;
		cin>>bud>>an>>cn>>um;
		for(int i=um;i>0;i--){
			int tmp=(bud-i*an)/cn;
			if(i+tmp>=lm&&tmp>=0&&i*an<=bud){
				cout<<i<<' '<<tmp<<endl;
				used=true;
				break;
			}
		}
		if(!used) cout<<"NA"<<endl;
	}
}

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

int main(){
	int q1,b,c1,c2,q2;
	while(cin >> q1 && q1){
		cin >> b >> c1 >> c2 >> q2;
		int X = 0 , Y = 0;
		while( X < q2 && b - c1 >= 0 ) X++ , b -= c1;
		while( b - c2 >= 0 ){
			Y++;
			b -= c2;
		}
		while( X && X+Y < q1){
			X --;
			b += c1;
			while( b - c2 >= 0 ){
				Y++;
				b -= c2;
			}
		}
		while( b - c2 >= 0 ){
			Y++;
			b -= c2;
		}
		if( X+Y < q1 || !X || b < 0) cout << "NA" << endl;
		else cout << X << " " << Y << endl;
	}
	
}

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

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

  return 0;
}